Map Lag on Unit Death -- code poorly written/leaking ?

ZakkWylde-

New Member
Reaction score
14
So it appears that whenever someone dies, there is this annoying map lag from which everyone suffers.
Here is the relevant code:

This is the sliding/Terrain Kill trigger that determines a unit should die:
JASS:

cope Sliding initializer Init

private function SlidingCond takes nothing returns boolean
        return (GetUnitTypeId(GetFilterUnit()) == 'E000')
endfunction
    
private function Sliding takes nothing returns nothing
    
    local unit u
    
    local real x
    local real y
    local real uX
    local real uY 
    local real facing
    
    local integer terType
    local integer t1
    local integer t2
    local integer t3
    local integer t4
    
    local integer i
    
    local boolean d1
    local boolean d2
    local boolean d3
    local boolean d4
    
    local boolean shouldSlide
    local boolean properTerrain
    local boolean alive
    
    call GroupEnumUnitsInRect(dhGroup, worldBounds, Condition(function SlidingCond))
    
    loop
        set u = FirstOfGroup(dhGroup)
        exitwhen u == null
        set i = GetUnitUserData(u)
        set uX = GetUnitX(u)
        set uY = GetUnitY(u)
        
        set t1 = GetTerrainType(uX + tightness, uY + tightness)
        set t2 = GetTerrainType(uX + tightness, uY - tightness)
        set t3 = GetTerrainType(uX - tightness, uY + tightness)
        set t4 = GetTerrainType(uX - tightness, uY - tightness)
        
        set d1 = (t1 == udg_DeathTerSnow or t1 == udg_DeathTerLava)    
        set d2 = (t2 == udg_DeathTerSnow or t2 == udg_DeathTerLava)
        set d3 = (t3 == udg_DeathTerSnow or t3 == udg_DeathTerLava)
        set d4 = (t4 == udg_DeathTerSnow or t4 == udg_DeathTerLava)
        
        set alive = (GetWidgetLife(u) >= .405)
        if not (d1 and d2 and d3 and d4) then
        
            set terType = GetTerrainType(uX, uY)
            set properTerrain = (terType == slide1 or terType == slide2 or terType == slide3 or terType == slide4)
            set shouldSlide = (alive and IsUnitPaused(u) == false and properTerrain)
            
            if shouldSlide then
                set facing = (GetUnitFacing(u) * bj_DEGTORAD)
                call SetUnitPosition(u, uX + ((slideSpeed<i> * Cos(facing))* 3.125), uY + ((slideSpeed<i> * Sin(facing))* 3.125))
            endif
        else
            call IssueImmediateOrder(u, &quot;stop&quot;)
            if (TKInUse<i> == false and alive) then
                call TriggerExecute(udg_checkTerrain<i>)
            endif
        endif
        
        
        call GroupRemoveUnit(dhGroup, u)
    endloop

endfunction

private function Init takes nothing returns nothing
    call TimerStart(CreateTimer(), 0.03125, true, function Sliding) //frequency of trigger
endfunction
    
endscope
</i></i></i></i>


Regarding [ljass] if (TKInUse == false and alive) then
call TriggerExecute(udg_checkTerrain)
endif [/ljass],
TKInUse will be seen in the following code, and udg_checkTerrain IS the trigger with the following code (there are 12 checkTerrains, one for each hero):

JASS:

function RedTerrainKill takes nothing returns nothing
    local integer i = 0
    local unit u = udg_DemonHunter<i>
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local effect e
    local effect e2
    
    if GetTerrainType(x, y) == udg_DeathTerSnow and GetUnitState(u, UNIT_STATE_LIFE) &gt;= 1 then
        set TKInUse<i> = true
        call PauseUnit(u, true)
        set isUnitDying<i> = true
        call SetUnitFacing(u, GetUnitFacing(u))
        set e = AddSpecialEffect(frost1, x, y)
        set e2 = AddSpecialEffect(frost2, x, y)
        call DisableTrigger(udg_checkTerrain<i>)
        call TriggerSleepAction(2)
        call SetUnitExploded(u, false)
        if isUnitDying<i> == true then
            call KillUnit(u)
        endif
        call PauseUnit(u, false)
        set isUnitDying<i> = false
        call DestroyEffect(e)
        call DestroyEffect(e2)
        set e = null
        set e2 = null
        set TKInUse<i> = false
        call EnableTrigger(udg_checkTerrain<i>)
    elseif GetTerrainType(x,y) == udg_DeathTerLava and GetUnitState(u, UNIT_STATE_LIFE) &gt;= 1 then
        set TKInUse<i> = true
        call PauseUnit(u, true)
        set isUnitDying<i> = true
        call SetUnitFacing(u, GetUnitFacing(u))
        set e = AddSpecialEffect(fire1, x, y)
        call DisableTrigger(udg_checkTerrain<i>)
        call TriggerSleepAction(1.95)
        set e2 = AddSpecialEffect(fire2, x, y)
        call TriggerSleepAction(.05)
        call SetUnitExploded(u, false)
        if isUnitDying<i> == true then
            call KillUnit(u)
        endif
        call PauseUnit(u, false)
        set isUnitDying<i> = false
        call DestroyEffect(e)
        call DestroyEffect(e2)
        set e = null
        set e2 = null
        set TKInUse<i> = false
        call EnableTrigger(udg_checkTerrain<i>)
    endif
endfunction

//===========================================================================
function InitTrig_RedTerrainKill takes nothing returns nothing
    set gg_trg_RedTerrainKill = CreateTrigger(  )
    call TriggerAddAction( gg_trg_RedTerrainKill, function RedTerrainKill )
endfunction
</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>


If that weren't enough, this is what runs when the unit actually dies. (REALLY SORRY FOR ALL THIS CODE, but I'D REALLY APPRECIATE finding out what's wrong with it <3)
JASS:

function Trig_check_if_alive_Conditions takes nothing returns boolean

    local integer Id = GetPlayerId( GetOwningPlayer( GetTriggerUnit() ) )
    return Id != 12 and Id != 15

endfunction

function Trig_check_if_alive_Actions takes nothing returns nothing

    local integer n = GetUnitUserData( GetTriggerUnit() )
    local integer i = 0
    
    local item it=UnitItemInSlot(udg_DemonHunter[n],0)
    local integer d=GetItemUserData(it)

    call SetItemPosition(it, GetRectCenterX(itemsloc[d]), GetRectCenterY(itemsloc[d]))
    
    set udg_CircleOn[n] = false
    
    if udg_Teamwork then
        loop
        exitwhen i&gt;11 or GetUnitState(udg_DemonHunter<i>, UNIT_STATE_LIFE) &gt; 0
            set i = i + 1
        endloop
    else 
        loop
        exitwhen i&gt;11 or GetUnitState(udg_DemonHunter<i>, UNIT_STATE_LIFE) &gt; 0 or GetUnitState(reviveCircle<i>, UNIT_STATE_LIFE) &gt; 0
            set i = i + 1
        endloop

    endif
    
    if (i &lt;= 11) then
        if udg_Teamwork then
            call TriggerExecute(makecircle[n])
        else
            if GetUnitState(reviveCircle[n], UNIT_STATE_LIFE) &gt; 0 then
                call circlerevive(n)
            endif
        endif
    endif
    
    if ( i&gt;11 ) and IsTriggerEnabled(gg_trg_DeathRez) then
        call ForGroup(reviveCircles, function RemoveCircles)
        if not udg_Teamwork then
            set i = 0
            loop
            exitwhen i &gt; 11
                set madecircle<i> = false
                set i = i+1
            endloop
        endif
        call TriggerExecute( gg_trg_DeathRez )
    endif

    

endfunction

//===========================================================================
function InitTrig_CheckIfAlive takes nothing returns nothing
    set gg_trg_CheckIfAlive = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_CheckIfAlive, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_CheckIfAlive, Condition( function Trig_check_if_alive_Conditions ) )
    call TriggerAddAction( gg_trg_CheckIfAlive, function Trig_check_if_alive_Actions )
endfunction
</i></i></i></i>


