Skip to main content
gamedev.net
🔒 Locked

Timers

Started by TheShadow 2 replies 300+ views
Original Post
TheShadow
TheShadow
I am looking for a way to program a Timer class that i would just call it and give me the time elapsed since the last call... anybody give any hints? GetTickCount()?? i don''t know how to use any of those time stuff
Mecha Engineer (Making Real Humanoid Suits)
TheShadow
TheShadow
dont worry about it... i just made my own.
Mecha Engineer (Making Real Humanoid Suits)
H4ck3r
H4ck3r
Maybe it would be nice to share it with us, then (I don''t need it, tho). It''s very easy to make, with gettickcount and threads...
TheShadow
TheShadow

  
#ifndef TDTIMER_H //timer.h

#define TDTIMER_H

class CTimer {
public:
void Initialize(void);
unsigned long GetElapsedTime(void);

private:
unsigned long initTime;
unsigned long currentTime;
unsigned long lastCallTime;
unsigned long elapsedTime;
};

#endif




  
//timer.cpp

#include "timer.h"
#include "windows.h"



void CTimer::Initialize()
{
initTime = GetTickCount();
lastCallTime = initTime;
}
unsigned long CTimer::GetElapsedTime()
{
elapsedTime = GetTickCount() - lastCallTime;
return elapsedTime * 0.1; //Return in 100th of a second

}


Mecha Engineer (Making Real Humanoid Suits)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.