@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.
Files changed (44) hide show
  1. package/Components/Component.types.d.ts +2 -1
  2. package/Components/ComponentArray.d.ts +4 -2
  3. package/Components/ComponentArray.js +15 -15
  4. package/Components/ComponentCursor.d.ts +8 -3
  5. package/Components/ComponentCursor.js +27 -9
  6. package/Contexts/ContextArray.d.ts +1 -1
  7. package/Contexts/ContextArray.js +6 -2
  8. package/Contexts/ContextCursor.d.ts +2 -1
  9. package/Contexts/ContextCursor.js +9 -1
  10. package/Data/serializeComponent.js +1 -1
  11. package/Data/serializeNode.js +4 -0
  12. package/Functional.d.ts +3 -3
  13. package/Functional.js +3 -3
  14. package/Graphs/Graph.d.ts +2 -1
  15. package/Graphs/Graph.js +14 -11
  16. package/Graphs/GraphClock.d.ts +8 -0
  17. package/Graphs/GraphClock.js +18 -0
  18. package/NCS.d.ts +10 -1
  19. package/Nodes/Node.types.d.ts +2 -2
  20. package/Nodes/NodeArray.d.ts +1 -0
  21. package/Nodes/NodeArray.js +6 -3
  22. package/Nodes/NodeComponents.d.ts +3 -3
  23. package/Nodes/NodeComponents.js +34 -13
  24. package/Nodes/NodeContext.js +6 -6
  25. package/Nodes/NodeCursor.d.ts +1 -1
  26. package/Nodes/NodeCursor.js +22 -11
  27. package/Nodes/NodeTags.js +2 -0
  28. package/Register/registerComponent.d.ts +12 -2
  29. package/Register/registerComponent.js +71 -14
  30. package/Schema/Functions/createSchemaBinaryObjectCursorClass.js +4 -4
  31. package/Schema/Functions/createSchemaObjectCursorClass.js +4 -4
  32. package/Schema/Functions/createSchemaTypedArrayCursorClass.js +4 -4
  33. package/Schema/Schema.js +6 -8
  34. package/Schema/SchemaArrayCursor.d.ts +1 -2
  35. package/Schema/SchemaArrayCursor.js +2 -6
  36. package/Schema/SchemaView.d.ts +3 -0
  37. package/Schema/SchemaView.js +16 -14
  38. package/Systems/System.types.d.ts +2 -1
  39. package/Systems/SystemInstance.d.ts +2 -1
  40. package/Systems/SystemInstance.js +2 -2
  41. package/Tags/Tag.js +1 -1
  42. package/Tags/TagArray.js +1 -1
  43. package/Util/ItemPool.js +1 -1
  44. package/package.json +1 -1
@@ -13,7 +13,6 @@ function traverseCreateJSON(parent, target, source) {
13
13
  }
14
14
  return target;
15
15
  }
