@benev/archimedes 0.1.0-3 → 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.
Files changed (66) hide show
  1. package/README.md +86 -10
  2. package/package.json +4 -4
  3. package/s/ecs/index.ts +6 -5
  4. package/s/ecs/parts/apply-change.ts +33 -0
  5. package/s/ecs/parts/change.ts +27 -0
  6. package/s/ecs/parts/entities.ts +98 -0
  7. package/s/ecs/parts/execute-systems.ts +18 -0
  8. package/s/ecs/parts/lifecycle.ts +30 -0
  9. package/s/ecs/parts/types.ts +25 -0
  10. package/s/ecs/test/setup-example.ts +49 -0
  11. package/s/ecs/test.ts +71 -61
  12. package/x/ecs/index.d.ts +6 -4
  13. package/x/ecs/index.js +6 -4
  14. package/x/ecs/index.js.map +1 -1
  15. package/x/ecs/parts/apply-change.d.ts +3 -0
  16. package/x/ecs/parts/apply-change.js +30 -0
  17. package/x/ecs/parts/apply-change.js.map +1 -0
  18. package/x/ecs/parts/change.d.ts +13 -0
  19. package/x/ecs/parts/change.js +15 -0
  20. package/x/ecs/parts/change.js.map +1 -0
  21. package/x/ecs/parts/entities.d.ts +11 -0
  22. package/x/ecs/parts/entities.js +70 -0
  23. package/x/ecs/parts/entities.js.map +1 -0
  24. package/x/ecs/parts/execute-systems.d.ts +3 -0
  25. package/x/ecs/parts/execute-systems.js +12 -0
  26. package/x/ecs/parts/execute-systems.js.map +1 -0
  27. package/x/ecs/parts/lifecycle.d.ts +3 -0
  28. package/x/ecs/parts/lifecycle.js +19 -0
  29. package/x/ecs/parts/lifecycle.js.map +1 -0
  30. package/x/ecs/parts/types.d.ts +21 -0
  31. package/x/ecs/parts/types.js +9 -0
  32. package/x/ecs/parts/types.js.map +1 -0
  33. package/x/ecs/test/setup-example.d.ts +15 -0
  34. package/x/ecs/test/setup-example.js +32 -0
  35. package/x/ecs/test/setup-example.js.map +1 -0
  36. package/x/ecs/test.d.ts +2 -2
  37. package/x/ecs/test.js +71 -61
  38. package/x/ecs/test.js.map +1 -1
  39. package/s/ecs/parts/changers.ts +0 -20
  40. package/s/ecs/parts/world.ts +0 -65
  41. package/s/ecs/test/setup-example-world.ts +0 -42
  42. package/s/ecs/types.ts +0 -24
  43. package/s/ecs/utils/apply-change.ts +0 -32
  44. package/s/ecs/utils/is-match.ts +0 -7
  45. package/s/ecs/utils/optimizer.ts +0 -38
  46. package/x/ecs/parts/changers.d.ts +0 -5
  47. package/x/ecs/parts/changers.js +0 -15
  48. package/x/ecs/parts/changers.js.map +0 -1
  49. package/x/ecs/parts/world.d.ts +0 -11
  50. package/x/ecs/parts/world.js +0 -58
  51. package/x/ecs/parts/world.js.map +0 -1
  52. package/x/ecs/test/setup-example-world.d.ts +0 -10
  53. package/x/ecs/test/setup-example-world.js +0 -31
  54. package/x/ecs/test/setup-example-world.js.map +0 -1
  55. package/x/ecs/types.d.ts +0 -21
  56. package/x/ecs/types.js +0 -6
  57. package/x/ecs/types.js.map +0 -1
  58. package/x/ecs/utils/apply-change.d.ts +0 -2
  59. package/x/ecs/utils/apply-change.js +0 -30
  60. package/x/ecs/utils/apply-change.js.map +0 -1
  61. package/x/ecs/utils/is-match.d.ts +0 -2
  62. package/x/ecs/utils/is-match.js +0 -4
  63. package/x/ecs/utils/is-match.js.map +0 -1
  64. package/x/ecs/utils/optimizer.d.ts +0 -9
  65. package/x/ecs/utils/optimizer.js +0 -37
  66. package/x/ecs/utils/optimizer.js.map +0 -1
