mirror of
https://github.com/demostf/demo.js
synced 2026-06-04 00:54:14 +02:00
Fix calculating entity diff from baseline
This commit is contained in:
parent
8fe977ff9f
commit
9eaf826814
3 changed files with 27 additions and 1 deletions
|
|
@ -77,7 +77,7 @@ export class PacketEntity {
|
||||||
public diffFromBaseLine(baselineProps: SendProp[]): SendProp[] {
|
public diffFromBaseLine(baselineProps: SendProp[]): SendProp[] {
|
||||||
return this.props.filter((prop) => {
|
return this.props.filter((prop) => {
|
||||||
const baseProp = PacketEntity.getPropByFullName(baselineProps, prop.definition.fullName);
|
const baseProp = PacketEntity.getPropByFullName(baselineProps, prop.definition.fullName);
|
||||||
return (!baseProp || prop.value !== baseProp.value);
|
return (!baseProp || !SendProp.areEqual(prop, baseProp));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,28 @@ export class SendProp {
|
||||||
prop.value = this.value;
|
prop.value = this.value;
|
||||||
return prop;
|
return prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static areEqual(a: SendProp, b: SendProp) {
|
||||||
|
return a.definition.fullName !== b.definition.fullName ? false : SendProp.valuesAreEqual(a.value, b.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static valuesAreEqual(a: SendPropValue | null, b: SendPropValue | null) {
|
||||||
|
if (Array.isArray(a) && Array.isArray(b)) {
|
||||||
|
if (a.length !== b.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < a.length; i++) {
|
||||||
|
if (!SendProp.valuesAreEqual(a[i], b[i])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else if (a instanceof Vector && b instanceof Vector) {
|
||||||
|
return Vector.areEqual(a, b);
|
||||||
|
} else {
|
||||||
|
return a === b;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SendPropArrayValue = Vector | number | string;
|
export type SendPropArrayValue = Vector | number | string;
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,8 @@ export class Vector {
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static areEqual(a: Vector, b: Vector) {
|
||||||
|
return a.x === b.x && a.y === b.y && a.z === b.z;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue