Skip to content

An entity component system for JavaScript built on shared array buffers

Notifications You must be signed in to change notification settings

NicholasHallman/quecs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QUECS

Quecs, pronounced quicks, is an entity component sytem for JavaScript inspired by bitecs, ecsy and becsy.

Example

const world = new World();

//define components
const Position = world.defineComponent({
    x: Types.i16,
    y: Types.i16,
});
const Player = world.defineComponent({});

// create entities
const {id: playerEid} = world.createEntity()
    .addComponent(Position)
    .addComponent(Player);

// set entity's component data
Position.x[playerEid] = 20;
Position.y[playerEid] = 10;

// define a query
const posQuery = world.defineQuery(Position);

// define a system
const moveHorizontalSystem = world => {
    const eids = posQuery();
    for(eid of eids) {
        Position.x[eid] += 1;
    }
}

//define a threaded system
const threadVerticleMoveSystem = threadedSystem([Position], (eids, [Position]) => {
    for(const eid of eids) {
        Position.y[eid] = 10;
    }
})

// create a phase to contain the systems
const physPhase = world.createPhase('physics');
// create the pipeline
physPhase.addSystem(moveHorizontalSystem)
    .addSystem(threadVerticleMoveSystem);

// run the phase
world.runPhase('physics');

Features

Entities

  • Creating entities
  • Adding Components
  • Remove Components
  • Chain notation

Components

  • Defining Components with typed properties
  • Defining Components with array properties
  • Manages store size
  • Single buffer for array properties
  • Indexable sub views for array properties

Phase

  • Define a phase
  • Add systems to a phase
  • Run the phase

Queries

  • Define query
  • Get entities from query
  • Cache entities in query
  • Not modifyer

Multithreading

  • Function for threading system
  • Check host environment to determine thread count and allocate worker pool
  • Shared array buffers for easy worker access
  • Entity subset threading (One thread runs a subset of entities against a system)
  • Multi phase threading (One thread runs per Phase)

About

An entity component system for JavaScript built on shared array buffers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published