• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Timer struct problems

Status
Not open for further replies.
Level 6
Joined
Jan 15, 2005
Messages
188
Hello,

I've got a very disfunctional timer struct. I would like to know how to optimize it so it works better. Currently, it returns the wrong information about half the time, and it's getting extremely buggy. I've talked to quite a few people, and for the most part they've said the struct is horrible. 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.

Code:
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.
 
Last edited:
Level 6
Joined
Jan 15, 2005
Messages
188
***bump***

I've updated to add what the exact problem is with it. This struct is really starting to get on my nerves, as every who's willing to look at it wont bother trying to explain anything about what's wrong with it. To me, it looks fine.
 
Status
Not open for further replies.
Top