From 89a54211e1fa8b6df3bcab6598eff6c428588990 Mon Sep 17 00:00:00 2001 From: genxium Date: Sat, 12 Nov 2022 12:18:00 +0800 Subject: [PATCH] Aligned constants used for backend collision unit-testing. --- battle_srv/models/room.go | 4 ++-- collider_visualizer/worldColliderDisplay.go | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/battle_srv/models/room.go b/battle_srv/models/room.go index 9dc1b36..a947116 100644 --- a/battle_srv/models/room.go +++ b/battle_srv/models/room.go @@ -1261,7 +1261,7 @@ func (pR *Room) applyInputFrameDownsyncDynamicsOnSingleRenderFrame(delayedInputF playerShape := playerCollider.Shape.(*resolv.ConvexPolygon) for _, obj := range collision.Objects { barrierShape := obj.Shape.(*resolv.ConvexPolygon) - if overlapped, pushbackX, pushbackY := CalcPushbacks(oldDx, oldDy, playerShape, barrierShape); overlapped { + if overlapped, pushbackX, pushbackY, _ := CalcPushbacks(oldDx, oldDy, playerShape, barrierShape); overlapped { Logger.Debug(fmt.Sprintf("Collided & overlapped: player.X=%v, player.Y=%v, oldDx=%v, oldDy=%v, playerShape=%v, toCheckBarrier=%v, pushbackX=%v, pushbackY=%v", playerCollider.X, playerCollider.Y, oldDx, oldDy, ConvexPolygonStr(playerShape), ConvexPolygonStr(barrierShape), pushbackX, pushbackY)) effPushbacks[joinIndex-1].X += pushbackX effPushbacks[joinIndex-1].Y += pushbackY @@ -1296,7 +1296,7 @@ func (pR *Room) inputFrameIdDebuggable(inputFrameId int32) bool { func (pR *Room) refreshColliders(spaceW, spaceH int32) { // Kindly note that by now, we've already got all the shapes in the tmx file into "pR.(Players | Barriers)" from "ParseTmxLayersAndGroups" - minStep := int(3) // the approx minimum distance a player can move per frame in world coordinate + minStep := int(pR.PlayerDefaultSpeed) // the approx minimum distance a player can move per frame in world coordinate space := resolv.NewSpace(int(spaceW), int(spaceH), minStep, minStep) // allocate a new collision space everytime after a battle is settled for _, player := range pR.Players { wx, wy := pR.virtualGridToWorldPos(player.VirtualGridX, player.VirtualGridY) diff --git a/collider_visualizer/worldColliderDisplay.go b/collider_visualizer/worldColliderDisplay.go index 5f1a2c5..9064e91 100644 --- a/collider_visualizer/worldColliderDisplay.go +++ b/collider_visualizer/worldColliderDisplay.go @@ -33,9 +33,11 @@ func NewWorldColliderDisplay(game *Game, stageDiscreteW, stageDiscreteH, stageTi spaceOffsetX := float64(spaceW) * 0.5 spaceOffsetY := float64(spaceH) * 0.5 - playerColliderRadius := float64(32) + playerDefaultSpeed := int32(10) + minStep := int(playerDefaultSpeed) + playerColliderRadius := float64(12) playerColliders := make([]*resolv.Object, len(playerPosList.Eles)) - space := resolv.NewSpace(int(spaceW), int(spaceH), 16, 16) + space := resolv.NewSpace(int(spaceW), int(spaceH), minStep, minStep) for i, playerPos := range playerPosList.Eles { playerCollider := GenerateRectCollider(playerPos.X, playerPos.Y, playerColliderRadius*2, playerColliderRadius*2, spaceOffsetX, spaceOffsetY, "Player") // [WARNING] Deliberately not using a circle because "resolv v0.5.1" doesn't yet align circle center with space cell center, regardless of the "specified within-object offset" Logger.Info(fmt.Sprintf("Player Collider#%d: playerPos.X=%v, playerPos.Y=%v, radius=%v, spaceOffsetX=%v, spaceOffsetY=%v, shape=%v", i, playerPos.X, playerPos.Y, playerColliderRadius, spaceOffsetX, spaceOffsetY, playerCollider.Shape))