PDF ArchiveHistorical archive . public document
2012 . January . 8

Entity Component System

Entity Component System.pdf . by Paul

PDF 1.5 3 pages 429.88 KB Filed 08/01/2012
Download this PDF
Entity Component System.pdf
Web reader . 3 pages
Page 1 of 3, Entity Component System
1 / 3

File preview

ENTITY COMPONENT SYSTEM The engine uses a component-based system1 for defining game entities such as the player, enemies and any other interactive objects. WIP 1 “Game Programming Patterns / Component” (http://gameprogrammingpatterns.com/component.html). Robert Nystrom. Logic Components These components deal strictly with entity game logic, such as reacting to game events, making decisions, responding to button presses, etc. Typically, a single generic Component class is available for all purposes, however, this approach has some limitations. An alternative design was used, suggested by Radical Entertainment at GDC 2009, 2 who proposed separating components into Attributes and Behaviors.3 Attributes and Behaviors in Short Attributes manage one category of data and any logic they have is limited in scope. For example, Health might make sure that its current value is never greater than its maximum value, and it can even notify other components when the current value drops below a certain critical level, but it does not contain any more complex logic. Attributes are dependent on no other Attributes or Behaviors. Behaviors control how the entity reacts to game events, make decisions, and alter the values of Attributes as needed. Behaviors are dependent on some of the Attributes, but they cannot directly interact with each other – they only react to how Attributes’ values are changed by the other Behaviors and to the events they are sent. Communication and Dependencies Behaviors can directly read and modify Attributes’ values, but they are not allowed to directly interact with each other. Both types of components are also able to post/ subscribe to specific events to/ from the other components through the entity’s local event manager. Behaviors may also post game-level events that Behaviors belonging to other entities can intercept. 2 “Theory and Practice of the Game Object Component Architecture” (http://www.gdcvault.com/free/gdc-canada09). Marcin Chady, Radical Entertainment. GDC 2009. 3 The words “Attribute”, “Behavior” and “Component” will refer to the actual classes, while “component” refers to the general concept and covers all the previous three words. Behaviors are meant to access Attributes’ values directly in cases where that information is needed on-demand, or when it is very frequently changing. An example is a RunningBehavior reading and modifying the entity’s StaminaAttribute. There are also cases where an Attribute’s value changes rarely and when that occurs, the correct Behaviors need to be notified. Continuously checking the Attribute’s value is inefficient; the better alternative is for Behaviors to subscribe to the type of event they are interested in and for the Attribute to notify them, as in the previous example with the entity’s Health reaching a critical level. Using a generic Component class, the relations between objects would be entirely unpredictable since any one component can communicate with any other. This makes it hard to alter or remove existing components and doing so may require rewriting others as well. There’s also the issue of what to do when two Components can both logically hold one piece of data. In an Attributes/ Behaviors system, dependencies between components are well defined: Attributes have no dependencies, and Behaviors may depend on some of the Attributes and on none of the other Behaviors; this means that they can be modified or removed without any risk. Building Entities An entity is built by loading and initializing all its components. The engine reads an entity definition file that specifies all the Attributes and Behaviors that make up the entity, as well as their dependencies; the components are then created from the corresponding script files. Using a generic Component, the building process would involve two passes through the entire list of components: one to create them and a second to resolve dependencies. This is because it cannot be ensured that all dependencies of a Component are available when it is created, especially when two Components depend on each other. Behaviors, however, can depend only on Attributes, which in turn have no dependencies. This means the engine can first create all the Attributes and then link the Behaviors to the Attributes they need, as they are being constructed. Updating State Behaviors process game logic and as such their state needs to be constantly updated by the engine. Attributes, however, serve only as data containers whose values are modified by Behaviors only when needed, which means they do not need to be explicitly updated by the engine. 4 This can improve efficiency by reducing the number of components that need to be updated. Generic Component classes, even if used only as data containers, offer no way for the engine to know that they do not need updating (their update function will still be called, even if it does nothing). 4 Any actions Attributes perform – checking values for consistency, sending events to other components – are done when Behaviors get or set their values.

Download Entity Component System

Entity Component System.pdf . PDF . 429.88 KB . 3 pages

Download PDF

File information

File name
Entity Component System.pdf
Author
Paul
Size
429.88 KB
Pages
3 pages
PDF version
1.5
Produced with
Microsoft® Word 2010
Filed on
08/01/2012
Page views
2 689
Document ID
entity-component-system
MD5
d9775e13ff682f5ba4882e1ff59ea248
SHA-512
667c51bb392fa352e1450bc77fa96a034e58e7b185da50d1bf8f4ccc1517b942c7bb7b018cca81ff8a3e231d458f9ea52d7b6cfe78ca4e8c626b99cbdc5f5c82

Share this document

This address never changes. It is the one to keep, to send, or to cite.

Shorter, for a text message or a post with a character limit.

To link to this document from a website or a blog.