From 2d080ad13416c2b2a9254f3ab238937a120e311c Mon Sep 17 00:00:00 2001 From: genxium Date: Sat, 12 Nov 2022 22:53:35 +0800 Subject: [PATCH] Fixed backend collision constants. --- battle_srv/models/room.go | 12 +++++------- collider_visualizer/worldColliderDisplay.go | 8 +++++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/battle_srv/models/room.go b/battle_srv/models/room.go index 40a3ed4..b4563ce 100644 --- a/battle_srv/models/room.go +++ b/battle_srv/models/room.go @@ -402,8 +402,7 @@ func (pR *Room) StartBattle() { spaceW := pR.StageDiscreteW * pR.StageTileW spaceH := pR.StageDiscreteH * pR.StageTileH - spaceOffsetX := float64(spaceW) * 0.5 - spaceOffsetY := float64(spaceH) * 0.5 + pR.collisionSpaceOffsetX, pR.collisionSpaceOffsetY = float64(spaceW)*0.5, float64(spaceH)*0.5 pR.refreshColliders(spaceW, spaceH) /** @@ -476,7 +475,7 @@ func (pR *Room) StartBattle() { // Apply "all-confirmed inputFrames" to move forward "pR.CurDynamicsRenderFrameId" nextDynamicsRenderFrameId := pR.ConvertToLastUsedRenderFrameId(pR.LastAllConfirmedInputFrameId, pR.InputDelayFrames) Logger.Debug(fmt.Sprintf("roomId=%v, room.RenderFrameId=%v, LastAllConfirmedInputFrameId=%v, InputDelayFrames=%v, nextDynamicsRenderFrameId=%v", pR.Id, pR.RenderFrameId, pR.LastAllConfirmedInputFrameId, pR.InputDelayFrames, nextDynamicsRenderFrameId)) - pR.applyInputFrameDownsyncDynamics(pR.CurDynamicsRenderFrameId, nextDynamicsRenderFrameId, spaceOffsetX, spaceOffsetY) + pR.applyInputFrameDownsyncDynamics(pR.CurDynamicsRenderFrameId, nextDynamicsRenderFrameId, pR.collisionSpaceOffsetX, pR.collisionSpaceOffsetY) dynamicsDuration = utils.UnixtimeNano() - dynamicsStartedAt } @@ -1251,7 +1250,7 @@ func (pR *Room) applyInputFrameDownsyncDynamicsOnSingleRenderFrame(delayedInputF playerCollider.Update() if 0 < encodedInput { - Logger.Debug(fmt.Sprintf("Moved playerId=%v: virtual (%d, %d) -> (%d, %d), now playerCollider at (%.2f, %.2f)", playerId, currPlayerDownsync.VirtualGridX, currPlayerDownsync.VirtualGridY, newVx, newVy, playerCollider.X, playerCollider.Y)) + Logger.Debug(fmt.Sprintf("Checking collision for playerId=%v: virtual (%d, %d) -> (%d, %d), now playerShape=%v", playerId, currPlayerDownsync.VirtualGridX, currPlayerDownsync.VirtualGridY, newVx, newVy, ConvexPolygonStr(playerCollider.Shape.(*resolv.ConvexPolygon)))) } } @@ -1262,15 +1261,14 @@ func (pR *Room) applyInputFrameDownsyncDynamicsOnSingleRenderFrame(delayedInputF playerCollider := collisionSysMap[collisionPlayerIndex] if collision := playerCollider.Check(0, 0); collision != nil { playerShape := playerCollider.Shape.(*resolv.ConvexPolygon) - Logger.Warn(fmt.Sprintf("Collided: a=%v", ConvexPolygonStr(playerShape))) for _, obj := range collision.Objects { barrierShape := obj.Shape.(*resolv.ConvexPolygon) if overlapped, pushbackX, pushbackY, overlapResult := CalcPushbacks(0, 0, playerShape, barrierShape); overlapped { - Logger.Warn(fmt.Sprintf("Overlapped: a=%v, b=%v, pushbackX=%v, pushbackY=%v", ConvexPolygonStr(playerShape), ConvexPolygonStr(barrierShape), pushbackX, pushbackY)) + Logger.Debug(fmt.Sprintf("Overlapped: a=%v, b=%v, pushbackX=%v, pushbackY=%v", ConvexPolygonStr(playerShape), ConvexPolygonStr(barrierShape), pushbackX, pushbackY)) effPushbacks[joinIndex-1].X += pushbackX effPushbacks[joinIndex-1].Y += pushbackY } else { - Logger.Warn(fmt.Sprintf("Collided BUT not overlapped: a=%v, b=%v, overlapResult=%v", ConvexPolygonStr(playerShape), ConvexPolygonStr(barrierShape), overlapResult)) + Logger.Debug(fmt.Sprintf("Collided BUT not overlapped: a=%v, b=%v, overlapResult=%v", ConvexPolygonStr(playerShape), ConvexPolygonStr(barrierShape), overlapResult)) } } } diff --git a/collider_visualizer/worldColliderDisplay.go b/collider_visualizer/worldColliderDisplay.go index a89a150..1d7a2db 100644 --- a/collider_visualizer/worldColliderDisplay.go +++ b/collider_visualizer/worldColliderDisplay.go @@ -58,11 +58,13 @@ func NewWorldColliderDisplay(game *Game, stageDiscreteW, stageDiscreteH, stageTi moveToCollide := true if moveToCollide { - proposedDx, proposedDy := -50.0, -60.0 + newVx, newVy := int32(-2959), int32(-2261) effPushback := Vec2D{X: float64(0), Y: float64(0)} toTestPlayerCollider := playerColliders[0] - toTestPlayerCollider.X += proposedDx - toTestPlayerCollider.Y += proposedDy + toTestPlayerCollider.X, toTestPlayerCollider.Y = VirtualGridToPolygonColliderAnchorPos(newVx, newVy, playerColliderRadius, playerColliderRadius, spaceOffsetX, spaceOffsetY, virtualGridToWorldRatio) + + Logger.Info(fmt.Sprintf("Checking collision for virtual (%d, %d), now playerShape=%v", newVx, newVy, ConvexPolygonStr(toTestPlayerCollider.Shape.(*resolv.ConvexPolygon)))) + toTestPlayerCollider.Update() if collision := toTestPlayerCollider.Check(0, 0); collision != nil { playerShape := toTestPlayerCollider.Shape.(*resolv.ConvexPolygon)