Refactor collision handling and item management in the Remorse project
- Introduced new structures for handling sweep impacts and collision results, including SweepItemImpact, SweepCandidateImpact, and SweepCollisionResult. - Implemented functions to check if a world point or sweep footprint is within a defined fast area. - Enhanced LiveFixedMapItems to manage contained items and support item allocation with parent-child relationships. - Updated collision detection logic to handle solid item impacts and collect sweep impacts from live items. - Added tests for new collision functionalities, including sweep impact resolution and candidate selection. - Modified existing tests to validate new item management features and ensure proper integration with the collision system.
This commit is contained in:
parent
b99fb59c12
commit
b3975ca41b
8 changed files with 467 additions and 8 deletions
|
|
@ -4,6 +4,24 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
const remorse::FastAreaRange fastArea{2, 4, 0, 2};
|
||||
assert(remorse::isWorldPointInFastArea(512, 512, fastArea));
|
||||
assert(!remorse::isWorldPointInFastArea(-1, 512, fastArea));
|
||||
assert(!remorse::isWorldPointInFastArea(0x8000, 512, fastArea));
|
||||
assert(remorse::isSweepFootprintInFastArea({1000, 1000, 0}, {2000, 1000, 0},
|
||||
32, 32, fastArea));
|
||||
assert(!remorse::isSweepFootprintInFastArea({1000, 1000, 0}, {2000, 1000, 0},
|
||||
32, 32, {2, 3, 0, 2}));
|
||||
assert(!remorse::isSweepFootprintInFastArea({1000, 1000, 0}, {2000, 1000, 0},
|
||||
32, 32, {2, 4, 1, 2}));
|
||||
const auto sweepArea = remorse::areaSweepCandidateBounds({511, 512, 0}, {1024, 1536, 0}, 32, 64);
|
||||
assert(sweepArea.minX == 479 && sweepArea.minY == 448 &&
|
||||
sweepArea.maxX == 1280 && sweepArea.maxY == 1792);
|
||||
const auto reverseArea = remorse::areaSweepCandidateBounds({1024, 1536, 0}, {511, 512, 0}, 32, 64);
|
||||
assert(reverseArea.minX == sweepArea.minX && reverseArea.maxY == sweepArea.maxY);
|
||||
const auto edgeSweepArea = remorse::areaSweepCandidateBounds({10, 10, 0}, {0x7fff, 0x7fff, 0}, 32, 64);
|
||||
assert(edgeSweepArea.minX == 0 && edgeSweepArea.minY == 0 &&
|
||||
edgeSweepArea.maxX == 0x7fff && edgeSweepArea.maxY == 0x7fff);
|
||||
const auto outsideBounds = remorse::clampAreaSweepBounds({10, 20, 10}, {-3, 0x8000, 252});
|
||||
assert(outsideBounds.destination.x == 0 && outsideBounds.destination.y == 0x7fff &&
|
||||
outsideBounds.destination.z == 250 && outsideBounds.failedDirections == 7 &&
|
||||
|
|
@ -56,6 +74,105 @@ int main()
|
|||
assert(flipped.extentX == 128);
|
||||
assert(flipped.extentY == 64);
|
||||
|
||||
const auto sweepItem = remorse::makeSweepItemBody({300, 300, 0}, obstacleInfo, true);
|
||||
assert(sweepItem.extentX == 64 && sweepItem.extentY == 32 && sweepItem.extentZ == 64);
|
||||
obstacleInfo.z = 0;
|
||||
const auto zeroHeightItem = remorse::makeSweepItemBody({300, 300, 0}, obstacleInfo);
|
||||
assert(zeroHeightItem.extentZ == 1);
|
||||
obstacleInfo.flags = 1;
|
||||
assert(remorse::makeSweepItemBody({300, 300, 0}, obstacleInfo).extentZ == 0);
|
||||
obstacleInfo.z = 8;
|
||||
obstacleInfo.flags = 0;
|
||||
|
||||
const remorse::CollisionBody sweepActor{{100, 100, 0}, 32, 32, 16};
|
||||
const remorse::CollisionBody sweepWall{{200, 100, 0}, 32, 32, 16};
|
||||
const auto rightHit = remorse::sweepSolidItemImpact(sweepActor, {250, 100, 0}, sweepWall);
|
||||
assert(rightHit && rightHit->failedDirections == 1 && rightHit->resolved.x == 168);
|
||||
const auto leftHit = remorse::sweepSolidItemImpact({{300, 100, 0}, 32, 32, 16},
|
||||
{150, 100, 0}, sweepWall);
|
||||
assert(leftHit && leftHit->failedDirections == 1 && leftHit->resolved.x == 232);
|
||||
const auto upHit = remorse::sweepSolidItemImpact(sweepActor, {100, 250, 0},
|
||||
{{100, 200, 0}, 32, 32, 16});
|
||||
assert(upHit && upHit->failedDirections == 2 && upHit->resolved.y == 168);
|
||||
const auto downHit = remorse::sweepSolidItemImpact({{100, 300, 0}, 32, 32, 16},
|
||||
{100, 150, 0}, {{100, 200, 0}, 32, 32, 16});
|
||||
assert(downHit && downHit->failedDirections == 2 && downHit->resolved.y == 232);
|
||||
const auto ascendingHit = remorse::sweepSolidItemImpact(sweepActor, {100, 100, 30},
|
||||
{{100, 100, 20}, 32, 32, 16});
|
||||
assert(ascendingHit && ascendingHit->failedDirections == 4 && ascendingHit->resolved.z == 4);
|
||||
const auto descendingHit = remorse::sweepSolidItemImpact({{100, 100, 40}, 32, 32, 16},
|
||||
{100, 100, 0}, {{100, 100, 20}, 32, 32, 16});
|
||||
assert(descendingHit && descendingHit->failedDirections == 4 && descendingHit->resolved.z == 36);
|
||||
assert(!remorse::sweepSolidItemImpact(sweepActor, {250, 100, 0},
|
||||
{{200, 200, 0}, 32, 32, 16}));
|
||||
|
||||
remorse::StagedFixedMapItem movingItem;
|
||||
movingItem.itemNumber = 0x100;
|
||||
movingItem.data.x = 512;
|
||||
movingItem.data.y = 512;
|
||||
movingItem.data.shape = 1;
|
||||
auto wallItem = movingItem;
|
||||
wallItem.itemNumber = 0x101;
|
||||
wallItem.data.x = 640;
|
||||
wallItem.data.shape = 2;
|
||||
auto harmlessItem = wallItem;
|
||||
harmlessItem.itemNumber = 0x102;
|
||||
harmlessItem.data.x = 600;
|
||||
harmlessItem.data.shape = 3;
|
||||
remorse::LiveFixedMapItems liveSweepItems({movingItem, wallItem, harmlessItem});
|
||||
std::vector<remorse::ShapeTypeInfo> sweepShapes(4);
|
||||
sweepShapes[1].x = sweepShapes[1].y = sweepShapes[1].z = 2;
|
||||
sweepShapes[2] = sweepShapes[1];
|
||||
sweepShapes[2].flags = 2;
|
||||
sweepShapes[3] = sweepShapes[1];
|
||||
const remorse::FastAreaRange allBlocks{-128, 128, -128, 128};
|
||||
const auto liveImpacts = remorse::collectSolidSweepImpacts(liveSweepItems, 0x100,
|
||||
{700, 512, 0}, sweepShapes, allBlocks);
|
||||
assert(liveImpacts && liveImpacts->size() == 1);
|
||||
assert((*liveImpacts)[0].itemNumber == 0x101 &&
|
||||
(*liveImpacts)[0].impact.failedDirections == 1 &&
|
||||
(*liveImpacts)[0].impact.resolved.x == 608);
|
||||
auto nextWall = wallItem;
|
||||
nextWall.itemNumber = 0x103;
|
||||
nextWall.data.x = 670;
|
||||
sweepShapes[2].x = 1;
|
||||
sweepShapes[2].y = 4;
|
||||
wallItem.data.flags = 0x20;
|
||||
remorse::LiveFixedMapItems flippedSweepItems({movingItem, wallItem, nextWall, harmlessItem});
|
||||
const auto flippedImpacts = remorse::collectSolidSweepImpacts(flippedSweepItems, 0x100,
|
||||
{700, 512, 0}, sweepShapes, allBlocks);
|
||||
assert(flippedImpacts && flippedImpacts->size() == 2);
|
||||
assert((*flippedImpacts)[0].itemNumber == 0x103 && (*flippedImpacts)[0].impact.resolved.x == 654);
|
||||
assert((*flippedImpacts)[1].itemNumber == 0x101 && (*flippedImpacts)[1].impact.resolved.x == 576);
|
||||
const auto nearestImpact = remorse::selectSolidSweepImpact({512, 512, 0},
|
||||
{700, 512, 0}, *flippedImpacts);
|
||||
assert(nearestImpact.firstCollision == 0x101 && nearestImpact.destination.x == 576 &&
|
||||
nearestImpact.failedDirections == 1);
|
||||
const auto resolvedLive = remorse::resolveSolidLiveSweep(flippedSweepItems, 0x100,
|
||||
{700, 512, 0}, sweepShapes, allBlocks);
|
||||
assert(resolvedLive && resolvedLive->firstCollision == 0x101 &&
|
||||
resolvedLive->destination.x == 576 && resolvedLive->failedDirections == 1);
|
||||
assert(!remorse::resolveSolidLiveSweep(flippedSweepItems, 0x100,
|
||||
{700, 512, 0}, sweepShapes, {2, 2, 0, 0}));
|
||||
const auto noImpact = remorse::selectSolidSweepImpact({512, 512, 0}, {700, 512, 0}, {});
|
||||
assert(noImpact.firstCollision == 0 && noImpact.destination.x == 700 &&
|
||||
noImpact.failedDirections == 0);
|
||||
const std::vector<remorse::SweepCandidateImpact> tiedImpacts{
|
||||
{0x101, {{576, 512, 0}, 1}}, {0x103, {{576, 512, 0}, 2}}};
|
||||
const auto tiedImpact = remorse::selectSolidSweepImpact({512, 512, 0},
|
||||
{700, 512, 0}, tiedImpacts);
|
||||
assert(tiedImpact.firstCollision == 0x101 && tiedImpact.failedDirections == 3);
|
||||
const std::vector<remorse::SweepCandidateImpact> mixedAxisImpacts{
|
||||
{0x101, {{540, 590, 0}, 1}}, {0x103, {{550, 550, 0}, 2}}};
|
||||
const auto mixedAxis = remorse::selectSolidSweepImpact({512, 512, 0},
|
||||
{700, 700, 0}, mixedAxisImpacts);
|
||||
assert(mixedAxis.firstCollision == 0x103 && mixedAxis.destination.x == 550 &&
|
||||
mixedAxis.destination.y == 550 && mixedAxis.failedDirections == 3);
|
||||
assert(!remorse::collectSolidSweepImpacts(liveSweepItems, 0x100,
|
||||
{700, 512, 0}, sweepShapes, {2, 2, 0, 0}));
|
||||
assert(!remorse::collectSolidSweepImpacts(liveSweepItems, 0x105,
|
||||
{700, 512, 0}, sweepShapes, allBlocks));
|
||||
|
||||
remorse::FixedMap map;
|
||||
remorse::FixedMapEntry solid;
|
||||
solid.x = 500;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "remorse/entity_dispatch_entry.h"
|
||||
#include "remorse/file_system.h"
|
||||
#include "remorse/fixed_map.h"
|
||||
#include "remorse/map_renderer.h"
|
||||
#include "remorse/type_flags.h"
|
||||
|
||||
#include <cassert>
|
||||
|
|
@ -181,6 +182,9 @@ int main()
|
|||
assert(!liveItems.moveItem(0x100, 0x8000, 0, 0));
|
||||
assert(liveItems.moveItem(0x100, 768, 511, 81));
|
||||
assert(liveItems.findItem(0x100)->data.x == 768 && blockItems[0].data.x == 511);
|
||||
const auto sweepBefore = liveItems.sweepCandidateIds({511, 511, 512, 512}, 0x105);
|
||||
assert(sweepBefore && (*sweepBefore == std::vector<remorse::u16>{0x103, 0x102}));
|
||||
assert(!liveItems.sweepCandidateIds({-1, 0, 512, 512}, 0x105));
|
||||
assert(liveItems.nearestItem(768 * 2, 511 * 2, 0)->itemNumber == 0x100);
|
||||
assert(!liveItems.nearestItem(511 * 2, 511 * 2, -1));
|
||||
assert(!liveItems.grabItem(0x106, searchShapes, liveKernel, liveGroups, 14));
|
||||
|
|
@ -197,6 +201,8 @@ int main()
|
|||
reorderedKernel.createProcess(1, reorderedGroups);
|
||||
}
|
||||
assert(reorderedItems.moveItem(0x100, 511, 511, 81));
|
||||
const auto sweepAfter = reorderedItems.sweepCandidateIds({511, 511, 512, 512}, 0x105);
|
||||
assert(sweepAfter && (*sweepAfter == std::vector<remorse::u16>{0x100, 0x103, 0x102}));
|
||||
const auto reorderedGrab = reorderedItems.grabItem(0x105, searchShapes,
|
||||
reorderedKernel, reorderedGroups, 14);
|
||||
assert(reorderedGrab && reorderedGrab->size() == 2 && (*reorderedGrab)[0] == 3 &&
|
||||
|
|
@ -221,6 +227,14 @@ int main()
|
|||
insertedKernel, insertedGroups, 14);
|
||||
assert(insertedGrab && insertedGrab->size() == 3 && (*insertedGrab)[0] == 3);
|
||||
assert(insertedKernel.findProcessForItemAndType(0x106, 0xf1) == insertedKernel.processAt(3));
|
||||
remorse::LiveFixedMapItems allocatedItems(blockItems, {{0x101, 0x100, 0}});
|
||||
newItem.itemNumber = 0;
|
||||
assert(!allocatedItems.findItem(0x101));
|
||||
assert(allocatedItems.allocateItem(newItem) == 0x106);
|
||||
assert(allocatedItems.findItem(0x106)->data.x == 511);
|
||||
assert(allocatedItems.allocateItem(newItem) == 0x107);
|
||||
newItem.data.x = 0x8000;
|
||||
assert(!allocatedItems.allocateItem(newItem) && !allocatedItems.findItem(0x108));
|
||||
remorse::LiveFixedMapItems movingItems(blockItems);
|
||||
remorse::ProcessKernel movingKernel;
|
||||
remorse::u16 movingGroups[32]{};
|
||||
|
|
@ -326,6 +340,25 @@ int main()
|
|||
assert((*contained)[0].itemNumber == 0x101 && (*contained)[0].parentItemNumber == 0x100);
|
||||
assert((*contained)[1].itemNumber == 0x102 && (*contained)[1].parentItemNumber == 0x101);
|
||||
assert((*contained)[2].itemNumber == 0x103 && (*contained)[2].parentItemNumber == 0x100);
|
||||
const auto directContainerItems = remorse::stageFixedMapItems(containedMap);
|
||||
assert(directContainerItems && directContainerItems->size() == 2);
|
||||
remorse::LiveFixedMapItems nestedItems(*directContainerItems, *contained);
|
||||
assert(nestedItems.containedParent(0x101) == 0x100 &&
|
||||
nestedItems.containedParent(0x102) == 0x101 && nestedItems.containedParent(0x103) == 0x100);
|
||||
remorse::StagedFixedMapItem nestedNewItem = directContainerItems->front();
|
||||
assert(nestedItems.allocateItem(nestedNewItem) == 0x105);
|
||||
assert(!nestedItems.findItem(0x101) && !nestedItems.findItem(0x102) &&
|
||||
!nestedItems.findItem(0x103) && nestedItems.findItem(0x105));
|
||||
nestedNewItem.itemNumber = 0x101;
|
||||
assert(nestedItems.insertItem(nestedNewItem));
|
||||
assert(nestedItems.containedParent(0x101) == 0 && nestedItems.containedParent(0x102) == 0x101);
|
||||
std::vector<remorse::StagedContainedFixedMapItem> fullItemRange;
|
||||
for (remorse::u16 itemNumber = 0x101; itemNumber < 0x2800; ++itemNumber) {
|
||||
fullItemRange.push_back({itemNumber, 0x100, 0});
|
||||
}
|
||||
remorse::LiveFixedMapItems exhaustedItems({directContainerItems->front()}, fullItemRange);
|
||||
assert(!exhaustedItems.allocateItem(nestedNewItem));
|
||||
assert(!exhaustedItems.findItem(0x101) && exhaustedItems.containedParent(0x101) == 0x100);
|
||||
containerShapes[1].family = 0;
|
||||
assert(!remorse::stageContainedFixedMapItems(containedMap, containerShapes));
|
||||
assert(remorse::itemGrabCanCreateProcess((*stagedItems)[0]));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue