refactor: simplify
This commit is contained in:
parent
768102d481
commit
1f642fe8e0
|
@ -37,7 +37,6 @@ export class Positioned extends decorate(Trait) {
|
|||
this.entity.position[0] = x;
|
||||
this.entity.position[1] = y;
|
||||
if (AVOCADO_CLIENT) {
|
||||
this._relaxServerPositionConstraintIfNearerThan = 0;
|
||||
this.serverPosition = this._position;
|
||||
this.serverPositionDirty = false;
|
||||
this.on('serverPositionChanged', this.onServerPositionChanged, this);
|
||||
|
@ -76,21 +75,12 @@ export class Positioned extends decorate(Trait) {
|
|||
packets(informed) {
|
||||
const {x, y} = this.stateDifferences();
|
||||
if (x || y) {
|
||||
// Physics slop can end us up with negatives. Don't allow them in the
|
||||
// packed representation, even though it means a slight loss in accuracy.
|
||||
// The world bounds will (should!) keep things *eventually* correct.
|
||||
const x = Math.max(0, this.state.x);
|
||||
const y = Math.max(0, this.state.y);
|
||||
return new TraitUpdatePositionedPositionPacket({
|
||||
position: [x, y],
|
||||
position: this.entity.position,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
set relaxServerPositionConstraintIfNearerThan(nearerThan) {
|
||||
this._relaxServerPositionConstraintIfNearerThan = nearerThan;
|
||||
}
|
||||
|
||||
listeners() {
|
||||
return {
|
||||
|
||||
|
@ -128,17 +118,7 @@ export class Positioned extends decorate(Trait) {
|
|||
return;
|
||||
}
|
||||
const diff = Vector.sub(this.serverPosition, this._position);
|
||||
const nearerThan = this._relaxServerPositionConstraintIfNearerThan;
|
||||
let lerp;
|
||||
if (
|
||||
nearerThan
|
||||
&& Vector.equalsClose(this._position, this.serverPosition, nearerThan)
|
||||
) {
|
||||
lerp = .01;
|
||||
}
|
||||
else {
|
||||
lerp = .5;
|
||||
}
|
||||
const lerp = .5;
|
||||
this._position = Vector.add(this._position, Vector.scale(diff, lerp));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user