Add extensive tests for animation, input handling, and map rendering
- Enhanced animation archive tests to validate frame metadata and start frame selection logic. - Introduced new tests for entity dispatch entry handling, including key event queuing and processing. - Added tests for fixed map item interactions, including glob egg hatching and item movement. - Expanded flex archive tests to cover teleport egg spawning and usecode event selection. - Implemented isometric controls tests to verify directional key handling and animation state changes. - Improved map renderer tests to ensure correct rendering of map previews and collision detection.
This commit is contained in:
parent
2e16b2d524
commit
e757bb33d0
20 changed files with 1247 additions and 142 deletions
|
|
@ -1,6 +1,8 @@
|
|||
#include "remorse/animation_archive.h"
|
||||
#include "remorse/collision.h"
|
||||
#include "remorse/entity_dispatch_entry.h"
|
||||
#include "remorse/fixed_map.h"
|
||||
#include "remorse/isometric_controls.h"
|
||||
#include "remorse/map_renderer.h"
|
||||
#include "remorse/type_flags.h"
|
||||
|
||||
|
|
@ -877,8 +879,139 @@ int main()
|
|||
assert(!remorse::KeyboardProcess::handleKeyEvent(*keyboard, 0x10, 0, keyboardEvent, lastEvent));
|
||||
keyboardEvent.character = 0x41;
|
||||
assert(remorse::KeyboardProcess::handleKeyEvent(*keyboard, 0x10, 0, keyboardEvent, lastEvent));
|
||||
remorse::ProcessKernel inputKernel;
|
||||
assert(!inputKernel.popPendingKeyEvent());
|
||||
for (remorse::u8 index = 0; index < 31; ++index) {
|
||||
remorse::KeyEvent queued{};
|
||||
queued.scanCode = index;
|
||||
assert(inputKernel.queuePendingKeyEvent(queued));
|
||||
}
|
||||
assert(inputKernel.pendingKeyEventCount() == 31);
|
||||
assert(!inputKernel.queuePendingKeyEvent({}));
|
||||
assert(inputKernel.pendingKeyEventOverflowed());
|
||||
for (remorse::u8 index = 0; index < 31; ++index) {
|
||||
const auto queued = inputKernel.popPendingKeyEvent();
|
||||
assert(queued && queued->scanCode == index);
|
||||
}
|
||||
assert(inputKernel.pendingKeyEventCount() == 0 && !inputKernel.pendingKeyEventOverflowed());
|
||||
remorse::KeyEvent wrapped{};
|
||||
wrapped.scanCode = 0x47;
|
||||
assert(inputKernel.queuePendingKeyEvent(wrapped));
|
||||
assert(inputKernel.popPendingKeyEvent()->scanCode == 0x47);
|
||||
remorse::u16 inputGroups[32]{};
|
||||
auto* inputKeyboard = inputKernel.createKeyboardProcess(1, inputGroups);
|
||||
auto* inputController = inputKernel.createControllerProcess(1, inputGroups);
|
||||
assert(inputController && inputController->base.bytes[0x00] == 0xa6 &&
|
||||
inputController->base.bytes[0x01] == 0x3a);
|
||||
assert(inputController->base.bytes[0x17] == 0x03 && inputController->extra[4] == 0x3c);
|
||||
assert(!inputKeyboard->extra[0]);
|
||||
assert(inputKernel.queuePendingKeyEvent(wrapped));
|
||||
wrapped.scanCode = 0x48;
|
||||
assert(inputKernel.queuePendingKeyEvent(wrapped));
|
||||
std::vector<remorse::u8> deliveredScans;
|
||||
inputKernel.dispatchPendingKeyEvents([](remorse::EntityDispatchEntryBase& process,
|
||||
remorse::u16 selector, remorse::u16 filter, remorse::KeyEvent& event, void* context) {
|
||||
assert(selector == 0x10 && filter == 0);
|
||||
assert(process.bytes[0x00] == 0xa6);
|
||||
static_cast<std::vector<remorse::u8>*>(context)->push_back(event.scanCode);
|
||||
}, &deliveredScans);
|
||||
assert((deliveredScans == std::vector<remorse::u8>{0x47, 0x48}));
|
||||
assert(inputKernel.pendingKeyEventCount() == 0);
|
||||
remorse::ControllerMovementState deliveredMovement;
|
||||
wrapped.scanCode = 0x48;
|
||||
wrapped.field8 = 1;
|
||||
assert(inputKernel.queuePendingKeyEvent(wrapped));
|
||||
inputKernel.dispatchPendingKeyEvents([](remorse::EntityDispatchEntryBase& process,
|
||||
remorse::u16 selector, remorse::u16 filter, remorse::KeyEvent& event, void* context) {
|
||||
assert(process.bytes[0] == 0xa6 && selector == 0x10 && filter == 0);
|
||||
static_cast<remorse::ControllerMovementState*>(context)->handleDirectionalKey(
|
||||
event.scanCode, event.modifiers, event.field8 != 0);
|
||||
}, &deliveredMovement);
|
||||
assert(deliveredMovement.request().animation == 1 && deliveredMovement.request().direction == 14);
|
||||
wrapped.field8 = 0;
|
||||
assert(inputKernel.queuePendingKeyEvent(wrapped));
|
||||
inputKernel.dispatchPendingKeyEvents([](remorse::EntityDispatchEntryBase&,
|
||||
remorse::u16, remorse::u16, remorse::KeyEvent& event, void* context) {
|
||||
static_cast<remorse::ControllerMovementState*>(context)->handleDirectionalKey(
|
||||
event.scanCode, event.modifiers, event.field8 != 0);
|
||||
}, &deliveredMovement);
|
||||
assert(deliveredMovement.request().animation == 0);
|
||||
assert(std::memcmp(&keyboardEvent, &lastEvent, sizeof(keyboardEvent)) == 0);
|
||||
assert(keyboard->extra[0] == 0x21);
|
||||
|
||||
remorse::ProcessKernel animationKernel;
|
||||
remorse::u16 animationGroups[32]{};
|
||||
for (int reservedSlot = 0; reservedSlot < 3; ++reservedSlot) {
|
||||
animationKernel.createProcess(1, animationGroups);
|
||||
}
|
||||
remorse::AnimationClip walking{};
|
||||
walking.header = {17, 4, 0, 0};
|
||||
walking.frameCount = 17;
|
||||
auto* animation = animationKernel.createAnimPrimitiveProcess(1, 1, 1, 6, walking, animationGroups);
|
||||
assert(animationKernel.processAt(3) == &animation->base);
|
||||
assert(animationKernel.allocationSizeAt(3) == 0x5b && animationGroups[1] == 4);
|
||||
assert(animationKernel.findProcessForItemAndType(1, 0xf0) == &animation->base);
|
||||
assert(animation->base.bytes[0] == 0x57 && animation->base.bytes[1] == 0x2a);
|
||||
assert(animation->base.bytes[0x16] == 0 && animation->base.bytes[0x17] == 0x08);
|
||||
assert(animation->extra[0] == 1 && animation->extra[4] == 1 && animation->extra[6] == 6);
|
||||
assert(animation->extra[7] == 17 && animation->extra[0x18] == 17 && animation->extra[0x19] == 4);
|
||||
remorse::LiveFixedMapItems animationItems({});
|
||||
assert(animationItems.initializeAvatar());
|
||||
assert(animationKernel.startAnimPrimitiveProcess(3, animationItems, walking));
|
||||
const auto* npcAnimation = animationItems.findNpcAnimation(1);
|
||||
assert(npcAnimation && npcAnimation->lastAnimation == 1 && npcAnimation->frame == 0);
|
||||
assert(!animationKernel.startAnimPrimitiveProcess(3, animationItems, walking));
|
||||
auto* repeatedWalk = animationKernel.createAnimPrimitiveProcess(1, 1, 1, 6, walking, animationGroups);
|
||||
assert(animationKernel.startAnimPrimitiveProcess(4, animationItems, walking));
|
||||
assert(repeatedWalk->base.bytes[0x3a] == 1 && animationItems.findNpcAnimation(1)->frame == 1);
|
||||
auto* turning = animationKernel.createAnimPrimitiveProcess(1, 1, 0, 6, walking, animationGroups);
|
||||
assert(animationKernel.startAnimPrimitiveProcess(5, animationItems, walking));
|
||||
assert(turning->base.bytes[0x3a] == 1 && animationItems.findNpcAnimation(1)->frame == 0);
|
||||
remorse::StagedFixedMapItem animationSpawn{};
|
||||
animationSpawn.data.x = 512;
|
||||
animationSpawn.data.y = 512;
|
||||
assert(animationItems.teleportAvatar(animationSpawn, 1));
|
||||
walking.frames.resize(17 * 8);
|
||||
auto& nextWalkFrame = walking.frames[3 * 17 + 1];
|
||||
nextWalkFrame.bytes[4] = 1;
|
||||
nextWalkFrame.bytes[5] = 2;
|
||||
std::vector<remorse::ShapeTypeInfo> animationShapes(2);
|
||||
animationShapes[1].x = animationShapes[1].y = animationShapes[1].z = 2;
|
||||
auto& movingNpc = *animationItems.editNpcAnimation(1);
|
||||
movingNpc.lastAnimation = 1;
|
||||
movingNpc.frame = 0;
|
||||
const auto animationArea = remorse::calculateFastAreaRange({512, 512, 0});
|
||||
assert(animationKernel.advanceGroundedAnimPrimitive(3, animationItems,
|
||||
walking, animationShapes, animationArea) == true);
|
||||
assert(animationItems.findItem(1)->data.x == 514 && animationItems.findItem(1)->data.y == 514);
|
||||
assert(movingNpc.frame == 1);
|
||||
nextWalkFrame.bytes[4] = 100;
|
||||
movingNpc.frame = 0;
|
||||
remorse::StagedFixedMapItem animationWall{};
|
||||
animationWall.itemNumber = 0x100;
|
||||
animationWall.data.shape = 2;
|
||||
animationWall.data.x = 650;
|
||||
animationWall.data.y = 650;
|
||||
animationShapes.push_back(animationShapes[1]);
|
||||
animationShapes[2].flags = 2;
|
||||
assert(animationItems.insertItem(animationWall));
|
||||
assert(animationKernel.advanceGroundedAnimPrimitive(3, animationItems,
|
||||
walking, animationShapes, animationArea) == false);
|
||||
assert(animationItems.findItem(1)->data.x == 514 && movingNpc.frame == 0);
|
||||
assert(animation->extra[0x0a] == 1);
|
||||
walking.header[1] = 5;
|
||||
nextWalkFrame.bytes[4] = 1;
|
||||
auto* twoStepWalk = animationKernel.createAnimPrimitiveProcess(1, 1, 1, 6, walking, animationGroups);
|
||||
assert(animationKernel.startAnimPrimitiveProcess(6, animationItems, walking));
|
||||
assert(movingNpc.frame == 8 && twoStepWalk->extra[7] == 17);
|
||||
movingNpc.frame = 16;
|
||||
assert(animationKernel.advanceGroundedAnimPrimitive(6, animationItems,
|
||||
walking, animationShapes, animationArea) == true);
|
||||
assert(movingNpc.frame == 1 && animationItems.findItem(1)->data.x == 516);
|
||||
twoStepWalk->base.bytes[0x18] |= 4;
|
||||
animationKernel.terminateProcess(6, animationGroups);
|
||||
assert(animationKernel.processAt(6) == nullptr && animationKernel.allocationSizeAt(6) == 0);
|
||||
assert(animationGroups[1] == 6 && animationKernel.itemHasProcess(1));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue