Published: 2013-03-25 22:59:12
March 25, 2013 15:57
March 25, 2013 15:57
Entity systems are growing in popularity, with well-known examples like Unity, and lesser known frameworks like Actionscript frameworks Ember2, Xember and my own Ash. There’s a very good reason for this; they simplify game architecture, encourage clean separation of responsibilities in your code, and are fun to use.
Up until fairly recent years, game programmers have consistently used a deep class hierarchy to represent game entities. The tide is beginning to shift from this use of deep hierarchies to a variety of methods that compose a game entity object as an aggregation of components. This article explains what this means, and explores some of the benefits and practical considerations of such an approach. I will describe my personal experience in implementing this system on a large code base, including how to sell the idea to other programmers and management.
I'm all about data-driven design. How much about data-driven design am I? I don't think a game engine should contain a single line of game-specific code. Not one. No hardcoded weapon types. No hardcoded HUD layout. No hardcoded unit AI. Nada. Zip. Zilch. I'm pretty inflexible in this regard.
Re-Use
The first and more sweeping reason is that once a game has shipped, its code tends to be reused for subsequent titles. Unfortunately, it takes a lot of understanding on the part of management and a lot of restraint on the part of developers to scrub the game engine of all its assumptions related to the old title; most teams would rather just launch wholesale into new development immediately. That's why the player input system was named PlayerF22Control for most of the development on I-Magic's F-18 game and why I suspect that Neversoft's Tony Hawk 3 still has a character class named CBruce.
Specialization
The second reason to prefer data-driven design is comparative advantage. A group of people will produce the most, for the least cost, when each member of the group performs the task for which he is, relatively, best suited. Heinlein was wrong. Specialization isn't just for ants. It's for anyone who wants to get things done and doesn't have ten lifetimes in which to do it.