From a4ebde3e0739cde95d449d047cb006b8f486ea8e Mon Sep 17 00:00:00 2001 From: genxium Date: Sat, 12 Nov 2022 11:41:18 +0800 Subject: [PATCH] Updated CLI unit tests again. --- collider_visualizer/worldColliderDisplay.go | 10 +++++----- dnmshared/resolv_helper.go | 6 +++--- frontend/assets/resources/map/simple/map.tmx | 2 +- .../assets/scripts/TileCollisionManagerSingleton.js | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/collider_visualizer/worldColliderDisplay.go b/collider_visualizer/worldColliderDisplay.go index 2d32b3a..5f1a2c5 100644 --- a/collider_visualizer/worldColliderDisplay.go +++ b/collider_visualizer/worldColliderDisplay.go @@ -53,24 +53,24 @@ func NewWorldColliderDisplay(game *Game, stageDiscreteW, stageDiscreteH, stageTi world.Space = space - moveToCollide := false + moveToCollide := true if moveToCollide { effPushback := Vec2D{X: float64(0), Y: float64(0)} toTestPlayerCollider := playerColliders[0] - toTestPlayerCollider.X += -2.98 - toTestPlayerCollider.Y += -50.0 + toTestPlayerCollider.X += -50.0 + toTestPlayerCollider.Y += -60.0 toTestPlayerCollider.Update() oldDx, oldDy := float64(0), float64(0) if collision := toTestPlayerCollider.Check(oldDx, oldDy); collision != nil { playerShape := toTestPlayerCollider.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, overlapResult := CalcPushbacks(oldDx, oldDy, playerShape, barrierShape); overlapped { Logger.Info(fmt.Sprintf("Overlapped: a=%v, b=%v, pushbackX=%v, pushbackY=%v", ConvexPolygonStr(playerShape), ConvexPolygonStr(barrierShape), pushbackX, pushbackY)) effPushback.X += pushbackX effPushback.Y += pushbackY } else { - Logger.Info(fmt.Sprintf("Collider BUT not overlapped: a=%v, b=%v", ConvexPolygonStr(playerShape), ConvexPolygonStr(barrierShape))) + Logger.Info(fmt.Sprintf("Collided BUT not overlapped: a=%v, b=%v, overlapResult=%v", ConvexPolygonStr(playerShape), ConvexPolygonStr(barrierShape), overlapResult)) } } toTestPlayerCollider.X -= effPushback.X diff --git a/dnmshared/resolv_helper.go b/dnmshared/resolv_helper.go index 2a7b7fa..afe38c5 100644 --- a/dnmshared/resolv_helper.go +++ b/dnmshared/resolv_helper.go @@ -55,7 +55,7 @@ func GenerateConvexPolygonCollider(unalignedSrc *Polygon2D, spaceOffsetX, spaceO return collider } -func CalcPushbacks(oldDx, oldDy float64, playerShape, barrierShape *resolv.ConvexPolygon) (bool, float64, float64) { +func CalcPushbacks(oldDx, oldDy float64, playerShape, barrierShape *resolv.ConvexPolygon) (bool, float64, float64, *SatResult) { origX, origY := playerShape.Position() defer func() { playerShape.SetPosition(origX, origY) @@ -71,9 +71,9 @@ func CalcPushbacks(oldDx, oldDy float64, playerShape, barrierShape *resolv.Conve } if overlapped := IsPolygonPairOverlapped(playerShape, barrierShape, overlapResult); overlapped { pushbackX, pushbackY := overlapResult.Overlap*overlapResult.OverlapX, overlapResult.Overlap*overlapResult.OverlapY - return true, pushbackX, pushbackY + return true, pushbackX, pushbackY, overlapResult } else { - return false, 0, 0 + return false, 0, 0, overlapResult } } diff --git a/frontend/assets/resources/map/simple/map.tmx b/frontend/assets/resources/map/simple/map.tmx index 5b1df99..16b49c2 100644 --- a/frontend/assets/resources/map/simple/map.tmx +++ b/frontend/assets/resources/map/simple/map.tmx @@ -8,7 +8,7 @@ - + diff --git a/frontend/assets/scripts/TileCollisionManagerSingleton.js b/frontend/assets/scripts/TileCollisionManagerSingleton.js index a37cd25..560f38a 100644 --- a/frontend/assets/scripts/TileCollisionManagerSingleton.js +++ b/frontend/assets/scripts/TileCollisionManagerSingleton.js @@ -371,7 +371,7 @@ TileCollisionManager.prototype.extractBoundaryObjects = function (withTiledMapNo const tilesElListUnderTilesets = {}; for (let tsxFilenameIdx = 0; tsxFilenameIdx < tsxFileNames.length; ++tsxFilenameIdx) { const tsxOrientation = tileSets[tsxFilenameIdx].orientation; - if (cc.TiledMap.Orientation.ORTHO == tsxOrientation) { + if (cc.TiledMap.Orientation.ORTHO != tsxOrientation) { cc.error("Error at tileset %s: We proceed with ONLY tilesets in ORTHO orientation for all map orientations by now.", tsxFileNames[tsxFilenameIdx]); continue; };