Add comprehensive tests for collision detection, entity dispatch, file system, isometric controls, map rendering, and sorting

- Implemented collision tests to verify overlap and movement logic for collision bodies.
- Enhanced entity dispatch entry tests to cover initialization, group ID management, and process handling.
- Expanded file system tests to include crash diagnostics and ensure proper game data root detection.
- Created isometric controls tests to validate movement requests and screen projection calculations.
- Added map renderer tests to check fixed map loading and rendering functionality.
- Introduced map sorter tests to confirm correct rendering order for various items.
This commit is contained in:
Maddo 2026-09-25 21:41:20 +02:00
commit 202679f857
27 changed files with 3530 additions and 81 deletions

View file

@ -2,6 +2,7 @@
#include "remorse/fixed_map.h"
#include "remorse/glob_archive.h"
#include "remorse/detail/map_sorter.h"
#include "remorse/shape_archive.h"
#include "remorse/type_flags.h"
@ -14,7 +15,12 @@ namespace {
constexpr u16 flagInvisible = 0x0010;
constexpr u16 flagFlipped = 0x0020;
constexpr u32 siSolid = 0x0002;
constexpr u32 siLand = 0x0008;
constexpr u32 siOccl = 0x0010;
constexpr u32 siDraw = 0x0100;
constexpr u32 siRoof = 0x0400;
constexpr u32 siTranslucent = 0x0800;
constexpr s32 globCoordMask = ~0x3ff;
constexpr s32 globCoordShift = 2;
constexpr s32 globCoordOffset = 2;
@ -139,12 +145,12 @@ std::vector<SceneItem> collectSceneItems(
s32 screenX(const SceneItem& item)
{
return (item.x - item.y) / 4;
return projectToScreen(WorldPoint{item.x, item.y, item.z}).x;
}
s32 screenY(const SceneItem& item)
{
return (item.x + item.y) / 8 - item.z;
return projectToScreen(WorldPoint{item.x, item.y, item.z}).y;
}
std::optional<DecodedShapeFrame> cachedDecode(
@ -166,10 +172,16 @@ std::optional<DecodedShapeFrame> cachedDecode(
return decoded;
}
std::vector<RenderNode> prepareRenderNodes(const std::vector<SceneItem>& items, const ShapeArchive& shapeArchive)
std::vector<RenderNode> prepareRenderNodes(
const std::vector<SceneItem>& items,
const ShapeArchive& shapeArchive,
const std::vector<ShapeTypeInfo>& typeFlags)
{
std::map<std::pair<u32, u32>, DecodedShapeFrame> cache;
std::vector<RenderNode> nodes;
std::vector<detail::RenderSortItem> sortItems;
nodes.reserve(items.size());
sortItems.reserve(items.size());
for (const SceneItem& item : items) {
const auto decoded = cachedDecode(shapeArchive, cache, item.shape, item.frame);
if (!decoded) {
@ -188,24 +200,52 @@ std::vector<RenderNode> prepareRenderNodes(const std::vector<SceneItem>& items,
node.top = bottomY - node.decoded.frame.yOffset;
node.right = node.left + static_cast<s32>(node.decoded.frame.width);
node.bottom = node.top + static_cast<s32>(node.decoded.frame.height);
const ShapeTypeInfo& info = typeFlags[item.shape];
const s32 xDimension = static_cast<s32>(flipped ? info.y : info.x) * 32;
const s32 yDimension = static_cast<s32>(flipped ? info.x : info.y) * 32;
const s32 zDimension = static_cast<s32>(info.z) * 8;
detail::RenderSortItem sortItem;
sortItem.left = node.left;
sortItem.top = node.top;
sortItem.right = node.right;
sortItem.bottom = node.bottom;
sortItem.x = item.x;
sortItem.xLeft = item.x - xDimension;
sortItem.y = item.y;
sortItem.yFar = item.y - yDimension;
sortItem.z = item.z;
sortItem.zTop = item.z + zDimension;
sortItem.sxLeft = sortItem.xLeft / 4 - item.y / 4;
sortItem.sxRight = item.x / 4 - sortItem.yFar / 4;
sortItem.sxTop = sortItem.xLeft / 4 - sortItem.yFar / 4;
sortItem.syTop = sortItem.xLeft / 8 + sortItem.yFar / 8 - sortItem.zTop;
sortItem.sxBottom = bottomX;
sortItem.syBottom = bottomY;
sortItem.shape = item.shape;
sortItem.frame = item.frame;
sortItem.bigFlatSquare = xDimension == yDimension && xDimension >= 128;
sortItem.flat = zDimension == 0;
sortItem.translucent = (info.flags & siTranslucent) != 0;
sortItem.animated = info.animationType != 0;
sortItem.occludes = (info.flags & siOccl) != 0 && !sortItem.translucent &&
(item.flags & flagInvisible) == 0;
sortItem.solid = (info.flags & siSolid) != 0;
sortItem.draw = (info.flags & siDraw) != 0;
sortItem.roof = (info.flags & siRoof) != 0;
sortItem.land = (info.flags & siLand) != 0;
sortItem.inventoryItem = info.family == 13;
nodes.push_back(node);
sortItems.push_back(sortItem);
}
std::sort(nodes.begin(), nodes.end(), [](const RenderNode& left, const RenderNode& right) {
const s32 leftKey = left.item.x + left.item.y;
const s32 rightKey = right.item.x + right.item.y;
if (leftKey != rightKey) {
return leftKey < rightKey;
}
if (left.item.z != right.item.z) {
return left.item.z < right.item.z;
}
if (left.item.y != right.item.y) {
return left.item.y < right.item.y;
}
return left.item.x < right.item.x;
});
return nodes;
const std::vector<std::size_t> order = detail::resolveRenderOrder(sortItems);
std::vector<RenderNode> orderedNodes;
orderedNodes.reserve(order.size());
for (const std::size_t index : order) {
orderedNodes.push_back(std::move(nodes[index]));
}
return orderedNodes;
}
void paintNode(RenderedMapImage& image, const RenderNode& node, const Palette256& palette)
@ -248,6 +288,11 @@ void writeLe32(std::ofstream& output, u32 value)
} // namespace
ScreenPoint projectToScreen(const WorldPoint& point)
{
return ScreenPoint{(point.x - point.y) / 4, (point.x + point.y) / 8 - point.z};
}
std::optional<RenderedMapImage> renderMapPreview(const GameDataRoot& root, const MapRenderOptions& options)
{
const auto fixedPath = resolveGameDataPath(root, std::filesystem::path("STATIC") / "FIXED.DAT");
@ -270,7 +315,7 @@ std::optional<RenderedMapImage> renderMapPreview(const GameDataRoot& root, const
}
const auto items = collectSceneItems(*fixedMap, *typeFlags, *globs, options);
auto nodes = prepareRenderNodes(items, *shapeArchive);
auto nodes = prepareRenderNodes(items, *shapeArchive, *typeFlags);
if (nodes.empty()) {
return std::nullopt;
}
@ -290,12 +335,22 @@ std::optional<RenderedMapImage> renderMapPreview(const GameDataRoot& root, const
image.rawItemCount = static_cast<u32>(fixedMap->entries.size());
image.renderItemCount = static_cast<u32>(items.size());
image.decodedItemCount = static_cast<u32>(nodes.size());
image.sourceLeft = nodes[0].left;
image.sourceTop = nodes[0].top;
image.fullWidth = maxRight - minLeft;
image.fullHeight = maxBottom - minTop;
image.width = std::min(options.maxWidth, static_cast<u32>(std::max<s32>(1, image.fullWidth)));
image.height = std::min(options.maxHeight, static_cast<u32>(std::max<s32>(1, image.fullHeight)));
image.width = options.viewCenter
? options.maxWidth
: std::min(options.maxWidth, static_cast<u32>(std::max<s32>(1, image.fullWidth)));
image.height = options.viewCenter
? options.maxHeight
: std::min(options.maxHeight, static_cast<u32>(std::max<s32>(1, image.fullHeight)));
if (options.viewCenter) {
const ScreenPoint center = projectToScreen(*options.viewCenter);
image.sourceLeft = center.x - static_cast<s32>(image.width / 2);
image.sourceTop = center.y - static_cast<s32>(image.height / 2);
} else {
image.sourceLeft = nodes[0].left;
image.sourceTop = nodes[0].top;
}
image.pixels.assign(
static_cast<std::size_t>(image.width) * image.height,
RgbColor{static_cast<u8>(10), static_cast<u8>(12), static_cast<u8>(18)});