/ecs

An MIT-licensed Python entity/component system library for games.

Primary LanguagePythonOtherNOASSERTION

ecs

https://travis-ci.org/seanfisk/ecs.png

ecs is an MIT-licensed Python entity/component system library for games.

There are many articles on the Internet advocating a switch to entity-based systems for game logic. However, many authors seem to burn themselves out telling why the old inheritance-based approach is problematic and how an entity system will solve your problems — without ever really explaining what it is or how to do it. This project attempts to provide an actual implementation for use in real games.

The library is called an "entity/component system" library rather than an "entity system," as the entity portion is just one building block of the total concept.

The module is called ecs. ces is too close to something else, and while there is another library called ecs, it's for an E-Commerce service from Amazon and is unlikely to name-clash in your projects.

As this module is in somewhat rarefied air, with not a lot of company, the concepts and API may change during development. Inspiration is taken from the Ash framework for ActionScript 3.0 and Artemis framework for Java.

Concepts

ecs stands for Entity, Component, and System. Each of these parts is important. So what are these?

Entity
Simply a unique identifier, used to label components as belonging to a logical grouping.
Component
A collection of data. Has no behavior associated with it.
System
Piece of code to operate on data in components for a single frame.

Details

ecs defines a few core core classes:

  • Entity
  • Component
  • System
  • EntityManager
  • SystemManager

The Entity class is simply a representation of a unique identifier, and is not to be subclassed. The Component class is intended to be subclassed for your custom components. System is also intended to be subclassed for your custom systems.

The EntityManager is a database that stores Component subclasses, referenced by their type and entity ID. The SystemManager maintains a set of System instances and allows them to perform their operations.

The real action happens in the update() method of your subclassed System classes. A System instance queries the EntityManager database for a set of Component subclasses and operates on the data contained in them.

Compatibility

ecs is compatible with CPython 2.6, 2.7, 3.3, and PyPy 2.2.0. CPython 3.0–3.2 may also work, but Python 3 users are encouraged to upgrade to Python 3.3. If upgrade is not a possibility for you, please file a issue! Tests ensuring compatibility are run continuously on Travis-CI and can also be run locally using tox.

Examples, Documentation, Contributions, and Issues

ecs is a very young project. As such, work on examples and documentation is just getting started. However, if you have read some of the articles mentioned on the Entity Systems wiki, use of ecs should be quite clear. The codebase is quite small and simple and has a comprehensive set of tests to go with it. Those with questions of any sort are encouraged to open an issue. Contributions are always welcome!

Similar Projects

This module was written because current entity/component system implementations for Python are scarce or underdeveloped. Here are some other projects similar to this one:

  • PyArtemis, a seemingly unmaintained port of Artemis to Python
  • Marcus von Appen's python-utils, which include ebs, an entity system framework similar to ecs. However, ebs does not draw a distinction between entity and component, which we feel is significant.

Further Reading

Entity/component systems are a relatively new concept. The canonical source for all entity system-related topics is the Entity Systems wiki, created by Adam Martin. Adam Martin has also written abundantly in his series of posts about Entity Systems, which are a great read for those just getting familiar with the concept.

History

ecs was originally created by Kevin Ward, and is now maintained by Sean Fisk. I (Sean) am using ecs in a game written using the Panda3D game engine.