HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Insane Massive Lag

04-18-2006, 04:15 PM#1
Thunder_Eye
hi all, this trigger "freezes" the game, the reason I say "freeze" is that it just causes and massive lag the moment it is fired. If i change the 0.20 to something like 2.00 it will just lag very hard every 2 second and then after maybe 8 seconds the game will freeze. The problem is the loop, If I remove it the trigger works fine. But if I dont want to make a singleplayer map I will need it :/

Any idea on how to optimize it? (I know about the PolarProjectionBJ but I'm too lazy to fix it. Hope I can do something else to fix the lag)

Collapse JASS:
function Trig_TurnLeft_Copy_Actions takes nothing returns nothing
    local integer i = 1
    local unit u
    local location l
    local location k
    loop
        exitwhen i == 8
        set u = udg_Playerhero[i]
        if udg_Forward[i] == true then
            if (udg_Left[i] == true) and (udg_Right[i] == false) then
                set k = GetUnitLoc(u)
                set l = PolarProjectionBJ(k, 100.00, ( GetUnitFacing(udg_Playerhero[i]) + 5.00 ))
                call IssuePointOrderLoc( udg_Playerhero[i], "move", l )
            elseif (udg_Left[i] == false) and (udg_Right[i] == true) then
                set k = GetUnitLoc(u)
                set l = PolarProjectionBJ(k, 100.00, ( GetUnitFacing(udg_Playerhero[i]) - 5.00 ))
                call IssuePointOrderLoc( udg_Playerhero[i], "move", l )
            else
                set k = GetUnitLoc(u)
                set l = PolarProjectionBJ(k, 100.00, ( GetUnitFacing(udg_Playerhero[i]) ))
                call IssuePointOrderLoc( udg_Playerhero[i], "move", l )
                
            endif
        endif
    call RemoveLocation(l)
    call RemoveLocation(k)
    endloop
    set l = null
    set k = null
    set u = null
    set i = 0
endfunction

//===========================================================================
function InitTrig_TurnLeft_Copy takes nothing returns nothing
    set gg_trg_TurnLeft_Copy = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_TurnLeft_Copy, 2.00 )
    call TriggerAddAction( gg_trg_TurnLeft_Copy, function Trig_TurnLeft_Copy_Actions )
endfunction
04-18-2006, 04:30 PM#2
iNfraNe
You forgot set i = i + 1
04-18-2006, 04:43 PM#3
Thunder_Eye
hehe, thank you;P

I assume the reason the loop stopped anyway was because of the "preventinfiniteloop" warcraft has.

EDIT: onto next problem. the map begins to lag pretty massivly after sometime, probably because of a leak in this trigger. Can someone see any?
04-18-2006, 05:57 PM#4
iNfraNe
Quote:
Originally Posted by Thunder_Eye
hehe, thank you;P

I assume the reason the loop stopped anyway was because of the "preventinfiniteloop" warcraft has.
yep
Quote:
Originally Posted by Thunder_Eye
EDIT: onto next problem. the map begins to lag pretty massivly after sometime, probably because of a leak in this trigger. Can someone see any?
Cant seem to spot any, are you sure its in this trigger?
04-18-2006, 07:18 PM#5
Thunder_Eye
It's either that trigger or this one
Collapse JASS:
function Trig_Timer_Copy_Func001Func001002003 takes nothing returns boolean
    return ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetEnumUnit())) == true )
endfunction

function Trig_Timer_Copy_Func001Func004C takes unit u returns boolean
    if ( not ( u == null ) ) then
        return false
    endif
    return true
endfunction

function Trig_Timer_Copy_Actions2 takes unit u returns nothing
    local effect e = AddSpecialEffectTarget("Objects\\Spawnmodels\\Human\\FragmentationShards\\FragBoomSpawn.mdl", u, "overhead")
    call KillUnit(u)
    call TriggerSleepAction(1.50)
    call RemoveUnit(u)
    call DestroyEffect(e)
    set e = null
endfunction

