Giter Site home page Giter Site logo

lua-emgr's Introduction

emgr

Table of Contents

emgr, or Entity Manager, is a simple Lua library which implements a paradigm similar to Entity Component System (ECS).

The main difference with ECS is that the Component and System concepts are merged into the Manager.

See src.

Concept

Entity

An entity is a table which is a set of managers, defining a composition. It also has some methods and will free itself from managers on garbage collection.

Operations and data are not owned by an entity; its role is to bind managers to an object with automatic memory management.

Manager

A manager can be anything implementing the manager interface (methods). It defines and manages a component for the entities.

Operations can be implemented by managers, maybe depending on other managers, or functions processing entities and multiple managers, etc.

โš ๏ธ
To ensure proper garbage collection, init() / free() should be called from the entity and the manager must not have a strong reference to entities just to manage the internal data.

API

-- Create an entity.
emgr.entity()

-- Entity.

-- Initialize the entity into a manager.
-- Can be called even if already initialized.
entity:init(manager, ...)

-- Free the entity from a manager.
-- Can be called even if already freed.
entity:free(manager)

-- Check if the entity has a manager as composition (i.e. is managed by a manager).
-- Low-level alternative: check `entity[manager]`
entity:has(manager)

-- Manager interface, called by corresponding entity methods.

manager:__init(entity, ...)
manager:__free(entity)
Example 1. Getting managers from an entity.
for manager in pairs(entity) do ... end

lua-emgr's People

Contributors

imagicthecat avatar

Watchers

 avatar  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.