Unit spawn optimizing

Parsival

Active Member
Reaction score
6
Hi.

I'm making a TD map and I need to spawn large amount of creeps each round (~25 for each player and there is place for 10ppl). Well, that's how I do it, but I tried many solutions:
Trigger:
  • Actions
    • For each (Integer IntegerC) from 1 to AllPlayers, do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • PlayerOwned[IntegerC] Equal to FALSE
          • Then - Actions
            • Set TempPoint = (Center of Spawn[IntegerC])
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • ((Real(IntegerC)) mod 2.00) Equal to 0.00
              • Then - Actions
                • Custom script: call UnitSpawn(udg_Monster_Amount[udg_NextLevel], udg_Monsters[udg_NextLevel], 11)
              • Else - Actions
                • Custom script: call UnitSpawn(udg_Monster_Amount[udg_NextLevel], udg_Monsters[udg_NextLevel], 10)
            • Custom script: call RemoveLocation (udg_TempPoint)
          • Else - Actions
    • For each (Integer IntegerC) from 1 to AllTeams, do (Actions)
      • Loop - Actions
        • Set TempPoint = (Center of Team[IntegerC])
        • Unit Group - Pick every unit in (Units in LeftTeam[IntegerC]) and do (Unit - Order (Picked unit) to Move TempPoint)
        • Unit Group - Pick every unit in (Units in RightTeam[IntegerC]) and do (Unit - Order (Picked unit) to Move TempPoint)
        • Custom script: call RemoveLocation (udg_TempPoint)

And that's the body of UnitSpawn function:
JASS:
function UnitSpawn takes integer Number, integer UnitID, integer Enemy returns nothing
    loop
        set Number = Number - 1
        exitwhen Number < 0
        call CreateUnitAtLoc(Player(Enemy), UnitID, udg_TempPoint, bj_UNIT_FACING)
    endloop
endfunction


Well, it causes annoying lag during each spawn. Is there any way to make it more smooth? I tried adding 'Wait' action before each single spawn but it makes this lag even longer. It froze my comp for half a minute.
I also tried to make separate trigger which orders each unit who entered spawn to move, but it changed nothing.
Same with spawn action. I tried For loop which creates 1 unit x times and normal spawn action which creates x units on location.

Any ideas? :((
Thanks.
 

Iky

New Member
Reaction score
2
maybe your code have group leaks, put a custon script: "set bj_wantDestroyGroup= true" before every group using and say to me if it worked.
And in you jass code, put "exit when Number < -1"
because the number code of the player 1 is 0
 

Parsival

Active Member
Reaction score
6
maybe your code have group leaks, put a custon script: "set bj_wantDestroyGroup= true" before every group using and say to me if it worked.
No, it still causes lag. But hey - you showed me memory leak. Thanks. It's helpful anyways.

And in you jass code, put "exit when Number < -1"
because the number code of the player 1 is 0
Hm. But a 'Number' variable just controls an amount of created units.


Well, any other ideas?
 

Iky

New Member
Reaction score
2
no, not other ideas :/
EDiT
i found a list of leaks in your jass code
put a remove location in the jass' loop code and say to me if its worked
 

Parsival

Active Member
Reaction score
6
put a remove location in the jass' loop code and say to me if its worked
TempPoint is being removed after spawning:
Trigger:
  • Custom script: call RemoveLocation (udg_TempPoint)


I don't have to remove it after each unit's spawn because it's still the same location in memory.
 

Iky

New Member
Reaction score
2
so, ¬¬, i dont know what do :/
EDIT:
i really dont see other leaks, but, however, try in the jass function, set the unit to null in the final, and if still so many leaks, try destroy the location every use, and set it again
 

Squeekems

TH.net Regular
Reaction score
11
When I have maps that involve a huge number of units I do the following:
In the object editor, I go to the units I am using in the map and change the following fields:
Art - Ground Texture: None
Art - Shadow Image (Unit): None
Art - Shadow Texture (Building): None
Art - Special: Delete the model.

The Ground Texture field is only for buildings.

I also go to Advanced>Gameplay Constants.... I check the checkbox at the top that says, "Use Custom Gameplay Constants." In there, I change the Decay Time (sec) - Bones to 5.00. If you have structure dying, I would suggest changing the Decay Time (sec) - Structures to 5.00 as well.
 

Parsival

Active Member
Reaction score
6
When I have maps that involve a huge number of units I do the following:
In the object editor, I go to the units I am using in the map and change the following fields:
Art - Ground Texture: None
Art - Shadow Image (Unit): None
Art - Shadow Texture (Building): None
Art - Special: Delete the model.

The Ground Texture field is only for buildings.

I also go to Advanced>Gameplay Constants.... I check the checkbox at the top that says, "Use Custom Gameplay Constants." In there, I change the Decay Time (sec) - Bones to 5.00. If you have structure dying, I would suggest changing the Decay Time (sec) - Structures to 5.00 as well.

Didn't help :(
 

NotInTheFace

Member
Reaction score
17
Are you preloading the units and their abilities? It might just be lagging because you're creating a new unit-type and has to load its resources and abilities.
 

Parsival

Active Member
Reaction score
6
Are you preloading the units and their abilities?
No. But it still seems to be lagging :(

I added this after ~1 sec of game time:
Trigger:
  • Actions
    • Unit - Create 1 Spiders (Level 1) for Player12(Brown) at (Center of (Playable map area)) facing Default
    • Unit - Remove (Last created unit) from the game


No leaks removal, because it was just a test.

Well, still lags :(
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
Perhaps you have triggers that fire on Unit Enters Map events or something, thus causing lag with each unit created as multiple actions run.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top