background preloader

Component-Based OOP

Facebook Twitter

Evolve Your Hierarchy. Refactoring Game Entities with Components 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. Different games have different requirements as to what is needed in a game entity, but in most games the concept of a game entity is quite similar.

A game entity is some object that exists in the game world, usually the object is visible to the player, and usually it can move around. Some example entities: MissileCarTankGrenadeGunHeroPedestrianAlienJetpackMed-kitRock Why so long? Resources. Component · Decoupling Patterns · Game Programming Patterns. Game Engine Design – Component Based Entities ← Entropy Interactive. Component based entities are becoming increasingly popular. They are a design pattern that can greatly improve the maintainability and flexibility of your game code. This tutorial will describe what component based entities are and how to design them.

A Java implementation is provided which can easily be translated to other languages. Object Hierarchies Traditionally, game entities used object hierarchies. This object hierarchy is simple enough. It is not clear what the apartment should inherit from. Composition The alternative to object hierarchies is a concept called composition. There are several advantages to this design pattern. Composition can also make game entities more flexible. A third advantage is that the program becomes easier to understand. Communication The difficulty of a composition is communication. On the other end of the spectrum is the abstract approach. A Hybrid Approach The implementation described here lies somewhere between the two previous methods. Implementation. Refactoring The Object System » Legend of Grimrock. Welcome to the first development update of Grimrock 2!

In this post I’m going to talk about a big internal change under the hood of the engine. The discussion should be especially interesting to modders. A small disclaimer before we get started: many things that we talk about in these updates are work in progress, incomplete or ideas that may not have been proven in practice to work. Therefore many things could very well change or be removed in the shipping version. We also want to keep some things, especially the puzzles, the plotline and probably most of the monsters as secrets to avoid spoiling the fun. There are a number of problems with the class based object model. Another classic problem is fitting new features to the class hierarchy. The final nail to the coffin of class hierarchies is rigidity.

Luckily there is another kind of object model which has gotten pretty popular in game developer circles because it happens to solve all these problems neatly. Game Programming Patterns / Behaving Patterns / Component.