GithubHelp home page GithubHelp logo

sgtcodfish / ashleycpp Goto Github PK

View Code? Open in Web Editor NEW
17.0 4.0 1.0 873 KB

A C++ clone of Ashley, a Java entity framework.

License: Other

CMake 0.96% C++ 86.84% Makefile 0.56% M4 0.74% C 0.49% Python 9.83% Shell 0.58%

ashleycpp's Introduction

AshleyCPP - C++11 ECS Framework

Build Status

AshleyCPP is a lightweight, cross-platform and easy to use Entity framework for C++11 based on the Java entity framework Ashley, targeted towards game development. It contains all the classes you need to get started making a game using a pure, ECS-oriented style.

It prioritises speed and simplicity and mirrors the public API of the original where possible to make it easy to learn, quick to run and simple to debug - and doubly so for users of the Java original.

The original is inspired by the Ash and Artemis frameworks.

AshleyCPP is a personal project and while there are no guarantees that it will compile and work, the master branch on GitHub should compile and function properly and should be usable for making projects right now. There is currently no guarantee of API stability between versions, or indeed any meaningful versioning.

Building

AshleyCPP uses the CMake build system and comes with three build targets; the debug library, "AshleyCPP-d", the release library "AshleyCPP" and the (imaginatively named) executable "AshleyCPPTest". The test program uses GTest, which is bundled.

To build the library from source, install a relatively recent version of CMake, navigate to a copy of the source and do the following:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=<CHOOSE ONE: Debug/Release> ..

and proceed as normal for your environment. If you don't care about the tests, you can run cmake -DEXCLUDE_TESTS=TRUE .. leaving you with just the library.

Usage Notes and API Changes

While AshleyCPP strives to match the exported public API of the Java original, differences in the languages mean that some differences exist. Such changes are listed in detail in APICHANGES.md, but a quickstart is given below.

First in foremost: In situations where in Java you'd use .class to get a Java class, in C++ you can #include <typeinfo> and:

typeid(ComponentClass); // Equivalent to ComponentClass.class in Java.  

// e.g. get a Family* that matches Entity having both ComponentA and ComponentB
ashley::Family::getFor({typeid(ComponentA), typeid(ComponentB)});
  • The whole library is enclosed in the ashley namespace. Use using namespace ashley; to save typing if you want.
  • You can #include individual headers (organised similarly to the Java packages) or #include "Ashley/Ashley.hpp"
  • Java generic functions that take vararg lists of Class<? extends Component> are replaced by std::initializer_list<std::type_index>. Some functions also provide template overloads which may be easier and faster to use; check the documentation for specific occurrences.
  • The library enforces ownership using std::unique_ptr; the engine owns all entities and systems that are passed into it and unless they're removed, all entities and systems die with the engine. Likewise, each Entity strictly owns its attached components. This minimises the risk of leaking memory.

For more specific changes, see the APICHANGES.md file.

Implementation Status

Ticked classes have both their implementation and tests complete.

  • Core
    • Component
    • ComponentMapper
    • ComponentType
    • Engine
    • Entity
    • EntityListener
    • EntitySystem
    • Family
  • Signals
    • Signal
    • Listener
  • Systems
    • IteratingSystem
    • IntervalSystem
    • IntervalIteratingSystem
    • SortedIteratingSystem
  • Util
    • ObjectPool
    • Poolable

NB:

  • Bag and ImmutableArray will probably not be implemented, there are better native C++ choices without reinventing the wheel.
  • Currently implements as far as Ashley commit #a276fe45.

Nice to have features:

  • Refactor/rewrite handling of entity ids, using a C++11 constexpr compile time hash and a templated Component class to prevent using a virtual method and vtable. Will lead to smaller components and better cache coherency.

License

AshleyCPP has the same license as the original, as shown here:

Ashley is licensed under the Apache 2 License, meaning you can use it free of charge, without strings attached in commercial and non-commercial projects. We love to get (non-mandatory) credit in case you release a game or app using Ashley!

A mention if you find AshleyCPP useful would be very much appreciated!

ashleycpp's People

Contributors

sgtcodfish avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

darnogor

ashleycpp's Issues

Implement Optional Instrumentation

Add an optional (toggled by a define) instrumentation system which allows users to track various statistics about the usage of various entities, systems and components.

It's important that this is all entirely optional, to avoid any performance impact in releases.

Examples of stats we could collect:

  • System ordering
  • Number of fetches within an update (i.e. usage of componentmapper)
  • The number of matching entities in an update cycle

Multithreading systems

It would be nice to have a base class, which called the component processEntities with multiple threads (from a pool). So it can be much faster (hopefully). The original ashley doesn't have this feature, but it would be a nice addition to this one.

See this theoretical post: https://gamedev.stackexchange.com/a/62754

Feature Parity with Java Original

Currently README.md suggests we have parity as of this commit.

We should get up to date, and update the README.

Todo:

  • Add EntitySystem::getEngine commit
    | see #9
  • Add EntityListener priority commit
  • Check what happens when adding the same entity to and engine twice, and define behaviour if neccessary issue
  • Check (+ test?) this issue
  • Consider splitting Engine class into smaller classes as in ashley PR#196

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.