LASTLY (thank you so much if you've gotten this far):
This is the makecircle function that is called when the unit has died (with Teamwork on):

JASS:

function MakeCircle takes integer n returns nothing
    local real offset=127-(2*tightness) //90
    local real checkoffset=20
    local real x=GetUnitX(udg_DemonHunter[n])
    local real y=GetUnitY(udg_DemonHunter[n])
    local real rx=x
    local real ry=y
    local boolean check=GetTerrainType(rx+checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry)!=deathTerrain and GetTerrainType(rx-checkoffset,ry)!=deathTerrain and GetTerrainType(rx,ry-checkoffset)!=deathTerrain and GetTerrainType(rx,ry+checkoffset)!=deathTerrain 
    if not(check)then
        set rx=x-offset
        set check=GetTerrainType(rx+checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry)!=deathTerrain and GetTerrainType(rx-checkoffset,ry)!=deathTerrain and GetTerrainType(rx,ry-checkoffset)!=deathTerrain and GetTerrainType(rx,ry+checkoffset)!=deathTerrain 
    endif
    if not(check)then
        set rx=x+offset
        set check=GetTerrainType(rx+checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry)!=deathTerrain and GetTerrainType(rx-checkoffset,ry)!=deathTerrain and GetTerrainType(rx,ry-checkoffset)!=deathTerrain and GetTerrainType(rx,ry+checkoffset)!=deathTerrain 
    endif
    if not(check)then
        set rx=x
        set ry=y-offset
        set check=GetTerrainType(rx+checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry)!=deathTerrain and GetTerrainType(rx-checkoffset,ry)!=deathTerrain and GetTerrainType(rx,ry-checkoffset)!=deathTerrain and GetTerrainType(rx,ry+checkoffset)!=deathTerrain 
    endif
    if not(check)then
        set rx=x
        set ry=y+offset
        set check=GetTerrainType(rx+checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry)!=deathTerrain and GetTerrainType(rx-checkoffset,ry)!=deathTerrain and GetTerrainType(rx,ry-checkoffset)!=deathTerrain and GetTerrainType(rx,ry+checkoffset)!=deathTerrain 
    endif
    if not(check)then
        set rx=x-offset
        set ry=y-offset
        set check=GetTerrainType(rx+checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry)!=deathTerrain and GetTerrainType(rx-checkoffset,ry)!=deathTerrain and GetTerrainType(rx,ry-checkoffset)!=deathTerrain and GetTerrainType(rx,ry+checkoffset)!=deathTerrain 
    endif
    if not(check)then
        set rx=x-offset
        set ry=y+offset
        set check=GetTerrainType(rx+checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry)!=deathTerrain and GetTerrainType(rx-checkoffset,ry)!=deathTerrain and GetTerrainType(rx,ry-checkoffset)!=deathTerrain and GetTerrainType(rx,ry+checkoffset)!=deathTerrain 
    endif
    if not(check)then
        set rx=x+offset
        set ry=y-offset
        set check=GetTerrainType(rx+checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry)!=deathTerrain and GetTerrainType(rx-checkoffset,ry)!=deathTerrain and GetTerrainType(rx,ry-checkoffset)!=deathTerrain and GetTerrainType(rx,ry+checkoffset)!=deathTerrain 
    endif
    if not(check)then
        set rx=x+offset
        set ry=y+offset
        set check=GetTerrainType(rx+checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry)!=deathTerrain and GetTerrainType(rx-checkoffset,ry)!=deathTerrain and GetTerrainType(rx,ry-checkoffset)!=deathTerrain and GetTerrainType(rx,ry+checkoffset)!=deathTerrain 
    endif
    //in case everything goes WRONGGGGgggggggg  I dont think the trigger ever goes past this part--it goes straight to call RemoveUnit(...)...
    if not (check) then
        set checkoffset = 0
        if not(check)then
            set rx=x-offset
            set check=GetTerrainType(rx+checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry)!=deathTerrain and GetTerrainType(rx-checkoffset,ry)!=deathTerrain and GetTerrainType(rx,ry-checkoffset)!=deathTerrain and GetTerrainType(rx,ry+checkoffset)!=deathTerrain 
        endif
        if not(check)then
            set rx=x+offset
            set check=GetTerrainType(rx+checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry)!=deathTerrain and GetTerrainType(rx-checkoffset,ry)!=deathTerrain and GetTerrainType(rx,ry-checkoffset)!=deathTerrain and GetTerrainType(rx,ry+checkoffset)!=deathTerrain 
        endif
        if not(check)then
            set rx=x
            set ry=y-offset
            set check=GetTerrainType(rx+checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry)!=deathTerrain and GetTerrainType(rx-checkoffset,ry)!=deathTerrain and GetTerrainType(rx,ry-checkoffset)!=deathTerrain and GetTerrainType(rx,ry+checkoffset)!=deathTerrain 
        endif
        if not(check)then
            set rx=x
            set ry=y+offset
            set check=GetTerrainType(rx+checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry)!=deathTerrain and GetTerrainType(rx-checkoffset,ry)!=deathTerrain and GetTerrainType(rx,ry-checkoffset)!=deathTerrain and GetTerrainType(rx,ry+checkoffset)!=deathTerrain 
        endif
        if not(check)then
            set rx=x-offset
            set ry=y-offset
            set check=GetTerrainType(rx+checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry)!=deathTerrain and GetTerrainType(rx-checkoffset,ry)!=deathTerrain and GetTerrainType(rx,ry-checkoffset)!=deathTerrain and GetTerrainType(rx,ry+checkoffset)!=deathTerrain 
        endif
        if not(check)then
            set rx=x-offset
            set ry=y+offset
            set check=GetTerrainType(rx+checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry)!=deathTerrain and GetTerrainType(rx-checkoffset,ry)!=deathTerrain and GetTerrainType(rx,ry-checkoffset)!=deathTerrain and GetTerrainType(rx,ry+checkoffset)!=deathTerrain 
        endif
        if not(check)then
            set rx=x+offset
            set ry=y-offset
            set check=GetTerrainType(rx+checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry)!=deathTerrain and GetTerrainType(rx-checkoffset,ry)!=deathTerrain and GetTerrainType(rx,ry-checkoffset)!=deathTerrain and GetTerrainType(rx,ry+checkoffset)!=deathTerrain 
        endif
        if not(check)then
            set rx=x+offset
            set ry=y+offset
            set check=GetTerrainType(rx+checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry+checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx-checkoffset,ry-checkoffset)!=deathTerrain and GetTerrainType(rx+checkoffset,ry)!=deathTerrain and GetTerrainType(rx-checkoffset,ry)!=deathTerrain and GetTerrainType(rx,ry-checkoffset)!=deathTerrain and GetTerrainType(rx,ry+checkoffset)!=deathTerrain 
        endif
        if not (check) then
        endif
    endif

    call RemoveUnit(reviveCircle[n])
    set reviveCircle[n]=CreateUnit(Player(n),&#039;h005&#039;,rx,ry,90)
    call TriggerRegisterUnitInRange(revivetrig[n],reviveCircle[n],80.00, null)
    call GroupAddUnit(reviveCircles,reviveCircle[n])
    call SetUnitPosition(udg_DemonHunter[n],rx,ry)
    call SetUnitAnimationByIndex(udg_DemonHunter[n],0)
    //call TriggerSleepAction(0.2)
    call TriggerSleepAction(0.001) //?
    
endfunction


I know this is a lot of code, but I have gone through it, and I don;t really understand why it would cause map lag...

Appreciate the help (A LOT!),
Zakk
 

Dirac

22710180
Reaction score
147
Obviously the lag comes from the MakeCircle function, you check so many values at the same time, i'm sure there's a way to avoid that. What's that TriggerSleepAction at the end of the code????
 

ZakkWylde-

New Member
Reaction score
14
hmmm, i'm not exactly sure. the person who gave it to me had TriggerSleepAction(.2), then I changed it to .001...
not even sure what a triggesleepaction does inside of a function declared in the map header (i.e. not in a trigger), to be honest.

if I popped in little trigger sleep actions between the checks, like .05 here .05 there, would that fix this problem?
is the rest of the code pretty solid?

EDIT: +rep for reading through my code and proposing the cause of problem :D
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top