@@ -1,42 +0,0 @@
1
-
2
- import {World} from "../parts/world.js"
3
- import {del, update} from "../parts/changers.js"
4
-
5
- export function setupExampleWorld() {
6
- const world = new World<{
7
- health: number
8
- bleed: number
9
- mana: number
10
- manaRegen: number
11
- }>()
12
-
13
- const systems = [
14
- function* manaRegen() {
15
- for (const [id, c] of world.select("mana", "manaRegen")) {
16
- if (c.manaRegen !== 0) {
17
- const mana = c.mana + c.manaRegen
18
- yield update(id, {...c, mana})
19
- }
20
- }
21
- },
22
-
23
- function* bleeding() {
24
- for (const [id, c] of world.select("health", "bleed")) {
25
- if (c.bleed !== 0) {
26
- const health = c.health - c.bleed
27
- yield update(id, {...c, health})
28
- }
29
- }
30
- },
31
-
32
- function* death() {
33
- for (const [id, c] of world.select("health")) {
34
- if (c.health <= 0)
35
- yield del(id)
36
- }
37
- },
38
- ]
39
-
40
- return {world, systems}
41
- }
42
-
package/s/ecs/types.ts DELETED
@@ -1,24 +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 Select<C extends Components, K extends keyof C> = Pick<C, K> & Partial<C>
9
-
10
- export enum Kind {Assign, Update}
11
- export type Delta<C extends Components> = Partial<{[K in keyof C]: C[K] | null}>
12
- export type Assign = [id: Id, kind: Kind, components?: Partial<Components>]
13
- export type Update = [id: Id, kind: Kind, delta: Delta<Components>]
14
- export type Change = Assign | Update
15
-
16
- export type LifecycleCallbacks<C extends Components, K extends keyof C> = {
17
- tick: (id: Id, components: Select<C, K>) => void
18
- exit: (id: Id) => void
19
- }
20
-
21
- export type LifecycleEnter<C extends Components, K extends keyof C> = (
22
- (id: Id, components: Select<C, K>) => LifecycleCallbacks<C, K>
23
- )
24
-
@@ -1,32 +0,0 @@
1
-
2
- import {GMap, is} from "@e280/stz"
3
- import {Assign, Change, Components, Entities, Kind, Update} from "../types.js"
4
-
5
- export function applyChangeToEntities<C extends Components>(entities: Entities<any>, change: Change) {
6
- switch (change[1]) {
7
- case Kind.Assign: return assign<C>(entities, <Assign>change)
8
- case Kind.Update: return update<C>(entities, <Update>change)
9
- default: throw new Error(`unknown change kind "${change[1]}"`)
10
- }
11
- }
12
-
13
- function assign<C extends Components>(entities: Entities<Partial<C>>, [id, _kind, components]: Assign) {
14
- if (components) {
15
- entities.set(id, components as Partial<C>)
16
- return components as Partial<C>
17
- }
18
- else {
19
- entities.delete(id)
20
- return undefined
21
- }
22
- }
23
-
24
- function update<C extends Components>(entities: Entities<Partial<C>>, [id, _kind, fresh]: Update) {
25
- const components = GMap.guarantee(entities, id, () => ({})) as any
26
- for (const [key, value] of Object.entries(fresh)) {
27
- if (!is.happy(value)) delete components[key]
28
- else components[key] = value
29
- }
30
- return components as Partial<C>
31
- }
32
-
@@ -1,7 +0,0 @@
1
-
2
- import {Components} from "../types.js"
3
-
4
- export function isMatch(set: Set<any>, components: Components) {
5
- return [...set].every(key => key in components)
6
- }
7
-
@@ -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,5 +0,0 @@
1
- import { Assign, Components, Delta, Id, Update } from "../types.js";
2
- export declare function create<C extends Components>(components: Partial<C>): Assign;
3
- export declare function assign<C extends Components>(id: Id, components: undefined | Partial<C>): Assign;
4
- export declare function del(id: Id): Assign;
5
- export declare function update<C extends Components>(id: Id, delta: Delta<C>): Update;
@@ -1,15 +0,0 @@
1
- import { makeId } from "./make-id.js";
2
- import { Kind } from "../types.js";
3
- export function create(components) {
4
- return [makeId(), Kind.Assign, components];
5
- }
6
- export function assign(id, components) {
7
- return [id, Kind.Assign, components];
8
- }
9
- export function del(id) {
10
- return [id, Kind.Assign];
11
- }
12
- export function update(id, delta) {
13
- return [id, Kind.Update, delta];
14
- }
15
- //# 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;AACnC,OAAO,EAAgC,IAAI,EAAS,MAAM,aAAa,CAAA;AAEvE,MAAM,UAAU,MAAM,CAAuB,UAAsB;IAClE,OAAO,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;AAC3C,CAAC;AAED,MAAM,UAAU,MAAM,CAAuB,EAAM,EAAE,UAAkC;IACtF,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;AACrC,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,EAAM;IACzB,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;AACzB,CAAC;AAED,MAAM,UAAU,MAAM,CAAuB,EAAM,EAAE,KAAe;IACnE,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;AAChC,CAAC"}
@@ -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(change: Change): string;
10
- execute(systems: System[]): Change[];
11
- }
@@ -1,58 +0,0 @@
1
- import { GMap } from "@e280/stz";
2
- import { Optimizer } from "../utils/optimizer.js";
3
- import { applyChangeToEntities as applyChange } from "../utils/apply-change.js";
4
- export class World {
5
- entities;
6
- #optimizer;
7
- constructor(entities = new Map()) {
8
- this.entities = entities;
9
- this.#optimizer = new Optimizer(entities);
10
- }
11
- require(id) {
12
- return GMap.require(this.entities, id);
13
- }
14
- *select(...required) {
15
- for (const entity of this.#optimizer.obtain(required)) {
16
- const [, components] = entity;
17
- if (required.every(r => r in components))
18
- yield entity;
19
- }
20
- }
21
- lifecycle(required, enter) {
22
- const alive = new GMap();
23
- const sel = () => this.select(...required);
24
- return function* () {
25
- const current = new Map(sel());
26
- for (const [id, callbacks] of alive) {
27
- if (current.has(id))
28
- continue;
29
- alive.delete(id);
30
- callbacks.exit(id);
31
- }
32
- for (const [id, components] of current) {
33
- const callbacks = alive.guarantee(id, () => enter(id, components));
34
- callbacks.tick(id, components);
35
- }
36
- };
37
- }
38
- apply(change) {
39
- const [id] = change;
40
- const components = applyChange(this.entities, change);
41
- if (components)
42
- this.#optimizer.update(id, components);
43
- else
44
- this.#optimizer.eliminate(id);
45
- return id;
46
- }
47
- execute(systems) {
48
- const changes = [];
49
- for (const system of systems) {
50
- for (const change of system()) {
51
- this.apply(change);
52
- changes.push(change);
53
- }
54
- }
55
- return changes;
56
- }
57
- }
58
- //# sourceMappingURL=world.js.map
@@ -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;AAC/C,OAAO,EAAC,qBAAqB,IAAI,WAAW,EAAC,MAAM,0BAA0B,CAAA;AAG7E,MAAM,OAAO,KAAK;IAGE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,CAAC,SAAS,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC,CAAA;gBAClE,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,UAAU,CAAC,CAAA;YAC/B,CAAC;QACF,CAAC,CAAA;IACF,CAAC;IAED,KAAK,CAAC,MAAc;QACnB,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAA;QACnB,MAAM,UAAU,GAAG,WAAW,CAAI,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;QACxD,IAAI,UAAU;YAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,EAAE,UAAU,CAAC,CAAA;;YACjD,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAClC,OAAO,EAAE,CAAA;IACV,CAAC;IAED,OAAO,CAAC,OAAiB;QACxB,MAAM,OAAO,GAAa,EAAE,CAAA;QAC5B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC9B,KAAK,MAAM,MAAM,IAAI,MAAM,EAAE,EAAE,CAAC;gBAC/B,IAAI,CAAC,KAAK,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").Assign, 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.js","sourceRoot":"","sources":["../../../s/ecs/test/setup-example-world.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,EAAC,MAAM,mBAAmB,CAAA;AACvC,OAAO,EAAC,GAAG,EAAE,MAAM,EAAC,MAAM,sBAAsB,CAAA;AAEhD,MAAM,UAAU,iBAAiB;IAChC,MAAM,KAAK,GAAG,IAAI,KAAK,EAKnB,CAAA;IAEJ,MAAM,OAAO,GAAG;QACf,QAAQ,CAAC,CAAC,SAAS;YAClB,KAAK,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,CAAC;gBACzD,IAAI,CAAC,CAAC,SAAS,KAAK,CAAC,EAAE,CAAC;oBACvB,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS,CAAA;oBACjC,MAAM,MAAM,CAAC,EAAE,EAAE,EAAC,GAAG,CAAC,EAAE,IAAI,EAAC,CAAC,CAAA;gBAC/B,CAAC;YACF,CAAC;QACF,CAAC;QAED,QAAQ,CAAC,CAAC,QAAQ;YACjB,KAAK,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC;gBACvD,IAAI,CAAC,CAAC,KAAK,KAAK,CAAC,EAAE,CAAC;oBACnB,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,CAAA;oBACjC,MAAM,MAAM,CAAC,EAAE,EAAE,EAAC,GAAG,CAAC,EAAE,MAAM,EAAC,CAAC,CAAA;gBACjC,CAAC;YACF,CAAC;QACF,CAAC;QAED,QAAQ,CAAC,CAAC,KAAK;YACd,KAAK,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC9C,IAAI,CAAC,CAAC,MAAM,IAAI,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,21 +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 Select<C extends Components, K extends keyof C> = Pick<C, K> & Partial<C>;
7
- export declare enum Kind {
8
- Assign = 0,
9
- Update = 1
10
- }
11
- export type Delta<C extends Components> = Partial<{
12
- [K in keyof C]: C[K] | null;
13
- }>;
14
- export type Assign = [id: Id, kind: Kind, components?: Partial<Components>];
15
- export type Update = [id: Id, kind: Kind, delta: Delta<Components>];
16
- export type Change = Assign | Update;
17
- export type LifecycleCallbacks<C extends Components, K extends keyof C> = {
18
- tick: (id: Id, components: Select<C, K>) => void;
19
- exit: (id: Id) => void;
20
- };
21
- 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
@@ -1,6 +0,0 @@
1
- export var Kind;
2
- (function (Kind) {
3
- Kind[Kind["Assign"] = 0] = "Assign";
4
- Kind[Kind["Update"] = 1] = "Update";
5
- })(Kind || (Kind = {}));
6
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../s/ecs/types.ts"],"names":[],"mappings":"AASA,MAAM,CAAN,IAAY,IAAqB;AAAjC,WAAY,IAAI;IAAE,mCAAM,CAAA;IAAE,mCAAM,CAAA;AAAA,CAAC,EAArB,IAAI,KAAJ,IAAI,QAAiB"}
@@ -1,2 +0,0 @@
1
- import { Change, Components, Entities } from "../types.js";
2
- export declare function applyChangeToEntities<C extends Components>(entities: Entities<any>, change: Change): Partial<C> | undefined;
@@ -1,30 +0,0 @@
1
- import { GMap, is } from "@e280/stz";
2
- import { Kind } from "../types.js";
3
- export function applyChangeToEntities(entities, change) {
4
- switch (change[1]) {
5
- case Kind.Assign: return assign(entities, change);
6
- case Kind.Update: return update(entities, change);
7
- default: throw new Error(`unknown change kind "${change[1]}"`);
8
- }
9
- }
10
- function assign(entities, [id, _kind, components]) {
11
- if (components) {
12
- entities.set(id, components);
13
- return components;
14
- }
15
- else {
16
- entities.delete(id);
17
- return undefined;
18
- }
19
- }
20
- function update(entities, [id, _kind, fresh]) {
21
- const components = GMap.guarantee(entities, id, () => ({}));
22
- for (const [key, value] of Object.entries(fresh)) {
23
- if (!is.happy(value))
24
- delete components[key];
25
- else
26
- components[key] = value;
27
- }
28
- return components;
29
- }
30
- //# sourceMappingURL=apply-change.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"apply-change.js","sourceRoot":"","sources":["../../../s/ecs/utils/apply-change.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAE,EAAE,EAAC,MAAM,WAAW,CAAA;AAClC,OAAO,EAAuC,IAAI,EAAS,MAAM,aAAa,CAAA;AAE9E,MAAM,UAAU,qBAAqB,CAAuB,QAAuB,EAAE,MAAc;IAClG,QAAQ,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QACnB,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,MAAM,CAAI,QAAQ,EAAU,MAAM,CAAC,CAAA;QAC5D,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,MAAM,CAAI,QAAQ,EAAU,MAAM,CAAC,CAAA;QAC5D,OAAO,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,wBAAwB,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IAC/D,CAAC;AACF,CAAC;AAED,SAAS,MAAM,CAAuB,QAA8B,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,UAAU,CAAS;IACpG,IAAI,UAAU,EAAE,CAAC;QAChB,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,UAAwB,CAAC,CAAA;QAC1C,OAAO,UAAwB,CAAA;IAChC,CAAC;SACI,CAAC;QACL,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QACnB,OAAO,SAAS,CAAA;IACjB,CAAC;AACF,CAAC;AAED,SAAS,MAAM,CAAuB,QAA8B,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,CAAS;IAC/F,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAQ,CAAA;IAClE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAClD,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC;YAAE,OAAO,UAAU,CAAC,GAAG,CAAC,CAAA;;YACvC,UAAU,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;IAC7B,CAAC;IACD,OAAO,UAAwB,CAAA;AAChC,CAAC"}
@@ -1,2 +0,0 @@
1
- import { Components } from "../types.js";
2
- export declare function isMatch(set: Set<any>, components: Components): boolean;
@@ -1,4 +0,0 @@
1
- export function isMatch(set, components) {
2
- return [...set].every(key => key in components);
3
- }
4
- //# sourceMappingURL=is-match.js.map
@@ -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
- }
@@ -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":[],"mappings":"AACA,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,EAAC,O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