HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

RctAr[1] = gg_rct_1 ... AutomaticSetup?!

05-28-2010, 11:45 PM#1
MasterofSickness
What I mean is the setup of the manually created regions in WE (in Jass they are rect) with a global array. I used to make this the whole time manually, but in fact I was always looking for an automation routine, like you can reread here:
Reference to old thread from 2006.
People like Vex said that I should keep making array references manually. Finally he gave me a good hint which I followed (setting up the huge list of code with an external text editor and just paste it in WE)... till now.
I got a relapse
From restarting my map again and again (for several different reasons each time) this manual setup of regions strained my nerves.
Always this same procedure...
Collapse JASS:
set RectAr[1]=gg_rct_1
set RectAr[2]=gg_rct_2
set RectAr[3]=gg_rct_3
Then either I had too many region declarations or too less or there were interrupts.

Now my current workarround (WITH THE HELP OF THE RETURN BUG 2.0).
I want to know what you think of it (besides that most of you are right when they say that the manual method nevertheless is well enough) and if I create any leaks that could harm the later game...

Collapse JASS:
library CustomScriptCode

globals
    private hashtable ht = InitHashtable()
endglobals

function RctId2Rct takes integer RctId returns rect
    call SaveFogStateHandle(ht, 0, RctId, ConvertFogState(RctId)) //Save RectId to HandleId
    return LoadRectHandle(ht, 0, RctId) //Load HandleId and return Rect
endfunction

endlibrary

Collapse JASS:
library Waypoints initializer Init //"initializer Init" for libraries & scopes if they should run at init

globals
    rect array RctAr
endglobals

private function Init takes nothing returns nothing //1 function called Init to run appropriate code
local integer i = GetHandleId(gg_rct_1) //should be 1048596
local integer A = 0

//Manual Setup:
//set RctAr[1]=gg_rct_1
//set RctAr[2]=gg_rct_2
//set RctAr[3]=gg_rct_3
//...

//Test: Get Rect IDs
//set i = GetHandleId(gg_rct_1)
//set s = I2S(i)
//call BJDebugMsg("1048596 = " + s) //fits!
//set i = GetHandleId(gg_rct_2)
//set s = I2S(i)
//call BJDebugMsg("1048597 = " + s) //fits!

loop
    exitwhen A == 56
    set A = A + 1
    set RctAr[A]=RctId2Rct(i)
    set i = i + 1
endloop
endfunction

endlibrary

This is just for the 56 first waypoints.
I will work it out after this consulting with you.
I tested it and it seams to work flawlessly.

So,
should I nullify or destroy anything or code anything in another way (I want an automated setup! ;) )
Thanks for all hints!
05-29-2010, 07:13 AM#2
PurgeandFire111
Haha, that is a cool technique! I never thought of that.

Anyway, some small things:
Collapse JASS:
function RectId2HandleId takes integer RectId returns nothing
    //local integer i = RectId
    call SaveFogStateHandle(ht, 0, RectId, ConvertFogState(RectId)) //use it directly
endfunction

And:
Collapse JASS:
local integer i = GetHandleId(gg_rct_1) //just set it on declaration

Other than that it is fine. Awesome technique, I'll have to keep that in mind. :P

You can destroy the hashtable when you are done though. [if you aren't using it anymore]

EDIT: You can also merge the 2 functions into just 1. It won't be that naming-friendly (lol Rect2I_I2Rect), but that shouldn't matter much. [unless the JassHelper inlining applies to those functions]
05-29-2010, 07:13 AM#3
Bribe
So saving the fogstate converts the integer back into a handle? That's awesome!

I'm wondering what you're doing by increasing the handle index by one each time? Is that because you know for sure that your pre-made rects are each seperated by an index of 1?
05-29-2010, 07:26 AM#4
PurgeandFire111
Quote:
Originally Posted by Bribe
So saving the fogstate converts the integer back into a handle? That's awesome!

Pretty much -> [Snippet] Typecasting

Finally a use for the new typecasting aside from the widget typecasting. xD

Quote:
Originally Posted by Bribe
I'm wondering what you're doing by increasing the handle index by one each time? Is that because you know for sure that your pre-made rects are each seperated by an index of 1?

Yep, the ones made on the editor are made consecutively in a function on map Init. Thus, they should have intervals of 1 for their ids.
05-29-2010, 10:07 AM#5
MasterofSickness
@ PurgeandFire111
Thanks for the improvements!
I will change it like you said and perhaps merge it into 1 function :)

And thanks for the praise ;)
But without weaaddar it would not have been possible for me (convertfogstate)!

EDIT
Updated 1st post with appropriate improvements!