• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Do loops leak like shit?

Status
Not open for further replies.
Level 19
Joined
Oct 29, 2007
Messages
1,184
Need help with my superoverleakage triggering!

Uhm.. Yah.. I had some triggers, that where running at every 0.04 second of time for a player. And then I thought it was a nice idea to make loop actions, so that the triggers work for all players. And uhm.. Now I got a nice moderate framerate drop while playing from about 60 (which I constantly had before I used teh loops) to I think 0. (but while playing I only tested untill the framerate hit 20.)

I can't seem to find the leaks, cause there must be some huge shit leaking. Can anybody help me? I'll post an example of a trigger here. They all follow the same pattern.
 
Last edited:
Level 19
Joined
Oct 29, 2007
Messages
1,184
  • Grass
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • For each (Integer tmp_integer) from 1 to 4, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • detect_up[tmp_integer] Equal to 1
            • Then - Actions
              • Set tmp_loc2 = (Position of Player[tmp_integer])
              • Set tmp_loc = (tmp_loc2 offset by 800.00 towards (Facing of Player[tmp_integer]) degrees)
              • Custom script: call RemoveLocation(udg_tmp_loc2)
            • Else - Actions
              • Set tmp_loc = (Position of Player[tmp_integer])
          • Set tmp_group = (Units in (Region centered at tmp_loc with size (2000.00, 2000.00)) matching ((Unit-type of (Matching unit)) Equal to Grass))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in tmp_group) Less than 32
            • Then - Actions
              • Set tmp_loc2 = (Random point in (Region centered at tmp_loc with size (1000.00, 1000.00)))
              • Unit - Create 1 Grass for Player 5 (Yellow) at (Random point in (Region centered at tmp_loc2 with size (1000.00, 1000.00))) facing Default building facing degrees
              • Custom script: call RemoveLocation(udg_tmp_loc2)
              • Set tmp_real = (Random real number between 80.00 and 150.00)
              • Animation - Change (Last created unit)'s size to (tmp_real%, tmp_real%, tmp_real%) of its original size
            • Else - Actions
              • Do nothing
          • Custom script: call RemoveLocation(udg_tmp_loc)
          • Custom script: call DestroyGroup(udg_tmp_group)
Most of the triggers are like this.
 
Level 6
Joined
Aug 19, 2006
Messages
187
Set tmp_group = (Units in ("!>>>Region centered at tmp_loc<<<!" with size (2000.00, 2000.00)) matching ((Unit-type of (Matching unit)) Equal to Grass))


Set tmp_loc2 = (Random point in ("!>>>Region centered at tmp_loc<<<!" with size (1000.00, 1000.00)))


Unit - Create 1 Grass for Player 5 (Yellow) at (Random point in ("!>>>Region centered at tmp_loc2<<<!" with size (1000.00, 1000.00))) facing Default building facing degrees


ok you leak even 3 regions
 
This should work. You will need a new region variable called 'tmp_region'.
tmp_real is used to set the region size.

  • Grass
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Custom script: set udg_tmp_region = Rect ( 0, 0, 0, 0 )
      • For each (Integer tmp_integer) from 1 to 4, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • detect_up[tmp_integer] Equal to 1
            • Then - Actions
              • Set tmp_loc2 = (Position of Player[tmp_integer])
              • Set tmp_loc = (tmp_loc2 offset by 800.00 towards (Facing of Player[tmp_integer]) degrees)
              • Custom script: call RemoveLocation ( udg_tmp_loc2 )
            • Else - Actions
              • Set tmp_loc = (Position of Player[tmp_integer])
          • Set tmp_real = 2000.00
          • Custom script: call SetRect ( udg_tmp_region, GetLocationX(udg_tmp_loc) - (udg_tmp_real * 0.5), GetLocationY(udg_tmp_loc) - (udg_tmp_real * 0.5), GetLocationX(udg_tmp_loc) + (udg_tmp_real * 0.5), GetLocationY(udg_tmp_loc) + (udg_tmp_real * 0.5) )
          • Set tmp_group = (Units in tmp_region matching ((Unit-type of (Matching unit)) Equal to Grass))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in tmp_group) Less than 32
            • Then - Actions
              • Set tmp_real = 2000.00
              • Custom script: call SetRect ( udg_tmp_region, GetLocationX(udg_tmp_loc) - (udg_tmp_real * 0.5), GetLocationY(udg_tmp_loc) - (udg_tmp_real * 0.5), GetLocationX(udg_tmp_loc) + (udg_tmp_real * 0.5), GetLocationY(udg_tmp_loc) + (udg_tmp_real * 0.5) )
              • Set tmp_loc2 = (Random point in tmp_region)
              • Unit - Create 1 Grass for Player 5 (Yellow) at tmp_loc2 facing Default building facing degrees
              • Custom script: call RemoveLocation(udg_tmp_loc2)
              • Set tmp_real = (Random real number between 80.00 and 150.00)
              • Animation - Change (Last created unit)'s size to (tmp_real%, tmp_real%, tmp_real%) of its original size
            • Else - Actions
          • Custom script: call RemoveLocation ( udg_tmp_loc )
          • Custom script: call DestroyGroup ( udg_tmp_group )
      • Custom script: call RemoveRect ( udg_tmp_region )
 

peq

peq

Level 6
Joined
May 13, 2007
Messages
171
Besides the leaks there are some other hidden performance killers in your code.

a) picking units takes more time than most other actions. Avoid it when possible. If there are many other units beside grass in the rect try to run this the other way round by picking all units of a type and then check if they are in the region.
b) (Number of units in tmp_group) sounds harmless but everytime you run this function it will run a loop over all the units in that group.
 
Status
Not open for further replies.
Top