function Trig_Timer_Copy_Func001A takes nothing returns nothing
    local unit pick = GetEnumUnit()
    local group targets = GetUnitsInRangeOfLocMatching(20.00, GetUnitLoc(pick), Condition(function Trig_Timer_Copy_Func001Func001002003))
    local unit target = GroupPickRandomUnit(targets)
    local location arrowpoint
    if ( Trig_Timer_Copy_Func001Func004C(target) ) then
        set arrowpoint = PolarProjectionBJ(GetUnitLoc(pick), 2.50, GetUnitFacing(pick))
        call SetUnitPositionLoc( pick, arrowpoint )
        call RemoveLocation(arrowpoint)
        call GroupClear( targets )
    else
        call UnitDamageTarget(pick, target, 300.00, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL, WEAPON_TYPE_WHOKNOWS)
        call Trig_Timer_Copy_Actions2(pick)
        call GroupRemoveUnit( udg_Arrows, pick )
    endif
    call DestroyGroup(targets)
    set pick = null
    set arrowpoint = null
    set targets = null
    set target = null  
endfunction

function Trig_Timer_Copy_Actions takes nothing returns nothing
    call ForGroupBJ( udg_Arrows, function Trig_Timer_Copy_Func001A )
    call SetCameraFieldForPlayer( Player(0), CAMERA_FIELD_ROTATION, GetUnitFacing(gg_unit_h000_0000), 0 )
endfunction

//===========================================================================
function InitTrig_Timer_Copy takes nothing returns nothing
    set gg_trg_Timer_Copy = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Timer_Copy, 0.01 )
    call TriggerAddAction( gg_trg_Timer_Copy, function Trig_Timer_Copy_Actions )
endfunction

(Probably this one)

EDIT: Yeah I think its this one.
EDIT2: Ok I tried changing the timer to 0.05(0.1 looked to ugly) and distance to 10. It works pretty ok but It looks a bit wierd(not very wierd)

Just wondering if there is any "prettier" way
EDIT3: Just noticed that the 30sec ingame lag still exists. So there is probably some leaks or something?
04-18-2006, 07:46 PM#6
blu_da_noob
Collapse JASS:
        set arrowpoint = PolarProjectionBJ(GetUnitLoc(pick), 2.50, GetUnitFacing(pick))

You are leaking on the GetUnitLoc(pick) there.

Edit: Same here:
Collapse JASS:
    local group targets = GetUnitsInRangeOfLocMatching(20.00, GetUnitLoc(pick), Condition(function Trig_Timer_Copy_Func001Func001002003))
04-18-2006, 07:49 PM#7
Thunder_Eye
Yeah Ive noticed those, just forgot to change the ones in the post ;P
A side note: The game goes from no-lag to massive-lag in just a second.

EDIT: just a thought, if I change the
Collapse JASS:
    if ( Trig_Timer_Copy_Func001Func004C(target) ) then
to
Collapse JASS:
    if ( not ( target == null ) ) then

would that make the trigger better as then it doesnt have to call an extra function?
04-18-2006, 08:22 PM#8
blu_da_noob
That function is checking if targett == null, not the opposite. Also, 'inlining' it would improve efficiency, but not by much.

Also, how many units are in the udg_Arrows group? Moving too many units (especially on a 0.01 timer) can easily cause lag, especially when not using SetUnitX/Y.
04-18-2006, 11:19 PM#9
illlusion
Quote:
Originally Posted by Thunder_Eye
hehe, thank you;P

I assume the reason the loop stopped anyway was because of the "preventinfiniteloop" warcraft has.

My friend once made a test to show that it's really not the limitation of max loop, but the limitation of max code line in single trigger.
04-21-2006, 01:27 PM#10
Thunder_Eye
Quote:
Originally Posted by blu_da_noob
Also, how many units are in the udg_Arrows group? Moving too many units (especially on a 0.01 timer) can easily cause lag, especially when not using SetUnitX/Y.

Yes It lags if there are to many arrows in the game, but even If it isn't it starts to lag after like 30sec.