osx_timer.cpp 1007 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "osx_timer.h"
  2. #include <api/timer/timerclient.h>
  3. timer_api *timerApi = NULL;
  4. TimerApi::TimerApi()
  5. {
  6. mainEventLoop = GetMainEventLoop();
  7. }
  8. static void WasabiTimerProc(EventLoopTimerRef inTimer, void * inUserData)
  9. {
  10. TimerClient *client = (TimerClient *)inUserData;
  11. if (client)
  12. client->timerclient_timerCallback(inTimer);
  13. }
  14. TimerToken TimerApi::timer_add(TimerClient *client, int id, int ms)
  15. {
  16. EventLoopTimerRef token;
  17. OSStatus err = InstallEventLoopTimer(mainEventLoop,
  18. (float)ms/1000.0f,
  19. (float)ms/1000.0f,
  20. WasabiTimerProc,
  21. client,
  22. &token);
  23. if (err == noErr)
  24. return token;
  25. else
  26. return 0;
  27. }
  28. void TimerApi::timer_remove(TimerClient *client, TimerToken token)
  29. {
  30. RemoveEventLoopTimer(token);
  31. }