Coder Social home page Coder Social logo

jecs's Introduction

License: Apache 2.0 Wally

Just an ECS

jecs is a stupidly fast Entity Component System (ECS).

  • Entity Relationships as first class citizens
  • Iterate 350,000 entities at 60 frames per second
  • Type-safe Luau API
  • Zero-dependency package
  • Optimized for column-major operations
  • Cache friendly archetype/SoA storage
  • Unit tested for stability

Example

local world = jecs.World.new()
local pair = jecs.pair

local ChildOf = world:component()
local Name = world:component()

local function parent(entity) 
    return world:target(entity, ChildOf)
end
local function getName(entity) 
    return world:get(entity, Name)
end

local alice = world:entity()
world:set(alice, Name, "alice")

local bob = world:entity()
world:add(bob, pair(ChildOf, alice))
world:set(bob, Name, "bob")

local sara = world:entity()
world:add(sara, pair(ChildOf, alice))
world:set(sara, Name, "sara")

print(getName(parent(sara)))

for e in world:query(pair(ChildOf, alice)) do 
    print(getName(e), "is the child of alice")
end

-- Output
-- "alice"
-- bob is the child of alice
-- sara is the child of alice

125 archetypes, 4 random components queried. Queries Can be found under /benches/query.lua

Inserting 8 components to an entity and updating them over 50 times. Insertions Can be found under /benches/insertions.lua

jecs's People

Contributors

alicesaidhi avatar howmanysmall avatar memorycode avatar outofbearspace avatar ukendio avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

jecs's Issues

WildCards

Queries should be able to have wildcard terms that can match multiple instances of a relationship

Better documentation needed

We need to add comprehensive documentation to our GitHub repository to help new contributors understand the project, its structure, and how to contribute. Proper documentation will also assist users in understanding how to use the project effectively.

Documentation should include:

  1. Overview

    • Brief description of the project.
    • Key features and functionalities.
  2. Installation

    • Prerequisites.
    • Step-by-step installation guide.
    • Configuration instructions.
  3. Usage

    • How to run the project.
    • Basic usage examples.
    • Explanation of main components.
  4. Contributing

    • Contribution guidelines.
    • How to report issues.
    • How to submit pull requests.
    • Code of conduct.
  5. FAQs

    • Common issues and troubleshooting.
    • Frequently asked questions.
  6. License

    • Licensing information.

Additional Notes:

  • Use Markdown for documentation.
  • Include images/screenshots where applicable.
  • Ensure the documentation is easy to navigate and well-organized.

Tasks:

  • Create an overview section.
  • Write installation instructions.
  • Provide usage examples.
  • Draft contributing guidelines.
  • Compile FAQs.
  • Add license information.

Cached Iterator

A lot of the computations in the queries are very expensive, e.g. populating the compatible archetypes in the world, caching indices to the the columns and unpacking the entity ID's for flags + low and high IDs for indexing and relations.

All of this overhead can be paid once up front for each system. This similar to how Matter's runtime queries work right now.

More unit tests needed!

The coverage over the codebase is pretty poor and a lot of potential edge cases have not been found yet. This is something we can add incrementally!

Sparse Components (non-movable components)

Non-movable components, that when inserted goes into the sparse set storage. The sparse component itself does not need to be moved to the destination archetype during insertion.

Benefits

  • Doesn't need to move the sparse component itself so slightly faster removals and insertions
  • Fast iteration of single sparse components since it should just iterate over the densely packed pool/column

Drawbacks

  • Explicit storage specification
  • Queries of sparse components are always slower than archetype queries except for two scenarios:
  1. if the query is just interested in a single sparse component (just iterate the dense array of the sparse set)
  2. if fragmentation is very high (like 1-2 entities per archetype, and lots of archetypes)

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.