- Joined
- Apr 18, 2010
- Messages
- 102
Hi.. I made a simple dash ability that creates after images when the caster is moving.
however there seems to be a leak that I cannot solve...
If i comment out this part of code
however there seems to be a leak that I cannot solve...
JASS:
scope Dashv2
globals
private real FPS = 1. / 32.
private string ANIMATION = "SLEEP"
private real RANGE = 450
private real CASTTIME = 0.0
private real DURATION = 0.25
private string DASHSFX = "war3mapImported\\nitu.mdx"
private integer SPELLID = 'Adsh'
endglobals
private struct tempDat
unit caster
player owner
real angle
real casttime
real duration
real speed
group fadegroup
integer stage
static integer dindex = -1
static timer period = CreateTimer()
static thistype array data
method GetUnitModel takes unit u returns string
local integer ut = GetUnitTypeId(u)
local string s
if ut == 'Hemy' then
set s = "war3mapImported\\Emiya.mdl"
endif
return s
endmethod
method destroy takes nothing returns nothing
local unit u
loop
set u = FirstOfGroup(this.fadegroup)
exitwhen u == null
call DummyAddRecycleTimer(u, 6)
call DestroySFX(u)
call GroupRemoveUnit(this.fadegroup, u)
endloop
set u = null
set this.caster = null
set this.owner = null
call DestroyGroup(this.fadegroup)
set this.fadegroup = null
if dindex == -1 then
call PauseTimer(period)
endif
call this.deallocate()
endmethod
static method periodic takes nothing returns nothing
local tempDat this
local integer i = 0
local real x1
local real y1
local real x2
local real y2
local unit u
loop
exitwhen i>dindex
set this = data[i]
if this.stage == 1 then
if GetWidgetLife(this.caster) >= 0.405 then
if this.casttime > 0 then
set this.casttime = this.casttime - FPS
else
set this.stage = 2
set x1 = GetUnitX(this.caster)
set y1 = GetUnitY(this.caster)
set u = GetRecycledDummy(x1,y1,0, Rad2Deg (this.angle) ) //uses DummyRecycler by flux
call DestroyEffect( AddSpecialEffectTarget( DASHSFX , u, "origin") )
call DummyAddRecycleTimer(u, 0.7)
endif
else
set this.stage = 0
endif
else
if this.stage == 2 then
if this.duration>0 then
set this.duration = this.duration - FPS
set x1 = GetUnitX(this.caster)
set y1 = GetUnitY(this.caster)
set x2 = x1 + this.speed*Cos(this.angle)
set y2 = y1 + this.speed*Sin(this.angle)
if IsTerrainWalkable(x2, y2) == true then
call SetUnitX(this.caster, x2)
call SetUnitY(this.caster, y2)
endif
set u = FirstOfGroup(this.fadegroup)
call GroupRemoveUnit(this.fadegroup, u)
call SetUnitVertexColor(u, 100, 100, 100, 50)
call SetUnitX(u, x1)
call SetUnitY(u, y2)
call FadeSFXTimed( u, 0.3)
call DummyAddRecycleTimer(u, 0.3 + 6.0)
else
set this.stage = 0
endif
endif
endif
if this.stage == 0 then
call PauseUnit(this.caster, false)
call SetUnitAnimation(this.caster, "stand")
call KB_DoneCasting(this.caster)
set data[i] = data[dindex]
set i = i - 1
set dindex = dindex - 1
call this.destroy()
endif
//increase i
set i = i + 1
set u = null
endloop
endmethod
static method onCast takes nothing returns nothing
local tempDat this
local integer looper
local unit u
local string sfx
local integer id
local real x
local real y
local real z
set this = thistype.allocate()
set this.caster = GetTriggerUnit()
set this.speed = RANGE / (DURATION/FPS)
set this.owner = GetOwningPlayer(this.caster)
set this.angle = moveangle[GetConvertedPlayerId(this.owner)]
set this.stage = 1
set this.casttime = CASTTIME
set this.duration = DURATION
set this.fadegroup = CreateGroup()
call PauseUnit(this.caster, true)
call IssueImmediateOrder(this.caster, "stop")
call SetUnitAnimation(this.caster, ANIMATION)
call KB_Casting(this.caster)
set x = GetUnitX(this.caster)
set y = GetUnitY(this.caster)
set z = GetUnitFlyHeight(this.caster)
set sfx = GetUnitModel(this.caster)
set looper = R2I( this.duration / FPS )
loop
exitwhen looper<1
set u = GetRecycledDummy(x, y, z, Rad2Deg(this.angle) )
call CreateSFX( u, sfx, "")
set id = GetUnitUserData(u)
call BlzPlaySpecialEffect( SFXhead[id], ANIM_TYPE_SLEEP)
call GroupAddUnit( this.fadegroup, u)
call SetUnitVertexColor(u, 0, 0, 0, 0)
set looper = looper - 1
endloop
set u = null
set sfx = ""
set dindex = dindex + 1
set data[dindex] = this
if dindex == 0 then
call TimerStart(period, FPS, true, function thistype.periodic)
endif
endmethod
static method onInit takes nothing returns nothing
call RegisterSpellEffectEvent('Adsh', function thistype.onCast)
endmethod
endstruct
endscope
If i comment out this part of code
- set u = FirstOfGroup(this.fadegroup)