Fast HTML5 Entity-Component-System library
npm install --save makr
var makr = require('makr')
var em = makr(Position, Motion, Display /* … component types */)
Fast HTML5 Entity-Component-System library
License: MIT License
It would make more sense and be useful for systems which deal with every entity. And you wouldn't even use query like that in the first place if you expected it to return nothing.
Changing it to the suggested behavior is as simple as removing this:
if (mask === 0) {
return []
}
At the moment the speed of querying depends on the amount of entities. As this should be one of the most common operations performed I think it should be optimized. I did a little experiment where I'd store all entities with the same mask in an array which could be accessed by their mask through a hashmap.
var hashMap = {}
hashMap[0] = [] //All entities with mask 0 stored here
hashMap[5] = [] //All entities with mask 5 stored here
...etc
The entities then move around based on their mask. This lets us get a constant query time no matter the amount of entities by simply testing the query mask against each index in the hashmap. Initial tests gave ~5mil queries per second no matter the amount of entities (with hardly any optimizations applied).
var result = []
var entityMasks = Object.keys(hashMap)
for (var index = 0; index < entityMasks.length; index++) {
var entityMask = entityMasks[index]
if ((entityMask & mask) === mask) {
Array.prototype.push.apply(result, this._entityCache[entityMask])
}
}
The problem is that you'd have to keep track of each entitys index in its hashMap[entityMask] array to remove it from there when its mask changes or it is destroyed. You'd also have to update the indices of the other entities in the mask array which would in turn make any operation that changes the mask of entities slower (the speed would now be determined by the amount of entities with the same mask and the index of the entity that was removed).
Thoughts? Or perhaps other ideas on how to do it? If something was unclear I'll explain it better.
Not sure if I'm being dense, but I've attempted to use this library with both rollup and webpack to no avail. With both of those build tools I'm getting the same error: Unknown component type 'undefined'.
import makr from 'makr';
class Body {
constructor(x, y) {
this.x = x
this.y = y
this.dx = 0
this.dy = 0
}
}
class Display {
constructor(img) {
this.img = img
}
}
// Create the entity manager
const em = makr(Body, Display)
const entity = em.create();
entity.add(Body); // error
entity.add(Display);
I should also mention that I'm using Babel 6 to transpile. I'm going to attempt to use 6to5 as I read in a forum post that you were using that.
Edit: Nevermind, it seems that 6to5 is actally Babel. Didn't realise that.
I think you mention somewhere that events are not needed in your library, I am new to ECS - can you show some example of how you handle communication between systems? Do events not help keep each system, behaviour without interdependencies?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.