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

@ -0,0 +1,47 @@
#pragma once
#include <array>
#include <filesystem>
#include <optional>
#include <vector>
#include "remorse\compat.h"
namespace remorse {
struct AnimationFrameMetadata {
std::array<u8, 8> bytes{};
};
struct AnimationClip {
std::array<u8, 4> header{};
u8 frameCount = 0;
u8 directionCount = 8;
std::vector<AnimationFrameMetadata> frames;
};
struct AnimationArchive {
std::vector<u8> bytes;
};
struct AnimationDisplacement {
s32 x = 0;
s32 y = 0;
s32 z = 0;
bool onGround = false;
};
std::optional<AnimationArchive> loadAnimationArchive(const std::filesystem::path& path);
std::optional<AnimationClip> loadAnimationClip(const AnimationArchive& archive, u32 shapeIndex, u8 animationIndex);
std::optional<AnimationFrameMetadata> getAnimationFrame(
const AnimationClip& clip,
u8 direction,
u8 frameIndex);
u16 getAnimationShapeFrame(const AnimationFrameMetadata& metadata) noexcept;
bool isAnimationFrameFlipped(const AnimationFrameMetadata& metadata) noexcept;
std::optional<AnimationDisplacement> decodeAnimationDisplacement(
const AnimationFrameMetadata& metadata,
u8 direction,
bool rotateDirection);
} // namespace remorse

View file

@ -0,0 +1,30 @@
#pragma once
#include <vector>
#include "remorse\fixed_map.h"
#include "remorse\glob_archive.h"
#include "remorse\map_renderer.h"
#include "remorse\type_flags.h"
namespace remorse {
struct CollisionBody {
WorldPoint location{};
s32 extentX = 0;
s32 extentY = 0;
s32 extentZ = 0;
};
CollisionBody makeCollisionBody(WorldPoint location, const ShapeTypeInfo& shapeInfo, bool flipped = false);
bool collisionBodiesOverlap(const CollisionBody& left, const CollisionBody& right);
bool canMoveCollisionBody(
const CollisionBody& body,
WorldPoint destination,
const std::vector<CollisionBody>& obstacles);
std::vector<CollisionBody> collectMapCollisionBodies(
const FixedMap& map,
const std::vector<ShapeTypeInfo>& shapeTypes,
const std::vector<GlobObject>& globObjects);
} // namespace remorse

View file

@ -0,0 +1,46 @@
#pragma once
#include <cstddef>
#include <vector>
#include "remorse/compat.h"
namespace remorse {
namespace detail {
struct RenderSortItem {
s32 left = 0;
s32 top = 0;
s32 right = 0;
s32 bottom = 0;
s32 x = 0;
s32 xLeft = 0;
s32 y = 0;
s32 yFar = 0;
s32 z = 0;
s32 zTop = 0;
s32 sxLeft = 0;
s32 sxRight = 0;
s32 sxTop = 0;
s32 syTop = 0;
s32 sxBottom = 0;
s32 syBottom = 0;
u16 shape = 0;
u8 frame = 0;
bool bigFlatSquare = false;
bool flat = false;
bool occludes = false;
bool solid = false;
bool draw = false;
bool roof = false;
bool translucent = false;
bool animated = false;
bool land = false;
bool sprite = false;
bool inventoryItem = false;
};
std::vector<std::size_t> resolveRenderOrder(const std::vector<RenderSortItem>& items);
} // namespace detail
} // namespace remorse

View file

