@benev/archimedes 0.1.0-2 → 0.1.0-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -10
- package/package.json +4 -4
- package/s/ecs/index.ts +6 -4
- package/s/ecs/parts/apply-change.ts +33 -0
- package/s/ecs/parts/change.ts +27 -0
- package/s/ecs/parts/entities.ts +98 -0
- package/s/ecs/parts/execute-systems.ts +18 -0
- package/s/ecs/parts/lifecycle.ts +30 -0
- package/s/ecs/parts/types.ts +25 -0
- package/s/ecs/test/setup-example.ts +49 -0
- package/s/ecs/test.ts +75 -48
- package/x/ecs/index.d.ts +6 -3
- package/x/ecs/index.js +6 -3
- package/x/ecs/index.js.map +1 -1
- package/x/ecs/parts/apply-change.d.ts +3 -0
- package/x/ecs/parts/apply-change.js +30 -0
- package/x/ecs/parts/apply-change.js.map +1 -0
- package/x/ecs/parts/change.d.ts +13 -0
- package/x/ecs/parts/change.js +15 -0
- package/x/ecs/parts/change.js.map +1 -0
- package/x/ecs/parts/entities.d.ts +11 -0
- package/x/ecs/parts/entities.js +70 -0
- package/x/ecs/parts/entities.js.map +1 -0
- package/x/ecs/parts/execute-systems.d.ts +3 -0
- package/x/ecs/parts/execute-systems.js +12 -0
- package/x/ecs/parts/execute-systems.js.map +1 -0
- package/x/ecs/parts/lifecycle.d.ts +3 -0
- package/x/ecs/parts/lifecycle.js +19 -0
- package/x/ecs/parts/lifecycle.js.map +1 -0
- package/x/ecs/parts/types.d.ts +21 -0
- package/x/ecs/parts/types.js +9 -0
- package/x/ecs/parts/types.js.map +1 -0
- package/x/ecs/test/setup-example.d.ts +15 -0
- package/x/ecs/test/setup-example.js +32 -0
- package/x/ecs/test/setup-example.js.map +1 -0
- package/x/ecs/test.d.ts +2 -0
- package/x/ecs/test.js +73 -48
- package/x/ecs/test.js.map +1 -1
- package/s/ecs/parts/changers.ts +0 -16
- package/s/ecs/parts/world.ts +0 -68
- package/s/ecs/test/setup-example-world.ts +0 -42
- package/s/ecs/types.ts +0 -19
- package/s/ecs/utils/is-match.ts +0 -7
- package/s/ecs/utils/optimizer.ts +0 -38
- package/x/ecs/parts/changers.d.ts +0 -4
- package/x/ecs/parts/changers.js +0 -11
- package/x/ecs/parts/changers.js.map +0 -1
- package/x/ecs/parts/world.d.ts +0 -11
- package/x/ecs/parts/world.js +0 -59
- package/x/ecs/parts/world.js.map +0 -1
- package/x/ecs/test/setup-example-world.d.ts +0 -10
- package/x/ecs/test/setup-example-world.js +0 -31
- package/x/ecs/test/setup-example-world.js.map +0 -1
- package/x/ecs/types.d.ts +0 -12
- package/x/ecs/types.js +0 -2
- package/x/ecs/types.js.map +0 -1
- package/x/ecs/utils/is-match.d.ts +0 -2
- package/x/ecs/utils/is-match.js +0 -4
- package/x/ecs/utils/is-match.js.map +0 -1
- package/x/ecs/utils/optimizer.d.ts +0 -9
- package/x/ecs/utils/optimizer.js +0 -37
- package/x/ecs/utils/optimizer.js.map +0 -1
package/s/ecs/types.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export type Entities<C extends Components> = Map<Id, C>
|
|
3
|
-
export type Components = Record<string, unknown>
|
|
4
|
-
export type System = () => Generator<Change>
|
|
5
|
-
|
|
6
|
-
export type Id = string
|
|
7
|
-
export type AsComponents<C extends Components> = C
|
|
8
|
-
export type Change = [id: Id, components?: Partial<Components>]
|
|
9
|
-
export type Select<C extends Components, K extends keyof C> = Pick<C, K> & Partial<C>
|
|
10
|
-
|
|
11
|
-
export type LifecycleCallbacks<C extends Components, K extends keyof C> = {
|
|
12
|
-
tick: (id: Id, components: Select<C, K>) => void
|
|
13
|
-
exit: (id: Id) => void
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type LifecycleEnter<C extends Components, K extends keyof C> = (
|
|
17
|
-
(id: Id, components: Select<C, K>) => LifecycleCallbacks<C, K>
|
|
18
|
-
)
|
|
19
|
-
|
package/s/ecs/utils/is-match.ts
DELETED
package/s/ecs/utils/optimizer.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {GMap} from "@e280/stz"
|
|
3
|
-
import {isMatch} from "./is-match.js"
|
|
4
|
-
import {Components, Entities, Id, Select} from "../types.js"
|
|
5
|
-
|
|
6
|
-
export class Optimizer<C extends Components> {
|
|
7
|
-
#index = new GMap<Set<keyof C>, Entities<Partial<C>>>()
|
|
8
|
-
|
|
9
|
-
constructor(public entities: Entities<Partial<C>>) {}
|
|
10
|
-
|
|
11
|
-
obtain<K extends keyof C>(componentKeys: K[]): Entities<Select<C, K>> {
|
|
12
|
-
for (const set of this.#index.keys()) {
|
|
13
|
-
if (set.size !== componentKeys.length) continue
|
|
14
|
-
if (componentKeys.every(key => set.has(key)))
|
|
15
|
-
return this.#index.require(set) as Entities<Select<C, K>>
|
|
16
|
-
}
|
|
17
|
-
const set = new Set(componentKeys)
|
|
18
|
-
const ents: Entities<Select<C, K>> = new GMap()
|
|
19
|
-
this.#index.set(set, ents)
|
|
20
|
-
for (const [id, components] of this.entities)
|
|
21
|
-
if (isMatch(set, components))
|
|
22
|
-
ents.set(id, components as Select<C, K>)
|
|
23
|
-
return ents
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
update(id: Id, components: Partial<C>) {
|
|
27
|
-
for (const [set, ents] of this.#index) {
|
|
28
|
-
if (isMatch(set, components)) ents.set(id, components)
|
|
29
|
-
else ents.delete(id)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
eliminate(id: Id) {
|
|
34
|
-
for (const ents of this.#index.values())
|
|
35
|
-
ents.delete(id)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Change, Components, Id } from "../types.js";
|
|
2
|
-
export declare function create<C extends Components>(components: Partial<C>): Change;
|
|
3
|
-
export declare function update<C extends Components>(id: Id, components: Partial<C>): Change;
|
|
4
|
-
export declare function del(id: Id): Change;
|
package/x/ecs/parts/changers.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { makeId } from "./make-id.js";
|
|
2
|
-
export function create(components) {
|
|
3
|
-
return [makeId(), components];
|
|
4
|
-
}
|
|
5
|
-
export function update(id, components) {
|
|
6
|
-
return [id, components];
|
|
7
|
-
}
|
|
8
|
-
export function del(id) {
|
|
9
|
-
return [id];
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=changers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"changers.js","sourceRoot":"","sources":["../../../s/ecs/parts/changers.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAA;AAGnC,MAAM,UAAU,MAAM,CAAuB,UAAsB;IAClE,OAAO,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC,CAAA;AAC9B,CAAC;AAED,MAAM,UAAU,MAAM,CAAuB,EAAM,EAAE,UAAsB;IAC1E,OAAO,CAAC,EAAE,EAAE,UAAU,CAAC,CAAA;AACxB,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,EAAM;IACzB,OAAO,CAAC,EAAE,CAAC,CAAA;AACZ,CAAC"}
|
package/x/ecs/parts/world.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Change, Components, Entities, Id, LifecycleEnter, Select, System } from "../types.js";
|
|
2
|
-
export declare class World<C extends Components> {
|
|
3
|
-
#private;
|
|
4
|
-
entities: Entities<Partial<C>>;
|
|
5
|
-
constructor(entities?: Entities<Partial<C>>);
|
|
6
|
-
require<C2 extends Partial<C> = Partial<C>>(id: Id): C2 & Partial<C>;
|
|
7
|
-
select<K extends keyof C>(...required: K[]): Generator<[id: string, components: Select<C, K>], void, unknown>;
|
|
8
|
-
lifecycle<K extends keyof C>(required: K[], enter: LifecycleEnter<C, K>): () => Generator<never, void, unknown>;
|
|
9
|
-
apply([id, components]: Change): string;
|
|
10
|
-
execute(systems: System[]): Change[];
|
|
11
|
-
}
|
package/x/ecs/parts/world.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { GMap } from "@e280/stz";
|
|
2
|
-
import { Optimizer } from "../utils/optimizer.js";
|
|
3
|
-
export class World {
|
|
4
|
-
entities;
|
|
5
|
-
#optimizer;
|
|
6
|
-
constructor(entities = new Map()) {
|
|
7
|
-
this.entities = entities;
|
|
8
|
-
this.#optimizer = new Optimizer(entities);
|
|
9
|
-
}
|
|
10
|
-
require(id) {
|
|
11
|
-
return GMap.require(this.entities, id);
|
|
12
|
-
}
|
|
13
|
-
*select(...required) {
|
|
14
|
-
for (const entity of this.#optimizer.obtain(required)) {
|
|
15
|
-
const [, components] = entity;
|
|
16
|
-
if (required.every(r => r in components))
|
|
17
|
-
yield entity;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
lifecycle(required, enter) {
|
|
21
|
-
const alive = new GMap();
|
|
22
|
-
const sel = () => this.select(...required);
|
|
23
|
-
return function* () {
|
|
24
|
-
const current = new Map(sel());
|
|
25
|
-
for (const [id, callbacks] of alive) {
|
|
26
|
-
if (current.has(id))
|
|
27
|
-
continue;
|
|
28
|
-
alive.delete(id);
|
|
29
|
-
callbacks.exit(id);
|
|
30
|
-
}
|
|
31
|
-
for (const [id, components] of current) {
|
|
32
|
-
const callbacks = alive.guarantee(id, () => enter(id, components));
|
|
33
|
-
callbacks.tick(id, components);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
apply([id, components]) {
|
|
38
|
-
if (components) {
|
|
39
|
-
this.entities.set(id, components);
|
|
40
|
-
this.#optimizer.update(id, components);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
this.entities.delete(id);
|
|
44
|
-
this.#optimizer.eliminate(id);
|
|
45
|
-
}
|
|
46
|
-
return id;
|
|
47
|
-
}
|
|
48
|
-
execute(systems) {
|
|
49
|
-
const changes = [];
|
|
50
|
-
for (const system of systems) {
|
|
51
|
-
for (const change of system()) {
|
|
52
|
-
this.apply(change);
|
|
53
|
-
changes.push(change);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return changes;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
//# sourceMappingURL=world.js.map
|
package/x/ecs/parts/world.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"world.js","sourceRoot":"","sources":["../../../s/ecs/parts/world.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAA;AAG/C,MAAM,OAAO,KAAK;IAGE;IAFnB,UAAU,CAAA;IAEV,YAAmB,WAAiC,IAAI,GAAG,EAAE;QAA1C,aAAQ,GAAR,QAAQ,CAAkC;QAC5D,IAAI,CAAC,UAAU,GAAG,IAAI,SAAS,CAAI,QAAQ,CAAC,CAAA;IAC7C,CAAC;IAED,OAAO,CAAqC,EAAM;QACjD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAoB,CAAA;IAC1D,CAAC;IAED,CAAC,MAAM,CAAoB,GAAG,QAAa;QAC1C,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvD,MAAM,CAAC,EAAC,UAAU,CAAC,GAAG,MAAM,CAAA;YAC5B,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,UAAU,CAAC;gBACvC,MAAM,MAA4C,CAAA;QACpD,CAAC;IACF,CAAC;IAED,SAAS,CAAoB,QAAa,EAAE,KAA2B;QACtE,MAAM,KAAK,GAAG,IAAI,IAAI,EAAgC,CAAA;QACtD,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAA;QAE1C,OAAO,QAAQ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CAAC,MAAM,CAAC,CAAA;gBAClB,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YACrB,CAAC;QACF,CAAC;QACD,OAAO,OAAO,CAAA;IACf,CAAC;CACD"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { World } from "../parts/world.js";
|
|
2
|
-
export declare function setupExampleWorld(): {
|
|
3
|
-
world: World<{
|
|
4
|
-
health: number;
|
|
5
|
-
bleed: number;
|
|
6
|
-
mana: number;
|
|
7
|
-
manaRegen: number;
|
|
8
|
-
}>;
|
|
9
|
-
systems: (() => Generator<import("../types.js").Change, void, unknown>)[];
|
|
10
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { World } from "../parts/world.js";
|
|
2
|
-
import { del, update } from "../parts/changers.js";
|
|
3
|
-
export function setupExampleWorld() {
|
|
4
|
-
const world = new World();
|
|
5
|
-
const systems = [
|
|
6
|
-
function* manaRegen() {
|
|
7
|
-
for (const [id, c] of world.select("mana", "manaRegen")) {
|
|
8
|
-
if (c.manaRegen !== 0) {
|
|
9
|
-
const mana = c.mana + c.manaRegen;
|
|
10
|
-
yield update(id, { ...c, mana });
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
function* bleeding() {
|
|
15
|
-
for (const [id, c] of world.select("health", "bleed")) {
|
|
16
|
-
if (c.bleed !== 0) {
|
|
17
|
-
const health = c.health - c.bleed;
|
|
18
|
-
yield update(id, { ...c, health });
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
function* death() {
|
|
23
|
-
for (const [id, c] of world.select("health")) {
|
|
24
|
-
if (c.health <= 0)
|
|
25
|
-
yield del(id);
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
];
|
|
29
|
-
return { world, systems };
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=setup-example-world.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup-example-world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I,CAAC;oBAChB,MAAM,GAAG,CAAC,EAAE,CAAC,CAAA;YACf,CAAC;QACF,CAAC;KACD,CAAA;IAED,OAAO,EAAC,KAAK,EAAE,OAAO,EAAC,CAAA;AACxB,CAAC"}
|
package/x/ecs/types.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export type Entities<C extends Components> = Map<Id, C>;
|
|
2
|
-
export type Components = Record<string, unknown>;
|
|
3
|
-
export type System = () => Generator<Change>;
|
|
4
|
-
export type Id = string;
|
|
5
|
-
export type AsComponents<C extends Components> = C;
|
|
6
|
-
export type Change = [id: Id, components?: Partial<Components>];
|
|
7
|
-
export type Select<C extends Components, K extends keyof C> = Pick<C, K> & Partial<C>;
|
|
8
|
-
export type LifecycleCallbacks<C extends Components, K extends keyof C> = {
|
|
9
|
-
tick: (id: Id, components: Select<C, K>) => void;
|
|
10
|
-
exit: (id: Id) => void;
|
|
11
|
-
};
|
|
12
|
-
export type LifecycleEnter<C extends Components, K extends keyof C> = ((id: Id, components: Select<C, K>) => LifecycleCallbacks<C, K>);
|
package/x/ecs/types.js
DELETED
package/x/ecs/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../s/ecs/types.ts"],"names":[],"mappings":""}
|
package/x/ecs/utils/is-match.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-match.js","sourceRoot":"","sources":["../../../s/ecs/utils/is-match.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,OAAO,CAAC,GAAa,EAAE,UAAsB;IAC5D,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,UAAU,CAAC,CAAA;AAChD,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Components, Entities, Id, Select } from "../types.js";
|
|
2
|
-
export declare class Optimizer<C extends Components> {
|
|
3
|
-
#private;
|
|
4
|
-
entities: Entities<Partial<C>>;
|
|
5
|
-
constructor(entities: Entities<Partial<C>>);
|
|
6
|
-
obtain<K extends keyof C>(componentKeys: K[]): Entities<Select<C, K>>;
|
|
7
|
-
update(id: Id, components: Partial<C>): void;
|
|
8
|
-
eliminate(id: Id): void;
|
|
9
|
-
}
|
package/x/ecs/utils/optimizer.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { GMap } from "@e280/stz";
|
|
2
|
-
import { isMatch } from "./is-match.js";
|
|
3
|
-
export class Optimizer {
|
|
4
|
-
entities;
|
|
5
|
-
#index = new GMap();
|
|
6
|
-
constructor(entities) {
|
|
7
|
-
this.entities = entities;
|
|
8
|
-
}
|
|
9
|
-
obtain(componentKeys) {
|
|
10
|
-
for (const set of this.#index.keys()) {
|
|
11
|
-
if (set.size !== componentKeys.length)
|
|
12
|
-
continue;
|
|
13
|
-
if (componentKeys.every(key => set.has(key)))
|
|
14
|
-
return this.#index.require(set);
|
|
15
|
-
}
|
|
16
|
-
const set = new Set(componentKeys);
|
|
17
|
-
const ents = new GMap();
|
|
18
|
-
this.#index.set(set, ents);
|
|
19
|
-
for (const [id, components] of this.entities)
|
|
20
|
-
if (isMatch(set, components))
|
|
21
|
-
ents.set(id, components);
|
|
22
|
-
return ents;
|
|
23
|
-
}
|
|
24
|
-
update(id, components) {
|
|
25
|
-
for (const [set, ents] of this.#index) {
|
|
26
|
-
if (isMatch(set, components))
|
|
27
|
-
ents.set(id, components);
|
|
28
|
-
else
|
|
29
|
-
ents.delete(id);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
eliminate(id) {
|
|
33
|
-
for (const ents of this.#index.values())
|
|
34
|
-
ents.delete(id);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=optimizer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"optimizer.js","sourceRoot":"","sources":["../../../s/ecs/utils/optimizer.ts"],"names":[],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