Original Post
Hi, I am having some timings problems, I am using c++ and gdi. What I want to do is every 30 seconds have a powerup come up. Then when you use the powerup, then have it active for a certain amount of time. I don't know too much about timing, I've looked around google and saw some High Performance Timers, but I don't know how to use them. I am currently using the timeGetTime() function and then comparing start and end times. But I guess the way I was doing it is really messed up because its giving me weird numbers, now I put it in a thread and its doing the same thing. Here is my timer class. It inherits from my thread class that works fine. The timer_func() is what it call once it hits the interval. It seems to call the function even without hitting the interval.
UTimer::UTimer(void)
{
timer_func = def_timer_func;
m_bIsRunning = false;
interval = 0;
}
void UTimer::OnStart(void)
{
m_TempTimeStart = m_TimeStart = m_TimeEnd = timeGetTime();
m_Time = 0;
m_bIsRunning = true;
}
void UTimer::OnFinish(void)
{
m_bIsRunning = false;
}
DWORD UTimer::Run(LPVOID)
{
while(m_bIsRunning)
{
m_TimeEnd = timeGetTime();
m_Time += m_TimeEnd - m_TimeStart;
m_TempInterval += m_Time;
m_TimeStart = m_TimeEnd;
if(m_TempInterval >= interval)
{
m_TempInterval = 0;
timer_func();
}
}
return GetLastError();
}
double UTimer::GetTime(void)
{
return m_Time;
}