@vworlds/vecs 1.0.14 → 1.0.16

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 (187) hide show
  1. package/README.md +249 -119
  2. package/dist/component.d.ts +52 -76
  3. package/dist/component.js +60 -45
  4. package/dist/component.js.map +1 -1
  5. package/dist/component_meta.d.ts +98 -0
  6. package/dist/component_meta.js +65 -0
  7. package/dist/component_meta.js.map +1 -0
  8. package/dist/dsl.d.ts +46 -34
  9. package/dist/dsl.js +459 -61
  10. package/dist/dsl.js.map +1 -1
  11. package/dist/entity/entity.base.d.ts +57 -0
  12. package/dist/entity/entity.base.js +81 -0
  13. package/dist/entity/entity.base.js.map +1 -0
  14. package/dist/entity/entity.components.d.ts +117 -0
  15. package/dist/entity/entity.components.js +244 -0
  16. package/dist/entity/entity.components.js.map +1 -0
  17. package/dist/entity/entity.d.ts +35 -0
  18. package/dist/entity/entity.identity.d.ts +8 -0
  19. package/dist/entity/entity.identity.js +15 -0
  20. package/dist/entity/entity.identity.js.map +1 -0
  21. package/dist/entity/entity.js +33 -0
  22. package/dist/entity/entity.js.map +1 -0
  23. package/dist/entity/entity.lifecycle.d.ts +12 -0
  24. package/dist/entity/entity.lifecycle.js +111 -0
  25. package/dist/entity/entity.lifecycle.js.map +1 -0
  26. package/dist/entity/entity.queries.d.ts +3 -0
  27. package/dist/entity/entity.queries.js +33 -0
  28. package/dist/entity/entity.queries.js.map +1 -0
  29. package/dist/entity/entity.relationships.d.ts +9 -0
  30. package/dist/entity/entity.relationships.js +74 -0
  31. package/dist/entity/entity.relationships.js.map +1 -0
  32. package/dist/entity/index.d.ts +2 -0
  33. package/dist/entity/index.js +3 -0
  34. package/dist/entity/index.js.map +1 -0
  35. package/dist/filter.d.ts +27 -8
  36. package/dist/filter.js +33 -18
  37. package/dist/filter.js.map +1 -1
  38. package/dist/index.d.ts +13 -5
  39. package/dist/index.js +12 -2
  40. package/dist/index.js.map +1 -1
  41. package/dist/inject.d.ts +80 -0
  42. package/dist/inject.js +270 -0
  43. package/dist/inject.js.map +1 -0
  44. package/dist/module.d.ts +23 -0
  45. package/dist/module.js +17 -0
  46. package/dist/module.js.map +1 -0
  47. package/dist/modules/identity.d.ts +15 -0
  48. package/dist/modules/identity.js +41 -0
  49. package/dist/modules/identity.js.map +1 -0
  50. package/dist/modules/singleton.d.ts +26 -0
  51. package/dist/modules/singleton.js +41 -0
  52. package/dist/modules/singleton.js.map +1 -0
  53. package/dist/package.json +18 -20
  54. package/dist/phase.d.ts +2 -2
  55. package/dist/query/index.d.ts +6 -0
  56. package/dist/query/index.js +5 -0
  57. package/dist/query/index.js.map +1 -0
  58. package/dist/query/query.00.base.d.ts +23 -0
  59. package/dist/query/query.00.base.js +77 -0
  60. package/dist/query/query.00.base.js.map +1 -0
  61. package/dist/query/query.01.reactive.d.ts +7 -0
  62. package/dist/query/query.01.reactive.js +58 -0
  63. package/dist/query/query.01.reactive.js.map +1 -0
  64. package/dist/query/query.02.lifecycle.d.ts +6 -0
  65. package/dist/query/query.02.lifecycle.js +63 -0
  66. package/dist/query/query.02.lifecycle.js.map +1 -0
  67. package/dist/query/query.03.tracking.d.ts +15 -0
  68. package/dist/query/query.03.tracking.js +31 -0
  69. package/dist/query/query.03.tracking.js.map +1 -0
  70. package/dist/query/query.04.callbacks.d.ts +14 -0
  71. package/dist/query/query.04.callbacks.js +65 -0
  72. package/dist/query/query.04.callbacks.js.map +1 -0
  73. package/dist/query/query.05.updates.d.ts +14 -0
  74. package/dist/query/query.05.updates.js +81 -0
  75. package/dist/query/query.05.updates.js.map +1 -0
  76. package/dist/query/query.06.predicate.d.ts +13 -0
  77. package/dist/query/query.06.predicate.js +40 -0
  78. package/dist/query/query.06.predicate.js.map +1 -0
  79. package/dist/query/query.07.groups.d.ts +41 -0
  80. package/dist/query/query.07.groups.js +110 -0
  81. package/dist/query/query.07.groups.js.map +1 -0
  82. package/dist/query/query.d.ts +53 -0
  83. package/dist/query/query.js +138 -0
  84. package/dist/query/query.js.map +1 -0
  85. package/dist/relationship.d.ts +19 -0
  86. package/dist/relationship.js +18 -0
  87. package/dist/relationship.js.map +1 -0
  88. package/dist/system.d.ts +37 -23
  89. package/dist/system.js +80 -64
  90. package/dist/system.js.map +1 -1
  91. package/dist/terms/all_term.d.ts +32 -0
  92. package/dist/terms/all_term.js +41 -0
  93. package/dist/terms/all_term.js.map +1 -0
  94. package/dist/terms/any_term.d.ts +33 -0
  95. package/dist/terms/any_term.js +42 -0
  96. package/dist/terms/any_term.js.map +1 -0
  97. package/dist/terms/build.d.ts +62 -0
  98. package/dist/terms/build.js +382 -0
  99. package/dist/terms/build.js.map +1 -0
  100. package/dist/terms/component_term.d.ts +37 -0
  101. package/dist/terms/component_term.js +49 -0
  102. package/dist/terms/component_term.js.map +1 -0
  103. package/dist/terms/empty_term.d.ts +6 -0
  104. package/dist/terms/empty_term.js +12 -0
  105. package/dist/terms/empty_term.js.map +1 -0
  106. package/dist/terms/index.d.ts +11 -0
  107. package/dist/terms/index.js +12 -0
  108. package/dist/terms/index.js.map +1 -0
  109. package/dist/terms/not_term.d.ts +35 -0
  110. package/dist/terms/not_term.js +47 -0
  111. package/dist/terms/not_term.js.map +1 -0
  112. package/dist/terms/only_term.d.ts +47 -0
  113. package/dist/terms/only_term.js +79 -0
  114. package/dist/terms/only_term.js.map +1 -0
  115. package/dist/terms/predicate_term.d.ts +80 -0
  116. package/dist/terms/predicate_term.js +109 -0
  117. package/dist/terms/predicate_term.js.map +1 -0
  118. package/dist/terms/target_term.d.ts +43 -0
  119. package/dist/terms/target_term.js +87 -0
  120. package/dist/terms/target_term.js.map +1 -0
  121. package/dist/terms/term.d.ts +94 -0
  122. package/dist/terms/term.js +202 -0
  123. package/dist/terms/term.js.map +1 -0
  124. package/dist/terms/world_term.d.ts +68 -0
  125. package/dist/terms/world_term.js +99 -0
  126. package/dist/terms/world_term.js.map +1 -0
  127. package/dist/timer.js +2 -2
  128. package/dist/timer.js.map +1 -1
  129. package/dist/util/array_map.js +12 -0
  130. package/dist/util/array_map.js.map +1 -1
  131. package/dist/util/bitset.js +107 -22
  132. package/dist/util/bitset.js.map +1 -1
  133. package/dist/util/dense_set.d.ts +1 -0
  134. package/dist/util/dense_set.js +90 -0
  135. package/dist/util/dense_set.js.map +1 -0
  136. package/dist/util/id_pool.d.ts +23 -0
  137. package/dist/util/id_pool.js +194 -0
  138. package/dist/util/id_pool.js.map +1 -0
  139. package/dist/util/ordered_set.js.map +1 -1
  140. package/dist/world/index.d.ts +3 -0
  141. package/dist/world/index.js +3 -0
  142. package/dist/world/index.js.map +1 -0
  143. package/dist/world/world.base.d.ts +6 -0
  144. package/dist/world/world.base.js +21 -0
  145. package/dist/world/world.base.js.map +1 -0
  146. package/dist/world/world.components.d.ts +67 -0
  147. package/dist/world/world.components.js +93 -0
  148. package/dist/world/world.components.js.map +1 -0
  149. package/dist/world/world.d.ts +29 -0
  150. package/dist/world/world.deferred.d.ts +13 -0
  151. package/dist/world/world.deferred.js +93 -0
  152. package/dist/world/world.deferred.js.map +1 -0
  153. package/dist/world/world.entities.d.ts +18 -0
  154. package/dist/world/world.entities.js +97 -0
  155. package/dist/world/world.entities.js.map +1 -0
  156. package/dist/world/world.js +39 -0
  157. package/dist/world/world.js.map +1 -0
  158. package/dist/world/world.modules.d.ts +12 -0
  159. package/dist/world/world.modules.js +21 -0
  160. package/dist/world/world.modules.js.map +1 -0
  161. package/dist/world/world.pipeline.d.ts +21 -0
  162. package/dist/world/world.pipeline.js +105 -0
  163. package/dist/world/world.pipeline.js.map +1 -0
  164. package/dist/world/world.pools.d.ts +9 -0
  165. package/dist/world/world.pools.js +59 -0
  166. package/dist/world/world.pools.js.map +1 -0
  167. package/dist/world/world.queries.d.ts +18 -0
  168. package/dist/world/world.queries.js +101 -0
  169. package/dist/world/world.queries.js.map +1 -0
  170. package/dist/world/world.storage.d.ts +7 -0
  171. package/dist/world/world.storage.js +26 -0
  172. package/dist/world/world.storage.js.map +1 -0
  173. package/package.json +18 -20
  174. package/tsconfig.build.json +13 -0
  175. package/.husky/pre-commit +0 -3
  176. package/.prettierrc +0 -7
  177. package/dist/entity.d.ts +0 -215
  178. package/dist/entity.js +0 -457
  179. package/dist/entity.js.map +0 -1
  180. package/dist/query.d.ts +0 -251
  181. package/dist/query.js +0 -353
  182. package/dist/query.js.map +0 -1
  183. package/dist/world.d.ts +0 -389
  184. package/dist/world.js +0 -631
  185. package/dist/world.js.map +0 -1
  186. package/eslint-rules/internal-underscore.js +0 -60
  187. package/eslint.config.js +0 -22
@@ -0,0 +1,9 @@
1
+ import { type IdPoolConfig } from "../util/id_pool.js";
2
+ import { Base, type WorldOptions } from "./world.base.js";
3
+ export declare const DEFAULT_POOLS: readonly IdPoolConfig[];
4
+ export declare class Pools extends Base {
5
+ constructor(options?: WorldOptions);
6
+ get pools(): ReadonlyArray<IdPoolConfig>;
7
+ /** Return the id that the named pool will allocate next without reserving it. */
8
+ peekNextEid(poolName: string): number;
9
+ }
@@ -0,0 +1,59 @@
1
+ import { IdPool, validateIdPoolConfigs } from "../util/id_pool.js";
2
+ import { Base } from "./world.base.js";
3
+ const RESERVED_EID = 0;
4
+ export const DEFAULT_POOLS = [
5
+ { name: "component", min: 1, max: 899 },
6
+ { name: "module", min: 900, max: 999 },
7
+ { name: "entity", min: 1000 },
8
+ ];
9
+ export class Pools extends Base {
10
+ constructor(options = {}) {
11
+ super();
12
+ /** @internal Baked id pool configs for this world. */
13
+ this._poolConfigs = [];
14
+ /** @internal Runtime allocators for every configured id range. */
15
+ this._pools = [];
16
+ const idPools = options.idPools ?? DEFAULT_POOLS;
17
+ validateIdPoolConfigs(idPools);
18
+ this._poolConfigs.push(...idPools.map((pool) => ({ ...pool })));
19
+ this._pools.push(...this._poolConfigs.map((pool) => new IdPool(pool.name, pool.min, pool.max)));
20
+ this._cacheNamedPools();
21
+ }
22
+ get pools() {
23
+ return this._poolConfigs.map((pool) => ({ ...pool }));
24
+ }
25
+ /** Return the id that the named pool will allocate next without reserving it. */
26
+ peekNextEid(poolName) {
27
+ return this._poolByName(poolName).peek();
28
+ }
29
+ /** @internal Cache the well-known pools used by hot paths. */
30
+ _cacheNamedPools() {
31
+ this._componentPool = this._poolByName("component");
32
+ this._modulePool = this._poolByName("module");
33
+ this._entityPool = this._poolByName("entity");
34
+ }
35
+ /** @internal Look up a configured id pool by name. */
36
+ _poolByName(name) {
37
+ const pool = this._pools.find((candidate) => candidate.name === name);
38
+ if (!pool) {
39
+ throw new Error(`Unknown id pool '${name}'`);
40
+ }
41
+ return pool;
42
+ }
43
+ /** @internal Return the pool that owns `eid`. */
44
+ _poolFor(eid) {
45
+ if (eid === RESERVED_EID) {
46
+ throw new Error(`Eid ${eid} is reserved`);
47
+ }
48
+ const pool = this._pools.find((candidate) => candidate.owns(eid));
49
+ if (!pool) {
50
+ throw new Error(`No id pool owns eid ${eid}`);
51
+ }
52
+ return pool;
53
+ }
54
+ /** @internal Reserve an externally assigned id in its owning pool. */
55
+ _reserveEid(eid) {
56
+ this._poolFor(eid).reserve(eid);
57
+ }
58
+ }
59
+ //# sourceMappingURL=world.pools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"world.pools.js","sourceRoot":"","sources":["../../src/world/world.pools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAqB,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACtF,OAAO,EAAE,IAAI,EAAqB,MAAM,iBAAiB,CAAC;AAE1D,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB,MAAM,CAAC,MAAM,aAAa,GAA4B;IACpD,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE;IACvC,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;IACtC,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE;CAC9B,CAAC;AAEF,MAAM,OAAO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CAAC;IAED,sDAAsD;IAC5C,WAAW,CAAC,IAAY;QAChC,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QACtE,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,oBAAoB,IAAI,GAAG,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iDAAiD;IACvC,QAAQ,CAAC,GAAW;QAC5B,IAAI,GAAG,KAAK,YAAY,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,OAAO,GAAG,cAAc,CAAC,CAAC;QAC5C,CAAC;QACD,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAClE,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,uBAAuB,GAAG,EAAE,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,sEAAsE;IAC5D,WAAW,CAAC,GAAW;QAC/B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,18 @@
1
+ import { type ComponentType } from "../component.js";
2
+ import { type ExtractRequired, type QueryDSL } from "../dsl.js";
3
+ import { Filter } from "../filter.js";
4
+ import { Query } from "../query/index.js";
5
+ import { Term } from "../terms/index.js";
6
+ import { Storage } from "./world.storage.js";
7
+ import type { World } from "./world.js";
8
+ export declare class Queries extends Storage {
9
+ /** Read-only view of every registered query (includes systems). */
10
+ get queries(): ReadonlyArray<Query>;
11
+ /** Create a non-reactive {@link Filter} that matches entities satisfying `q`. */
12
+ filter<Q extends QueryDSL>(this: World, q: Q): Filter<ExtractRequired<Q>>;
13
+ filter<T extends ComponentType[]>(this: World, q: QueryDSL, _guaranteed: readonly [...T]): Filter<T>;
14
+ /** Create and return a standalone {@link Query}, ready for fluent configuration. */
15
+ query(this: World, name: string): Query;
16
+ /** Return the shared materialized term for a reactive query DSL expression. */
17
+ getTerm(this: World, q: QueryDSL): Term;
18
+ }
@@ -0,0 +1,101 @@
1
+ import { Filter } from "../filter.js";
2
+ import { Query } from "../query/index.js";
3
+ import { getCachedTerm, getTerm, notifyComponentAdded, notifyComponentChanged, notifyComponentRemoved, notifyEntityCreated, notifyEntityDestroyed, } from "../terms/build.js";
4
+ import { Storage } from "./world.storage.js";
5
+ export class Queries extends Storage {
6
+ constructor() {
7
+ super(...arguments);
8
+ /** @internal All registered queries, including systems (which extend `Query`). */
9
+ this._queries = [];
10
+ /** @internal Queries created but not yet built into the world. */
11
+ this._unbuiltQueries = new Set();
12
+ /** @internal Canonical DSL key -> live term. */
13
+ this._termCache = new Map();
14
+ /** @internal Component eid -> pinned component leaf term. */
15
+ this._componentTerms = new Map();
16
+ /** @internal True while the world is driving one logical frame. */
17
+ this._frameInProgress = false;
18
+ /** @internal True while the world is auto-building pending queries. */
19
+ this._buildingPendingQueries = false;
20
+ }
21
+ /** Read-only view of every registered query (includes systems). */
22
+ get queries() {
23
+ return this._queries;
24
+ }
25
+ /** @internal Register and index a freshly built {@link Query}. */
26
+ _addQuery(q) {
27
+ if (this._frameInProgress && !this._buildingPendingQueries) {
28
+ throw new Error("queries cannot be built while a frame is in progress");
29
+ }
30
+ this._removeUnbuiltQuery(q);
31
+ this._queries.push(q);
32
+ }
33
+ /** @internal Track a newly-created query until it is explicitly or automatically built. */
34
+ _addUnbuiltQuery(q) {
35
+ this._unbuiltQueries.add(q);
36
+ }
37
+ /** @internal Unregister a query and purge its membership from every entity. */
38
+ _removeQuery(q) {
39
+ this._removeUnbuiltQuery(q);
40
+ const idx = this._queries.indexOf(q);
41
+ if (idx !== -1) {
42
+ this._queries.splice(idx, 1);
43
+ }
44
+ q._unsubscribeRootTerm();
45
+ this._entities.forEach((e) => e._purgeQuery(q));
46
+ }
47
+ /** @internal Stop tracking a pending query. */
48
+ _removeUnbuiltQuery(q) {
49
+ this._unbuiltQueries.delete(q);
50
+ }
51
+ filter(q, _guaranteed) {
52
+ return new Filter(this, q);
53
+ }
54
+ /** Create and return a standalone {@link Query}, ready for fluent configuration. */
55
+ query(name) {
56
+ return new Query(name, this);
57
+ }
58
+ /** Return the shared materialized term for a reactive query DSL expression. */
59
+ getTerm(q) {
60
+ return getTerm(this, q);
61
+ }
62
+ /** @internal Return a cached term without creating one. */
63
+ _getCachedTerm(q) {
64
+ return getCachedTerm(this, q);
65
+ }
66
+ /** @internal Drive the component leaf for a newly attached component. */
67
+ _notifyComponentAdded(eid, entity) {
68
+ notifyComponentAdded(this, eid, entity);
69
+ }
70
+ /** @internal Drive predicate/target refresh for changed component data. */
71
+ _notifyComponentChanged(eid, entity) {
72
+ notifyComponentChanged(this, eid, entity);
73
+ }
74
+ /** @internal Drive the component leaf for a detached component. */
75
+ _notifyComponentRemoved(eid, entity) {
76
+ notifyComponentRemoved(this, eid, entity);
77
+ }
78
+ /** @internal Drive the world leaf for a created entity. */
79
+ _notifyEntityCreated(entity) {
80
+ notifyEntityCreated(this, entity);
81
+ }
82
+ /** @internal Drive the world/component leaves for a destroyed entity. */
83
+ _notifyEntityDestroyed(entity) {
84
+ notifyEntityDestroyed(this, entity);
85
+ }
86
+ /** @internal Build every query that has not yet entered the world. */
87
+ _buildPendingQueries() {
88
+ if (this._unbuiltQueries.size === 0) {
89
+ return;
90
+ }
91
+ const pending = [...this._unbuiltQueries];
92
+ this._buildingPendingQueries = true;
93
+ try {
94
+ pending.forEach((q) => q._build());
95
+ }
96
+ finally {
97
+ this._buildingPendingQueries = false;
98
+ }
99
+ }
100
+ }
101
+ //# sourceMappingURL=world.queries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"world.queries.js","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CAAC,CAAC;IAChE,CAAC;IAED,mEAAmE;IAC5D,uBAAuB,CAAC,GAAW,EAAE,MAAc;QACxD,sBAAsB,CAAC,IAAwB,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IAED,2DAA2D;IACpD,oBAAoB,CAAC,MAAc;QACxC,mBAAmB,CAAC,IAAwB,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IAED,yEAAyE;IAClE,sBAAsB,CAAC,MAAc;QAC1C,qBAAqB,CAAC,IAAwB,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;IAED,sEAAsE;IAC5D,oBAAoB;QAC5B,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YACpC,OAAO;QACT,CAAC;QACD,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC;QAC1C,IAAI,CAAC,uBAAuB,GAAG,IAAI,CAAC;QACpC,IAAI,CAAC;YACH,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;QACrC,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,uBAAuB,GAAG,KAAK,CAAC;QACvC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ import type { Entity } from "../entity/index.js";
2
+ import { type ReadonlyArrayMap } from "../util/array_map.js";
3
+ import { Pools } from "./world.pools.js";
4
+ export declare class Storage extends Pools {
5
+ /** Read-only view of the live entities, keyed by entity id. */
6
+ get entities(): ReadonlyArrayMap<Entity>;
7
+ }
@@ -0,0 +1,26 @@
1
+ import { ArrayMap } from "../util/array_map.js";
2
+ import { Pools } from "./world.pools.js";
3
+ export class Storage extends Pools {
4
+ constructor() {
5
+ super(...arguments);
6
+ /**
7
+ * @internal Entity id -> entity. Owns every live entity.
8
+ *
9
+ * Backed by an {@link ArrayMap} rather than a `Map`: entity ids are dense
10
+ * pooled integers, so array indexing beats hashing on the lookups that run
11
+ * per component during teardown (`world.entity(componentEid)` in
12
+ * `Entity._destroy`) and on every `world.entity(eid)` resolution.
13
+ */
14
+ this._entities = new ArrayMap();
15
+ }
16
+ /** Read-only view of the live entities, keyed by entity id. */
17
+ get entities() {
18
+ return this._entities;
19
+ }
20
+ /** @internal Remove an entity from the world's entity map (called by `Entity._destroy`). */
21
+ _unregisterEntity(entity) {
22
+ this._entities.delete(entity.eid);
23
+ this._poolFor(entity.eid).free(entity.eid);
24
+ }
25
+ }
26
+ //# sourceMappingURL=world.storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"world.storage.js","sourceRoot":"","sources":["../../src/world/world.storage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAyB,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,MAAM,OAAO,OAAQ,SAAQ,KAAK;IAAlC;;QACE;;;;;;;WAOG;QACO,cAAS,GAAG,IAAI,QAAQ,EAAU,CAAC;IAY/C,CAAC;IAVC,+DAA+D;IAC/D,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,4FAA4F;IACrF,iBAAiB,CAAC,MAAc;QACrC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC7C,CAAC;CACF"}
package/package.json CHANGED
@@ -1,32 +1,30 @@
1
1
  {
2
2
  "name": "@vworlds/vecs",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "development": {
10
+ "types": "./src/index.ts",
11
+ "import": "./src/index.ts"
12
+ },
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ }
16
+ },
7
17
  "scripts": {
8
- "clean": "rimraf dist && rimraf tsconfig.tsbuildinfo",
9
- "prepack": "yarn build",
10
- "build": "yarn clean && yarn compile",
11
- "compile": "tsc --build && cp \"./package.json\" ./dist/",
18
+ "clean": "rimraf dist",
19
+ "prepack": "npm run build",
20
+ "build": "npm run clean && npm run compile",
21
+ "compile": "tsc -p tsconfig.build.json && cp \"./package.json\" ./dist/",
22
+ "bench:ecs": "NODE_OPTIONS=--max-old-space-size=32768 RUN_VECS_ECS_BENCH=1 vitest run tests/ecs.bench.test.ts --pool=forks --poolOptions.forks.singleFork",
12
23
  "test": "vitest run",
13
24
  "test:watch": "vitest",
14
- "lint": "eslint src/ tests/",
25
+ "lint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\" --no-error-on-unmatched-pattern",
15
26
  "typecheck": "tsc --noEmit",
16
- "format:check": "prettier --check \"**/*.{ts,md}\"",
17
- "prepare": "husky"
18
- },
19
- "devDependencies": {
20
- "@types/node": "^20.0.0",
21
- "@typescript-eslint/eslint-plugin": "^8.59.1",
22
- "@typescript-eslint/parser": "^8.59.1",
23
- "eslint": "^10.2.1",
24
- "husky": "^9.1.7",
25
- "lint-staged": "^16.4.0",
26
- "prettier": "^3.8.3",
27
- "rimraf": "^5.0.0",
28
- "typescript": "^4.8.4",
29
- "vitest": "^1.6.0"
27
+ "format:check": "prettier --check \"**/*.{ts,md}\""
30
28
  },
