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

[Solved] Trigger causes too much lag

Status
Not open for further replies.
Level 3
Joined
Sep 21, 2013
Messages
36
Hello, everyone.
So, I made 2 triggers.
First:
  • Map initialization
  • Unit - Create 1 Dummy TriggerUnit for Player 10 (Light Blue) at (Center of (Playable map area)) facing Default building facing degrees
  • Hero - Create Dust of Appearance and give it to (Last created unit)
  • Set ID__Unit = (Last created unit)
  • Set ID__Item = (Last created item)
Basically, it's a set up for the second trigger. It gives to the permanent dummy unit item Dust of Appearance with global AoE and infinite charges. I think this trigger is pretty OK.

Second:
  • Time - Every 0.10 seconds of game time
  • Hero - Order ID__Unit to use ID__Item
  • Set TempUnitGroup = (Units in (Playable map area) matching (((Matching unit) has buff True Sight ) Equal to True))
  • Set TempUnitGroup_2 = (Units in (Playable map area))
  • Unit Group - Pick every unit in TempUnitGroup_2 and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • ((Picked unit) has buff Invisibility) Equal to True
              • ((Picked unit) has buff Wind Walk) Equal to True
              • (Unit-type of (Picked unit)) Equal to Invisible Guy 1
              • (Unit-type of (Picked unit)) Equal to Invisible Guy 2
        • Then - Actions
          • Set InvisibleUnit = (Picked unit)
          • Set TempPoint = (Position of InvisibleUnit)
          • Set TempUnitGroup_3 = (Units within 700.00 of TempPoint matching (((Matching unit) is in TempUnitGroup) Equal to True))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in TempUnitGroup_3) Greater than 0
            • Then - Actions
              • If ((InvisibleUnit is A sapper) Equal to True) then do (Do nothing) else do (Unit - Add classification of A sapper to InvisibleUnit)
            • Else - Actions
              • Unit - Remove classification of A sapper from InvisibleUnit
        • Else - Actions
          • If (((Picked unit) is A sapper) Equal to True) then do (Unit - Remove classification of A sapper from (Picked unit)) else do (Do nothing)
  • Custom script: call RemoveLocation (udg_TempPoint)
  • Custom script: call DestroyGroup (udg_TempUnitGroup)
  • Custom script: call DestroyGroup (udg_TempUnitGroup_2)
  • Custom script: call DestroyGroup (udg_TempUnitGroup_3)
Second trigger fires Dust of Appearance every .1 sec which works on suicidal units only.
Every time unit with True Sight buff comes within 700 of invisible unit, invisible unit gets the classification of suicidal, Dust buff, and is revealed to the enemy.

2nd trigger works as intended, but it causes so much lags, map is unplayable. Please help me to fix lagging, thanks in advance :thumbs_up:

And sorry for my bad english.

UPD:
I've made a discovery. Lagging only occurs when there are many invisible (i.e. detectable) units.
Maybe I can improve trigger to fix it somehow?

testmap
 
Last edited:

Wrda

Spell Reviewer
Level 25
Joined
Nov 18, 2012
Messages
1,870
Is it supposed to use the item all the time?
You only need 2 groups. Delete group3

  • Set TempUnitGroup = (Units in (Playable map area))
  • Unit Group - Pick every unit in TempUnitGroup and do (Actions)
    • Loop Actions
      • Set InvisibleUnit = (Picked unit)
Should be like this.
 
Level 3
Joined
Sep 21, 2013
Messages
36
Here it is.
I've made a discovery. Lagging only occurs when there are many invisible (i.e. detectable) units.
Maybe I can improve trigger to fix it somehow?
 

Attachments

  • ID_by_RandomUser.w3x
    16.1 KB · Views: 130
Level 20
Joined
Aug 13, 2013
Messages
1,696
ID Main Loop in every 0.10 seconds must initially turn off, don't register some units in the map in every 0.10 seconds because that will loop into the playable map area - Unit Groups that will cause lags, you can register units in the map initialization then must not destroy that group because it is set only in the start of the game. You don't need temp_unitGroup2, use temp_unitGroup1 instead. You must destroy temp_unitGroups3 inside the loop because it will destroy only 1 temp_unitGroup3 into the 10 temp_unitGroup3. You must learn about efficiency of triggering and reading some tutorials in here will help you.
 
