Refactor usecode task management and enhance teleportation logic
- Improved the queueUsecodeTask function to streamline process termination and context management. - Added robust error handling for event context creation and memory writing. - Enhanced the loadSceneAsync function to better handle avatar teleportation, including a new teleporter process. - Expanded entity dispatch tests to cover movement and teleporter processes, ensuring correct behavior under various conditions. - Introduced new tests for usecode runtime memory allocation and context creation, validating edge cases and error handling. - Updated flex archive tests to ensure proper loading and unloading of usecode slot chunk caches.
This commit is contained in:
parent
8c23bb02c9
commit
0771c86043
12 changed files with 1091 additions and 253 deletions
|
|
@ -1050,5 +1050,101 @@ int main()
|
|||
assert(animationKernel.processAt(6) == nullptr && animationKernel.allocationSizeAt(6) == 0);
|
||||
assert(animationGroups[1] == 6 && animationKernel.itemHasProcess(1));
|
||||
|
||||
remorse::ProcessKernel movementKernel;
|
||||
remorse::u16 movementGroups[32]{};
|
||||
for (int reservedSlot = 0; reservedSlot < 3; ++reservedSlot) {
|
||||
movementKernel.createProcess(1, movementGroups);
|
||||
}
|
||||
assert(movementKernel.createSystemTimerProcess(1, movementGroups));
|
||||
assert(movementKernel.createKeyboardProcess(1, movementGroups));
|
||||
assert(movementKernel.createControllerProcess(1, movementGroups));
|
||||
remorse::KeyEvent movementKey{};
|
||||
movementKey.scanCode = 0x48;
|
||||
movementKey.field8 = 1;
|
||||
assert(movementKernel.queuePendingKeyEvent(movementKey));
|
||||
remorse::ControllerMovementState movementController;
|
||||
movementKernel.dispatchPendingKeyEvents([](remorse::EntityDispatchEntryBase& process,
|
||||
remorse::u16 selector, remorse::u16 filter, remorse::KeyEvent& event, void* context) {
|
||||
if (process.bytes[0] == 0xa6 && process.bytes[1] == 0x3a) {
|
||||
assert(selector == 0x10 && filter == 0);
|
||||
static_cast<remorse::ControllerMovementState*>(context)->handleDirectionalKey(
|
||||
event.scanCode, event.modifiers, event.field8 != 0);
|
||||
}
|
||||
}, &movementController);
|
||||
const auto movementRequest = movementController.request();
|
||||
assert(movementRequest.animation == 1 && movementRequest.direction == 14);
|
||||
|
||||
remorse::AnimationClip controllerWalk{};
|
||||
controllerWalk.header = {17, 4, 0, 0};
|
||||
controllerWalk.frameCount = 17;
|
||||
controllerWalk.frames.resize(17 * 8);
|
||||
auto& controllerStep = controllerWalk.frames[7 * 17 + 1];
|
||||
controllerStep.bytes[4] = 1;
|
||||
controllerStep.bytes[5] = 2;
|
||||
remorse::LiveFixedMapItems movementItems({});
|
||||
assert(movementItems.initializeAvatar());
|
||||
remorse::StagedFixedMapItem movementSpawn{};
|
||||
movementSpawn.data.x = 512;
|
||||
movementSpawn.data.y = 512;
|
||||
assert(movementItems.teleportAvatar(movementSpawn, 1));
|
||||
std::vector<remorse::ShapeTypeInfo> movementShapes(2);
|
||||
movementShapes[1].x = movementShapes[1].y = movementShapes[1].z = 2;
|
||||
auto* controllerAnimation = movementKernel.createAnimPrimitiveProcess(1, 1,
|
||||
movementRequest.animation, movementRequest.direction, controllerWalk, movementGroups);
|
||||
assert(controllerAnimation);
|
||||
const remorse::u16 controllerAnimationId = static_cast<remorse::u16>(
|
||||
controllerAnimation->base.bytes[2] | (static_cast<remorse::u16>(controllerAnimation->base.bytes[3]) << 8));
|
||||
assert(movementKernel.startAnimPrimitiveProcess(controllerAnimationId, movementItems, controllerWalk));
|
||||
struct ControllerTickContext {
|
||||
remorse::ProcessKernel* kernel;
|
||||
remorse::LiveFixedMapItems* items;
|
||||
const remorse::AnimationClip* clip;
|
||||
const std::vector<remorse::ShapeTypeInfo>* shapes;
|
||||
remorse::FastAreaRange fastArea;
|
||||
remorse::u16 processId;
|
||||
std::optional<bool> advanced;
|
||||
} controllerTick{&movementKernel, &movementItems, &controllerWalk, &movementShapes,
|
||||
remorse::calculateFastAreaRange({512, 512, 0}), controllerAnimationId};
|
||||
movementKernel.runTimedSchedulerPass(1, [](remorse::EntityDispatchEntryBase& process, void* context) {
|
||||
auto& tick = *static_cast<ControllerTickContext*>(context);
|
||||
if (&process == tick.kernel->processAt(tick.processId)) {
|
||||
tick.advanced = tick.kernel->advanceGroundedAnimPrimitive(tick.processId,
|
||||
*tick.items, *tick.clip, *tick.shapes, tick.fastArea);
|
||||
}
|
||||
}, &controllerTick);
|
||||
assert(controllerTick.advanced == true && movementKernel.itemHasProcess(1));
|
||||
assert(movementItems.findItem(1)->data.x == 510 && movementItems.findItem(1)->data.y == 510 &&
|
||||
movementItems.findNpcAnimation(1)->frame == 1);
|
||||
movementKey.field8 = 0;
|
||||
assert(movementKernel.queuePendingKeyEvent(movementKey));
|
||||
movementKernel.dispatchPendingKeyEvents([](remorse::EntityDispatchEntryBase& process,
|
||||
remorse::u16 selector, remorse::u16 filter, remorse::KeyEvent& event, void* context) {
|
||||
if (process.bytes[0] == 0xa6 && process.bytes[1] == 0x3a) {
|
||||
assert(selector == 0x10 && filter == 0);
|
||||
static_cast<remorse::ControllerMovementState*>(context)->handleDirectionalKey(
|
||||
event.scanCode, event.modifiers, event.field8 != 0);
|
||||
}
|
||||
}, &movementController);
|
||||
assert(movementController.request().animation == 0 && movementController.request().direction == 14);
|
||||
|
||||
remorse::ProcessKernel teleporterKernel;
|
||||
remorse::u16 teleporterGroups[32]{};
|
||||
for (int reservedSlot = 0; reservedSlot < 3; ++reservedSlot) {
|
||||
teleporterKernel.createProcess(1, teleporterGroups);
|
||||
}
|
||||
auto* teleporter = teleporterKernel.createTeleporterProcess(1, 1, 0x1e, teleporterGroups);
|
||||
const remorse::u16 teleporterProcessId = static_cast<remorse::u16>(
|
||||
teleporter->base.bytes[2] | (static_cast<remorse::u16>(teleporter->base.bytes[3]) << 8));
|
||||
assert(teleporterKernel.processAt(teleporterProcessId) == &teleporter->base &&
|
||||
teleporterKernel.allocationSizeAt(teleporterProcessId) == 0x36 &&
|
||||
std::strcmp(teleporterKernel.processNameAt(teleporterProcessId), "Teleporter") == 0);
|
||||
assert(teleporter->base.bytes[0] == 0x3a && teleporter->base.bytes[1] == 0x0f &&
|
||||
teleporter->base.bytes[0x32] == 1 && teleporter->base.bytes[0x33] == 0 &&
|
||||
teleporter->base.bytes[0x34] == 0x1e && teleporter->base.bytes[0x35] == 0);
|
||||
teleporter->base.bytes[0x18] |= 4;
|
||||
teleporterKernel.terminateProcess(teleporterProcessId, teleporterGroups);
|
||||
assert(teleporterKernel.processAt(teleporterProcessId) == nullptr &&
|
||||
teleporterKernel.allocationSizeAt(teleporterProcessId) == 0 && teleporterGroups[1] == 3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue