• 🏆 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!

Performance question regarding periodic triggers

Status
Not open for further replies.

Vunjo

Hosted Project: SC
Level 14
Joined
Jul 1, 2010
Messages
1,340
So while I was working on a PvP Arena map, I thought of multiple ways to code the same spell in Trigger Editor.

The spell is basically periodic Healing while a unit has a specific buff. Now in my case, there's only 1 Hero with a spell that applies this buff, and it only applies to himself, meaning no other unit type in the game can ever get this buff. At the same time, there are up to 4 players in the game, and each of them can control only 1 Hero at a time, while there can easily be 20 units on the map at a time. Because of this I was asking myself what would be the most optimized way to code a spell?

So I figured a couple of possibilities

1) Running For function, even though most of the times only 1 out of 4 players will have the buff, and even that 1 player does not have it permanently.

  • Periodic
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 4, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Hero[(Integer A)] has buff Rejuvenation) Equal to True
            • Then - Actions
              • Unit - Set life of Hero[(Integer A)] to ((Life of Hero[(Integer A)]) + 5.00)
            • Else - Actions
2) Picking units matching unit has the buff. This is actually my primary question. Is there a difference in picking units matching conditions, and picking all units and then checking for conditions? Does Warcraft engine in the first example still pick through all units and then select only those with buffs for the purposes of the trigger, meaning that it still runs kind of slow given the number of units it has to go through?

  • Periodic 2
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) has buff Rejuvenation) Equal to True
            • Then - Actions
              • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + 5.00)
            • Else - Actions
OR

  • Periodic 3
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area) matching (((Matching unit) has buff Rejuvenation) Equal to True)) and do (Actions)
        • Loop - Actions
          • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + 5.00)
To conclude. I have 2 questions. Are the triggers Periodic 2 and Periodic 3 equally optimized? If not, is it better to use the first trigger in my case then?

Thanks in advance.
 

Vunjo

Hosted Project: SC
Level 14
Joined
Jul 1, 2010
Messages
1,340
groups are literally "pick everything, drop the units out of range/condition, return". in case if you know who to check, use direct access. you should only use groups in case if buffs can be achieved by anything and you can't/dont wanna track it

So the first trigger is more efficient in my case, while second and third are exactly the same?
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
Do note that what Draco wrote is true only for the case when you are creating new group.

The "Set myGroup = (Units in ...)" and "Pick every unit *in something that is not a unit group*..." actions are creating unit group (in your case, trigger 2 and trigger 3 also leak those unit group!).

However if you create the group only once, and reuse that one group, then it is not slower at all.
E.g.
  • Map Ini
  • ..code..
  • Set myGroup = (Unit within 500.00 of ...) //we create a unit gorup only once at map ini
  • Periodic 2
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in myGroup) and do (Actions) //we pick all units of the group we created at map ini
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) has buff Rejuvenation) Equal to True
            • Then - Actions
              • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + 5.00)
            • Else - Actions
In this case the group does not leak, nor is it slower than array, because you reuse that one group.
 
Status
Not open for further replies.
Top