timePast auto reconnect

This commit is contained in:
k8w 2021-12-03 01:11:51 +08:00
parent c9ac4a6470
commit 50c8976712
2 changed files with 12 additions and 19 deletions

View File

@ -69,6 +69,8 @@ export class GameScene extends Component {
} }
update(dt: number) { update(dt: number) {
this.gameManager.localTimePast();
// Send Inputs // Send Inputs
if (this._selfSpeed && this._selfSpeed.lengthSqr()) { if (this._selfSpeed && this._selfSpeed.lengthSqr()) {
this._selfSpeed.normalize().multiplyScalar(gameConfig.moveSpeed); this._selfSpeed.normalize().multiplyScalar(gameConfig.moveSpeed);

View File

@ -46,12 +46,8 @@ export class GameManager {
if (!this.client.isConnected) { if (!this.client.isConnected) {
let resConnect = await this.client.connect(); let resConnect = await this.client.connect();
if (!resConnect.isSucc) { if (!resConnect.isSucc) {
if (confirm('连接到服务器失败,是否重试')) { await new Promise(rs => { setTimeout(rs, 2000) })
return this.join(); return this.join();
}
else {
return;
}
} }
} }
@ -92,13 +88,6 @@ export class GameManager {
}); });
}) })
}) })
// 本地时间流逝(会被下一次服务器状态覆盖)
this.gameSystem.applyInput({
type: 'TimePast',
dt: Date.now() - this.lastRecvSetverStateTime
});
this.lastRecvSetverStateTime = Date.now();
} }
pendingInputMsgs: MsgClientInput[] = []; pendingInputMsgs: MsgClientInput[] = [];
@ -119,13 +108,15 @@ export class GameManager {
...input, ...input,
playerId: this.selfPlayerId playerId: this.selfPlayerId
}); });
}
// 本地时间流逝(会被下一次服务器状态覆盖) // 本地时间流逝(会被下一次服务器状态覆盖)
// this.gameSystem.applyInput({ localTimePast() {
// type: 'TimePast', this.gameSystem.applyInput({
// dt: Date.now() - this.lastRecvSetverStateTime type: 'TimePast',
// }); dt: Date.now() - this.lastRecvSetverStateTime
// this.lastRecvSetverStateTime = Date.now(); });
this.lastRecvSetverStateTime = Date.now();
} }
} }