Sign in to follow this  
Sc4Freak

Update order of subsystems and intra-frame dependencies

Recommended Posts

Sc4Freak    643
This is something I've been wondering about for a while, but haven't been able to come up with a really good solution for. Every game is going to have certain dependencies between subsystems and entities in the game: for example, if a camera is following the player, the camera has a dependency on the player's position.

Now, the order in which you update things in your game can have a significant impact. If you update the player before the camera, the camera's position at the end of the tick will have correctly updated with the player's latest position. But if you update the player after the camera, the camera will perpetually be one-frame behind (it'll always be looking at last ticks data).

In current game, my update order is a bit ad-hoc. I don't have any defined way to deal with these sorts of depenencies: I just update things in any order I like and go back and fix things if something breaks. And I don't have any way to deal with a circular dependency. This has led to the unfortunate situation of objects being arbitrarily either 0 or 1 tick behind.

One easy solution I've heard is to double-buffer game state. At tick t=1, BufferA contains the game state as it was at t=0. The game logic reads from BufferA and writes to BufferB. At the end of tick t=1, BufferB contains the game state at t=1. The two buffers are pointer-swapped, and the process repeats for t=2. This essentially forces everything to be one tick behind, but you don't have to worry about update order.

Are there any better ways to handle this?

Share this post


Link to post
Share on other sites
wqking    761
Unless you are developing mobile games for very low end portal with maybe 10 FPS, the order doesn't have significant impact.

Both camera being one frame ahead or behind doesn't matter on a 30~60 FPS game, nobody will notice the difference.
Don't forget the human-being's reaction time is about 100ms.

So for visual effect, one frame is trivial issue. But if it affects your AI or physics, it's matter and you need to change upon on your AI or physics engine.

AFAIR, I ever did a very simple test, render/update very simple animation in wrong order, the first frame is visually wrong, then it becomes correct later. Thinking the end of current frame is next frame's beginning... Edited by wqking

Share this post


Link to post
Share on other sites
Hodgman    51324
We've had significant bugs because of this on a 30hz game. They're usually very subtle and hard to track down, but kind of butterfly effect their way into unexpected symptoms....

We ended up with a data-driven sub-system loader, where a text file could list the order of updates, making it easier to tweak. You could specify things like [i]X must execute after Y[/i], or [i]Z must come before W[/i], and the manager would build a dependency graph and spit out a linear list of tasks to run.

Share this post


Link to post
Share on other sites
wqking    761
[quote name='Hodgman' timestamp='1302598945' post='4797439']
We've had significant bugs because of this on a 30hz game. They're usually very subtle and hard to track down, but kind of butterfly effect their way into unexpected symptoms....

We ended up with a data-driven sub-system loader, where a text file could list the order of updates, making it easier to tweak. You could specify things like [i]X must execute after Y[/i], or [i]Z must come before W[/i], and the manager would build a dependency graph and spit out a linear list of tasks to run.
[/quote]

Yes, a z-order like tech can be used.
An update-order value is assigned to a sub system, then the sub system manager sorts the sub systems according to the update-order, then update in the order.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this