- 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.
322 lines
No EOL
18 KiB
C++
322 lines
No EOL
18 KiB
C++
#include "remorse/isometric_controls.h"
|
|
#include "remorse/map_renderer.h"
|
|
|
|
#include <cassert>
|
|
|
|
int main()
|
|
{
|
|
remorse::ControllerMovementState controller;
|
|
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 == 0 && controller.request().direction == 2);
|
|
controller.handleDirectionalKey(0x48, 0, false);
|
|
assert(controller.request().animation == 0 && controller.request().direction == 2);
|
|
controller.handleDirectionalKey(0x49, 0x20, true);
|
|
assert(controller.request().animation == 0);
|
|
controller.handleDirectionalKey(0x47, 0x40, true);
|
|
assert(controller.request().animation == 3 && controller.request().direction == 12);
|
|
controller.clear();
|
|
assert(controller.request().animation == 0);
|
|
assert(remorse::controllerWalkRequested(0));
|
|
assert(!remorse::controllerWalkRequested(0x01));
|
|
assert(!remorse::controllerWalkRequested(0x02));
|
|
assert(!remorse::controllerWalkRequested(0x40));
|
|
assert(remorse::controllerWalkRequested(0x41));
|
|
assert(remorse::controllerWalkRequested(0x42));
|
|
constexpr remorse::u8 scans[] = {0x47, 0x48, 0x49, 0x4b, 0x4d, 0x4f, 0x50, 0x51};
|
|
constexpr remorse::u8 directions[] = {12, 14, 0, 10, 2, 8, 6, 4};
|
|
for (std::size_t index = 0; index < std::size(scans); ++index) {
|
|
assert(remorse::controllerDirectionFromScan(scans[index]) == directions[index]);
|
|
}
|
|
assert(!remorse::controllerDirectionFromScan(0x52));
|
|
constexpr remorse::s32 originX = 1024;
|
|
constexpr remorse::s32 originY = 2048;
|
|
const remorse::ScreenPoint origin = remorse::projectToScreen({originX, originY, 0});
|
|
|
|
const auto east = remorse::worldPositionAtScreenOffset(originX, originY, 1.0, 0.0);
|
|
const remorse::ScreenPoint eastProjection = remorse::projectToScreen({
|
|
static_cast<remorse::s32>(east.x), static_cast<remorse::s32>(east.y), 0});
|
|
assert(eastProjection.x - origin.x == 1);
|
|
assert(eastProjection.y - origin.y == 0);
|
|
|
|
const auto north = remorse::worldPositionAtScreenOffset(originX, originY, 0.0, -1.0);
|
|
const remorse::ScreenPoint northProjection = remorse::projectToScreen({
|
|
static_cast<remorse::s32>(north.x), static_cast<remorse::s32>(north.y), 0});
|
|
assert(northProjection.x - origin.x == 0);
|
|
assert(northProjection.y - origin.y == -1);
|
|
|
|
const auto west = remorse::worldPositionAtScreenOffset(originX, originY, -1.0, 0.0);
|
|
const remorse::ScreenPoint westProjection = remorse::projectToScreen({
|
|
static_cast<remorse::s32>(west.x), static_cast<remorse::s32>(west.y), 0});
|
|
assert(westProjection.x - origin.x == -1);
|
|
assert(westProjection.y - origin.y == 0);
|
|
|
|
const auto south = remorse::worldPositionAtScreenOffset(originX, originY, 0.0, 1.0);
|
|
const remorse::ScreenPoint southProjection = remorse::projectToScreen({
|
|
static_cast<remorse::s32>(south.x), static_cast<remorse::s32>(south.y), 0});
|
|
assert(southProjection.x - origin.x == 0);
|
|
assert(southProjection.y - origin.y == 1);
|
|
remorse::AnimationFrameMetadata forwardFrame{};
|
|
forwardFrame.bytes[4] = 6;
|
|
const auto forward = remorse::hostMovementStep(forwardFrame, 6, false);
|
|
assert(forward && forward->x > 0 && forward->y > 0);
|
|
remorse::AnimationFrameMetadata reverseFrame{};
|
|
reverseFrame.bytes[4] = 0xfe;
|
|
reverseFrame.bytes[5] = 3;
|
|
const auto authoredReverse = remorse::decodeAnimationDisplacement(reverseFrame, 6, false);
|
|
const auto hostReverse = remorse::hostMovementStep(reverseFrame, 6, false);
|
|
assert(authoredReverse && authoredReverse->x < 0 && authoredReverse->y < 0);
|
|
assert(hostReverse && hostReverse->x == 0 && hostReverse->y == 0);
|
|
assert(hostReverse->z == authoredReverse->z && hostReverse->onGround == authoredReverse->onGround);
|
|
return 0;
|
|
} |