Enhanced frontend logging.

This commit is contained in:
genxium 2022-12-22 21:27:14 +08:00
parent 14bb6fa1ea
commit faee73ae50
5 changed files with 34 additions and 26 deletions

View File

@ -878,7 +878,7 @@ func (pR *Room) OnPlayerDisconnected(playerId int32) {
default: default:
atomic.StoreInt32(&(pR.Players[playerId].BattleState), PlayerBattleStateIns.DISCONNECTED) atomic.StoreInt32(&(pR.Players[playerId].BattleState), PlayerBattleStateIns.DISCONNECTED)
pR.clearPlayerNetworkSession(playerId) // Still need clear the network session pointers, because "OnPlayerDisconnected" is only triggered from "signalToCloseConnOfThisPlayer" in "ws/serve.go", when the same player reconnects the network session pointers will be re-assigned pR.clearPlayerNetworkSession(playerId) // Still need clear the network session pointers, because "OnPlayerDisconnected" is only triggered from "signalToCloseConnOfThisPlayer" in "ws/serve.go", when the same player reconnects the network session pointers will be re-assigned
Logger.Warn("OnPlayerDisconnected finished:", zap.Any("roomId", pR.Id), zap.Any("playerId", playerId), zap.Any("playerBattleState", pR.Players[playerId].BattleState), zap.Any("nowRoomBattleState", pR.State), zap.Any("nowRoomEffectivePlayerCount", pR.EffectivePlayerCount), zap.Any("now InputsBuffer", pR.InputsBufferString(true))) Logger.Warn("OnPlayerDisconnected finished:", zap.Any("roomId", pR.Id), zap.Any("playerId", playerId), zap.Any("playerBattleState", pR.Players[playerId].BattleState), zap.Any("nowRoomBattleState", pR.State), zap.Any("nowRoomEffectivePlayerCount", pR.EffectivePlayerCount))
} }
} }

View File

