• 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.

What is the best? 1 large group or x small ones?

Status
Not open for further replies.
Level 23
Joined
Nov 29, 2006
Messages
2,482
Hm well, I dont need any help with the scripting this time... I just need some info

But let say I have this event every 5 seconds. Should I add all units which I want to use in the group and then filter them by if:s?
Or should I declare a new unit group for each type?
What is the best in speed and anti-lag aspect?

My second question is: If I have a timer which is periodic every 1 seconds. Would it be best to add all units which is going to be used in the group through the whole game and add/remove units into it once they're created/destroyed?
Or should I create a group at every timer expiration and then destroy the group once its created?

/regards
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Hm well, to make sure you got it right, let me post an example of what I mean

JASS:
//Filter Functions
function FilterIsRoot takes nothing returns boolean
    return GetUnitPointValue(GetFilterUnit()) == 5 
endfunction

function FilterIsBuildingId takes nothing returns boolean
    return GetUnitPointValue(GetFilterUnit()) == 10
endfunction

function FilterIsHero takes nothing returns boolean
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true
endfunction

function FilterIsPeonAncient takes nothing returns boolean
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_PEON) == true and IsUnitType(GetTriggerUnit(), UNIT_TYPE_ANCIENT) == true
endfunction

function FilterIsMainBuilding takes nothing returns boolean
    return GetUnitPointValue(GetFilterUnit()) == 30
endfunction
//End of Filter Functions
function CountUnitsWithFilter takes player whichPlayer, boolexpr e returns integer
    local group g = CreateGroup()
    local unit u
    local integer i = 0
    call GroupEnumUnitsOfPlayer(g, whichPlayer, e)
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        call GroupRemoveUnit(g,u)
        set i = i+1
    endloop
    call DestroyBoolExpr(e)
    call DestroyGroup(g)
    set e = null
    set g = null
    return i
endfunction
function ResourceTaxes takes integer income returns nothing
    //looping through all players
    set counter = CountUnitsWithFilter(Player(i), Condition( function FilterIsHero))
    //do something
    set counter = CountUnitsWithFilter(Player(i), Condition( function FilterIsPeonAncient))
    //do something
    //do this for the filters above
    //....
endfunction

or doing:

JASS:
function another takes nothing returns nothing
    local group g = CreateGroup()
    // loop through players 
    call GroupEnumUnitsofPlayer....
    //endloop
    //first of group looping
    if (condition1) then //by using filterfunctions stated at the top of the first one (changing the taking to takes unit u instead of nothing)
        //do something
    elseif (condition2) then
    //.........
    endif
    endloop
//destroy group...
//more stuff...
endfunction

Im sorry the last one was perhaps really dumb described... But did you get what I mean?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Rawr, that's inefficient:

JASS:
globals
    group enumGrp = CreateGroup()
    integer count
endglobals

function CountFilter takes nothing returns boolean
    if <your conditions> then
        set count = count + 1
    endif
    return false
endfunction

function SomeFunc takes nothing returns nothing
    //time to count!
    set count = 0
    call GroupEnumUnits...(enumGrp,<other needed params>,Filter(function CountFilter))
    //use count
endfunction
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
yea but the problem is that the countings are then multiplyed by different factors afterwards...

JASS:
set taxes = taxes + counter * heroRate
//
set taxes = taxes + counter * buildingRate
//
set taxes = taxes + counter * entBuilderRate
//...

oh wait I could use point value to that? (if its not colliding with something...)

call GroupEnumUnits...(enumGrp,<other needed params>,Filter(function CountFilter))

so you mean that I can just add how many Condition functions I want? Wouldn't that be a boolexpr leak?

Im totally unclear in my mind...
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
yea but the problem is that the countings are then multiplyed by different factors afterwards...
Locals are fun! Except in the example provided you don't even need locals...

oh wait I could use point value to that? (if its not colliding with something...)
?

so you mean that I can just add how many Condition functions I want? Wouldn't that be a boolexpr leak?
Boolexprs act similar to Strings: Filter(function hi) == Filter(function hi) should return true.
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Wait I must be dumb... I didnt even get what you did in your first code :S

Quote:
yea but the problem is that the countings are then multiplyed by different factors afterwards...

Locals are fun!
Uhm yea but how will it determinate the right unit multiplying the right counting values?
Thats what I meant, that I should use the point value for every unit to determinate the factor to multiply it with.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Uhm yea but how will it determinate the right unit multiplying the right counting values?
Separate enums, or an array of counters, or however approach you like most.

Or just remove the counter and do the addition right there...

JASS:
globals
    group enumGrp = CreateGroup()
    integer tax
endglobals

function SomeFilter takes nothing returns boolean
    if <cond1> then
        set tax = tax + <cond1>Rate
    elseif <cond2> then
        //etc
    endif
    return false
endfunction

function Hi takes nothing returns nothing
    //assuming taxes is local due to saving through waits...
    //otherwise just use the global
    set tax = taxes
    call GroupEnumUnits...(enumGrp,<other params>,Filter(function SomeFilter))
    set taxes = tax
endfunction
 
Last edited:
Level 12
Joined
Apr 27, 2008
Messages
1,228
If it is global, you have to destroy it each time you initialize it(=CreateGroup()), but you do not have to null it.
Am am not to certain about that difference.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
A question though... Im assuming the unit group is global?, meaning you never destroy it?
Exactly. It's way more efficient that way.

Edit: Also, what is the differences between "Filter(..." and "Condition(..."
One returns a filterfunc, one returns a conditionfunc. However, no one cares because they're both children of boolexpr.

If it is global, you have to destroy it each time you initialize it(=CreateGroup()), but you do not have to null it.
No you don't...


Forgot = CreateGroup() in my last example, silly me.
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Could it be even more efficient?

Okay, so I've made it in the structure you said Poot.
Is there anything I have forgotten? (the system works just like intent but could it be better?)

JASS:
function ResourceFilter takes nothing returns boolean
    local integer heroRate = 20
    local integer buildingRate = 10
    local integer entRate = buildingRate
    local integer entBuilderRate = entRate/2
    local integer rootRate = 5
    local integer mainRate = 30
    local unit u = GetFilterUnit()
    if (IsUnitType(u, UNIT_TYPE_HERO)) then
        set income = income - heroRate
    elseif (GetUnitPointValue(u) == buildingRate) then
        set income = income - buildingRate
    elseif (IsUnitType(u, UNIT_TYPE_PEON) and IsUnitType(u, UNIT_TYPE_ANCIENT)) then
        set income = income - entBuilderRate
    elseif (GetUnitPointValue(u) == rootRate) then
        set income = income + rootRate
    elseif (GetUnitPointValue(u) == mainRate) then
        set income = income + mainRate
    endif
    set u = null
    return false
endfunction
function UpdateResources takes nothing returns nothing
    local integer i = 0
    loop
        exitwhen i == 12
        set income = 0 
        call GroupEnumUnitsOfPlayer(enumGrp,Player(i),Filter(function ResourceFilter))
        call SetPlayerState(Player(i),PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Player(i), PLAYER_STATE_RESOURCE_GOLD)+income)
        call UpdateMultiboard(income, i)
        set i = i+1
    endloop
endfunction
 
Status
Not open for further replies.
Top