31
29
  "dependencies": {
32
30
  "eventemitter3": "^4.0.7"
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "composite": true,
6
+ "emitDeclarationOnly": false,
7
+ "noEmit": false,
8
+ "outDir": "dist",
9
+ "rootDir": "src",
10
+ "tsBuildInfoFile": "dist/tsconfig.tsbuildinfo"
11
+ },
12
+ "include": ["src"]
13
+ }
package/.husky/pre-commit DELETED
@@ -1,3 +0,0 @@
1
- npx tsc --noEmit
2
- npx lint-staged
3
- yarn format:check
package/.prettierrc DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "semi": true,
3
- "singleQuote": false,
4
- "tabWidth": 2,
5
- "trailingComma": "es5",
6
- "printWidth": 100
7
- }
package/dist/entity.d.ts DELETED
@@ -1,215 +0,0 @@
1
- import { type Component, type ComponentClass, type ComponentClassOrType } from "./component.js";
2
- import type { World } from "./world.js";
3
- import { ReadonlyArrayMap } from "./util/array_map.js";
4
- import { Events } from "./util/events.js";
5
- import { Bitset } from "./util/bitset.js";
6
- type EntityEvents = Events<{
7
- destroy(): void;
8
- }>;
9
- /**
10
- * A game object: a unique numeric id with an arbitrary set of
11
- * {@link Component | components} attached.
12
- *
13
- * Never instantiate `Entity` directly. Use {@link World.entity} for an
14
- * auto-assigned id, or {@link World.getOrCreateEntity} when the id comes from
15
- * an external authority such as a game server:
16
- *
17
- * ```ts
18
- * const e = world.entity();
19
- * e.set(Position, { x: 100 });
20
- * ```
21
- *
22
- * Entities support a parent-child hierarchy. `parent` and `children` form a
23
- * bidirectional link maintained by {@link setParent}; the children set is
24
- * created lazily. Destroying a parent recursively destroys its children.
25
- *
26
- * ## Deferred semantics
27
- *
28
- * Inside a system body or `forEach` iteration the world is in **deferred
29
- * mode**: `add` / `attach` / `set` / `modified` / `remove` / `destroy` /
30
- * `setParent` only enqueue commands. The data layer (the components map and
31
- * `componentBitmask`) is mutated when the world drains its queue. Concretely,
32
- * while deferred:
33
- *
34
- * - `entity.get(C)` returns `undefined` after `entity.add(C)` (no instance yet).
35
- * - `entity.get(C)` returns `undefined` after `entity.attach(instance)` if C was absent.
36
- * - `entity.get(C)` returns the previous value after `entity.set(C, props)`.
37
- * - `entity.get(C)` still returns the component after `entity.remove(C)`.
38
- *
39
- * Outside deferred mode the same calls execute inline and mutations are
40
- * visible immediately.
41
- */
42
- export declare class Entity {
43
- /** World that owns this entity. */
44
- readonly world: World;
45
- /** Unique numeric entity id assigned at creation. */
46
- readonly eid: number;
47
- /**
48
- * Bitmask of component type ids currently attached to this entity. Used by
49
- * the world for fast archetype matching against query predicates.
50
- */
51
- readonly componentBitmask: Bitset;
52
- /**
53
- * Free-form property bag. Modules can use it to associate arbitrary data with
54
- * an entity without registering a dedicated component.
55
- */
56
- properties: Map<string, any>;
57
- constructor(
58
- /** World that owns this entity. */
59
- world: World,
60
- /** Unique numeric entity id assigned at creation. */
61
- eid: number);
62
- /** Fire every `onAdd` hook registered for `meta`. */
63
- private _runOnAddHandlers;
64
- /** Fire every `onSet` hook registered for `meta`. */
65
- private _runOnSetHandlers;
66
- /**
67
- * Re-evaluate every world query for this entity, firing `_enter` / `_exit`
68
- * routing whenever membership flipped.
69
- */
70
- private _updateQueries;
71
- /** Store a component instance and perform the shared add-side bookkeeping. */
72
- private _storeComponent;
73
- /** Perform the shared set-side hook and query update routing. */
74
- private _notifyComponentSet;
75
- /**
76
- * Construct a fresh component of `type`, apply `props`, store it on this
77
- * entity, fire the `onAdd` hook, and route query updates.
78
- *
79
- * If the component type belongs to an exclusivity group, any conflicting
80
- * component already on this entity is removed first.
81
- */
82
- private _new;
83
- /**
84
- * Read-only view of direct child entities. The backing set is created lazily
85
- * on the first child link; before that this getter returns a shared empty set.
86
- */
87
- get children(): ReadonlySet<Entity>;
88
- /**
89
- * Read-only view of all components currently attached to this entity, keyed
90
- * by numeric component type id.
91
- *
92
- * The mutating methods (`set`, `delete`, `clear`) are not exposed. Use
93
- * `entity.add`, `entity.attach`, `entity.set`, and `entity.remove` to change
94
- * the component set.
95
- *
96
- * ```ts
97
- * entity.components.forEach((c) => console.log(c.constructor.name));
98
- * ```
99
- */
100
- get components(): ReadonlyArrayMap<Component>;
101
- /** `true` when no components are currently attached to this entity. */
102
- get empty(): boolean;
103
- /**
104
- * Typed event emitter for entity-level lifecycle events. Currently only the
105
- * `"destroy"` event is emitted, just before the entity is fully torn down.
106
- *
107
- * The emitter is created lazily on first access.
108
- */
109
- get events(): EntityEvents;
110
- /** Parent entity in the scene hierarchy, or `undefined` for a root entity. */
111
- get parent(): Entity | undefined;
112
- /**
113
- * Attach a component to this entity if it is not already present.
114
- *
115
- * Idempotent. Does not fire `onSet` -- use {@link set} when you want to apply
116
- * data and notify watchers.
117
- *
118
- * @param Class - Component class to instantiate.
119
- * @returns This entity, for chaining.
120
- */
121
- add<C extends ComponentClass>(Class: C): Entity;
122
- /**
123
- * Attach a component by numeric type id.
124
- *
125
- * @param type - Numeric component type id.
126
- * @returns This entity, for chaining.
127
- */
128
- add(type: number): Entity;
129
- /**
130
- * Attach an existing component instance to this entity and store that exact
131
- * object. If a component of the same registered class already exists, it is
132
- * replaced rather than assigned into.
133
- *
134
- * `attach` uses the instance constructor to resolve component metadata, so
135
- * the constructor must already be registered in this world. The operation
136
- * fires hooks and query updates like a `set` operation.
137
- *
138
- * @param component - Existing component instance to store on the entity.
139
- * @returns This entity, for chaining.
140
- */
141
- attach(component: Component): Entity;
142
- /**
143
- * Destroy this entity and recursively destroy its children.
144
- *
145
- * Each component fires its `onRemove` hook, the `"destroy"` event is emitted
146
- * just before teardown, and the entity is unregistered from the world.
147
- * After destruction the entity must not be used.
148
- */
149
- destroy(): void;
150
- /**
151
- * Look up a component on this entity.
152
- *
153
- * @param typeOrClass - Component class or numeric type id.
154
- * @returns The component instance, or `undefined` when it is not attached.
155
- */
156
- get<C extends ComponentClass>(typeOrClass: number | C): InstanceType<C> | undefined;
157
- /**
158
- * Mark a component type as having changed, queueing the corresponding `onSet` / `update`
159
- * notifications.
160
- *
161
- * Repeated calls before the world routes the modified command are coalesced via
162
- * the entity's dirty component bitset.
163
- *
164
- * @param typeOrClass - Component class or numeric type id whose data changed.
165
- * @returns This entity, for chaining.
166
- */
167
- modified(typeOrClass: ComponentClassOrType): Entity;
168
- /**
169
- * Detach a component from this entity.
170
- *
171
- * In deferred mode the removal is queued; `get(C)` continues to return the
172
- * component until the queue drains. When applied, queries fire `exit`
173
- * callbacks first and the `onRemove` hook fires last.
174
- *
175
- * @param Class - Component class to detach.
176
- */
177
- remove<C extends ComponentClass>(Class: C): void;
178
- /**
179
- * Detach a component by numeric type id.
180
- *
181
- * @param type - Numeric component type id.
182
- */
183
- remove(type: number): void;
184
- /**
185
- * Reparent this entity. In deferred mode the change is queued; outside
186
- * deferred mode it executes inline.
187
- *
188
- * @param newParent - New parent, or `undefined` to make this a root entity.
189
- */
190
- setParent(newParent: Entity | undefined): void;
191
- /**
192
- * Attach a component (creating it if necessary), copy `props` onto the
193
- * instance, and fire the `onSet` hook plus any `update` callbacks for the
194
- * component type.
195
- *
196
- * In deferred mode `props` are not applied until the queued `Set` command is
197
- * routed.
198
- *
199
- * @param Class - Component class to instantiate.
200
- * @param props - Properties to assign onto the component instance.
201
- * @returns This entity, for chaining.
202
- */
203
- set<C extends ComponentClass>(Class: C, props: Partial<InstanceType<C>>): Entity;
204
- /**
205
- * Attach a component by numeric type id and copy `props` onto it.
206
- *
207
- * @param type - Numeric component type id.
208
- * @param props - Properties to assign onto the component instance.
209
- * @returns This entity, for chaining.
210
- */
211
- set(type: number, props: Partial<Component>): Entity;
212
- /** Returns `"EntityN"` where N is the entity id. */
213
- toString(): string;
214
- }
215
- export {};