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:
Maddo 2026-09-27 11:48:14 +02:00
commit e757bb33d0
20 changed files with 1247 additions and 142 deletions

View file

@ -1,10 +1,14 @@
#include "remorse/collision.h"
#include "remorse/file_system.h"
#include "remorse/fixed_map.h"
#include "remorse/glob_archive.h"
#include "remorse/map_renderer.h"
#include "remorse/type_flags.h"
#include <algorithm>
#include <cassert>
#include <filesystem>
#include <utility>
int main()
{
@ -51,5 +55,100 @@ int main()
const remorse::ScreenPoint center = remorse::projectToScreen(*options.viewCenter);
assert(centeredImage->sourceLeft == center.x - static_cast<remorse::s32>(options.maxWidth / 2));
assert(centeredImage->sourceTop == center.y - static_cast<remorse::s32>(options.maxHeight / 2));
const auto typesPath = remorse::resolveGameDataPath(*root, std::filesystem::path("STATIC") / "TYPEFLAG.DAT");
const auto globPath = remorse::resolveGameDataPath(*root, std::filesystem::path("STATIC") / "GLOB.FLX");
assert(typesPath && globPath);
const auto shapeTypes = remorse::loadTypeFlags(*typesPath);
const auto globs = remorse::loadGlobObjects(*globPath);
assert(shapeTypes && shapeTypes->size() > 1 && globs);
const auto stagedItems = remorse::stageFixedMapItems(*fixedMap);
assert(stagedItems);
const auto startingEgg = remorse::findTeleportEgg(*stagedItems, *shapeTypes, 0x1e);
assert(startingEgg && startingEgg->itemNumber >= 0x100);
assert((startingEgg->data.quality & 0xff) == 0x1e && startingEgg->data.frame == 1);
assert(startingEgg->data.x > 0 && startingEgg->data.y > 0);
assert(startingEgg->data.x * 2 == fixedMap->entries[startingEgg->recordIndex].x);
assert(startingEgg->data.y * 2 == fixedMap->entries[startingEgg->recordIndex].y);
const auto obstacles = remorse::collectMapCollisionBodies(*fixedMap, *shapeTypes, *globs);
const remorse::WorldPoint spawn{startingEgg->data.x * 2, startingEgg->data.y * 2, startingEgg->data.z};
options.maxWidth = 320;
options.maxHeight = 200;
options.viewCenter = spawn;
const auto startingScene = remorse::renderMapPreview(*root, options);
assert(startingScene && startingScene->paintedItemCount > 0);
remorse::LiveFixedMapItems liveSceneItems(*stagedItems);
auto cachedRenderer = remorse::loadMapSceneRenderer(*root, 1);
assert(cachedRenderer);
const auto liveBefore = cachedRenderer->render(options, &liveSceneItems);
const auto samePixels = [](const auto& left, const auto& right) {
return left.size() == right.size() && std::equal(left.begin(), left.end(), right.begin(),
[](const auto& lhs, const auto& rhs) {
return lhs.red == rhs.red && lhs.green == rhs.green && lhs.blue == rhs.blue;
});
};
assert(liveBefore && samePixels(liveBefore->pixels, startingScene->pixels));
const remorse::s32 redrawRadius = static_cast<remorse::s32>(
options.maxWidth + options.maxHeight * 2 + 512);
options.worldRect = remorse::WorldRect{spawn.x - redrawRadius, spawn.y - redrawRadius,
spawn.x + redrawRadius, spawn.y + redrawRadius};
const auto boundedScene = cachedRenderer->render(options, &liveSceneItems);
assert(boundedScene && samePixels(boundedScene->pixels, liveBefore->pixels));
options.worldRect.reset();
const auto nearEgg = std::find_if(stagedItems->begin(), stagedItems->end(), [&](const auto& item) {
return item.data.shape < shapeTypes->size() &&
(*shapeTypes)[item.data.shape].family == 3 && item.data.quality != 0 &&
std::any_of(globs->begin(), globs->end(), [&](const auto& object) {
return object.index == item.data.quality;
});
});
assert(nearEgg != stagedItems->end());
{
options.viewCenter = remorse::WorldPoint{
nearEgg->data.x * 2, nearEgg->data.y * 2, nearEgg->data.z};
const auto unhatchedScene = cachedRenderer->render(options, &liveSceneItems);
assert(unhatchedScene);
const auto glob = std::find_if(globs->begin(), globs->end(), [&](const auto& object) {
return object.index == nearEgg->data.quality;
});
assert(glob != globs->end());
const auto childIds = liveSceneItems.hatchGlobEgg(nearEgg->itemNumber, *glob, *shapeTypes);
assert(childIds && childIds->size() == glob->entries.size());
const auto hatchedScene = cachedRenderer->render(options, &liveSceneItems);
assert(hatchedScene && samePixels(hatchedScene->pixels, unhatchedScene->pixels));
for (const remorse::u16 childId : *childIds) {
const auto* child = liveSceneItems.findItem(childId);
assert(child && liveSceneItems.moveItem(childId,
static_cast<remorse::u16>(child->data.x + 512),
static_cast<remorse::u16>(child->data.y + 512), child->data.z));
}
const auto movedScene = cachedRenderer->render(options, &liveSceneItems);
assert(movedScene && !samePixels(movedScene->pixels, hatchedScene->pixels));
}
options.viewCenter = spawn;
auto visibleItem = std::find_if(stagedItems->begin(), stagedItems->end(), [&](const auto& item) {
if (item.data.shape >= shapeTypes->size() || (item.data.flags & 0x10) != 0 ||
((*shapeTypes)[item.data.shape].flags & 0x400) != 0) {
return false;
}
const auto family = (*shapeTypes)[item.data.shape].family;
if (family == 3 || family == 4 || family == 7 || family == 8) {
return false;
}
return true;
});
assert(visibleItem != stagedItems->end());
assert(liveSceneItems.moveItem(visibleItem->itemNumber, startingEgg->data.x,
startingEgg->data.y, 16));
const auto liveAfter = cachedRenderer->render(options, &liveSceneItems);
assert(liveAfter && !samePixels(liveAfter->pixels, liveBefore->pixels));
assert(!cachedRenderer->decodedFrames.empty());
const auto actor = remorse::makeCollisionBody(spawn, (*shapeTypes)[1]);
bool canLeaveSpawn = false;
for (const auto [deltaX, deltaY] : {std::pair{32, 0}, {0, 32}, {-32, 0}, {0, -32}}) {
canLeaveSpawn |= remorse::canMoveCollisionBody(actor,
{spawn.x + deltaX, spawn.y + deltaY, spawn.z}, obstacles);
}
assert(canLeaveSpawn);
return 0;
}