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) {
this.gameManager.localTimePast();
// Send Inputs
if (this._selfSpeed && this._selfSpeed.lengthSqr()) {
this._selfSpeed.normalize().multiplyScalar(gameConfig.moveSpeed);

View File

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