vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

Hibrid TimerUtils

Guest · 878

0 Members and 2 Guests are viewing this topic.

Rating
Average Score
« Created: October 09, 2017, 12:02:55 AM by moyack »

Hibrid TimerUtils
on: December 20, 2014, 06:49:41 PM
Category: Execution, Variables
Language: vJASS

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
  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: December 19, 2017, 08:00:38 PM by moyack »



 

Power of Corruption - A Warcraft III altered melee map   Chaos Realm - The world of Game modders and wc3 addicts     WC3JASS.com - The JASS Vault   Jetcraft - A Starcraft II mod