Giter Site home page Giter Site logo

entitysystem's Introduction

EntitySystem

Managers

EntityManager

The EntityManager is the context in which Entities interact, and where they are stored. Entities are stored as a group of Units, where each type of Unit is stored contiguously in memory in UnitManagers. It keeps track of and assigns entityIds, and provides the interface between Units, Systems and the rest of the game engine.

UnitManager

UnitManagers store one UnitType each in a sorted vector on the units enityId.

Instead of Units being inserted and erased during updates, they are inserted through an insertion queue, which is emptied at the beginning every update, and erased by setting a flag, where every flagged Unit is erased together after every update. This is done to avoid iterator invalidation, and excessive reallocation.

Units

Units

Units are commonality between Events and Components.

Units make up Entities. Which Entity the Unit is owned by, is indicated by its entityId. An Entity can have any number of Units of any type.

Units have two ways of being "disabled". They can be set to be erased, in which case the Unit will be erased at the end of the current update. Units that are set to be erased on creation, will stay around for one update. They can also be set to be ignored. An ignored Unit will with immediate effect, be ignored by Systems and erased at the end of the current update.

LimitedLifetimeUnits are Units with a lifetime that is automatically decreased every update by deltatime. Once a LimitedLifetimeUnits lifetime is less than or equal to zero it is erased.

Components

Components are a type of Unit. Components are the basic building blocks of an entity. Components are only erased if done so manually.

Events

Events are a type of LimitedLifetimeUnit, and are erased automatically once lifetime is less than or equal to zero.

Basic Events do not have a target or an Entity its a part of, and its entityId is there only to uniquely identify the Event.

Targeted Events do have a target or Entity its a part of, and are only considered by Systems in context with other units with same entityId.

Systems

Systems define interaction between Entities and Events. They are updated in two parts. One update to change internal state of the System, and one update per Entity that has all the requested Units. Events are a type of LimitedLifetimeUnit, and are erased automatically once lifetime is less than or equal to zero.

Basic Events do not have a target or an Entity its a part of, and its entityId is there only to uniquely identify the Event.

Targeted Events do have a target or Entity its a part of, and are only considered by Systems in context with other units with same entityId.

Systems can optionally derive from OptionalSystemTypes. A system that derives from OptionalSystemTypes can set a bool value for every UnitType. UnitTypes are mandatory by default, that is, they need to be present for System.updateEntities to be called with each type. When a UnitType is set to optional, System.updateEntities will be called with an entity, regardless if a unit of this type was found for the entity or not.

entitysystem's People

Watchers

 avatar

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.