Friday, 25 March 2011

Advice needed on plug&play GameWorlds.

At the moment, my BaseGameEntity classes (inside my main GameWorld class) have a virtual Draw() function which derived classes use to call some OpenGL commands.

Ideally, I would like to make my main GameWorld class completely locked up and independant of any rendering engine.

i.e., GameWorld can create a world, populate it, accept input messages and take a time value (delta time) to update the GameWorld. Completely on it's own without any 3rd party, OpenGL, DirectX, OGRE3D etc. proprietry engine.

For those in the know, what is the best (or most common sense) way to 'interface' such a closed system? The renderering engine (which I'll call AssociatedRenderer) basically needs to have knowledge of each entity it renders. For all intents and purposes, it's needs a "BaseGameEntity" pointer handed to it for each entity in the game, updated each loop cycle.

Should I add an AssociatedRenderer 'interface' class to each BaseGameEntity that has the following properties?



class AssociatedRenderer {
- void Attach(BaseGameEntity *); // i.e., ->Attach(this);
called in BaseGameEntity constructor

- void Update(void); // i.e., in OpenGL this draws, in OGRE
this updates entity positions.

}


... and leave it to each project that uses GameWorld how to implement AssociatedRenderer?

The downside is that I end up with different versions of AssociatedRenderer in each project that implements it differently. Could get confusing very quickly.

3 comments:

  1. Unless you're really considering to support multiple rendering systems, I wouldn't bother. You'll run the risk of losing time over-engineering something you won't be using anyway.

    These days I would just commit to a rendering engine (like Ogre) and run with that.

    ReplyDelete
  2. Yeah, I think you're right. In fact, as OGRE has worked so nicely on both my Win and OSX setups, it makes sense to just go ahead with that.

    In fact, it took a surprisingly short amount of time today to just plug the GameWorld into OGRE for testing. Horrible screenshot here, but each of those Ogre Heads is a GameWorld entity.

    screenshot

    ReplyDelete
  3. I would first finish the core game part, then worry about something I know I won't need =)

    ReplyDelete