@ -2,6 +2,10 @@
#include "remorse/compat.h"
#include <cstddef>
#include <memory>
#include <vector>
namespace remorse {
CR_PACK_PUSH_1
@ -9,23 +13,139 @@ struct EntityDispatchEntryBase {
u8 bytes[0x32];
} CR_PACKED;
struct StandProcessEntry {
EntityDispatchEntryBase base;
u8 extra[0x10];
} CR_PACKED;
struct SystemTimerProcessEntry {
EntityDispatchEntryBase base;
u8 extra[0x18];
} CR_PACKED;
struct KeyboardProcessEntry {
EntityDispatchEntryBase base;
u8 extra[0x04];
} CR_PACKED;
struct KeyDaemonProcessEntry {
EntityDispatchEntryBase base;
u8 extra[0x0e];
} CR_PACKED;
struct KeyEvent {
u8 character;
u8 scanCode;
u16 modifiers;
u16 field4;
u16 field6;
u8 field8;
u8 field9;
u16 fieldA;
} CR_PACKED;
struct EntityDispatchEntryRuntimeState {
u8 bytes[0x18];
} CR_PACKED;
CR_PACK_POP
static_assert(sizeof(EntityDispatchEntryBase) == 0x32, "EntityDispatchEntryBase size must match allocation evidence");
static_assert(sizeof(StandProcessEntry) == 0x42, "StandProcessEntry size must match allocation evidence");
static_assert(sizeof(SystemTimerProcessEntry) == 0x4a, "SystemTimerProcessEntry size must match allocation evidence");
static_assert(sizeof(KeyboardProcessEntry) == 0x36, "KeyboardProcessEntry size must match allocation evidence");
static_assert(sizeof(KeyDaemonProcessEntry) == 0x40, "KeyDaemonProcessEntry size must match allocation evidence");
static_assert(sizeof(KeyEvent) == 0x0c, "KeyEvent size must match keyboard event copy");
struct NpcBehaviorServices {
bool (*isEntirelyOnScreen)(u16 npcNumber, void* context);
u16 (*getActivity)(u16 npcNumber, void* context);
bool (*isCurrentActivitySpecifiedBy)(u16 npcNumber, u16 activity, void* context);
bool (*canSeeControlledNPC)(u16 npcNumber, void* context);
void (*startNextBehavior)(u16 npcNumber, u16 activity, void* context);
void* context;
};
class ProcessKernel {
public:
EntityDispatchEntryBase* createProcess(u8 activeGroup, u16 (&groupCounts)[32]);
StandProcessEntry* createStandProcess(u8 activeGroup, u16 npcNumber, u16 (&groupCounts)[32]);
SystemTimerProcessEntry* createSystemTimerProcess(u8 activeGroup, u16 (&groupCounts)[32]);
KeyboardProcessEntry* createKeyboardProcess(u8 activeGroup, u16 (&groupCounts)[32]);
KeyDaemonProcessEntry* createKeyDaemonProcess(u8 activeGroup, u16 (&groupCounts)[32]);
void deliverSystemTimerEvent();
u32 systemTimerTick() const;
void setSyncContext(bool enabled, u16 currentProcessId);
void setMarkNewProcesses(bool enabled);
void setLastAllocationSize(u16 size);
u16 addProcess(EntityDispatchEntryBase& entry);
void clearProcessSlot(u16 id);
void terminateProcess(u16 id, u16 (&groupCounts)[32]);
void clearTerminatedProcesses();
void scanRunnableProcesses(u8 activeGroup, void (*run)(EntityDispatchEntryBase&, void*), void* context, u32 timerTick = 0);
EntityDispatchEntryBase* processAt(u16 id) const;
u16 allocationSizeAt(u16 id) const;
const char* processNameAt(u16 id) const;
bool itemHasProcess(u16 itemNumber) const;
u16 processCount() const;
u16 terminatedProcessCount() const;
u16 newlyCreatedCount() const;
std::size_t capacity() const;
private:
void releaseOwnedProcess(u16 id);
std::vector<EntityDispatchEntryBase*> processes_;
std::vector<u16> allocationSizes_;
std::vector<const char*> processNames_;
std::vector<std::unique_ptr<EntityDispatchEntryBase>> ownedProcesses_;
std::vector<std::unique_ptr<StandProcessEntry>> ownedStandProcesses_;
std::unique_ptr<SystemTimerProcessEntry> systemTimerProcess_;
std::unique_ptr<KeyboardProcessEntry> keyboardProcess_;
std::unique_ptr<KeyDaemonProcessEntry> keyDaemonProcess_;
u16 systemTimerProcessId_ = 0xffff;
std::vector<u8> itemProcessPresence_;
u16 lastAllocationSize_ = 0;
u16 processCount_ = 0;
u16 terminatedProcessCount_ = 0;
u16 newlyCreatedCount_ = 0;
u16 currentProcessId_ = 0;
bool syncEnabled_ = false;
bool markNewProcesses_ = false;
};
class EntityDispatchEntry {
public:
static constexpr u16 initBaseSegment = 0x11e0;
static constexpr u16 initBaseOffset = 0x0000;
static EntityDispatchEntryBase* initBase(EntityDispatchEntryBase* entry);
static void setGroupId(EntityDispatchEntryBase& entry, u8 groupId);
static EntityDispatchEntryBase* initBase(EntityDispatchEntryBase* entry, u8 activeGroup, u16 (&groupCounts)[32]);
static void setGroupId(EntityDispatchEntryBase& entry, u8 groupId, u16 (&groupCounts)[32]);
static void incrementGroupId(EntityDispatchEntryBase& entry);
static void setSourceType(EntityDispatchEntryBase& entry, u16 sourceType);
static void setEventTypeChecked(EntityDispatchEntryBase& entry, u16 eventType);
static void sleep(EntityDispatchEntryBase& entry, u32 timerTick, u32 duration);
static void unlinkSleep(EntityDispatchEntryBase& entry);
};
class StandProcess {
public:
static constexpr u16 runOffset = 0x0359;
static constexpr u16 vtableOffset = 0x1f0f;
static void run(EntityDispatchEntryBase& entry, bool (*startBehavior)(const EntityDispatchEntryBase&, void*),
void* context, u32 timerTick);
static void run(StandProcessEntry& entry, const NpcBehaviorServices& services, u32 timerTick);
};
class SystemTimerProcess {
public:
static u32 tick(const SystemTimerProcessEntry& entry);
static void increment(SystemTimerProcessEntry& entry);
};
class KeyboardProcess {
public:
static bool handleKeyEvent(KeyboardProcessEntry& process, u16 selector, u16 filter,
KeyEvent& event, const KeyEvent& lastEvent);
};
} // namespace remorse

