#include "Timer.h"
Timer::Timer()
{
second_elapsed = 0;
second_from_1970 = 0;
timer_thread = new Thread<Timer>(this);
timer_thread->ThreadFunction = get_update;
//timer_thread-> = this;
time_shift = 1;
started = false;
}
Timer::~Timer()
{
timer_thread->Close();
delete timer_thread;
}
void Timer::restart()
{
second_from_1970 = time(NULL);
//second_elapsed = 0;
}
void Timer::start()
{
started = true;
second_from_1970 = time(NULL);
timer_thread->Create();
}
void Timer::stop()
{
timer_thread->Close();
}
int Timer::get_seconds()
{
return second_elapsed*time_shift;
}
float Timer::get_milliseconds()
{
#ifdef WIN32
GetSystemTime(&_time);
return _time.wMilliseconds+(second_elapsed*1000)*time_shift;
#endif
}
int Timer::delta_time(int t1,int t0)
{
return difftime(t1,t0);
}
int Timer::update()
{
while(timer_thread->is_running())
{
second_elapsed = time(NULL)-second_from_1970;
}
return 0;
}