Level 3
Joined
Sep 21, 2013
Messages
36
Thanks, jakeZinc.
I made some changes, now it's leakless?
  • Time - Every 0.20 seconds of game time
  • Hero - Order ID__Unit to use ID__Item
  • Set TempUnitGroup_1 = (Units in (Playable map area))
  • Unit Group - Pick every unit in TempUnitGroup_1 and do (Actions)
    • Loop - Actions
      • Set InvisibleUnit = (Picked unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (InvisibleUnit has buff Invisibility) Equal to True
              • (InvisibleUnit has buff Wind Walk) Equal to True
              • (Unit-type of InvisibleUnit) Equal to Invisible Guy 1
              • (Unit-type of InvisibleUnit) Equal to Invisible Guy 2
        • Then - Actions
          • Set TempPoint = (Position of InvisibleUnit)
          • Set TempUnitGroup_2 = (Units within 700.00 of TempPoint matching (((Matching unit) has buff True Sight ) Equal to True))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in TempUnitGroup_2) Greater than 0
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (InvisibleUnit is A sapper) Equal to False
                • Then - Actions
                  • Unit - Add classification of A sapper to InvisibleUnit
                • Else - Actions
            • Else - Actions
              • Unit - Remove classification of A sapper from InvisibleUnit
          • Custom script: call RemoveLocation (udg_TempPoint)
          • Custom script: call DestroyGroup (udg_TempUnitGroup_2)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (InvisibleUnit is A sapper) Equal to True
            • Then - Actions
              • Unit - Remove classification of A sapper from InvisibleUnit
            • Else - Actions
  • Custom script: call DestroyGroup (udg_TempUnitGroup_1)
 
Last edited:
Level 3
Joined
Sep 21, 2013
Messages
36
Fxd. Thanks, Rheiko.
Now it's perfectly leakless? :xxd:
  • Time - Every 0.20 seconds of game time
  • Hero - Order ID__Unit to use ID__Item
  • Set TempUnitGroup_1 = (Units in (Playable map area))
  • Unit Group - Pick every unit in TempUnitGroup_1 and do (Actions)
    • Loop - Actions
      • Set InvisibleUnit = (Picked unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (InvisibleUnit has buff Invisibility) Equal to True
              • (InvisibleUnit has buff Wind Walk) Equal to True
              • (Unit-type of InvisibleUnit) Equal to Invisible Guy 1
              • (Unit-type of InvisibleUnit) Equal to Invisible Guy 2
        • Then - Actions
          • Set TempPoint = (Position of InvisibleUnit)
          • Set TempUnitGroup_2 = (Units within 700.00 of TempPoint matching (((Matching unit) has buff True Sight ) Equal to True))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in TempUnitGroup_2) Greater than 0
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (InvisibleUnit is A sapper) Equal to False
                • Then - Actions
                  • Unit - Add classification of A sapper to InvisibleUnit
                • Else - Actions
            • Else - Actions
              • Unit - Remove classification of A sapper from InvisibleUnit
          • Custom script: call RemoveLocation (udg_TempPoint)
          • Custom script: call DestroyGroup (udg_TempUnitGroup_2)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (InvisibleUnit is A sapper) Equal to True
            • Then - Actions
              • Unit - Remove classification of A sapper from InvisibleUnit
            • Else - Actions
  • Custom script: call DestroyGroup (udg_TempUnitGroup_1)
 
Level 3
Joined
Sep 21, 2013
Messages
36
I'll try it, thanks.

Sry for stupid question, deathismyfriend, but isn't units are automatically removed from unit groups after [Unit - Remove] function?
I don't use this function very often. It feels risky, lol.
Thanks in advance.
 
