HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

GroupRecycling

01-12-2009, 06:56 PM#1
akolyt0r
Im currently updating an old map i made, therefore i added some libraries as
TimerUtils, Table ...
i also added this minimal Version of CSSafety to Recycle Groups only since i got TimerUtils for Timers....
Expand JASS:

However i am not totally sure how i should convert the triggers of my map to use this correctly ...problems:
Collapse JASS:
// Example of Old Script
set udg_TempGroup=GetUnitsOfPlayerMatching(p,BOOLEXPR_TRUE)
set bj_wantDestroyGroup=true
call ForGroupBJ(udg_TempGroup,function DoSomething)
//

//=========================================
// New "Good !?" Script:
local group g=NewGroup()
call GroupEnumUnitsOfPlayer(g, p, BOOLEXPR_TRUE)
//call DestroyBoolExpr(filter) this one is called in the "GetUnitsOfPlayerMatching"-BJ function,
//However i dont think i need it because my BOOLEXPR_TRUE is a global i reuse all over the place.. !?
call ForGroup(g,function DoSomething)
call ReleaseGroup(g)
set g=null //correct ?

another question... is CSSafety still up to date for group recycling or is there a newer system ?
01-12-2009, 07:52 PM#2
Zerzax
Try making the group a struct member, only create a new one if the index's group is null, then use GroupClear when you call onDestroy. Don't destroy it. This is essentially the same as a group stack, without any extra implementation.
01-12-2009, 07:59 PM#3
akolyt0r
well i this map groups are used widely in (and some of them are periodic aswell) gameplay triggers, were i dont have (and need) any structs.
01-12-2009, 08:04 PM#4
moyack
Quote:
Collapse JASS:
//=========================================
// New "Good !?" Script:
local group g=NewGroup()
call GroupEnumUnitsOfPlayer(g, p, BOOLEXPR_TRUE)
//call DestroyBoolExpr(filter) this one is called in the "GetUnitsOfPlayerMatching"-BJ function,
//However i dont think i need it because my BOOLEXPR_TRUE is a global i reuse all over the place.. !?
call ForGroup(g,function DoSomething)
call ReleaseGroup(g)
//set g=null //Not neccesary anymore...
Yes, that's correct.
01-12-2009, 08:09 PM#5
Joker
minus the g=null part.
01-12-2009, 08:17 PM#6
Troll-Brain
If i assume he won't use any more the function DestroyGroup, and use ReleaseGroup instead, set g= null is unneeded, no ?
01-12-2009, 08:30 PM#7
akolyt0r
Quote:
Originally Posted by Troll-Brain
If i assume he won't use any more the function DestroyGroup, and use ReleaseGroup instead, set g= null is unneeded, no ?
well thats why i asked ..i am not sure either :/
01-12-2009, 08:52 PM#8
Anitarf
Why not just keep a global group?

Collapse JASS:
globals
    private group g = CreateGroup()
endglobals

...
    call GroupEnumUnitsOfPlayer(g, p, BOOLEXPR_TRUE)
    call ForGroup(g,function DoSomething) //you could avoid calling ForGroup by doing your stuff in the GroupEnum filter
    call GroupClear(g)
01-12-2009, 09:17 PM#9
Troll-Brain
For triggers which are evaluate/executed only one time or little more it's overskilled imho, i mean we create a group for it but we don't really have the need.

What about the null thing ?
01-12-2009, 09:25 PM#10
Fledermaus
Since it's just a reference of a global group, you don't need to null it.
01-12-2009, 10:28 PM#11
moyack
Quote:
Originally Posted by Joker
minus the g=null part.
Ahh yes... I just CnPed to answer.... nullifying is not neccesary.
01-12-2009, 10:36 PM#12
Troll-Brain
Just to be more clear, for a local trackable variable, we don't use to null it, because the trackable will be never destroyed, right ?

I mean a handle in general which is never destroyed, we don't need to null the local variable reference ?
01-12-2009, 10:41 PM#13
Captain Griffen
A handle which is never destroyed can never have its handle index recycled, so no need to null it.
01-12-2009, 10:44 PM#14
Troll-Brain
Quote:
Originally Posted by Captain Griffen
A handle which is never destroyed can never have its handle index recycled, so no need to null it.
ok, that's clear for me now, thx.