| 04-12-2007, 12:24 AM | #1 |
The purpose of this thread is to discuss how is the best way to improve the unit group usage in hard conditions (and, why not, in a normal situation). I have this JASS function which uses intensively a unit group. It creates and dynamically fills and clean a group. Optimized function??:constant function Test_MaxUnits takes nothing returns integer return 50 endfunction function Test_IsWarrior takes nothing returns boolean return IsUnitType(GetFilterUnit(), UNIT_TYPE_PEON)== false and IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false endfunction function Test_UnitsAvaliability takes nothing returns nothing local integer c local group g = CreateGroup() local player p = GetTriggerPlayer() local boolexpr Cnd = Condition(function Test_IsWarrior) loop call GroupEnumUnitsOfPlayer(g, p, Cnd) set bj_groupCountUnits = 0 call ForGroup(g, function CountUnitsInGroupEnum) set c = bj_groupCountUnits exitwhen c >= Test_MaxUnits() call GroupClear(g) call PolledWait(10.) endloop call DestroyGroup(g) call DestroyBoolExpr(Cnd) set g = null set p = null set Cnd = null endfunction Before this trigger there was this: A bad function??:constant function Test_MaxUnits takes nothing returns integer return 50 endfunction function Test_IsWarrior takes nothing returns boolean return IsUnitType(GetFilterUnit(), UNIT_TYPE_PEON)== false and IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false endfunction function Test_UnitsAvaliability takes nothing returns nothing local integer c local group g local player p = GetTriggerPlayer() local boolexpr Cnd = Condition(function Test_IsWarrior) loop set g = CreateGroup() call GroupEnumUnitsOfPlayer(g, p, Cnd) set bj_groupCountUnits = 0 call ForGroup(g, function CountUnitsInGroupEnum) set c = bj_groupCountUnits exitwhen c >= Test_MaxUnits() call DestroyGroup(g) call PolledWait(10.) endloop call DestroyGroup(g) call DestroyBoolExpr(Cnd) set g = null set p = null set Cnd = null endfunction What's the best option?? is there a better way to do that?? Thanks for your comments. |
| 04-12-2007, 01:08 AM | #2 |
I don't think it matters since you are setting the group anyways. I'm not sure, but I don't think it matters much. EDIT: Wait... The first is better I think because you clear the group then delete it.. In the second one, you delete it two times, but don't clear it! lol... I'm not entirely sure though.. |
| 04-12-2007, 01:20 AM | #3 |
I think the first is the best because it recycle the variable, but I have my doubts about the function GroupClear(), I've heard that it's not good enough and I want to confirm that. In the other hand, I want to know if the boolexpr variable is managed in an efficient (and correct) way. |
| 04-12-2007, 01:36 AM | #4 |
Yea, but wouldn't it not matter because you destroy the group anyways, or am I wrong? I'm pretty sure that the boolexpr is alright, it matches the conditions of the function and it makes sense etc. Just wondering, did you test this out? ![]() |
