Jump to content
  • Advertisement

Archived

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

Gunner

Game timing

This topic is 6690 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, How do you guys set your games to run at the same speed on all systems ? I usually stick to the monitor''s frequency, gives me a rock solid/smooth top framerate and the game keeps the same speed on all other systems. Here''s my problem, whenever the user has a different default refresh rate other than 60hrz at 640x480, let''s say 75hrz, his game will run faster ( of course ). I''m not worried about lower end systems that might not be able to sustain the top framerate. I''ve tried sxengine''s timer wich allows you to specify a target framerate, well, it''s not as smooth as syncing to the monitor''s refresh(not even close), soo i ditched that angle. I guess the solution i''m looking for is to use the function SetDisplayMode(width, height, bpp, refresh rate, 0); in the IDirectDraw7 Interface. With that one you can specify a refresh rate. I wouldn''t go any higher than 60, and at least i would know everyone is maxing at 60fps. Problem is, i don''t know how to initialise it with DelphiX. Help ? How is everyone else keeping game the same speed ? Any other tip would also help. Thanks, Regards, Gunner. Sysimage inc.

Share this post


Link to post
Share on other sites
Advertisement
Frameskiping... plain and simple. Look how MAME and other emulators "fake" 60 FPS on 75Hz and 85Hz by drawing some frames twice (too fast) and not drawing others (too slow)



[ turbo | turbo.gamedev.net ]

Share this post


Link to post
Share on other sites
Use either GetTickCount() or QueryPerformanceCounter().

GetTickCount() is precise to about 1/1,000 of a sec.
QueryPerformanceCounter() is around 1/1,000,000 I think.
Use QueryPerformanceFrequency() to get the real number.

Here''s what I do with them.
First I calculate the framebudget, or the number of "ticks" allowed for each frame. For example, if useing GetTickCount, and you want 60 fps:

framebudget = 1000/60

So it''s about 16 thousanths of a second per frame.
Now I establish the time the frame starts:
framestarttime = GetTickCount();

Now immediately start the rendering. When the rendering is done, I check to see if the rendering process took too long (more than 16 ticks) by calling GetTickCount() again. If it''s done before hand, like it took 6 ticks for example, then I loop in a delay until the following is true:

(GetTickCount-framestarttime) >= framebudget

This is just what I personally do, I don''t know how anybody else here likes that method...it''s not capable of skipping frames, it''s just a speed limiter(although it wouldn''t be hard to implement a frame skipper inside of this).
I''m actually curious to see if anybody here knows any flaws with it??? Let me know, I always want to improve!


When life hands you lemons, throw them at God's head.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The above post is correct. That is pretty much the standard that I have seen... However, good practice is to do any extra AI routines inside that loop....


DO
{
// Cycle through AI Routines here and do one per check... be sure
// not to make the AI Routines too complex or you will miss your
// check again
}
while(GetTickCount() < (StartTime - 30)) //??? or whatever

Enoch Dagor

Share this post


Link to post
Share on other sites
Hi there, the best idea I''ve heard yet (Which I have not implemented yet) is to have 2 threads, one painting everythin as fast as the darn computer can go (60fps, 75fps, 120fps?) However the second thread is respnsoble for updating the units, this thread will use some timer functions to stick to moving units I don''t know like 10pixels per second.. Just an example, of course you could have other units running much faster!
This works great cause you get the maximum fps but will still have the same speed on all computers.
Now here''s the only catch, if they run it on a system WAY below your requirement''s, like let''s say they have an old video card on a K6-2 400Mhz, so an OK computer but a crap card. Well the framerate will max out on the card at like 10-20 fps and your units will still move 10 pixels per second, so then it starts to get choppy, but it''s still running at the same speed.

Hope that helped some!
See ya,
Ben

Share this post


Link to post
Share on other sites
wow, thanks all for your input !

I'm going to try those approaches, looks pretty good.

Now i guess i won't be able to frag my friend anymore with our little network sniper game, i had my refresh at 80hrz and he had his at 60. i kept telling him his reflexes sucked, ahrm well, after this fps fix with the methods suggested above, it might another story all together

Thanks again.

Gunner.
Sysimage inc.

Edited by - Gunner on June 23, 2000 3:17:02 PM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Well there is a more better way.

//Get the lastime with this functions
QueryPerformanceFrequency(Last_Time);
Time_Scale := 1.0 / Last_Time;

In every frame you get the new time and calculates the elapsed time

QueryPerformanceCounter(Current_Time);
Time_Elapsed := (Current_Time - Last_Time) * Time_Scale;
last_time := current_time;


Now you have a number (time_elapsed) which gives you the delay between every frame. In your move function you multiply all your movements with this number (time_elapsed). That''s the best way. Your game will be run at every fps (400 FPS or 2 FPS) with the same speed!

Neo
www.neobrothers.de

Share this post


Link to post
Share on other sites
    
DWORD start_time;

while(!done) //game loop;

{
start_time=GetickCount();

//stuff

while(GetTickCount()-start_time<33); //30 frames perscond (can be changed)
}


JoeMont001@aol.com

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!