| 05-09-2008, 11:46 PM | #1 |
Hello, I've got a very disfunctional timer struct. I would like to know how to optimize it so it works better. The problem is that it sometimes does not return the correct information, leading to bugs like spells not activating and such. If anyone could either re-write it or something to aid me in the fixing of this timer struct, I'd greatly appreciate it and +rep. JASS:struct TimerStruct timer this //The timer boolean isFree //To know when the timer is being used or not unit caster player owner PlayerStruct ownerStruct integer cyclesLeft unit target real damage integer buff boolean miscBool integer miscInt real miscReal string miscString string miscString2 string func //Stuff for holding values to be destroyed, or periodic locations etc. effect e real x real y location loc endstruct function TS2I takes TimerStruct ts returns integer return ts endfunction function I2TS takes integer i returns TimerStruct return i endfunction globals timer array TimerList //Note: TimerList[0] = null, or maybe a special game time trigger integer TimerListTop=0 integer TimerListPreviousIndex=1 constant integer TimerStartNum = 45 endglobals //=========================================================================== //Set and Get Timer Struct function SetTimerStruct takes timer t, TimerStruct s returns nothing if( TS2I(s) == 0 ) then call CleanAttachedVars( t ) else call AttachInt( t, "struct", s ) endif endfunction function GetTimerStruct takes timer t returns TimerStruct return GetAttachedInt( t, "struct" ) endfunction function TimerHasStruct takes timer t returns boolean if( GetAttachedInt(t,"struct") == 0 ) then return false endif return true endfunction function DestroyTimerStruct takes timer t returns nothing local TimerStruct ts = GetTimerStruct( t ) set ts.this = null set ts.isFree = true call SetTimerStruct( t, 0 ) endfunction //=========================================================================== //Init Timer List function TimerCreate takes nothing returns timer local TimerStruct ts set TimerListTop = TimerListTop + 1 set TimerList[TimerListTop] = CreateTimer() call TriggerRegisterTimerExpireEventBJ( gg_trg_SpellLibAndTimerLibrary, TimerList[TimerListTop] ) set ts = I2TS( TimerListTop ) call SetTimerStruct( TimerList[TimerListTop], ts ) set ts.this = TimerList[TimerListTop] set ts.isFree = true return TimerList[TimerListTop] endfunction function InitTimerList takes nothing returns nothing loop call TimerCreate() exitwhen TimerListTop > TimerStartNum endloop endfunction //=========================================================================== //Get and Return Timer function GetTimer takes nothing returns timer local integer index = TimerListPreviousIndex + 1 local TimerStruct ts loop set ts = I2TS( index ) if( index > TimerListTop ) then set index = 1 elseif( ts.isFree ) then set TimerListPreviousIndex = index set ts.isFree = false return ts.this elseif( index == TimerListPreviousIndex ) then set TimerListPreviousIndex = TimerListTop return TimerCreate() else set index = index + 1 endif endloop return null //Will never get here endfunction function GetInitiatedTimer takes boolean periodic, real time returns timer return StartTimerBJ( GetTimer(), periodic, time ) endfunction function ReturnTimer takes timer t returns nothing local TimerStruct ts = GetTimerStruct( t ) call PauseTimer( t ) set ts.isFree = true // call DestroyTimerStruct( t ) // if( udg_TimerStackTop < 8190 ) then // set udg_TimerStackTop = udg_TimerStackTop + 1 // set udg_TimerStack[udg_TimerStackTop] = t // else // call DestroyTimer( t ) // endif endfunction Thanks for your time, if you decide to help. |
