Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
SecurityCam - Timer.cpp

Timer.cpp

Caricato da: Carlduke
Scarica il programma completo

  1. #include "Timer.h"
  2.  
  3. Timer::Timer()
  4. {
  5.         second_elapsed = 0;
  6.         second_from_1970 = 0;
  7.  
  8.         timer_thread = new Thread<Timer>(this);
  9.         timer_thread->ThreadFunction = get_update;
  10.        
  11.         //timer_thread-> = this;
  12.  
  13.         time_shift = 1;
  14.         started = false;
  15. }
  16.  
  17. Timer::~Timer()
  18. {
  19.         timer_thread->Close();
  20.     delete timer_thread;
  21. }
  22.  
  23. void Timer::restart()
  24. {
  25.         second_from_1970 = time(NULL);
  26.         //second_elapsed = 0;
  27. }
  28.  
  29. void Timer::start()
  30. {
  31.    started = true;
  32.    second_from_1970 = time(NULL);
  33.    timer_thread->Create();
  34. }
  35.  
  36. void Timer::stop()
  37. {
  38.         timer_thread->Close();
  39. }
  40.  
  41. int Timer::get_seconds()
  42. {
  43.     return second_elapsed*time_shift;
  44. }
  45.  
  46. float Timer::get_milliseconds()
  47. {
  48. #ifdef WIN32
  49.         GetSystemTime(&_time);
  50.         return _time.wMilliseconds+(second_elapsed*1000)*time_shift;
  51. #endif
  52.  
  53. }
  54.  
  55.  
  56. int Timer::delta_time(int t1,int t0)
  57. {
  58.         return difftime(t1,t0);
  59. }
  60.  
  61. int Timer::update()
  62. {
  63.         while(timer_thread->is_running())
  64.         {
  65.                 second_elapsed = time(NULL)-second_from_1970;
  66.         }
  67.  
  68.         return 0;
  69. }