I'm trying to get 30FPS even

Blitz3D Forums/Blitz3D Programming/I'm trying to get 30FPS even

_33(Posted 2007) [#1]
I have no clue how, as the technique I use gives me 31.2 FPS... Any help appreciated.

MadJack?

:D


semar(Posted 2007) [#2]
You're probably using floats in your fps calculation.

You my convert your fps value to an integer using Floor or Ceil.

IntFPS = Ceil(FPS#) ;rounds up
or
IntFPS = Floor(FPS#) ;rounds down


Sergio.


Jasu(Posted 2007) [#3]
If you want the FPS to be exactly 30, then use CreateTimer/WaitTimer commands.


Vorderman(Posted 2007) [#4]
Use Mark's Castle Timing code framework from the archives and just set the FPS counter to 30.


Gabriel(Posted 2007) [#5]
If you want the FPS to be exactly 30, then use CreateTimer/WaitTimer commands.


Won't work. If the computer can't keep up, you can't wait negative time to get up to 30 FPS.

To clarify the OP do you want to render at 30fps, update at 30FPS or both?


H&K(Posted 2007) [#6]
31.2 Hummmm, Are you sure its not 31.25?

If it is, it might be because you have a fixed refresh rate of 16Milli (ie 62.5 Hrtz).
The main problem of trying to anwser you question, is that without any code, or even a description of how you are trying to maintain 30FPS, we are all just guessing


Wings(Posted 2007) [#7]
Some tipps.

1) Remove som objects. for testing prupose.

2) Flip False ; False make blitz skipp vbl.


MadJack(Posted 2007) [#8]
_33

I just used timer commands.

Of course it assumes your proggy will run faster than 30fps if running unlimited and it assumes one cycle = one logic update + one renderworld - so it's pretty basic.


puki(Posted 2007) [#9]
Personally, if I was aiming for 30 FPS but I got 31.2 FPS - I'd be rather chuffed.


_33(Posted 2007) [#10]
Oh boy!! Great to have so much feedback! I'm building a music video, and I need 30FPS straight to test and sync the music with the refresh for live tests, but the final will be a render, so I have my own timer for that. Yes, H&K, it might just be 31.25 hz refresh rate in reality. I absolutely need 30 fps because this code may be used for live performances. That's true H&K that my same code does 62.5 hz refresh rate if I try to sync with the monitor refresh of 60 hz, well it flips between 62.5 and 57.5...

Gabriel, eventually it will be at a point where the image won't keep up, but presently I just want a perfect 30 fps refresh so I can sync the music that I have been given and my 3D work that I need to time it to.

Use Mark's Castle Timing code framework from the archives and just set the FPS counter to 30.


Thanks Vorderman, I'll look into this ASAP.

Thanks all for the excellent feedback and prompt reply!

I'll consider that easy option MadJack, thanks!


Adam Novagen(Posted 2007) [#11]
If you want the FPS to be exactly 30, then use CreateTimer/WaitTimer commands.

Not true. CreateTimer() and WaitTimer() cause unecessary slowdown. A program demo I made once ran at 24FPS normally. When I added CreateTimer(60) & WaitTimer(timername) to limit it on faster PCs, the framerate on the original PC dropped to 20.


Stevie G(Posted 2007) [#12]

Not true. CreateTimer() and WaitTimer() cause unecessary slowdown. A program demo I made once ran at 24FPS normally. When I added CreateTimer(60) & WaitTimer(timername) to limit it on faster PCs, the framerate on the original PC dropped to 20.



I beg to differ. I always use it.


Gabriel(Posted 2007) [#13]
I beg to differ. I always use it.

Why? It sounds mathematically correct to me.

You've got a timer going off 60 times per second. That's once every ~17 milliseconds. But your main loop takes ~41 milliseconds, because you're getting 24fps. So when your main loop finishes running, it waits for the timer to hit, but it's already passed 17 and 34, so it's not going to hit now until it reaches 51 milliseconds. 1000/51 is 20 frames per second, give or take the rounding I did to get to 17 and 41.


Stevie G(Posted 2007) [#14]
If you put it like that, I hereby retract the above statement!

The problem I have with using physics stuff is that I MUST keep a fixed timestep and simply allow processors to update as fast as they can so that while it may only be able to run at 30fps it's still smooth.

Probably best to re-think my strategy - any thoughts?


Gabriel(Posted 2007) [#15]
Indeed you must have a fixed timestep if you're doing any integration. I've always used render tweening for that. If you were using anything other than B3D, it might be a bit messy, because you have to SLERP quaternion orientations and animation can be a real pain, but B3D makes tweening easy.

See here for the theory :

http://www.gaffer.org/game-physics/fix-your-timestep/

And here for the B3D Practice :

http://www.blitzbasic.com/codearcs/codearcs.php?code=1497


H&K(Posted 2007) [#16]
You've got a timer going off 60 times per second. That's once every ~17 milliseconds. But your main loop takes ~41 milliseconds, because you're getting 24fps. So when your main loop finishes running, it waits for the timer to hit, but it's already passed 17 and 34, so it's not going to hit now until it reaches 51 milliseconds. 1000/51 is 20 frames per second, give or take the rounding I did to get to 17 and 41.
Are you sure? (Not with the Maths), but wouldnt the timmer alreay have fired? That is wouldnt you have two timers events already on the event queue?


Stevie G(Posted 2007) [#17]

Indeed you must have a fixed timestep if you're doing any integration. I've always used render tweening for that. If you were using anything other than B3D, it might be a bit messy, because you have to SLERP quaternion orientations and animation can be a real pain, but B3D makes tweening easy.



Can't use tweening as my velocity is implied by current position - previous position and it'd be prone to lurching and maybe simulation explosion. Also, all my objects are part of a collection of single surfaces. I'll leave well alone I think.


Gabriel(Posted 2007) [#18]
Are you sure?

No, I just did Adam's numbers in my head real quick and they came out exactly right, which seemed like too much of a coincidence to be one.

I've never used timers, and I doubt I ever will. They're a hackish solution and I've always found the proper solution perfectly workable. Hopefully I'll never find myself in a situation like StevieG where I have no choice.

And before anyone asks me if I'm sure StevieG has no choice, again, no. Both problems he raises with tweening sound like problems I could solve, but I'm sure he knows his physics better than I do, so I'm going to assume he's right.


H&K(Posted 2007) [#19]
They're a hackish solution
Oh

My basic framework is based arround self-running hooked Function. (Bit like Skids Fakeing mutitasking).
I must admit I never go 100%cpu and it just seemed to me that event passing was the way to go rather than linea logic.

Would you say that I was on the wrong track to begin with?

I will say that I wouldnt question it, if Bmax had PreEmtive hooks.


Gabriel(Posted 2007) [#20]
Would you say that I was on the wrong track to begin with?

I'm not sure what you're trying to achieve, and I'm not familiar with Skidracer's fake multitasking.

When I say they're a hackish solution, I mean specifically in relation to game timing. They only ever slow your game down, they can't speed it up, so they're only solving half the problem. Granted you may hope that less than half the people are going too slow, but you get my drift. Moreover because anyone who is going too slow won't be well-served, it encourages you to overcompensate and set your fixed rate too low to make sure that most people are covered, and I don't like low fixed-rates very much. Furthermore, I'm not particularly fond of tying refresh and update framerates to each other, I think they work much better if you decouple updates from rendering, render at a fixed rate and render as fast as you can. I guess you could say, they're a perfectly good solution to half a problem.

In other respects, they may have perfectly valid uses, but as I say, I'm not sure what you're doing.


_33(Posted 2007) [#21]
I've tried the following:
Global timer = CreateTimer(30)
While user_input <> CTRL_W
   ticks = WaitTimer(timer)
   ...
   UpdateScene()
   UpdateWorld
   ...
Wend

With using a timer, I narrowed down the problem a bit. While I previously had a time difference of 10 seconds between video/music and the timer + screen refresh after 4 minutes of playing, now I have 2.5 seconds using this code. It is still quite unacceptable, but better.

I'm trying to find Mark's Castle example code... Cheers.

Maybe if I could use the remainder of the previous frame timer and make sure I don't loose anything, I could create a very precise timer...


_33(Posted 2007) [#22]
Well, here's the solution I came up with, and it's rock solid:
Global sys_timer%         = MilliSecs()
Dim framePeriod%(3)
Global framePeriod_id% = 1
framePeriod(1)     = 34
framePeriod(2)     = 33
framePeriod(3)     = 33
Global frameElapsed%      = 0
Global frameTime%  	      = 0
Global framecounter%      = 0

While user_input <> CTRL_W
   frameTime = sys_timer + framePeriod(framePeriod_id)
   Repeat
      sys_timer = MilliSecs()
      frameElapsed = sys_timer - frameTime
   Until frameElapsed >= 0
   framePeriod_id = (framePeriod_id Mod 3) + 1

   UpdateScene()
   UpdateWorld
   ...
   framecounter = framecounter + 1
Wend