2020-06-02 10:48:04 +02:00
|
|
|
/**
|
|
|
|
* This class is in charge of computing the position of all players.
|
|
|
|
* Player movement is delayed by 200ms so position depends on ticks.
|
|
|
|
*/
|
2020-06-02 13:44:42 +02:00
|
|
|
import {PlayerMovement} from "./PlayerMovement";
|
|
|
|
import {HasMovedEvent} from "./GameManager";
|
|
|
|
|
2020-06-02 10:48:04 +02:00
|
|
|
export class PlayersPositionInterpolator {
|
2020-06-02 13:44:42 +02:00
|
|
|
playerMovements: Map<string, PlayerMovement> = new Map<string, PlayerMovement>();
|
|
|
|
|
|
|
|
updatePlayerPosition(userId: string, playerMovement: PlayerMovement) : void {
|
|
|
|
this.playerMovements.set(userId, playerMovement);
|
|
|
|
}
|
|
|
|
|
|
|
|
removePlayer(userId: string): void {
|
|
|
|
this.playerMovements.delete(userId);
|
|
|
|
}
|
2020-06-02 10:48:04 +02:00
|
|
|
|
2020-06-02 13:44:42 +02:00
|
|
|
getUpdatedPositions(tick: number) : Map<string, HasMovedEvent> {
|
|
|
|
let positions = new Map<string, HasMovedEvent>();
|
|
|
|
this.playerMovements.forEach((playerMovement: PlayerMovement, userId: string) => {
|
|
|
|
if (playerMovement.isOutdated(tick)) {
|
|
|
|
//console.log("outdated")
|
|
|
|
this.playerMovements.delete(userId);
|
|
|
|
}
|
|
|
|
//console.log("moving")
|
|
|
|
positions.set(userId, playerMovement.getPosition(tick))
|
|
|
|
});
|
|
|
|
return positions;
|
|
|
|
}
|
2020-06-02 10:48:04 +02:00
|
|
|
}
|