Display Jitters
Blitz3D Forums/Blitz3D Programming/Display Jitters
| ||
I have been looking around for quite awhile trying to figure out how to get smooth animation. With every method I have tried for timing, I get jitters in movements. I have tried using vwait flip false, but that doesn't work. I have also tried using a timer with millisecs, but that also doesn't work. This code shows the problem well:Graphics3D 800,600 SetBuffer BackBuffer() camera=CreateCamera() MoveEntity camera,0,0,-10 light=CreateLight() MoveEntity light,0,0,-15 Type cube Field x#,y#,meshHandle End Type SeedRnd MilliSecs() While Not KeyHit(1) timer=timer+1 If timer>14 Then timer=0 If timer=0 Then a.cube= New cube a\meshHandle=CreateCube() a\x=Rnd(-4,4) a\y=-10 EndIf For a.cube=Each cube a\y=a\y+0.2 PositionEntity a\meshHandle,a\x,a\y,0 If a\y>15 Then Delete a Next UpdateWorld RenderWorld Flip Wend End This code has boxes flying upwards, and on my computer their motion is very jerky. Anyone have any ideas? The jitters aren't as noticeable in full 3D, but my game is not like that. Thanks. |
| ||
I tried it with debug NOT enabled, and it was smooth. Then I tried it with debug enabled, and it "jittered". |
| ||
For me it jitters with debug off as well... |
| ||
always smooth for me fullscreen, jerky in window mode. |
| ||
check your background tasks. kill everything that is not neccessary and try again. If this wasn't the cause, try this: run with flip false and check the frametime in milisecs. If it's near the sync rate (like 17 ms @ 60hz), you may have a "near-sync-rate" problem. This means the app will run with 60 fps for a couple of frames, then for 30 frames for some further frames, then 60 again. etc. toggling between 60 and 30 fps is mostly obvious, although 20/30 is also disturbing, as well as 15/20. But I still think it's the background tasks problem. I remember when I didn't have a router, there were hundreds of firewall alerts every day and each one paused the machine for some milisecs. This really depends on the priority level of a background task. |
| ||
I turned off my firewall, and that didn't solve it. If I run it with just flip false, though, there are no jitters, but I don't think I could run a game like that, could I? I measured the frame time with flip false and it gave around 5 milliseconds. How would I fix the near-sync-rate problem if that's what it is? Thanks again for your help. |
| ||
use delta timing. The frametime is measured and the movement of the objects is multiplied with the relative frametime. So when it runs faster, objects will move with smaller steps. Although the frametime is measured from the prev. frame, it may still be 98% representative fot the current frame. So somewhere in your mainloop you have something like this: t2=t T=millisecs() ft#=t-t2 delta#=ft / 16.67 now every object that is moving must use the delta factor, example: x#=x# + (xstep# * delta#) positionentity thing,x,y,z This method also makes sure the objects will move with the same speed on all machines, regardless of the framerate. BTW. if you have AniMeshes in your app, all you need to do now to sync them with this system is to use delta as the parameter for Updateworld(): UpdateWorld(delta#) However, I'm not sure if this will solve your problem. But you may try it this way. Well your jitter problem with sync on rather sounds like your machine is missing some syncs - that would be very bugous on the hardware level. |
| ||
forgot to mention: for delta you need to add this: t=millisecs()-17 right before wour mainloop starts, this will initialize it correctly. Additionally I'd suggest to check delta for nonsense values and limit them reasonably. Plus, if you pause the game, you need to "reset" T before continuing the game. |
| ||
i've had to slow down the logic loop speed... GameTimer=CreateTimer(24) here's the mainloop code... FPS=WaitTimer(GameTimer) For k=1 To FPS ** game logic here ** Next Next UpdateWorld() RenderWorld() ... VWait:FlipFalse of course, all the other reaction speeds had to be adjusted accordingly(movements, rotations, etc)... it seemed that Blitz was running the code faster than the refresh for the card/monitor combo... and slowing down the logic loop seemed to be the only solution... hope this helps... --Mike |