diff --git a/README.md b/README.md index 3204824..3bc936d 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ - [flock-ecs](https://github.com/dannyfritz/flock-ecs) - [geotic](https://github.com/ddmills/geotic) - [goodluck](https://github.com/piesku/goodluck) +- [js13k-ecs](https://github.com/kutuluk/js13k-ecs) - [makr](https://github.com/makrjs/makr) - [perform-ecs](https://github.com/fireveined/perform-ecs) - [picoes](https://github.com/ayebear/picoes) @@ -30,6 +31,7 @@ Create and delete (entities: 4000) flock-ecs: 79 op/s (±19.40%) geotic: 63 op/s (±4.27%) goodluck: 1,665 op/s (±6.60%) + js13k-ecs: 70 op/s (±1.48%) makr: 3,112 op/s (±1.59%) perform-ecs: 366 op/s (±1.66%) picoes: 134 op/s (±4.97%) @@ -47,6 +49,7 @@ Update (entities: 4000, queries: 3) flock-ecs: 1,933 op/s (±2.89%) geotic: 18,772 op/s (±1.25%) goodluck: 22,509 op/s (±1.56%) + js13k-ecs: 10,814 op/s (±3.40%) makr: 8,446 op/s (±1.25%) perform-ecs: 43,760 op/s (±0.61%) picoes: 1,174 op/s (±1.11%) diff --git a/package.json b/package.json index dee3302..921d7de 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "flock-ecs": "^0.1.5", "geotic": "^4.1.4", "goodluck": "^5.2.0", + "js13k-ecs": "^0.1.4", "kleur": "^4.1.4", "makr": "^2.1.1", "perform-ecs": "^0.7.8", diff --git a/src/cases/js13k-ecs.js b/src/cases/js13k-ecs.js new file mode 100644 index 0000000..21d3327 --- /dev/null +++ b/src/cases/js13k-ecs.js @@ -0,0 +1,90 @@ +import ecs from "js13k-ecs"; + +function Position(x, y) { + this.x = x; + this.y = y; +} + +function Velocity(dx, dy) { + this.dx = dx; + this.dy = dy; +} + +function Animation(frame, size) { + this.frame = frame; + this.size = size; +} + +function Render(sprite) { + this.sprite = sprite; +} + +ecs.register(Position); +ecs.register(Velocity); +ecs.register(Animation); +ecs.register(Render); + +function insertEntities(count) { + let entities = []; + + for (let i = 0; i < count; i++) { + let e1 = ecs.create(); + let e2 = ecs.create(); + let e3 = ecs.create(); + let e4 = ecs.create(); + + e1.add(new Position(0, 0)); + e2.add(new Position(0, 0), new Render("A")); + e3.add(new Position(0, 0), new Render("A"), new Animation(0, 5)); + e4.add( + new Position(0, 0), + new Render("A"), + new Animation(0, 5), + new Velocity(0.1, 0.1) + ); + + entities.push(e1, e2, e3, e4); + } + + return entities; +} + +export const name = "js13k-ecs"; + +export function bench_create_delete(count) { + return () => { + for (let entity of insertEntities(count)) { + entity.eject(); + } + }; +} + +export function bench_update(count) { + insertEntities(count); + + let movables = ecs.select(Position, Velocity); + let animations = ecs.select(Animation); + let renderables = ecs.select(Position, Render); + + function movablesFn(entity) { + let pos = entity.get(Position); + let vel = entity.get(Velocity); + pos.x += vel.dx; + pos.y += vel.dy; + } + + function animationsFn(entity) { + let anim = entity.get(Animation); + anim.frame = (anim.frame + 1) % anim.size; + } + + function renderablesFn(entity) { + if (!entity) throw new Error(); + } + + return () => { + movables.iterate(movablesFn); + animations.iterate(animationsFn); + renderables.iterate(renderablesFn); + }; +} diff --git a/src/index.js b/src/index.js index 7439308..60a82f5 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,7 @@ import * as flock_ecs from "./cases/flock-ecs.js"; import * as geotic from "./cases/geotic.js"; import * as goodluck from "./cases/goodluck.js"; import * as jakeklassen__ecs from "./cases/jakeklassen__ecs.js"; +import * as js13k_ecs from "./cases/js13k-ecs.js"; import * as makr from "./cases/makr.js"; import * as perform_ecs from "./cases/perform-ecs.js"; import * as picoes from "./cases/picoes.js"; @@ -28,6 +29,7 @@ add_implementation(ent_comp); add_implementation(flock_ecs); add_implementation(geotic); add_implementation(goodluck); +add_implementation(js13k_ecs); add_implementation(makr); add_implementation(perform_ecs); add_implementation(picoes); diff --git a/yarn.lock b/yarn.lock index 5e10af5..cabd754 100644 --- a/yarn.lock +++ b/yarn.lock @@ -53,6 +53,11 @@ goodluck@^5.2.0: resolved "https://registry.yarnpkg.com/goodluck/-/goodluck-5.2.0.tgz#8f06ca10318292af75fb2e0ffa7a332f640553d6" integrity sha512-DzPuYxSuVObwbpyjKMYbMRucfcn6pt8HQSLEU5zPEp7twN6C7LlhUdOBVQTd48WHCCBgSH+WJr8XO8Pxc2JCyQ== +js13k-ecs@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/js13k-ecs/-/js13k-ecs-0.1.4.tgz#680b1f37c6f898f8e704232678507bbb08677717" + integrity sha512-F/OgEkkKMIyZ4b5znThA72oqQDusYFB9m3GZOhjXR2yHR3U6me7363Dc80gM+g3kz9gajhEe3adMstefNeGbqw== + kleur@^4.1.4: version "4.1.4" resolved "https://registry.yarnpkg.com/kleur/-/kleur-4.1.4.tgz#8c202987d7e577766d039a8cd461934c01cda04d"