Odd problem with GLMax2DDriver

BlitzMax Forums/BlitzMax Programming/Odd problem with GLMax2DDriver

TomToad(Posted 2011) [#1]
posted some code in the beginner's forum in the coding challenge thread. The timing was linked directly with the monitor's vSync.

Decided I would try implementing fixed rate logic with tweening. This is where everything gets interesting. After changing the logic, everything moved a little jerky. What was really weird was that everything sped up when I moved the mouse. Thinking I made a mistake in my logic, I looked over my code again, and again. Redid a few things, improved a few things, but the jerkiness was still there.

Tried compiling using Flip False so the flip happened as fast as possible. Everything ran smoothly, but I did get a little tearing (not surprising since the flips are no longer synced to the vertical sync).

My code was using the GLMax2DDriver. I decided to comment out the line so that it would use the default D3D9Max2DDriver. Everything ran smoothly, regardless of what Flip was set to. Then I realized, the jerkiness was coming from several frames being buffered, then drawn one after another. When I moved the mouse, several frames were being rendered in rapid succession, hence the speedup.

Odd thing was, the drawing portion of my program did not change at all, only the logic portion. Everything ran smoothly before making any changes; but the changes I made, which only affected where everything was drawn, not what or when, seemed to have altered openGl behavior.

Here is the modified code if anyone wants to try. Just uncomment the SetGraphicsDriver to try it with OpenGL.

BTW, my video card is an NVidia GeForce 9100

Image:

Code:



col(Posted 2011) [#2]
Seems to be smooth here with OGL and Dx. I've tried it with my Dx11 driver and its ok with that too.

After trying a couple of things its not smooth at all!! Its regular but not smooth.

Might be talking crap here ( I'm real tired and we all know what that means :D ) but...
Using float for 'i' makes it smooth when using syncing, but not smooth with Flip0
Local i:Float = 0
If Time >= LogicTime
	i = Float(Time - LogicTime)/MSPF+1 'The number of full logic frame iterations
	logicTime :+ i*MSPF 'update LogicTime for the next frame
End If

The Tween variable is always 0 because of the brackets around the calculation?
Local Tween:Float = (Time - (LogicTime - MSPF)) / MSPF 'Find the Tween Value

to

Local Tween:Float = (Time - LogicTime - MSPF) / MSPF 'Find the Tween Value


Sony Vaio VGN-FW31M - Vista Home 32bit.

EDIT:- One thing. To get it to work, the media file is spelt different to the file name used in the code. The media file needs to be changed to include a space between the words 'Chicken' and 'Little' or take the space out in the code at Lines 3 and 15 :P

Last edited 2011


TomToad(Posted 2011) [#3]
That won't work right. As an example, let's say that LogicTime (The next time a full frame tick has occurred) is 100. MSFP (Milliseconds per frame) is 10. Now through the loop, Millisecs(), which is stored in Time in order to keep a consistent value throughout the function, is 115. So there are 2 full logic frames that must be calculated (1 at 100 and one at 110), and we are halfway to a third frame (which will occur at 120 milliseconds()) so tween needs to be .5.
With i an int and brackets in the Tween calculation

(115-100) = 15
15/10 = 1.5
1.5 gets truncated to 1 since we are dealing with ints.
1 + 1 = 2

So far ok, we have the 2 times our function will loop through a full frame

LogicTime =
2 * 10 = 20
20 + LogicTime = 120

Perfect, we updated LogicTime to the next full frame tick

Now to compute the Tween

Tween=
120 - 10 = 110
115 - 110 = 5
5 / 10 = .5

Just what we need for the tween value.

Now for your version.

115 - 100 = 15
15 / 10 = 1.5 This will not get truncated
1.5 + 1 = 2.5 Not the value we want, it will still work at this point, but complications come later

LogicTime =
2.5 * 10 = 25
100+25 = 125

Not the value we want. The next logic frame will tick off too late.

Tween =
115 - 125 = -10
-10 - 10 = -20
-20 / 10 = -2.0

Once again, not the value we want.

Stepping through this, I have discovered a bug. Tween is always 0, but not because of the brackets, rather because of the integer division. I should change that to

Tween:Float = Float(Time - (LogicTime - MSPF)) / MSPF


col(Posted 2011) [#4]
I did say I was tired ;)
Does your fix work ok? I'm at work at the mo so can't test on my system until later.


TomToad(Posted 2011) [#5]
No, it doesn't. For 2D games, tweening doesn't really make that much of a noticeable difference, unless you are extremely perceptive. It becomes more apparent when programming 3D games. I am beginning to think my problem is just with the OpenGL drivers on the cheap imbedded gpu in my system. Both DX drivers work just fine.