How do I make and use a timer correctly?

Started by
0 comments, last by Adaline 12 years, 8 months ago
Hello, I am currently working on a Pacman remake (purely 2D, my first game btw so its more a try to learn some program skills than to create something fun).
So now I am having the problem that the game runs with different speed on different computers and since I have read that there are different timers out there I would like to know what are the best ones (I am programming under Windows but I would like to have the opportunity to easily port the game to Linux or even portable devices).

But I also need help with the principle of a timer. I know it measures (or returns) the time that has passed since the last call (or do only certain timers do that?) but what do I have to do with that information now?


For my game I would like to have a constant game speed of 60fps so I think I know what I have to do with a PC that is too fast - after he is done with the update, drawing etc functions of the game, he has to wait a certain time (what would that be if I want 60fps?) until he repeats them so I simply put him on wait until that time has passed.

But what do I have to do with a PC that is not so fast? For example a really slow PC that makes only 10 fps (or more drastically 0.1fps), what is that PC supposed to do to keep up with the game speed?

Thanks in advance :)
Advertisement
Hello

I give you my class that implements a timer :


class Chrono
{
protected:
double t;

double getTime()
{
__int64 count,freq;
QueryPerformanceCounter((LARGE_INTEGER *)&count);
QueryPerformanceFrequency((LARGE_INTEGER *)&freq);
return double(count)/double(freq);
}

public:
Chrono(void)
{
reset();
}

void reset(double time=0.0)
{
t=getTime()-time;
}

double time()
{
return getTime()-t;
}

~Chrono(void)
{}
};


(I can explain it if that's not clear)
Hope that helps you
:wink:

This topic is closed to new replies.

Advertisement