Enhance item handling and collision detection in remorse
- Introduced new functionality for staging and managing fixed map items, including the ability to build block chains and find candidates for item interactions. - Updated the main application logic to utilize staged item block chains for improved item finding and grabbing mechanics. - Added weight attribute to shape type information, allowing for more nuanced item interactions based on weight. - Enhanced collision tests to cover new item handling scenarios, including gravity sweeps and item grabbing. - Implemented additional tests for entity dispatch entries and fixed map items to ensure robustness of item spawning and movement logic. - Improved type flags loading to validate weight against binary data, ensuring consistency in item attributes.
This commit is contained in:
parent
c346b0e1a7
commit
b99fb59c12
15 changed files with 961 additions and 18 deletions
|
|
@ -4,6 +4,24 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
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 &&
|
||||
outsideBounds.failed);
|
||||
const auto belowFloor = remorse::clampAreaSweepBounds({10, 20, 10}, {10, 20, -3});
|
||||
assert(belowFloor.destination.z == 0 && belowFloor.failedDirections == 4 && !belowFloor.failed);
|
||||
const auto withinBounds = remorse::clampAreaSweepBounds({10, 20, 10}, {12, 23, 11});
|
||||
assert(withinBounds.failedDirections == 0 && !withinBounds.failed);
|
||||
const auto gravityStep = remorse::planGravitySweep({100, 200, 250}, 3, -2, 4, 2, 3);
|
||||
assert(gravityStep.destination.x == 109 && gravityStep.destination.y == 194);
|
||||
assert(gravityStep.destination.z == 6 && gravityStep.nextZSpeed == -2);
|
||||
const auto slowStep = remorse::planGravitySweep({100, 200, 0}, 3, -2, -4, 2, 0);
|
||||
assert(slowStep.destination.x == 103 && slowStep.destination.y == 198);
|
||||
assert(slowStep.destination.z == 252 && slowStep.nextZSpeed == -6);
|
||||
const auto cappedStep = remorse::planGravitySweep({100, 200, 0}, 3, -2, 4, 2, 5);
|
||||
assert(cappedStep.destination.x == 112 && cappedStep.destination.y == 192);
|
||||
assert(cappedStep.destination.z == 16 && cappedStep.nextZSpeed == -4);
|
||||
|
||||
const remorse::CollisionBody actor{{100, 100, 0}, 96, 96, 80};
|
||||
const remorse::CollisionBody wall{{300, 100, 0}, 64, 96, 128};
|
||||
assert(!remorse::collisionBodiesOverlap(actor, wall));
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
#include "remorse/entity_dispatch_entry.h"
|
||||
#include "remorse/fixed_map.h"
|
||||
#include "remorse/map_renderer.h"
|
||||
#include "remorse/type_flags.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
|
@ -285,6 +288,33 @@ int main()
|
|||
assert(spawnContext.runs == 1 && spawnContext.spawned == spawningKernel.processAt(2));
|
||||
assert(spawningProcess->bytes[0x18] == 0x07 && spawnContext.spawned->bytes[0x16] == 0);
|
||||
|
||||
remorse::ProcessKernel itemSpawnKernel;
|
||||
remorse::u16 itemSpawnGroups[32]{};
|
||||
for (int index = 0; index < 3; ++index) {
|
||||
itemSpawnKernel.createProcess(1, itemSpawnGroups);
|
||||
}
|
||||
auto* itemSpawner = itemSpawnKernel.createProcess(2, itemSpawnGroups);
|
||||
itemSpawner->bytes[0x18] |= 0x02;
|
||||
struct ItemSpawnContext {
|
||||
remorse::ProcessKernel* kernel;
|
||||
remorse::u16 (*groups)[32];
|
||||
remorse::EntityDispatchEntryBase* spawned = nullptr;
|
||||
int spawnedRuns = 0;
|
||||
} itemSpawnContext{&itemSpawnKernel, &itemSpawnGroups};
|
||||
auto spawnItemRun = [](remorse::EntityDispatchEntryBase& process, void* context) {
|
||||
auto& state = *static_cast<ItemSpawnContext*>(context);
|
||||
if (process.bytes[0] == remorse::ItemProcess::vtableOffset % 256) {
|
||||
++state.spawnedRuns;
|
||||
} else if (state.spawned == nullptr && process.bytes[2] == 3) {
|
||||
state.spawned = state.kernel->createItemProcess(2, 0x100, *state.groups);
|
||||
}
|
||||
};
|
||||
itemSpawnKernel.scanRunnableProcesses(2, spawnItemRun, &itemSpawnContext);
|
||||
assert(itemSpawnContext.spawned && itemSpawnContext.spawnedRuns == 0 &&
|
||||
(itemSpawnContext.spawned->bytes[0x16] & 0x40) == 0);
|
||||
itemSpawnKernel.scanRunnableProcesses(2, spawnItemRun, &itemSpawnContext);
|
||||
assert(itemSpawnContext.spawnedRuns == 1);
|
||||
|
||||
remorse::ProcessKernel retiringKernel;
|
||||
remorse::u16 retiringGroups[32]{};
|
||||
for (int index = 0; index < 3; ++index) {
|
||||
|
|
@ -372,7 +402,11 @@ int main()
|
|||
assert(itemProcess->bytes[6] == 0xf1 && itemProcess->bytes[7] == 0);
|
||||
assert(cachedItemKernel.itemHasProcess(0x100) && cachedItemKernel.itemProcessTypes(0x100) == 2);
|
||||
assert(cachedItemGroups[1] == 4);
|
||||
assert(cachedItemKernel.findProcessForItemAndType(0x100, 0xf1) == itemProcess);
|
||||
assert(cachedItemKernel.findProcessForItemAndType(0, 0x0c) == itemProcess);
|
||||
assert(cachedItemKernel.findProcessForItemAndType(0x101, 0xf1) == nullptr);
|
||||
auto* sharedItemProcess = cachedItemKernel.createItemProcess(1, 0x100, cachedItemGroups);
|
||||
assert(cachedItemKernel.findProcessForItemAndType(0x100, 0xf1) == itemProcess);
|
||||
assert(cachedItemKernel.itemProcessTypes(0x100) == 2);
|
||||
cachedItemKernel.setProcessSourceType(*sharedItemProcess, 0x101);
|
||||
assert(cachedItemKernel.itemHasProcess(0x100) && cachedItemKernel.itemHasProcess(0x101));
|
||||
|
|
@ -422,6 +456,7 @@ int main()
|
|||
}
|
||||
}, &itemRunContext);
|
||||
assert(releasedItem == 0x100 && !cachedItemKernel.itemHasProcess(0x100));
|
||||
assert(cachedItemKernel.findProcessForItemAndType(0x100, 0xf1) == nullptr);
|
||||
assert(cachedItemKernel.itemProcessTypes(0x100) == 0);
|
||||
assert(cachedItemKernel.processAt(3) == nullptr && cachedItemGroups[1] == 3);
|
||||
bool itemTeardownRejected = false;
|
||||
|
|
@ -431,6 +466,143 @@ int main()
|
|||
itemTeardownRejected = true;
|
||||
}
|
||||
assert(itemTeardownRejected && standGroups[2] == 2 && standKernel.processAt(1) == standing);
|
||||
remorse::ProcessKernel gravityKernel;
|
||||
remorse::u16 gravityGroups[32]{};
|
||||
for (int index = 0; index < 3; ++index) {
|
||||
gravityKernel.createProcess(1, gravityGroups);
|
||||
}
|
||||
const auto gravityId = gravityKernel.hurlItem(1, 0x100, 2, -3, 4, 2, 10, gravityGroups);
|
||||
auto* gravityEntry = gravityKernel.processAt(gravityId);
|
||||
assert(gravityEntry && gravityKernel.allocationSizeAt(gravityId) == 0x42);
|
||||
assert(std::strcmp(gravityKernel.processNameAt(gravityId), "Gravity") == 0);
|
||||
assert(gravityKernel.findProcessForItemAndType(0x100, 0x203) == gravityEntry);
|
||||
assert(gravityEntry->bytes[0] == 0x10 && gravityEntry->bytes[1] == 0x06);
|
||||
assert(gravityEntry->bytes[0x32] == 2 && gravityEntry->bytes[0x34] == 0xfd &&
|
||||
gravityEntry->bytes[0x35] == 0xff && gravityEntry->bytes[0x36] == 4);
|
||||
assert(gravityEntry->bytes[0x38] == 2 && gravityEntry->bytes[0x3b] == 200);
|
||||
assert((gravityEntry->bytes[0x19] & 0x10) != 0 && gravityEntry->bytes[0x0a] == 10 &&
|
||||
gravityEntry->bytes[0x0e] == 20 && gravityGroups[1] == 4);
|
||||
assert(gravityKernel.hurlItem(1, 0x100, -4, 5, -2, 99, 11, gravityGroups) == gravityId);
|
||||
assert(gravityEntry->bytes[0x32] == 0xfe && gravityEntry->bytes[0x33] == 0xff &&
|
||||
gravityEntry->bytes[0x34] == 2 && gravityEntry->bytes[0x36] == 2 &&
|
||||
gravityEntry->bytes[0x38] == 2 && gravityGroups[1] == 4);
|
||||
bool invalidHurlRejected = false;
|
||||
try {
|
||||
gravityKernel.hurlItem(1, 0x2400, 0, 0, 0, 2, 10, gravityGroups);
|
||||
} catch (const std::out_of_range&) {
|
||||
invalidHurlRejected = true;
|
||||
}
|
||||
assert(invalidHurlRejected && gravityGroups[1] == 4);
|
||||
int gravityRuns = 0;
|
||||
auto countGravityRun = [](remorse::EntityDispatchEntryBase& process, void* context) {
|
||||
if (process.bytes[0] == 0x10 && process.bytes[1] == 0x06) {
|
||||
++*static_cast<int*>(context);
|
||||
}
|
||||
};
|
||||
gravityKernel.scanRunnableProcesses(1, countGravityRun, &gravityRuns, 30);
|
||||
assert(gravityRuns == 0);
|
||||
gravityKernel.scanRunnableProcesses(1, countGravityRun, &gravityRuns, 31);
|
||||
assert(gravityRuns == 1 && gravityKernel.itemHasProcess(0x100));
|
||||
remorse::StagedFixedMapItem fallingItem{};
|
||||
fallingItem.itemNumber = 0x100;
|
||||
fallingItem.data.x = 100;
|
||||
fallingItem.data.y = 100;
|
||||
fallingItem.data.z = 10;
|
||||
remorse::LiveFixedMapItems fallingItems({fallingItem});
|
||||
auto approveGravity = [](remorse::u16 itemNumber, const remorse::WorldPoint& from,
|
||||
const remorse::WorldPoint& to, void* context) {
|
||||
++*static_cast<int*>(context);
|
||||
return itemNumber == 0x100 && from.x == 100 && from.y == 100 && from.z == 10 &&
|
||||
to.x == 98 && to.y == 102 && to.z == 12;
|
||||
};
|
||||
int sweepCalls = 0;
|
||||
assert(!gravityKernel.runUnobstructedGravity(gravityId, fallingItems, 1, 31, nullptr, nullptr));
|
||||
assert(sweepCalls == 0 && fallingItems.findItem(0x100)->data.x == 100);
|
||||
auto rejectGravity = [](remorse::u16, const remorse::WorldPoint&, const remorse::WorldPoint&,
|
||||
void* context) {
|
||||
++*static_cast<int*>(context);
|
||||
return false;
|
||||
};
|
||||
assert(!gravityKernel.runUnobstructedGravity(gravityId, fallingItems, 1, 31,
|
||||
rejectGravity, &sweepCalls));
|
||||
assert(sweepCalls == 1 && fallingItems.findItem(0x100)->data.x == 100 &&
|
||||
gravityEntry->bytes[0x36] == 2 && (gravityEntry->bytes[0x19] & 0x10) == 0);
|
||||
assert(gravityKernel.runUnobstructedGravity(gravityId, fallingItems, 1, 31,
|
||||
approveGravity, &sweepCalls));
|
||||
assert(sweepCalls == 2 && fallingItems.findItem(0x100)->data.x == 98 &&
|
||||
fallingItems.findItem(0x100)->data.y == 102 && fallingItems.findItem(0x100)->data.z == 12);
|
||||
assert(gravityEntry->bytes[0x36] == 0 && gravityEntry->bytes[0x37] == 0 &&
|
||||
(gravityEntry->bytes[0x19] & 0x10) != 0 && gravityEntry->bytes[0x0e] == 4);
|
||||
assert(!gravityKernel.runUnobstructedGravity(gravityId, fallingItems, 1, 32,
|
||||
approveGravity, &sweepCalls) && sweepCalls == 2);
|
||||
remorse::ProcessKernel horizontalKernel;
|
||||
remorse::u16 horizontalGroups[32]{};
|
||||
for (int index = 0; index < 3; ++index) {
|
||||
horizontalKernel.createProcess(1, horizontalGroups);
|
||||
}
|
||||
const auto horizontalId = horizontalKernel.hurlItem(1, 0x100, 2, 0, 0, 2, 0, horizontalGroups);
|
||||
remorse::StagedFixedMapItem supportedItem = fallingItem;
|
||||
supportedItem.data.shape = 1;
|
||||
supportedItem.data.z = 72;
|
||||
supportedItem.itemNumber = 0x101;
|
||||
fallingItem.data.shape = 1;
|
||||
fallingItem.data.z = 80;
|
||||
remorse::LiveFixedMapItems horizontalItems({fallingItem, supportedItem});
|
||||
std::vector<remorse::ShapeTypeInfo> horizontalShapes(2);
|
||||
horizontalShapes[1].x = 1;
|
||||
horizontalShapes[1].y = 1;
|
||||
horizontalShapes[1].z = 1;
|
||||
horizontalKernel.scanRunnableProcesses(1, countGravityRun, &gravityRuns, 21);
|
||||
struct HorizontalSweep {
|
||||
remorse::ProcessKernel* kernel;
|
||||
int calls = 0;
|
||||
} horizontalSweep{&horizontalKernel};
|
||||
auto approveHorizontal = [](remorse::u16 itemNumber, const remorse::WorldPoint& from,
|
||||
const remorse::WorldPoint& to, void* context) {
|
||||
auto& state = *static_cast<HorizontalSweep*>(context);
|
||||
++state.calls;
|
||||
return itemNumber == 0x100 && from.x == 100 && from.z == 80 && to.x == 102 &&
|
||||
to.z == 80 && state.kernel->findProcessForItemAndType(0x101, 0xf1) != nullptr;
|
||||
};
|
||||
assert(!horizontalKernel.runUnobstructedGravity(horizontalId, horizontalItems, 1, 21,
|
||||
approveHorizontal, &horizontalSweep));
|
||||
assert(horizontalSweep.calls == 0 && horizontalKernel.processCount() == 4);
|
||||
auto rejectHorizontal = [](remorse::u16, const remorse::WorldPoint&,
|
||||
const remorse::WorldPoint&, void* context) {
|
||||
++static_cast<HorizontalSweep*>(context)->calls;
|
||||
return false;
|
||||
};
|
||||
assert(!horizontalKernel.runUnobstructedGravity(horizontalId, horizontalItems, 1, 21,
|
||||
rejectHorizontal, &horizontalSweep, &horizontalShapes, &horizontalGroups));
|
||||
assert(horizontalSweep.calls == 1 && horizontalItems.findItem(0x100)->data.x == 100 &&
|
||||
horizontalKernel.findProcessForItemAndType(0x101, 0xf1) != nullptr &&
|
||||
horizontalKernel.processCount() == 5);
|
||||
assert(horizontalKernel.runUnobstructedGravity(horizontalId, horizontalItems, 1, 21,
|
||||
approveHorizontal, &horizontalSweep, &horizontalShapes, &horizontalGroups));
|
||||
assert(horizontalSweep.calls == 2 && horizontalItems.findItem(0x100)->data.x == 102 &&
|
||||
horizontalKernel.processCount() == 6);
|
||||
assert(horizontalKernel.processAt(horizontalId)->bytes[0x36] == 0xfe &&
|
||||
horizontalKernel.processAt(horizontalId)->bytes[0x37] == 0xff);
|
||||
gravityKernel.terminateProcess(gravityId, gravityGroups);
|
||||
assert(gravityKernel.findProcessForItemAndType(0x100, 0x203) == nullptr);
|
||||
gravityKernel.clearTerminatedProcesses();
|
||||
assert(gravityKernel.processAt(gravityId) == nullptr && !gravityKernel.itemHasProcess(0x100));
|
||||
assert(gravityKernel.hurlItem(1, 0x100, 0, 0, 0, 2, 31, gravityGroups) == gravityId);
|
||||
remorse::ProcessKernel externalGravityKernel;
|
||||
remorse::u16 externalGravityGroups[32]{};
|
||||
for (int index = 0; index < 3; ++index) {
|
||||
externalGravityKernel.createProcess(1, externalGravityGroups);
|
||||
}
|
||||
auto* externalGravity = externalGravityKernel.createProcess(1, externalGravityGroups);
|
||||
externalGravityKernel.setProcessSourceType(*externalGravity, 0x101);
|
||||
externalGravityKernel.setProcessEventTypeChecked(*externalGravity, 0x203);
|
||||
bool unownedGravityRejected = false;
|
||||
try {
|
||||
externalGravityKernel.hurlItem(1, 0x101, 1, 0, 0, 2, 0, externalGravityGroups);
|
||||
} catch (const std::logic_error&) {
|
||||
unownedGravityRejected = true;
|
||||
}
|
||||
assert(unownedGravityRejected && externalGravityGroups[1] == 4);
|
||||
struct StandContext {
|
||||
remorse::u32 tick;
|
||||
bool visible;
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ int main()
|
|||
const auto typeFlagPath = remorse::resolveGameDataPath(*root, std::filesystem::path("STATIC") / "TYPEFLAG.DAT");
|
||||
const auto typeFlags = typeFlagPath ? remorse::loadTypeFlags(*typeFlagPath) : std::nullopt;
|
||||
assert(typeFlags && cachedItems->front().data.shape < typeFlags->size());
|
||||
const auto retailContained = remorse::stageContainedFixedMapItems(*retailMap, *typeFlags);
|
||||
assert(retailContained && retailContained->empty());
|
||||
const auto& originShape = (*typeFlags)[cachedItems->front().data.shape];
|
||||
auto origin = cachedItems->front();
|
||||
origin.data.z = 80;
|
||||
|
|
@ -49,6 +51,12 @@ int main()
|
|||
candidate.itemNumber = static_cast<remorse::u16>(origin.itemNumber + 1);
|
||||
candidate.data.z = static_cast<remorse::u8>(origin.data.z + (originShape.z == 0 && (originShape.flags & 1) == 0 ? 1 : originShape.z * 8));
|
||||
remorse::ShapeTypeInfo footprint{0, 0, 1, 1, 0, 0};
|
||||
assert(!remorse::itemFallStartsHurl(footprint));
|
||||
footprint.weight = 2;
|
||||
assert(remorse::itemFallStartsHurl(footprint));
|
||||
footprint.flags = 1;
|
||||
assert(!remorse::itemFallStartsHurl(footprint));
|
||||
footprint.flags = 0;
|
||||
assert(remorse::classifyItemFindZMatch(origin, originShape, candidate, footprint, 3) == 1);
|
||||
assert(remorse::classifyItemFindZMatch(origin, originShape, candidate, footprint, 2) == 0);
|
||||
candidate.data.z = 79;
|
||||
|
|
@ -62,6 +70,23 @@ int main()
|
|||
const auto retailSearchBlocks = remorse::itemFindBlockOrder(retailSearchArea);
|
||||
assert(!retailSearchBlocks.empty() && retailSearchBlocks.front() ==
|
||||
(retailSearchArea.minX >> 9) * 0x40 + (retailSearchArea.minY >> 9));
|
||||
const auto retailChains = remorse::buildStagedItemBlockChains(*cachedItems);
|
||||
assert(retailChains);
|
||||
const auto retailCandidates = remorse::itemFindCandidateOrder(retailSearchArea, *retailChains);
|
||||
std::size_t stagedItemsInAreaBlocks = 0;
|
||||
for (const auto& item : *cachedItems) {
|
||||
const auto block = (item.data.x >> 9) * 0x40 + (item.data.y >> 9);
|
||||
for (const auto searchBlock : retailSearchBlocks) {
|
||||
if (block == searchBlock) {
|
||||
++stagedItemsInAreaBlocks;
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(!retailCandidates.empty() && retailCandidates.size() == stagedItemsInAreaBlocks);
|
||||
const auto retailGrabCandidates = remorse::itemGrabSearchCandidates(cachedItems->front(), *cachedItems, *typeFlags);
|
||||
const auto retailGrabActions = remorse::planItemGrabActions(cachedItems->front(), *cachedItems, *typeFlags);
|
||||
assert(retailGrabCandidates && retailGrabCandidates->size() == 1);
|
||||
assert(retailGrabActions && retailGrabActions->empty());
|
||||
origin.data.x = 511;
|
||||
origin.data.y = 511;
|
||||
const auto crossingArea = remorse::itemFindAreaAroundItem(origin, footprint);
|
||||
|
|
@ -73,9 +98,163 @@ int main()
|
|||
const auto edgeArea = remorse::itemFindAreaAroundItem(origin, footprint);
|
||||
assert(edgeArea.minX == 0 && edgeArea.minY == 0);
|
||||
assert((remorse::itemFindBlockOrder(edgeArea) == std::vector<remorse::u16>{0}));
|
||||
std::vector<remorse::StagedFixedMapItem> blockItems(4);
|
||||
blockItems[0].itemNumber = 0x100;
|
||||
blockItems[0].data.x = 511;
|
||||
blockItems[0].data.y = 511;
|
||||
blockItems[1].itemNumber = 0x102;
|
||||
blockItems[1].data.x = 512;
|
||||
blockItems[1].data.y = 511;
|
||||
blockItems[2].itemNumber = 0x103;
|
||||
blockItems[2].data.x = 511;
|
||||
blockItems[2].data.y = 511;
|
||||
blockItems[3].itemNumber = 0x104;
|
||||
blockItems[3].data.x = 512;
|
||||
blockItems[3].data.y = 512;
|
||||
const auto chains = remorse::buildStagedItemBlockChains(blockItems);
|
||||
assert(chains && chains->heads[0] == 0x103 && chains->next[0x103] == 0x100);
|
||||
assert((remorse::itemFindCandidateOrder(crossingArea, *chains) ==
|
||||
std::vector<remorse::u16>{0x103, 0x100, 0x102, 0x104}));
|
||||
blockItems[3].itemNumber = 0x103;
|
||||
assert(!remorse::buildStagedItemBlockChains(blockItems));
|
||||
blockItems[3].itemNumber = 0x104;
|
||||
blockItems[3].data.x = 0x8000;
|
||||
assert(!remorse::buildStagedItemBlockChains(blockItems));
|
||||
blockItems[3].data.x = 512;
|
||||
std::vector<remorse::ShapeTypeInfo> searchShapes(2, footprint);
|
||||
auto searchOrigin = origin;
|
||||
searchOrigin.itemNumber = 0x105;
|
||||
searchOrigin.data.x = 511;
|
||||
searchOrigin.data.y = 511;
|
||||
searchOrigin.data.z = 80;
|
||||
searchOrigin.data.shape = 1;
|
||||
for (auto& item : blockItems) {
|
||||
item.data.shape = 1;
|
||||
}
|
||||
blockItems[0].data.z = 81;
|
||||
blockItems[1].data.z = 0;
|
||||
blockItems[2].data.z = 79;
|
||||
blockItems[3].data.z = 81;
|
||||
blockItems.push_back(searchOrigin);
|
||||
const auto zMatches = remorse::itemFindZMatches(searchOrigin, blockItems, searchShapes, 3);
|
||||
assert(zMatches && zMatches->size() == 3);
|
||||
assert((*zMatches)[0].itemNumber == 0x103 && (*zMatches)[0].matchType == 2);
|
||||
assert((*zMatches)[1].itemNumber == 0x100 && (*zMatches)[1].matchType == 1);
|
||||
assert((*zMatches)[2].itemNumber == 0x104 && (*zMatches)[2].matchType == 1);
|
||||
const auto topMatches = remorse::itemFindZMatches(searchOrigin, blockItems, searchShapes, 1);
|
||||
assert(topMatches && topMatches->size() == 2);
|
||||
blockItems[3].data.x = 768;
|
||||
searchShapes[1].x = 17;
|
||||
assert(remorse::classifyItemFindZMatch(searchOrigin, searchShapes[1],
|
||||
blockItems[3], searchShapes[1], 1) == 1);
|
||||
const auto grabCandidates = remorse::itemGrabSearchCandidates(searchOrigin, blockItems, searchShapes);
|
||||
assert(grabCandidates && grabCandidates->size() == 2);
|
||||
assert((*grabCandidates)[0].itemNumber == 0x103 && (*grabCandidates)[0].matchType == 2);
|
||||
assert((*grabCandidates)[1].itemNumber == 0x100 && (*grabCandidates)[1].matchType == 1);
|
||||
const auto grabActions = remorse::planItemGrabActions(searchOrigin, blockItems, searchShapes);
|
||||
assert(grabActions && grabActions->size() == 2);
|
||||
assert((*grabActions)[0].itemNumber == 0x103 &&
|
||||
(*grabActions)[0].kind == remorse::ItemGrabActionKind::CreateProcess);
|
||||
assert((*grabActions)[1].itemNumber == 0x100 &&
|
||||
(*grabActions)[1].kind == remorse::ItemGrabActionKind::Hurl);
|
||||
remorse::ProcessKernel grabKernel;
|
||||
remorse::u16 grabGroups[32]{};
|
||||
for (int index = 0; index < 3; ++index) {
|
||||
grabKernel.createProcess(1, grabGroups);
|
||||
}
|
||||
const auto dispatched = remorse::dispatchStagedItemGrab(searchOrigin, blockItems, searchShapes,
|
||||
grabKernel, grabGroups, 12);
|
||||
assert(dispatched && dispatched->size() == 2 && (*dispatched)[0] == 3 && (*dispatched)[1] == 4);
|
||||
assert(grabKernel.findProcessForItemAndType(0x103, 0xf1) == grabKernel.processAt(3));
|
||||
assert(grabKernel.findProcessForItemAndType(0x100, 0x203) == grabKernel.processAt(4));
|
||||
const auto repeated = remorse::dispatchStagedItemGrab(searchOrigin, blockItems, searchShapes,
|
||||
grabKernel, grabGroups, 13);
|
||||
assert(repeated && repeated->size() == 2 && (*repeated)[0] == 5 && (*repeated)[1] == 4);
|
||||
assert(grabGroups[1] == 6);
|
||||
remorse::LiveFixedMapItems liveItems(blockItems);
|
||||
remorse::ProcessKernel liveKernel;
|
||||
remorse::u16 liveGroups[32]{};
|
||||
for (int index = 0; index < 3; ++index) {
|
||||
liveKernel.createProcess(1, liveGroups);
|
||||
}
|
||||
assert(!liveItems.findItem(0x106) && !liveItems.moveItem(0x106, 0, 0, 0));
|
||||
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);
|
||||
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));
|
||||
const auto liveDispatched = liveItems.grabItem(0x105, searchShapes, liveKernel, liveGroups, 14);
|
||||
assert(liveDispatched && liveDispatched->size() == 1 && (*liveDispatched)[0] == 3);
|
||||
assert(liveKernel.findProcessForItemAndType(0x103, 0xf1) == liveKernel.processAt(3));
|
||||
assert(liveKernel.findProcessForItemAndType(0x100, 0x203) == nullptr);
|
||||
assert(liveItems.moveItem(0x100, 768, 511, 255));
|
||||
assert(liveItems.findItem(0x100)->data.z == 250);
|
||||
remorse::LiveFixedMapItems reorderedItems(blockItems);
|
||||
remorse::ProcessKernel reorderedKernel;
|
||||
remorse::u16 reorderedGroups[32]{};
|
||||
for (int index = 0; index < 3; ++index) {
|
||||
reorderedKernel.createProcess(1, reorderedGroups);
|
||||
}
|
||||
assert(reorderedItems.moveItem(0x100, 511, 511, 81));
|
||||
const auto reorderedGrab = reorderedItems.grabItem(0x105, searchShapes,
|
||||
reorderedKernel, reorderedGroups, 14);
|
||||
assert(reorderedGrab && reorderedGrab->size() == 2 && (*reorderedGrab)[0] == 3 &&
|
||||
(*reorderedGrab)[1] == 4);
|
||||
assert(reorderedKernel.findProcessForItemAndType(0x100, 0x203) == reorderedKernel.processAt(3));
|
||||
assert(reorderedKernel.findProcessForItemAndType(0x103, 0xf1) == reorderedKernel.processAt(4));
|
||||
remorse::LiveFixedMapItems insertedItems(blockItems);
|
||||
remorse::StagedFixedMapItem newItem = blockItems[2];
|
||||
newItem.itemNumber = 0x106;
|
||||
assert(!insertedItems.insertItem(blockItems[2]));
|
||||
newItem.data.x = 0x8000;
|
||||
assert(!insertedItems.insertItem(newItem));
|
||||
newItem.data.x = 511;
|
||||
assert(insertedItems.insertItem(newItem));
|
||||
assert(insertedItems.findItem(0x106)->data.x == 511);
|
||||
remorse::ProcessKernel insertedKernel;
|
||||
remorse::u16 insertedGroups[32]{};
|
||||
for (int index = 0; index < 3; ++index) {
|
||||
insertedKernel.createProcess(1, insertedGroups);
|
||||
}
|
||||
const auto insertedGrab = insertedItems.grabItem(0x105, searchShapes,
|
||||
insertedKernel, insertedGroups, 14);
|
||||
assert(insertedGrab && insertedGrab->size() == 3 && (*insertedGrab)[0] == 3);
|
||||
assert(insertedKernel.findProcessForItemAndType(0x106, 0xf1) == insertedKernel.processAt(3));
|
||||
remorse::LiveFixedMapItems movingItems(blockItems);
|
||||
remorse::ProcessKernel movingKernel;
|
||||
remorse::u16 movingGroups[32]{};
|
||||
for (int index = 0; index < 3; ++index) {
|
||||
movingKernel.createProcess(1, movingGroups);
|
||||
}
|
||||
const auto rejectedMove = movingItems.moveApprovedItem(0x105, 0x8000, 0, 0,
|
||||
searchShapes, movingKernel, movingGroups, 14);
|
||||
assert(!rejectedMove && movingItems.findItem(0x105)->data.x == 511 && movingKernel.processCount() == 3);
|
||||
const auto approvedMove = movingItems.moveApprovedItem(0x105, 768, 768, 80,
|
||||
searchShapes, movingKernel, movingGroups, 14);
|
||||
assert(approvedMove && approvedMove->size() == 2 && (*approvedMove)[0] == 3 && (*approvedMove)[1] == 4);
|
||||
assert(movingItems.findItem(0x105)->data.x == 768 && movingItems.findItem(0x105)->data.y == 768);
|
||||
const auto afterMoveGrab = movingItems.grabItem(0x105, searchShapes, movingKernel, movingGroups, 15);
|
||||
assert(afterMoveGrab && afterMoveGrab->empty());
|
||||
blockItems[0].itemNumber = 0x2400;
|
||||
const auto priorProcessCount = grabKernel.processCount();
|
||||
assert(!remorse::dispatchStagedItemGrab(searchOrigin, blockItems, searchShapes,
|
||||
grabKernel, grabGroups, 14));
|
||||
assert(grabKernel.processCount() == priorProcessCount);
|
||||
blockItems[0].itemNumber = 0x100;
|
||||
blockItems[2].data.flags |= 2;
|
||||
searchShapes[1].weight = 0;
|
||||
const auto blockedActions = remorse::planItemGrabActions(searchOrigin, blockItems, searchShapes);
|
||||
assert(blockedActions && blockedActions->empty());
|
||||
searchShapes[1].x = 1;
|
||||
searchOrigin.data.shape = 2;
|
||||
assert(!remorse::itemFindZMatches(searchOrigin, blockItems, searchShapes, 3));
|
||||
candidate.itemNumber = 0;
|
||||
assert(remorse::classifyItemFindZMatch(origin, originShape, candidate, footprint, 3) == 0);
|
||||
assert(cachedItems->front().recordIndex < retailMap->entries.size());
|
||||
const remorse::LiveFixedMapItems retailLiveItems(*cachedItems);
|
||||
assert(retailLiveItems.findItem(cachedItems->front().itemNumber)->recordIndex ==
|
||||
cachedItems->front().recordIndex);
|
||||
for (const auto& item : *cachedItems) {
|
||||
const auto& record = retailMap->entries[item.recordIndex];
|
||||
assert(record.shape != 0 && (record.flags & 8) == 0);
|
||||
|
|
@ -128,6 +307,27 @@ int main()
|
|||
assert((*stagedItems)[0].recordIndex == 1 && (*stagedItems)[0].itemNumber == 0x100);
|
||||
assert((*stagedItems)[1].recordIndex == 3 && (*stagedItems)[1].itemNumber == 0x102);
|
||||
assert((*stagedItems)[1].data.flags == 0);
|
||||
remorse::FixedMap containedMap;
|
||||
containedMap.index = 1;
|
||||
containedMap.entries.resize(5);
|
||||
for (auto& record : containedMap.entries) {
|
||||
record.shape = 1;
|
||||
}
|
||||
containedMap.entries[1].flags = 8;
|
||||
containedMap.entries[1].x = 2;
|
||||
containedMap.entries[2].flags = 8;
|
||||
containedMap.entries[2].x = 4;
|
||||
containedMap.entries[3].flags = 8;
|
||||
containedMap.entries[3].x = 2;
|
||||
std::vector<remorse::ShapeTypeInfo> containerShapes(2);
|
||||
containerShapes[1].family = 6;
|
||||
const auto contained = remorse::stageContainedFixedMapItems(containedMap, containerShapes);
|
||||
assert(contained && contained->size() == 3);
|
||||
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);
|
||||
containerShapes[1].family = 0;
|
||||
assert(!remorse::stageContainedFixedMapItems(containedMap, containerShapes));
|
||||
assert(remorse::itemGrabCanCreateProcess((*stagedItems)[0]));
|
||||
(*stagedItems)[0].data.flags |= 0x02;
|
||||
assert(!remorse::itemGrabCanCreateProcess((*stagedItems)[0]));
|
||||
|
|
|
|||
|
|
@ -15,6 +15,11 @@ int main()
|
|||
const auto infos = remorse::loadTypeFlags(*typeFlagPath);
|
||||
assert(infos.has_value());
|
||||
assert(infos->size() == 2048);
|
||||
const auto bytes = remorse::readBinaryFile(*typeFlagPath);
|
||||
assert(bytes && bytes->size() == infos->size() * 9);
|
||||
for (std::size_t index = 0; index < infos->size(); ++index) {
|
||||
assert((*infos)[index].weight == (*bytes)[index * 9 + 7]);
|
||||
}
|
||||
|
||||
bool foundGlobFamily = false;
|
||||
for (const remorse::ShapeTypeInfo& info : *infos) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue