- Joined
- Dec 9, 2008
- Messages
- 52
This bit of code runs fine for a minute and then the lag gets progressively worse. Without this trigger the game doesn't lag even after an hour. Any ideas? I realize I'm calling this function a lot and there's a logical mistake in it, but that doesn't affect the fact that it's leaking.
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)
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