Author Topic: Constant Game Speed independent of Variable FPS  (Read 15618 times)

r0ber7

• Prof. Inline
• Posts: 550
Re: Constant Game Speed independent of Variable FPS
« Reply #15 on: 2012-Dec-04 »
Is it a virtual camera, everything moves left using an offset variable when the camera pans right for example?

Yes. Objects have their x & y position in the world. object screen drawing position = (object world position - camera position). So on the one hand I'm interpolating the camera position, on the other hand I'm interpolating any moving objects. Camera position is an int, and so is everything else I use for drawing.

Vsync is set to "let the program determine" in my nVidia screen, and project options of max fps -1 & 60 both give the same result.

Thanks for the comments, I'll figure it out eventually.

Slydog

• Prof. Inline
• Posts: 932
• KodeSource
Re: Constant Game Speed independent of Variable FPS
« Reply #16 on: 2012-Dec-04 »
@r0ber7

You *may* want to try converting your camera position 'ints' to 'floats'. (And perhaps your object positions too)
Do all math and updates to those using floats also.
Then, you will be able to handle sub/fraction pixel movement smoothly.

When I implemented my 'kinetic scroll' algorithm to mimic iPhone's scrolling, it would only work with floats, or else it would be very jerky when it was at a fraction of an int speeds.

But, if your speed is say 2 constantly, and you're still getting jerkiness, then I suppose you may have another problem somewhere.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

kanonet

• Prof. Inline
• Posts: 1142
Re: Constant Game Speed independent of Variable FPS
« Reply #17 on: 2012-Dec-04 »
But if you do your camera etc. in float you may get the same camera shivering that we know from 3D.
When you add a number that are really different in size like 0.1 vs 1000 etc. then you get float inaccuracy...
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Slydog

• Prof. Inline
• Posts: 932
• KodeSource
Re: Constant Game Speed independent of Variable FPS
« Reply #18 on: 2012-Dec-04 »
@kanonet

All the calculations and updates are done to a float variable, then converted by GLB to an int when used for a position.  But I suspect that's not what you're questioning.

I'm not too sure what you mean by "camera shivering that we know from 3D".
In my game my 3D camera is positioned using my tween / easing library.
When it gets to its destination (smoothly), it stops and remains fixed, no 'shivering'.
My tween library *sets* the camera position each frame (it knows where the camera should be), it doesn't just add an offset value to the current position, so this may have something to do with it.

I also don't know what you were leading to regarding float inaccuracy.
In that if you keep incrementing a position variable by a floating value, eventually it will drift away from what you are expecting?  Or because '0.1' and '1000.0' are far apart . . . and . . . dang, still don't know what you were inferring.  I guess without an example situation (not code) I may not.

I understand the nature of floats, I just can't readily come up with a situation where they could be a problem (with positioning specifically).  (But mind you, in my programming career, I sure had run ins with float inaccuracy bugs! ha)

[Cool, my '777'th post!  Dang, now I can't make any new posts or I will ruin it!]
« Last Edit: 2012-Dec-04 by Slydog »
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

bigsofty

• Community Developer
• Prof. Inline
• Posts: 2702
Re: Constant Game Speed independent of Variable FPS
« Reply #19 on: 2012-Dec-04 »
TBH if the problem was a float to int conversion, then I would expect to see constant shivering. not just intermediate shivering.

I use this system in 3D, so I interpolate between vectors, which are all floats, this may be why I dont get the same problems. I would not like to use ints internally though, even for 2D, as the interpolation relies on the fact that it can use sub-pixel accuracy when calculating the next point on the screen, for really slow moving objects for example.

For example it has enough time to render 10 frames and it only has to move a sprite 4 pixels. It will try and increment each frame 0.4 pixels. You would loose the interpolation accuracy if using ints. The same would be true of the camera.

This still may not me the problem though as there are other factors that could be producing this effect. Rober7, if you could provide a simple cut-down example of the problem, I would take a small look if you like?
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

r0ber7

• Prof. Inline
• Posts: 550
Re: Constant Game Speed independent of Variable FPS
« Reply #20 on: 2012-Dec-05 »
Hmm... yeeesss...

Ok. So, I have to use ints. This is because of the z_project lib I use. If I use floats I'll get tiny errors when scaling on different screens, which looks as if the screen has been "sliced up". I don't think that using ints is the cause of the problem anyway, because (in the name of science!) I did change all position related variables to floats this afternoon, and it was still jittery. Intermediate indeed, bigsofty. I have another idea now: put the camera movements inside the draw() function. I know, this is cheating a bit, but hey, might work.

Maybe if that doesn't work I'll post some code here. Thanks for all the suggestions you guys. I suspect this has something to do with internal game specifics rather than the actual gameloop code though, so I feel bad for derailing the thread.

Hemlos

• To boldy go where no pixel has gone before!
• Global Moderator
• Prof. Inline
• Posts: 1645
• Particle Hawk
Re: Constant Game Speed independent of Variable FPS
« Reply #21 on: 2012-Dec-13 »
If its not your code, Im willing to bet your camera is out of opengl's boundary limits.
The size of the opengl world is -32000 to 32000 in each dimension, if you go further it causes problems.

http://www.glbasic.com/forum/index.php?topic=3904.msg28557#msg28557

I suspect this is your problem because you are using integer for 3d coordinates.
You should use floats in the 3d world, otherwise(ints) you are wasting precious 3d space.

64000.0 total opengl world width would be 64km wide.
Build all objects relative to 1 xyz position=1 meter. eg 0.5 would be a half meter.

Furthermore, the best way to setup a camera in opengl is move the world, not the camera.
In your case, alternatively, you can make grids and shift the grids and the camera relative to 000 xyz when the camera goes too far.

Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Wampus

• Prof. Inline
• Posts: 1004
Re: Constant Game Speed independent of Variable FPS
« Reply #22 on: 2012-Dec-14 »
Ok. So, I have to use ints. This is because of the z_project lib I use. If I use floats I'll get tiny errors when scaling on different screens, which looks as if the screen has been "sliced up". I don't think that using ints is the cause of the problem anyway, because (in the name of science!) I did change all position related variables to floats this afternoon, and it was still jittery. Intermediate indeed, bigsofty. I have another idea now: put the camera movements inside the draw() function. I know, this is cheating a bit, but hey, might work.

Tiny errors when scaling causing sliced up look? Hmm, you know that sounds like a sprite extrusion issue. Here is a thread about a similar problem (or the same problem) and solutions: http://www.glbasic.com/forum/index.php?topic=5057.0. Confused me a lot tbw.