Updating..

0 views
Skip to first unread message

Michael Cann

unread,
Jul 6, 2010, 12:24:49 PM7/6/10
to swft-fr...@googlegroups.com
Updating is a critical part of any game. Each frame you need to update entities' positions, perform collisions, update AI and many other operations not forgetting to render at the end of all of it. 

As Glidias mentioned in the controllers post currently Swft follows the PBE example of having anything that wishes to be updated register by implementing the IUpdateable interface then registering itself for updates via a central location such as a scene. 

In the BloonBlaster example the BloonController extends from a common component UpdateableEntitiyComponent which, for convencince, performs the registering and unregistering:

package co.uk.swft.engine.components.common
{
import co.uk.swft.base.EntityComponent;
import co.uk.swft.engine.managers.scene.IScene;
import co.uk.swft.engine.managers.scene.IUpdateable;

public class UpdateableEntityComponent extends EntityComponent implements IUpdateable
{
// Dependencies
[Inject] public var scene : IScene;

override public function onRegister():void
{
scene.registerForUpdates(this);
}

public function update(frameDelta:int) : void
{
}

override public function onRemove():void
{
scene.unRegisterForUpdates(this);
}
}
}


Now Glidias brought up a good point that currently there is no way to assign priorities to the updateables. What this means is that some things could update, perform collisions then render before others hence things could become 1-frame out of sync, have jittery collisions or worse.

Now there are a coupple of ways this could be combated. We could simply add another parameter to "scene.registerForUpdates()" which is an integer value representing a priority value. So before an update phase begins the updateabes are ordered based on their update priority. This is, I believe, the way that PBE does it. 

This would work on a per updateable level, although it is a little clumsy and would likely involve magic numbers hard-coded. It however wouldn't guarantee that all the updates of one entity are performed before another entity begins its updates. 

Suppose for example that you had 3 components in EntityA that were registered for updates and you had two components in EntityB registed for updates. You want ComponentA2 to update before A1 and A3 so you set the priority of the update in A2 to -10. Now you want to make sure the ComponentB2 in EntityB to update before ComponentB1 so you set its priority to -10 too. Now however you want to make sure that EntityB updates only once EntityA has finished all its updates. 

So you see here there perhaps may be a case when you need entity-level update priorities too. 

So perhaps you could put another param in the "scene.registerForUpdates(this)" to indicate a priority for entity updates. But now we are looking at three parameters in this method which is starting to look complicated.

It is possible that updates occur "top-down" rather than bottom up. In this scenario we have the entity itself register for updates rather than the components. That way each frame loop you then manually call update on the components in the order you wish them updated. The registerForUpdates call takes in a single integer parameter for priority.

To be perfectly honest im not sure which is the best method. I want it to be simple to just plug and play components. So you can drop a component into an entity but at the same time if we set a precedence of having component update themselfs do we run into priority issues discussed above.

Anyone have thoughts on the best method?

Cheers,
Mike
Reply all
Reply to author
Forward
0 new messages