16
- const tempData = [];
17
16
  export class SchemaView {
18
17
  schema;
19
18
  id;
@@ -23,6 +22,8 @@ export class SchemaView {
23
22
  _createData;
24
23
  _cursorClass;
25
24
  _dataPool = new ItemPool();
25
+ _cursorPool = new ItemPool();
26
+ _tempData = [];
26
27
  constructor(schema, id, meta, byteOffset, byteSize, _createData, _cursorClass) {
27
28
  this.schema = schema;
28
29
  this.id = id;
@@ -35,20 +36,20 @@ export class SchemaView {
35
36
  returnData(returnData) {
36
37
  this._dataPool.addItem(returnData);
37
38
  }
39
+ returnCursor(cursor) {
40
+ this._cursorPool.addItem(cursor);
41
+ }
38
42
  createData(overrides) {
39
43
  const data = this._createData;
40
- overrides && (tempData.length = 0);
44
+ overrides && (this._tempData.length = 0);
41
45
  let baseData = !overrides
42
46
  ? this.schema._data
43
- : this.schema.createData(tempData, overrides);
47
+ : this.schema.createData(this._tempData, overrides);
44
48
  if (this._dataPool.items.length) {
45
49
  const newData = this._dataPool.get();
46
50
  if (data.type == "object") {
47
51
  for (let i = 0; i < baseData.length; i++) {
48
- newData[i] =
49
- typeof baseData[i] == "object"
50
- ? structuredClone(baseData[i])
51
- : baseData[i];
52
+ newData[i] = baseData[i];
52
53
  }
53
54
  return newData;
54
55
  }
@@ -69,10 +70,7 @@ export class SchemaView {
69
70
  if (data.type == "object") {
70
71
  const newData = new Array(baseData.length);
71
72
  for (let i = 0; i < baseData.length; i++) {
72
- newData[i] =
73
- typeof baseData[i] == "object"
74
- ? structuredClone(baseData[i])
75
- : baseData[i];
73
+ newData[i] = baseData[i];
76
74
  }
77
75
  return newData;
78
76
  }
@@ -106,18 +104,22 @@ export class SchemaView {
106
104
  throw new Error(`NCS: Invalid create data`);
107
105
  }
108
106
  createCursor() {
107
+ const pooled = this._cursorPool.get();
108
+ if (pooled) {
109
+ return pooled;
110
+ }
109
111
  return new this._cursorClass(this, this.meta, this._createData, this.byteOffset);
110
112
  }
111
113
  /** Converts data for use of remote components */
112
114
  toRemote(cursor) {
113
115
  if (this._createData.type == "object") {
114
- return cursor.__cursor.data;
116
+ return cursor.__cursor._cachedData;
115
117
  }
116
118
  if (this._createData.type == "typed-array") {
117
- return cursor.__cursor.data;
119
+ return cursor.__cursor._cachedData;
118
120
  }
119
121
  if (this._createData.type == "binary-object") {
120
- return cursor.__cursor.data.buffer;
122
+ return cursor.__cursor._cachedData.buffer;
121
123
  }
122
124
  }
123
125
  /** Converts data for remote data to local data*/
@@ -1,3 +1,4 @@
1
+ import { GraphClock } from "../Graphs/GraphClock";
1
2
  import { QueryPrototype } from "../Queries/QueryPrototype";
2
3
  import { SystemInstance } from "./SystemInstance";
3
4
  export type SystemRegisterData = {
@@ -12,5 +13,5 @@ export type SystemRegisterData = {
12
13
  /**
13
14
  * The update function of the system.
14
15
  */
15
- update(system: SystemInstance, delta: number): void;
16
+ update(system: SystemInstance, clock: GraphClock): void;
16
17
  };
@@ -2,12 +2,13 @@ import { Graph } from "../Graphs/Graph";
2
2
  import { SystemRegisterData } from "./System.types";
3
3
  import { QueryInstance } from "../Queries/QueryInstance";
4
4
  import { NodeCursor } from "../Nodes/NodeCursor";
5
+ import { GraphClock } from "../Graphs/GraphClock";
5
6
  export declare class SystemInstance {
6
7
  graph: Graph;
7
8
  proto: SystemRegisterData;
8
9
  queries: QueryInstance[];
9
10
  node: NodeCursor;
10
11
  constructor(graph: Graph, proto: SystemRegisterData);
11
- update(delta: number): void;
12
+ update(clock: GraphClock): void;
12
13
  dispose(): void;
13
14
  }
@@ -12,8 +12,8 @@ export class SystemInstance {
12
12
  }
13
13
  this.graph._systems.push(this);
14
14
  }
15
- update(delta) {
16
- this.proto.update(this, delta);
15
+ update(clock) {
16
+ this.proto.update(this, clock);
17
17
  }
18
18
  dispose() {
19
19
  for (let i = 0; i < this.graph._systems.length; i++) {
package/Tags/Tag.js CHANGED
@@ -12,7 +12,7 @@ export class Tag {
12
12
  *traverseChildren() {
13
13
  const children = [...this.children];
14
14
  while (children.length) {
15
- const child = children.shift();
15
+ const child = children.pop();
16
16
  yield child;
17
17
  if (child.children.length)
18
18
  children.push(...child.children);
package/Tags/TagArray.js CHANGED
@@ -18,7 +18,7 @@ export class TagArray {
18
18
  }
19
19
  addTag(node) {
20
20
  let slot = this._freeSlots.length
21
- ? this._freeSlots.shift()
21
+ ? this._freeSlots.pop()
22
22
  : this._node.length;
23
23
  this._node[slot] = node;
24
24
  this.observers.tagAdded.notify(slot);
package/Util/ItemPool.js CHANGED
@@ -8,7 +8,7 @@ export class ItemPool {
8
8
  return true;
9
9
  }
10
10
  get() {
11
- const item = this.items.shift();
11
+ const item = this.items.pop();
12
12
  if (!item)
13
13
  return null;
14
14
  return item;
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@amodx/ncs","version":"0.0.24","module":"index.js","types":"index.d.ts","type":"module","description":"NCS (Node Component System) is a library for the base of any NCS/ECS system.","keywords":[],"scripts":{"build":"mkdir -p dist && rm -rf dist/* && cp package.json dist/package.json && cd ./src && npx tsc","compile":"cd ./src && npx tsc --watch"},"repository":{"url":"git+https://github.com/Amodx/Libraries.git"},"bugs":{"url":"https://github.com/Amodx/Libraries/issues"},"homepage":"https://github.com/Amodx/Libraries","author":"Amodx","license":"MIT","devDependencies":{},"main":"index.js","publishConfig":{"access":"public"}}
1
+ {"name":"@amodx/ncs","version":"0.0.27","module":"index.js","types":"index.d.ts","type":"module","description":"NCS (Node Component System) is a library for the base of any NCS/ECS system.","keywords":[],"scripts":{"build":"mkdir -p dist && rm -rf dist/* && cp package.json dist/package.json && cd ./src && npx tsc","compile":"cd ./src && npx tsc --watch"},"repository":{"url":"git+https://github.com/Amodx/Libraries.git"},"bugs":{"url":"https://github.com/Amodx/Libraries/issues"},"homepage":"https://github.com/Amodx/Libraries","author":"Amodx","license":"MIT","devDependencies":{},"main":"index.js","publishConfig":{"access":"public"}}