GithubHelp home page GithubHelp logo

picotron-ecs-framework's Introduction

The ecs.lua file contains the entire ECS framework. The rest of this repository is a demo which both shows the framework in use, and provides a concrete sample of how to use it.

API

ecs

The ECS framework module.

ecs.world(bitmask_size) Creates a new world.

  • bitmask_size [optional] - The number of 64-bit integers to use for bitmasks. Default is 4. You can register up to bitmask_size*64 components in a world, but higher numbers have a small performance cost.
  • Returns: The world object.

ecs.comp(world,tab,key,constructor) Creates a new component type.

  • world [optional] - The world object to register the component with.
  • tab [optional] - The table to put the component in.
  • key - The name of the component type.
  • constructor - The function which creates a new instance of the component.
  • Returns: A component type table which can be called to create new components.

ecs.sys(world,include,exclude,func) Creates a new set of system data.

  • world [optional] - The world object to register the system with.
  • include - The components which entities must have to be included in the query.
  • exclude [optional] - The components which entities must not have to be included in the query
  • func - The function which processes receives the query and processes the entities.
  • Returns: The system data.

world

A single independent instance of an ECS.

world:comp(tab,key,constructor) Alias for ecs.comp(world,tab,key,constructor) which automatically registers the component with the world.

world:sys(include,exclude,func) Alias for ecs.sys(world,include,exclude,func) which automatically registers the system with the world.

world:reg_comp(comp_type) Registers a component type with the world.

  • comp_type - The component type to register.
  • Returns: The world object, for chaining.

world:reg_sys(sys_data) Registers a system with the world.

  • system_data - The system data to register.
  • Returns: The world object, for chaining.

world:ent() Creates a new entity.

  • Returns: The entity.

world:run(sys_data,...) Executes a system for the world.

  • sys_data - The system data to execute.
  • ... - Additional arguments to pass to the system.
  • Returns: The world object, for chaining.

query

An iterator which returns a component for each entry in a system's include argument, plus the entity which possesses them.

entity

entity.comps A map of all components on the entity. Keys are component type names, values are components. Can be used to fetch optional components or the components of referenced entities during system execution.

entity:add(comp,key) Adds a component to the entity. Calling a function created by ecs.comp will return both arguments at once.

  • comp - The component to add.
  • key - The name of the component type.
  • Returns: The entity, for chaining.

entity:remove(key) Removes a component from the entity. Note that the act of removing it from the entity.comps table is deferred until the next system execution call.

  • key - The name of the component type.
  • Returns: The entity, for chaining.

entity:ref() Creates a weak reference to the entity. Useful for referencing entities from other entities.

  • Returns: A callable table. When called, it will return the entity if it still exists, or nil if not.

entity:destroy() Queues the entity for destruction. Use this during system execution.

entity:destroy_immediate() Destroys the entity. Use this outside of system execution.

picotron-ecs-framework's People

Contributors

abledbody avatar

Stargazers

aerger avatar skooch avatar

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.