• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Quick question about forGroup

Status
Not open for further replies.
Level 11
Joined
Sep 12, 2008
Messages
657
I gotta know.. does forGroup remove every unit that is used inside?
because when i do this:

JASS:
set capGroup = GetUnitsOfTypeIdAll('hwtw') 
call ForGroup(nodeGroup, function nodeGroupSetupLoop)

and then in a loop do this:

JASS:
call BJDebugMsg(I2S(CountUnitsInGroup(nodeGroup)))
call ForGroup(nodeGroup, function nodeGroupLoop)

i get spam of "0".. and yeah, it does run on initialization (the first code),
because its not the entire thing.. the other thing are just debug messages..
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
No ForGroup doesn't remove units, as long you don't ask it in the callback function.

You probably doesn't enum units at all, or you are destroying the group somewhere, or even use a GroupEnum.

Your lines of code by themselves are not enough, we miss a part of the code.

Also make sure you don't use the custom script set bj_wantDestroyGroup = true.
If it still not fixed in the new patch (which is probably the case) it doesn't work very well with GroupEnumUnitOfType, because of the lame gui functions.
It will enumerate units of player red ( Player(0) ) and then will destroy the group and have a group leak or something like that (have to check these functions to remember it exactly).
I'm just sure it will enum only Player(0) 's units.
 
Level 11
Joined
Sep 12, 2008
Messages
657
btw.. i didnt fix any leaks to this point.. lol
not heavy 1's atleast, and no, i dont use bj_wantdestroygroup.
and well.. i did this:
JASS:
    public function stackEnumoration takes integer data, string messageKey returns nothing
        if messageKey == "nodeID" then
            set capGroup = GetUnitsOfTypeIdAll('hwtw') 
            //to be honest, the forGroup i thought was buggy was here..
            // but removed it, cuz it wasnt needed, found a way to make it easier for me ;p (removed a part of the code which was defintly unneeded)
        endif
        if messageKey == "capSpeed" then
            set captureSpeed[GetHandleId(GetEnumUnit())] = data
        endif
        if messageKey == "unitID" then
            set capturingUnitID[GetHandleId(GetEnumUnit())] = data
        endif
    endfunction
    
    public function nodeGroupLoop takes nothing returns nothing
        call BJDebugMsg("Another Test")
    endfunction
    
    public function loopHandler takes nothing returns nothing
        //call BJDebugMsg(I2S(CountUnitsInGroup(nodeGroup)))
        call ForGroup(nodeGroup, function nodeGroupLoop)
    endfunction
    
    private function onInit takes nothing returns nothing
        set captureSpeed = iStack.create()
        set percentsTaken = iStack.create()
        set capturingUnitID = iStack.create()
        call TimerStart(CreateTimer(), 0.032, true, function loopHandler)
        
        call nodeData.stackData.enumorate(stackEnumoration, false)
    endfunction

those are the functions who serve the group functions.
btw, stackEnumoration is a function interfance,
and stackData is just.. well stack [my version of it]

Edit2: just realisd the stack enumoration GetEnumUnit, gonna fix it :p
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
JASS:
set capGroup = GetUnitsOfTypeIdAll('hwtw') 

public function loopHandler takes nothing returns nothing
    //call BJDebugMsg(I2S(CountUnitsInGroup(nodeGroup)))
    call ForGroup(nodeGroup, function nodeGroupLoop)
endfunction

As long you don't set them to the same group (set groupA = groupB will be done by reference not by value, which means it will be the same group) :

capGroup != nodeGroup != nodeGroupLoop
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,286
Do keep in mind how groups work.

Create group -> fill group -> use group.

Natives which add units to the group such as all units of player and all units in area do not create a group and need a pre created group passed to them to fill. This level was obscured by GUI which ruined a major optimization potential. It is recommened to recycle groups as much as possible and in a lot of cases a global constant group could be used instead of a locally created group for instantly computed functions (logically you load it into a local if you plan to use it extensivly). You can also recycle groups just like timers.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
The best of the best of global groups is bj_lastCreatedGroup. Never gets destroyed, perfect for one-shot enumerations.

Perfect if you don't use gui at all (at least with groups), including of course the gui functions used in jass (blizzard.j).

One constant group is not to much a burden, plus i hate typing bj_lastCreatedGroup.

At least that is definitely a bad idea to use it in a public resource.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
I just wanted to mean that is not a good idea for a public resource that's all.
Now if you are happy with this ugly name instead of using your own, i would be silly to have something about it.
Personnaly i still hate the variable name even if i'm agree with your points.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,286
Variable space and code has a very low cost of only RAM. It is far more important to get the code to execute as fast as possible rather than make everything as neat as possible.

In some cases, doing stuff like loop unwinding could be better than a nice neat loop for example as yes it makes more code but it means less computations needed (as loops have an overhead). There is dimishing returns though as if you make too much code that it can no longer fit it all in cache, it will slow down as cache faults occur.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,286
You reach the limit all the time.

Even really modern processors like the lattest core I7 have only 16 MB cache or so and those are really expensive. The average processor WC3 was made for was sub 1 MB cache. Some laptop processors have cache in the order of hundreds of kilobytes.

A cache miss only causes a memory access which is 10-100 (depending on age of system) slower than if it was in cache. It is pointless even trying to factor in cache as like I said, it can vary greatly between systems. The only real time it could be considered is if you unwind a 1000000 itteration loop (only possible in programming languages) but in WC3 its existance is near meaningless. I should not have mentioned it come to think of it.
 
Status
Not open for further replies.
Top