1. time based movement

i'm trying to implement time based movement to make my game run at the same speed on all systems. however i can't seem to get it right. Could someone have a quick look through my code and tell me where i am going wrong? The time code stuff is in the "base.cpp" and "render.cpp" files.

Thanks for any help u can give me!

2. I have never actually tried to do this, but I do remember seeing an article on it at Game Tutorials. Take a look at the last turorial on this page:
http://www.gametutorials.com/Tutoria...OpenGL_Pg1.htm

Hopefully that will help.

- Sean

3. Im a novice programmer, and you probably know much more than me. I program with Borland 3.1 so that tells you what type of programs I am creating right now. Anyways, when I want my programs to run the same speed on all computers I use the monitors screen refresh. Most monitors run at the same speed, give or take a little, so may be you can do something like that. Just a thought. Im not sure if it works the same with windows programs, but it seems to work good with dos. Anyways, thats my 2 cents - and thats all it's probably worth, if that. Good luck!

4. To get a program to run at the same speed one system is to calculate the time inbetween frames, then scale movement by that.

Keeping track of the time between frames is easy, I'll assume you can figure that out.

Then each time you want to move
PlayerPosition += speed_val*rate;

speed_val is the number of units to move in 1 second
rate = time rate (seconds per frame)

5. I have an example on another forum, is it allowed to post links in here?

6. Time-based movement is very simple in any game. Essentially, it is this:

You create your own clock, using the O/S's time manager. For example, lets say you want to draw a frame every 20th of a second.

You create a callback and have your O/S interrupt (that is, call your callback) every 20th of a second. Inside the callback, you simply set one of your global variables, a "flag" to TRUE. Something to let you know it's okay to draw a frame.

Then everytime through your program's main code, at some regular interval, you check to see the state of that flag. If it's not TRUE, you don't draw a frame. If it is TRUE, you _do_ draw the frame and then you clear the flag to FALSE.

On slow machines it would always be TRUE, on fast ones, you'd only draw every 20th of a second.

---

Note, you can still miss a frame this way if you happen to miss an interrupt (let's say the system didn't interrupt you because it had a higher-priority interrupt it had to service and yours was sacrificed), but that's not a big deal. Virtually wouldn't happen and if it did, wouldn't really affect game play.

This is the most common method for regulating game speed in the industry today.