Skip to content

Commit

Permalink
Add js13k-ecs
Browse files Browse the repository at this point in the history
  • Loading branch information
ooflorent committed Feb 2, 2021
1 parent b23f915 commit 9dba27e
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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%)
Expand All @@ -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%)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
90 changes: 90 additions & 0 deletions src/cases/js13k-ecs.js
Original file line number Diff line number Diff line change
@@ -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);
};
}
24 changes: 13 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -21,17 +22,18 @@ const update_3_queries_suite = suite(
`Update (entities: ${4 * NUM_ENTITIES}, queries: 3)`
);

add_implementation(jakeklassen__ecs);
add_implementation(bitecs);
add_implementation(ecsy);
add_implementation(ent_comp);
add_implementation(flock_ecs);
add_implementation(geotic);
add_implementation(goodluck);
add_implementation(makr);
add_implementation(perform_ecs);
add_implementation(picoes);
add_implementation(tiny_ecs);
// add_implementation(jakeklassen__ecs);
// add_implementation(bitecs);
// add_implementation(ecsy);
// 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);
// add_implementation(tiny_ecs);

create_and_delete_suite.run();
update_3_queries_suite.run();
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 9dba27e

Please sign in to comment.