Advertisement

Question about umh, time perioid

Started by June 29, 2003 09:06 PM
14 comments, last by Mkk 21 years, 8 months ago
is there anything that controls the time In NeHe´s tutorials ? I mean, in openGL super bible´s exams there were some kind of timer that controlled how fast the program will "refresh" but in NeHe´s tuts I haven´t seen anything like that so does it just depend on computer speed how fast the programs based on his code will run? PS. Sorry for my sucky english, it´s late and the cpu in my head is not working 100% right now ;-D
Actually, yeah. Nehe''s, like most tuts out there, purely base themselves on the max refresh rate the PC can handle.. you could, however, make a timer in ur engine, and, when it hits the time, you do the DrawGLScene procedure..
Advertisement
Yeah, that what I thought, just wanted to make sure.

Thanks a lot pal! :-)

[edited by - Mkk on June 29, 2003 10:54:35 PM]
Nehe lessons 1-20 base their speed on the max fps the scene can give. But in lesson 21 a simple timer is inculded... it simple wasts cpu cycles so a max fps could be seted. There you can have some kind of simple time controller.
"You take The Blue Book and the story ends. You wake in your bed and you believe whatever you want to believe. You take The Red Book and you stay in Wonderland and I show you how deep the rabbit-hole goes."
Is it ok to use windows own function SetTimer()?
Well there are a many, many, ways of propertiming in a game. One is doing it all pure time based, for windows use the timeGetTime()and from taht you can time verthing (it uses mili seconds).

Another thing i have done is a scale factor. To get this factor i do a

gscale = 1/FPS;

Where FPS is the frames per second. Then when i do anyhting that involves movement, rotation, timing etc i just multiply it bu gscale.

I know there are plenty of more options, jsut thought i would share some I use. Good luck
Advertisement
When programming for windows or linux you DON'T want to use an fps. You'll want to get the max framerate possible, since you never know when your OS might act up (windows ecspecially) and make the game slow down.

What you DO want:
Check the system-timer each frame, using timeGetTime(); and calculate how much time has passed since the last frame was drawn. You then use that difference to progress your animations, and move/rotate your objects accordingly to how much time has passed.

For example: Say I have a game with a coin in it, and I want it to do 1 spin (2PI) every second:

CoinRotation = (sin(timeGetTime())/2+0.5) * 2PI;

as sin always returns -1 to 1, we used /2+0.5 to make it 0 to 2.

This worked for my coins, though it really depends on what you want to do with it. SOmetimes you might wanna use += instead of = for better results. You just have to try it.

[edited by - Ruudje on June 30, 2003 8:00:26 AM]
Why wouldnt you want to adjust frame based movement by the FPS? If a game slows down the FPS slow down...

say a game is running at 80 FPS and a game is running at 20 FPS with the simple adjustment of 1/FPS yeilds the same speed.

using the number 80...

at 80 FPS
1/80 * 80 = 1 per frame, 80 times a second = 80
at 20 FPS
1/20 * 80 = 4 per frame, 20 times a second = 80

"since you never know when your OS might act up (windows ecspecially) and make the game slow down."

So if for some reasion your "os may act up" it still yeilds the same timing. Am i missing somthing?

[edited by - skow on June 30, 2003 9:49:16 AM]
go ahead then, if you want your game to pause every once in a while... just ask yourself, why all proffesional games on the pc use this technique... you should only use a fixed fps on a console
Ive been using this and never had a game pause.

I''m just wondering what is wrong with it, how would it "pause." I''m not saying your worng, like i said i use timeGetTime() myself.

Whats the flaw in my logic? Could you explain instead of just saying I''m wrong?

timeGetTime(); is windows only correct? It''s nice to have a method that isnt dependent on a OS''s functions.

This topic is closed to new replies.

Advertisement