Add comprehensive tests for entity dispatch, file system, fixed map, flex archive, isometric controls, and crash setup

- Enhance `entity_dispatch_entry_tests.cpp` with additional assertions for event type checks, group ID increments, and error handling.
- Refactor `file_system_tests.cpp` to streamline probe execution and enhance output validation.
- Extend `fixed_map_tests.cpp` to cover retail map loading, item classification, and process creation scenarios.
- Introduce new checks in `flex_archive_tests.cpp` for usecode loading and event handling, ensuring robust validation of game data.
- Add tests in `isometric_controls_tests.cpp` for controller direction mapping based on scan codes.
- Implement `test_crash_setup.cpp` to initialize crash diagnostics for improved error handling during tests.
This commit is contained in:
Maddo 2026-09-26 15:36:11 +02:00
commit c346b0e1a7
17 changed files with 1207 additions and 92 deletions

View file

@ -14,6 +14,7 @@
#include "remorse/runtime.h"
#include "remorse/shape_archive.h"
#include "remorse/type_flags.h"
#include "remorse/usecode_archive.h"
#include <algorithm>
#include <cmath>
@ -37,6 +38,7 @@ constexpr remorse::u32 backingHeight = 1440;
constexpr int initialClientWidth = 1280;
constexpr int initialClientHeight = 760;
constexpr double simulationTickSeconds = 0.025;
constexpr remorse::s32 diagnosticItemRange = 48;
struct AppState {
remorse::GameDataRoot root;
@ -45,6 +47,13 @@ struct AppState {
remorse::u16 diagnosticGroupCounts[32]{};
remorse::StandProcessEntry* diagnosticStand = nullptr;
remorse::KeyboardProcessEntry* diagnosticKeyboard = nullptr;
std::vector<remorse::StagedFixedMapItem> stagedItems;
std::optional<remorse::StagedFixedMapItem> diagnosticItem;
remorse::u16 diagnosticItemProcessId = 0;
remorse::u16 diagnosticReleaseEventItem = 0;
std::string diagnosticReleaseClass;
std::size_t diagnosticReleaseBodyBytes = 0;
bool diagnosticItemCompleted = false;
remorse::u32 standWakeCount = 0;
remorse::u32 diagnosticKeyEvents = 0;
std::mutex sceneMutex;
@ -55,6 +64,9 @@ struct AppState {
std::vector<std::optional<remorse::DecodedShapeFrame>> playerFrames;
remorse::CollisionBody playerCollisionBody{};
std::vector<remorse::CollisionBody> collisionBodies;
std::vector<remorse::ShapeTypeInfo> shapeTypes;
std::optional<remorse::FlexArchive> usecodeArchive;
std::vector<remorse::u8> usecodeOwnerRows;
remorse::Palette256 playerPalette{};
std::vector<std::uint8_t> dibPixels;
std::vector<std::uint8_t> viewPixels;
@ -139,6 +151,7 @@ void loadSceneAsync(HWND window, AppState& state)
PostMessageW(window, sceneReadyMessage, 0, 0);
return;
}
const auto stagedItems = remorse::stageFixedMapItems(*map);
const auto shapeTypes = remorse::loadTypeFlags(*typeFlagsPath);
const auto globObjects = remorse::loadGlobObjects(*globPath);
@ -148,6 +161,11 @@ void loadSceneAsync(HWND window, AppState& state)
return;
}
auto collisionBodies = remorse::collectMapCollisionBodies(*map, *shapeTypes, *globObjects);
const auto usecodePath = remorse::resolveGameDataPath(
state.root, std::filesystem::path("USECODE") / "EUSECODE.FLX");
auto usecodeArchive = usecodePath ? remorse::loadFlexArchive(*usecodePath) : std::nullopt;
const auto usecodeOwnerRows = usecodeArchive
? remorse::loadUsecodeOwnerRows(*usecodeArchive) : std::nullopt;
const auto animationPath = remorse::resolveGameDataPath(
state.root, std::filesystem::path("STATIC") / "ANIM.DAT");
@ -246,6 +264,11 @@ void loadSceneAsync(HWND window, AppState& state)
state.playerWorld = spawn;
state.playerCollisionBody = remorse::makeCollisionBody(spawn, (*shapeTypes)[1]);
state.collisionBodies = std::move(collisionBodies);
state.shapeTypes = *shapeTypes;
state.usecodeArchive = std::move(usecodeArchive);
if (usecodeOwnerRows) {
state.usecodeOwnerRows = *usecodeOwnerRows;
}
state.minWorldX = minX;
state.minWorldY = minY;
state.maxWorldX = maxX;
@ -257,6 +280,9 @@ void loadSceneAsync(HWND window, AppState& state)
state.runAnimation = *runAnimation;
state.playerFrames = std::move(playerFrames);
state.playerPalette = *palette;
if (stagedItems) {
state.stagedItems = std::move(*stagedItems);
}
state.sceneLoaded = true;
}
} catch (const std::exception& error) {
@ -285,23 +311,23 @@ bool isKeyDown(int key)
std::optional<remorse::u8> readMovementDirection()
{
if (isKeyDown(VK_HOME) || isKeyDown(VK_NUMPAD7) || isKeyDown('Q')) return static_cast<remorse::u8>(12);
if (isKeyDown(VK_PRIOR) || isKeyDown(VK_NUMPAD9) || isKeyDown('E')) return static_cast<remorse::u8>(0);
if (isKeyDown(VK_END) || isKeyDown(VK_NUMPAD1) || isKeyDown('Z')) return static_cast<remorse::u8>(8);
if (isKeyDown(VK_NEXT) || isKeyDown(VK_NUMPAD3) || isKeyDown('C')) return static_cast<remorse::u8>(4);
if (isKeyDown(VK_HOME) || isKeyDown(VK_NUMPAD7) || isKeyDown('Q')) return remorse::controllerDirectionFromScan(0x47);
if (isKeyDown(VK_PRIOR) || isKeyDown(VK_NUMPAD9) || isKeyDown('E')) return remorse::controllerDirectionFromScan(0x49);
if (isKeyDown(VK_END) || isKeyDown(VK_NUMPAD1) || isKeyDown('Z')) return remorse::controllerDirectionFromScan(0x4f);
if (isKeyDown(VK_NEXT) || isKeyDown(VK_NUMPAD3) || isKeyDown('C')) return remorse::controllerDirectionFromScan(0x51);
const bool up = isKeyDown(VK_UP) || isKeyDown('W') || isKeyDown(VK_NUMPAD8);
const bool right = isKeyDown(VK_RIGHT) || isKeyDown('D') || isKeyDown(VK_NUMPAD6);
const bool down = isKeyDown(VK_DOWN) || isKeyDown('S') || isKeyDown(VK_NUMPAD2);
const bool left = isKeyDown(VK_LEFT) || isKeyDown('A') || isKeyDown(VK_NUMPAD4);
if (up && left) return static_cast<remorse::u8>(12);
if (up && right) return static_cast<remorse::u8>(0);
if (down && left) return static_cast<remorse::u8>(8);
if (down && right) return static_cast<remorse::u8>(4);
if (up) return static_cast<remorse::u8>(14);
if (right) return static_cast<remorse::u8>(2);
if (down) return static_cast<remorse::u8>(6);
if (left) return static_cast<remorse::u8>(10);
if (up && left) return remorse::controllerDirectionFromScan(0x47);
if (up && right) return remorse::controllerDirectionFromScan(0x49);
if (down && left) return remorse::controllerDirectionFromScan(0x4f);
if (down && right) return remorse::controllerDirectionFromScan(0x51);
if (up) return remorse::controllerDirectionFromScan(0x48);
if (right) return remorse::controllerDirectionFromScan(0x4d);
if (down) return remorse::controllerDirectionFromScan(0x50);
if (left) return remorse::controllerDirectionFromScan(0x4b);
return std::nullopt;
}
@ -488,7 +514,7 @@ void paintWindow(HWND window, AppState& state)
}
compositePlayer(device, state, viewWidth, viewHeight, sourceLeft, sourceTop, viewStride);
RECT hud{0, 0, viewWidth, 62};
RECT hud{0, 0, viewWidth, 80};
HBRUSH hudBrush = CreateSolidBrush(RGB(14, 24, 29));
FillRect(device, &hud, hudBrush);
DeleteObject(hudBrush);
@ -510,7 +536,7 @@ void paintWindow(HWND window, AppState& state)
HFONT hudFont = CreateFontW(-16, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, FALSE,
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, L"Consolas");
RECT labelBounds{20, 0, viewWidth - 12, 36};
RECT labelBounds{20, 0, viewWidth - 12, 30};
const int saved = SaveDC(device);
SetBkMode(device, TRANSPARENT);
SetTextColor(device, RGB(224, 229, 214));
@ -528,9 +554,27 @@ void paintWindow(HWND window, AppState& state)
: 0)
<< L" | WAKEUPS " << state.standWakeCount
<< L" | KEY EVENTS " << state.diagnosticKeyEvents;
RECT diagnosticsBounds{20, 36, viewWidth - 12, hud.bottom - 1};
RECT diagnosticsBounds{20, 30, viewWidth - 12, 54};
SetTextColor(device, RGB(74, 207, 184));
DrawTextW(device, diagnostics.str().c_str(), -1, &diagnosticsBounds, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
const auto nearbyItem = remorse::nearestStagedFixedMapItem(
state.stagedItems, state.playerWorld.x, state.playerWorld.y, diagnosticItemRange);
if (state.diagnosticItem || nearbyItem) {
const auto& displayItem = state.diagnosticItem ? state.diagnosticItem : nearbyItem;
std::wostringstream itemStatus;
itemStatus << L"MAP ITEM " << displayItem->itemNumber
<< L" | SHAPE " << displayItem->data.shape
<< L" | RELEASE REQUEST " << state.diagnosticReleaseEventItem
<< L" | " << (state.diagnosticReleaseBodyBytes != 0
? widen(state.diagnosticReleaseClass) + L" SCRIPT " + std::to_wstring(state.diagnosticReleaseBodyBytes) + L" BYTES (NOT RUN)"
: L"NO RELEASE SCRIPT")
<< L" | PROCESS " << (state.diagnosticItemCompleted ? L"DONE" :
state.diagnosticItemProcessId != 0 ? L"QUEUED" :
displayItem->itemNumber > remorse::ProcessKernel::maxTrackedItemNumber ? L"ITEM OUT OF RANGE" :
!remorse::itemGrabCanCreateProcess(*displayItem) ? L"ITEM FLAG BLOCKS" : L"F: TEST RELEASE");
RECT itemBounds{20, 54, viewWidth - 12, hud.bottom - 1};
DrawTextW(device, itemStatus.str().c_str(), -1, &itemBounds, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
}
RestoreDC(device, saved);
DeleteObject(hudFont);
@ -567,14 +611,38 @@ void updatePlayer(HWND window, AppState& state)
state.diagnosticKernel.deliverSystemTimerEvent();
const bool wasSleeping = (state.diagnosticStand->base.bytes[0x19] & 0x10) != 0;
const remorse::u32 previousSleepStart = standSleepStart(*state.diagnosticStand);
state.diagnosticKernel.scanRunnableProcesses(1, [](remorse::EntityDispatchEntryBase& entry, void* context) {
state.diagnosticKernel.runTimedSchedulerPass(state.diagnosticKernel.activeGroup(), [](remorse::EntityDispatchEntryBase& entry, void* context) {
auto& app = *static_cast<AppState*>(context);
if (&entry == &app.diagnosticStand->base) {
remorse::StandProcess::run(entry,
[](const remorse::EntityDispatchEntryBase&, void*) { return false; },
nullptr, app.diagnosticKernel.systemTimerTick());
} else if (entry.bytes[0] == 0x2f && entry.bytes[1] == 0x10) {
remorse::ItemProcess::run(entry, app.diagnosticKernel, app.diagnosticGroupCounts,
[](remorse::u16 itemNumber, remorse::u32 eventMask, remorse::u16 eventId, void* releaseContext) {
auto& app = *static_cast<AppState*>(releaseContext);
app.diagnosticReleaseEventItem = itemNumber;
if (app.diagnosticItem && app.usecodeArchive &&
app.diagnosticItem->data.shape < app.shapeTypes.size()) {
const auto& item = *app.diagnosticItem;
const remorse::UsecodeItemIdentity identity{item.itemNumber, item.data.shape,
item.data.flags, item.data.quality, app.shapeTypes[item.data.shape].family, false};
const remorse::UsecodeClassBases bases{0, 0x800, 0x900};
const auto eligible = remorse::selectEligibleUsecodeEvent(*app.usecodeArchive,
app.usecodeOwnerRows, identity, bases, eventMask, eventId);
if (eligible) {
app.diagnosticReleaseClass = eligible->className;
app.diagnosticReleaseBodyBytes = eligible->body.bytes.size();
}
}
}, &app);
}
}, &state, state.diagnosticKernel.systemTimerTick());
}, &state);
state.diagnosticKernel.refreshActiveGroup(state.diagnosticGroupCounts);
if (state.diagnosticItemProcessId != 0 &&
state.diagnosticKernel.processAt(state.diagnosticItemProcessId) == nullptr) {
state.diagnosticItemCompleted = true;
}
if (wasSleeping && standSleepStart(*state.diagnosticStand) != previousSleepStart) {
++state.standWakeCount;
}
@ -656,6 +724,26 @@ LRESULT CALLBACK windowProcedure(HWND window, UINT message, WPARAM wParam, LPARA
updatePlayer(window, *state);
}
return 0;
case WM_KEYDOWN:
if (wParam == 'F') {
std::lock_guard<std::mutex> lock(state->sceneMutex);
if (state->sceneLoaded && state->scene && !state->diagnosticItemCompleted &&
state->diagnosticItemProcessId == 0) {
state->diagnosticItem = remorse::nearestStagedFixedMapItem(
state->stagedItems, state->playerWorld.x, state->playerWorld.y, diagnosticItemRange);
}
if (state->diagnosticItem && state->diagnosticItemProcessId == 0 &&
state->diagnosticItem->itemNumber <= remorse::ProcessKernel::maxTrackedItemNumber &&
remorse::itemGrabCanCreateProcess(*state->diagnosticItem)) {
auto* itemProcess = state->diagnosticKernel.createItemProcess(
state->diagnosticKernel.activeGroup(), state->diagnosticItem->itemNumber,
state->diagnosticGroupCounts);
state->diagnosticItemProcessId = static_cast<remorse::u16>(
itemProcess->bytes[2] | (static_cast<remorse::u16>(itemProcess->bytes[3]) << 8));
InvalidateRect(window, nullptr, FALSE);
}
}
return 0;
case WM_CHAR:
if (wParam > 0 && wParam <= 0xff) {
remorse::KeyEvent lastEvent{};
@ -677,9 +765,10 @@ LRESULT CALLBACK windowProcedure(HWND window, UINT message, WPARAM wParam, LPARA
case WM_PAINT:
paintWindow(window, *state);
return 0;
case sceneReadyMessage:
case sceneReadyMessage: {
InvalidateRect(window, nullptr, FALSE);
return 0;
}
case WM_DESTROY:
KillTimer(window, timerId);
if (state->sceneThread.joinable()) {