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:
Maddo 2026-09-26 19:50:26 +02:00
commit b3975ca41b
8 changed files with 467 additions and 8 deletions

View file

@ -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]));