Thursday, April 19, 2012

Can't find the leak

Hi guys,

I need some help finding what leaks in this code. If this code is enabled, the game gets unbearably jerky after about 3 minutes. If the code is disabled, things are fine.

I understand I'm calling this trigger every 20ms, but if that were exclusively causing the lag, the lag would start the moment the trigger starts. Also, setting the location to null after I've removed it doesn't delay the onset of lag, so I don't think that's a way to stop any leaks.

In return I'll go answer whatever questions I can in some other threads.

Thanks


Code:
function checkheight takes nothing returns nothing
local real last_x = LoadReal(udg_hash,GetHandleId(GetEnumUnit()),StringHash("last_x"))
local real last_y = LoadReal(udg_hash,GetHandleId(GetEnumUnit()),StringHash("last_y"))
local real last_z = LoadReal(udg_hash,GetHandleId(GetEnumUnit()),StringHash("last_z"))
local location l = GetUnitLoc(GetEnumUnit())
local real x = GetLocationX(l)
local real y = GetLocationY(l)
local real z = GetLocationZ(l)
local real distance = SquareRoot((x-last_x) * (x-last_x) + (y-last_y) * (y-last_y))
local real height = z - last_z
local real slope = AtanBJ(height/distance)
if slope > 60 then
call SetUnitPosition(GetEnumUnit(),last_x,last_y)
else
call SaveReal(udg_hash,GetHandleId(GetEnumUnit()),StringHash("last_x"),x)
call SaveReal(udg_hash,GetHandleId(GetEnumUnit()),StringHash("last_y"),y)
call SaveReal(udg_hash,GetHandleId(GetEnumUnit()),StringHash("last_z"),z)
endif
call RemoveLocation(l)
//set l = null
endfunction

function Trig_pumpheight_Actions takes nothing returns nothing
call ForGroup(udg_allunits, function checkheight)
endfunction

//===========================================================================
function InitTrig_pumpheight takes nothing returns nothing
set gg_trg_pumpheight = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_pumpheight, 0.02 )
call TriggerAddAction( gg_trg_pumpheight, function Trig_pumpheight_Actions )
endfunction

No comments:

Post a Comment