Slowing down programs
I have ran into another problem...
If I handle my messages in pure loops, it goes all too fast.
Anyone know a good way to make the game go in a normal speed, which can be about machine independent, and without slowing other parts of the program? :confused:
I dont know what your asking, but possibly a timer? Im not exactly sure how to use them, i think you catch the WM_TIMER message, have someone else here answer that :-p
You could use a sleep() function, that allows you to pause your program for a certain amount of time (usually in milliseconds), and often uses the spare time to work on other CPU tasks. There are a number of different sleep() functions out there, so just look for one that statisies your requirements from machine indpendency. Just place that in your loop and pause for however long you think it should pause for. Be sure to make this amount adjustable, as processor speed will vary from machine to machine.
> Anyone know a good way to make the game go in a normal speed
Which graphics library are you using?
Some of them allow you to synchronise your program to the monitor refresh rate, so that your game progresses at a known rate.
Or say for example that your character has a velocity of 100 pixels per second.
If a game loop takes 100ms, then you move the character 10 pixels.
If a game loop takes 500ms, then you move the character 50 pixels.
The end result is, the quicker your program loops, the smaller the move your character makes on each iteration of the loop.
I use OpenGL for my game-part, together with pure Win32API.
What are the goodies and what are the drawbacks using
WM_TIMER and Sleep() ?
The correct way of doing this is NOT a timer or a sleep() function. To make your timing machine independent, you need to pass a delta value to your render function. This delta value is the amount of time that has passed since the last time your render function was called.
This way the timing will be the same on all machines, but faster machines will get better fps than slower machines.
If you want to limit the fps, then you just need to wait until the delta value reaches a preset number before you call the render function.
good idea :p
Got any links or such how to bring it into life? :confused: