Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Timer-based Movement

Author
Message
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 1st May 2005 05:36


Alright so the source is overly complex for what it's showing, but it works very nicely.

I didn't add motion interpoling, figured people would enjoy trying to think of thier own solutions to that.. especially given as mine just complicates matters further, no doubt needlessly.

I'll post it up if people want it though.
Keeping the movement to a VSync of 60 though, should allow you to by-pass the whole worry about smooth rendering, it's only when your trying to render slower than that it starts having a hissy fit.

Setting up your program in this mannor though allows you to do more before it starts affecting performance. If you use a physics engine like newton especially... you see a HUGE performance boost from limiting the number of calls, and it interpols the movement values for you. So it's smooth as anything.

Generally speaking try to keep most of your more processor intensive tasks and base movement within the Timer Loop, then just update the 3D and non-speed related (ie Controls) to outside of the loop.

The best part is when your program slows down, what is in the timer loop doesn't. In-fact you can even forgot syncing outside of the Timer loop and you'll find that the application will run slightly smoother.

It's a very good technique is alot of your application needs to be broken into smaller parts.

Your signature has been erased by a mod. Please resize it to under 600x120. Thanks!

Login to post a reply

Server time is: 2024-04-28 17:04:44
Your offset time is: 2024-04-28 17:04:44