Need help with anax?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

miguelmartin75
440 Stars 47 Forks MIT License 296 Commits 30 Opened issues

Description

An open source C++ entity system.

Services available

!
?

Need anything else?

Contributors list

anax Build Status

anax is an open source C++ entity system designed to be portable, lightweight and easy to use. It is aimed toward Game Development, however it would be possible to use it for other projects.

What's an Entity System?

An entity system, or entity component system is a pattern for building complex extensible projects (typically games). It separates functionality into three major parts: components, systems and entities. Where entities are used to describe an object within the game, components are used to store data for the entities to describe them, and systems are used to contain game logic.

You can read about them further here.

Getting Started

Dependencies

To compile, install, and use anax, a C++11 compliant compiler is required.

Installation

(mkdir -p build && cmake .. && make install)

A more detailed tutorial on how to install is available on the wiki.

Quick Tutorial

This section will explain how to use the library, but it will not go into much specific detail. If you want a more detailed guide, please refer to this page on the wiki.

NOTE:

It is assumed you know what an Entity System is.

The World

A World is used to describe you game world or 'entity system' if you will. You must always have at least one World object in order to use anax. e.g.

World world;

Entities

An entity is what you use to describe an object in your game. e.g. a player, a gun, etc. To create entities, you must have a World object, and call

createEntity()
on the World object.
World world;
// ... 
Entity entity = world.createEntity();

Entities are implemented as an identifier (32 or 64 bits). The Entity objects have a reference to the World object, and may be accessed via

getWorld()
. The
Entity
class acts as a handle to entities, you can think of it as a pointer. You may have multiple
Entity
handles to represent the same entity, e.g.
Entity entity1 = world.createEntity();
Entity entity2 = entity1; // entity2 and entity1 "point" to the same entity

To destroy/kill an entity, you can either call

World::killEntity
or
Entity::kill
. e.g.
entity.kill();
// or
world.killEntity(entity);

Once you have killed an entity, other copies of your entity handles will automatically be invalidated and will not be of use (an assertion will occur if you attempt to use an invalidated entity). e.g.

Entity entity1 = world.createEntity();
Entity entity2 = entity1;

entity1.kill();

// This will cause an assertion // see below for details about this member function entity2.addComponent(0, 3, 5);

Components

A Component is used to describe data for an Entity, for example: the position, velocity, etc. To define your own component, you simply inherit from

Component
.
struct PositionComponent : anax::Component
{
    // ...
};

You may add/remove/get components to entities through the public methods defined in the entity class.

  • addComponent
  • removeComponent
  • getComponent

e.g.

// adding components
entity.addComponent(2, 3, 5);

// removing components entity.removeComponent();

// getting components auto pos = entity.getComponent();

Systems

A System is used to contain on entities with specific components (require or exclude a set of component types). It is typically used to update, render or perform some logic these entities.

struct MovementSystem : anax::System<:requires velocitycomponent>>
{
    // ...
};

That is, a movement system requires entities with a

PositionComponent
and
VelocityComponent
. You may determine if an entity is removed/added to the system via these two override-able (virtual) methods:
  • onEntityAdded(Entity&)
  • onEntityRemoved(Entity&)

That's basically it, you can pretty much go and code. If you want more details, check the documentation or this getting started guide on the wiki.

Get Involved

Want to get involved with the project? You are free to help out on the project, but please see the

CONTRIBUTING.md
file before doing so.

Also, don't be afraid to send pull requests, especially for those that fix bugs (email me if you're unsure)!

License

See LICENSE.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.