Migrating messages locally into back and front
This commit is contained in:
parent
b4f971c501
commit
d7209d8864
18 changed files with 46 additions and 14 deletions
|
@ -7,7 +7,7 @@ import {
|
|||
SetPlayerDetailsMessage, UserMovedMessage,
|
||||
UserMovesMessage,
|
||||
ViewportMessage
|
||||
} from "../../messages/generated/messages_pb"
|
||||
} from "./Messages/generated/messages_pb"
|
||||
|
||||
const SocketIo = require('socket.io-client');
|
||||
import Socket = SocketIOClient.Socket;
|
||||
|
|
1
front/src/Messages/.gitignore
vendored
Normal file
1
front/src/Messages/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/generated/
|
|
@ -1,4 +1,4 @@
|
|||
import {PositionMessage} from "../../../messages/generated/messages_pb";
|
||||
import {PositionMessage} from "../Messages/generated/messages_pb";
|
||||
import {PointInterface} from "../Connection";
|
||||
import Direction = PositionMessage.Direction;
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ import {FourOFourSceneName} from "../Reconnecting/FourOFourScene";
|
|||
import {ItemFactoryInterface} from "../Items/ItemFactoryInterface";
|
||||
import {ActionableItem} from "../Items/ActionableItem";
|
||||
import {UserInputManager} from "../UserInput/UserInputManager";
|
||||
import {UserMovedMessage} from "../../../../messages/generated/messages_pb";
|
||||
import {UserMovedMessage} from "../../Messages/generated/messages_pb";
|
||||
import {ProtobufClientUtils} from "../../Network/ProtobufClientUtils";
|
||||
|
||||
|
||||
|
@ -220,6 +220,7 @@ export class GameScene extends Phaser.Scene implements CenterListener {
|
|||
if (position === undefined) {
|
||||
throw new Error('Position missing from UserMovedMessage');
|
||||
}
|
||||
//console.log('Received position ', position.getX(), position.getY(), "from user", message.getUserid());
|
||||
|
||||
const messageUserMoved: MessageUserMovedInterface = {
|
||||
userId: message.getUserid(),
|
||||
|
@ -1079,6 +1080,7 @@ export class GameScene extends Phaser.Scene implements CenterListener {
|
|||
// We do not update the player position directly (because it is sent only every 200ms).
|
||||
// Instead we use the PlayersPositionInterpolator that will do a smooth animation over the next 200ms.
|
||||
const playerMovement = new PlayerMovement({ x: player.x, y: player.y }, this.currentTick, message.position, this.currentTick + POSITION_DELAY);
|
||||
//console.log('Target position: ', player.x, player.y);
|
||||
this.playersPositionInterpolator.updatePlayerPosition(player.userId, playerMovement);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,13 @@ export class PlayerMovement {
|
|||
public getPosition(tick: number): HasMovedEvent {
|
||||
// Special case: end position reached and end position is not moving
|
||||
if (tick >= this.endTick && this.endPosition.moving === false) {
|
||||
//console.log('Movement finished ', this.endPosition)
|
||||
return this.endPosition;
|
||||
}
|
||||
|
||||
const x = (this.endPosition.x - this.startPosition.x) * ((tick - this.startTick) / (this.endTick - this.startTick)) + this.startPosition.x;
|
||||
const y = (this.endPosition.y - this.startPosition.y) * ((tick - this.startTick) / (this.endTick - this.startTick)) + this.startPosition.y;
|
||||
|
||||
//console.log('Computed position ', x, y)
|
||||
return {
|
||||
x,
|
||||
y,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue