@amodx/ncs 0.0.24 → 0.0.27
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/Components/Component.types.d.ts +2 -1
- package/Components/ComponentArray.d.ts +4 -2
- package/Components/ComponentArray.js +15 -15
- package/Components/ComponentCursor.d.ts +8 -3
- package/Components/ComponentCursor.js +27 -9
- package/Contexts/ContextArray.d.ts +1 -1
- package/Contexts/ContextArray.js +6 -2
- package/Contexts/ContextCursor.d.ts +2 -1
- package/Contexts/ContextCursor.js +9 -1
- package/Data/serializeComponent.js +1 -1
- package/Data/serializeNode.js +4 -0
- package/Functional.d.ts +3 -3
- package/Functional.js +3 -3
- package/Graphs/Graph.d.ts +2 -1
- package/Graphs/Graph.js +14 -11
- package/Graphs/GraphClock.d.ts +8 -0
- package/Graphs/GraphClock.js +18 -0
- package/NCS.d.ts +10 -1
- package/Nodes/Node.types.d.ts +2 -2
- package/Nodes/NodeArray.d.ts +1 -0
- package/Nodes/NodeArray.js +6 -3
- package/Nodes/NodeComponents.d.ts +3 -3
- package/Nodes/NodeComponents.js +34 -13
- package/Nodes/NodeContext.js +6 -6
- package/Nodes/NodeCursor.d.ts +1 -1
- package/Nodes/NodeCursor.js +22 -11
- package/Nodes/NodeTags.js +2 -0
- package/Register/registerComponent.d.ts +12 -2
- package/Register/registerComponent.js +71 -14
- package/Schema/Functions/createSchemaBinaryObjectCursorClass.js +4 -4
- package/Schema/Functions/createSchemaObjectCursorClass.js +4 -4
- package/Schema/Functions/createSchemaTypedArrayCursorClass.js +4 -4
- package/Schema/Schema.js +6 -8
- package/Schema/SchemaArrayCursor.d.ts +1 -2
- package/Schema/SchemaArrayCursor.js +2 -6
- package/Schema/SchemaView.d.ts +3 -0
- package/Schema/SchemaView.js +16 -14
- package/Systems/System.types.d.ts +2 -1
- package/Systems/SystemInstance.d.ts +2 -1
- package/Systems/SystemInstance.js +2 -2
- package/Tags/Tag.js +1 -1
- package/Tags/TagArray.js +1 -1
- package/Util/ItemPool.js +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Schema } from "../Schema/Schema";
|
|
2
2
|
import { ComponentCursor } from "./ComponentCursor";
|
|
3
3
|
import { RecursivePartial } from "../Util/Util.types";
|
|
4
|
+
import { GraphClock } from "../Graphs/GraphClock";
|
|
4
5
|
export type CreateComponentData<ComponentSchema extends object = any> = [
|
|
5
6
|
/**
|
|
6
7
|
* The type of the component.
|
|
@@ -73,7 +74,7 @@ export type ComponentRegisterData<ComponentSchema extends object = any, Data ext
|
|
|
73
74
|
* @param component - The instance of the component being updated.
|
|
74
75
|
* @param delta - The time since the last update
|
|
75
76
|
*/
|
|
76
|
-
update?(component: ComponentCursor<ComponentSchema, Data, Shared>,
|
|
77
|
+
update?(component: ComponentCursor<ComponentSchema, Data, Shared>, clock: GraphClock): void;
|
|
77
78
|
/**
|
|
78
79
|
* Optional disposal function for the component.
|
|
79
80
|
*
|
|
@@ -2,6 +2,8 @@ import { Observable } from "../Util/Observable";
|
|
|
2
2
|
import { SchemaArray } from "../Schema/SchemaArray";
|
|
3
3
|
import { ComponentRegisterData } from "./Component.types";
|
|
4
4
|
import { Graph } from "../Graphs/Graph";
|
|
5
|
+
import { ItemPool } from "../Util/ItemPool";
|
|
6
|
+
import { GraphClock } from "../Graphs/GraphClock";
|
|
5
7
|
type ComponentObserverData = [type: number, index: number];
|
|
6
8
|
declare class ComponentArrayObservers {
|
|
7
9
|
componentAdded: Observable<ComponentObserverData>;
|
|
@@ -17,14 +19,14 @@ export declare class ComponentArray {
|
|
|
17
19
|
_disposed: boolean[];
|
|
18
20
|
_data: any[];
|
|
19
21
|
schemaArray: SchemaArray;
|
|
22
|
+
dataPool: ItemPool<any>;
|
|
20
23
|
proto: ComponentRegisterData;
|
|
21
24
|
observers: ComponentArrayObservers;
|
|
22
|
-
private _nodeCursor;
|
|
23
25
|
private _componentCursor;
|
|
24
26
|
constructor(graph: Graph, numberTypeId: number);
|
|
25
27
|
addComponent(node: number, schema: any | null, schemaView: string | null): number;
|
|
26
28
|
removeComponent(index: number): number | null;
|
|
27
|
-
update(
|
|
29
|
+
update(clock: GraphClock): void;
|
|
28
30
|
init(index: number): boolean;
|
|
29
31
|
}
|
|
30
32
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Observable } from "../Util/Observable";
|
|
2
2
|
import { NCSRegister } from "../Register/NCSRegister";
|
|
3
|
-
import { NodeCursor } from "../Nodes/NodeCursor";
|
|
4
3
|
import { ComponentCursor } from "./ComponentCursor";
|
|
4
|
+
import { ItemPool } from "../Util/ItemPool";
|
|
5
5
|
const componentObserverData = [0, 0];
|
|
6
6
|
class ComponentArrayObservers {
|
|
7
7
|
componentAdded = new Observable();
|
|
@@ -17,9 +17,9 @@ export class ComponentArray {
|
|
|
17
17
|
_disposed = [];
|
|
18
18
|
_data = [];
|
|
19
19
|
schemaArray;
|
|
20
|
+
dataPool = new ItemPool();
|
|
20
21
|
proto;
|
|
21
22
|
observers = new ComponentArrayObservers();
|
|
22
|
-
_nodeCursor;
|
|
23
23
|
_componentCursor;
|
|
24
24
|
constructor(graph, numberTypeId) {
|
|
25
25
|
this.graph = graph;
|
|
@@ -28,12 +28,12 @@ export class ComponentArray {
|
|
|
28
28
|
if (proto.schema)
|
|
29
29
|
this.schemaArray = proto.schema.array;
|
|
30
30
|
this.proto = proto;
|
|
31
|
-
this._nodeCursor = NodeCursor.Get();
|
|
32
31
|
this._componentCursor = ComponentCursor.Get();
|
|
32
|
+
this._componentCursor._returnable = false;
|
|
33
33
|
}
|
|
34
34
|
addComponent(node, schema, schemaView) {
|
|
35
35
|
let slot = this._freeSlots.length
|
|
36
|
-
? this._freeSlots.
|
|
36
|
+
? this._freeSlots.pop()
|
|
37
37
|
: this._node.length;
|
|
38
38
|
this._node[slot] = node;
|
|
39
39
|
this._disposed[slot] = false;
|
|
@@ -45,7 +45,7 @@ export class ComponentArray {
|
|
|
45
45
|
return slot;
|
|
46
46
|
}
|
|
47
47
|
removeComponent(index) {
|
|
48
|
-
if (this.
|
|
48
|
+
if (this._disposed[index])
|
|
49
49
|
return null;
|
|
50
50
|
componentObserverData[0] = this.numberTypeId;
|
|
51
51
|
componentObserverData[1] = index;
|
|
@@ -60,15 +60,19 @@ export class ComponentArray {
|
|
|
60
60
|
this.schemaArray.removeData(index);
|
|
61
61
|
return nodeIndex;
|
|
62
62
|
}
|
|
63
|
-
update(
|
|
63
|
+
update(clock) {
|
|
64
64
|
const update = this.proto.update;
|
|
65
65
|
if (!update)
|
|
66
66
|
return;
|
|
67
67
|
for (let i = 0; i < this._disposed.length; i++) {
|
|
68
|
-
|
|
68
|
+
const node = this._node[i];
|
|
69
|
+
if (this._disposed[i] ||
|
|
70
|
+
this.graph._nodes._disposed[node] ||
|
|
71
|
+
this.graph._nodes._beingDisposed[node] ||
|
|
72
|
+
node < 0)
|
|
69
73
|
continue;
|
|
70
|
-
this._componentCursor.setInstance(
|
|
71
|
-
update(this._componentCursor,
|
|
74
|
+
this._componentCursor.setInstance(node, this.graph, this.numberTypeId, i);
|
|
75
|
+
update(this._componentCursor, clock);
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
init(index) {
|
|
@@ -78,12 +82,8 @@ export class ComponentArray {
|
|
|
78
82
|
const cursor = !this.proto.performance?.useReusableCursor
|
|
79
83
|
? ComponentCursor.Get()
|
|
80
84
|
: this._componentCursor;
|
|
81
|
-
|
|
82
|
-
? NodeCursor.Get()
|
|
83
|
-
: this._nodeCursor;
|
|
84
|
-
cursor.setInstance(nodeCursor
|
|
85
|
-
.setNode(this.graph, this._node[index]), this.numberTypeId, index);
|
|
85
|
+
cursor.setInstance(this._node[index], this.graph, this.numberTypeId, index);
|
|
86
86
|
init(cursor);
|
|
87
|
-
return
|
|
87
|
+
return true;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -2,9 +2,12 @@ import { ComponentRegisterData } from "./Component.types";
|
|
|
2
2
|
import { SchemaCursor } from "../Schema/Schema.types";
|
|
3
3
|
import { NodeCursor } from "../Nodes/NodeCursor";
|
|
4
4
|
import { ComponentArray } from "./ComponentArray";
|
|
5
|
+
import { Graph } from "../Graphs/Graph";
|
|
6
|
+
import { ItemPool } from "../Util/ItemPool";
|
|
7
|
+
import { GraphClock } from "../Graphs/GraphClock";
|
|
5
8
|
export declare class ComponentCursor<ComponentSchema extends object = {}, Data extends any = any, Shared extends any = any> {
|
|
6
9
|
static Get(): ComponentCursor<{}, any, any>;
|
|
7
|
-
static
|
|
10
|
+
static Return(cursor: ComponentCursor): boolean;
|
|
8
11
|
/**The index of the parent node in the node array */
|
|
9
12
|
get nodeIndex(): number;
|
|
10
13
|
/**The index in the component array */
|
|
@@ -14,6 +17,7 @@ export declare class ComponentCursor<ComponentSchema extends object = {}, Data e
|
|
|
14
17
|
schema: SchemaCursor<ComponentSchema>;
|
|
15
18
|
get data(): Data;
|
|
16
19
|
set data(data: Data);
|
|
20
|
+
get dataPool(): ItemPool<Data>;
|
|
17
21
|
node: NodeCursor;
|
|
18
22
|
arrays: ComponentArray;
|
|
19
23
|
__proto: ComponentRegisterData<ComponentSchema, Data, Shared>;
|
|
@@ -21,10 +25,11 @@ export declare class ComponentCursor<ComponentSchema extends object = {}, Data e
|
|
|
21
25
|
private _index;
|
|
22
26
|
private _type;
|
|
23
27
|
private constructor();
|
|
24
|
-
|
|
28
|
+
_returnable: boolean;
|
|
29
|
+
setInstance(nodeIndex: number, graph: Graph, type: number, index: number): this;
|
|
25
30
|
get isDisposed(): boolean;
|
|
26
31
|
dispose(): void;
|
|
27
32
|
returnCursor(): boolean;
|
|
28
33
|
cloneCursor(cursor?: ComponentCursor, nodeCursor?: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared>;
|
|
29
|
-
update(
|
|
34
|
+
update(graphClock: GraphClock): void;
|
|
30
35
|
}
|
|
@@ -8,7 +8,12 @@ export class ComponentCursor {
|
|
|
8
8
|
return new ComponentCursor();
|
|
9
9
|
return cursor;
|
|
10
10
|
}
|
|
11
|
-
static
|
|
11
|
+
static Return(cursor) {
|
|
12
|
+
if (cursor.schema) {
|
|
13
|
+
cursor.schema.__view.returnCursor(cursor.schema);
|
|
14
|
+
cursor.schema = null;
|
|
15
|
+
}
|
|
16
|
+
cursor._index = -1;
|
|
12
17
|
return NCSPools.componentCursor.addItem(cursor);
|
|
13
18
|
}
|
|
14
19
|
/**The index of the parent node in the node array */
|
|
@@ -32,7 +37,10 @@ export class ComponentCursor {
|
|
|
32
37
|
set data(data) {
|
|
33
38
|
this.arrays._data[this._index] = data;
|
|
34
39
|
}
|
|
35
|
-
|
|
40
|
+
get dataPool() {
|
|
41
|
+
return this.arrays.dataPool;
|
|
42
|
+
}
|
|
43
|
+
node = NodeCursor.Get();
|
|
36
44
|
arrays;
|
|
37
45
|
__proto;
|
|
38
46
|
get typeId() {
|
|
@@ -41,37 +49,47 @@ export class ComponentCursor {
|
|
|
41
49
|
_index = 0;
|
|
42
50
|
_type = 0;
|
|
43
51
|
constructor() { }
|
|
44
|
-
|
|
52
|
+
_returnable = true;
|
|
53
|
+
setInstance(nodeIndex, graph, type, index) {
|
|
45
54
|
this._index = index;
|
|
46
55
|
this._type = type;
|
|
47
|
-
this.node
|
|
56
|
+
this.node.setNode(graph, nodeIndex);
|
|
48
57
|
this.__proto = NCSRegister.components.items[this._type];
|
|
49
|
-
this.arrays =
|
|
58
|
+
this.arrays = graph._components[type];
|
|
50
59
|
if (this.arrays?.schemaArray?._data[index] !== undefined) {
|
|
51
60
|
this.schema = this.arrays.schemaArray.createViewCursor(index);
|
|
52
61
|
this.schema.setInstance(index);
|
|
53
62
|
}
|
|
63
|
+
else {
|
|
64
|
+
this.schema = null;
|
|
65
|
+
}
|
|
54
66
|
return this;
|
|
55
67
|
}
|
|
56
68
|
get isDisposed() {
|
|
69
|
+
if (this._index == -1 || this.nodeIndex == -1)
|
|
70
|
+
return true;
|
|
57
71
|
return this.arrays._disposed[this._index];
|
|
58
72
|
}
|
|
59
73
|
dispose() {
|
|
60
74
|
if (this.__proto.dispose)
|
|
61
75
|
this.__proto.dispose(this);
|
|
62
76
|
this.arrays.removeComponent(this._index);
|
|
77
|
+
this._index = -1;
|
|
78
|
+
this.node.clear(true, true, true, true, true);
|
|
63
79
|
}
|
|
64
80
|
returnCursor() {
|
|
65
|
-
|
|
81
|
+
if (!this._returnable)
|
|
82
|
+
throw new Error(`Tried to return component cursor that cannot be returned`);
|
|
83
|
+
return ComponentCursor.Return(this);
|
|
66
84
|
}
|
|
67
85
|
cloneCursor(cursor, nodeCursor) {
|
|
68
86
|
const newCursor = cursor || ComponentCursor.Get();
|
|
69
87
|
const newNodeCursor = nodeCursor || NodeCursor.Get();
|
|
70
88
|
newNodeCursor.setNode(this.node.graph, this.node.index);
|
|
71
|
-
newCursor.setInstance(newNodeCursor, this.typeId, this._index);
|
|
89
|
+
newCursor.setInstance(newNodeCursor.index, newNodeCursor.graph, this.typeId, this._index);
|
|
72
90
|
return newCursor;
|
|
73
91
|
}
|
|
74
|
-
update(
|
|
75
|
-
this.__proto.update && this.__proto.update(this,
|
|
92
|
+
update(graphClock) {
|
|
93
|
+
this.__proto.update && this.__proto.update(this, graphClock);
|
|
76
94
|
}
|
|
77
95
|
}
|
|
@@ -7,7 +7,7 @@ export declare class ContextArray {
|
|
|
7
7
|
_state: ContextStateData[];
|
|
8
8
|
_disposed: boolean[];
|
|
9
9
|
_data: any[];
|
|
10
|
-
schemaArray: SchemaArray[];
|
|
10
|
+
schemaArray: (SchemaArray | null)[];
|
|
11
11
|
numberTypeId: number;
|
|
12
12
|
addContext(type: number, node: number[], state: ContextStateData, schema: any | null, data?: any | null): number;
|
|
13
13
|
removeContext(index: number): number[] | null;
|
package/Contexts/ContextArray.js
CHANGED
|
@@ -6,11 +6,11 @@ export class ContextArray {
|
|
|
6
6
|
_state = [];
|
|
7
7
|
_disposed = [];
|
|
8
8
|
_data = [];
|
|
9
|
-
schemaArray;
|
|
9
|
+
schemaArray = [];
|
|
10
10
|
numberTypeId;
|
|
11
11
|
addContext(type, node, state, schema, data = null) {
|
|
12
12
|
let slot = this._freeSlots.length
|
|
13
|
-
? this._freeSlots.
|
|
13
|
+
? this._freeSlots.pop()
|
|
14
14
|
: this._node.length;
|
|
15
15
|
const contextSchema = NCSRegister.contexts.get(type).schema;
|
|
16
16
|
if (contextSchema) {
|
|
@@ -21,6 +21,9 @@ export class ContextArray {
|
|
|
21
21
|
}
|
|
22
22
|
schemaArray.setData(slot, schema);
|
|
23
23
|
}
|
|
24
|
+
else {
|
|
25
|
+
this.schemaArray[type] = null;
|
|
26
|
+
}
|
|
24
27
|
this._type[slot] = type;
|
|
25
28
|
this._node[slot] = node;
|
|
26
29
|
this._state[slot] = state;
|
|
@@ -41,6 +44,7 @@ export class ContextArray {
|
|
|
41
44
|
if (schemaArray) {
|
|
42
45
|
schemaArray.removeData(index);
|
|
43
46
|
}
|
|
47
|
+
this.schemaArray[this._type[index]] = null;
|
|
44
48
|
this._data[index] = undefined;
|
|
45
49
|
return data;
|
|
46
50
|
}
|
|
@@ -5,7 +5,7 @@ import { SchemaCursor } from "../Schema/Schema.types";
|
|
|
5
5
|
import { Graph } from "../Graphs/Graph";
|
|
6
6
|
export declare class ContextCursor<ContextSchema extends {} = {}, Data extends {} = {}> {
|
|
7
7
|
static Get(): ContextCursor<{}, {}>;
|
|
8
|
-
static
|
|
8
|
+
static Return(cursor: ContextCursor): boolean;
|
|
9
9
|
proto: ContextRegisterData<ContextSchema, Data>;
|
|
10
10
|
_index: number;
|
|
11
11
|
_type: number;
|
|
@@ -21,4 +21,5 @@ export declare class ContextCursor<ContextSchema extends {} = {}, Data extends {
|
|
|
21
21
|
private constructor();
|
|
22
22
|
setContext(node: NodeCursor, index: number): void;
|
|
23
23
|
dispose(): void;
|
|
24
|
+
returnCursor(): boolean;
|
|
24
25
|
}
|
|
@@ -7,7 +7,12 @@ export class ContextCursor {
|
|
|
7
7
|
return new ContextCursor();
|
|
8
8
|
return cursor;
|
|
9
9
|
}
|
|
10
|
-
static
|
|
10
|
+
static Return(cursor) {
|
|
11
|
+
if (cursor.schema) {
|
|
12
|
+
cursor.schema.__view.returnCursor(cursor.schema);
|
|
13
|
+
cursor.schema = null;
|
|
14
|
+
}
|
|
15
|
+
cursor._index = -1;
|
|
11
16
|
return NCSPools.contextCursor.addItem(cursor);
|
|
12
17
|
}
|
|
13
18
|
proto;
|
|
@@ -44,4 +49,7 @@ export class ContextCursor {
|
|
|
44
49
|
dispose() {
|
|
45
50
|
this.arrays.removeContext(this._index);
|
|
46
51
|
}
|
|
52
|
+
returnCursor() {
|
|
53
|
+
return ContextCursor.Return(this);
|
|
54
|
+
}
|
|
47
55
|
}
|
|
@@ -10,7 +10,7 @@ export function serializeComponentData(data) {
|
|
|
10
10
|
export function serializeComponent(component) {
|
|
11
11
|
return {
|
|
12
12
|
type: component.type,
|
|
13
|
-
...(component.schema?.__cursor?.
|
|
13
|
+
...(component.schema?.__cursor?._cachedData ? { schema: component.schema.toJSON() } : {}),
|
|
14
14
|
...(component.schema?.__view && component.schema?.__view.id !== "default"
|
|
15
15
|
? { schemaViewId: component.schema.__view.id }
|
|
16
16
|
: {}),
|
package/Data/serializeNode.js
CHANGED
|
@@ -14,6 +14,8 @@ export function serializeNodeData(data) {
|
|
|
14
14
|
if (data[2]) {
|
|
15
15
|
nodeData.components = [];
|
|
16
16
|
for (const comp of data[2]) {
|
|
17
|
+
if (!comp)
|
|
18
|
+
continue;
|
|
17
19
|
nodeData.components.push(serializeComponentData(comp));
|
|
18
20
|
}
|
|
19
21
|
}
|
|
@@ -26,6 +28,8 @@ export function serializeNodeData(data) {
|
|
|
26
28
|
if (data[4]) {
|
|
27
29
|
nodeData.children = [];
|
|
28
30
|
for (const child of data[4]) {
|
|
31
|
+
if (!child)
|
|
32
|
+
continue;
|
|
29
33
|
nodeData.children.push(serializeNodeData(child));
|
|
30
34
|
}
|
|
31
35
|
}
|
package/Functional.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { CreateNodeData } from "./Nodes/Node.types";
|
|
|
2
2
|
import { CreateComponentData } from "./Components/Component.types";
|
|
3
3
|
import { RegisteredTag } from "./Register/registerTag";
|
|
4
4
|
export declare function Node(): CreateNodeData;
|
|
5
|
-
export declare function Node(components?: CreateComponentData[], tags?: number[] | null, ...children: CreateNodeData[]): CreateNodeData;
|
|
6
|
-
export declare function Node(data: string, components?: CreateComponentData[], ...children: CreateNodeData[]): CreateNodeData;
|
|
5
|
+
export declare function Node(components?: (CreateComponentData | null)[], tags?: number[] | null, ...children: CreateNodeData[]): CreateNodeData;
|
|
6
|
+
export declare function Node(data: string, components?: (CreateComponentData | null)[], ...children: CreateNodeData[]): CreateNodeData;
|
|
7
7
|
export declare function Node(data: {
|
|
8
8
|
id?: true;
|
|
9
9
|
name?: string;
|
|
10
10
|
tags?: number[];
|
|
11
|
-
}, components?: CreateComponentData[], ...children: CreateNodeData[]): CreateNodeData;
|
|
11
|
+
}, components?: (CreateComponentData | null)[], ...children: CreateNodeData[]): CreateNodeData;
|
|
12
12
|
export declare function Tag(id: string, ...children: RegisteredTag[]): RegisteredTag;
|
package/Functional.js
CHANGED
|
@@ -26,8 +26,8 @@ export function Node(dataOrComponents, maybeComponentsOrChildren, ...restChildre
|
|
|
26
26
|
}
|
|
27
27
|
export function Tag(id, ...children) {
|
|
28
28
|
const tag = NCS.registerTag({ id });
|
|
29
|
-
children
|
|
30
|
-
tag.tag.addChild(
|
|
31
|
-
}
|
|
29
|
+
for (const child of children) {
|
|
30
|
+
tag.tag.addChild(child.tag);
|
|
31
|
+
}
|
|
32
32
|
return tag;
|
|
33
33
|
}
|
package/Graphs/Graph.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { NodeCursor } from "../Nodes/NodeCursor";
|
|
|
5
5
|
import { ContextArray } from "../Contexts/ContextArray";
|
|
6
6
|
import { TagArray } from "../Tags/TagArray";
|
|
7
7
|
import { SystemInstance } from "../Systems/SystemInstance";
|
|
8
|
+
import { GraphClock } from "./GraphClock";
|
|
8
9
|
export declare class Graph {
|
|
9
10
|
_systems: SystemInstance[];
|
|
10
11
|
_nodes: NodeArray;
|
|
@@ -18,6 +19,6 @@ export declare class Graph {
|
|
|
18
19
|
getNodeFromId(id: bigint | string, cursor?: NodeCursor): NodeCursor;
|
|
19
20
|
addNode(data: CreateNodeData, parent?: number, cursor?: NodeCursor): NodeCursor;
|
|
20
21
|
removeNode(index: number): boolean;
|
|
21
|
-
|
|
22
|
+
clock: GraphClock;
|
|
22
23
|
update(): void;
|
|
23
24
|
}
|
package/Graphs/Graph.js
CHANGED
|
@@ -3,13 +3,17 @@ import { NodeArray } from "../Nodes/NodeArray";
|
|
|
3
3
|
import { NodeCursor } from "../Nodes/NodeCursor";
|
|
4
4
|
import { ContextArray } from "../Contexts/ContextArray";
|
|
5
5
|
import { NCSPools } from "../Pools/NCSPools";
|
|
6
|
+
import { GraphClock } from "./GraphClock";
|
|
6
7
|
function createNode(graph, data, parent) {
|
|
7
8
|
const newNode = graph._nodes.addNode(typeof data[0] == "string" ? NodeId.FromString(data[0]) : data[0], parent, data[1]);
|
|
8
9
|
const nodeCursor = NodeCursor.Get();
|
|
9
10
|
nodeCursor.setNode(graph, newNode);
|
|
10
11
|
if (data[2]?.length) {
|
|
11
12
|
for (let i = 0; i < data[2].length; i++) {
|
|
12
|
-
|
|
13
|
+
const comp = data[2][i];
|
|
14
|
+
if (!comp)
|
|
15
|
+
continue;
|
|
16
|
+
nodeCursor.components.add(comp);
|
|
13
17
|
}
|
|
14
18
|
}
|
|
15
19
|
if (data[3]?.length) {
|
|
@@ -19,7 +23,10 @@ function createNode(graph, data, parent) {
|
|
|
19
23
|
}
|
|
20
24
|
if (data[4]?.length) {
|
|
21
25
|
for (let i = 0; i < data[4].length; i++) {
|
|
22
|
-
|
|
26
|
+
const node = data[4][i];
|
|
27
|
+
if (!node)
|
|
28
|
+
continue;
|
|
29
|
+
createNode(graph, node, newNode);
|
|
23
30
|
}
|
|
24
31
|
}
|
|
25
32
|
nodeCursor.setNode(graph, newNode);
|
|
@@ -93,20 +100,16 @@ export class Graph {
|
|
|
93
100
|
return false;
|
|
94
101
|
return true;
|
|
95
102
|
}
|
|
96
|
-
|
|
103
|
+
clock = new GraphClock();
|
|
97
104
|
update() {
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
this.clock.update();
|
|
106
|
+
if (!this.clock.delta)
|
|
100
107
|
return;
|
|
101
|
-
}
|
|
102
|
-
const current = performance.now();
|
|
103
|
-
const delta = current - this._lastTime;
|
|
104
|
-
this._lastTime = current;
|
|
105
108
|
for (let i = 0; i < this._updatingComponents.length; i++) {
|
|
106
|
-
this._updatingComponents[i].update(
|
|
109
|
+
this._updatingComponents[i].update(this.clock);
|
|
107
110
|
}
|
|
108
111
|
for (let i = 0; i < this._systems.length; i++) {
|
|
109
|
-
this._systems[i].update(
|
|
112
|
+
this._systems[i].update(this.clock);
|
|
110
113
|
}
|
|
111
114
|
}
|
|
112
115
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class GraphClock {
|
|
2
|
+
_lastTime = 0;
|
|
3
|
+
expectedDelta = 1000 / 60;
|
|
4
|
+
deltaRatio = 0;
|
|
5
|
+
delta = 0;
|
|
6
|
+
totalTime = 0;
|
|
7
|
+
update() {
|
|
8
|
+
if (this._lastTime === 0) {
|
|
9
|
+
this._lastTime = performance.now();
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const current = performance.now();
|
|
13
|
+
this.delta = current - this._lastTime;
|
|
14
|
+
this.totalTime += this.delta;
|
|
15
|
+
this.deltaRatio = this.delta / this.expectedDelta;
|
|
16
|
+
this._lastTime = current;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/NCS.d.ts
CHANGED
|
@@ -51,13 +51,22 @@ export declare const NCS: {
|
|
|
51
51
|
getAll(node: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared>[] | null;
|
|
52
52
|
remove(node: NodeCursor): boolean;
|
|
53
53
|
removeAll(node: NodeCursor): boolean;
|
|
54
|
-
|
|
54
|
+
serializedNodeData: {
|
|
55
55
|
get(node: SerializedNodeData): import("./Data/SerializedData.types").SerializedComponentData<ComponentSchema> | null;
|
|
56
56
|
set(node: SerializedNodeData, componentSchema?: Partial<ComponentSchema> | undefined): void;
|
|
57
|
+
set(node: CreateNodeData, schema: string, schemaViewId?: string | null): import("./Data/SerializedData.types").SerializedComponentData<ComponentSchema>[] | null;
|
|
57
58
|
getAll(node: SerializedNodeData): import("./Data/SerializedData.types").SerializedComponentData<ComponentSchema>[] | null;
|
|
58
59
|
remove(node: SerializedNodeData): import("./Data/SerializedData.types").SerializedComponentData<ComponentSchema> | null;
|
|
59
60
|
removeAll(node: SerializedNodeData): import("./Data/SerializedData.types").SerializedComponentData<ComponentSchema>[] | null;
|
|
60
61
|
};
|
|
62
|
+
nodeData: {
|
|
63
|
+
get(node: CreateNodeData): CreateComponentData<ComponentSchema> | null;
|
|
64
|
+
set(node: CreateNodeData, componentSchema?: Partial<ComponentSchema> | undefined): void;
|
|
65
|
+
set(node: CreateNodeData, schema: string, schemaViewId?: string, remote?: true | null): CreateComponentData<ComponentSchema>[] | null;
|
|
66
|
+
getAll(node: CreateNodeData): CreateComponentData<ComponentSchema>[] | null;
|
|
67
|
+
remove(node: CreateNodeData): CreateComponentData<ComponentSchema> | null;
|
|
68
|
+
removeAll(node: CreateNodeData): CreateComponentData<ComponentSchema>[] | null;
|
|
69
|
+
};
|
|
61
70
|
type: string;
|
|
62
71
|
typeId: number;
|
|
63
72
|
data: import("./Components/Component.types").ComponentRegisterData<ComponentSchema, Data, Shared>;
|
package/Nodes/Node.types.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type CreateNodeData = [
|
|
|
12
12
|
/**
|
|
13
13
|
* The components of the node.
|
|
14
14
|
*/
|
|
15
|
-
components: CreateComponentData[] | null,
|
|
15
|
+
components: (CreateComponentData | null)[] | null,
|
|
16
16
|
/**
|
|
17
17
|
* The tags of the node.
|
|
18
18
|
*/
|
|
@@ -20,7 +20,7 @@ export type CreateNodeData = [
|
|
|
20
20
|
/**
|
|
21
21
|
* The children nodes of the node.
|
|
22
22
|
*/
|
|
23
|
-
children: CreateNodeData[] | null
|
|
23
|
+
children: (CreateNodeData | null)[] | null
|
|
24
24
|
];
|
|
25
25
|
export declare enum NodeObserverIds {
|
|
26
26
|
Disposed = 0,
|
package/Nodes/NodeArray.d.ts
CHANGED
package/Nodes/NodeArray.js
CHANGED
|
@@ -23,12 +23,13 @@ export class NodeArray {
|
|
|
23
23
|
_components = [];
|
|
24
24
|
_tags = [];
|
|
25
25
|
_context = [];
|
|
26
|
+
_beingDisposed = [];
|
|
26
27
|
_disposed = [];
|
|
27
28
|
_enabled = [];
|
|
28
29
|
_hasObservers = [];
|
|
29
30
|
_count = 0;
|
|
30
31
|
addNode(id, parent, name) {
|
|
31
|
-
let slot = this._freeSlots.
|
|
32
|
+
let slot = this._freeSlots.pop();
|
|
32
33
|
if (slot === undefined) {
|
|
33
34
|
slot = this._count;
|
|
34
35
|
this._count++;
|
|
@@ -39,18 +40,20 @@ export class NodeArray {
|
|
|
39
40
|
this._disposed[slot] = false;
|
|
40
41
|
this._enabled[slot] = true;
|
|
41
42
|
this._hasObservers[slot] = false;
|
|
43
|
+
this._beingDisposed[slot] = false;
|
|
42
44
|
return slot;
|
|
43
45
|
}
|
|
44
46
|
removeNode(slot) {
|
|
45
|
-
if (this.
|
|
47
|
+
if (this._disposed[slot] === true)
|
|
46
48
|
return false;
|
|
47
49
|
this._freeSlots.push(slot);
|
|
48
50
|
this._indexMap[slot] && this.removeNodeId(this._indexMap[slot]);
|
|
49
|
-
this._parents[slot] =
|
|
51
|
+
this._parents[slot] = -1;
|
|
50
52
|
this._names[slot] = "";
|
|
51
53
|
this._disposed[slot] = true;
|
|
52
54
|
this._enabled[slot] = false;
|
|
53
55
|
this._hasObservers[slot] = false;
|
|
56
|
+
this._beingDisposed[slot] = false;
|
|
54
57
|
for (let j = 0; j < observerValues.length; j++) {
|
|
55
58
|
const key = observerValues[j];
|
|
56
59
|
const observer = this._observers[key]?.[slot];
|
|
@@ -11,9 +11,9 @@ export declare class NodeComponents {
|
|
|
11
11
|
add(comp: CreateComponentData): number;
|
|
12
12
|
remove(type: string): true | undefined;
|
|
13
13
|
has(type: string): boolean;
|
|
14
|
-
get(type: string, cursor?: ComponentCursor
|
|
14
|
+
get(type: string, cursor?: ComponentCursor | null): ComponentCursor<any, any, any> | null;
|
|
15
15
|
getAll(type: string): ComponentCursor<any, any, any>[];
|
|
16
16
|
removeAll(type: string): boolean;
|
|
17
|
-
getChild(type: string, cursor?: ComponentCursor
|
|
18
|
-
getParent(type: string, cursor?: ComponentCursor
|
|
17
|
+
getChild(type: string, cursor?: ComponentCursor | null): ComponentCursor<any, any, any> | null;
|
|
18
|
+
getParent(type: string, cursor?: ComponentCursor | null): ComponentCursor<any, any, any> | null;
|
|
19
19
|
}
|