Different update rate for render and logic

Software: Away3D 4.x

louis87, Jr. Member
Posted: 17 October 2011 09:17 AM   Total Posts: 46

Hi everyone,

It is recommendable to separate the rate of the logic (using a Timer) to the rate of the render? It penalizes the performance?

Thanks!

   

Richard Olsson, Administrator
Posted: 17 October 2011 09:49 AM   Total Posts: 1192   [ # 1 ]

Before I say anything else, it’s important to understand that Flash Player does not support threading (yet) which means that you can’t really separate logic and rendering in a way that one doesn’t affect the performance of the other.

However, what you can do, is to calculate AI logic and things like that only every third frame for example (or stretch the calculations evenly over three frames). As long as it’s possible for you to do so (i.e. NPC reactions don’t have to happen more often than that) it should leave more power to the render engine than doing those same calculations every frame.

In the end, you’re gonna have to give it a try to see whether it delivers any noticeable performance increase for your use case. Let us know how it goes! smile

   

louis87, Jr. Member
Posted: 17 October 2011 09:57 AM   Total Posts: 46   [ # 2 ]

Thanks Richard!

I think I’m going to wait to multi-threading, but I’ll keep that in mind if I’ll need it.

   

Avatar
TheSillyOne, Newbie
Posted: 01 November 2011 10:27 AM   Total Posts: 28   [ # 3 ]

Don’t wait for MT, you can learn a lot here! Check out schedulers and task queues.

Also, please do not use a timer for this, you might regret it (jumpy frame rate etc.).

Best regards.

   

louis87, Jr. Member
Posted: 02 November 2011 07:39 AM   Total Posts: 46   [ # 4 ]

I studied about schedulers and task queues, but programming with ADA, that supports multiples tasks and concurrence. Do you know how to do in as3 or when can I read about it?

   

inSertCodE, Sr. Member
Posted: 03 November 2011 11:00 AM   Total Posts: 105   [ # 5 ]

I was thinking about same problem, how would I synchronize game running at same speed at different fps…

I’m gonna go with the simplest solution.
For example you setup the project at 60 fps.
And object needs to move by 100 per second.

You convert the move distance to the current frame rate. You update the movement each frame.

max move distance p/frame = max.movement p/s / max fps

... or because the max.movement p/s and max fps are constants you go straight

max move distance p/frame = 1.6667

then you adjust the move distance per render to the current framerate

move distance = (max.fps/fps) * max move distance p/s

or

move distance = (max.fps/fps) * 1.6667


So lets check the calculations…
-If your app runs at 60 fps for 5 seconds it will update 300 times
it will move the object (60/60) * 1.6667 = 1.6667 per frame
or 300*1.6667 = 500 point in 5 seconds

-If your app runs at 30 fps for 5 seconds it will update 150 times
it will move the object (60/30) * 1.6667 = 3.3334 per frame
or 150*3.3334 = 500 point in 5 seconds

-If your app runs at 23 fps for 5 seconds it will update 115 times
it will move the object (60/23) * 1.6667 = 4.3479 per frame
or 115*4.3479 = 500 point in 5 seconds

The framerate can wary so you have to calculate the move distance each frame.

This is how i see solution to time bounding. I’ll be glad if you could share some better ideas.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X