Timer.lua 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. require "Polycode/EventDispatcher"
  2. class "Timer" (EventDispatcher)
  3. EVENT_TRIGGER = 0
  4. function Timer:Timer(...)
  5. if type(arg[1]) == "table" and count(arg) == 1 then
  6. if ""..arg[1]:class() == "EventDispatcher" then
  7. self.__ptr = arg[1].__ptr
  8. return
  9. end
  10. end
  11. for k,v in pairs(arg) do
  12. if type(v) == "table" then
  13. if v.__ptr ~= nil then
  14. arg[k] = v.__ptr
  15. end
  16. end
  17. end
  18. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  19. self.__ptr = Polycore.Timer(unpack(arg))
  20. Polycore.__ptr_lookup[self.__ptr] = self
  21. end
  22. end
  23. function Timer:Pause(paused)
  24. local retVal = Polycore.Timer_Pause(self.__ptr, paused)
  25. end
  26. function Timer:isPaused()
  27. local retVal = Polycore.Timer_isPaused(self.__ptr)
  28. return retVal
  29. end
  30. function Timer:getTicks()
  31. local retVal = Polycore.Timer_getTicks(self.__ptr)
  32. return retVal
  33. end
  34. function Timer:Update(ticks)
  35. local retVal = Polycore.Timer_Update(self.__ptr, ticks)
  36. end
  37. function Timer:Reset()
  38. local retVal = Polycore.Timer_Reset(self.__ptr)
  39. end
  40. function Timer:hasElapsed()
  41. local retVal = Polycore.Timer_hasElapsed(self.__ptr)
  42. return retVal
  43. end
  44. function Timer:getElapsedf()
  45. local retVal = Polycore.Timer_getElapsedf(self.__ptr)
  46. return retVal
  47. end
  48. function Timer:__delete()
  49. Polycore.__ptr_lookup[self.__ptr] = nil
  50. Polycore.delete_Timer(self.__ptr)
  51. end