Thursday, September 16, 2010

Spatial Containers

I'm realizing that there are a number of places within The Render Engine that need to be tightened, cleaned up, optimized, or rewritten entirely.  That isn't a bad thing, because it means that the engine will either be faster or easier to work with.  One such example is that I've been trying to figure out how, or where, I can use threading with WebWorkers in the engine.  I had thought that maybe collision detection could take advantage of just such a thing.

As I was studying the code, I realized that the methods which update the collision model are contained everywhere except the spatial containers.  How odd, I thought to myself, that I should make such a simple mistake.  It would take a very specific knowledge of the collisions containers to know how to create your own or to utilize an existing one!  So, I did some rewriting and moved the code out of the ColliderComponent and into SpatialContainer.  This way, as objects move about, all they need to do is let the collision model know where they are (and, of course, who they are).  That simplified a lot, and cleaned up the code dramatically.

By componentizing the system, from the start, I've been able to keep these inner workings well enough hidden from the typical engine's user.  But this was just atrocious (in my opinion) and needed to be redone.  It's not a speed improvement, but it does take the burden off of the user.  That is a win to me that was worth implementing.

I know there will be more, and some will be more difficult to implement than others, but in the end I believe that The Render Engine v2.0 will be a better engine because of it.  Now, back to trying to figure out how I can take advantage of threading within the engine...

No comments:

Post a Comment