How to install Entity Component Systems: Anax, EntityX, Artemis (C++)

I’m currently testing three Entity Component System (ECS) libraries for inclusion in TilemapKit: Anax, EntityX, Artemis (C++).

I thought I’ll write down the installation steps for you. Since two of them rely on CMAKE for building they won’t work out of the box when dropped into an Xcode project.

The steps outlined here are tested with a new SpriteKit project created with Xcode 7.1 and compile for OS X. I assume iOS will be the same.

Working knowledge of Xcode and github is assumed. Also remember: if you use Objective-C and C++ together in the same project you’ll have to rename the .m files to .mm to compile the code as Objective-C++.

Adding Anax to an Xcode project

Anax uses CMAKE as build system. Therefore if you want to use it in a “regular” project that doesn’t use CMAKE the library requires a couple code changes, mainly replacing the CMAKE variables with actual values and fixing a compiler warning. It is still fairly easy to set up, should take less than 15 minutes.

  • Clone the repository
  • Rename include/anax/Config.hpp.inl to Config.hpp
  • Add all files in folders include and src to the desired target
  • Edit Config.hpp:
    • Replace all occurances of #cmakedefine with #define
    • Replace all CMAKE @identifier@ variables with actual values (see CMakeLists.txt for current values).
    • The affected lines and their values are:
  • Optional: edit EntityIdPool.cpp (line ~74). In function ::get change the return line to this one (cast added to suppress compiler warning):
  • Edit target’s Build Settings:
    • Locate the Header Search Paths setting
    • Add an entry pointing to anax’ include folder, for instance: $(SRCROOT)/anax/include
  • Import the main header in a source file:
    • #import "anax.hpp"
  • Done! Anax should compile without warnings using Xcode’s default build settings.

Adding EntityX to an Xcode project

EntityX also uses CMAKE and requires a few minor code changes as well. You should also ensure to not add or to remove all files with the _test suffix – unfortunately these unit tests are in the same folders as the rest of the source files. Nevertheless EntityX is easy to set up in less than 15 minutes.

  • Clone the repository
  • Rename entity/config.h.in to config.h
  • Add the folder entityx/entityx to the desired target
    • Note: that’s the folder containing config.h
    • Caution: do not add or subsequently remove all files with _test.cc suffix. You do not need to include the unit tests. Including them will cause linker errors (duplicate symbols).
      • It’s these files you should remove/avoid: Benchmarks_test.cc, Dependencies_test.cc, Entity_test.cc, Event_test.cc, Pool_test.cc, System_test.cc, TagsComponent_test.cc
  • Edit Config.h:
    • Replace all CMAKE @identifier@ variables with actual values (see CMakeLists.txt for current values).
    • The affected lines and their values are:
  • Edit target’s Build Settings:
    • Locate the Header Search Paths setting
    • Add an entry pointing to EntityX’ root folder (where README.md is), for instance: $(SRCROOT)/entityx
      • Caution: do not point the header search path to the entityx/entityx folder but the folder above that!
  • Import the main header in a source file:
    • #import "entityx.hpp"
  • Done! EntityX should compile without warnings using Xcode’s default build settings.

Adding Artemis-Cpp to an Xcode project

Artemis-Cpp is the easiest ECS to install as it does not rely on CMAKE. It only requires an (optional) code fix to avoid an ominous warning that occurs only in Xcode 7. Artemis should be ready to work with in under 10 minutes.

  • Clone the repository
  • Add all files in folders include and src to the desired target
    • Optional: you may want to remove the file Entity (no extension), it’s empty and doesn’t seem to serve any purpose.
  • Optional: edit SystemManager.cpp (line ~30):
    • Adding a cast to (void) fixes the warning: Expression with side effects will be evaluated despite being used as an operand to ‘typeid’
  • Edit target’s Build Settings:
    • Locate the Header Search Paths setting
    • Add an entry pointing to Artemis’ include folder, for instance: $(SRCROOT)/Artemis-Cpp/include
  • Import the main header in a source file:
    • #import "Artemis.h"
  • Done! Artemis-Cpp should compile without warnings using Xcode’s default build settings.

Which one should I go with?

I can’t say that yet – I’m still evaluating and benchmarking. I’ll post a summary of what I like/dislike about each ECS and which one I’ll be going with for TilemapKit by tomorrow. Stay tuned!

Comments

Loading Facebook Comments ...

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Pingback: Entity Component System Compared: EntityX, Anax, Artemis