Skip to content

Commit

Permalink
Upgraded libraries, added javelin, re-enabled ecsy, generated new ben…
Browse files Browse the repository at this point in the history
…chmarks (#19)

* Upgraded to latest release of libraries

* Added Javelin ecs

* Re-enabled ecsy benchmarks

* Updated benchmark results (not running under debugger)

* Fixed major error in component add/remove for miniplex and javelin targets

* Removed results.txt artifact
  • Loading branch information
robknopf authored Mar 3, 2024
1 parent dde7267 commit ad4a9dc
Show file tree
Hide file tree
Showing 9 changed files with 500 additions and 342 deletions.
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as libs from './libraries';
import * as suts from './suites';
import * as libs from './libraries/index.js';
import * as suts from './suites/index.js';
import elegantSpinner from 'elegant-spinner';
import logUpdate from 'log-update';

Expand Down Expand Up @@ -44,8 +44,7 @@ suites.forEach((suite) => {
const lib = `${libIdx}/${libraries.length}`;

logUpdate(
`${frame()} ${suite.name} - ${lib} ${
library.name
`${frame()} ${suite.name} - ${lib} ${library.name
} ${progress.toFixed(0)}%`
);
}
Expand Down
32 changes: 17 additions & 15 deletions libraries/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
export { default as GeoticLibrary } from './lib-geotic';
export { default as PerformEcsLibrary } from './lib-perform-ecs';
export { default as ApeEcsLibrary } from './lib-ape-ecs';
// export { default as EcsyLibrary } from './lib-ecsy';
export { default as NanoEcsLibrary } from './lib-nano-ecs';
export { default as TinyEcsLibrary } from './lib-tiny-ecs';
export { default as miniplexLibrary } from './lib-miniplex';
export { default as YaglEcsLibrary } from './lib-yagl-ecs';
export { default as UecsEcsLibrary } from './lib-uecs';
export { default as BitecsEcsLibrary } from './lib-bitecs';
export { default as GoodluckLibrary } from './lib-goodluck';
export { default as PicoesLibrary } from './lib-picoes';
export { default as WolfEcsLibrary } from './lib-wolf-ecs';
export { default as PiecsLibrary } from './lib-piecs';
export { default as HarmonyEcsLibrary } from './lib-harmony-ecs';
export { default as miniplexLibrary } from './lib-miniplex.js';
export { default as JavelinEcsLibrary } from './lib-javelin-ecs.js';
export { default as GeoticLibrary } from './lib-geotic.js';
export { default as PerformEcsLibrary } from './lib-perform-ecs.js';
export { default as NanoEcsLibrary } from './lib-nano-ecs.js';
export { default as TinyEcsLibrary } from './lib-tiny-ecs.js';
export { default as YaglEcsLibrary } from './lib-yagl-ecs.js';
export { default as UecsEcsLibrary } from './lib-uecs.js';
export { default as BitecsEcsLibrary } from './lib-bitecs.js';
export { default as GoodluckLibrary } from './lib-goodluck.js';
export { default as PicoesLibrary } from './lib-picoes.js';
export { default as WolfEcsLibrary } from './lib-wolf-ecs.js';
export { default as PiecsLibrary } from './lib-piecs.js';
export { default as HarmonyEcsLibrary } from './lib-harmony-ecs.js';
export { default as EcsyLibrary } from './lib-ecsy.js';
export { default as ApeEcsLibrary } from './lib-ape-ecs.js';

6 changes: 3 additions & 3 deletions libraries/lib-harmony-ecs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { World, Schema, Entity, Query, formats } from 'harmony-ecs';
import { World, Schema, Entity, Query, Format } from 'harmony-ecs';

const Vector2 = { x: formats.float32, y: formats.float32 };
const Vector2 = { x: Format.float32, y: Format.float32 };

export default {
name: 'harmony-ecs',
Expand Down Expand Up @@ -34,7 +34,7 @@ export default {
},

destroyEntity(id) {
Entity.delete(this.world, id);
Entity.destroy(this.world, id);
},

cleanup() {
Expand Down
72 changes: 72 additions & 0 deletions libraries/lib-javelin-ecs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import pkg from '@javelin/ecs';
const { createWorld, createQuery, toComponent, number } = pkg;

let updateCount = 0;

const movementSystem = (world) => {
let movingEntities = createQuery(Position, Velocity);

/* Return the system */
return (world) => {
/* Now apply the velocity to the position. */
for (const [entities, [positions, velocities]] of movingEntities) {
for (let i = 0; i < entities.length; i++) {
positions[i].x += velocities[i].x;
positions[i].y += velocities[i].y;
positions[i].z += velocities[i].z;

updateCount++;
}
}
};
};

const Velocity = {
x: number,
y: number,
z: number
}
const Position = {
x: number,
y: number,
z: number
}

export default {
name: 'javelin-ecs',
suites: ['Add/Remove', 'Destroy', 'Velocity'],
setup() {
this.world = createWorld();
this.movementSystem = movementSystem(this.world);
this.world.addSystem(this.movementSystem);
},
createEntity() {
return this.world.create();
},
addPositionComponent(entity) {
this.world.attach(entity, toComponent({ x: 0, y: 0, z: 0 }, Position));
},
addVelocityComponent(entity) {
this.world.attach(entity, toComponent({ x: 1, y: 2, z: 3 }, Velocity));
},
removePositionComponent(entity) {
this.world.detach(entity, Position);
},
removeVelocityComponent(entity) {
this.world.detach(entity, Velocity);
},
destroyEntity(entity) {
this.world.destroy(entity);
},
cleanup() {
updateCount = 0;
this.world = null;
this.movementSystem = null;
},
updateMovementSystem() {
this.world.step();
},
getMovementSystemUpdateCount() {
return updateCount;
},
};
14 changes: 5 additions & 9 deletions libraries/lib-miniplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const movementSystem = (world) => {

/* Return the system */
return () => {
movingEntities ||= world.archetype('position', 'velocity');
movingEntities ||= world.with('position', 'velocity');

/* Get the index for the archetype we created earlier. */
const { entities } = movingEntities;
Expand All @@ -31,21 +31,17 @@ export default {
this.movementSystem = movementSystem(this.world);
},
createEntity() {
return this.world.createEntity({});
return this.world.add({});
},
addPositionComponent(entity) {
/* Entities are just JavaScript objects, and components just properties on
those objects. In Typescript, you get full type checking of all your
entities and components. TypeScript is great and you should use it! (But
miniplex will happily work without it, too.) */
this.world.addComponent(entity, {
position: { x: 0, y: 0, z: 0 },
});
this.world.addComponent(entity, "position", { x: 0, y: 0, z: 0 });
},
addVelocityComponent(entity) {
this.world.addComponent(entity, {
velocity: { x: 1, y: 2, z: 3 },
});
this.world.addComponent(entity, "velocity", { x: 1, y: 2, z: 3 });
},
removePositionComponent(entity) {
this.world.removeComponent(entity, 'position');
Expand All @@ -54,7 +50,7 @@ export default {
this.world.removeComponent(entity, 'velocity');
},
destroyEntity(entity) {
this.world.destroyEntity(entity);
this.world.remove(entity);
},
cleanup() {
updateCount = 0;
Expand Down
Loading

0 comments on commit ad4a9dc

Please sign in to comment.