Game loop and update

I find that the update mechanism of XNA is not completely right

usually the order in the update makes sense because it's expected to be like this:

  1. UpdateInput (it can be from gamepad, netowrk ...)
  2. UpdateAI
  3. UpdatePhysic (or simulation)

Using the GameServices collection it ca be reached if:

GameServices.GetService<>() return a collection of services of type T and not just only one

in this way you can write something like:

inputservice[] inputs = GameServices.GetServices<inputservice>();

Foreach (inputservice is in inputs) { inputs.Update();}

AiService[] ai = GameServices<AiService>()

foreach( AiService ais in ai) { ais.Update(); }

Otherwise now you can support extremly simple games where you can write everytime ALL THE UPDATE CODE in the update method.

The point still unsolved is what to do if some components updates a position after the simulation pass?

[1061 byte] By [colombod] at [2007-12-24]
# 1

colombod wrote:
The point still unsolved is what to do if some components updates a position after the simulation pass?

I don't understand the issue. The next time through the loop the components will use the updated information.

JimPerry at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 2

Your game should have a gamename.Designer.cs in addition to the gamename.cs (click the plus next to gamename.cs). That file has the implementation of InitializeComponent()...at the end of InitializeComponent(), there are calls to this.GameComponents.Add()...the order things are done are the order they appear here.

I've yet to try it, but I'm hoping you can manipulate the GameComponents collection in the Update() routine, though it could throw one of those, don't mess with the collection in a foreach exceptions...if not you could re-order them at startup or something.

at any rate, I agree, the order in which GameComponent calls Update and Draw can have adverse consequences depending on what you are wanting your GameComponent to do.

jjb3rd at 2007-8-31 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...