Implement gravity resolution and fast area calculations in collision handling

This commit is contained in:
Maddo 2026-09-26 21:58:01 +02:00
commit 2e16b2d524
8 changed files with 301 additions and 26 deletions

View file

@ -4,6 +4,14 @@
int main()
{
const auto centeredArea = remorse::calculateFastAreaRange({512, 512, 0});
assert(centeredArea.minSum == -3 && centeredArea.maxSum == 7 &&
centeredArea.minDifference == -3 && centeredArea.maxDifference == 3);
assert(remorse::isWorldPointInFastArea(512, 512, centeredArea));
assert(!remorse::isWorldPointInFastArea(4096, 512, centeredArea));
const auto beforeBlockCrossing = remorse::calculateFastAreaRange({511, 512, 0});
assert(beforeBlockCrossing.minSum == centeredArea.minSum - 1 &&
beforeBlockCrossing.minDifference == centeredArea.minDifference - 1);
const remorse::FastAreaRange fastArea{2, 4, 0, 2};
assert(remorse::isWorldPointInFastArea(512, 512, fastArea));
assert(!remorse::isWorldPointInFastArea(-1, 512, fastArea));
@ -126,7 +134,7 @@ int main()
sweepShapes[2].flags = 2;
sweepShapes[3] = sweepShapes[1];
const remorse::FastAreaRange allBlocks{-128, 128, -128, 128};
const auto liveImpacts = remorse::collectSolidSweepImpacts(liveSweepItems, 0x100,
const auto liveImpacts = remorse::collectSweepItemImpacts(liveSweepItems, 0x100,
{700, 512, 0}, sweepShapes, allBlocks);
assert(liveImpacts && liveImpacts->size() == 1);
assert((*liveImpacts)[0].itemNumber == 0x101 &&
@ -139,7 +147,7 @@ int main()
sweepShapes[2].y = 4;
wallItem.data.flags = 0x20;
remorse::LiveFixedMapItems flippedSweepItems({movingItem, wallItem, nextWall, harmlessItem});
const auto flippedImpacts = remorse::collectSolidSweepImpacts(flippedSweepItems, 0x100,
const auto flippedImpacts = remorse::collectSweepItemImpacts(flippedSweepItems, 0x100,
{700, 512, 0}, sweepShapes, allBlocks);
assert(flippedImpacts && flippedImpacts->size() == 2);
assert((*flippedImpacts)[0].itemNumber == 0x103 && (*flippedImpacts)[0].impact.resolved.x == 654);
@ -152,8 +160,18 @@ int main()
{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 outsideFastArea = remorse::resolveSolidLiveSweep(flippedSweepItems, 0x100,
{700, 512, 0}, sweepShapes, {2, 2, 0, 0});
assert(outsideFastArea && outsideFastArea->failed &&
outsideFastArea->destination.x == 512 && outsideFastArea->failedDirections == 3);
const auto outsideWorld = remorse::resolveSolidLiveSweep(flippedSweepItems, 0x100,
{-1, 512, 0}, sweepShapes, allBlocks);
assert(outsideWorld && outsideWorld->failed && outsideWorld->failedDirections == 3 &&
outsideWorld->destination.x == 512);
const auto aboveCeiling = remorse::resolveSolidLiveSweep(flippedSweepItems, 0x100,
{512, 512, 251}, sweepShapes, allBlocks);
assert(aboveCeiling && !aboveCeiling->failed && aboveCeiling->failedDirections == 4 &&
aboveCeiling->destination.z == 250);
const auto noImpact = remorse::selectSolidSweepImpact({512, 512, 0}, {700, 512, 0}, {});
assert(noImpact.firstCollision == 0 && noImpact.destination.x == 700 &&
noImpact.failedDirections == 0);
@ -168,9 +186,49 @@ int main()
{700, 700, 0}, mixedAxisImpacts);
assert(mixedAxis.firstCollision == 0x103 && mixedAxis.destination.x == 550 &&
mixedAxis.destination.y == 550 && mixedAxis.failedDirections == 3);
assert(!remorse::collectSolidSweepImpacts(liveSweepItems, 0x100,
sweepShapes[3].flags = 0x40;
remorse::LiveFixedMapItems damagingItems({movingItem, harmlessItem});
const auto damageOnly = remorse::resolveSolidLiveSweep(damagingItems, 0x100,
{700, 512, 0}, sweepShapes, allBlocks);
assert(damageOnly && damageOnly->firstCollision == 0 &&
damageOnly->destination.x == 700 && damageOnly->failedDirections == 0 &&
(damageOnly->damagingContacts == std::vector<remorse::u16>{0x102}));
movingItem.data.z = 32;
wallItem.data.x = 512;
wallItem.data.z = 16;
remorse::LiveFixedMapItems floorItems({movingItem, wallItem});
const auto floorDisabled = remorse::resolveSolidLiveSweep(floorItems, 0x100,
{512, 512, 32}, sweepShapes, allBlocks);
assert(floorDisabled && floorDisabled->supportItem == 0);
const auto floorTouch = remorse::resolveSolidLiveSweep(floorItems, 0x100,
{512, 512, 32}, sweepShapes, allBlocks, remorse::u8{0});
assert(floorTouch && floorTouch->supportItem == 0x101 && floorTouch->supportGap == 0 &&
floorTouch->destination.z == 32 && floorTouch->firstCollision == 0);
const auto floorStep = remorse::resolveSolidLiveSweep(floorItems, 0x100,
{512, 512, 41}, sweepShapes, allBlocks, remorse::u8{9});
assert(floorStep && floorStep->supportGap == 9 && floorStep->destination.z == 41);
const auto floorTooFar = remorse::resolveSolidLiveSweep(floorItems, 0x100,
{512, 512, 42}, sweepShapes, allBlocks, remorse::u8{9});
assert(floorTooFar && !floorTooFar->supportGap);
auto lowerFloor = wallItem;
lowerFloor.itemNumber = 0x104;
lowerFloor.data.z = 17;
remorse::LiveFixedMapItems layeredFloorItems({movingItem, wallItem, lowerFloor});
const auto closestFloor = remorse::resolveSolidLiveSweep(layeredFloorItems, 0x100,
{512, 512, 41}, sweepShapes, allBlocks, remorse::u8{9});
assert(closestFloor && closestFloor->supportItem == 0x104 && closestFloor->supportGap == 8);
lowerFloor.data.x = 650;
remorse::LiveFixedMapItems distantFloorItems({movingItem, lowerFloor});
const auto outsideFootprint = remorse::resolveSolidLiveSweep(distantFloorItems, 0x100,
{512, 512, 37}, sweepShapes, allBlocks, remorse::u8{9});
assert(outsideFootprint && !outsideFootprint->supportGap);
sweepShapes[2].flags = 0x40;
const auto damagingFloor = remorse::resolveSolidLiveSweep(floorItems, 0x100,
{512, 512, 32}, sweepShapes, allBlocks, remorse::u8{0});
assert(damagingFloor && !damagingFloor->supportGap);
assert(!remorse::collectSweepItemImpacts(liveSweepItems, 0x100,
{700, 512, 0}, sweepShapes, {2, 2, 0, 0}));
assert(!remorse::collectSolidSweepImpacts(liveSweepItems, 0x105,
assert(!remorse::collectSweepItemImpacts(liveSweepItems, 0x105,
{700, 512, 0}, sweepShapes, allBlocks));
remorse::FixedMap map;