Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Timing/framerate in games

Author
Message
malcom2073
21
Years of Service
User Offline
Joined: 12th Mar 2003
Location:
Posted: 2nd Jul 2007 19:03
Alright, I really cant give a code example for this without posting the code for my entire game, but I'll try to explain it best I can.

So if I set sync rate 60, it sets the framerate to a maxiumum of 60.

How can I have an even iteration inside my game loop? With a sync rate of 60, if I have

i = i + 1

inside my main game loop, it will increment 60 times a second. Well what if I want it to incriment only once a second? I've tried using the timer() function, but that isnt accurate enough, because if my game slows down to say, 10fps (which means the main loop is looping 10 times a second), then it's horribly inaccurate and can be off by as much as a tenth of a second. Any thoughts?
vorconan
18
Years of Service
User Offline
Joined: 4th Nov 2006
Location: Wales
Posted: 2nd Jul 2007 19:14
malcom2073
21
Years of Service
User Offline
Joined: 12th Mar 2003
Location:
Posted: 3rd Jul 2007 06:22 Edited at: 3rd Jul 2007 06:30
Eh, the time function is about the same as the timer function.


As for the game being unplayable at 10fps: Most games dont slow down if your video drops to 10fps, they just get choppy. When designing a game, you do not design it only to run on a fast computer, you have to design it to be playable on many computers of different speeds. If a game starts running slow and causing multiplayer sync problems because one person is running at 30fps, and one is running at 60, that's bad programming What's the solution to that? So in 5 seconds, I dont fly 300 meters, and you fly 600.

The timer function will get that alot more accurate, saying that I'd fly 300, and you'd fly 305 say, but it still varies depending on when the loop gets to the part where it checks the timer. Game speed hasnt been cpu speed dependant since the old dx2 days.
malcom2073
21
Years of Service
User Offline
Joined: 12th Mar 2003
Location:
Posted: 3rd Jul 2007 17:30 Edited at: 3rd Jul 2007 17:48
Ack, no that dosent work at all lol. It has the same issue, when the video slows down, the code slows down as well. The only difference is, now the framerate can go up to 1000, and the code runs just as fast. Which I can limit, but the lower end is still a problem.
Xenocythe
19
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 3rd Jul 2007 18:03
Sync On
Sync Rate 60

Do
cap=cap+1
If cap=6
i=i+1
cap=0
endif
Sync
Loop




That should do it.

malcom2073
21
Years of Service
User Offline
Joined: 12th Mar 2003
Location:
Posted: 3rd Jul 2007 18:10 Edited at: 3rd Jul 2007 18:11
My problem is not the video running faster than the code. My problem is when the video runs SLOW, it brings the code down with it. Seems the the code can run at any speed, up to the video speed. If the video goes slow, the code will go slow.
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 4th Jul 2007 23:38
What you need is Timer Based Movement. One of the newsletters hade a "Perfect 60 FPS" tutorial on the subject.

malcom2073
21
Years of Service
User Offline
Joined: 12th Mar 2003
Location:
Posted: 5th Jul 2007 07:12
Don't suppose you have a link to this?
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 5th Jul 2007 21:10
After clicking on random newsletters I found it! It's Lee's Tip Of The Month in Newsletter #42.

malcom2073
21
Years of Service
User Offline
Joined: 12th Mar 2003
Location:
Posted: 6th Jul 2007 03:48
Excellent! This is exactly what I'm looking for. Thanks!
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 6th Jul 2007 12:36
Glad to help

Login to post a reply

Server time is: 2024-11-25 15:22:18
Your offset time is: 2024-11-25 15:22:18