Git Product home page Git Product logo

bitecs's Introduction

❤ ❤ ❤
bitECS

Version Minzipped Downloads License

Functional, minimal, data-oriented, ultra-high performance ECS library written using JavaScript TypedArrays.

✨ Features

🔮 Simple, declarative API 🔥 Blazing fast iteration
🔍 Powerful & performant queries 💾 Serialization included
🍃 Zero dependencies 🌐 Node or browser
🤏 ~5kb minzipped 🏷 TypeScript support
❤ Made with love 🔺 glMatrix support

📈 Benchmarks

noctjs/ecs-benchmark ddmills/js-ecs-benchmarks

💿 Install

npm i bitecs

📘 Documentation

🏁 Getting Started
📑 API
FAQ
🏛 Tutorial

🕹 Example

import {
  createWorld,
  Types,
  defineComponent,
  defineQuery,
  addEntity,
  addComponent,
  pipe,
} from 'bitecs'

const Vector3 = { x: Types.f32, y: Types.f32, z: Types.f32 }
const Position = defineComponent(Vector3)
const Velocity = defineComponent(Vector3)

const movementQuery = defineQuery([Position, Velocity])

const movementSystem = (world) => {
  const { time: { delta } } = world
  const ents = movementQuery(world)
  for (let i = 0; i < ents.length; i++) {
    const eid = ents[i]
    Position.x[eid] += Velocity.x[eid] * delta
    Position.y[eid] += Velocity.y[eid] * delta
    Position.z[eid] += Velocity.z[eid] * delta
  }
  return world
}

const timeSystem = world => {
  const { time } = world
  const now = performance.now()
  const delta = now - time.then
  time.delta = delta
  time.elapsed += delta
  time.then = now
  return world
}

const pipeline = pipe(movementSystem, timeSystem)

const world = createWorld()
world.time = { delta: 0, elapsed: 0, then: performance.now() }

const eid = addEntity(world)
addComponent(world, Position, eid)
addComponent(world, Velocity, eid)
Velocity.x[eid] = 1.23
Velocity.y[eid] = 1.23

setInterval(() => {
  pipeline(world)
}, 16)

🔌 Powering

bitecs's People

Contributors

natethegreatt avatar ooflorent avatar supremetechnopriest avatar robertlong avatar sebovzeoueb avatar wulffhunter avatar dependabot[bot] avatar netpro2k avatar aditya-mitra avatar dannyfritz avatar vegeta897 avatar endershadow8 avatar foundrium avatar fielding avatar glensargent avatar johnshaughnessy avatar juliangarnier avatar krispya avatar worbunkel avatar codingbitsdev avatar tresky avatar

Stargazers

Michael avatar

Forkers

blopata

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.