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
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue