Thanks to visit codestin.com
Credit goes to github.com

Skip to content

nnt1054/bitECS

 
 

Repository files navigation

✨ What's in this Fork?

Added a Dirty modifier for serialization. If an Entity has a Component with at least one changed Dirty property since the last serialization call, then all properties for that Component for that Entity will be serialized.

const ComponentA = defineComponent({
  dirtyFlag: Types.f32,
  x: Types.f32,
  y: Types.f32,
  z: Types.f32,
})

const dirtySerializer = defineSerializer([Dirty(ComponentA.dirtyFlag)])
let packet = dirtySerializer(world)

ComponentA.x[eid]++

// not watching changes to ComponentA.x so the packet is empty
packet = dirtySerializer(world)
console.log(packet.byteLength) // => 0

ComponentA.dirtyFlag[eid]++

// since dirtyFlag has changed, serialize all Component props for eid
packet = dirtySerializer(world)
console.log(packet.byteLength) // => 52

⚠️ v0.4 coming soon! Read the docs here

❤ ❤ ❤
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

About

Flexible, minimal, data-oriented ECS library for Typescript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 99.9%
  • TypeScript 0.1%