| 10-10-2006, 03:39 PM | #1 |
I made a spell that got plenty of leaks( noticed because it started freezing the game after about 30 casts, lagging like hell after about 15 ), so i ask for some help on cleaning it up, sp i also can learn something :p Heres the code: JASS:function Trig_AxeBoomerang_Conditions takes nothing returns boolean return GetSpellAbilityId() == 'A00B' endfunction function Trig_AxeBoomerang_MovingBack takes nothing returns nothing local timer tm=GetExpiredTimer() local unit array dummy local boolean array bool local unit caster=GetHandleUnit( tm, "caster" ) local real dist=GetHandleReal( tm, "dist" ) local location loc local location target local location casterloc=GetUnitLoc( caster ) local real angle set bool[0]=GetHandleBoolean( tm, "bool[0]" ) set bool[1]=GetHandleBoolean( tm, "bool[1]" ) set dummy[0]=GetHandleUnit( tm, "dummy[0]" ) set dummy[1]=GetHandleUnit( tm, "dummy[1]" ) call SetHandleReal( tm, "dist", dist+0.2 ) set loc=GetUnitLoc( dummy[0] ) set angle=AngleBetweenPoints( loc, casterloc ) set target=PolarProjectionBJ( loc, dist, angle ) call SetUnitPositionLoc( dummy[0], target ) if DistanceBetweenPoints( loc, casterloc )<=30 then call RemoveUnit( dummy[0] ) set bool[0]=true call SetHandleBoolean( tm, "bool[0]", bool[0] ) call RemoveLocation( loc ) call RemoveLocation( target ) set dummy[0]=null endif set loc=GetUnitLoc( dummy[1] ) set angle=AngleBetweenPoints( loc, casterloc ) set target=PolarProjectionBJ( loc, dist, angle ) call SetUnitPositionLoc( dummy[1], target ) if DistanceBetweenPoints( loc, casterloc )<=30 then call RemoveUnit( dummy[1] ) set bool[1]=true call SetHandleBoolean( tm, "bool[1]", bool[1] ) call RemoveLocation( loc ) call RemoveLocation( target ) set dummy[1]=null endif call RemoveLocation( casterloc ) if bool[1] and bool[2] then call FlushHandleLocals( tm ) call DestroyTimer( tm ) endif endfunction function Trig_AxeBoomerang_Moving takes nothing returns nothing local timer t=GetExpiredTimer() local timer tm local real array angle local unit array dummy local boolean array bool local unit caster=GetHandleUnit( t, "caster" ) local real dist=GetHandleReal( t, "dist" ) local location loc local location target set bool[0]=GetHandleBoolean( t, "bool[0]" ) set bool[1]=GetHandleBoolean( t, "bool[1]" ) set angle[0]=GetHandleReal( t, "angle[0]" ) set angle[1]=GetHandleReal( t, "angle[1]" ) set dummy[0]=GetHandleUnit( t, "dummy[0]" ) set dummy[1]=GetHandleUnit( t, "dummy[1]" ) set loc=GetUnitLoc( dummy[0] ) set target=PolarProjectionBJ( loc, dist, angle[0] ) call SetUnitPositionLoc( dummy[0], target ) call RemoveLocation( loc ) call RemoveLocation( target ) set loc=GetUnitLoc( dummy[1] ) set target=PolarProjectionBJ( loc, dist, angle[1] ) call SetUnitPositionLoc( dummy[1], target ) call RemoveLocation( loc ) call RemoveLocation( target ) call SetHandleReal( t, "angle[0]", angle[0]-0.5 ) call SetHandleReal( t, "angle[1]", angle[1]+0.5 ) call SetHandleReal( t, "dist", dist-0.2 ) if dist<=0 then call FlushHandleLocals( t ) call DestroyTimer( t ) set tm=CreateTimer() call TimerStart( tm, 0.02, true, function Trig_AxeBoomerang_MovingBack ) call SetHandleHandle( tm, "dummy[0]", dummy[0] ) call SetHandleHandle( tm, "dummy[1]", dummy[1] ) call SetHandleHandle( tm, "caster", caster ) call SetHandleReal( tm, "dist", dist ) call SetHandleBoolean( tm, "bool[0]", bool[0] ) call SetHandleBoolean( tm, "bool[1]", bool[1] ) endif set dummy[0]=null set dummy[1]=null endfunction function Trig_AxeBoomerang_Actions takes nothing returns nothing local timer t=CreateTimer() local unit caster=GetTriggerUnit() local unit array dummy local real array angle local real dist=20 local boolean array bool local location loca=GetUnitLoc( caster ) local location locb=GetSpellTargetLoc() set bool[0]=false set bool[1]=false set angle[0]=AngleBetweenPoints( loca, locb )+20 set angle[1]=AngleBetweenPoints( loca, locb )-20 set dummy[0]=CreateUnitAtLoc( GetOwningPlayer( caster ), 'h002', loca, angle[0] ) set dummy[1]=CreateUnitAtLoc( GetOwningPlayer( caster ), 'h002', loca, angle[1] ) call SetHandleHandle( t, "dummy[0]", dummy[0] ) call SetHandleHandle( t, "dummy[1]", dummy[1] ) call SetHandleBoolean( t, "bool[0]", bool[0] ) call SetHandleBoolean( t, "bool[1]", bool[1] ) call SetHandleHandle( t, "caster", caster ) call SetHandleReal( t, "angle[0]", angle[0] ) call SetHandleReal( t, "angle[1]", angle[1] ) call SetHandleReal( t, "dist", dist ) call TimerStart( t, 0.02, true, function Trig_AxeBoomerang_Moving ) call RemoveLocation( loca ) call RemoveLocation( locb ) set caster=null set dummy[0]=null set dummy[1]=null endfunction //=========================================================================== function InitTrig_AxeBoomerang takes nothing returns nothing set gg_trg_AxeBoomerang = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_AxeBoomerang, EVENT_PLAYER_UNIT_SPELL_CAST ) call TriggerAddCondition( gg_trg_AxeBoomerang, Condition( function Trig_AxeBoomerang_Conditions ) ) call TriggerAddAction( gg_trg_AxeBoomerang, function Trig_AxeBoomerang_Actions ) endfunction Help apreciated - Thanks |
| 10-10-2006, 03:47 PM | #2 |
Why in gods name do you create variables for values that you only use once. And arrays for two values at that? In your return function you will only remove your locs if the conditions for your if/then/elses are true, meaning they would leak. You also miss many handle nullings. Can't see too much other that that, add a debug message to check that your timers are being destroyed in the end etc. |
