Giter Club home page Giter Club logo

bitecs's Introduction

Notice

New alpha branch in-development: https://github.com/NateTheGreatt/bitECS/tree/v0.3.0a

Features:

  • Functional API
  • Serialization
  • Change detecting and inverted (Not) queries
  • And more

๐Ÿ‘พ bitECS ๐Ÿ‘พ

Tiny, data-driven, high performance ECS library written using JavaScript TypedArrays.

Features

  • <3kb gzipped
  • Zero dependencies
  • Node or Browser
  • Blazing fast

Install

npm i bitecs

Example

import World from 'bitecs'

// Create a world
const world = World()

// Register some components
world.registerComponent('POSITION', { x: 'float32', y: 'float32' })
world.registerComponent('VELOCITY', { vx: 'int8', vy: 'int8', speed: 'uint16' })

// Register a system
world.registerSystem({
  name: 'MOVEMENT',
  components: ['POSITION', 'VELOCITY'],
  update: (POSITION, VELOCITY) => entities => {
    for (let i = 0; i < entities.length; i++) {
      const eid = entities[i]
      POSITION.x[eid] += VELOCITY.vx[eid] * VELOCITY.speed[eid]
      POSITION.y[eid] += VELOCITY.vy[eid] * VELOCITY.speed[eid]
    }
  }
})

// Create a query
const positions = world.createQuery(['POSITION']) // array will continuously update, no need to recreate

// Create an entity
const eid = world.addEntity()

// Add components to entity
world.addComponent('POSITION', eid, { x: 100, y: 100 })
world.addComponent('VELOCITY', eid, { vx: 1, vy: -1, speed: 100 })

// Create an event loop and step world
setInterval(() => {
  world.step()
}, 1000 / 30) // 30 tick on server

// For browser, use frame rate
const loop = () => {
  world.step()
  requestAnimationFrame(loop)
}
loop()

Full documentation and feature rich examples can be found here.

bitecs's People

Contributors

dependabot[bot] avatar natethegreatt avatar ooflorent avatar supremetechnopriest avatar

Stargazers

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