Minor fixes for rejoining signals.

This commit is contained in:
genxium
2022-10-04 11:24:47 +08:00
parent 1004fd45db
commit a6731dc7d6
8 changed files with 269 additions and 191 deletions

View File

@@ -45,6 +45,7 @@ message BattleColliderInfo {
int32 nstDelayFrames = 15;
int32 inputFrameUpsyncDelayTolerance = 16;
int32 maxChasingRenderFramesPerUpdate = 17;
int32 playerBattleState = 18;
}
message Player {

View File

@@ -440,7 +440,7 @@
"array": [
0,
0,
209.57814771583418,
216.50635094610968,
0,
0,
0,

View File

@@ -22,6 +22,16 @@ window.MAGIC_ROOM_DOWNSYNC_FRAME_ID = {
BATTLE_START: 0
};
window.PlayerBattleState = {
ADDED_PENDING_BATTLE_COLLIDER_ACK: 0,
READDED_PENDING_BATTLE_COLLIDER_ACK: 1,
ACTIVE: 2,
DISCONNECTED: 3,
LOST: 4,
EXPELLED_DURING_GAME: 5,
EXPELLED_IN_DISMISSAL: 6
};
cc.Class({
extends: cc.Component,
@@ -97,6 +107,10 @@ cc.Class({
type: cc.TiledMap,
default: null
},
renderFrameIdLagTolerance: {
type: cc.Integer,
default: 4 // implies (renderFrameIdLagTolerance >> inputScaleFrames) count of inputFrameIds
},
},
_inputFrameIdDebuggable(inputFrameId) {
@@ -334,10 +348,10 @@ cc.Class({
window.handleClientSessionCloseOrError = function() {
console.warn('+++++++ Common handleClientSessionCloseOrError()');
if (ALL_BATTLE_STATES.IN_SETTLEMENT == self.battleState) { //如果是游戏时间结束引起的断连
console.log("游戏结束引起的断连, 不需要回到登录页面");
if (ALL_BATTLE_STATES.IN_SETTLEMENT == self.battleState) {
console.log("Battled ended by settlement");
} else {
console.warn("意外断连,即将回到登录页面");
console.warn("Connection lost, going back to login page");
window.clearLocalStorageAndBackToLoginScene(true);
}
};
@@ -510,7 +524,7 @@ cc.Class({
} else if (null != boundRoomId) {
self.disableGameRuleNode();
self.battleState = ALL_BATTLE_STATES.WAITING;
window.initPersistentSessionClient(self.initAfterWSConnected, expectedRoomId);
window.initPersistentSessionClient(self.initAfterWSConnected, boundRoomId);
} else {
self.showPopupInCanvas(self.gameRuleNode);
// Deliberately left blank. -- YFLu
@@ -633,10 +647,11 @@ cc.Class({
if (window.RING_BUFF_NON_CONSECUTIVE_SET == dumpRenderCacheRet) {
// Deliberately left blank, in this case "chaserRenderFrameId" is already reset to proper value.
} else {
const inputFrameIdConsecutive = (inputFrameDownsyncId == self.lastAllConfirmedInputFrameId + 1);
const localInputFrame = self.recentInputCache.getByFrameId(inputFrameDownsyncId);
if (null == localInputFrame) {
console.warn("localInputFrame not existing: recentInputCache is NOT having inputFrameDownsyncId=", inputFrameDownsyncId, "; now recentInputCache=", self._stringifyRecentInputCache(false));
} else if (null == firstPredictedYetIncorrectInputFrameId && !self.equalInputLists(localInputFrame.inputList, inputFrameDownsync.inputList)) {
if (null == localInputFrame && false == inputFrameIdConsecutive) {
throw "localInputFrame not existing and is NOT CONSECUTIVELY EXTENDING recentInputCache: inputFrameDownsyncId=" + inputFrameDownsyncId + ", lastAllConfirmedInputFrameId=" + self.lastAllConfirmedInputFrameId + ", recentInputCache=" + self._stringifyRecentInputCache(false);
} else if (null == firstPredictedYetIncorrectInputFrameId && null != localInputFrame && !self.equalInputLists(localInputFrame.inputList, inputFrameDownsync.inputList)) {
firstPredictedYetIncorrectInputFrameId = inputFrameDownsyncId;
}
}
@@ -687,7 +702,7 @@ cc.Class({
logBattleStats() {
const self = this;
let s = [];
s.push("Battle stats: lastUpsyncInputFrameId=" + self.lastUpsyncInputFrameId + ", lastAllConfirmedInputFrameId=" + self.lastAllConfirmedInputFrameId);
s.push("Battle stats: renderFrameId=" + self.renderFrameId + ", lastAllConfirmedRenderFrameId=" + self.lastAllConfirmedRenderFrameId + ", lastUpsyncInputFrameId=" + self.lastUpsyncInputFrameId + ", lastAllConfirmedInputFrameId=" + self.lastAllConfirmedInputFrameId);
for (let i = self.recentInputCache.stFrameId; i < self.recentInputCache.edFrameId; ++i) {
const inputFrameDownsync = self.recentInputCache.getByFrameId(i);
@@ -790,7 +805,7 @@ cc.Class({
} finally {
// Update countdown
if (null != self.countdownNanos) {
self.countdownNanos -= self.rollbackEstimatedDt * 1000000000;
self.countdownNanos -= (performance.now() - self.lastRenderFrameIdTriggeredAt) * 1000000;
if (self.countdownNanos <= 0) {
self.onBattleStopped(self.playerRichInfoDict);
return;
@@ -879,29 +894,26 @@ cc.Class({
setLocalZOrder(toShowNode, 10);
},
onBattleReadyToStart(playerMetas, isSelfRejoining) {
hideFindingPlayersGUI() {
const self = this;
if (null == self.findingPlayerNode.parent) return;
self.findingPlayerNode.parent.removeChild(self.findingPlayerNode);
},
onBattleReadyToStart(playerMetas) {
console.log("Calling `onBattleReadyToStart` with:", playerMetas);
const self = this;
const findingPlayerScriptIns = self.findingPlayerNode.getComponent("FindingPlayer");
findingPlayerScriptIns.hideExitButton();
findingPlayerScriptIns.updatePlayersInfo(playerMetas);
const hideFindingPlayersGUI = function() {
if (null == self.findingPlayerNode.parent) return;
self.findingPlayerNode.parent.removeChild(self.findingPlayerNode);
};
if (true == isSelfRejoining) {
hideFindingPlayersGUI();
} else {
// Delay to hide the "finding player" GUI, then show a countdown clock
window.setTimeout(() => {
hideFindingPlayersGUI();
const countDownScriptIns = self.countdownToBeginGameNode.getComponent("CountdownToBeginGame");
countDownScriptIns.setData();
self.showPopupInCanvas(self.countdownToBeginGameNode);
}, 1500);
}
// Delay to hide the "finding player" GUI, then show a countdown clock
window.setTimeout(() => {
self.hideFindingPlayersGUI();
const countDownScriptIns = self.countdownToBeginGameNode.getComponent("CountdownToBeginGame");
countDownScriptIns.setData();
self.showPopupInCanvas(self.countdownToBeginGameNode);
}, 1500);
},
_createRoomDownsyncFrameLocally(renderFrameId, collisionSys, collisionSysMap) {
@@ -1046,7 +1058,7 @@ cc.Class({
}
}
latestRdf = self._createRoomDownsyncFrameLocally(i+1, collisionSys, collisionSysMap);
latestRdf = self._createRoomDownsyncFrameLocally(i + 1, collisionSys, collisionSysMap);
}
return latestRdf;

View File

@@ -166,9 +166,10 @@ window.initPersistentSessionClient = function(onopenCb, expectedRoomId) {
break;
case window.DOWNSYNC_MSG_ACT_PLAYER_READDED_AND_ACKED:
// Deliberately left blank for now
mapIns.hideFindingPlayersGUI();
break;
case window.DOWNSYNC_MSG_ACT_BATTLE_READY_TO_START:
mapIns.onBattleReadyToStart(resp.rdf.playerMetas, false);
mapIns.onBattleReadyToStart(resp.rdf.playerMetas);
break;
case window.DOWNSYNC_MSG_ACT_BATTLE_START:
mapIns.onRoomDownsyncFrame(resp.rdf);
@@ -180,10 +181,22 @@ window.initPersistentSessionClient = function(onopenCb, expectedRoomId) {
mapIns.onInputFrameDownsyncBatch(resp.inputFrameDownsyncBatch);
break;
case window.DOWNSYNC_MSG_ACT_FORCED_RESYNC:
console.warn("Got forced resync@localRenderFrameId=", mapIns.renderFrameId, ", @lastAllConfirmedRenderFrameId=", mapIns.lastAllConfirmedRenderFrameId, "@lastAllConfirmedInputFrameId=", mapIns.lastAllConfirmedInputFrameId, ", @localRecentInputCache=", mapIns._stringifyRecentInputCache(false), ", the incoming resp=\n", JSON.stringify(resp));
// The following order of execution is important, because "onInputFrameDownsyncBatch" is only available when state is IN_BATTLE
const dumpRenderCacheRet = mapIns.onRoomDownsyncFrame(resp.rdf);
mapIns.onInputFrameDownsyncBatch(resp.inputFrameDownsyncBatch, dumpRenderCacheRet);
if (null == resp.inputFrameDownsyncBatch || 0 >= resp.inputFrameDownsyncBatch.length) {
console.error("Got empty inputFrameDownsyncBatch upon resync@localRenderFrameId=", mapIns.renderFrameId, ", @lastAllConfirmedRenderFrameId=", mapIns.lastAllConfirmedRenderFrameId, "@lastAllConfirmedInputFrameId=", mapIns.lastAllConfirmedInputFrameId, ", @localRecentInputCache=", mapIns._stringifyRecentInputCache(false), ", the incoming resp=\n", JSON.stringify(resp, null, 2));
return;
}
// Unless upon ws session lost and reconnected, it's maintained true that "inputFrameDownsyncBatch[0].inputFrameId == frontend.lastAllConfirmedInputFrameId+1", and in this case we should try to keep frontend moving only by "frontend.recentInputCache" to avoid jiggling of synced positions
const inputFrameIdConsecutive = (resp.inputFrameDownsyncBatch[0].inputFrameId == mapIns.lastAllConfirmedInputFrameId + 1);
const renderFrameIdConsecutive = (resp.rdf.id <= mapIns.renderFrameId + mapIns.renderFrameIdLagTolerance);
if (inputFrameIdConsecutive && renderFrameIdConsecutive) {
console.log("Got consecutive resync@localRenderFrameId=", mapIns.renderFrameId, ", @lastAllConfirmedRenderFrameId=", mapIns.lastAllConfirmedRenderFrameId, "@lastAllConfirmedInputFrameId=", mapIns.lastAllConfirmedInputFrameId, ", @localRecentInputCache=", mapIns._stringifyRecentInputCache(false), ", the incoming resp=\n", JSON.stringify(resp));
mapIns.onInputFrameDownsyncBatch(resp.inputFrameDownsyncBatch);
} else {
console.warn("Got forced resync@localRenderFrameId=", mapIns.renderFrameId, ", @lastAllConfirmedRenderFrameId=", mapIns.lastAllConfirmedRenderFrameId, "@lastAllConfirmedInputFrameId=", mapIns.lastAllConfirmedInputFrameId, ", @localRecentInputCache=", mapIns._stringifyRecentInputCache(false), ", the incoming resp=\n", JSON.stringify(resp, null, 2));
// The following order of execution is important
const dumpRenderCacheRet = mapIns.onRoomDownsyncFrame(resp.rdf);
mapIns.onInputFrameDownsyncBatch(resp.inputFrameDownsyncBatch, dumpRenderCacheRet);
}
break;
default:
break;

View File

@@ -1196,6 +1196,7 @@ $root.treasurehunterx = (function() {
* @property {number|null} [nstDelayFrames] BattleColliderInfo nstDelayFrames
* @property {number|null} [inputFrameUpsyncDelayTolerance] BattleColliderInfo inputFrameUpsyncDelayTolerance
* @property {number|null} [maxChasingRenderFramesPerUpdate] BattleColliderInfo maxChasingRenderFramesPerUpdate
* @property {number|null} [playerBattleState] BattleColliderInfo playerBattleState
*/
/**
@@ -1351,6 +1352,14 @@ $root.treasurehunterx = (function() {
*/
BattleColliderInfo.prototype.maxChasingRenderFramesPerUpdate = 0;
/**
* BattleColliderInfo playerBattleState.
* @member {number} playerBattleState
* @memberof treasurehunterx.BattleColliderInfo
* @instance
*/
BattleColliderInfo.prototype.playerBattleState = 0;
/**
* Creates a new BattleColliderInfo instance using the specified properties.
* @function create
@@ -1415,6 +1424,8 @@ $root.treasurehunterx = (function() {
writer.uint32(/* id 16, wireType 0 =*/128).int32(message.inputFrameUpsyncDelayTolerance);
if (message.maxChasingRenderFramesPerUpdate != null && Object.hasOwnProperty.call(message, "maxChasingRenderFramesPerUpdate"))
writer.uint32(/* id 17, wireType 0 =*/136).int32(message.maxChasingRenderFramesPerUpdate);
if (message.playerBattleState != null && Object.hasOwnProperty.call(message, "playerBattleState"))
writer.uint32(/* id 18, wireType 0 =*/144).int32(message.playerBattleState);
return writer;
};
@@ -1555,6 +1566,10 @@ $root.treasurehunterx = (function() {
message.maxChasingRenderFramesPerUpdate = reader.int32();
break;
}
case 18: {
message.playerBattleState = reader.int32();
break;
}
default:
reader.skipType(tag & 7);
break;
@@ -1655,6 +1670,9 @@ $root.treasurehunterx = (function() {
if (message.maxChasingRenderFramesPerUpdate != null && message.hasOwnProperty("maxChasingRenderFramesPerUpdate"))
if (!$util.isInteger(message.maxChasingRenderFramesPerUpdate))
return "maxChasingRenderFramesPerUpdate: integer expected";
if (message.playerBattleState != null && message.hasOwnProperty("playerBattleState"))
if (!$util.isInteger(message.playerBattleState))
return "playerBattleState: integer expected";
return null;
};
@@ -1727,6 +1745,8 @@ $root.treasurehunterx = (function() {
message.inputFrameUpsyncDelayTolerance = object.inputFrameUpsyncDelayTolerance | 0;
if (object.maxChasingRenderFramesPerUpdate != null)
message.maxChasingRenderFramesPerUpdate = object.maxChasingRenderFramesPerUpdate | 0;
if (object.playerBattleState != null)
message.playerBattleState = object.playerBattleState | 0;
return message;
};
@@ -1767,6 +1787,7 @@ $root.treasurehunterx = (function() {
object.nstDelayFrames = 0;
object.inputFrameUpsyncDelayTolerance = 0;
object.maxChasingRenderFramesPerUpdate = 0;
object.playerBattleState = 0;
}
if (message.stageName != null && message.hasOwnProperty("stageName"))
object.stageName = message.stageName;
@@ -1812,6 +1833,8 @@ $root.treasurehunterx = (function() {
object.inputFrameUpsyncDelayTolerance = message.inputFrameUpsyncDelayTolerance;
if (message.maxChasingRenderFramesPerUpdate != null && message.hasOwnProperty("maxChasingRenderFramesPerUpdate"))
object.maxChasingRenderFramesPerUpdate = message.maxChasingRenderFramesPerUpdate;
if (message.playerBattleState != null && message.hasOwnProperty("playerBattleState"))
object.playerBattleState = message.playerBattleState;
return object;
};