0.1.11 • Published 5 years ago
modecs v0.1.11
🌌 ModECS 🌌
Small, fast, data-oriented, runtime-composable ECS library written in JavaScript.
Features
- ~5 KB gzipped
- Classless ES6
- Performance focused
- Runtime composable
- Promotes reusability
Planned
- Topological ordering of system loops based on component type dependencies
- Serializable state (all the way down to systems & their update functions)
- External store adapters
- V programming language port with Node bindings to the same API
Install
npm i modecs
Example
const ModECS = require('modecs')
const engine = ModECS()
// register components with a name and shape
engine.registerComponent('POSITION', { x: 0, y: 0 })
engine.registerComponent('TARGET', { x: 0, y: 0 })
engine.registerSystem(
// name of the system
'Movement',
// component types required by the system
['POSITION','TARGET'],
// a setup function to initialize the system with (happens once)
() => {
const speed = 10
// return the update function to be called every tick
// position and target components, as well as the entityId they exist on are injected
return (position, target, entityId) => {
position.x += target.x * speed * engine.time.delta
position.y += target.y * speed * engine.time.delta
}
}
)
// createEntity returns a new ID
const entityID1 = engine.createEntity()
engine.addEntity(entityID1)
const entityID2 = engine.createEntity()
engine.addEntity(entityID2) // must add entity to the engine before adding components
// add components to an ID with a name and shape
engine.addComponent(entityID2, 'POSITION', { x: 50 })
engine.addComponent(entityID2, 'TARGET', { x: 1, y: 1 }) // entity2 will move southeast
engine.start()
Check out the Introduction for more details.
0.1.11
5 years ago
0.1.10
5 years ago
0.1.9
5 years ago
0.1.8
5 years ago
0.1.7
5 years ago
0.1.6
5 years ago
0.1.5
5 years ago
0.1.4
5 years ago
0.1.3
5 years ago
0.1.2
5 years ago
0.1.1
5 years ago
0.1.0
5 years ago
0.0.7
5 years ago
0.0.6
5 years ago
0.0.5
5 years ago
0.0.4
5 years ago
0.0.3
5 years ago
0.0.2
5 years ago
0.0.1
5 years ago