From f24bff2a160fa3be7eebf0b784cc164c3015b3b2 Mon Sep 17 00:00:00 2001 From: Sezz Date: Fri, 21 Jan 2022 14:39:19 +1100 Subject: [PATCH 1/3] Follow naming conventions --- TR5Main/Game/Lara/lara_test_structs.h | 46 ++++++------- TR5Main/Game/Lara/lara_tests.cpp | 98 +++++++++++++-------------- 2 files changed, 72 insertions(+), 72 deletions(-) diff --git a/TR5Main/Game/Lara/lara_test_structs.h b/TR5Main/Game/Lara/lara_test_structs.h index 1c1c2f26a..684555b3b 100644 --- a/TR5Main/Game/Lara/lara_test_structs.h +++ b/TR5Main/Game/Lara/lara_test_structs.h @@ -2,39 +2,39 @@ struct MoveTestData { - short angle; - int lowerBound; - int upperBound; - bool checkSlopeDown = true; - bool checkSlopeUp = true; - bool checkDeath = true; + short Angle; + int LowerBound; + int UpperBound; + bool CheckSlopeDown = true; + bool CheckSlopeUp = true; + bool CheckDeath = true; }; struct VaultTestData { - int lowerBound; - int upperBound; - int clampMin; - int clampMax; - int gapMin; - bool checkSwampDepth = true; + int LowerBound; + int UpperBound; + int ClampMin; + int ClampMax; + int GapMin; + bool CheckSwampDepth = true; }; struct VaultTestResultData { - bool success; - int height; + bool Success; + int Height; }; struct CrawlVaultTestData { - int lowerBound; - int upperBound; - int clampMin; - int gapMin; - int crossDist; - int destDist; - int probeDeltaMax; - bool checkSlope = true; - bool checkDeath = true; + int LowerBound; + int UpperBound; + int ClampMin; + int GapMin; + int CrossDist; + int DestDist; + int ProbeHeightDifMax; + bool CheckSlope = true; + bool CheckDeath = true; }; diff --git a/TR5Main/Game/Lara/lara_tests.cpp b/TR5Main/Game/Lara/lara_tests.cpp index 8630c773c..76f911bae 100644 --- a/TR5Main/Game/Lara/lara_tests.cpp +++ b/TR5Main/Game/Lara/lara_tests.cpp @@ -123,9 +123,9 @@ bool TestLaraVault(ITEM_INFO* item, COLL_INFO* coll) // Vault to crouch up one step. auto vaultResult = TestLaraVault1StepToCrouch(item, coll); - if (vaultResult.success && !success) + if (vaultResult.Success && !success) { - item->pos.yPos = vaultResult.height + CLICK(1); + item->pos.yPos = vaultResult.Height + CLICK(1); item->animNumber = LA_VAULT_TO_CROUCH_1CLICK; item->currentAnimState = LS_GRABBING; item->frameNumber = GetFrameNumber(item, 0); @@ -136,9 +136,9 @@ bool TestLaraVault(ITEM_INFO* item, COLL_INFO* coll) // Vault to stand up two steps. vaultResult = TestLaraVault2Steps(item, coll); - if (vaultResult.success && !success) + if (vaultResult.Success && !success) { - item->pos.yPos = vaultResult.height + CLICK(2); + item->pos.yPos = vaultResult.Height + CLICK(2); item->animNumber = LA_VAULT_TO_STAND_2CLICK_START; item->currentAnimState = LS_GRABBING; item->frameNumber = GetFrameNumber(item, 0); @@ -148,10 +148,10 @@ bool TestLaraVault(ITEM_INFO* item, COLL_INFO* coll) } // Vault to crouch up two steps. vaultResult = TestLaraVault2StepsToCrouch(item, coll); - if (vaultResult.success && !success && + if (vaultResult.Success && !success && g_GameFlow->Animations.CrawlExtended) { - item->pos.yPos = vaultResult.height + CLICK(2); + item->pos.yPos = vaultResult.Height + CLICK(2); item->animNumber = LA_VAULT_TO_CROUCH_2CLICK; item->frameNumber = GetFrameNumber(item, 0); item->currentAnimState = LS_GRABBING; @@ -162,9 +162,9 @@ bool TestLaraVault(ITEM_INFO* item, COLL_INFO* coll) // Vault to stand up three steps. vaultResult = TestLaraVault3Steps(item, coll); - if (vaultResult.success && !success) + if (vaultResult.Success && !success) { - item->pos.yPos = vaultResult.height + CLICK(3); + item->pos.yPos = vaultResult.Height + CLICK(3); item->animNumber = LA_VAULT_TO_STAND_3CLICK; item->currentAnimState = LS_GRABBING; item->frameNumber = GetFrameNumber(item, 0); @@ -174,10 +174,10 @@ bool TestLaraVault(ITEM_INFO* item, COLL_INFO* coll) } // Vault to crouch up three steps. vaultResult = TestLaraVault3StepsToCrouch(item, coll); - if (vaultResult.success && !success && + if (vaultResult.Success && !success && g_GameFlow->Animations.CrawlExtended) { - item->pos.yPos = vaultResult.height + CLICK(3); + item->pos.yPos = vaultResult.Height + CLICK(3); item->animNumber = LA_VAULT_TO_CROUCH_3CLICK; item->frameNumber = GetFrameNumber(item, 0); item->currentAnimState = LS_GRABBING; @@ -188,9 +188,9 @@ bool TestLaraVault(ITEM_INFO* item, COLL_INFO* coll) // Auto jump to hang. vaultResult = TestLaraVaultAutoJump(item, coll); - if (vaultResult.success && !success) + if (vaultResult.Success && !success) { - info->calcFallSpeed = -3 - sqrt(-9600 - 12 * (vaultResult.height - item->pos.yPos)); + info->calcFallSpeed = -3 - sqrt(-9600 - 12 * (vaultResult.Height - item->pos.yPos)); item->animNumber = LA_STAND_SOLID; item->frameNumber = GetFrameNumber(item, 0); item->goalAnimState = LS_JUMP_UP; @@ -209,9 +209,9 @@ bool TestLaraVault(ITEM_INFO* item, COLL_INFO* coll) // Auto jump to ladder. auto ladderAutoJumpResult = TestLaraLadderAutoJump(item, coll); - if (ladderAutoJumpResult.success) + if (ladderAutoJumpResult.Success) { - info->calcFallSpeed = -3 - sqrt(-9600 - 12 * std::max((ladderAutoJumpResult.height - item->pos.yPos + CLICK(0.2f)), -CLICK(7.1f))); + info->calcFallSpeed = -3 - sqrt(-9600 - 12 * std::max((ladderAutoJumpResult.Height - item->pos.yPos + CLICK(0.2f)), -CLICK(7.1f))); item->animNumber = LA_STAND_SOLID; item->frameNumber = GetFrameNumber(item, 0); item->goalAnimState = LS_JUMP_UP; @@ -1572,13 +1572,13 @@ bool TestLaraStepDown(ITEM_INFO* item, COLL_INFO* coll) bool TestLaraMoveTolerance(ITEM_INFO* item, COLL_INFO* coll, MoveTestData testData) { int y = item->pos.yPos; - auto probe = GetCollisionResult(item, testData.angle, coll->Setup.Radius * sqrt(2) + 4, -coll->Setup.Height); // Offset required to account for gap between Lara and the wall. Results in slight overshoot, but avoids oscillation. - bool isSlopeDown = testData.checkSlopeDown ? (probe.Position.Slope && probe.Position.Floor >= y) : false; - bool isSlopeUp = testData.checkSlopeUp ? (probe.Position.Slope && probe.Position.Floor < y) : false; - bool isDeath = testData.checkDeath ? probe.Block->Flags.Death : false; + auto probe = GetCollisionResult(item, testData.Angle, coll->Setup.Radius * sqrt(2) + 4, -coll->Setup.Height); // Offset required to account for gap between Lara and the wall. Results in slight overshoot, but avoids oscillation. + bool isSlopeDown = testData.CheckSlopeDown ? (probe.Position.Slope && probe.Position.Floor >= y) : false; + bool isSlopeUp = testData.CheckSlopeUp ? (probe.Position.Slope && probe.Position.Floor < y) : false; + bool isDeath = testData.CheckDeath ? probe.Block->Flags.Death : false; - if ((probe.Position.Floor - y) <= testData.lowerBound && // Lower floor bound. - (probe.Position.Floor - y) >= testData.upperBound && // Upper floor bound. + if ((probe.Position.Floor - y) <= testData.LowerBound && // Lower floor bound. + (probe.Position.Floor - y) >= testData.UpperBound && // Upper floor bound. (probe.Position.Ceiling - y) < -coll->Setup.Height && // Lowest ceiling bound. abs(probe.Position.Ceiling - probe.Position.Floor) > coll->Setup.Height && // Space is not a clamp. !isSlopeDown && !isSlopeUp && !isDeath && // No slope or death sector (if applicable). @@ -1598,13 +1598,13 @@ bool TestLaraMoveTolerance(ITEM_INFO* item, COLL_INFO* coll, MoveTestData testDa bool TestLaraCrawlMoveTolerance(ITEM_INFO* item, COLL_INFO* coll, MoveTestData testData) { int y = item->pos.yPos; - auto probe = GetCollisionResult(item, testData.angle, LARA_RAD_CRAWL * sqrt(2) + 4, -LARA_HEIGHT_CRAWL); - bool isSlopeDown = testData.checkSlopeDown ? (probe.Position.Slope && probe.Position.Floor >= y) : false; - bool isSlopeUp = testData.checkSlopeUp ? (probe.Position.Slope && probe.Position.Floor < y) : false; - bool isDeath = testData.checkDeath ? probe.Block->Flags.Death : false; + auto probe = GetCollisionResult(item, testData.Angle, LARA_RAD_CRAWL * sqrt(2) + 4, -LARA_HEIGHT_CRAWL); + bool isSlopeDown = testData.CheckSlopeDown ? (probe.Position.Slope && probe.Position.Floor >= y) : false; + bool isSlopeUp = testData.CheckSlopeUp ? (probe.Position.Slope && probe.Position.Floor < y) : false; + bool isDeath = testData.CheckDeath ? probe.Block->Flags.Death : false; - if ((probe.Position.Floor - y) <= testData.lowerBound && // Lower floor bound. - (probe.Position.Floor - y) >= testData.upperBound && // Upper floor bound. + if ((probe.Position.Floor - y) <= testData.LowerBound && // Lower floor bound. + (probe.Position.Floor - y) >= testData.UpperBound && // Upper floor bound. (probe.Position.Ceiling - y) < -LARA_HEIGHT_CRAWL && // Lowest ceiling bound. abs(probe.Position.Ceiling - probe.Position.Floor) > LARA_HEIGHT_CRAWL && // Space is not a clamp. !isSlopeDown && !isSlopeUp && !isDeath && // No slope or death sector (if applicable). @@ -1831,25 +1831,25 @@ VaultTestResultData TestLaraVaultTolerance(ITEM_INFO* item, COLL_INFO* coll, Vau int y = item->pos.yPos; auto probeFront = GetCollisionResult(item, coll->NearestLedgeAngle, coll->Setup.Radius * sqrt(2) + 4, -coll->Setup.Height); auto probeMiddle = GetCollisionResult(item); - bool swampTooDeep = testData.checkSwampDepth ? (TestLaraSwamp(item) && info->waterSurfaceDist < -CLICK(3)) : TestLaraSwamp(item); + bool swampTooDeep = testData.CheckSwampDepth ? (TestLaraSwamp(item) && info->waterSurfaceDist < -CLICK(3)) : TestLaraSwamp(item); // "Floor" ahead may be formed by ceiling; raise y position of probe point to find potential vault candidate location. - int yOffset = testData.lowerBound; + int yOffset = testData.LowerBound; while (((probeFront.Position.Ceiling - y) > -coll->Setup.Height || // Ceiling is below Lara's height. - abs(probeFront.Position.Ceiling - probeFront.Position.Floor) <= testData.clampMin || // Clamp is too small. - abs(probeFront.Position.Ceiling - probeFront.Position.Floor) > testData.clampMax) && // Clamp is too large. - yOffset > (testData.upperBound - coll->Setup.Height)) // Offset is not too high. + abs(probeFront.Position.Ceiling - probeFront.Position.Floor) <= testData.ClampMin || // Clamp is too small. + abs(probeFront.Position.Ceiling - probeFront.Position.Floor) > testData.ClampMax) && // Clamp is too large. + yOffset > (testData.UpperBound - coll->Setup.Height)) // Offset is not too high. { probeFront = GetCollisionResult(item, coll->NearestLedgeAngle, coll->Setup.Radius * sqrt(2) + 4, yOffset); - yOffset -= std::max((int)CLICK(0.5f), testData.clampMin); + yOffset -= std::max((int)CLICK(0.5f), testData.ClampMin); } // Assess vault candidate location. - if ((probeFront.Position.Floor - y) < testData.lowerBound && // Lower floor bound. - (probeFront.Position.Floor - y) >= testData.upperBound && // Upper floor bound. - abs(probeFront.Position.Ceiling - probeFront.Position.Floor) > testData.clampMin && // Lower clamp limit. - abs(probeFront.Position.Ceiling - probeFront.Position.Floor) <= testData.clampMax && // Upper clamp limit. - abs(probeMiddle.Position.Ceiling - probeFront.Position.Floor) >= testData.gapMin && // Gap is optically permissive. + if ((probeFront.Position.Floor - y) < testData.LowerBound && // Lower floor bound. + (probeFront.Position.Floor - y) >= testData.UpperBound && // Upper floor bound. + abs(probeFront.Position.Ceiling - probeFront.Position.Floor) > testData.ClampMin && // Lower clamp limit. + abs(probeFront.Position.Ceiling - probeFront.Position.Floor) <= testData.ClampMax && // Upper clamp limit. + abs(probeMiddle.Position.Ceiling - probeFront.Position.Floor) >= testData.GapMin && // Gap is optically permissive. !swampTooDeep && // Swamp depth is permissive. probeFront.Position.Floor != NO_HEIGHT) { @@ -2025,20 +2025,20 @@ bool TestLaraMonkeyAutoJump(ITEM_INFO* item, COLL_INFO* coll) bool TestLaraCrawlVaultTolerance(ITEM_INFO* item, COLL_INFO* coll, CrawlVaultTestData testData) { int y = item->pos.yPos; - auto probeA = GetCollisionResult(item, item->pos.yRot, testData.crossDist, -LARA_HEIGHT_CRAWL); // Crossing. - auto probeB = GetCollisionResult(item, item->pos.yRot, testData.destDist, -LARA_HEIGHT_CRAWL); // Approximate destination. + auto probeA = GetCollisionResult(item, item->pos.yRot, testData.CrossDist, -LARA_HEIGHT_CRAWL); // Crossing. + auto probeB = GetCollisionResult(item, item->pos.yRot, testData.DestDist, -LARA_HEIGHT_CRAWL); // Approximate destination. auto probeMiddle = GetCollisionResult(item); - bool isSlope = testData.checkSlope ? probeB.Position.Slope : false; - bool isDeath = testData.checkDeath ? probeB.Block->Flags.Death : false; + bool isSlope = testData.CheckSlope ? probeB.Position.Slope : false; + bool isDeath = testData.CheckDeath ? probeB.Block->Flags.Death : false; - if ((probeA.Position.Floor - y) <= testData.lowerBound && // Lower floor bound. - (probeA.Position.Floor - y) >= testData.upperBound && // Upper floor bound. - abs(probeA.Position.Ceiling - probeA.Position.Floor) > testData.clampMin && // Crossing clamp limit. - abs(probeB.Position.Ceiling - probeB.Position.Floor) > testData.clampMin && // Destination clamp limit. - abs(probeMiddle.Position.Ceiling - probeA.Position.Floor) >= testData.gapMin && // Gap is optically permissive (going up). - abs(probeA.Position.Ceiling - probeMiddle.Position.Floor) >= testData.gapMin && // Gap is optically permissive (going down). - abs(probeA.Position.Floor - probeB.Position.Floor) <= testData.probeDeltaMax && // Crossing and destination floor height difference suggests continuous crawl surface. - (probeA.Position.Ceiling - y) < -testData.gapMin && // Ceiling height is permissive. + if ((probeA.Position.Floor - y) <= testData.LowerBound && // Lower floor bound. + (probeA.Position.Floor - y) >= testData.UpperBound && // Upper floor bound. + abs(probeA.Position.Ceiling - probeA.Position.Floor) > testData.ClampMin && // Crossing clamp limit. + abs(probeB.Position.Ceiling - probeB.Position.Floor) > testData.ClampMin && // Destination clamp limit. + abs(probeMiddle.Position.Ceiling - probeA.Position.Floor) >= testData.GapMin && // Gap is optically permissive (going up). + abs(probeA.Position.Ceiling - probeMiddle.Position.Floor) >= testData.GapMin && // Gap is optically permissive (going down). + abs(probeA.Position.Floor - probeB.Position.Floor) <= testData.ProbeHeightDifMax && // Crossing and destination floor height difference suggests continuous crawl surface. + (probeA.Position.Ceiling - y) < -testData.GapMin && // Ceiling height is permissive. !isSlope && !isDeath && // No slope or death sector. probeA.Position.Floor != NO_HEIGHT && probeB.Position.Floor != NO_HEIGHT) { From afae198a118ac08bf37ae214d141f9e12aa7fd59 Mon Sep 17 00:00:00 2001 From: Sezz Date: Wed, 26 Jan 2022 20:27:52 +1100 Subject: [PATCH 2/3] Move CornerTestResult struct; organise test structs --- TR5Main/Game/Lara/lara_test_structs.h | 15 +- TR5Main/Game/Lara/lara_tests.cpp | 196 ++++++++++++-------------- TR5Main/Game/Lara/lara_tests.h | 22 +-- 3 files changed, 116 insertions(+), 117 deletions(-) diff --git a/TR5Main/Game/Lara/lara_test_structs.h b/TR5Main/Game/Lara/lara_test_structs.h index 684555b3b..d8c7c3e18 100644 --- a/TR5Main/Game/Lara/lara_test_structs.h +++ b/TR5Main/Game/Lara/lara_test_structs.h @@ -1,6 +1,6 @@ #pragma once -struct MoveTestData +struct MoveTestSetup { short Angle; int LowerBound; @@ -10,7 +10,7 @@ struct MoveTestData bool CheckDeath = true; }; -struct VaultTestData +struct VaultTestSetup { int LowerBound; int UpperBound; @@ -20,13 +20,13 @@ struct VaultTestData bool CheckSwampDepth = true; }; -struct VaultTestResultData +struct VaultTestResult { bool Success; int Height; }; -struct CrawlVaultTestData +struct CrawlVaultTestSetup { int LowerBound; int UpperBound; @@ -38,3 +38,10 @@ struct CrawlVaultTestData bool CheckSlope = true; bool CheckDeath = true; }; + +struct CornerTestResult +{ + bool Success; + PHD_3DPOS ProbeResult; + PHD_3DPOS RealPositionResult; +}; diff --git a/TR5Main/Game/Lara/lara_tests.cpp b/TR5Main/Game/Lara/lara_tests.cpp index 76f911bae..3a9aa6ab4 100644 --- a/TR5Main/Game/Lara/lara_tests.cpp +++ b/TR5Main/Game/Lara/lara_tests.cpp @@ -21,14 +21,6 @@ using namespace TEN::Renderer; using namespace TEN::Floordata; -// TODO: Move to lara_test_structs.h after merge of Sezz vaults branch -struct CornerTestResult -{ - bool Success; - PHD_3DPOS ProbeResult; - PHD_3DPOS RealPositionResult; -}; - // ----------------------------- // TEST FUNCTIONS // For State Control & Collision @@ -1569,16 +1561,16 @@ bool TestLaraStepDown(ITEM_INFO* item, COLL_INFO* coll) // TODO: This function and its clone below should become obsolete with more accurate and accessible collision detection in the future. // For now, it supercedes old probes and is used alongside COLL_INFO. @Sezz 2021.10.24 -bool TestLaraMoveTolerance(ITEM_INFO* item, COLL_INFO* coll, MoveTestData testData) +bool TestLaraMoveTolerance(ITEM_INFO* item, COLL_INFO* coll, MoveTestSetup testSetup) { int y = item->pos.yPos; - auto probe = GetCollisionResult(item, testData.Angle, coll->Setup.Radius * sqrt(2) + 4, -coll->Setup.Height); // Offset required to account for gap between Lara and the wall. Results in slight overshoot, but avoids oscillation. - bool isSlopeDown = testData.CheckSlopeDown ? (probe.Position.Slope && probe.Position.Floor >= y) : false; - bool isSlopeUp = testData.CheckSlopeUp ? (probe.Position.Slope && probe.Position.Floor < y) : false; - bool isDeath = testData.CheckDeath ? probe.Block->Flags.Death : false; + auto probe = GetCollisionResult(item, testSetup.Angle, coll->Setup.Radius * sqrt(2) + 4, -coll->Setup.Height); // Offset required to account for gap between Lara and the wall. Results in slight overshoot, but avoids oscillation. + bool isSlopeDown = testSetup.CheckSlopeDown ? (probe.Position.Slope && probe.Position.Floor >= y) : false; + bool isSlopeUp = testSetup.CheckSlopeUp ? (probe.Position.Slope && probe.Position.Floor < y) : false; + bool isDeath = testSetup.CheckDeath ? probe.Block->Flags.Death : false; - if ((probe.Position.Floor - y) <= testData.LowerBound && // Lower floor bound. - (probe.Position.Floor - y) >= testData.UpperBound && // Upper floor bound. + if ((probe.Position.Floor - y) <= testSetup.LowerBound && // Lower floor bound. + (probe.Position.Floor - y) >= testSetup.UpperBound && // Upper floor bound. (probe.Position.Ceiling - y) < -coll->Setup.Height && // Lowest ceiling bound. abs(probe.Position.Ceiling - probe.Position.Floor) > coll->Setup.Height && // Space is not a clamp. !isSlopeDown && !isSlopeUp && !isDeath && // No slope or death sector (if applicable). @@ -1595,16 +1587,16 @@ bool TestLaraMoveTolerance(ITEM_INFO* item, COLL_INFO* coll, MoveTestData testDa // This means they will store the wrong values for tests called in crawl CONTROL functions. // When states become objects, collision setup should occur at the beginning of each state, eliminating the need // for this clone function. @Sezz 2021.12.05 -bool TestLaraCrawlMoveTolerance(ITEM_INFO* item, COLL_INFO* coll, MoveTestData testData) +bool TestLaraCrawlMoveTolerance(ITEM_INFO* item, COLL_INFO* coll, MoveTestSetup testSetup) { int y = item->pos.yPos; - auto probe = GetCollisionResult(item, testData.Angle, LARA_RAD_CRAWL * sqrt(2) + 4, -LARA_HEIGHT_CRAWL); - bool isSlopeDown = testData.CheckSlopeDown ? (probe.Position.Slope && probe.Position.Floor >= y) : false; - bool isSlopeUp = testData.CheckSlopeUp ? (probe.Position.Slope && probe.Position.Floor < y) : false; - bool isDeath = testData.CheckDeath ? probe.Block->Flags.Death : false; + auto probe = GetCollisionResult(item, testSetup.Angle, LARA_RAD_CRAWL * sqrt(2) + 4, -LARA_HEIGHT_CRAWL); + bool isSlopeDown = testSetup.CheckSlopeDown ? (probe.Position.Slope && probe.Position.Floor >= y) : false; + bool isSlopeUp = testSetup.CheckSlopeUp ? (probe.Position.Slope && probe.Position.Floor < y) : false; + bool isDeath = testSetup.CheckDeath ? probe.Block->Flags.Death : false; - if ((probe.Position.Floor - y) <= testData.LowerBound && // Lower floor bound. - (probe.Position.Floor - y) >= testData.UpperBound && // Upper floor bound. + if ((probe.Position.Floor - y) <= testSetup.LowerBound && // Lower floor bound. + (probe.Position.Floor - y) >= testSetup.UpperBound && // Upper floor bound. (probe.Position.Ceiling - y) < -LARA_HEIGHT_CRAWL && // Lowest ceiling bound. abs(probe.Position.Ceiling - probe.Position.Floor) > LARA_HEIGHT_CRAWL && // Space is not a clamp. !isSlopeDown && !isSlopeUp && !isDeath && // No slope or death sector (if applicable). @@ -1620,7 +1612,7 @@ bool TestLaraRunForward(ITEM_INFO* item, COLL_INFO* coll) { // Using BadHeightUp/Down defined in run state collision function. - MoveTestData testData + MoveTestSetup testSetup { item->pos.yRot, NO_BAD_POS, @@ -1628,84 +1620,84 @@ bool TestLaraRunForward(ITEM_INFO* item, COLL_INFO* coll) false, true, false }; - return TestLaraMoveTolerance(item, coll, testData); + return TestLaraMoveTolerance(item, coll, testSetup); } bool TestLaraWalkForward(ITEM_INFO* item, COLL_INFO* coll) { // Using BadHeightUp/Down defined in walk state collision function. - MoveTestData testData + MoveTestSetup testSetup { item->pos.yRot, STEPUP_HEIGHT, -STEPUP_HEIGHT }; - return TestLaraMoveTolerance(item, coll, testData); + return TestLaraMoveTolerance(item, coll, testSetup); } bool TestLaraWalkBack(ITEM_INFO* item, COLL_INFO* coll) { // Using BadHeightUp/Down defined in walk back state collision function. - MoveTestData testData + MoveTestSetup testSetup { item->pos.yRot + ANGLE(180.0f), STEPUP_HEIGHT, -STEPUP_HEIGHT }; - return TestLaraMoveTolerance(item, coll, testData); + return TestLaraMoveTolerance(item, coll, testSetup); } bool TestLaraRunBack(ITEM_INFO* item, COLL_INFO* coll) { // Using BadHeightUp/Down defined in hop back state collision function. - MoveTestData testData + MoveTestSetup testSetup { item->pos.yRot + ANGLE(180.0f), NO_BAD_POS, -STEPUP_HEIGHT, false, false, false }; - return TestLaraMoveTolerance(item, coll, testData); + return TestLaraMoveTolerance(item, coll, testSetup); } bool TestLaraStepLeft(ITEM_INFO* item, COLL_INFO* coll) { // Using BadHeightUp/Down defined in step left state collision function. - MoveTestData testData + MoveTestSetup testSetup { item->pos.yRot - ANGLE(90.0f), CLICK(0.8f), -CLICK(0.8f) }; - return TestLaraMoveTolerance(item, coll, testData); + return TestLaraMoveTolerance(item, coll, testSetup); } bool TestLaraStepRight(ITEM_INFO* item, COLL_INFO* coll) { // Using BadHeightUp/Down defined in step right state collision function. - MoveTestData testData + MoveTestSetup testSetup { item->pos.yRot + ANGLE(90.0f), CLICK(0.8f), -CLICK(0.8f) }; - return TestLaraMoveTolerance(item, coll, testData); + return TestLaraMoveTolerance(item, coll, testSetup); } bool TestLaraWadeForwardSwamp(ITEM_INFO* item, COLL_INFO* coll) { // Using BadHeightUp/Down defined in wade forward state collision function. - MoveTestData testData + MoveTestSetup testSetup { item->pos.yRot, NO_BAD_POS, @@ -1713,14 +1705,14 @@ bool TestLaraWadeForwardSwamp(ITEM_INFO* item, COLL_INFO* coll) false, false, false }; - return TestLaraMoveTolerance(item, coll, testData); + return TestLaraMoveTolerance(item, coll, testSetup); } bool TestLaraWalkBackSwamp(ITEM_INFO* item, COLL_INFO* coll) { // Using BadHeightUp defined in walk back state collision function. - MoveTestData testData + MoveTestSetup testSetup { item->pos.yRot + ANGLE(180.0f), NO_BAD_POS, @@ -1728,14 +1720,14 @@ bool TestLaraWalkBackSwamp(ITEM_INFO* item, COLL_INFO* coll) false, false, false }; - return TestLaraMoveTolerance(item, coll, testData); + return TestLaraMoveTolerance(item, coll, testSetup); } bool TestLaraStepLeftSwamp(ITEM_INFO* item, COLL_INFO* coll) { // Using BadHeightUp defined in step left state collision function. - MoveTestData testData + MoveTestSetup testSetup { item->pos.yRot - ANGLE(90.0f), NO_BAD_POS, @@ -1743,14 +1735,14 @@ bool TestLaraStepLeftSwamp(ITEM_INFO* item, COLL_INFO* coll) false, false, false }; - return TestLaraMoveTolerance(item, coll, testData); + return TestLaraMoveTolerance(item, coll, testSetup); } bool TestLaraStepRightSwamp(ITEM_INFO* item, COLL_INFO* coll) { // Using BadHeightUp defined in step right state collision function. - MoveTestData testData + MoveTestSetup testSetup { item->pos.yRot + ANGLE(90.0f), NO_BAD_POS, @@ -1758,35 +1750,35 @@ bool TestLaraStepRightSwamp(ITEM_INFO* item, COLL_INFO* coll) false, false, false }; - return TestLaraMoveTolerance(item, coll, testData); + return TestLaraMoveTolerance(item, coll, testSetup); } bool TestLaraCrawlForward(ITEM_INFO* item, COLL_INFO* coll) { // Using BadHeightUp/Down defined in crawl state collision functions. - MoveTestData testData + MoveTestSetup testSetup { item->pos.yRot, CLICK(1) - 1, -(CLICK(1) - 1) }; - return TestLaraCrawlMoveTolerance(item, coll, testData); + return TestLaraCrawlMoveTolerance(item, coll, testSetup); } bool TestLaraCrawlBack(ITEM_INFO* item, COLL_INFO* coll) { // Using BadHeightUp/Down defined in crawl state collision functions. - MoveTestData testData + MoveTestSetup testSetup { item->pos.yRot + ANGLE(180.0f), CLICK(1) - 1, -(CLICK(1) - 1) }; - return TestLaraCrawlMoveTolerance(item, coll, testData); + return TestLaraCrawlMoveTolerance(item, coll, testSetup); } bool TestLaraCrouchToCrawl(ITEM_INFO* item) @@ -1824,48 +1816,48 @@ bool TestLaraCrouchRoll(ITEM_INFO* item, COLL_INFO* coll) return false; } -VaultTestResultData TestLaraVaultTolerance(ITEM_INFO* item, COLL_INFO* coll, VaultTestData testData) +VaultTestResult TestLaraVaultTolerance(ITEM_INFO* item, COLL_INFO* coll, VaultTestSetup testSetup) { LaraInfo*& info = item->data; int y = item->pos.yPos; auto probeFront = GetCollisionResult(item, coll->NearestLedgeAngle, coll->Setup.Radius * sqrt(2) + 4, -coll->Setup.Height); auto probeMiddle = GetCollisionResult(item); - bool swampTooDeep = testData.CheckSwampDepth ? (TestLaraSwamp(item) && info->waterSurfaceDist < -CLICK(3)) : TestLaraSwamp(item); + bool swampTooDeep = testSetup.CheckSwampDepth ? (TestLaraSwamp(item) && info->waterSurfaceDist < -CLICK(3)) : TestLaraSwamp(item); // "Floor" ahead may be formed by ceiling; raise y position of probe point to find potential vault candidate location. - int yOffset = testData.LowerBound; + int yOffset = testSetup.LowerBound; while (((probeFront.Position.Ceiling - y) > -coll->Setup.Height || // Ceiling is below Lara's height. - abs(probeFront.Position.Ceiling - probeFront.Position.Floor) <= testData.ClampMin || // Clamp is too small. - abs(probeFront.Position.Ceiling - probeFront.Position.Floor) > testData.ClampMax) && // Clamp is too large. - yOffset > (testData.UpperBound - coll->Setup.Height)) // Offset is not too high. + abs(probeFront.Position.Ceiling - probeFront.Position.Floor) <= testSetup.ClampMin || // Clamp is too small. + abs(probeFront.Position.Ceiling - probeFront.Position.Floor) > testSetup.ClampMax) && // Clamp is too large. + yOffset > (testSetup.UpperBound - coll->Setup.Height)) // Offset is not too high. { probeFront = GetCollisionResult(item, coll->NearestLedgeAngle, coll->Setup.Radius * sqrt(2) + 4, yOffset); - yOffset -= std::max((int)CLICK(0.5f), testData.ClampMin); + yOffset -= std::max((int)CLICK(0.5f), testSetup.ClampMin); } // Assess vault candidate location. - if ((probeFront.Position.Floor - y) < testData.LowerBound && // Lower floor bound. - (probeFront.Position.Floor - y) >= testData.UpperBound && // Upper floor bound. - abs(probeFront.Position.Ceiling - probeFront.Position.Floor) > testData.ClampMin && // Lower clamp limit. - abs(probeFront.Position.Ceiling - probeFront.Position.Floor) <= testData.ClampMax && // Upper clamp limit. - abs(probeMiddle.Position.Ceiling - probeFront.Position.Floor) >= testData.GapMin && // Gap is optically permissive. + if ((probeFront.Position.Floor - y) < testSetup.LowerBound && // Lower floor bound. + (probeFront.Position.Floor - y) >= testSetup.UpperBound && // Upper floor bound. + abs(probeFront.Position.Ceiling - probeFront.Position.Floor) > testSetup.ClampMin && // Lower clamp limit. + abs(probeFront.Position.Ceiling - probeFront.Position.Floor) <= testSetup.ClampMax && // Upper clamp limit. + abs(probeMiddle.Position.Ceiling - probeFront.Position.Floor) >= testSetup.GapMin && // Gap is optically permissive. !swampTooDeep && // Swamp depth is permissive. probeFront.Position.Floor != NO_HEIGHT) { - return VaultTestResultData { true, probeFront.Position.Floor }; + return VaultTestResult { true, probeFront.Position.Floor }; } - return VaultTestResultData { false, NO_HEIGHT }; + return VaultTestResult { false, NO_HEIGHT }; } -VaultTestResultData TestLaraVault2Steps(ITEM_INFO* item, COLL_INFO* coll) +VaultTestResult TestLaraVault2Steps(ITEM_INFO* item, COLL_INFO* coll) { // Floor range: (-STEPUP_HEIGHT, -CLICK(2.5f)] // Clamp range: (-LARA_HEIGHT, MAX_HEIGHT] - VaultTestData testData + VaultTestSetup testSetup { -STEPUP_HEIGHT, -CLICK(2.5f), @@ -1874,15 +1866,15 @@ VaultTestResultData TestLaraVault2Steps(ITEM_INFO* item, COLL_INFO* coll) CLICK(1) }; - return TestLaraVaultTolerance(item, coll, testData); + return TestLaraVaultTolerance(item, coll, testSetup); } -VaultTestResultData TestLaraVault3Steps(ITEM_INFO* item, COLL_INFO* coll) +VaultTestResult TestLaraVault3Steps(ITEM_INFO* item, COLL_INFO* coll) { // Floor range: (-CLICK(2.5f), -CLICK(3.5f)] // Clamp range: (-LARA_HEIGHT, MAX_HEIGHT] - VaultTestData testData + VaultTestSetup testSetup { -CLICK(2.5f), -CLICK(3.5f), @@ -1891,15 +1883,15 @@ VaultTestResultData TestLaraVault3Steps(ITEM_INFO* item, COLL_INFO* coll) CLICK(1), }; - return TestLaraVaultTolerance(item, coll, testData); + return TestLaraVaultTolerance(item, coll, testSetup); } -VaultTestResultData TestLaraVaultAutoJump(ITEM_INFO* item, COLL_INFO* coll) +VaultTestResult TestLaraVaultAutoJump(ITEM_INFO* item, COLL_INFO* coll) { // Floor range: (-CLICK(3.5f), -CLICK(7.5f)] // Clamp range: (-CLICK(0.1f), MAX_HEIGHT] - VaultTestData testData + VaultTestSetup testSetup { -CLICK(3.5f), -CLICK(7.5f), @@ -1909,15 +1901,15 @@ VaultTestResultData TestLaraVaultAutoJump(ITEM_INFO* item, COLL_INFO* coll) false }; - return TestLaraVaultTolerance(item, coll, testData); + return TestLaraVaultTolerance(item, coll, testSetup); } -VaultTestResultData TestLaraVault1StepToCrouch(ITEM_INFO* item, COLL_INFO* coll) +VaultTestResult TestLaraVault1StepToCrouch(ITEM_INFO* item, COLL_INFO* coll) { // Floor range: (0, -STEPUP_HEIGHT] // Clamp range: (-LARA_HEIGHT_CRAWL, -LARA_HEIGHT] - VaultTestData testData + VaultTestSetup testSetup { 0, -STEPUP_HEIGHT, @@ -1926,15 +1918,15 @@ VaultTestResultData TestLaraVault1StepToCrouch(ITEM_INFO* item, COLL_INFO* coll) CLICK(1), }; - return TestLaraVaultTolerance(item, coll, testData); + return TestLaraVaultTolerance(item, coll, testSetup); } -VaultTestResultData TestLaraVault2StepsToCrouch(ITEM_INFO* item, COLL_INFO* coll) +VaultTestResult TestLaraVault2StepsToCrouch(ITEM_INFO* item, COLL_INFO* coll) { // Floor range: (-STEPUP_HEIGHT, -CLICK(2.5f)] // Clamp range: (-LARA_HEIGHT_CRAWL, -LARA_HEIGHT] - VaultTestData testData + VaultTestSetup testSetup { -STEPUP_HEIGHT, -CLICK(2.5f), @@ -1943,15 +1935,15 @@ VaultTestResultData TestLaraVault2StepsToCrouch(ITEM_INFO* item, COLL_INFO* coll CLICK(1), }; - return TestLaraVaultTolerance(item, coll, testData); + return TestLaraVaultTolerance(item, coll, testSetup); } -VaultTestResultData TestLaraVault3StepsToCrouch(ITEM_INFO* item, COLL_INFO* coll) +VaultTestResult TestLaraVault3StepsToCrouch(ITEM_INFO* item, COLL_INFO* coll) { // Floor range: (-CLICK(2.5f), -CLICK(3.5f)] // Clamp range: (-LARA_HEIGHT_CRAWL, -LARA_HEIGHT] - VaultTestData testData + VaultTestSetup testSetup { -CLICK(2.5f), -CLICK(3.5f), @@ -1960,10 +1952,10 @@ VaultTestResultData TestLaraVault3StepsToCrouch(ITEM_INFO* item, COLL_INFO* coll CLICK(1), }; - return TestLaraVaultTolerance(item, coll, testData); + return TestLaraVaultTolerance(item, coll, testSetup); } -VaultTestResultData TestLaraLadderAutoJump(ITEM_INFO* item, COLL_INFO* coll) +VaultTestResult TestLaraLadderAutoJump(ITEM_INFO* item, COLL_INFO* coll) { LaraInfo*& info = item->data; @@ -1977,10 +1969,10 @@ VaultTestResultData TestLaraLadderAutoJump(ITEM_INFO* item, COLL_INFO* coll) (probeMiddle.Position.Ceiling - y) <= -CLICK(6.5f) && // Lower middle ceiling bound. coll->NearestLedgeDistance <= coll->Setup.Radius) // Appropriate distance from wall. { - return VaultTestResultData{ true, probeMiddle.Position.Ceiling }; + return VaultTestResult{ true, probeMiddle.Position.Ceiling }; } - return VaultTestResultData{ false, NO_HEIGHT }; + return VaultTestResult{ false, NO_HEIGHT }; } bool TestLaraLadderMount(ITEM_INFO* item, COLL_INFO* coll) @@ -2022,23 +2014,23 @@ bool TestLaraMonkeyAutoJump(ITEM_INFO* item, COLL_INFO* coll) return false; } -bool TestLaraCrawlVaultTolerance(ITEM_INFO* item, COLL_INFO* coll, CrawlVaultTestData testData) +bool TestLaraCrawlVaultTolerance(ITEM_INFO* item, COLL_INFO* coll, CrawlVaultTestSetup testSetup) { int y = item->pos.yPos; - auto probeA = GetCollisionResult(item, item->pos.yRot, testData.CrossDist, -LARA_HEIGHT_CRAWL); // Crossing. - auto probeB = GetCollisionResult(item, item->pos.yRot, testData.DestDist, -LARA_HEIGHT_CRAWL); // Approximate destination. + auto probeA = GetCollisionResult(item, item->pos.yRot, testSetup.CrossDist, -LARA_HEIGHT_CRAWL); // Crossing. + auto probeB = GetCollisionResult(item, item->pos.yRot, testSetup.DestDist, -LARA_HEIGHT_CRAWL); // Approximate destination. auto probeMiddle = GetCollisionResult(item); - bool isSlope = testData.CheckSlope ? probeB.Position.Slope : false; - bool isDeath = testData.CheckDeath ? probeB.Block->Flags.Death : false; + bool isSlope = testSetup.CheckSlope ? probeB.Position.Slope : false; + bool isDeath = testSetup.CheckDeath ? probeB.Block->Flags.Death : false; - if ((probeA.Position.Floor - y) <= testData.LowerBound && // Lower floor bound. - (probeA.Position.Floor - y) >= testData.UpperBound && // Upper floor bound. - abs(probeA.Position.Ceiling - probeA.Position.Floor) > testData.ClampMin && // Crossing clamp limit. - abs(probeB.Position.Ceiling - probeB.Position.Floor) > testData.ClampMin && // Destination clamp limit. - abs(probeMiddle.Position.Ceiling - probeA.Position.Floor) >= testData.GapMin && // Gap is optically permissive (going up). - abs(probeA.Position.Ceiling - probeMiddle.Position.Floor) >= testData.GapMin && // Gap is optically permissive (going down). - abs(probeA.Position.Floor - probeB.Position.Floor) <= testData.ProbeHeightDifMax && // Crossing and destination floor height difference suggests continuous crawl surface. - (probeA.Position.Ceiling - y) < -testData.GapMin && // Ceiling height is permissive. + if ((probeA.Position.Floor - y) <= testSetup.LowerBound && // Lower floor bound. + (probeA.Position.Floor - y) >= testSetup.UpperBound && // Upper floor bound. + abs(probeA.Position.Ceiling - probeA.Position.Floor) > testSetup.ClampMin && // Crossing clamp limit. + abs(probeB.Position.Ceiling - probeB.Position.Floor) > testSetup.ClampMin && // Destination clamp limit. + abs(probeMiddle.Position.Ceiling - probeA.Position.Floor) >= testSetup.GapMin && // Gap is optically permissive (going up). + abs(probeA.Position.Ceiling - probeMiddle.Position.Floor) >= testSetup.GapMin && // Gap is optically permissive (going down). + abs(probeA.Position.Floor - probeB.Position.Floor) <= testSetup.ProbeHeightDifMax && // Crossing and destination floor height difference suggests continuous crawl surface. + (probeA.Position.Ceiling - y) < -testSetup.GapMin && // Ceiling height is permissive. !isSlope && !isDeath && // No slope or death sector. probeA.Position.Floor != NO_HEIGHT && probeB.Position.Floor != NO_HEIGHT) { @@ -2052,7 +2044,7 @@ bool TestLaraCrawlUpStep(ITEM_INFO* item, COLL_INFO* coll) { // Floor range: [-CLICK(1), -STEPUP_HEIGHT] - CrawlVaultTestData testData + CrawlVaultTestSetup testSetup { -CLICK(1), -STEPUP_HEIGHT, @@ -2063,14 +2055,14 @@ bool TestLaraCrawlUpStep(ITEM_INFO* item, COLL_INFO* coll) CLICK(1) - 1 }; - return TestLaraCrawlVaultTolerance(item, coll, testData); + return TestLaraCrawlVaultTolerance(item, coll, testSetup); } bool TestLaraCrawlDownStep(ITEM_INFO* item, COLL_INFO* coll) { // Floor range: [STEPUP_HEIGHT, CLICK(1)] - CrawlVaultTestData testData + CrawlVaultTestSetup testSetup { STEPUP_HEIGHT, CLICK(1), @@ -2081,14 +2073,14 @@ bool TestLaraCrawlDownStep(ITEM_INFO* item, COLL_INFO* coll) CLICK(1) - 1 }; - return TestLaraCrawlVaultTolerance(item, coll, testData); + return TestLaraCrawlVaultTolerance(item, coll, testSetup); } bool TestLaraCrawlExitDownStep(ITEM_INFO* item, COLL_INFO* coll) { // Floor range: [STEPUP_HEIGHT, CLICK(1)] - CrawlVaultTestData testData + CrawlVaultTestSetup testSetup { STEPUP_HEIGHT, CLICK(1), @@ -2100,14 +2092,14 @@ bool TestLaraCrawlExitDownStep(ITEM_INFO* item, COLL_INFO* coll) false }; - return TestLaraCrawlVaultTolerance(item, coll, testData); + return TestLaraCrawlVaultTolerance(item, coll, testSetup); } bool TestLaraCrawlExitJump(ITEM_INFO* item, COLL_INFO* coll) { // Floor range: [-MAX_HEIGHT, STEPUP_HEIGHT) - CrawlVaultTestData testData + CrawlVaultTestSetup testSetup { -MAX_HEIGHT, STEPUP_HEIGHT + 1, @@ -2119,7 +2111,7 @@ bool TestLaraCrawlExitJump(ITEM_INFO* item, COLL_INFO* coll) false }; - return TestLaraCrawlVaultTolerance(item, coll, testData); + return TestLaraCrawlVaultTolerance(item, coll, testSetup); } bool TestLaraCrawlVault(ITEM_INFO* item, COLL_INFO* coll) diff --git a/TR5Main/Game/Lara/lara_tests.h b/TR5Main/Game/Lara/lara_tests.h index 3447e0056..559d3c54f 100644 --- a/TR5Main/Game/Lara/lara_tests.h +++ b/TR5Main/Game/Lara/lara_tests.h @@ -60,8 +60,8 @@ bool TestLaraStep(COLL_INFO* coll); bool TestLaraStepUp(ITEM_INFO* item, COLL_INFO* coll); bool TestLaraStepDown(ITEM_INFO* item, COLL_INFO* coll); -bool TestLaraMoveTolerance(ITEM_INFO* item, COLL_INFO* coll, MoveTestData testData); -bool TestLaraCrawlMoveTolerance(ITEM_INFO* item, COLL_INFO* coll, MoveTestData testData); +bool TestLaraMoveTolerance(ITEM_INFO* item, COLL_INFO* coll, MoveTestSetup testSetup); +bool TestLaraCrawlMoveTolerance(ITEM_INFO* item, COLL_INFO* coll, MoveTestSetup testSetup); bool TestLaraRunForward(ITEM_INFO* item, COLL_INFO* coll); bool TestLaraWalkForward(ITEM_INFO* item, COLL_INFO* coll); bool TestLaraWalkBack(ITEM_INFO* item, COLL_INFO* coll); @@ -78,19 +78,19 @@ bool TestLaraCrawlBack(ITEM_INFO* item, COLL_INFO* coll); bool TestLaraCrouchToCrawl(ITEM_INFO* item); bool TestLaraCrouchRoll(ITEM_INFO* item, COLL_INFO* coll); -VaultTestResultData TestLaraVaultTolerance(ITEM_INFO* item, COLL_INFO* coll, VaultTestData testData); -VaultTestResultData TestLaraVault2Steps(ITEM_INFO* item, COLL_INFO* coll); -VaultTestResultData TestLaraVault3Steps(ITEM_INFO* item, COLL_INFO* coll); -VaultTestResultData TestLaraVaultAutoJump(ITEM_INFO* item, COLL_INFO* coll); -VaultTestResultData TestLaraVault1StepToCrouch(ITEM_INFO* item, COLL_INFO* coll); -VaultTestResultData TestLaraVault2StepsToCrouch(ITEM_INFO* item, COLL_INFO* coll); -VaultTestResultData TestLaraVault3StepsToCrouch(ITEM_INFO* item, COLL_INFO* coll); +VaultTestResult TestLaraVaultTolerance(ITEM_INFO* item, COLL_INFO* coll, VaultTestSetup testSetup); +VaultTestResult TestLaraVault2Steps(ITEM_INFO* item, COLL_INFO* coll); +VaultTestResult TestLaraVault3Steps(ITEM_INFO* item, COLL_INFO* coll); +VaultTestResult TestLaraVaultAutoJump(ITEM_INFO* item, COLL_INFO* coll); +VaultTestResult TestLaraVault1StepToCrouch(ITEM_INFO* item, COLL_INFO* coll); +VaultTestResult TestLaraVault2StepsToCrouch(ITEM_INFO* item, COLL_INFO* coll); +VaultTestResult TestLaraVault3StepsToCrouch(ITEM_INFO* item, COLL_INFO* coll); -VaultTestResultData TestLaraLadderAutoJump(ITEM_INFO* item, COLL_INFO* coll); +VaultTestResult TestLaraLadderAutoJump(ITEM_INFO* item, COLL_INFO* coll); bool TestLaraLadderMount(ITEM_INFO* item, COLL_INFO* coll); bool TestLaraMonkeyAutoJump(ITEM_INFO* item, COLL_INFO* coll); -bool TestLaraCrawlVaultTolerance(ITEM_INFO* item, COLL_INFO* coll, CrawlVaultTestData testData); +bool TestLaraCrawlVaultTolerance(ITEM_INFO* item, COLL_INFO* coll, CrawlVaultTestSetup testSetup); bool TestLaraCrawlUpStep(ITEM_INFO* item, COLL_INFO* coll); bool TestLaraCrawlDownStep(ITEM_INFO* item, COLL_INFO* coll); bool TestLaraCrawlExitDownStep(ITEM_INFO* item, COLL_INFO* coll); From c99cd6f1cb3586d3cb309017ab2bfc6848bb825d Mon Sep 17 00:00:00 2001 From: Sezz Date: Thu, 27 Jan 2022 13:24:49 +1100 Subject: [PATCH 3/3] Introduce OFFSET_RADIUS expression --- TR5Main/Game/Lara/lara_tests.cpp | 14 +++++++------- TR5Main/Specific/trmath.h | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/TR5Main/Game/Lara/lara_tests.cpp b/TR5Main/Game/Lara/lara_tests.cpp index 3a9aa6ab4..ca057aa45 100644 --- a/TR5Main/Game/Lara/lara_tests.cpp +++ b/TR5Main/Game/Lara/lara_tests.cpp @@ -74,7 +74,7 @@ bool TestValidLedge(ITEM_INFO* item, COLL_INFO* coll, bool ignoreHeadroom, bool return false; // Discard if ledge is not within distance threshold - if (abs(coll->NearestLedgeDistance) > coll->Setup.Radius * sqrt(2) + 4) + if (abs(coll->NearestLedgeDistance) > OFFSET_RADIUS(coll->Setup.Radius)) return false; // Discard if ledge is not within angle threshold @@ -1564,7 +1564,7 @@ bool TestLaraStepDown(ITEM_INFO* item, COLL_INFO* coll) bool TestLaraMoveTolerance(ITEM_INFO* item, COLL_INFO* coll, MoveTestSetup testSetup) { int y = item->pos.yPos; - auto probe = GetCollisionResult(item, testSetup.Angle, coll->Setup.Radius * sqrt(2) + 4, -coll->Setup.Height); // Offset required to account for gap between Lara and the wall. Results in slight overshoot, but avoids oscillation. + auto probe = GetCollisionResult(item, testSetup.Angle, OFFSET_RADIUS(coll->Setup.Radius), -coll->Setup.Height); // Offset required to account for gap between Lara and the wall. Results in slight overshoot, but avoids oscillation. bool isSlopeDown = testSetup.CheckSlopeDown ? (probe.Position.Slope && probe.Position.Floor >= y) : false; bool isSlopeUp = testSetup.CheckSlopeUp ? (probe.Position.Slope && probe.Position.Floor < y) : false; bool isDeath = testSetup.CheckDeath ? probe.Block->Flags.Death : false; @@ -1590,7 +1590,7 @@ bool TestLaraMoveTolerance(ITEM_INFO* item, COLL_INFO* coll, MoveTestSetup testS bool TestLaraCrawlMoveTolerance(ITEM_INFO* item, COLL_INFO* coll, MoveTestSetup testSetup) { int y = item->pos.yPos; - auto probe = GetCollisionResult(item, testSetup.Angle, LARA_RAD_CRAWL * sqrt(2) + 4, -LARA_HEIGHT_CRAWL); + auto probe = GetCollisionResult(item, testSetup.Angle, OFFSET_RADIUS(LARA_RAD_CRAWL), -LARA_HEIGHT_CRAWL); bool isSlopeDown = testSetup.CheckSlopeDown ? (probe.Position.Slope && probe.Position.Floor >= y) : false; bool isSlopeUp = testSetup.CheckSlopeUp ? (probe.Position.Slope && probe.Position.Floor < y) : false; bool isDeath = testSetup.CheckDeath ? probe.Block->Flags.Death : false; @@ -1821,7 +1821,7 @@ VaultTestResult TestLaraVaultTolerance(ITEM_INFO* item, COLL_INFO* coll, VaultTe LaraInfo*& info = item->data; int y = item->pos.yPos; - auto probeFront = GetCollisionResult(item, coll->NearestLedgeAngle, coll->Setup.Radius * sqrt(2) + 4, -coll->Setup.Height); + auto probeFront = GetCollisionResult(item, coll->NearestLedgeAngle, OFFSET_RADIUS(coll->Setup.Radius), -coll->Setup.Height); auto probeMiddle = GetCollisionResult(item); bool swampTooDeep = testSetup.CheckSwampDepth ? (TestLaraSwamp(item) && info->waterSurfaceDist < -CLICK(3)) : TestLaraSwamp(item); @@ -1832,7 +1832,7 @@ VaultTestResult TestLaraVaultTolerance(ITEM_INFO* item, COLL_INFO* coll, VaultTe abs(probeFront.Position.Ceiling - probeFront.Position.Floor) > testSetup.ClampMax) && // Clamp is too large. yOffset > (testSetup.UpperBound - coll->Setup.Height)) // Offset is not too high. { - probeFront = GetCollisionResult(item, coll->NearestLedgeAngle, coll->Setup.Radius * sqrt(2) + 4, yOffset); + probeFront = GetCollisionResult(item, coll->NearestLedgeAngle, OFFSET_RADIUS(coll->Setup.Radius), yOffset); yOffset -= std::max((int)CLICK(0.5f), testSetup.ClampMin); } @@ -1960,7 +1960,7 @@ VaultTestResult TestLaraLadderAutoJump(ITEM_INFO* item, COLL_INFO* coll) LaraInfo*& info = item->data; int y = item->pos.yPos; - auto probeFront = GetCollisionResult(item, coll->NearestLedgeAngle, coll->Setup.Radius * sqrt(2) + 4, -coll->Setup.Height); + auto probeFront = GetCollisionResult(item, coll->NearestLedgeAngle, OFFSET_RADIUS(coll->Setup.Radius), -coll->Setup.Height); auto probeMiddle = GetCollisionResult(item); if (TestValidLedgeAngle(item, coll) && @@ -1981,7 +1981,7 @@ bool TestLaraLadderMount(ITEM_INFO* item, COLL_INFO* coll) int y = item->pos.yPos; auto probeMiddle = GetCollisionResult(item); - auto probeFront = GetCollisionResult(item, coll->NearestLedgeAngle, coll->Setup.Radius * sqrt(2) + 4, -coll->Setup.Height); + auto probeFront = GetCollisionResult(item, coll->NearestLedgeAngle, OFFSET_RADIUS(coll->Setup.Radius), -coll->Setup.Height); if (TestValidLedgeAngle(item, coll) && info->climbStatus && // Ladder sector flag set. diff --git a/TR5Main/Specific/trmath.h b/TR5Main/Specific/trmath.h index 230879c74..7f9f961e5 100644 --- a/TR5Main/Specific/trmath.h +++ b/TR5Main/Specific/trmath.h @@ -35,6 +35,7 @@ constexpr auto SQUARE = [](auto x) { return x * x; }; constexpr auto CLICK = [](auto x) { return STEP_SIZE * x; }; constexpr auto SECTOR = [](auto x) { return WALL_SIZE * x; }; constexpr auto MESH_BITS = [](auto x) { return 1 << x; }; +constexpr auto OFFSET_RADIUS = [](auto x) { return x * sqrt(2) + 4; }; short ANGLE(float angle); short FROM_DEGREES(float angle);