- 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.
76 lines
No EOL
4 KiB
C++
76 lines
No EOL
4 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.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);
|
|
controller.handleDirectionalKey(0x48, 0, false);
|
|
assert(controller.request().animation == 0 && controller.request().direction == 14);
|
|
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;
|
|
} |