Archived

This topic is now archived and is closed to further replies.

Destroyer

Non set fps... or not forcing the computer to wait...

Recommended Posts

Destroyer    122
Hi, I know this is possible - I''ve see it on other games like liero... How would I go about making the main game loop without forcing the computer to wait a specific time. For example:
  
int Game_Main(void)
{
  //do game stuff here

  
  Wait_Clock(100); //10 fps

}
  
Without having to use that wait_clock ? How would I go about making the the fps shoot right up, but also take into account I''m animating as well and I don''t want my animations running at something crazy like 50 fps when I only have 10 frames in the animation to start with, and they we''re originally only to be displayed every tenth of a second anyway? Try to make sense of that :p Thanks, Destroyer

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Well it is a good idea to run the graphics engine in a seperate thread.

but you do an if that checks how much time has passed since the game engine was last looped... you should use QueryPerformanceCounter() but I''ll use GetTickCount()

Both windows... but there are similar function for the other OSes.


long lastTime = GetTickCount();
while (true)
{
// Graphics Engine Stuff

if (GetTickCount() < lastTime + 100)
{
lastTime = GetTickCount()
// Game Engine Stuff
}
}

Share this post


Link to post
Share on other sites
Mark_C    122
Well it is a good idea to run the graphics engine in a seperate thread.

but you do an if that checks how much time has passed since the game engine was last looped... you should use QueryPerformanceCounter() but I'll use GetTickCount()

Both windows... but there are similar function for the other OSes.

  
long lastTime = GetTickCount();
while (true)
{
// Graphics Engine Stuff


if (GetTickCount() < lastTime + 100)
{
lastTime = GetTickCount()
// Game Engine Stuff

}
}


(Sorry for the double post...)

Edited by - Mark_C on December 11, 2001 7:32:26 PM

Share this post


Link to post
Share on other sites
Mark_C    122
Well you''d want to put whatever you wanted to limit in the if statement.


If you are using windows you can do multi-threading with:

CreateThread()
TerminateThread()
SuspendThread()
ResumeThread()

Share this post


Link to post
Share on other sites
AdmiralBinary    100
The preferred method is to modify the amount an object is animated/moved by the time passed since the last frame.
Example:

  
DWORD lastTime;
void Update()
{
DWORD timeElapsed = timeGetTime()-lastTime;
...
object.x += (object.speed*timeElapsed);
}


This is a very simple example, but does not require you to make the CPU wait until it does the next frame. To make this work for a 2D game, your objects should have their x,y values as FLOATS to maintain precision.

"That''s what I think anyway." - Mr Bean

---------------

I finally got it all together...
...and then forgot where I put it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
hey I was wondering if the approach I am using is any good. I have my basic setup where I initialize all the services I need (direct x and other windows stuff) then I create an object which is a subclass of GameState and assign it to a pointer. Then I register a timer to call a pretty simple function, something like this:

if(lock) return;
lock=true;

//nextState is a StateLoader*, not a GameState*
if(nextState){
delete(gameState);
gamestate=nextState-&gtcreateState();
nextState=0;}

gameState-&gttick(); //this runs one frame of the game
lock=false;

So I don''t have a loop in my code, the timer controls things. I have run into a problem though. I can only debug the first frame of my game.

Share this post


Link to post
Share on other sites