Updating Scenegraph from data model

Hello All,

I’ve just started to look at creating a simple shooter game using Xith. The main aim of this is to learn a bit about Xith while doing something (relatively) simple and fun.

What I had in mind was a simple top down shooter (2d world) using 3d models and effects. This way I get to play with Xith, while (hopefully) not having too much of a headache with the game.

I want to use a MVC style design where the rendering is handled by Xith and I have a simple data model running the game.

What I want to know is what is the best way of updating the scenegraph from the data model?

Do i have to run the model in the same thread as the scenegraph and do somthing like this (from Xith3DTextureBlendTest) where I tick the model, then update the scenegraph and then render it?



while (true)
{
      view.renderOnce();

      try
      {
            Thread.sleep(10L);
      }
      catch (Exception e)
      {
      }
      angle += 0.005f;
      testRotateY.rotY(angle);
      testRotateYGroup.setTransform(testRotateY);
}

Or could I run the data model in a seperate thread and set up some kind of observer to update the scenegraph between renderings, so that the model can sync it’s self to it’s own timeing updates.

Sorry I’ve rambled a bit, I hope you can help point me in the right direction.

Dan.

On a multi-processor system using multi-threads would be nice. :slight_smile: (OK, probably not only on multi-processor systems, but mainly there.)
However please bear in mind that Xith3d is not thread-safe (like Java’s collections), so you’ve to take care about this yourself.

Because I figured out it’s not worth the hassle with my Xith app mostly runing on single-processor systems, I took exactly the route you quoted: one thread. It works fine.

loop {
model.simulate…
view.doRenderOnce…
controller.fetchKeysAndMouse…
}

MVC. :slight_smile:

Thanks Preston,

It was the whole “not thread safe” aspect I was concerned about.

I was just wondering what experience other people had in this situation and wanted to at least start doing things in a recognised way. It seems I was at least thinking along the right lines.

Now I’ve just got to find some time… :wink:

Dan.

It sometimes also makes sense to partially place scene updates to Xith3D callbacks (I guess something like GeometryUpdater - I was never using this till now), so you can parallelize the work of GPU and CPU - these days you always have at least 2-processor system with GPU and CPU, so parralelizing their work may speed up overal performance, and, of course, increase framerates.

Yuri