From faee73ae50be53a8f5bac4472be1dce6799f4cf8 Mon Sep 17 00:00:00 2001 From: genxium Date: Thu, 22 Dec 2022 21:27:14 +0800 Subject: [PATCH] Enhanced frontend logging. --- battle_srv/models/room.go | 2 +- collider_visualizer/worldColliderDisplay.go | 8 ++-- frontend/assets/scenes/login.fire | 2 +- frontend/assets/scripts/Map.js | 45 ++++++++++++--------- frontend/assets/scripts/WsSessionMgr.js | 3 +- 5 files changed, 34 insertions(+), 26 deletions(-) diff --git a/battle_srv/models/room.go b/battle_srv/models/room.go index 4a6090c..34b3cfb 100644 --- a/battle_srv/models/room.go +++ b/battle_srv/models/room.go @@ -878,7 +878,7 @@ func (pR *Room) OnPlayerDisconnected(playerId int32) { default: 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 - 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)) } } diff --git a/collider_visualizer/worldColliderDisplay.go b/collider_visualizer/worldColliderDisplay.go index 37c7343..11517c6 100644 --- a/collider_visualizer/worldColliderDisplay.go +++ b/collider_visualizer/worldColliderDisplay.go @@ -65,9 +65,11 @@ func NewWorldColliderDisplay(game *Game, stageDiscreteW, stageDiscreteH, stageTi if moveToCollide { effPushback := Vec2D{X: float64(0), Y: float64(0)} toTestPlayerCollider := playerColliders[0] - //colliderWidth, colliderHeight := playerColliderRadius*2, playerColliderRadius*4 - //newVx, newVy := int32(27999), int32(-420270) - //toTestPlayerCollider.X, toTestPlayerCollider.Y = VirtualGridToPolygonColliderBLPos(newVx, newVy, colliderWidth, colliderHeight, topPadding, bottomPadding, leftPadding, rightPadding, spaceOffsetX, spaceOffsetY, virtualGridToWorldRatio) + colliderWidth, colliderHeight := playerColliderRadius*2, playerColliderRadius*4 + newVx, newVy := int32(-189000), int32(-497000) + 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)))) diff --git a/frontend/assets/scenes/login.fire b/frontend/assets/scenes/login.fire index 5cbb696..31ccba3 100644 --- a/frontend/assets/scenes/login.fire +++ b/frontend/assets/scenes/login.fire @@ -440,7 +440,7 @@ "array": [ 0, 0, - 210.4441731196186, + 209.73151519075364, 0, 0, 0, diff --git a/frontend/assets/scripts/Map.js b/frontend/assets/scripts/Map.js index a102360..814ce52 100644 --- a/frontend/assets/scripts/Map.js +++ b/frontend/assets/scripts/Map.js @@ -117,6 +117,10 @@ cc.Class({ return ((inputFrameId << this.inputScaleFrames) + inputDelayFrames); }, + _convertToLastUsedRenderFrameId(inputFrameId, inputDelayFrames) { + return ((inputFrameId << this.inputScaleFrames) + inputDelayFrames + (1 << this.inputScaleFrames) - 1); + }, + shouldGenerateInputFrameUpsync(renderFrameId) { return ((renderFrameId & ((1 << this.inputScaleFrames) - 1)) == 0); }, @@ -779,28 +783,15 @@ lastAllConfirmedInputFrameId=${self.lastAllConfirmedInputFrameId}`); 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() { const self = this; if (ALL_BATTLE_STATES.IN_BATTLE != self.battleState) { return; } + self._stringifyRecentInputAndRenderCacheCorrespondingly(); window.closeWSConnection(constants.RET_CODE.BATTLE_STOPPED); self.battleState = ALL_BATTLE_STATES.IN_SETTLEMENT; self.countdownNanos = null; - self.logBattleStats(); if (self.musicEffectManagerScriptIns) { self.musicEffectManagerScriptIns.stopAllMusic(); } @@ -908,14 +899,14 @@ lastAllConfirmedInputFrameId=${self.lastAllConfirmedInputFrameId}`); const delayedInputFrameId = self._convertToInputFrameId(rdf.id, 0); const othersForcedDownsyncRenderFrame = self.othersForcedDownsyncRenderFrameDict.get(rdf.id); 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)} othersForcedDownsyncRenderFrame=${JSON.stringify(othersForcedDownsyncRenderFrame)} -recentRenderCache=${self._stringifyRecentRenderCache(true)} -recentInputCache=${self._stringifyRecentInputCache(true)}`); - closeWSConnection(constants.RET_CODE.CLIENT_MISMATCHED_RENDER_FRAME, ""); - self.onManualRejoinRequired("[DEBUG] CLIENT_MISMATCHED_RENDER_FRAME"); +${self._stringifyRecentInputAndRenderCacheCorrespondingly()}`); + // closeWSConnection(constants.RET_CODE.CLIENT_MISMATCHED_RENDER_FRAME, ""); + // self.onManualRejoinRequired("[DEBUG] CLIENT_MISMATCHED_RENDER_FRAME"); rdf = othersForcedDownsyncRenderFrame; + self.othersForcedDownsyncRenderFrameDict.delete(rdf.id); } } self.applyRoomDownsyncFrameDynamics(rdf, prevRdf); @@ -1603,6 +1594,22 @@ playerColliderPos=${self.stringifyColliderCenterInWorld(playerCollider, halfColl 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) { // [WARNING] Introduces loss of precision! const self = this; diff --git a/frontend/assets/scripts/WsSessionMgr.js b/frontend/assets/scripts/WsSessionMgr.js index 2ff3d3c..4174857 100644 --- a/frontend/assets/scripts/WsSessionMgr.js +++ b/frontend/assets/scripts/WsSessionMgr.js @@ -211,8 +211,7 @@ window.initPersistentSessionClient = function(onopenCb, expectedRoomId) { case constants.RET_CODE.PLAYER_NOT_FOUND: case constants.RET_CODE.PLAYER_CHEATING: case 1006: // Peer(i.e. the backend) gone unexpectedly - console.warn(`recentRenderCache=${mapIns._stringifyRecentRenderCache(true)} -recentInputCache=${mapIns._stringifyRecentInputCache(true)}`); + console.warn(`${mapIns._stringifyRecentInputAndRenderCacheCorrespondingly()}`); window.clearLocalStorageAndBackToLoginScene(true); break; default: