Warcraft III: MapsModelsSkinsIconsSpellsToolsTutorials
WC3 JASS: Code SnippetsJASS and vJASS Spells and SystemsJass Tutorials
Chat @Discord

Author Topic: TimerUtils  (Read 164 times)

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 984
  • WC3 Models: 53
  • WC3 Tutorials: 13
  • WC3 Tools: 10
  • WC3 Maps: 12
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 5
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
TimerUtils
« on: December 20, 2014, 06:49:41 PM »

Related Topics or Resources



by
Description

This small library allows to attach data structs into timers in an easy way, following the structure proposed by Vexorian, just for compatibility.

Requirements:

 - Microtable
 - Alloc

Actual Code

Code: jass  [Select]
  1. library TimerUtils requires Alloc, MicroTable
  2.  
  3. private struct data extends array
  4.     static key K // used to connect the data struct with the variable
  5.     static key D // used to link other data struct to the timer
  6.     timer t
  7.    
  8.     implement Alloc
  9.    
  10.     method destroy takes nothing returns nothing
  11.         call PauseTimer(.t)
  12.         call ClearData(.t, thistype.K)
  13.         call .deallocate()
  14.     endmethod
  15.    
  16.     static method create takes nothing returns thistype
  17.         local thistype this = thistype.allocate()
  18.         if this.t == null then
  19.             set this.t = CreateTimer()
  20.         endif
  21.         call StoreData(this.t, thistype.K, this)
  22.         return this
  23.     endmethod
  24.    
  25. endstruct
  26.  
  27. function NewTimer takes nothing returns timer
  28.     return data(data.create()).t
  29. endfunction
  30.  
  31. function ReleaseTimer takes timer t returns nothing
  32.     call data(GetData(t, data.K)).destroy()
  33. endfunction
  34.  
  35. function SetTimerData takes timer t, integer d returns nothing
  36.     call StoreData(t, data.D, d)
  37. endfunction
  38.  
  39. function GetTimerData takes timer t returns integer
  40.     return GetData(t, data.D)
  41. endfunction
  42.  
  43. endlibrary
« Last Edit: October 09, 2017, 12:01:53 AM by moyack »

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

 

Blizzard Modding Information Center Starcraft II Modding Information Center Wacraft III Modding Information Center WC3JASS.com - The JASS Vault Chronicles of Darkness - A Warcraft III mod Jetcraft - A Starcraft II mod Troll Smash - A Warcraft III Arena
  Mod DB - Change the Game Power of Corruption - A Warcraft III altered melee map Chaos Realm - The world of Game modders and wc3 addicts Follow us on Facebook!!