Dirac
22710180
- Reaction score
- 147
Hello, i coded this system that allows you to get the position of a unit seconds ago, it's supposed to be very accurate. But it drops the FPS roughly. Is there a way to prevent the FPS drop?
EDIT: forgot to mention, it has a 5 second maximum storage per unit, and only indexes units that belong to player 9
Also, how do i see the FPS ingame? i only can tell by how slow the game flows
EDIT: forgot to mention, it has a 5 second maximum storage per unit, and only indexes units that belong to player 9
JASS:
library UnitHistory uses TimerUtils,AIDS
private struct UH extends array
private static method AIDS_filter takes unit u returns boolean
return GetOwningPlayer(u)==Player(8)
endmethod
hashtable x
hashtable y
timer t
private static method periodic takes nothing returns nothing
local integer i=50
local thistype this=GetTimerData(GetExpiredTimer())
loop
exitwhen i<1
call SaveReal(.x,GetUnitIndex(.unit),i,LoadReal(.x,GetUnitIndex(.unit),i-1))
call SaveReal(.y,GetUnitIndex(.unit),i,LoadReal(.y,GetUnitIndex(.unit),i-1))
set i=i-1
endloop
call SaveReal(.x,GetUnitIndex(.unit),0,GetUnitX(.unit))
call SaveReal(.y,GetUnitIndex(.unit),0,GetUnitY(.unit))
endmethod
private method AIDS_onCreate takes nothing returns nothing
local integer i=50
local real x=GetUnitX(.unit)
local real y=GetUnitY(.unit)
set .t=NewTimer()
set .x=InitHashtable()
set .y=InitHashtable()
call SetTimerData(.t,this)
call TimerStart(.t,0.1,true,function thistype.periodic)
loop
exitwhen i<0
call SaveReal(.x,GetUnitIndex(.unit),i,x)
call SaveReal(.y,GetUnitIndex(.unit),i,y)
set i=i-1
endloop
endmethod
private method AIDS_onDestroy takes nothing returns nothing
call ReleaseTimer(.t)
call FlushParentHashtable(.x)
call FlushParentHashtable(.y)
endmethod
//! runtextmacro AIDS()
endstruct
function GetXSecondsAgo takes unit whichUnit,real seconds returns real
return LoadReal(UH[whichUnit].x,GetUnitIndex(whichUnit),R2I(seconds*10))
endfunction
function GetYSecondsAgo takes unit whichUnit,real seconds returns real
return LoadReal(UH[whichUnit].y,GetUnitIndex(whichUnit),R2I(seconds*10))
endfunction
endlibrary
Also, how do i see the FPS ingame? i only can tell by how slow the game flows