@ -65,9 +65,11 @@ func NewWorldColliderDisplay(game *Game, stageDiscreteW, stageDiscreteH, stageTi
if moveToCollide { if moveToCollide {
effPushback := Vec2D{X: float64(0), Y: float64(0)} effPushback := Vec2D{X: float64(0), Y: float64(0)}
toTestPlayerCollider := playerColliders[0] toTestPlayerCollider := playerColliders[0]
//colliderWidth, colliderHeight := playerColliderRadius*2, playerColliderRadius*4 colliderWidth, colliderHeight := playerColliderRadius*2, playerColliderRadius*4
//newVx, newVy := int32(27999), int32(-420270) newVx, newVy := int32(-189000), int32(-497000)
//toTestPlayerCollider.X, toTestPlayerCollider.Y = VirtualGridToPolygonColliderBLPos(newVx, newVy, colliderWidth, colliderHeight, topPadding, bottomPadding, leftPadding, rightPadding, spaceOffsetX, spaceOffsetY, virtualGridToWorldRatio) toTestPlayerCollider.X, toTestPlayerCollider.Y = VirtualGridToPolygonColliderBLPos(newVx, newVy, colliderWidth, colliderHeight, topPadding, bottomPadding, leftPadding, rightPadding, spaceOffsetX, spaceOffsetY, virtualGridToWorldRatio)
playerColliders[1].X, playerColliders[1].Y = VirtualGridToPolygonColliderBLPos(int32(-165000), int32(-504000), colliderWidth, colliderHeight, topPadding, bottomPadding, leftPadding, rightPadding, spaceOffsetX, spaceOffsetY, virtualGridToWorldRatio)
playerColliders[1].Update()
Logger.Info(fmt.Sprintf("Checking collision for playerShape=%v", ConvexPolygonStr(toTestPlayerCollider.Shape.(*resolv.ConvexPolygon)))) Logger.Info(fmt.Sprintf("Checking collision for playerShape=%v", ConvexPolygonStr(toTestPlayerCollider.Shape.(*resolv.ConvexPolygon))))

View File

@ -440,7 +440,7 @@
"array": [ "array": [
0, 0,
0, 0,
210.4441731196186, 209.73151519075364,
0, 0,
0, 0,
0, 0,

View File

@ -117,6 +117,10 @@ cc.Class({
return ((inputFrameId << this.inputScaleFrames) + inputDelayFrames); return ((inputFrameId << this.inputScaleFrames) + inputDelayFrames);
}, },
_convertToLastUsedRenderFrameId(inputFrameId, inputDelayFrames) {
return ((inputFrameId << this.inputScaleFrames) + inputDelayFrames + (1 << this.inputScaleFrames) - 1);
},
shouldGenerateInputFrameUpsync(renderFrameId) { shouldGenerateInputFrameUpsync(renderFrameId) {
return ((renderFrameId & ((1 << this.inputScaleFrames) - 1)) == 0); return ((renderFrameId & ((1 << this.inputScaleFrames) - 1)) == 0);
}, },
@ -779,28 +783,15 @@ lastAllConfirmedInputFrameId=${self.lastAllConfirmedInputFrameId}`);
findingPlayerScriptIns.updatePlayersInfo(rdf.players); findingPlayerScriptIns.updatePlayersInfo(rdf.players);
}, },
logBattleStats() {
const self = this;
let s = [];
s.push(`Battle stats: renderFrameId=${self.renderFrameId}, lastUpsyncInputFrameId=${self.lastUpsyncInputFrameId}, lastAllConfirmedInputFrameId=${self.lastAllConfirmedInputFrameId}, chaserRenderFrameId=${self.chaserRenderFrameId}; recentRenderCache=${self._stringifyRecentRenderCache(false)}, recentInputCache=${self._stringifyRecentInputCache(false)}`);
for (let i = self.recentInputCache.stFrameId; i < self.recentInputCache.edFrameId; ++i) {
const inputFrameDownsync = self.recentInputCache.getByFrameId(i);
s.push(JSON.stringify(inputFrameDownsync));
}
console.log(s.join('\n'));
},
onBattleStopped() { onBattleStopped() {
const self = this; const self = this;
if (ALL_BATTLE_STATES.IN_BATTLE != self.battleState) { if (ALL_BATTLE_STATES.IN_BATTLE != self.battleState) {
return; return;
} }
self._stringifyRecentInputAndRenderCacheCorrespondingly();
window.closeWSConnection(constants.RET_CODE.BATTLE_STOPPED); window.closeWSConnection(constants.RET_CODE.BATTLE_STOPPED);
self.battleState = ALL_BATTLE_STATES.IN_SETTLEMENT; self.battleState = ALL_BATTLE_STATES.IN_SETTLEMENT;
self.countdownNanos = null; self.countdownNanos = null;
self.logBattleStats();
if (self.musicEffectManagerScriptIns) { if (self.musicEffectManagerScriptIns) {
self.musicEffectManagerScriptIns.stopAllMusic(); self.musicEffectManagerScriptIns.stopAllMusic();
} }
@ -908,14 +899,14 @@ lastAllConfirmedInputFrameId=${self.lastAllConfirmedInputFrameId}`);
const delayedInputFrameId = self._convertToInputFrameId(rdf.id, 0); const delayedInputFrameId = self._convertToInputFrameId(rdf.id, 0);
const othersForcedDownsyncRenderFrame = self.othersForcedDownsyncRenderFrameDict.get(rdf.id); const othersForcedDownsyncRenderFrame = self.othersForcedDownsyncRenderFrameDict.get(rdf.id);
if (self.lastAllConfirmedInputFrameId >= delayedInputFrameId && !self.equalRoomDownsyncFrames(othersForcedDownsyncRenderFrame, rdf)) { if (self.lastAllConfirmedInputFrameId >= delayedInputFrameId && !self.equalRoomDownsyncFrames(othersForcedDownsyncRenderFrame, rdf)) {
console.warn(`Mismatched render frame@rdf.id=${rdf.id} w/ inputFrameId=${delayedInputFrameId}, @lastAllConfirmedInputFrameId=${self.lastAllConfirmedInputFrameId}, @chaserRenderFrameId=${self.chaserRenderFrameId}: console.warn(`Mismatched render frame@rdf.id=${rdf.id} w/ inputFrameId=${delayedInputFrameId}:
rdf=${JSON.stringify(rdf)} rdf=${JSON.stringify(rdf)}
othersForcedDownsyncRenderFrame=${JSON.stringify(othersForcedDownsyncRenderFrame)} othersForcedDownsyncRenderFrame=${JSON.stringify(othersForcedDownsyncRenderFrame)}
recentRenderCache=${self._stringifyRecentRenderCache(true)} ${self._stringifyRecentInputAndRenderCacheCorrespondingly()}`);
recentInputCache=${self._stringifyRecentInputCache(true)}`); // closeWSConnection(constants.RET_CODE.CLIENT_MISMATCHED_RENDER_FRAME, "");
closeWSConnection(constants.RET_CODE.CLIENT_MISMATCHED_RENDER_FRAME, ""); // self.onManualRejoinRequired("[DEBUG] CLIENT_MISMATCHED_RENDER_FRAME");
self.onManualRejoinRequired("[DEBUG] CLIENT_MISMATCHED_RENDER_FRAME");
rdf = othersForcedDownsyncRenderFrame; rdf = othersForcedDownsyncRenderFrame;
self.othersForcedDownsyncRenderFrameDict.delete(rdf.id);
} }
} }
self.applyRoomDownsyncFrameDynamics(rdf, prevRdf); self.applyRoomDownsyncFrameDynamics(rdf, prevRdf);
@ -1603,6 +1594,22 @@ playerColliderPos=${self.stringifyColliderCenterInWorld(playerCollider, halfColl
return `[stRenderFrameId=${self.recentRenderCache.stFrameId}, edRenderFrameId=${self.recentRenderCache.edFrameId})`; return `[stRenderFrameId=${self.recentRenderCache.stFrameId}, edRenderFrameId=${self.recentRenderCache.edFrameId})`;
}, },
_stringifyRecentInputAndRenderCacheCorrespondingly() {
const self = this;
let s = [];
s.push(`@lastAllConfirmedInputFrameId=${self.lastAllConfirmedInputFrameId}, @renderFrameId=${self.renderFrameId}, @chaserRenderFrameId=${self.chaserRenderFrameId}`);
for (let i = self.recentRenderCache.stFrameId; i < self.recentRenderCache.edFrameId; ++i) {
let jPrev = self._convertToInputFrameId(i - 1, self.inputDelayFrames);
let j = self._convertToInputFrameId(i, self.inputDelayFrames);
if (i == self.recentRenderCache.stFrameId || j > jPrev) {
s.push(JSON.stringify(self.recentInputCache.getByFrameId(j)));
}
s.push(JSON.stringify(self.recentRenderCache.getByFrameId(i)));
}
return s.join('\n');
},
worldToVirtualGridPos(x, y) { worldToVirtualGridPos(x, y) {
// [WARNING] Introduces loss of precision! // [WARNING] Introduces loss of precision!
const self = this; const self = this;

View File

@ -211,8 +211,7 @@ window.initPersistentSessionClient = function(onopenCb, expectedRoomId) {
case constants.RET_CODE.PLAYER_NOT_FOUND: case constants.RET_CODE.PLAYER_NOT_FOUND:
case constants.RET_CODE.PLAYER_CHEATING: case constants.RET_CODE.PLAYER_CHEATING:
case 1006: // Peer(i.e. the backend) gone unexpectedly case 1006: // Peer(i.e. the backend) gone unexpectedly
console.warn(`recentRenderCache=${mapIns._stringifyRecentRenderCache(true)} console.warn(`${mapIns._stringifyRecentInputAndRenderCacheCorrespondingly()}`);
recentInputCache=${mapIns._stringifyRecentInputCache(true)}`);
window.clearLocalStorageAndBackToLoginScene(true); window.clearLocalStorageAndBackToLoginScene(true);
break; break;
default: default: