@vworlds/vecs 1.0.10 → 1.0.12
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/.husky/pre-commit +1 -0
- package/README.md +299 -228
- package/dist/command.d.ts +1 -46
- package/dist/component.d.ts +51 -59
- package/dist/component.js +31 -25
- package/dist/component.js.map +1 -1
- package/dist/dsl.d.ts +34 -26
- package/dist/dsl.js +46 -20
- package/dist/dsl.js.map +1 -1
- package/dist/entity.d.ts +96 -106
- package/dist/entity.js +261 -190
- package/dist/entity.js.map +1 -1
- package/dist/filter.d.ts +31 -23
- package/dist/filter.js +24 -17
- package/dist/filter.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/package.json +3 -1
- package/dist/phase.d.ts +12 -30
- package/dist/phase.js +11 -10
- package/dist/phase.js.map +1 -1
- package/dist/query.d.ts +107 -144
- package/dist/query.js +200 -169
- package/dist/query.js.map +1 -1
- package/dist/system.d.ts +170 -86
- package/dist/system.js +253 -114
- package/dist/system.js.map +1 -1
- package/dist/timer.d.ts +50 -0
- package/dist/timer.js +154 -0
- package/dist/timer.js.map +1 -0
- package/dist/util/array_map.d.ts +4 -55
- package/dist/util/array_map.js +35 -37
- package/dist/util/array_map.js.map +1 -1
- package/dist/util/bitset.d.ts +40 -50
- package/dist/util/bitset.js +76 -62
- package/dist/util/bitset.js.map +1 -1
- package/dist/util/events.d.ts +14 -18
- package/dist/util/events.js +24 -3
- package/dist/util/events.js.map +1 -1
- package/dist/util/ordered_set.d.ts +1 -17
- package/dist/util/ordered_set.js +74 -25
- package/dist/util/ordered_set.js.map +1 -1
- package/dist/world.d.ts +230 -218
- package/dist/world.js +422 -327
- package/dist/world.js.map +1 -1
- package/eslint-rules/internal-underscore.js +60 -0
- package/eslint.config.js +5 -0
- package/package.json +3 -1
package/dist/timer.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/** Shared state and start/stop control for concrete tick sources. */
|
|
2
|
+
class BaseTickSource {
|
|
3
|
+
constructor() {
|
|
4
|
+
/** @internal */
|
|
5
|
+
this._didTick = false;
|
|
6
|
+
/** @internal */
|
|
7
|
+
this._running = true;
|
|
8
|
+
/** @internal */
|
|
9
|
+
this._lastEvaluatedFrame = -1;
|
|
10
|
+
/** @internal */
|
|
11
|
+
this._timeSinceLastTick = 0;
|
|
12
|
+
/** @internal Delta accumulated into the most recent tick, in milliseconds. */
|
|
13
|
+
this._lastFireDelta = 0;
|
|
14
|
+
}
|
|
15
|
+
get didTick() {
|
|
16
|
+
return this._didTick;
|
|
17
|
+
}
|
|
18
|
+
get lastFireDelta() {
|
|
19
|
+
return this._lastFireDelta;
|
|
20
|
+
}
|
|
21
|
+
/** Resume this source without replaying time elapsed while stopped. */
|
|
22
|
+
start() {
|
|
23
|
+
this._running = true;
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
/** Pause this source, freezing accumulators and counters until `start()`. */
|
|
27
|
+
stop() {
|
|
28
|
+
this._running = false;
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
/** @internal Register this source with `world`. */
|
|
32
|
+
_register(world) {
|
|
33
|
+
world._registerTickSource(this);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Fires every `intervalSeconds` of accumulated wall-clock time. */
|
|
37
|
+
export class IntervalTickSource extends BaseTickSource {
|
|
38
|
+
/**
|
|
39
|
+
* Create an interval source.
|
|
40
|
+
*
|
|
41
|
+
* Intervals are expressed in seconds, unlike `World.progress` and
|
|
42
|
+
* `World.beginFrame`, which receive millisecond deltas. Large deltas produce
|
|
43
|
+
* at most one tick; residual time is preserved by subtracting the interval.
|
|
44
|
+
*
|
|
45
|
+
* @param intervalSeconds - Positive interval duration in seconds.
|
|
46
|
+
* @throws When `intervalSeconds` is less than or equal to zero.
|
|
47
|
+
*/
|
|
48
|
+
constructor(intervalSeconds) {
|
|
49
|
+
super();
|
|
50
|
+
this._accumulator = 0;
|
|
51
|
+
if (intervalSeconds <= 0) {
|
|
52
|
+
throw "interval seconds must be greater than 0";
|
|
53
|
+
}
|
|
54
|
+
this._intervalMs = intervalSeconds * 1000;
|
|
55
|
+
}
|
|
56
|
+
/** @internal */
|
|
57
|
+
_evalTick(deltaMs, frameId) {
|
|
58
|
+
if (this._lastEvaluatedFrame === frameId) {
|
|
59
|
+
return this._didTick;
|
|
60
|
+
}
|
|
61
|
+
this._lastEvaluatedFrame = frameId;
|
|
62
|
+
if (!this._running) {
|
|
63
|
+
this._didTick = false;
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
this._timeSinceLastTick += deltaMs;
|
|
67
|
+
this._accumulator += deltaMs;
|
|
68
|
+
let fired = false;
|
|
69
|
+
if (this._accumulator >= this._intervalMs) {
|
|
70
|
+
this._accumulator -= this._intervalMs;
|
|
71
|
+
fired = true;
|
|
72
|
+
this._lastFireDelta = this._timeSinceLastTick;
|
|
73
|
+
this._timeSinceLastTick = 0;
|
|
74
|
+
}
|
|
75
|
+
this._didTick = fired;
|
|
76
|
+
return fired;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Fires every `rate` ticks of `source`, or every `rate` frames without one. */
|
|
80
|
+
export class RateTickSource extends BaseTickSource {
|
|
81
|
+
/**
|
|
82
|
+
* Create a rate filter.
|
|
83
|
+
*
|
|
84
|
+
* Without `source`, this counts world frames. With `source`, it counts ticks
|
|
85
|
+
* from that upstream clock. The source is immutable, so cyclic source graphs
|
|
86
|
+
* cannot be constructed through the public API.
|
|
87
|
+
*
|
|
88
|
+
* @param rate - Positive integer tick divisor.
|
|
89
|
+
* @param source - Optional upstream source to divide.
|
|
90
|
+
* @throws When `rate` is not a positive integer.
|
|
91
|
+
*/
|
|
92
|
+
constructor(rate, source) {
|
|
93
|
+
super();
|
|
94
|
+
this._counter = 0;
|
|
95
|
+
if (!Number.isInteger(rate) || rate <= 0) {
|
|
96
|
+
throw "rate must be a positive integer";
|
|
97
|
+
}
|
|
98
|
+
this._rate = rate;
|
|
99
|
+
this._source = source;
|
|
100
|
+
}
|
|
101
|
+
/** @internal */
|
|
102
|
+
_evalTick(deltaMs, frameId) {
|
|
103
|
+
if (this._lastEvaluatedFrame === frameId) {
|
|
104
|
+
return this._didTick;
|
|
105
|
+
}
|
|
106
|
+
this._lastEvaluatedFrame = frameId;
|
|
107
|
+
if (!this._running) {
|
|
108
|
+
this._didTick = false;
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
const upstreamFired = this._source ? this._source._evalTick(deltaMs, frameId) : true;
|
|
112
|
+
const upstreamDelta = this._source ? this._source.lastFireDelta : deltaMs;
|
|
113
|
+
let fired = false;
|
|
114
|
+
if (upstreamFired) {
|
|
115
|
+
this._timeSinceLastTick += upstreamDelta;
|
|
116
|
+
this._counter++;
|
|
117
|
+
if (this._counter >= this._rate) {
|
|
118
|
+
this._counter = 0;
|
|
119
|
+
fired = true;
|
|
120
|
+
this._lastFireDelta = this._timeSinceLastTick;
|
|
121
|
+
this._timeSinceLastTick = 0;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
this._didTick = fired;
|
|
125
|
+
return fired;
|
|
126
|
+
}
|
|
127
|
+
/** @internal */
|
|
128
|
+
_register(world) {
|
|
129
|
+
super._register(world);
|
|
130
|
+
this._source?._register(world);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** @internal Singleton source used by systems with no explicit cadence. */
|
|
134
|
+
class _AlwaysTickSource {
|
|
135
|
+
constructor() {
|
|
136
|
+
this._lastDelta = 0;
|
|
137
|
+
}
|
|
138
|
+
get didTick() {
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
get lastFireDelta() {
|
|
142
|
+
return this._lastDelta;
|
|
143
|
+
}
|
|
144
|
+
/** @internal */
|
|
145
|
+
_evalTick(deltaMs, _frameId) {
|
|
146
|
+
this._lastDelta = deltaMs;
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
/** @internal */
|
|
150
|
+
_register(_world) { }
|
|
151
|
+
}
|
|
152
|
+
/** @internal Shared default clock for unconfigured systems. */
|
|
153
|
+
export const ALWAYS_TICK_SOURCE = new _AlwaysTickSource();
|
|
154
|
+
//# sourceMappingURL=timer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer.js","sourceRoot":"","sources":["../src/timer.ts"],"names":[],"mappings":"AAcA,qEAAqE;AACrE,MAAe,cAAc;IAA7B;QACE,gBAAgB;QACN,aAAQ,GAAG,KAAK,CAAC;QAC3B,gBAAgB;QACN,aAAQ,GAAG,IAAI,CAAC;QAC1B,gBAAgB;QACN,wBAAmB,GAAG,CAAC,CAAC,CAAC;QACnC,gBAAgB;QACN,uBAAkB,GAAG,CAAC,CAAC;QACjC,8EAA8E;QACvE,mBAAc,GAAG,CAAC,CAAC;IA6B5B,CAAC;IA3BC,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED,uEAAuE;IAChE,KAAK;QACV,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,6EAA6E;IACtE,IAAI;QACT,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAKD,mDAAmD;IAC5C,SAAS,CAAC,KAAY;QAC3B,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACF;AAED,oEAAoE;AACpE,MAAM,OAAO,kBAAmB,SAAQ,cAAc;IAIpD;;;;;;;;;OASG;IACH,YAAmB,eAAuB;QACxC,KAAK,EAAE,CAAC;QAbF,iBAAY,GAAG,CAAC,CAAC;QAcvB,IAAI,eAAe,IAAI,CAAC,EAAE;YACxB,MAAM,yCAAyC,CAAC;SACjD;QACD,I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CAAC;IAkBzB,CAAC;IAhBC,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,gBAAgB;IACT,SAAS,CAAC,OAAe,EAAE,QAAgB;QAChD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gBAAgB;IACT,SAAS,CAAC,MAAa,IAAS,CAAC;CACzC;AAED,+DAA+D;AAC/D,MAAM,CAAC,MAAM,kBAAkB,GAAgB,IAAI,iBAAiB,EAAE,CAAC"}
|
package/dist/util/array_map.d.ts
CHANGED
|
@@ -1,58 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Read-only view of an {@link ArrayMap}: the mutating methods `set`, `delete`,
|
|
3
|
+
* and `clear` are omitted.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
* `Map` because array index access avoids the hash-table overhead. Used
|
|
6
|
-
* internally to store per-entity component instances and per-type component
|
|
7
|
-
* metadata.
|
|
8
|
-
*
|
|
9
|
-
* Keys must be non-negative integers. Gaps in the key space are represented
|
|
10
|
-
* as `undefined` slots and do not count toward `size`.
|
|
11
|
-
*
|
|
12
|
-
* @typeParam T - The value type stored in the map.
|
|
5
|
+
* @typeParam T - Value type stored in the map.
|
|
13
6
|
*/
|
|
14
|
-
export
|
|
15
|
-
private backend;
|
|
16
|
-
private _size;
|
|
17
|
-
constructor();
|
|
18
|
-
/**
|
|
19
|
-
* Store `value` at `key`, replacing any existing value.
|
|
20
|
-
*
|
|
21
|
-
* @param key - Non-negative integer key.
|
|
22
|
-
* @param value - Value to store.
|
|
23
|
-
*/
|
|
24
|
-
set(key: number, value: T): void;
|
|
25
|
-
/**
|
|
26
|
-
* Return the value stored at `key`, or `undefined` if not present.
|
|
27
|
-
*
|
|
28
|
-
* @param key - Non-negative integer key.
|
|
29
|
-
*/
|
|
30
|
-
get(key: number): T | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* Remove the entry at `key`. Does nothing if `key` is not present.
|
|
33
|
-
*
|
|
34
|
-
* @param key - Non-negative integer key.
|
|
35
|
-
*/
|
|
36
|
-
delete(key: number): void;
|
|
37
|
-
/**
|
|
38
|
-
* Return `true` if an entry exists at `key`.
|
|
39
|
-
*
|
|
40
|
-
* @param key - Non-negative integer key.
|
|
41
|
-
*/
|
|
42
|
-
has(key: number): boolean;
|
|
43
|
-
/**
|
|
44
|
-
* Iterate over all present entries.
|
|
45
|
-
*
|
|
46
|
-
* Undefined slots are skipped; the callback is only called for keys that
|
|
47
|
-
* have an associated value.
|
|
48
|
-
*
|
|
49
|
-
* @param callback - Called with `(value, key, map)` for each entry.
|
|
50
|
-
*/
|
|
51
|
-
forEach(callback: (value: T, key: number, map: ArrayMap<T>) => void): void;
|
|
52
|
-
/**
|
|
53
|
-
* Remove all entries and reset the size to zero.
|
|
54
|
-
*/
|
|
55
|
-
clear(): void;
|
|
56
|
-
/** The number of entries currently in the map. */
|
|
57
|
-
get size(): number;
|
|
58
|
-
}
|
|
7
|
+
export type ReadonlyArrayMap<T> = Omit<ArrayMap<T>, "set" | "delete" | "clear">;
|
package/dist/util/array_map.js
CHANGED
|
@@ -1,84 +1,82 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A `Map<number, T>` backed by a sparse JavaScript array.
|
|
2
|
+
* A `Map<number, T>` substitute backed by a sparse JavaScript array.
|
|
3
3
|
*
|
|
4
|
-
* For small, dense integer key spaces
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* metadata.
|
|
4
|
+
* For small, dense, non-negative integer key spaces, indexing into a regular
|
|
5
|
+
* array is faster than the hash-table lookups performed by the built-in
|
|
6
|
+
* `Map`. `ArrayMap` is used inside the ECS to store per-entity component
|
|
7
|
+
* instances and per-type metadata.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* Empty slots are represented as `undefined` and do not count toward
|
|
10
|
+
* {@link size}.
|
|
11
11
|
*
|
|
12
|
-
* @
|
|
12
|
+
* @internal Used only inside the package.
|
|
13
|
+
*
|
|
14
|
+
* @typeParam T - Value type stored in the map.
|
|
13
15
|
*/
|
|
14
16
|
export class ArrayMap {
|
|
15
17
|
constructor() {
|
|
16
|
-
this.
|
|
18
|
+
this._backend = [];
|
|
17
19
|
this._size = 0;
|
|
18
20
|
}
|
|
21
|
+
/** The number of entries currently in the map. */
|
|
22
|
+
get size() {
|
|
23
|
+
return this._size;
|
|
24
|
+
}
|
|
19
25
|
/**
|
|
20
|
-
*
|
|
26
|
+
* Insert or replace the value at `key`.
|
|
21
27
|
*
|
|
22
28
|
* @param key - Non-negative integer key.
|
|
23
29
|
* @param value - Value to store.
|
|
24
30
|
*/
|
|
25
31
|
set(key, value) {
|
|
26
|
-
if (this.
|
|
32
|
+
if (this._backend[key] === undefined) {
|
|
27
33
|
this._size++;
|
|
28
34
|
}
|
|
29
|
-
this.
|
|
35
|
+
this._backend[key] = value;
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
32
|
-
*
|
|
38
|
+
* Retrieve the value stored at `key`, or `undefined` if no entry exists.
|
|
33
39
|
*
|
|
34
40
|
* @param key - Non-negative integer key.
|
|
35
41
|
*/
|
|
36
42
|
get(key) {
|
|
37
|
-
return this.
|
|
43
|
+
return this._backend[key];
|
|
38
44
|
}
|
|
39
45
|
/**
|
|
40
|
-
*
|
|
46
|
+
* Return `true` when an entry exists at `key`.
|
|
41
47
|
*
|
|
42
48
|
* @param key - Non-negative integer key.
|
|
43
49
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this.backend[key] = undefined;
|
|
47
|
-
this._size--;
|
|
48
|
-
}
|
|
50
|
+
has(key) {
|
|
51
|
+
return this._backend[key] !== undefined;
|
|
49
52
|
}
|
|
50
53
|
/**
|
|
51
|
-
*
|
|
54
|
+
* Remove the entry at `key`. Does nothing if no entry exists there.
|
|
52
55
|
*
|
|
53
56
|
* @param key - Non-negative integer key.
|
|
54
57
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
delete(key) {
|
|
59
|
+
if (this._backend[key] !== undefined) {
|
|
60
|
+
this._backend[key] = undefined;
|
|
61
|
+
this._size--;
|
|
62
|
+
}
|
|
57
63
|
}
|
|
58
64
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* Undefined slots are skipped; the callback is only called for keys that
|
|
62
|
-
* have an associated value.
|
|
65
|
+
* Visit every present entry in ascending key order. Empty slots are skipped.
|
|
63
66
|
*
|
|
64
|
-
* @param callback -
|
|
67
|
+
* @param callback - Invoked with `(value, key, map)` for each entry.
|
|
65
68
|
*/
|
|
66
69
|
forEach(callback) {
|
|
67
|
-
this.
|
|
70
|
+
this._backend.forEach((value, index) => {
|
|
68
71
|
if (value !== undefined) {
|
|
69
72
|
callback(value, index, this);
|
|
70
73
|
}
|
|
71
74
|
});
|
|
72
75
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Remove all entries and reset the size to zero.
|
|
75
|
-
*/
|
|
76
|
+
/** Remove all entries and reset {@link size} to zero. */
|
|
76
77
|
clear() {
|
|
77
|
-
this.
|
|
78
|
-
|
|
79
|
-
/** The number of entries currently in the map. */
|
|
80
|
-
get size() {
|
|
81
|
-
return this._size;
|
|
78
|
+
this._backend.length = 0;
|
|
79
|
+
this._size = 0;
|
|
82
80
|
}
|
|
83
81
|
}
|
|
84
82
|
//# sourceMappingURL=array_map.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array_map.js","sourceRoot":"","sources":["../../src/util/array_map.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"array_map.js","sourceRoot":"","sources":["../../src/util/array_map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,QAAQ;IAArB;QACU,aAAQ,GAAsB,EAAE,CAAC;QACjC,UAAK,GAAW,CAAC,CAAC;I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|
* A compact, growable set of non-negative integers backed by an array of
|
|
3
3
|
* 32-bit words.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* ids attached to an entity) and
|
|
7
|
-
*
|
|
5
|
+
* `Bitset` is the data structure the ECS uses to represent entity archetypes
|
|
6
|
+
* (the set of component type ids attached to an entity) and watchlists
|
|
7
|
+
* (the set of component types a query reacts to).
|
|
8
|
+
*
|
|
9
|
+
* It is exported in the public API so component data can use it for
|
|
10
|
+
* compact bit-flag fields:
|
|
8
11
|
*
|
|
9
12
|
* ```ts
|
|
10
13
|
* class Tags extends Component {
|
|
11
|
-
* tags
|
|
12
|
-
* oldTags = new Bitset();
|
|
14
|
+
* tags = new Bitset();
|
|
13
15
|
* }
|
|
14
16
|
*
|
|
15
|
-
*
|
|
17
|
+
* tags.tags.add(TAG_VISIBLE);
|
|
16
18
|
* if (tags.tags.has(TAG_VISIBLE)) { ... }
|
|
17
19
|
* ```
|
|
18
20
|
*/
|
|
19
21
|
export declare class Bitset {
|
|
20
|
-
/** @internal */
|
|
21
|
-
_bits: number[];
|
|
22
|
-
constructor();
|
|
23
|
-
/**
|
|
24
|
-
* Return `true` if this bitset and `other` have exactly the same bits set.
|
|
25
|
-
*/
|
|
26
|
-
equal(other: Bitset): boolean;
|
|
27
22
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* @internal Low-level bulk operation; prefer {@link add} for single bits.
|
|
31
|
-
*/
|
|
32
|
-
addIndexBitmask(arrayIndex: number, bitmask: number): void;
|
|
33
|
-
/**
|
|
34
|
-
* Replace the word at position `arrayIndex` with `bitmask`.
|
|
23
|
+
* Set bit `n`.
|
|
35
24
|
*
|
|
36
|
-
* @
|
|
25
|
+
* @param n - Non-negative integer bit index.
|
|
37
26
|
*/
|
|
38
|
-
|
|
27
|
+
add(n: number): void;
|
|
39
28
|
/**
|
|
40
29
|
* Set the bit described by `bptr` (fast path using a pre-computed
|
|
41
30
|
* {@link BitPtr}).
|
|
31
|
+
*
|
|
32
|
+
* @param bptr - Pre-computed pointer to a bit position.
|
|
42
33
|
*/
|
|
43
34
|
addBit(bptr: BitPtr): void;
|
|
44
35
|
/**
|
|
45
|
-
*
|
|
36
|
+
* Clear bit `n`. Trailing zero words are trimmed so the internal storage
|
|
37
|
+
* stays compact.
|
|
46
38
|
*
|
|
47
39
|
* @param n - Non-negative integer bit index.
|
|
48
40
|
*/
|
|
49
|
-
|
|
41
|
+
delete(n: number): void;
|
|
50
42
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* Trailing zero words are trimmed so that the internal array stays compact.
|
|
43
|
+
* Return `true` when bit `n` is set.
|
|
54
44
|
*
|
|
55
45
|
* @param n - Non-negative integer bit index.
|
|
56
46
|
*/
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Return `true` if the bit described by `bptr` is set (fast path).
|
|
60
|
-
*/
|
|
61
|
-
hasBit(bptr: BitPtr): boolean;
|
|
47
|
+
has(n: number): boolean;
|
|
62
48
|
/**
|
|
63
|
-
* Return `true`
|
|
49
|
+
* Return `true` when the bit described by `bptr` is set (fast path).
|
|
64
50
|
*
|
|
65
|
-
* @param
|
|
51
|
+
* @param bptr - Pre-computed pointer to a bit position.
|
|
66
52
|
*/
|
|
67
|
-
|
|
53
|
+
hasBit(bptr: BitPtr): boolean;
|
|
68
54
|
/**
|
|
69
|
-
* Return `true`
|
|
55
|
+
* Return `true` when this bitset and `other` have exactly the same bits set.
|
|
70
56
|
*
|
|
71
|
-
* @
|
|
57
|
+
* @param other - Bitset to compare against.
|
|
72
58
|
*/
|
|
73
|
-
|
|
59
|
+
equal(other: Bitset): boolean;
|
|
74
60
|
/**
|
|
75
|
-
* Return `true`
|
|
76
|
-
* `other` is a subset of `this`).
|
|
61
|
+
* Return `true` when every bit set in `other` is also set in this bitset
|
|
62
|
+
* (i.e. `other` is a subset of `this`).
|
|
77
63
|
*
|
|
78
64
|
* Used by the world to test whether an entity's archetype satisfies a
|
|
79
|
-
*
|
|
65
|
+
* `HAS` query.
|
|
66
|
+
*
|
|
67
|
+
* @param other - Bitset whose set bits must all appear in this bitset.
|
|
80
68
|
*/
|
|
81
69
|
hasBitset(other: Bitset): boolean;
|
|
82
70
|
/**
|
|
83
|
-
*
|
|
71
|
+
* Visit each set bit index in ascending order.
|
|
84
72
|
*
|
|
85
|
-
* @param callback -
|
|
73
|
+
* @param callback - Invoked once per set bit.
|
|
86
74
|
*/
|
|
87
75
|
forEach(callback: (n: number) => void): void;
|
|
88
76
|
/**
|
|
89
|
-
* Return an array of
|
|
90
|
-
*
|
|
91
|
-
* @returns `number[]` of set bit positions.
|
|
77
|
+
* Return an array of every set bit index in ascending order.
|
|
92
78
|
*/
|
|
93
79
|
indices(): number[];
|
|
94
80
|
}
|
|
@@ -96,12 +82,12 @@ export declare class Bitset {
|
|
|
96
82
|
* A pre-computed pointer into a {@link Bitset}'s internal word array.
|
|
97
83
|
*
|
|
98
84
|
* Computing `arrayIndex` and `bitmask` from a raw bit index requires a floor
|
|
99
|
-
* division and a
|
|
85
|
+
* division and a bit shift. `BitPtr` caches both values so that hot-path
|
|
100
86
|
* archetype checks ({@link Bitset.hasBit}, {@link Bitset.addBit}) avoid
|
|
101
87
|
* repeating the arithmetic on every entity update.
|
|
102
88
|
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
89
|
+
* One `BitPtr` is created per registered component type and stored on
|
|
90
|
+
* `ComponentMeta.bitPtr`.
|
|
105
91
|
*/
|
|
106
92
|
export declare class BitPtr {
|
|
107
93
|
/** The raw bit index this pointer refers to. */
|
|
@@ -113,6 +99,10 @@ export declare class BitPtr {
|
|
|
113
99
|
constructor(
|
|
114
100
|
/** The raw bit index this pointer refers to. */
|
|
115
101
|
value: number);
|
|
116
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* Return `true` when both pointers refer to the same bit position.
|
|
104
|
+
*
|
|
105
|
+
* @param other - Pointer to compare against.
|
|
106
|
+
*/
|
|
117
107
|
equals(other: BitPtr): boolean;
|
|
118
108
|
}
|