View file

@ -0,0 +1,42 @@
#pragma once
#include "remorse/animation_archive.h"
#include "remorse/compat.h"
namespace remorse {
struct WorldPositionD {
double x = 0.0;
double y = 0.0;
};
inline bool controllerWalkRequested(u16 modifiers)
{
const bool shiftDown = (modifiers & 0x03) != 0;
const bool capsLockOn = (modifiers & 0x40) != 0;
return shiftDown == capsLockOn;
}
inline std::optional<AnimationDisplacement> hostMovementStep(
const AnimationFrameMetadata& metadata, u8 direction, bool rotateDirection)
{
auto step = decodeAnimationDisplacement(metadata, direction, rotateDirection);
if (step && (metadata.bytes[5] & 1) != 0) {
step->x = 0;
step->y = 0;
}
return step;
}
inline WorldPositionD worldPositionAtScreenOffset(
s32 originX,
s32 originY,
double screenOffsetX,
double screenOffsetY)
{
return WorldPositionD{
originX + 2.0 * screenOffsetX + 4.0 * screenOffsetY,
originY - 2.0 * screenOffsetX + 4.0 * screenOffsetY};
}
} // namespace remorse

View file

@ -17,6 +17,17 @@ struct WorldRect {
s32 maxY = 0;
};
struct WorldPoint {
s32 x = 0;
s32 y = 0;
s32 z = 0;
};
struct ScreenPoint {
s32 x = 0;
s32 y = 0;
};
struct MapRenderOptions {
u32 mapIndex = 1;
u32 maxWidth = 1600;
@ -24,6 +35,7 @@ struct MapRenderOptions {
bool expandGlobs = true;
bool includeRoofs = false;
bool includeHiddenMarkers = false;
std::optional<WorldPoint> viewCenter;
std::optional<WorldRect> worldRect;
};
@ -42,6 +54,7 @@ struct RenderedMapImage {
};
std::optional<RenderedMapImage> renderMapPreview(const GameDataRoot& root, const MapRenderOptions& options);
ScreenPoint projectToScreen(const WorldPoint& point);
bool writeBmp24(const std::filesystem::path& path, const RenderedMapImage& image);
} // namespace remorse

View file

@ -20,5 +20,6 @@ struct ExportManifestSummary {
std::optional<ExportManifestSummary> loadExportManifestSummary(const std::filesystem::path& manifestPath);
std::filesystem::path defaultManifestPath(const std::filesystem::path& currentPath);
void printStartupReport(const ExportManifestSummary& manifest);
void installCrashDiagnostics();
} // namespace remorse