fix: physics slop can yield negative position

This commit is contained in:
cha0s 2019-05-14 05:03:25 -05:00
parent 60df5d61df
commit d0ae543ae4

View File

@ -78,7 +78,12 @@ export class Positioned extends decorate(Trait) {
this.state.x !== this.previousState.x
|| this.state.y !== this.previousState.y
) {
const packed = ((this.state.y) << 16) | (this.state.x << 0);
// 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);
const packed = (y << 16) | (x << 0);
packets.push(new TraitPositionedPacket({
position: packed,
}, this.entity));