Skip to content
April 22, 2011 / racoonacoon

Setting up a Scene class…and breaking everything else

In my last post I mentioned how we got the basics of deferred rendering working. Since then I have made a bit of an improvement to the frame rate by making use of the stencil buffer. I would normally delve into explanation on the stencil buffer and show examples of what I am taking about, but since Claudius is currently in a broken state I am unable to do so. Wait? Claudius is broken? Yea, well, one of the things CJ and I really want to do before the class is over is have a bunch of levels that you can progress to. You know, you start at level 1, and, once you beat it, go to the next level and so on and so forth in an endlessly blissful progression. Regrettably, Claudius didn’t really have the facilities to handle this well. This was perhaps an oversight on my part, but given that the core of Claudius was quickly built to help me catch up on long overdue graphics labs a semester back (and to force myself to learn C++ correctly), I’m not really going to be all that hard on myself. Basically, the internal design of the system went something like this:

To put it simply, there were far too many interdependencies. The Updater and Renderer relied on Claudius which in turn relied on the Updater and Renderer which in turn used Claudius to get a reference to the single Register. While I enjoy the concept of having a separate class that acts like a database to store all of our objects (the object register) it wasn’t implemented all that well with the rest of the system. This also made level progression difficult and error prone. Instead of being able to create a logical grouping of the items you want in a level, you instead have to manually add and remove all the items from the register. If you left something there you didn’t want then it would erroneously appear in the new level. We had to do something about this…

As always in computer programming, anything can be solved with another layer of indirection:

The solution to remove all the nasty interdependencies was to create a Scene class that has its own personal copy of the Register, Updater, and Renderer. The Updater and Renderer now requires a Scene pointer to be passed to them when they are created to bind them to that one scene. This allows the updater & renderer to easily ask the scene for a pointer to the register so it can get the items it needs. Claudius now only has to worry about keeping tabs on a single Scene object.  The beautiful thing about this design is that the Scene in Claudius can easily be swapped out for a different scene, allowing for multiple levels to be created very easily. It’s literally as easy as this:

Scene* scene1 = new Scene();

/*Add all the objects you want into this scene*/

claudiusReference->ChangeScene(scene1);

Once it gets time to go to the next level, its a breeze.

Scene* scene2 = new Scene();

/*Add all the objects you want in the new scene*/

claudiusReference->ChangeScene(scene2);

Another thing I am working on is getting level loading to be asynchronous. In other words, we don’t freeze up the entire system while a level loads. Instead, we still allow the game loop to process while we load a scene. This will allows us to display another scene (such as an interactive loading screen) while the scene we want loads in the background. I plan to use the OpenMP cross platform threading library for this aspect, as I’m not a masochist who likes working directly with Window’s hardware threads.

So yeah, as you can probably expect, moving from diagram1 to diagram2 results in many things being broken along the way. Mostly internal things, but a few external code bits also relied on Claudius for a reference for the ObjectRegister. Since the ObjectRegister is one of the most important parts of Claudius (it allows components to talk to one another) I’ll have to make sure objects can still grab a copy of the register if they need it. Anyway, I better get back to fixing everything so we have something more to show for than just a broken engine! Over and out!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: