Skip to main content
GameDev.net gamedev.net
🔒 Locked

limit fps...

Started by colinisinhere Feb 25, 2003 at 7:19 PM 4 replies 1k views
Original Post
colinisinhere
colinisinhere
hey, im making a first person shooter and i dont want to do time based movment because it seems kinda hard... but i thought that it might be easier to just force the game to run at 30 fps... because you dont need it to go any faster then that... anyway... is this possible... please help me
trub
trub
Time based movement isn''t that hard. Just think simple time based physics instead of pushing a move every time you update a frame. There is a great article here on gamedev (do a search in the resources) about how to impliment it quite simply. There is also an article on gametutorials.com. I suggest looking at both so you get a good idea what is going on. Also, people can see better than 30fps (you may be getting that number from the framrate of movies but movies play there frames blurred rather than clear like in rendered graphics so it tricks the eye into thinking its a more fluid motion)
mang?
zealouselixir
zealouselixir
Sure. Drop a "Sleep(33);" in your main loop. That''ll make your game run (if possible) at ~30 FPS.

But that''s lame.

Are you planning on just skipping over things that immediately appear "too hard" at first glance forever? If so, you won''t make it very far. And besides, time-based (i.e. framerate independent) motion isn''t hard at all.

1) Store the last tick in a long (initially set to GetTickCount())
2) Every frame, subtract the last tick from GetTickCount(). This is your "time delta" and is expressed in milliseconds (divide by 1000 to get seconds).
3) Assuming you''ve expressed your object velocities in units/sec, just multiply the time delta in seconds by these velocities and add them to their respective positions.
4) reset the last tick to GetTickCount().

Code:

int CurTick = 0, LastTick = GetTickCount();
float Delta;

while(1) // main loop
{
CurTick = GetTickCount();
Delta = (CurTick-LastTick)/1000.0f;

MoveShip(Delta);

LastTick = CurTick;

//...
}

void MoveShip(float Time)
{
ShipPos.x += ShipVel.x*Time; // simple integration
//...
}


Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
[twitter]warrenm[/twitter]
zedzeek
zedzeek
>>im making a first person shooter and i dont want to do time based movment because it seems kinda hard<<

its not hard

>>but i thought that it might be easier to just force the game to run at 30 fps<<

good idea, i do the movement/ai etc side all on a fixed fps IIRC ~40fps.
rendering though i run at the max the machine can handle

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html
g7tommyB
g7tommyB
How do you manage that Zedzeek?
Do you use multi-threading or just setup your rendering
completely independent from your main game loop?

Thanks,

TommyB
g7tommyB
zedzeek
zedzeek
http://www.flipcode.com/cgi-bin/msg.cgi?showThread=Tip-MainLoopTimeSteps&forum=totd&id=-1

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html

Topic Locked

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

Sign in to reply to this topic.