- Joined
- Dec 11, 2014
- Messages
- 2,004
This is vJASS but it is so simple that it can be recalled as a JASS thing.
I'm trying to learn index recycling, but I can't test it. Will this work correctly? What I'm trying to achieve is to when something is nulled, the index is added to a recycling list. On indexing (think of cast) it checks for the recycled index and if it exists, it uses the recycled index instead of creating a new one. My indexes start with 1.
What I'm creating is a walk/jump system.
On index:
Deindex:
I'm trying to learn index recycling, but I can't test it. Will this work correctly? What I'm trying to achieve is to when something is nulled, the index is added to a recycling list. On indexing (think of cast) it checks for the recycled index and if it exists, it uses the recycled index instead of creating a new one. My indexes start with 1.
What I'm creating is a walk/jump system.
On index:
JASS:
static method slide takes unit u, real height, real dur, location where returns nothing
local location l = GetUnitLoc(u)
local real ddur = dur / 2
local real dx = GetLocationX(where) - GetLocationX(l)
local real dy = GetLocationY(where) - GetLocationY(l)
if height > 0 then
if height != 0 then
if RecyclerMax > 0 then
set SlideUnit[Recycler[RecyclerMax]] = u
set SlideReal[Recycler[RecyclerMax]] = ddur
set RecyclerMax = RecyclerMax - 1
else
set SlideInt = SlideInt + 1
set SlideUnit[SlideInt] = u
set SlideReal[SlideInt] = ddur
endif
call SetUnitFlyHeight(u, height, height / ddur)
call TimerStart(CreateTimer(), ddur, false, function Cinema.goDown)
endif
set udg_Knockback2DAngle = bj_RADTODEG * Atan2(GetLocationY(where) - GetLocationY(l), GetLocationX(where) - GetLocationX(l))
//timed movement settings, using a knockback by bribe
set udg_Knockback2DTime = dur
set udg_Knockback2DDistance = SquareRoot(dx * dx + dy * dy)
set udg_Knockback2DUnit = u
set udg_Knockback2DCollision = -1.00
set udg_Knockback2DSimple = true
call TriggerExecute(gg_trg_Knockback_2D)
endif
call RemoveLocation(l)
endmethod
Deindex:
JASS:
private static method goDown takes nothing returns nothing
local integer i = 1
loop
exitwhen i > SlideInt
if SlideUnit[i] != null then
call SetUnitFlyHeight(SlideUnit[i], 0, (GetUnitFlyHeight(SlideUnit[i]) / SlideReal[SlideInt]))
set SlideUnit[i] = null
set SlideReal[i] = 0
set RecyclerMax = RecyclerMax + 1
set Recycler[RecyclerMax] = i
endif
set i = i + 1
endloop
endmethod