Friday, 2024-03-29, 9:50 AM


Main
Registration
Login
Welcome Guest | RSS  
[ New messages · Members · Forum rules · Search · RSS ]
  • Page 1 of 1
  • 1
Forum moderator: Hanky, Fireeye  
Clan NgO Forums » Discussions » Junk Yard » [vJASS] Timer Recycler + Data Attachement
[vJASS] Timer Recycler + Data Attachement
HankyDate: Wednesday, 2008-11-19, 9:45 PM | Message # 1
Lieutenant colonel
Group: Moderators
Messages: 116
Reputation: 9
Status: Offline
Hello, today I want to present another system. This you can use like the Costum Interface just that this is less constant then the other system. The costum interface is more useful for constant stuff like motions. This system is useful for everthing what is timed.

Pros:
- Good speed
- more useable as the Costum Interface
- easy to use

Need:
- "H2I" function

System Script

Code
library TimerRecycler
     globals
       private integer max              =0
       private integer cmax             =0
       private constant integer minIndex=0x100000
          
       private timer array rTimer
       private integer array orAtt
       private integer array data
       private boolean array inUse
     endglobals

     function GetNextTimer takes integer dat returns timer
       local integer index
       set cmax=cmax+1
       if max<cmax then
         set rTimer[cmax]=CreateTimer()
         set max         =cmax
       endif
       set index       =H2I(rTimer[cmax])-minIndex
       set orAtt[index]=cmax
       set inUse[index]=true
       set data[index] =dat
       return rTimer[cmax]
     endfunction
        
     function GetTimerData takes timer t returns integer
       local integer index=H2I(t)-minIndex
        
       if inUse[index] then
         return data[index]
       debug else
       debug call BJDebugMsg("Index error")
       endif
          
       return 0
     endfunction
        
     function RecycleTimer takes timer t returns nothing
       local integer index=H2I(t)-minIndex
       local integer indec
       if inUse[index] then
         set indec=H2I(rTimer[cmax])-minIndex
         call PauseTimer(t)
            
         set rTimer[orAtt[index]]=rTimer[cmax]
         set rTimer[cmax]        =t
            
         set orAtt[indec]        =orAtt[index]
         set inUse[indec]        =true
         set inUse[index]        =false
         set cmax=cmax-1
       endif
     endfunction
endlibrary

How to use?

There are three functions:

Code
1.) function GetNextTimer takes integer dat returns timer
2.) function RecycleTimer takes timer t returns nothing
3.) function GetTimerData takes timer t returns integer

1.) This function is like "CreateTimer". It create or find for you automaticly a timer handle so you can use it. In the parameter "integer dat" you can attach structs or single datas.

2.) This function is like "DestroyTimer". It will recycle the timer so that the timer will be reused by the next "GetNextTimer" call.

3.) With this function you get the attached data or struct.

If you want it more effective but less save then just use this modificated system:

Code
library TimerRecycler
     globals
       private integer max              =0
       private integer cmax             =0
       private constant integer minIndex=0x100000
          
       private timer array rTimer
       private integer array orAtt
       private integer array data
     endglobals

     function GetNextTimer takes integer dat returns timer
       local integer index
       set cmax=cmax+1
       if max<cmax then
         set rTimer[cmax]=CreateTimer()
         set max         =cmax
       endif
       set index       =H2I(rTimer[cmax])-minIndex
       set orAtt[index]=cmax
       set data[index] =dat
       return rTimer[cmax]
     endfunction
        
     function GetTimerData takes timer t returns integer
       return data[H2I(t)-minIndex]
     endfunction
        
     function RecycleTimer takes timer t returns nothing
       local integer index=H2I(t)-minIndex
       local integer indec
       set indec=H2I(rTimer[cmax])-minIndex
       call PauseTimer(t)
            
       set rTimer[orAtt[index]]=rTimer[cmax]
       set rTimer[cmax]        =t
            
       set orAtt[indec]        =orAtt[index]
       set cmax=cmax-1
     endfunction
endlibrary

I hope you enjoy it.



Made by Smoe reworked by GiR aka Darkt3mpl3r
 
Clan NgO Forums » Discussions » Junk Yard » [vJASS] Timer Recycler + Data Attachement
  • Page 1 of 1
  • 1
Search:

Clan NgO © 2024Powered by uCoz