• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Need help optimizing this

Status
Not open for further replies.
Level 20
Joined
Jun 27, 2011
Messages
1,864
It works fine but becomes laggy with excessive use.

  • Rocket Barrage
    • Events
      • Game - DamageEvent becomes Equal to 2.00
    • Conditions
      • (Unit-type of DamageEventSource) Equal to |cff778899War Machine|r (Rocket Barrage)
    • Actions
      • Set Temp_Point = (Position of DamageEventSource)
      • Set Temp_Point2 = (Position of DamageEventTarget)
      • For each (Integer A) from 1 to 3, do (Actions)
        • Loop - Actions
          • Unit - Create 1 Dummy Unit (RB) for (Owner of DamageEventSource) at Temp_Point facing (Facing of DamageEventSource) degrees
          • Unit - Add a 0.15 second Generic expiration timer to (Last created unit)
          • Set Temp_Point3[(Integer A)] = (Random point in (Region centered at Temp_Point2 with size ((Random real number between RocketBarrage_AreaWidth and RocketBarrage_AreaHeight), (Random real number between RocketBarrage_AreaWidth and RocketBarrage_AreaHeight))))
          • Unit - Order (Last created unit) to Attack Ground Temp_Point3[(Integer A)]
      • Custom script: call RemoveLocation( udg_Temp_Point3[1] )
      • Custom script: call RemoveLocation( udg_Temp_Point3[2] )
      • Custom script: call RemoveLocation( udg_Temp_Point3[3] )
      • Custom script: call RemoveLocation( udg_Temp_Point )
      • Custom script: call RemoveLocation( udg_Temp_Point2 )
I use Bribe's Damage Engine. RocketBarrage_AreaHeight and Width is both set to 200.00.
 
Reusing dummies would be a lot more efficient in the long run. I assume war machines can be attacked a decent amount of times. Making 3 dummy units for each damage event they take can add up really fast (linearly, but still pretty fast because of the 3). Wc3 isn't perfect when cleaning up memory from dummy units, so we try to avoid removing and killing dummies in favor of dummy recycling.

It is a bit annoying to implement for this trigger, but you would basically have a group of dummy unit (RB)'s. When you need them, move them to the appropriate spot and apply the orders. Remove them from the group for 0.15 sec (so they can do their attack), and then add them back to the group afterward so they can be reused for later triggers. If the group is empty, create a new dummy unit.

That is the general strategy. During burst moments, the number of dummy units may rise, but it is a pretty good algorithm in general. Definitely better than creating & removing them all the time. The units won't take up much performance as long as their hidden. If you need their death animations or whatever, try to use special effects instead.

Note: This won't optimize for performance. It is just for memory--if your map may be played for hours, these sorts of optimizations may make a difference.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Looks to me like you are leaking 3 rect objects (what GUI calls a "Region" but is not a JASS region object) every execution of the trigger.

  • Rocket Barrage
    • Events
      • Game - DamageEvent becomes Equal to 2.00
    • Conditions
      • (Unit-type of DamageEventSource) Equal to |cff778899War Machine|r (Rocket Barrage)
    • Actions
      • Set Temp_Point = (Position of DamageEventSource)
      • Set Temp_Point2 = (Position of DamageEventTarget)
      • For each (Integer A) from 1 to 3, do (Actions)
        • Loop - Actions
          • Unit - Create 1 Dummy Unit (RB) for (Owner of DamageEventSource) at Temp_Point facing (Facing of DamageEventSource) degrees
          • Unit - Add a 0.15 second Generic expiration timer to (Last created unit)
          • Set Temp_Rect = (Region centered at Temp_Point2 with size ((Random real number between RocketBarrage_AreaWidth and RocketBarrage_AreaHeight), (Random real number between RocketBarrage_AreaWidth and RocketBarrage_AreaHeight)))
          • Set Temp_Point3 = (Random point in (Temp_Rect))
          • Unit - Order (Last created unit) to Attack Ground Temp_Point3
          • Custom script: call RemoveLocation( udg_Temp_Point3 )
          • Custom script: call RemoveRect( udg_Temp_Rect )
      • Custom script: call RemoveLocation( udg_Temp_Point )
      • Custom script: call RemoveLocation( udg_Temp_Point2 )
Added temp rect variable called Temp_Rect (GUI type region). This is set to the rect before use so that reference to it is not lost.
Made Temp_Point3 not an array. There is no reason for it to be an array unless it needs to be one somewhere else.
In lined Temp_Point3 cleanup into the loop for less procedural coupling.
Added JASS statement to remove the rect objects after use inside the loop.

Should notice a massive improvement in performance over time as due to the nature of damage detection systems this was probably a pretty massive leak when using War Machines.
 
Status
Not open for further replies.
Top