@colyseus/schema 2.0.28 → 2.0.29
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/build/cjs/index.js +22 -31
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +19 -43
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +22 -31
- package/lib/index.js +2 -4
- package/lib/index.js.map +1 -1
- package/lib/utils.d.ts +0 -1
- package/lib/utils.js +1 -26
- package/lib/utils.js.map +1 -1
- package/lib/v3.js +195 -81
- package/lib/v3.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +0 -3
- package/src/utils.ts +0 -25
package/build/umd/index.js
CHANGED
|
@@ -3186,6 +3186,28 @@
|
|
|
3186
3186
|
return Schema;
|
|
3187
3187
|
}());
|
|
3188
3188
|
|
|
3189
|
+
function dumpChanges(schema) {
|
|
3190
|
+
var changeTrees = [schema['$changes']];
|
|
3191
|
+
var numChangeTrees = 1;
|
|
3192
|
+
var dump = {};
|
|
3193
|
+
var currentStructure = dump;
|
|
3194
|
+
var _loop_1 = function (i) {
|
|
3195
|
+
var changeTree = changeTrees[i];
|
|
3196
|
+
changeTree.changes.forEach(function (change) {
|
|
3197
|
+
var ref = changeTree.ref;
|
|
3198
|
+
var fieldIndex = change.index;
|
|
3199
|
+
var field = (ref['_definition'])
|
|
3200
|
+
? ref['_definition'].fieldsByIndex[fieldIndex]
|
|
3201
|
+
: ref['$indexes'].get(fieldIndex);
|
|
3202
|
+
currentStructure[field] = changeTree.getValue(fieldIndex);
|
|
3203
|
+
});
|
|
3204
|
+
};
|
|
3205
|
+
for (var i = 0; i < numChangeTrees; i++) {
|
|
3206
|
+
_loop_1(i);
|
|
3207
|
+
}
|
|
3208
|
+
return dump;
|
|
3209
|
+
}
|
|
3210
|
+
|
|
3189
3211
|
var reflectionContext = { context: new Context() };
|
|
3190
3212
|
/**
|
|
3191
3213
|
* Reflection
|
|
@@ -3344,41 +3366,10 @@
|
|
|
3344
3366
|
return Reflection;
|
|
3345
3367
|
}(Schema));
|
|
3346
3368
|
|
|
3347
|
-
function dumpChanges(schema) {
|
|
3348
|
-
var changeTrees = [schema['$changes']];
|
|
3349
|
-
var numChangeTrees = 1;
|
|
3350
|
-
var dump = {};
|
|
3351
|
-
var currentStructure = dump;
|
|
3352
|
-
var _loop_1 = function (i) {
|
|
3353
|
-
var changeTree = changeTrees[i];
|
|
3354
|
-
changeTree.changes.forEach(function (change) {
|
|
3355
|
-
var ref = changeTree.ref;
|
|
3356
|
-
var fieldIndex = change.index;
|
|
3357
|
-
var field = (ref['_definition'])
|
|
3358
|
-
? ref['_definition'].fieldsByIndex[fieldIndex]
|
|
3359
|
-
: ref['$indexes'].get(fieldIndex);
|
|
3360
|
-
currentStructure[field] = changeTree.getValue(fieldIndex);
|
|
3361
|
-
});
|
|
3362
|
-
};
|
|
3363
|
-
for (var i = 0; i < numChangeTrees; i++) {
|
|
3364
|
-
_loop_1(i);
|
|
3365
|
-
}
|
|
3366
|
-
return dump;
|
|
3367
|
-
}
|
|
3368
|
-
function checkTypeScriptConfig() {
|
|
3369
|
-
var r = new ReflectionField();
|
|
3370
|
-
var descriptor = Object.getOwnPropertyDescriptor(r, "name");
|
|
3371
|
-
if (descriptor.get === undefined || descriptor.set === undefined) {
|
|
3372
|
-
console.error("\n\u203C\uFE0F Please check your tsconfig.json \u203C\uFE0F\n\n@colyseus/schema requires the following settings:\n-------------------------------------------------\n\n \"compilerOptions\": {\n // ...\n \"useDefineForClassFields\": false,\n \"experimentalDecorators\": true,\n // ...\n }\n\n-------------------------------------------------\nMore info \u2192 https://github.com/colyseus/colyseus/issues/510#issuecomment-1507828422\n");
|
|
3373
|
-
process.exit(1);
|
|
3374
|
-
}
|
|
3375
|
-
}
|
|
3376
|
-
|
|
3377
3369
|
registerType("map", { constructor: MapSchema });
|
|
3378
3370
|
registerType("array", { constructor: ArraySchema });
|
|
3379
3371
|
registerType("set", { constructor: SetSchema });
|
|
3380
3372
|
registerType("collection", { constructor: CollectionSchema, });
|
|
3381
|
-
checkTypeScriptConfig();
|
|
3382
3373
|
|
|
3383
3374
|
exports.ArraySchema = ArraySchema;
|
|
3384
3375
|
exports.CollectionSchema = CollectionSchema;
|
package/lib/index.js
CHANGED
|
@@ -17,11 +17,9 @@ Object.defineProperty(exports, "registerType", { enumerable: true, get: function
|
|
|
17
17
|
(0, typeRegistry_1.registerType)("array", { constructor: ArraySchema_1.ArraySchema });
|
|
18
18
|
(0, typeRegistry_1.registerType)("set", { constructor: SetSchema_1.SetSchema });
|
|
19
19
|
(0, typeRegistry_1.registerType)("collection", { constructor: CollectionSchema_1.CollectionSchema, });
|
|
20
|
-
const utils_1 = require("./utils");
|
|
21
|
-
(0, utils_1.checkTypeScriptConfig)();
|
|
22
20
|
// Utils
|
|
23
|
-
var
|
|
24
|
-
Object.defineProperty(exports, "dumpChanges", { enumerable: true, get: function () { return
|
|
21
|
+
var utils_1 = require("./utils");
|
|
22
|
+
Object.defineProperty(exports, "dumpChanges", { enumerable: true, get: function () { return utils_1.dumpChanges; } });
|
|
25
23
|
const encode = require("./encoding/encode");
|
|
26
24
|
exports.encode = encode;
|
|
27
25
|
const decode = require("./encoding/decode");
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AAGf,iDAA6C;AACpC,0FADA,qBAAS,OACA;AAElB,qDAAkD;AACzC,4FADA,yBAAW,OACA;AAEpB,+DAA4D;AACnD,iGADA,mCAAgB,OACA;AAEzB,iDAA8C;AACrC,0FADA,qBAAS,OACA;AAElB,uDAAoD;AAC3C,6FADA,2BAAY,OACA;AAErB,IAAA,2BAAY,EAAC,KAAK,EAAE,EAAE,WAAW,EAAE,qBAAS,EAAE,CAAC,CAAC;AAChD,IAAA,2BAAY,EAAC,OAAO,EAAE,EAAE,WAA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AY;AACZ,+GAAA,gBAAgB,OAAA;AAChB,sGAAA,OAAO,OAAA;AAWX,+BAAmC;AAA1B,iGAAA,SAAS,OAAA","sourcesContent":["export { Schema } from \"./Schema\";\nexport type { DataChange } from \"./Schema\";\n\nimport { MapSchema } from \"./types/MapSchema\"\nexport { MapSchema };\n\nimport { ArraySchema } from \"./types/ArraySchema\";\nexport { ArraySchema };\n\nimport { CollectionSchema } from \"./types/CollectionSchema\";\nexport { CollectionSchema };\n\nimport { SetSchema } from \"./types/SetSchema\";\nexport { SetSchema };\n\nimport { registerType } from \"./types/typeRegistry\";\nexport { registerType };\n\nregisterType(\"map\", { constructor: MapSchema });\nregisterType(\"array\", { constructor: ArraySchema });\nregisterType(\"set\", { constructor: SetSchema });\nregisterType(\"collection\", { constructor: CollectionSchema, });\n\n// Utils\nexport { dumpChanges } from \"./utils\";\n\n// Encoder / Decoder\nexport type { Iterator } from \"./encoding/decode\";\nimport * as encode from \"./encoding/encode\";\nimport * as decode from \"./encoding/decode\";\nexport { encode, decode };\n\n// Reflection\nexport {\n Reflection,\n ReflectionType,\n ReflectionField,\n} from \"./Reflection\";\n\nexport {\n // Annotations\n type,\n deprecated,\n filter,\n filterChildren,\n defineTypes,\n hasFilter,\n\n // Internals\n SchemaDefinition,\n Context,\n} from \"./annotations\";\n\n// Annotation types\nexport type {\n DefinitionType,\n PrimitiveType,\n Definition,\n FilterCallback,\n} from \"./annotations\";\n\nexport { OPERATION } from \"./spec\";\n"]}
|
package/lib/utils.d.ts
CHANGED
package/lib/utils.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const Reflection_1 = require("./Reflection");
|
|
3
|
+
exports.dumpChanges = void 0;
|
|
5
4
|
function dumpChanges(schema) {
|
|
6
5
|
const changeTrees = [schema['$changes']];
|
|
7
6
|
let numChangeTrees = 1;
|
|
@@ -21,28 +20,4 @@ function dumpChanges(schema) {
|
|
|
21
20
|
return dump;
|
|
22
21
|
}
|
|
23
22
|
exports.dumpChanges = dumpChanges;
|
|
24
|
-
function checkTypeScriptConfig() {
|
|
25
|
-
const r = new Reflection_1.ReflectionField();
|
|
26
|
-
const descriptor = Object.getOwnPropertyDescriptor(r, "name");
|
|
27
|
-
if (descriptor.get === undefined || descriptor.set === undefined) {
|
|
28
|
-
console.error(`
|
|
29
|
-
‼️ Please check your tsconfig.json ‼️
|
|
30
|
-
|
|
31
|
-
@colyseus/schema requires the following settings:
|
|
32
|
-
-------------------------------------------------
|
|
33
|
-
|
|
34
|
-
"compilerOptions": {
|
|
35
|
-
// ...
|
|
36
|
-
"useDefineForClassFields": false,
|
|
37
|
-
"experimentalDecorators": true,
|
|
38
|
-
// ...
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
-------------------------------------------------
|
|
42
|
-
More info → https://github.com/colyseus/colyseus/issues/510#issuecomment-1507828422
|
|
43
|
-
`);
|
|
44
|
-
process.exit(1);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.checkTypeScriptConfig = checkTypeScriptConfig;
|
|
48
23
|
//# sourceMappingURL=utils.js.map
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAGA,SAAgB,WAAW,CAAC,MAAc;IACtC,MAAM,WAAW,GAAiB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IACvD,IAAI,cAAc,GAAG,CAAC,CAAC;IAEvB,MAAM,IAAI,GAAG,EAAE,CAAC;IAChB,IAAI,gBAAgB,GAAG,IAAI,CAAC;IAE5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,cAAc,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;QAElC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YAClC,MAAM,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC;YAC3B,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC;YAEhC,MAAM,KAAK,GAAG,CAAE,GAAc,CAAC,aAAa,CAAC,CAAC;gBAC1C,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,aAAa,CAAC,UAAU,CAAC;gBAC9C,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAEtC,gBAAgB,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;IAEP,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAxBD,kCAwBC","sourcesContent":["import { Schema } from \"./Schema\";\nimport { ChangeTree } from \"./changes/ChangeTree\";\n\nexport function dumpChanges(schema: Schema) {\n const changeTrees: ChangeTree[] = [schema['$changes']];\n let numChangeTrees = 1;\n\n const dump = {};\n let currentStructure = dump;\n\n for (let i = 0; i < numChangeTrees; i++) {\n const changeTree = changeTrees[i];\n\n changeTree.changes.forEach((change) => {\n const ref = changeTree.ref;\n const fieldIndex = change.index;\n\n const field = ((ref as Schema)['_definition'])\n ? ref['_definition'].fieldsByIndex[fieldIndex]\n : ref['$indexes'].get(fieldIndex);\n\n currentStructure[field] = changeTree.getValue(fieldIndex);\n });\n\n }\n\n return dump;\n}\n"]}
|
package/lib/v3.js
CHANGED
|
@@ -5,6 +5,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
12
|
const util = require("node:util");
|
|
10
13
|
require("./symbol.shim");
|
|
@@ -13,11 +16,32 @@ const annotations_1 = require("./annotations");
|
|
|
13
16
|
const Schema_1 = require("./Schema");
|
|
14
17
|
const ArraySchema_1 = require("./types/ArraySchema");
|
|
15
18
|
const MapSchema_1 = require("./types/MapSchema");
|
|
16
|
-
const Encoder_1 = require("./Encoder");
|
|
17
|
-
const Decoder_1 = require("./Decoder");
|
|
18
|
-
const EncodeOperation_1 = require("./
|
|
19
|
-
const
|
|
20
|
-
const DecodeOperation_1 = require("./
|
|
19
|
+
const Encoder_1 = require("./encoder/Encoder");
|
|
20
|
+
const Decoder_1 = require("./decoder/Decoder");
|
|
21
|
+
const EncodeOperation_1 = require("./encoder/EncodeOperation");
|
|
22
|
+
const symbols_1 = require("./types/symbols");
|
|
23
|
+
const DecodeOperation_1 = require("./decoder/DecodeOperation");
|
|
24
|
+
const Reflection_1 = require("./Reflection");
|
|
25
|
+
const StateView_1 = require("./encoder/StateView");
|
|
26
|
+
function logSingleCall(label, callback) {
|
|
27
|
+
const time = Date.now();
|
|
28
|
+
const res = callback();
|
|
29
|
+
console.log(`${label}:`, Date.now() - time);
|
|
30
|
+
return res;
|
|
31
|
+
}
|
|
32
|
+
function logTime(label, callback) {
|
|
33
|
+
const time = Date.now();
|
|
34
|
+
for (let i = 0; i < 500000; i++) {
|
|
35
|
+
callback();
|
|
36
|
+
}
|
|
37
|
+
console.log(`${label}:`, Date.now() - time);
|
|
38
|
+
}
|
|
39
|
+
// // @ts-ignore
|
|
40
|
+
// globalThis.perform = function perform() {
|
|
41
|
+
// for (let i = 0; i < 500000; i++) {
|
|
42
|
+
// encoder.encodeAll();
|
|
43
|
+
// }
|
|
44
|
+
// }
|
|
21
45
|
// const timeout = setInterval(() => {}, 1000);
|
|
22
46
|
// function decorate({ get, set }, context: ClassAccessorDecoratorContext): ClassAccessorDecoratorResult<any, any> {
|
|
23
47
|
// const field = context.name.toString();
|
|
@@ -86,67 +110,65 @@ const DecodeOperation_1 = require("./changes/DecodeOperation");
|
|
|
86
110
|
// const encoded = encoder.encode();
|
|
87
111
|
// const decoder = new Decoder(new RootState());
|
|
88
112
|
// decoder.decode(encoded);
|
|
89
|
-
// process.exit();
|
|
90
113
|
function log(message) {
|
|
91
114
|
console.log(util.inspect(message, false, 10, true));
|
|
92
115
|
}
|
|
93
|
-
Schema_1.Schema[
|
|
94
|
-
Schema_1.Schema[
|
|
95
|
-
MapSchema_1.MapSchema[
|
|
96
|
-
MapSchema_1.MapSchema[
|
|
97
|
-
ArraySchema_1.ArraySchema[
|
|
98
|
-
ArraySchema_1.ArraySchema[
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
__decorate([
|
|
102
|
-
(0, annotations_1.type)("number")
|
|
103
|
-
], Vec3.prototype, "x", void 0);
|
|
104
|
-
__decorate([
|
|
105
|
-
(0, annotations_1.type)("number")
|
|
106
|
-
], Vec3.prototype, "y", void 0);
|
|
107
|
-
__decorate([
|
|
108
|
-
(0, annotations_1.type)("number")
|
|
109
|
-
], Vec3.prototype, "z", void 0);
|
|
116
|
+
Schema_1.Schema[symbols_1.$encoder] = EncodeOperation_1.encodeSchemaOperation;
|
|
117
|
+
Schema_1.Schema[symbols_1.$decoder] = DecodeOperation_1.decodeSchemaOperation;
|
|
118
|
+
MapSchema_1.MapSchema[symbols_1.$encoder] = EncodeOperation_1.encodeKeyValueOperation;
|
|
119
|
+
MapSchema_1.MapSchema[symbols_1.$decoder] = DecodeOperation_1.decodeKeyValueOperation;
|
|
120
|
+
ArraySchema_1.ArraySchema[symbols_1.$encoder] = EncodeOperation_1.encodeKeyValueOperation;
|
|
121
|
+
ArraySchema_1.ArraySchema[symbols_1.$decoder] = DecodeOperation_1.decodeKeyValueOperation;
|
|
122
|
+
// // No need to extend Schema!
|
|
110
123
|
// class Vec3 {
|
|
111
124
|
// x: number;
|
|
112
125
|
// y: number;
|
|
113
126
|
// z: number;
|
|
114
127
|
// constructor() {
|
|
128
|
+
// // Need to initialize property descriptors
|
|
115
129
|
// Schema.initialize(this);
|
|
116
130
|
// }
|
|
117
|
-
// assign(data: { x: number, y: number, z: number }) {
|
|
118
|
-
// this.x = data.x;
|
|
119
|
-
// this.y = data.y;
|
|
120
|
-
// this.z = data.z;
|
|
121
|
-
// return this;
|
|
122
|
-
// }
|
|
123
131
|
// }
|
|
132
|
+
// // Define fields to encode/decode
|
|
124
133
|
// Metadata.setFields(Vec3, {
|
|
125
134
|
// x: "number",
|
|
126
135
|
// y: "number",
|
|
127
136
|
// z: "number",
|
|
128
137
|
// });
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
//
|
|
134
|
-
//
|
|
135
|
-
//
|
|
136
|
-
// changeTree.change(index, operation, encodeSchemaOperation);
|
|
138
|
+
// //
|
|
139
|
+
// Vec3[$track] = function (
|
|
140
|
+
// changeTree: ChangeTree,
|
|
141
|
+
// index: number,
|
|
142
|
+
// operation: OPERATION = OPERATION.ADD
|
|
143
|
+
// ) {
|
|
144
|
+
// changeTree.change(index, operation);
|
|
137
145
|
// };
|
|
138
146
|
// Vec3[$encoder] = encodeSchemaOperation;
|
|
139
147
|
// Vec3[$decoder] = decodeSchemaOperation;
|
|
140
148
|
// // @ts-ignore
|
|
141
149
|
// if (!Vec3.prototype.toJSON) { Vec3.prototype.toJSON = Schema.prototype.toJSON; }
|
|
142
150
|
// -------------------------------------------------------------------------------
|
|
151
|
+
class Vec3 extends Schema_1.Schema {
|
|
152
|
+
}
|
|
153
|
+
__decorate([
|
|
154
|
+
(0, annotations_1.type)("number"),
|
|
155
|
+
__metadata("design:type", Number)
|
|
156
|
+
], Vec3.prototype, "x", void 0);
|
|
157
|
+
__decorate([
|
|
158
|
+
(0, annotations_1.type)("number"),
|
|
159
|
+
__metadata("design:type", Number)
|
|
160
|
+
], Vec3.prototype, "y", void 0);
|
|
161
|
+
__decorate([
|
|
162
|
+
(0, annotations_1.type)("number"),
|
|
163
|
+
__metadata("design:type", Number)
|
|
164
|
+
], Vec3.prototype, "z", void 0);
|
|
143
165
|
// Vec3[$track] = function (changeTree, index) {
|
|
144
166
|
// changeTree.change(0, OPERATION.ADD);
|
|
145
167
|
// };
|
|
146
|
-
// Vec3[$encoder] = function (encoder, bytes, changeTree, index, operation) {
|
|
147
|
-
// encode.number(bytes, changeTree.ref.x);
|
|
148
|
-
// encode.number(bytes, changeTree.ref.y);
|
|
149
|
-
// encode.number(bytes, changeTree.ref.z);
|
|
168
|
+
// Vec3[$encoder] = function (encoder, bytes, changeTree, index, operation, it) {
|
|
169
|
+
// encode.number(bytes, changeTree.ref.x, it);
|
|
170
|
+
// encode.number(bytes, changeTree.ref.y, it);
|
|
171
|
+
// encode.number(bytes, changeTree.ref.z, it);
|
|
150
172
|
// };
|
|
151
173
|
// Vec3[$decoder] = function (
|
|
152
174
|
// decoder: Decoder<any>,
|
|
@@ -168,78 +190,170 @@ class Entity extends Schema_1.Schema {
|
|
|
168
190
|
}
|
|
169
191
|
}
|
|
170
192
|
__decorate([
|
|
171
|
-
(0, annotations_1.type)(Vec3)
|
|
193
|
+
(0, annotations_1.type)(Vec3),
|
|
194
|
+
__metadata("design:type", Object)
|
|
172
195
|
], Entity.prototype, "position", void 0);
|
|
173
|
-
|
|
174
|
-
|
|
196
|
+
class Card extends Schema_1.Schema {
|
|
197
|
+
}
|
|
198
|
+
__decorate([
|
|
199
|
+
(0, annotations_1.type)("string"),
|
|
200
|
+
__metadata("design:type", String)
|
|
201
|
+
], Card.prototype, "suit", void 0);
|
|
202
|
+
__decorate([
|
|
203
|
+
(0, annotations_1.type)("number"),
|
|
204
|
+
__metadata("design:type", Number)
|
|
205
|
+
], Card.prototype, "num", void 0);
|
|
175
206
|
class Player extends Entity {
|
|
176
207
|
constructor() {
|
|
177
208
|
super(...arguments);
|
|
178
209
|
this.rotation = new Vec3().assign({ x: 0, y: 0, z: 0 });
|
|
210
|
+
this.secret = "private info only for this player";
|
|
211
|
+
// @type([Card])
|
|
212
|
+
// cards = new ArraySchema<Card>(
|
|
213
|
+
// new Card().assign({ suit: "Hearts", num: 1 }),
|
|
214
|
+
// new Card().assign({ suit: "Spaces", num: 2 }),
|
|
215
|
+
// new Card().assign({ suit: "Diamonds", num: 3 }),
|
|
216
|
+
// );
|
|
179
217
|
}
|
|
180
218
|
}
|
|
181
219
|
__decorate([
|
|
182
|
-
(0, annotations_1.type)(Vec3)
|
|
220
|
+
(0, annotations_1.type)(Vec3),
|
|
221
|
+
__metadata("design:type", Object)
|
|
183
222
|
], Player.prototype, "rotation", void 0);
|
|
223
|
+
__decorate([
|
|
224
|
+
(0, annotations_1.type)("string"),
|
|
225
|
+
__metadata("design:type", String)
|
|
226
|
+
], Player.prototype, "secret", void 0);
|
|
227
|
+
class Team extends Schema_1.Schema {
|
|
228
|
+
constructor() {
|
|
229
|
+
super(...arguments);
|
|
230
|
+
this.entities = new MapSchema_1.MapSchema();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
__decorate([
|
|
234
|
+
(0, annotations_1.type)({ map: Entity }),
|
|
235
|
+
__metadata("design:type", Object)
|
|
236
|
+
], Team.prototype, "entities", void 0);
|
|
184
237
|
class State extends Schema_1.Schema {
|
|
185
238
|
constructor() {
|
|
186
239
|
super(...arguments);
|
|
187
|
-
// @type({ map: Base }) players = new MapSchema<Entity>();
|
|
188
240
|
this.num = 0;
|
|
189
241
|
this.str = "Hello world!";
|
|
190
|
-
|
|
242
|
+
this.teams = new ArraySchema_1.ArraySchema();
|
|
243
|
+
// @type({ map: Entity }) entities = new MapSchema<Entity>();
|
|
244
|
+
// @type(Entity) entity1 = new Player().assign({
|
|
245
|
+
// position: new Vec3().assign({ x: 1, y: 2, z: 3 }),
|
|
246
|
+
// rotation: new Vec3().assign({ x: 4, y: 5, z: 6 }),
|
|
247
|
+
// });
|
|
248
|
+
// @type(Entity) entity2 = new Player().assign({
|
|
191
249
|
// position: new Vec3().assign({ x: 1, y: 2, z: 3 }),
|
|
192
250
|
// rotation: new Vec3().assign({ x: 4, y: 5, z: 6 }),
|
|
193
251
|
// });
|
|
194
|
-
this.entities = new MapSchema_1.MapSchema();
|
|
195
252
|
}
|
|
196
253
|
}
|
|
197
254
|
__decorate([
|
|
198
|
-
(0, annotations_1.type)("number")
|
|
255
|
+
(0, annotations_1.type)("number"),
|
|
256
|
+
__metadata("design:type", Number)
|
|
199
257
|
], State.prototype, "num", void 0);
|
|
200
258
|
__decorate([
|
|
201
|
-
(0, annotations_1.type)("string")
|
|
259
|
+
(0, annotations_1.type)("string"),
|
|
260
|
+
__metadata("design:type", Object)
|
|
202
261
|
], State.prototype, "str", void 0);
|
|
203
262
|
__decorate([
|
|
204
|
-
|
|
205
|
-
|
|
263
|
+
annotations_1.owned,
|
|
264
|
+
(0, annotations_1.type)([Team]),
|
|
265
|
+
__metadata("design:type", Object)
|
|
266
|
+
], State.prototype, "teams", void 0);
|
|
206
267
|
const state = new State();
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
})
|
|
268
|
+
// for (let i=0;i<1000;i++) {
|
|
269
|
+
// state.entities.set("one" + i, new Player().assign({
|
|
270
|
+
// position: new Vec3().assign({ x: 1, y: 2, z: 3 }),
|
|
271
|
+
// rotation: new Vec3().assign({ x: 4, y: 5, z: 6 }),
|
|
272
|
+
// }));
|
|
273
|
+
// }
|
|
274
|
+
// state.entities.set("one", new Player().assign({
|
|
275
|
+
// position: new Vec3().assign({ x: 1, y: 2, z: 3 }),
|
|
276
|
+
// rotation: new Vec3().assign({ x: 4, y: 5, z: 6 }),
|
|
277
|
+
// }));
|
|
278
|
+
// state.entities.set("two", new Player().assign({
|
|
279
|
+
// position: new Vec3().assign({ x: 10, y: 10, z: 3 }),
|
|
280
|
+
// rotation: new Vec3().assign({ x: 4, y: 5, z: 6 }),
|
|
281
|
+
// }));
|
|
282
|
+
function addTeam() {
|
|
283
|
+
const team = new Team();
|
|
284
|
+
team.entities.set("one", new Player().assign({
|
|
285
|
+
position: new Vec3().assign({ x: 1, y: 2, z: 3 }),
|
|
286
|
+
rotation: new Vec3().assign({ x: 4, y: 5, z: 6 }),
|
|
287
|
+
}));
|
|
288
|
+
team.entities.set("two", new Player().assign({
|
|
289
|
+
position: new Vec3().assign({ x: 7, y: 8, z: 9 }),
|
|
290
|
+
rotation: new Vec3().assign({ x: 2, y: 3, z: 4 }),
|
|
291
|
+
}));
|
|
292
|
+
state.teams.push(team);
|
|
293
|
+
}
|
|
294
|
+
addTeam();
|
|
295
|
+
addTeam();
|
|
296
|
+
const it = { offset: 0 };
|
|
215
297
|
const encoder = new Encoder_1.Encoder(state);
|
|
216
|
-
|
|
217
|
-
|
|
298
|
+
// logTime("encode time", () => encoder.encodeAll());
|
|
299
|
+
// const encoded = encoder.encode(it);
|
|
300
|
+
console.log("> will encode all...", state.toJSON());
|
|
301
|
+
const encoded = encoder.encode(it);
|
|
302
|
+
console.log("HEAP TOTAL:", process.memoryUsage().heapTotal / 1024 / 1024, "MB");
|
|
303
|
+
console.log("HEAP USED:", process.memoryUsage().heapUsed / 1024 / 1024, "MB");
|
|
304
|
+
// console.log("encoded.buffer =>", `(${encoded.byteLength} bytes)`);
|
|
305
|
+
const sharedOffset = it.offset;
|
|
306
|
+
// const team1View = new StateView<State>();
|
|
307
|
+
// team1View.owns(state.teams[0]);
|
|
308
|
+
const view = new StateView_1.StateView();
|
|
309
|
+
view.owns(state.teams[0]);
|
|
310
|
+
// view1['owned'].add(state[$changes]);
|
|
311
|
+
// view1['owned'].add(state.teams[$changes]);
|
|
312
|
+
// view1.owns(state.teams[0]);
|
|
313
|
+
// view1.owns(state.entities);
|
|
314
|
+
// view1.owns(state.entities.get("one"));
|
|
315
|
+
const view2 = new StateView_1.StateView();
|
|
316
|
+
console.log(">>> VIEW 2");
|
|
317
|
+
view2.owns(state.teams[1]);
|
|
318
|
+
// view2.owns(state.entities.get("two"));
|
|
319
|
+
console.log("> will encode view 1...");
|
|
320
|
+
const viewEncoded1 = encoder.encodeView(view, sharedOffset, it, encoder.sharedBuffer);
|
|
321
|
+
console.log("done. view1 encoded =>", `(${viewEncoded1.byteLength} bytes)`);
|
|
322
|
+
console.log("> will encode view 2...");
|
|
323
|
+
const viewEncoded2 = encoder.encodeView(view2, sharedOffset, it, encoder.sharedBuffer);
|
|
324
|
+
console.log("done. view2 encoded =>", `(${viewEncoded2.byteLength} bytes)`);
|
|
218
325
|
// setTimeout(() => {
|
|
219
326
|
// for (let i = 0; i < 500000; i++) {
|
|
220
327
|
// encoder.encodeAll();
|
|
221
328
|
// }
|
|
222
329
|
// }, 1000)
|
|
223
|
-
//
|
|
224
|
-
globalThis.perform = function perform() {
|
|
225
|
-
for (let i = 0; i < 500000; i++) {
|
|
226
|
-
encoder.encodeAll();
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
function logTime(label, callback) {
|
|
230
|
-
const time = Date.now();
|
|
231
|
-
for (let i = 0; i < 500000; i++) {
|
|
232
|
-
callback();
|
|
233
|
-
}
|
|
234
|
-
console.log(`${label}:`, Date.now() - time);
|
|
235
|
-
}
|
|
236
|
-
logTime("encode time", () => encoder.encodeAll());
|
|
330
|
+
// logTime("encode time", () => encoder.encodeAll());
|
|
237
331
|
// console.log(`encode: (${encoded.length})`, encoded);
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
332
|
+
console.log("----------------------------------- ENCODE reflection...");
|
|
333
|
+
const encodedReflection = Reflection_1.Reflection.encode(state, encoder.context);
|
|
334
|
+
console.log("----------------------------------- DECODE reflection...");
|
|
335
|
+
const decodedState = Reflection_1.Reflection.decode(encodedReflection);
|
|
336
|
+
// const decodedState = new State();
|
|
337
|
+
const decoder = new Decoder_1.Decoder(decodedState);
|
|
338
|
+
console.log("> will decode...");
|
|
339
|
+
// decoder.decode(encoded);
|
|
340
|
+
const changes = decoder.decode(viewEncoded1);
|
|
341
|
+
// decoder.decode(viewEncoded2);
|
|
342
|
+
console.log("CHANGES =>", changes);
|
|
343
|
+
// log(new DataView(encoded.buffer, 0, it.offset));
|
|
344
|
+
// log(new DataView(viewEncoded1.buffer, 0, it.offset));
|
|
345
|
+
log(decodedState.toJSON());
|
|
346
|
+
// console.log("encoder.$root.changes =>", encoder.$root.changes.length);
|
|
347
|
+
// console.log("encoder.$root.filteredChanges =>", encoder.$root.filteredChanges.length);
|
|
348
|
+
// state.teams[0].entities.get("one").position.x = 100;
|
|
349
|
+
// // encoder.
|
|
350
|
+
// const it2 = { offset: 0 };
|
|
351
|
+
// // const encoded = encoder.encode(it);
|
|
352
|
+
// const encoded2 = encoder.encode(it2);
|
|
353
|
+
// console.log(`> shared encode... (${encoded2.byteLength} bytes)`);
|
|
354
|
+
// const viewEncoded3 = encoder.encodeView(view1, sharedOffset, it, encoder.sharedBuffer);
|
|
355
|
+
// console.log(`> view1... (${viewEncoded3.byteLength} bytes)`);
|
|
356
|
+
// log(decoder.root.toJSON());
|
|
243
357
|
// logTime("decode time", () => decoder.decode(encoded));
|
|
244
358
|
// console.log("changes =>", changes);
|
|
245
359
|
// const rotation = state.entity.rotation;
|
package/lib/v3.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v3.js","sourceRoot":"","sources":["../src/v3.ts"],"names":[],"mappings":";;;;;;;;AAAA,kCAAkC;AAClC,yBAAuB;AAEvB,+CAAqC;AACrC,8EAA8E;AAE9E,qCAA8C;AAC9C,qDAAkD;AAClD,iDAA8C;AAE9C,uCAAoC;AACpC,uCAAoC;AAEpC,+DAA2F;AAI3F,6CAAqG;AACrG,+DAA2F;AAI3F,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A+C;AAC/C,gDAAgD;AAChD,mDAAmD;AACnD,uBAAuB;AACvB,uCAAuC;AACvC,gBAAgB;AAChB,4BAA4B;AAC5B,aAAa;AACb,QAAQ;AACR,IAAI;AAEJ,kBAAkB;AAClB,qDAAqD;AACrD,uCAAuC;AACvC,IAAI;AAEJ,+BAA+B;AAC/B,qCAAqC;AACrC,mCAAmC;AACnC,4CAA4C;AAC5C,mDAAmD","sourcesContent":["import * as util from \"node:util\";\nimport \"./symbol.shim\";\n\nimport { type } from \"./annotations\";\n// import { Reflection, ReflectionField, ReflectionType } from \"./Reflection\";\n\nimport { DataChange, Schema } from \"./Schema\";\nimport { ArraySchema } from \"./types/ArraySchema\";\nimport { MapSchema } from \"./types/MapSchema\";\n\nimport { Encoder } from \"./Encoder\";\nimport { Decoder } from \"./Decoder\";\nimport { OPERATION } from \"./spec\";\nimport { encodeKeyValueOperation, encodeSchemaOperation } from \"./changes/EncodeOperation\";\n\nimport * as encode from \"./encoding/encode\";\nimport * as decode from \"./encoding/decode\";\nimport { $changes, $decoder, $deleteByIndex, $encoder, $getByIndex, $track } from \"./changes/consts\";\nimport { decodeKeyValueOperation, decodeSchemaOperation } from \"./changes/DecodeOperation\";\nimport { Ref } from \"./changes/ChangeTree\";\nimport { Metadata } from \"./Metadata\";\n\n// const timeout = setInterval(() => {}, 1000);\n\n// function decorate({ get, set }, context: ClassAccessorDecoratorContext): ClassAccessorDecoratorResult<any, any> {\n// const field = context.name.toString();\n// // const fieldIndex = Metadata.addField(context.metadata, field, type);\n\n// const parent = Object.getPrototypeOf(context.metadata);\n\n// let lastIndex = (parent && parent[-1] as number) ?? -1;\n// lastIndex++;\n\n// context.metadata[field] = { type: \"number\" };\n\n// Object.defineProperty(context.metadata, lastIndex, {\n// value: field,\n// enumerable: false,\n// configurable: true,\n// });\n\n// Object.defineProperty(context.metadata, -1, {\n// value: lastIndex,\n// enumerable: false,\n// configurable: true\n// });\n\n// return {\n// init(value) { return value; },\n// get() { return get.call(this); },\n// set(value: any) { set.call(this, value); },\n// };\n// }\n\n// class Fruit {\n// @decorate accessor frutose: number = 1;\n// }\n\n// class Banana extends Fruit {\n// @decorate accessor potassium: number = 10;\n// }\n\n// class Berry extends Fruit {\n// @decorate accessor antioxidants: number = 10;\n// }\n\n// class Strawberry extends Berry {\n// @decorate accessor fiber: number = 10;\n// }\n\n// class Grape extends Berry {\n// @decorate accessor vitaminc: number = 5;\n// }\n\n// console.log(\"fruit:\", Fruit[Symbol.metadata], Object.keys(Fruit[Symbol.metadata]));\n// console.log(\"banana:\", Banana[Symbol.metadata], Object.keys(Banana[Symbol.metadata]));\n// console.log(\"strawberry:\", Strawberry[Symbol.metadata], Object.keys(Strawberry[Symbol.metadata]));\n// console.log(\"grape:\", Grape[Symbol.metadata], Object.keys(Grape[Symbol.metadata]));\n\n// console.log(\"GRAPE =>\");\n\n// function printFields(metadata) {\n// let i = 0;\n// const len = metadata[-1]\n// console.log({ len });\n// for (let i = 0; i <= len; i++) {\n// console.log(\"over len...\", i, metadata[i])\n// }\n// }\n\n// console.log(\"Grape...\");\n// printFields(Grape[Symbol.metadata]);\n\n// console.log(\"Banana...\");\n// printFields(Banana[Symbol.metadata]);\n\n\n// class Item extends Schema {\n// @type(\"string\") accessor name: string;\n// }\n\n// class RootState extends Schema {\n// @type([Item]) accessor items = new ArraySchema<Item>();\n// }\n\n// const s = new RootState();\n// s.items.push(new Item().assign({ name: \"hello\" }));\n\n// const encoder = new Encoder(s);\n// const encoded = encoder.encode();\n\n// const decoder = new Decoder(new RootState());\n// decoder.decode(encoded);\n\n// process.exit();\n\nfunction log(message: any) {\n console.log(util.inspect(message, false, 10, true));\n}\n\nSchema[$encoder] = encodeSchemaOperation;\nSchema[$decoder] = decodeSchemaOperation;\n\nMapSchema[$encoder] = encodeKeyValueOperation;\nMapSchema[$decoder] = decodeKeyValueOperation;\n\nArraySchema[$encoder] = encodeKeyValueOperation;\nArraySchema[$encoder] = decodeKeyValueOperation;\n\nclass Vec3 extends Schema {\n @type(\"number\") x: number;\n @type(\"number\") y: number;\n @type(\"number\") z: number;\n}\n\n// class Vec3 {\n// x: number;\n// y: number;\n// z: number;\n// constructor() {\n// Schema.initialize(this);\n// }\n// assign(data: { x: number, y: number, z: number }) {\n// this.x = data.x;\n// this.y = data.y;\n// this.z = data.z;\n// return this;\n// }\n// }\n// Metadata.setFields(Vec3, {\n// x: \"number\",\n// y: \"number\",\n// z: \"number\",\n// });\n// Vec3.prototype[$getByIndex] = function (index: number) {\n// return this[this.constructor[Symbol.metadata][index]];\n// };\n// Vec3.prototype[$deleteByIndex] = function (index: number) {\n// this[this.constructor[Symbol.metadata][index]] = undefined;\n// };\n// Vec3[$track] = function (changeTree, index: number, operation: OPERATION = OPERATION.ADD) {\n// changeTree.change(index, operation, encodeSchemaOperation);\n// };\n// Vec3[$encoder] = encodeSchemaOperation;\n// Vec3[$decoder] = decodeSchemaOperation;\n// // @ts-ignore\n// if (!Vec3.prototype.toJSON) { Vec3.prototype.toJSON = Schema.prototype.toJSON; }\n\n// -------------------------------------------------------------------------------\n\n// Vec3[$track] = function (changeTree, index) {\n// changeTree.change(0, OPERATION.ADD);\n// };\n// Vec3[$encoder] = function (encoder, bytes, changeTree, index, operation) {\n// encode.number(bytes, changeTree.ref.x);\n// encode.number(bytes, changeTree.ref.y);\n// encode.number(bytes, changeTree.ref.z);\n// };\n// Vec3[$decoder] = function (\n// decoder: Decoder<any>,\n// bytes: number[],\n// it: decode.Iterator,\n// ref: Vec3,\n// allChanges: DataChange[]\n// ) {\n// ref.x = decode.number(bytes, it);\n// ref.y = decode.number(bytes, it);\n// ref.z = decode.number(bytes, it);\n// };\n\nclass Base extends Schema {}\n\nclass Entity extends Schema {\n @type(Vec3) position = new Vec3().assign({ x: 0, y: 0, z: 0 });\n}\n\n// TODO: @entity shouldn't be required here.\n// (TypeContext.register() is required for inheritance support)\nclass Player extends Entity {\n @type(Vec3) rotation = new Vec3().assign({ x: 0, y: 0, z: 0 });\n}\n\nclass State extends Schema {\n // @type({ map: Base }) players = new MapSchema<Entity>();\n @type(\"number\") num: number = 0;\n @type(\"string\") str = \"Hello world!\";\n // @type(Entity) entity = new Player().assign({\n // position: new Vec3().assign({ x: 1, y: 2, z: 3 }),\n // rotation: new Vec3().assign({ x: 4, y: 5, z: 6 }),\n // });\n @type({ map: Entity }) entities = new MapSchema<Entity>();\n}\n\nconst state = new State();\n\nstate.entities.set(\"one\", new Player().assign({\n position: new Vec3().assign({ x: 1, y: 2, z: 3 }),\n rotation: new Vec3().assign({ x: 4, y: 5, z: 6 }),\n}));\n\nstate.entities.set(\"two\", new Player().assign({\n position: new Vec3().assign({ x: 7, y: 8, z: 9 }),\n rotation: new Vec3().assign({ x: 2, y: 3, z: 4 }),\n}));\n\nconst encoder = new Encoder(state);\nconst encoded = encoder.encodeAll();\nconsole.log(`(${encoded.length})`, encoded);\n\n// setTimeout(() => {\n// for (let i = 0; i < 500000; i++) {\n// encoder.encodeAll();\n// }\n// }, 1000)\n\n// @ts-ignore\nglobalThis.perform = function perform() {\n for (let i = 0; i < 500000; i++) {\n encoder.encodeAll();\n }\n}\n\nfunction logTime(label: string, callback: Function) {\n const time = Date.now();\n for (let i = 0; i < 500000; i++) {\n callback();\n }\n console.log(`${label}:`, Date.now() - time);\n}\nlogTime(\"encode time\", () => encoder.encodeAll());\n\n// console.log(`encode: (${encoded.length})`, encoded);\n\n// const encodedReflection = Reflection.encode(state, encoder.context);\n// const decoded = Reflection.decode(encodedReflection);\n\nconst decoder = new Decoder(new State());\ndecoder.decode(encoded);\n\nlog(decoder.root.toJSON());\n// logTime(\"decode time\", () => decoder.decode(encoded));\n\n// console.log(\"changes =>\", changes);\n\n// const rotation = state.entity.rotation;\n// rotation.x = 100;\n\n// state.entity.rotation = undefined;\n\n// const encoded2 = encoder.encode();\n// console.log({ encoded2 });\n\n// decoder.decode(encoded2);\n// console.log(\"decoded =>\", decoded.toJSON());\n\n// console.profile();\n// const time = Date.now();\n// for (let i = 0; i < 300000; i++) {\n// const state = new State();\n// encoder['setRoot'](state);\n// encoder.encode();\n// }\n// console.log(\"encode time:\", Date.now() - time);\n// console.profileEnd();\n\n// state.players.set(\"entity\", new Entity());\n// state.players.set(\"one\", new Player());\n// console.log(\"state:\", state);\n// console.log(\"state.players\", state.players);\n// console.log(\"state.players.one\", state.players.get(\"one\"));\n// console.log(\"state.players.one.position\", state.players.get(\"one\").position);\n\n// const encoder = new Encoder(state);\n// // encoder.change()\n\n// let encoded = encoder.encodeAll();\n// console.log({ encoded })\n\n// const decoder = new Decoder(new State());\n// decoder.decode(encoded);\n// log(decoder['root'].toJSON());\n\n// const reflection = Reflection.encode(state);\n// console.log(\"encoded =>\", reflection);\n// log(Reflection.decode(reflection))\n\n///////...............................................\n// function type (type: string) {\n// return function (_: any, context: ClassFieldDecoratorContext) {\n// context.addInitializer(function() {\n// console.log(\"INITIALIZER!\", this);\n// setTimeout(() => {\n// context.access.set(this, \"WHAT\");\n// }, 1000);\n// });\n\n// context.access.get = function(object) {\n// return object[context.name];\n// }\n\n// context.access.set = function(object, value) {\n// console.log(\"setter...\", object, value);\n// object[context.name] = `Setter[${value}]`;\n// };\n\n// return function(value) {\n// console.log(\"SET\", this, value);\n// if (typeof(value) === \"string\") {\n// value = `Initializer[${value}]`;\n// } else {\n// value = value * 100;\n// }\n// return value;\n// };\n// }\n// }\n\n// class MyState {\n// @type(\"string\") name: string = \"Hello world!\";\n// @type(\"number\") num: number = 1;\n// }\n\n// const state = new MyState();\n// console.log(\"name: \", state.name);\n// console.log(\"num: \", state.num);\n// state.name = `${state.name} modified...`;\n// setTimeout(() => console.log(state.name), 1100);\n"]}
|
|
1
|
+
{"version":3,"file":"v3.js","sourceRoot":"","sources":["../src/v3.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,kCAAkC;AAClC,yBAAuB;AAEvB,+CAA4C;AAC5C,8EAA8E;AAE9E,qCAA8C;AAC9C,qDAAkD;AAClD,iDAA8C;AAE9C,+CAA4C;AAC5C,+CAA4C;AAE5C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CAA0C;AAC1C,gCAAgC;AAChC,+CAA+C;AAC/C,8DAA8D;AAC9D,gFAAgF;AAEhF,sCAAsC;AACtC,sBAAsB;AAEtB,qCAAqC;AACrC,2BAA2B;AAE3B,4CAA4C;AAC5C,2BAA2B;AAC3B,iCAAiC;AAEjC,+CAA+C;AAC/C,yCAAyC;AACzC,qCAAqC;AAErC,sDAAsD;AACtD,iCAAiC;AACjC,sEAAsE;AACtE,8CAA8C;AAC9C,iDAAiD;AACjD,iCAAiC;AACjC,oDAAoD;AACpD,wBAAwB;AACxB,cAAc;AAEd,kDAAkD;AAClD,2CAA2C;AAC3C,YAAY;AAEZ,yDAAyD;AACzD,uDAAuD;AACvD,yDAAyD;AACzD,aAAa;AAEb,mCAAmC;AACnC,+CAA+C;AAC/C,gDAAgD;AAChD,mDAAmD;AACnD,uBAAuB;AACvB,uCAAuC;AACvC,gBAAgB;AAChB,4BAA4B;AAC5B,aAAa;AACb,QAAQ;AACR,IAAI;AAEJ,kBAAkB;AAClB,qDAAqD;AACrD,uCAAuC;AACvC,IAAI;AAEJ,+BAA+B;AAC/B,qCAAqC;AACrC,mCAAmC;AACnC,4CAA4C;AAC5C,mDAAmD","sourcesContent":["import * as util from \"node:util\";\nimport \"./symbol.shim\";\n\nimport { owned, type } from \"./annotations\";\n// import { Reflection, ReflectionField, ReflectionType } from \"./Reflection\";\n\nimport { DataChange, Schema } from \"./Schema\";\nimport { ArraySchema } from \"./types/ArraySchema\";\nimport { MapSchema } from \"./types/MapSchema\";\n\nimport { Encoder } from \"./encoder/Encoder\";\nimport { Decoder } from \"./decoder/Decoder\";\nimport { OPERATION } from \"./encoding/spec\";\nimport { encodeKeyValueOperation, encodeSchemaOperation, encodeValue } from \"./encoder/EncodeOperation\";\n\nimport * as encode from \"./encoding/encode\";\nimport * as decode from \"./encoding/decode\";\nimport { $changes, $decoder, $deleteByIndex, $encoder, $getByIndex, $track } from \"./types/symbols\";\nimport { decodeKeyValueOperation, decodeSchemaOperation } from \"./decoder/DecodeOperation\";\nimport { ChangeTree, Ref } from \"./encoder/ChangeTree\";\nimport { Metadata } from \"./Metadata\";\nimport { Reflection } from \"./Reflection\";\nimport { StateView } from \"./encoder/StateView\";\n\nfunction logSingleCall(label: string, callback: Function) {\n const time = Date.now();\n const res = callback();\n console.log(`${label}:`, Date.now() - time);\n return res;\n}\n\nfunction logTime(label: string, callback: Function) {\n const time = Date.now();\n for (let i = 0; i < 500000; i++) {\n callback();\n }\n console.log(`${label}:`, Date.now() - time);\n}\n\n\n// // @ts-ignore\n// globalThis.perform = function perform() {\n// for (let i = 0; i < 500000; i++) {\n// encoder.encodeAll();\n// }\n// }\n\n// const timeout = setInterval(() => {}, 1000);\n\n// function decorate({ get, set }, context: ClassAccessorDecoratorContext): ClassAccessorDecoratorResult<any, any> {\n// const field = context.name.toString();\n// // const fieldIndex = Metadata.addField(context.metadata, field, type);\n\n// const parent = Object.getPrototypeOf(context.metadata);\n\n// let lastIndex = (parent && parent[-1] as number) ?? -1;\n// lastIndex++;\n\n// context.metadata[field] = { type: \"number\" };\n\n// Object.defineProperty(context.metadata, lastIndex, {\n// value: field,\n// enumerable: false,\n// configurable: true,\n// });\n\n// Object.defineProperty(context.metadata, -1, {\n// value: lastIndex,\n// enumerable: false,\n// configurable: true\n// });\n\n// return {\n// init(value) { return value; },\n// get() { return get.call(this); },\n// set(value: any) { set.call(this, value); },\n// };\n// }\n\n// class Fruit {\n// @decorate accessor frutose: number = 1;\n// }\n\n// class Banana extends Fruit {\n// @decorate accessor potassium: number = 10;\n// }\n\n// class Berry extends Fruit {\n// @decorate accessor antioxidants: number = 10;\n// }\n\n// class Strawberry extends Berry {\n// @decorate accessor fiber: number = 10;\n// }\n\n// class Grape extends Berry {\n// @decorate accessor vitaminc: number = 5;\n// }\n\n// console.log(\"fruit:\", Fruit[Symbol.metadata], Object.keys(Fruit[Symbol.metadata]));\n// console.log(\"banana:\", Banana[Symbol.metadata], Object.keys(Banana[Symbol.metadata]));\n// console.log(\"strawberry:\", Strawberry[Symbol.metadata], Object.keys(Strawberry[Symbol.metadata]));\n// console.log(\"grape:\", Grape[Symbol.metadata], Object.keys(Grape[Symbol.metadata]));\n\n// console.log(\"GRAPE =>\");\n\n// function printFields(metadata) {\n// let i = 0;\n// const len = metadata[-1]\n// console.log({ len });\n// for (let i = 0; i <= len; i++) {\n// console.log(\"over len...\", i, metadata[i])\n// }\n// }\n\n// console.log(\"Grape...\");\n// printFields(Grape[Symbol.metadata]);\n\n// console.log(\"Banana...\");\n// printFields(Banana[Symbol.metadata]);\n\n\n// class Item extends Schema {\n// @type(\"string\") accessor name: string;\n// }\n\n// class RootState extends Schema {\n// @type([Item]) accessor items = new ArraySchema<Item>();\n// }\n\n// const s = new RootState();\n// s.items.push(new Item().assign({ name: \"hello\" }));\n\n// const encoder = new Encoder(s);\n// const encoded = encoder.encode();\n\n// const decoder = new Decoder(new RootState());\n// decoder.decode(encoded);\n\nfunction log(message: any) {\n console.log(util.inspect(message, false, 10, true));\n}\n\nSchema[$encoder] = encodeSchemaOperation;\nSchema[$decoder] = decodeSchemaOperation;\n\nMapSchema[$encoder] = encodeKeyValueOperation;\nMapSchema[$decoder] = decodeKeyValueOperation;\n\nArraySchema[$encoder] = encodeKeyValueOperation;\nArraySchema[$decoder] = decodeKeyValueOperation;\n\n// // No need to extend Schema!\n// class Vec3 {\n// x: number;\n// y: number;\n// z: number;\n// constructor() {\n// // Need to initialize property descriptors\n// Schema.initialize(this);\n// }\n// }\n// // Define fields to encode/decode\n// Metadata.setFields(Vec3, {\n// x: \"number\",\n// y: \"number\",\n// z: \"number\",\n// });\n// //\n// Vec3[$track] = function (\n// changeTree: ChangeTree,\n// index: number,\n// operation: OPERATION = OPERATION.ADD\n// ) {\n// changeTree.change(index, operation);\n// };\n// Vec3[$encoder] = encodeSchemaOperation;\n// Vec3[$decoder] = decodeSchemaOperation;\n// // @ts-ignore\n// if (!Vec3.prototype.toJSON) { Vec3.prototype.toJSON = Schema.prototype.toJSON; }\n\n// -------------------------------------------------------------------------------\n\nclass Vec3 extends Schema {\n @type(\"number\") x: number;\n @type(\"number\") y: number;\n @type(\"number\") z: number;\n}\n// Vec3[$track] = function (changeTree, index) {\n// changeTree.change(0, OPERATION.ADD);\n// };\n// Vec3[$encoder] = function (encoder, bytes, changeTree, index, operation, it) {\n// encode.number(bytes, changeTree.ref.x, it);\n// encode.number(bytes, changeTree.ref.y, it);\n// encode.number(bytes, changeTree.ref.z, it);\n// };\n// Vec3[$decoder] = function (\n// decoder: Decoder<any>,\n// bytes: number[],\n// it: decode.Iterator,\n// ref: Vec3,\n// allChanges: DataChange[]\n// ) {\n// ref.x = decode.number(bytes, it);\n// ref.y = decode.number(bytes, it);\n// ref.z = decode.number(bytes, it);\n// };\n\nclass Base extends Schema {}\n\nclass Entity extends Schema {\n @type(Vec3) position = new Vec3().assign({ x: 0, y: 0, z: 0 });\n}\n\nclass Card extends Schema {\n @type(\"string\") suit: string;\n @type(\"number\") num: number;\n}\n\nclass Player extends Entity {\n @type(Vec3) rotation = new Vec3().assign({ x: 0, y: 0, z: 0 });\n @type(\"string\") secret: string = \"private info only for this player\";\n\n // @type([Card])\n // cards = new ArraySchema<Card>(\n // new Card().assign({ suit: \"Hearts\", num: 1 }),\n // new Card().assign({ suit: \"Spaces\", num: 2 }),\n // new Card().assign({ suit: \"Diamonds\", num: 3 }),\n // );\n}\n\nclass Team extends Schema {\n @type({ map: Entity }) entities = new MapSchema<Entity>();\n}\n\nclass State extends Schema {\n @type(\"number\") num: number = 0;\n @type(\"string\") str = \"Hello world!\"\n\n @owned @type([Team]) teams = new ArraySchema<Team>();\n\n // @type({ map: Entity }) entities = new MapSchema<Entity>();\n\n // @type(Entity) entity1 = new Player().assign({\n // position: new Vec3().assign({ x: 1, y: 2, z: 3 }),\n // rotation: new Vec3().assign({ x: 4, y: 5, z: 6 }),\n // });\n // @type(Entity) entity2 = new Player().assign({\n // position: new Vec3().assign({ x: 1, y: 2, z: 3 }),\n // rotation: new Vec3().assign({ x: 4, y: 5, z: 6 }),\n // });\n}\n\nconst state = new State();\n\n// for (let i=0;i<1000;i++) {\n// state.entities.set(\"one\" + i, new Player().assign({\n// position: new Vec3().assign({ x: 1, y: 2, z: 3 }),\n// rotation: new Vec3().assign({ x: 4, y: 5, z: 6 }),\n// }));\n// }\n\n// state.entities.set(\"one\", new Player().assign({\n// position: new Vec3().assign({ x: 1, y: 2, z: 3 }),\n// rotation: new Vec3().assign({ x: 4, y: 5, z: 6 }),\n// }));\n\n// state.entities.set(\"two\", new Player().assign({\n// position: new Vec3().assign({ x: 10, y: 10, z: 3 }),\n// rotation: new Vec3().assign({ x: 4, y: 5, z: 6 }),\n// }));\n\nfunction addTeam() {\n const team = new Team();\n team.entities.set(\"one\", new Player().assign({\n position: new Vec3().assign({ x: 1, y: 2, z: 3 }),\n rotation: new Vec3().assign({ x: 4, y: 5, z: 6 }),\n }));\n team.entities.set(\"two\", new Player().assign({\n position: new Vec3().assign({ x: 7, y: 8, z: 9 }),\n rotation: new Vec3().assign({ x: 2, y: 3, z: 4 }),\n }));\n state.teams.push(team);\n}\n\naddTeam();\naddTeam();\n\nconst it = { offset: 0 };\n\n\nconst encoder = new Encoder(state);\n// logTime(\"encode time\", () => encoder.encodeAll());\n\n// const encoded = encoder.encode(it);\n\nconsole.log(\"> will encode all...\", state.toJSON());\nconst encoded = encoder.encode(it);\n\nconsole.log(\"HEAP TOTAL:\", process.memoryUsage().heapTotal / 1024 / 1024, \"MB\");\nconsole.log(\"HEAP USED:\", process.memoryUsage().heapUsed / 1024 / 1024, \"MB\");\n\n// console.log(\"encoded.buffer =>\", `(${encoded.byteLength} bytes)`);\n\nconst sharedOffset = it.offset;\n\n// const team1View = new StateView<State>();\n// team1View.owns(state.teams[0]);\n\nconst view = new StateView();\nview.owns(state.teams[0]);\n\n// view1['owned'].add(state[$changes]);\n// view1['owned'].add(state.teams[$changes]);\n// view1.owns(state.teams[0]);\n// view1.owns(state.entities);\n// view1.owns(state.entities.get(\"one\"));\n\nconst view2 = new StateView<State>();\nconsole.log(\">>> VIEW 2\");\nview2.owns(state.teams[1]);\n// view2.owns(state.entities.get(\"two\"));\n\nconsole.log(\"> will encode view 1...\");\nconst viewEncoded1 = encoder.encodeView(view, sharedOffset, it, encoder.sharedBuffer);\nconsole.log(\"done. view1 encoded =>\", `(${viewEncoded1.byteLength} bytes)`);\n\nconsole.log(\"> will encode view 2...\");\nconst viewEncoded2 = encoder.encodeView(view2, sharedOffset, it, encoder.sharedBuffer);\nconsole.log(\"done. view2 encoded =>\", `(${viewEncoded2.byteLength} bytes)`);\n\n// setTimeout(() => {\n// for (let i = 0; i < 500000; i++) {\n// encoder.encodeAll();\n// }\n// }, 1000)\n\n// logTime(\"encode time\", () => encoder.encodeAll());\n\n// console.log(`encode: (${encoded.length})`, encoded);\n\nconsole.log(\"----------------------------------- ENCODE reflection...\");\nconst encodedReflection = Reflection.encode(state, encoder.context);\nconsole.log(\"----------------------------------- DECODE reflection...\");\nconst decodedState = Reflection.decode<State>(encodedReflection);\n\n// const decodedState = new State();\nconst decoder = new Decoder(decodedState);\n\nconsole.log(\"> will decode...\");\n\n// decoder.decode(encoded);\nconst changes = decoder.decode(viewEncoded1);\n\n// decoder.decode(viewEncoded2);\nconsole.log(\"CHANGES =>\", changes)\n\n// log(new DataView(encoded.buffer, 0, it.offset));\n// log(new DataView(viewEncoded1.buffer, 0, it.offset));\nlog(decodedState.toJSON());\n\n// console.log(\"encoder.$root.changes =>\", encoder.$root.changes.length);\n// console.log(\"encoder.$root.filteredChanges =>\", encoder.$root.filteredChanges.length);\n\n// state.teams[0].entities.get(\"one\").position.x = 100;\n\n// // encoder.\n\n// const it2 = { offset: 0 };\n// // const encoded = encoder.encode(it);\n// const encoded2 = encoder.encode(it2);\n// console.log(`> shared encode... (${encoded2.byteLength} bytes)`);\n\n// const viewEncoded3 = encoder.encodeView(view1, sharedOffset, it, encoder.sharedBuffer);\n// console.log(`> view1... (${viewEncoded3.byteLength} bytes)`);\n\n\n// log(decoder.root.toJSON());\n// logTime(\"decode time\", () => decoder.decode(encoded));\n\n// console.log(\"changes =>\", changes);\n\n// const rotation = state.entity.rotation;\n// rotation.x = 100;\n\n// state.entity.rotation = undefined;\n\n// const encoded2 = encoder.encode();\n// console.log({ encoded2 });\n\n// decoder.decode(encoded2);\n// console.log(\"decoded =>\", decoded.toJSON());\n\n// console.profile();\n// const time = Date.now();\n// for (let i = 0; i < 300000; i++) {\n// const state = new State();\n// encoder['setRoot'](state);\n// encoder.encode();\n// }\n// console.log(\"encode time:\", Date.now() - time);\n// console.profileEnd();\n\n// state.players.set(\"entity\", new Entity());\n// state.players.set(\"one\", new Player());\n// console.log(\"state:\", state);\n// console.log(\"state.players\", state.players);\n// console.log(\"state.players.one\", state.players.get(\"one\"));\n// console.log(\"state.players.one.position\", state.players.get(\"one\").position);\n\n// const encoder = new Encoder(state);\n// // encoder.change()\n\n// let encoded = encoder.encodeAll();\n// console.log({ encoded })\n\n// const decoder = new Decoder(new State());\n// decoder.decode(encoded);\n// log(decoder['root'].toJSON());\n\n// const reflection = Reflection.encode(state);\n// console.log(\"encoded =>\", reflection);\n// log(Reflection.decode(reflection))\n\n///////...............................................\n// function type (type: string) {\n// return function (_: any, context: ClassFieldDecoratorContext) {\n// context.addInitializer(function() {\n// console.log(\"INITIALIZER!\", this);\n// setTimeout(() => {\n// context.access.set(this, \"WHAT\");\n// }, 1000);\n// });\n\n// context.access.get = function(object) {\n// return object[context.name];\n// }\n\n// context.access.set = function(object, value) {\n// console.log(\"setter...\", object, value);\n// object[context.name] = `Setter[${value}]`;\n// };\n\n// return function(value) {\n// console.log(\"SET\", this, value);\n// if (typeof(value) === \"string\") {\n// value = `Initializer[${value}]`;\n// } else {\n// value = value * 100;\n// }\n// return value;\n// };\n// }\n// }\n\n// class MyState {\n// @type(\"string\") name: string = \"Hello world!\";\n// @type(\"number\") num: number = 1;\n// }\n\n// const state = new MyState();\n// console.log(\"name: \", state.name);\n// console.log(\"num: \", state.num);\n// state.name = `${state.name} modified...`;\n// setTimeout(() => console.log(state.name), 1100);\n"]}
|