@colyseus/schema 3.0.0-alpha.49 → 3.0.0-alpha.50
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 +18 -46
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +18 -46
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +18 -46
- package/lib/encoder/Encoder.js +18 -46
- package/lib/encoder/Encoder.js.map +1 -1
- package/package.json +1 -1
- package/src/encoder/Encoder.ts +19 -59
package/build/esm/index.mjs
CHANGED
|
@@ -3794,20 +3794,12 @@ class Encoder {
|
|
|
3794
3794
|
const changeTrees = this.root[changeSetName];
|
|
3795
3795
|
for (let i = 0, numChangeTrees = changeTrees.length; i < numChangeTrees; i++) {
|
|
3796
3796
|
const changeTree = changeTrees[i];
|
|
3797
|
-
// // Root#removeChangeFromChangeSet() is now removing instead of setting to "undefined"
|
|
3798
|
-
// if (changeTree === undefined) { continue; }
|
|
3799
3797
|
const operations = changeTree[changeSetName];
|
|
3800
3798
|
const ref = changeTree.ref;
|
|
3801
3799
|
const ctor = ref.constructor;
|
|
3802
3800
|
const encoder = ctor[$encoder];
|
|
3803
3801
|
const filter = ctor[$filter];
|
|
3804
3802
|
const metadata = ctor[Symbol.metadata];
|
|
3805
|
-
// try { throw new Error(); } catch (e) {
|
|
3806
|
-
// // only print if not coming from Reflection.ts
|
|
3807
|
-
// if (!e.stack.includes("src/Reflection.ts")) {
|
|
3808
|
-
// console.log("ChangeTree:", { refId: changeTree.refId, ref: ref.constructor.name });
|
|
3809
|
-
// }
|
|
3810
|
-
// }
|
|
3811
3803
|
if (hasView) {
|
|
3812
3804
|
if (!view.items.has(changeTree)) {
|
|
3813
3805
|
view.invisible.add(changeTree);
|
|
@@ -3842,24 +3834,12 @@ class Encoder {
|
|
|
3842
3834
|
// view?.invisible.add(changeTree);
|
|
3843
3835
|
continue;
|
|
3844
3836
|
}
|
|
3845
|
-
// try { throw new Error(); } catch (e) {
|
|
3846
|
-
// // only print if not coming from Reflection.ts
|
|
3847
|
-
// if (!e.stack.includes("src/Reflection.ts")) {
|
|
3848
|
-
// console.log("WILL ENCODE", {
|
|
3849
|
-
// ref: changeTree.ref.constructor.name,
|
|
3850
|
-
// fieldIndex,
|
|
3851
|
-
// operation: OPERATION[operation],
|
|
3852
|
-
// });
|
|
3853
|
-
// }
|
|
3854
|
-
// }
|
|
3855
|
-
// console.log("encode...", { ref: changeTree.ref.constructor.name, refId: changeTree.refId, fieldIndex, operation });
|
|
3856
3837
|
encoder(this, buffer, changeTree, fieldIndex, operation, it, isEncodeAll, hasView, metadata);
|
|
3857
3838
|
}
|
|
3858
|
-
if (shouldDiscardChanges) {
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
}
|
|
3839
|
+
// if (shouldDiscardChanges) {
|
|
3840
|
+
// changeTree.discard();
|
|
3841
|
+
// changeTree.isNew = false; // Not a new instance anymore
|
|
3842
|
+
// }
|
|
3863
3843
|
}
|
|
3864
3844
|
if (it.offset > buffer.byteLength) {
|
|
3865
3845
|
const newSize = getNextPowerOf2(buffer.byteLength * 2);
|
|
@@ -3871,7 +3851,7 @@ class Encoder {
|
|
|
3871
3851
|
//
|
|
3872
3852
|
// resize buffer and re-encode (TODO: can we avoid re-encoding here?)
|
|
3873
3853
|
//
|
|
3874
|
-
buffer = Buffer.
|
|
3854
|
+
buffer = Buffer.alloc(newSize);
|
|
3875
3855
|
// assign resized buffer to local sharedBuffer
|
|
3876
3856
|
if (buffer === this.sharedBuffer) {
|
|
3877
3857
|
this.sharedBuffer = buffer;
|
|
@@ -3879,28 +3859,27 @@ class Encoder {
|
|
|
3879
3859
|
return this.encode({ offset: initialOffset }, view, buffer, changeSetName, isEncodeAll);
|
|
3880
3860
|
}
|
|
3881
3861
|
else {
|
|
3882
|
-
//
|
|
3883
|
-
//
|
|
3884
|
-
//
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3862
|
+
//
|
|
3863
|
+
// only clear changes after making sure buffer resize is not required.
|
|
3864
|
+
//
|
|
3865
|
+
if (shouldDiscardChanges) {
|
|
3866
|
+
//
|
|
3867
|
+
// TODO: avoid iterating over change trees twice.
|
|
3868
|
+
//
|
|
3869
|
+
for (let i = 0, numChangeTrees = changeTrees.length; i < numChangeTrees; i++) {
|
|
3870
|
+
const changeTree = changeTrees[i];
|
|
3871
|
+
changeTree.discard();
|
|
3872
|
+
changeTree.isNew = false; // Not a new instance anymore
|
|
3873
|
+
}
|
|
3874
|
+
}
|
|
3891
3875
|
return buffer.subarray(0, it.offset);
|
|
3892
3876
|
}
|
|
3893
3877
|
}
|
|
3894
3878
|
encodeAll(it = { offset: 0 }, buffer = this.sharedBuffer) {
|
|
3895
|
-
// console.log(`\nencodeAll(), this.root.allChanges (${(Object.keys(this.root.allChanges).length)})`);
|
|
3896
|
-
// this.debugChanges("allChanges");
|
|
3897
3879
|
return this.encode(it, undefined, buffer, "allChanges", true);
|
|
3898
3880
|
}
|
|
3899
3881
|
encodeAllView(view, sharedOffset, it, bytes = this.sharedBuffer) {
|
|
3900
3882
|
const viewOffset = it.offset;
|
|
3901
|
-
// console.log(`\nencodeAllView(), this.root.allFilteredChanges (${(Object.keys(this.root.allFilteredChanges).length)})`);
|
|
3902
|
-
// this.debugChanges("allFilteredChanges");
|
|
3903
|
-
// console.log("\n\nENCODE ALL FOR VIEW...\n\n")
|
|
3904
3883
|
// try to encode "filtered" changes
|
|
3905
3884
|
this.encode(it, view, bytes, "allFilteredChanges", true, viewOffset);
|
|
3906
3885
|
return Buffer.concat([
|
|
@@ -3928,13 +3907,8 @@ class Encoder {
|
|
|
3928
3907
|
}
|
|
3929
3908
|
encodeView(view, sharedOffset, it, bytes = this.sharedBuffer) {
|
|
3930
3909
|
const viewOffset = it.offset;
|
|
3931
|
-
// console.log(`\nencodeView(), view.changes (${view.changes.size})`);
|
|
3932
|
-
// this.debugChanges(view.changes);
|
|
3933
|
-
// console.log(`\nencodeView(), this.root.filteredChanges (${this.root.filteredChanges.size})`);
|
|
3934
|
-
// this.debugChanges("filteredChanges");
|
|
3935
3910
|
// encode visibility changes (add/remove for this view)
|
|
3936
3911
|
const refIds = Object.keys(view.changes);
|
|
3937
|
-
// console.log("ENCODE VIEW:", refIds);
|
|
3938
3912
|
for (let i = 0, numRefIds = refIds.length; i < numRefIds; i++) {
|
|
3939
3913
|
const refId = refIds[i];
|
|
3940
3914
|
const changes = view.changes[refId];
|
|
@@ -3966,7 +3940,6 @@ class Encoder {
|
|
|
3966
3940
|
//
|
|
3967
3941
|
// clear "view" changes after encoding
|
|
3968
3942
|
view.changes = {};
|
|
3969
|
-
// console.log("FILTERED CHANGES:", this.root.filteredChanges);
|
|
3970
3943
|
// try to encode "filtered" changes
|
|
3971
3944
|
this.encode(it, view, bytes, "filteredChanges", false, viewOffset);
|
|
3972
3945
|
return Buffer.concat([
|
|
@@ -3989,7 +3962,6 @@ class Encoder {
|
|
|
3989
3962
|
// }
|
|
3990
3963
|
}
|
|
3991
3964
|
discardChanges() {
|
|
3992
|
-
// console.log("DISCARD CHANGES!");
|
|
3993
3965
|
// discard shared changes
|
|
3994
3966
|
let length = this.root.changes.length;
|
|
3995
3967
|
if (length > 0) {
|