Enhance animation and control tests; improve rendering and shape loading validation

- Added tests for player animations in animation_archive_tests to ensure all animations are loaded correctly.
- Updated entity_dispatch_entry_tests to validate animation direction updates and added tests for sixteen-direction animations.
- Expanded isometric_controls_tests with comprehensive key event handling and action requests for various controller states.
- Improved map_renderer_tests by adding viewport rendering tests to compare unbounded and bounded views.
- Enhanced shape_archive_tests to validate shape frame loading and decoding consistency.
This commit is contained in:
Maddo 2026-10-07 00:18:08 +02:00
commit a76b071049
28 changed files with 1608 additions and 154 deletions

View file

@ -4,6 +4,7 @@
#include "remorse/shape_archive.h"
#include <cassert>
#include <array>
#include <filesystem>
namespace {
@ -100,6 +101,14 @@ int main()
assert(stand.has_value() && stand->frameCount > 0);
assert(walk.has_value() && walk->frameCount == 17);
assert(run.has_value() && run->frameCount == 12);
std::array<std::optional<remorse::AnimationClip>, 0x40> playerAnimations;
for (const remorse::u8 index : remorse::controllerAnimationIndices) {
playerAnimations[index] = remorse::loadAnimationClip(
*animationArchive, 1, index);
}
for (const remorse::u8 animation : remorse::controllerAnimationIndices) {
assert(playerAnimations[animation] && playerAnimations[animation]->frameCount != 0);
}
for (const remorse::AnimationClip* clip : {&*walk, &*run}) {
assert(clip->header[1] == 5);
for (remorse::u8 direction = 0; direction < 16; ++direction) {
@ -148,7 +157,10 @@ int main()
const auto playerFrames = remorse::loadShapeFrames(*shapeArchive, 1);
assert(playerFrames.has_value() && playerFrames->size() >= walk->frameCount);
std::vector<bool> referencedFrames(playerFrames->size(), false);
for (const remorse::AnimationClip* clip : {&*stand, &*walk, &*run}) {
for (const auto& clip : playerAnimations) {
if (!clip) {
continue;
}
for (remorse::u8 direction = 0; direction < 16; ++direction) {
for (remorse::u8 frame = 0; frame < clip->frameCount; ++frame) {
const auto metadata = remorse::getAnimationFrame(*clip, direction, frame);
@ -159,14 +171,13 @@ int main()
}
}
}
bool decodedReferencedFrame = false;
for (std::size_t frame = 0; frame < referencedFrames.size(); ++frame) {
if (referencedFrames[frame]) {
assert(remorse::decodeShapeFrame(*shapeArchive, 1, static_cast<remorse::u32>(frame)).has_value());
decodedReferencedFrame = true;
break;
assert(remorse::decodeShapeFrame((*playerFrames)[frame]).has_value());
}
}
assert(decodedReferencedFrame);
assert(std::any_of(referencedFrames.begin(), referencedFrames.end(), [](bool referenced) {
return referenced;
}));
return 0;
}

View file

@ -997,6 +997,10 @@ int main()
assert(animationKernel.startAnimPrimitiveProcess(3, animationItems, walking));
const auto* npcAnimation = animationItems.findNpcAnimation(1);
assert(npcAnimation && npcAnimation->lastAnimation == 1 && npcAnimation->frame == 0);
assert(animationKernel.updateAnimPrimitiveDirection(3, animationItems, 7) == 6);
assert(animation->extra[6] == 6 && npcAnimation->frame == 0 && npcAnimation->direction == 6);
assert(animationKernel.updateAnimPrimitiveDirection(3, animationItems, 0x11) == 8);
assert(animationKernel.updateAnimPrimitiveDirection(3, animationItems, 0x12) == 6);
assert(!animationKernel.startAnimPrimitiveProcess(3, animationItems, walking));
auto* repeatedWalk = animationKernel.createAnimPrimitiveProcess(1, 1, 1, 6, walking, animationGroups);
assert(animationKernel.startAnimPrimitiveProcess(4, animationItems, walking));
@ -1004,6 +1008,21 @@ int main()
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::ProcessKernel sixteenDirectionKernel;
remorse::u16 sixteenDirectionGroups[32]{};
for (int reservedSlot = 0; reservedSlot < 3; ++reservedSlot) {
sixteenDirectionKernel.createProcess(1, sixteenDirectionGroups);
}
auto sixteenWalking = walking;
sixteenWalking.header[3] |= 0x40;
auto* sixteenDirection = sixteenDirectionKernel.createAnimPrimitiveProcess(1, 1, 1, 6,
sixteenWalking, sixteenDirectionGroups);
remorse::LiveFixedMapItems sixteenItems({});
assert(sixteenItems.initializeAvatar());
assert(sixteenDirectionKernel.startAnimPrimitiveProcess(3, sixteenItems, sixteenWalking));
assert(sixteenDirectionKernel.updateAnimPrimitiveDirection(3, sixteenItems, 0x11) == 15);
assert(sixteenDirection->extra[6] == 15);
assert(sixteenDirectionKernel.updateAnimPrimitiveDirection(3, sixteenItems, 0x12) == 14);
remorse::StagedFixedMapItem animationSpawn{};
animationSpawn.data.x = 512;
animationSpawn.data.y = 512;
@ -1022,6 +1041,11 @@ int main()
walking, animationShapes, animationArea) == true);
assert(animationItems.findItem(1)->data.x == 514 && animationItems.findItem(1)->data.y == 514);
assert(movingNpc.frame == 1);
nextWalkFrame.bytes[5] = 0;
assert(animationKernel.advanceGroundedAnimPrimitive(3, animationItems,
walking, animationShapes, animationArea) == true);
assert(animationItems.findItem(1)->data.x == 514 && movingNpc.frame == 2);
nextWalkFrame.bytes[5] = 2;
nextWalkFrame.bytes[4] = 100;
movingNpc.frame = 0;
remorse::StagedFixedMapItem animationWall{};

View file

@ -9,12 +9,258 @@ int main()
assert(controller.request().animation == 0);
controller.handleDirectionalKey(0x48, 0, true);
assert(controller.request().animation == 1 && controller.request().direction == 14);
controller.handleKeyEvent(0x50, 0, 0, 1);
assert(controller.request().direction == 14);
controller.handleKeyEvent(0x48, 0x0a00, 1, 1);
const auto jump = controller.takeActionRequest();
assert(jump && jump->animation == 0x24 && jump->direction == 14 && jump->oneShot);
remorse::ControllerMovementState keypadKneelController;
keypadKneelController.handleKeyEvent(0x4c, 0, 1, 1, 0);
assert(!keypadKneelController.takeActionRequest());
keypadKneelController.handleKeyEvent(0x4c, 0, 1, 1, 1);
assert(keypadKneelController.takeActionRequest()->animation == 0x28);
keypadKneelController.handleKeyEvent(0x4c, 0, 1, 1, 1);
assert(keypadKneelController.takeActionRequest()->animation == 0x29);
remorse::ControllerMovementState ctrlDownKneelController;
ctrlDownKneelController.handleKeyEvent(0x50, 0x0100, 1, 1, 0);
assert(!ctrlDownKneelController.takeActionRequest());
ctrlDownKneelController.handleKeyEvent(0x50, 0x0100, 1, 1, 1);
assert(ctrlDownKneelController.takeActionRequest()->animation == 0x28);
ctrlDownKneelController.handleKeyEvent(0x50, 0x0100, 1, 1, 1);
assert(ctrlDownKneelController.takeActionRequest()->animation == 0x29);
remorse::ControllerMovementState commandController;
commandController.handleKeyEvent(0x39, 0, 1, 1, 1);
assert(commandController.takeCommandRequest()->command == remorse::ControllerCommand::FireWeapon);
commandController.handleKeyEvent(0x52, 0, 1, 1, 1);
assert(commandController.takeCommandRequest()->command == remorse::ControllerCommand::FireWeapon);
commandController.handleKeyEvent(0x52, 0x0100, 1, 1, 1, 0);
assert(commandController.takeCommandRequest()->command == remorse::ControllerCommand::FireWeapon);
commandController.handleKeyEvent(0x4a, 0, 1, 1, 1);
assert(commandController.takeCommandRequest()->command == remorse::ControllerCommand::SelectNextItem);
commandController.handleKeyEvent(0x37, 0, 1, 1, 1, 1);
assert(!commandController.takeCommandRequest());
commandController.handleKeyEvent(0x37, 0, 1, 1, 1, 0);
assert(commandController.takeCommandRequest()->command == remorse::ControllerCommand::CycleWeaponForward);
commandController.handleKeyEvent(0x4e, 0, 1, 1, 1);
assert(commandController.takeCommandRequest()->command == remorse::ControllerCommand::OpenInventory);
commandController.handleKeyEvent(0x53, 0x0100, 1, 1, 1, 0);
assert(commandController.takeCommandRequest()->command == remorse::ControllerCommand::OpenInventory);
commandController.handleKeyEvent(0x53, 0, 1, 1, 1, 1);
assert(!commandController.takeCommandRequest());
commandController.handleKeyEvent(0x53, 0, 1, 1, 1, 0);
assert(commandController.takeCommandRequest()->command == remorse::ControllerCommand::OpenInventory);
commandController.handleKeyEvent(0x39, 0, 1, 1, 0);
assert(!commandController.takeCommandRequest());
remorse::ControllerActorState restrictedCommandActor;
restrictedCommandActor.mapNumber = 0x40;
commandController.setActorState(restrictedCommandActor);
commandController.handleKeyEvent(0x39, 0, 1, 1, 1);
assert(!commandController.takeCommandRequest());
restrictedCommandActor.mapNumber = 1;
restrictedCommandActor.npcNumber = 2;
commandController.setActorState(restrictedCommandActor);
commandController.handleKeyEvent(0x4a, 0, 1, 1, 1);
assert(!commandController.takeCommandRequest());
remorse::ControllerMovementState altNumLockRight;
remorse::ControllerActorState altTurnActor;
altTurnActor.direction = 14;
altNumLockRight.setActorState(altTurnActor);
altNumLockRight.handleKeyEvent(0x4d, 0x0a20, 1, 1);
const auto altTurn = altNumLockRight.takeActionRequest();
assert(altTurn && altTurn->animation == 0x1d && altTurn->direction == 13);
remorse::ControllerMovementState jumpController;
jumpController.handleKeyEvent(0x35, 0, 1, 1);
const auto slashJump = jumpController.takeActionRequest();
assert(slashJump && slashJump->animation == 0x24 && slashJump->oneShot);
jumpController.handleKeyEvent(0x35, 0, 1, 0);
assert(!jumpController.takeActionRequest());
remorse::ControllerMovementState modifierReleaseController;
modifierReleaseController.handleKeyEvent(0x48, 0, 1, 1);
assert(modifierReleaseController.request().animation == 1);
modifierReleaseController.handleKeyEvent(0x1d, 0x0100, 1, 1);
modifierReleaseController.handleKeyEvent(0x48, 0x0100, 1, 0);
assert(modifierReleaseController.request().animation == 0);
remorse::ControllerMovementState combatTurnController;
remorse::ControllerActorState combatTurnActor;
combatTurnActor.avatarSomethingCombatty = true;
combatTurnActor.direction = 14;
combatTurnController.setActorState(combatTurnActor);
combatTurnController.handleKeyEvent(0x4b, 0, 1, 1);
const auto combatTurn = combatTurnController.takeActionRequest();
assert(combatTurn && combatTurn->animation == 4 && combatTurn->direction == 13);
combatTurnActor.kneeling = true;
combatTurnActor.direction = 13;
combatTurnController.setActorState(combatTurnActor);
combatTurnController.handleKeyEvent(0x4d, 0, 1, 1);
const auto kneelingCombatTurn = combatTurnController.takeActionRequest();
assert(kneelingCombatTurn && kneelingCombatTurn->animation == 0x2e && kneelingCombatTurn->direction == 14);
remorse::ControllerMovementState ctrlDiagonalController;
remorse::ControllerActorState ctrlDiagonalActor;
ctrlDiagonalActor.direction = 14;
ctrlDiagonalController.setActorState(ctrlDiagonalActor);
ctrlDiagonalController.handleKeyEvent(0x47, 0x0100, 1, 1);
const auto ctrlDiagonalLeft = ctrlDiagonalController.takeActionRequest();
assert(ctrlDiagonalLeft && ctrlDiagonalLeft->animation == 0x17 && ctrlDiagonalLeft->direction == 0);
ctrlDiagonalController.handleKeyEvent(0x49, 0x0100, 1, 1);
const auto ctrlDiagonalRight = ctrlDiagonalController.takeActionRequest();
assert(ctrlDiagonalRight && ctrlDiagonalRight->animation == 0x18 && ctrlDiagonalRight->direction == 12);
ctrlDiagonalController.handleKeyEvent(0x47, 0x0120, 1, 1);
assert(!ctrlDiagonalController.takeActionRequest());
modifierReleaseController.handleKeyEvent(0x48, 0x0100, 1, 1);
assert(modifierReleaseController.takeActionRequest()->animation == 0x3a);
modifierReleaseController.handleKeyEvent(0x48, 0x0100, 1, 0);
assert(modifierReleaseController.request().animation == 0);
controller.handleKeyEvent(0x4b, 0x0500, 1, 1);
const auto combatStep = controller.takeActionRequest();
assert(combatStep && combatStep->animation == 0x3d && combatStep->oneShot);
controller.handleKeyEvent(0x4c, 0x0500, 1, 1);
const auto crouch = controller.takeActionRequest();
assert(crouch && crouch->animation == 0x28);
controller.handleKeyEvent(0x4c, 0x0500, 1, 1);
assert(controller.takeActionRequest()->animation == 0x29);
remorse::ControllerMovementState numLockController;
numLockController.setFacingDirection(14);
numLockController.setTurnStep(2);
numLockController.handleKeyEvent(0x4d, 0x20, 1, 1);
assert(numLockController.request().animation == 0 && numLockController.request().direction == 0);
numLockController.setFacingDirection(0);
numLockController.handleKeyEvent(0x48, 0x21, 1, 1);
assert(numLockController.request().animation == 3 && numLockController.request().direction == 0);
numLockController.handleKeyEvent(0x50, 0x20, 1, 1);
assert(numLockController.request().animation == 2 && numLockController.request().direction == 0);
numLockController.handleKeyEvent(0x50, 0x20, 1, 0);
assert(numLockController.request().animation == 1 && numLockController.request().direction == 0);
remorse::ControllerMovementState gatedController;
remorse::ControllerActorState actorState;
actorState.controllerEnabled = false;
gatedController.setActorState(actorState);
gatedController.handleDirectionalKey(0x48, 0, true);
assert(gatedController.request().animation == 0);
actorState.controllerEnabled = true;
actorState.avatarInStasis = true;
gatedController.setActorState(actorState);
gatedController.handleDirectionalKey(0x48, 0, true);
assert(gatedController.request().animation == 0);
actorState.npcNumber = 2;
gatedController.setActorState(actorState);
gatedController.handleDirectionalKey(0x48, 0, true);
assert(gatedController.request().animation == 1);
assert(remorse::controllerAllowsInPlaceDirectionUpdate(0x30));
assert(!remorse::controllerAllowsInPlaceDirectionUpdate(0x28));
constexpr remorse::u8 nonCombatAnimations[] = {0, 1, 11, 16, 32, 55, 58, 59};
for (const remorse::u8 animation : nonCombatAnimations) {
assert(remorse::controllerLastAnimationIsNotCombat(animation));
}
assert(!remorse::controllerLastAnimationIsNotCombat(4));
assert(!remorse::controllerLastAnimationIsNotCombat(3));
assert(remorse::controllerLastAnimationIsRunningJumping(3));
assert(remorse::controllerLastAnimationIsRunningJumping(48));
assert(remorse::controllerLastAnimationIsRunningJumping(49));
assert(remorse::controllerLastAnimationIsRunningJumping(56));
assert(!remorse::controllerLastAnimationIsRunningJumping(34));
remorse::ControllerMovementState jumpKeyController;
jumpKeyController.handleKeyEvent(0x0f, 0, 1, 1, 1);
assert(jumpKeyController.takeActionRequest()->animation == 56);
remorse::ControllerActorState busyRunner;
busyRunner.busy = true;
busyRunner.lastAnimation = 3;
jumpKeyController.setActorState(busyRunner);
jumpKeyController.handleKeyEvent(0x24, 0, 1, 1, 1);
assert(jumpKeyController.takeActionRequest()->animation == 56);
busyRunner.lastAnimation = 56;
jumpKeyController.setActorState(busyRunner);
jumpKeyController.handleKeyEvent(0x0f, 0, 1, 1, 1);
assert(!jumpKeyController.takeActionRequest());
busyRunner.lastAnimation = 4;
jumpKeyController.setActorState(busyRunner);
jumpKeyController.handleKeyEvent(0x0f, 0, 1, 1, 1);
assert(!jumpKeyController.takeActionRequest());
remorse::ControllerMovementState busyTurnController;
actorState.npcNumber = 1;
actorState.avatarInStasis = false;
actorState.busy = true;
actorState.lastAnimation = 1;
busyTurnController.setActorState(actorState);
busyTurnController.handleKeyEvent(0x4d, 0x20, 1, 1);
const auto busyTurn = busyTurnController.request();
assert(busyTurn.updateDirectionInPlace && busyTurn.animation == 1 && busyTurn.direction == 0x11);
assert(busyTurnController.takeInPlaceDirectionUpdate() == 0x11);
actorState.lastAnimation = 0x28;
busyTurnController.setActorState(actorState);
busyTurnController.handleKeyEvent(0x4d, 0x20, 1, 1);
assert(!busyTurnController.takeInPlaceDirectionUpdate());
assert(busyTurnController.request().animation == 0 && busyTurnController.request().direction == 14);
remorse::ControllerMovementState clearedBusyTurnController;
actorState.lastAnimation = 1;
clearedBusyTurnController.setActorState(actorState);
clearedBusyTurnController.handleKeyEvent(0x4d, 0x20, 1, 1);
assert(clearedBusyTurnController.request().updateDirectionInPlace);
clearedBusyTurnController.clear();
assert(!clearedBusyTurnController.request().updateDirectionInPlace);
remorse::ControllerMovementState armedRunController;
actorState.busy = false;
actorState.activeWeapon = true;
actorState.mapNumber = 1;
actorState.direction = 14;
actorState.lastAnimation = 0;
armedRunController.setActorState(actorState);
armedRunController.handleKeyEvent(0x48, 0x01, 1, 1);
assert(armedRunController.request().animation == 0x22);
actorState.lastAnimation = 48;
armedRunController.setActorState(actorState);
assert(armedRunController.request().animation == 0x30);
remorse::ControllerMovementState unarmedRunController;
actorState.activeWeapon = false;
actorState.lastAnimation = 0;
unarmedRunController.setActorState(actorState);
unarmedRunController.handleKeyEvent(0x48, 0x01, 1, 1);
assert(unarmedRunController.request().animation == 0x22);
actorState.lastAnimation = 0x22;
unarmedRunController.setActorState(actorState);
assert(unarmedRunController.request().animation == 3);
remorse::ControllerMovementState combatControlController;
actorState.lastAnimationNotCombat = false;
actorState.kneeling = false;
actorState.npcNumber = 1;
combatControlController.setActorState(actorState);
combatControlController.handleKeyEvent(0x48, 0x0100, 1, 1);
assert(combatControlController.takeActionRequest()->animation == 0x0b);
remorse::ControllerMovementState kneelingControlController;
actorState.kneeling = true;
kneelingControlController.setActorState(actorState);
kneelingControlController.handleKeyEvent(0x48, 0x0100, 1, 1);
assert(kneelingControlController.takeActionRequest()->animation == 0x29);
remorse::ControllerMovementState nonAvatarControlController;
actorState.kneeling = false;
actorState.lastAnimationNotCombat = true;
actorState.npcNumber = 2;
nonAvatarControlController.setActorState(actorState);
nonAvatarControlController.handleKeyEvent(0x48, 0x0100, 1, 1);
assert(!nonAvatarControlController.takeActionRequest());
remorse::ControllerMovementState mapFortyController;
actorState.mapNumber = 0x40;
actorState.lastAnimation = 0;
actorState.direction = 14;
mapFortyController.setActorState(actorState);
mapFortyController.handleKeyEvent(0x48, 0x01, 1, 1);
assert(mapFortyController.request().animation == 0x26);
remorse::ControllerMovementState mapFortyContinuation;
actorState.lastAnimation = 38;
mapFortyContinuation.setActorState(actorState);
mapFortyContinuation.handleKeyEvent(0x48, 0x01, 1, 1);
assert(mapFortyContinuation.request().animation == 3);
remorse::ControllerMovementState mapFortyMisfacing;
actorState.lastAnimation = 0;
actorState.direction = 12;
mapFortyMisfacing.setActorState(actorState);
mapFortyMisfacing.handleKeyEvent(0x48, 0x01, 1, 1);
assert(mapFortyMisfacing.request().animation == 0);
controller.handleDirectionalKey(0x4d, 1, true);
assert(controller.request().animation == 3 && controller.request().direction == 2);
controller.handleDirectionalKey(0x4d, 1, false);
assert(controller.request().animation == 3 && controller.request().direction == 14);
assert(controller.request().animation == 0 && controller.request().direction == 2);
controller.handleDirectionalKey(0x48, 0, false);
assert(controller.request().animation == 0 && controller.request().direction == 14);
assert(controller.request().animation == 0 && controller.request().direction == 2);
controller.handleDirectionalKey(0x49, 0x20, true);
assert(controller.request().animation == 0);
controller.handleDirectionalKey(0x47, 0x40, true);

View file

@ -114,6 +114,22 @@ int main()
});
};
assert(liveBefore && samePixels(liveBefore->pixels, startingScene->pixels));
remorse::MapRenderOptions viewportOptions;
viewportOptions.mapIndex = 1;
viewportOptions.maxWidth = 2560;
viewportOptions.maxHeight = 1440;
viewportOptions.includeRoofs = true;
viewportOptions.viewCenter = spawn;
const auto unboundedViewport = cachedRenderer->render(viewportOptions, &liveSceneItems);
const remorse::s32 viewportRadius = 2560 + 1440 * 2 + 512;
viewportOptions.worldRect = remorse::WorldRect{
spawn.x - viewportRadius, spawn.y - viewportRadius,
spawn.x + viewportRadius, spawn.y + viewportRadius};
const auto boundedViewport = cachedRenderer->render(viewportOptions, &liveSceneItems);
assert(unboundedViewport && boundedViewport);
assert(samePixels(unboundedViewport->pixels, boundedViewport->pixels));
assert(unboundedViewport->coverage == boundedViewport->coverage);
assert(boundedViewport->renderItemCount < unboundedViewport->renderItemCount);
const auto playerFrame = remorse::decodeShapeFrame(cachedRenderer->shapes, 1, 0);
assert(playerFrame);
const remorse::MapRenderSprite playerSprite{spawn, 1, 0, false,

View file

@ -21,6 +21,10 @@ int main()
if (frame && !frame->pixels.empty()) {
assert(frame->frame.width > 0);
assert(frame->frame.height > 0);
const auto parsedFrames = remorse::loadShapeFrames(*archive, shape);
assert(parsedFrames && !parsedFrames->empty());
const auto decodedFromParsed = remorse::decodeShapeFrame(parsedFrames->front());
assert(decodedFromParsed && decodedFromParsed->pixels == frame->pixels);
decodedFrame = true;
break;
}