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

@ -9,6 +9,7 @@
#include <algorithm>
#include <fstream>
#include <map>
#include <unordered_map>
namespace remorse {
namespace {
@ -71,16 +72,6 @@ RgbColor scalePaletteColor(const RgbColor& color)
return scaled;
}
std::optional<GlobObject> findGlobObject(const std::vector<GlobObject>& globs, u32 index)
{
for (const GlobObject& object : globs) {
if (object.index == index) {
return object;
}
}
return std::nullopt;
}
std::vector<SceneItem> collectSceneItems(
const FixedMap& fixedMap,
const std::vector<ShapeTypeInfo>& typeFlags,
@ -88,6 +79,12 @@ std::vector<SceneItem> collectSceneItems(
const MapRenderOptions& options,
const LiveFixedMapItems* liveItems)
{
std::unordered_map<u32, const GlobObject*> globsByIndex;
globsByIndex.reserve(globs.size());
for (const GlobObject& glob : globs) {
globsByIndex.try_emplace(glob.index, &glob);
}
std::vector<SceneItem> pending;
pending.reserve(fixedMap.entries.size());
std::vector<const StagedFixedMapItem*> liveByRecord;
@ -145,9 +142,9 @@ std::vector<SceneItem> collectSceneItems(
const auto* stagedEgg = liveByRecord.empty() || index >= liveByRecord.size()
? nullptr : liveByRecord[index];
const auto glob = stagedEgg && liveItems->isGlobHatched(stagedEgg->itemNumber)
? std::nullopt : findGlobObject(globs, item.quality);
if (glob) {
for (const GlobObjectEntry& entry : glob->entries) {
? globsByIndex.end() : globsByIndex.find(item.quality);
if (glob != globsByIndex.end()) {
for (const GlobObjectEntry& entry : glob->second->entries) {
pending.push_back(SceneItem{
(item.x & globCoordMask) + (static_cast<s32>(entry.x) << globCoordShift) + globCoordOffset,
(item.y & globCoordMask) + (static_cast<s32>(entry.y) << globCoordShift) + globCoordOffset,
@ -184,6 +181,7 @@ s32 screenY(const SceneItem& item)
const DecodedShapeFrame* cachedDecode(
const ShapeArchive& archive,
std::map<u32, std::vector<ShapeFrame>>& parsedFrames,
std::map<std::pair<u32, u32>, DecodedShapeFrame>& cache,
u32 shape,
u32 frame)
@ -193,7 +191,18 @@ const DecodedShapeFrame* cachedDecode(
if (found != cache.end()) {
return &found->second;
}
const auto decoded = decodeShapeFrame(archive, shape, frame);
auto parsed = parsedFrames.find(shape);
if (parsed == parsedFrames.end()) {
auto frames = loadShapeFrames(archive, shape);
if (!frames) {
return nullptr;
}
parsed = parsedFrames.emplace(shape, std::move(*frames)).first;
}
if (frame >= parsed->second.size()) {
return nullptr;
}
const auto decoded = decodeShapeFrame(parsed->second[frame]);
if (!decoded) {
return nullptr;
}
@ -203,6 +212,7 @@ const DecodedShapeFrame* cachedDecode(
std::vector<RenderNode> prepareRenderNodes(
const std::vector<SceneItem>& items,
const ShapeArchive& shapeArchive,
std::map<u32, std::vector<ShapeFrame>>& parsedFrames,
const std::vector<ShapeTypeInfo>& typeFlags,
std::map<std::pair<u32, u32>, DecodedShapeFrame>& cache)
{
@ -212,7 +222,8 @@ std::vector<RenderNode> prepareRenderNodes(
sortItems.reserve(items.size());
for (const SceneItem& item : items) {
const auto* decoded = item.decodedOverride != nullptr
? item.decodedOverride : cachedDecode(shapeArchive, cache, item.shape, item.frame);
? item.decodedOverride : cachedDecode(
shapeArchive, parsedFrames, cache, item.shape, item.frame);
if (!decoded) {
continue;
}
@ -371,7 +382,8 @@ std::optional<RenderedMapImage> MapSceneRenderer::render(const MapRenderOptions&
items.push_back(sceneSprite);
}
}
auto nodes = prepareRenderNodes(items, shapes, typeFlags, decodedFrames);
std::map<u32, std::vector<ShapeFrame>> parsedFrames;
auto nodes = prepareRenderNodes(items, shapes, parsedFrames, typeFlags, decodedFrames);
if (nodes.empty()) {
return std::nullopt;
}