Level 13
Joined
Mar 24, 2013
Messages
1,105
I think what you're saying is do units get removed from unit groups when they are removed from the game. I believe the answer is no, it will reference a null unit, but it still thinks there is something in the group. When a unit dies or is removed from the game just remove triggering unit from your unit group.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
Pretty much as poke has said. They do not get removed from the group when using unit - remove unit. They also don't get removed when the unit dies. You have to do it manually. Also using unit - remove is fine. It is actually better as it refreshes the handle count immediately and removes the other data stored when that unit is created. However neither unit - remove or unit - kill removes the memory created by the unit. This is a bug that can not be fixed. You need a ton of units for this to matter though. Just use unit - remove whenever possible.
 
Level 3
Joined
Sep 21, 2013
Messages
36
Hello, everyone.
Sorry for bothering, but I need your help yet again.
I was very busy IRL for a few months and recently returned to my map.
I tested trigger again with this
JASS:
function HandleCount takes nothing returns nothing
    local location L = Location(0,0)
    call BJDebugMsg(I2S(GetHandleId(L)-0x100000))
    call RemoveLocation(L)
    set L = null
endfunction

//===========================================================================
function InitTrig_HandleCounter takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEvent(t,0.09,true)
    call TriggerAddAction(t,function HandleCount)
endfunction
and it seems like Destroy Group script is not working at all.

I had 100 invisible units in my map and every .10 seconds trigger leaked exactly for 100.
When I delete RemoveLocation custom script trigger leaks for 200 each .10 seconds. And when I delete DestroyGroup script nothing changes at all: still 100 leaks each .10

No matter what I do call DestroyGroup() in this trigger doesn't work.

Please help me fix this. Thanks in advance.
 
Level 3
Joined
Sep 21, 2013
Messages
36
It was in #9 post, but bump anyway :xxd::
  • Time - Every 0.20 seconds of game time
  • Hero - Order ID__Unit to use ID__Item
  • Set TempUnitGroup_1 = (Units in (Playable map area))
  • Unit Group - Pick every unit in TempUnitGroup_1 and do (Actions)
    • Loop - Actions
      • Set InvisibleUnit = (Picked unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (InvisibleUnit has buff Invisibility) Equal to True
              • (InvisibleUnit has buff Wind Walk) Equal to True
              • (Unit-type of InvisibleUnit) Equal to Invisible Guy 1
              • (Unit-type of InvisibleUnit) Equal to Invisible Guy 2
        • Then - Actions
          • Set TempPoint = (Position of InvisibleUnit)
          • Set TempUnitGroup_2 = (Units within 700.00 of TempPoint matching (((Matching unit) has buff True Sight ) Equal to True))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in TempUnitGroup_2) Greater than 0
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (InvisibleUnit is A sapper) Equal to False
                • Then - Actions
                  • Unit - Add classification of A sapper to InvisibleUnit
                • Else - Actions
            • Else - Actions
              • Unit - Remove classification of A sapper from InvisibleUnit
          • Custom script: call RemoveLocation (udg_TempPoint)
          • Custom script: call DestroyGroup (udg_TempUnitGroup_2)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (InvisibleUnit is A sapper) Equal to True
            • Then - Actions
              • Unit - Remove classification of A sapper from InvisibleUnit
            • Else - Actions
  • Custom script: call DestroyGroup (udg_TempUnitGroup_1)
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
That checks the handle ids. It will always go up when a new unit is placed. You never remove the units you add to the map. So you are adding 100 units every .1 seconds. Also adding 100 units every .1 seconds is a very bad idea as you will soon hit the memory limit for wc3 and the game will crash. Always look for ways on how to reduce the amount of units you add to the map. Example if you make a spell that needs a dummy unit to cast a spell on a unit, you normally only need one dummy unit for the whole map. You never remove that unit that way you never have to create a new unit to replace that old unit.

Units always leak even when you remove them from game (although a very small amount it adds up fast when creating tons of units)
 
Level 3
Joined
Sep 21, 2013
Messages
36
100 units every .1 seconds

But I didn't. Only thing that can possible leak in my trigger is unit groups. I don't think custom script for destroying them even works at all.
I didn't create any units, only points and unit groups. When I disable removeloc script trigger adds 200 hanldles(?) every .1, so the only things that can leak are unit groups.
 
Status
Not open for further replies.
Top