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

@ -39,6 +39,13 @@ std::optional<AnimationFrameMetadata> getAnimationFrame(
u8 frameIndex);
u16 getAnimationShapeFrame(const AnimationFrameMetadata& metadata) noexcept;
bool isAnimationFrameFlipped(const AnimationFrameMetadata& metadata) noexcept;
u8 selectAnimationStartFrame(
const AnimationClip& clip,
bool returningFromTwoStep,
bool sameAsLastAnimation,
bool controlledAvatar,
bool entirelyOnScreen,
u8 frameSkip) noexcept;
std::optional<AnimationDisplacement> decodeAnimationDisplacement(
const AnimationFrameMetadata& metadata,
u8 direction,

View file

@ -2,13 +2,16 @@
#include "remorse/compat.h"
#include <array>
#include <cstddef>
#include <memory>
#include <optional>
#include <vector>
namespace remorse {
class LiveFixedMapItems;
struct AnimationClip;
struct ShapeTypeInfo;
struct WorldPoint;
struct FastAreaRange;
@ -43,6 +46,16 @@ struct KeyDaemonProcessEntry {
u8 extra[0x0e];
} CR_PACKED;
struct ControllerProcessEntry {
EntityDispatchEntryBase base;
u8 extra[0x0e];
} CR_PACKED;
struct AnimPrimitiveProcessEntry {
EntityDispatchEntryBase base;
u8 extra[0x29];
} CR_PACKED;
struct KeyEvent {
u8 character;
u8 scanCode;
@ -65,6 +78,8 @@ static_assert(sizeof(GravityProcessEntry) == 0x42, "GravityProcessEntry size mus
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(ControllerProcessEntry) == 0x40, "ControllerProcessEntry size must match allocation evidence");
static_assert(sizeof(AnimPrimitiveProcessEntry) == 0x5b, "AnimPrimitiveProcessEntry size must match allocation evidence");
static_assert(sizeof(KeyEvent) == 0x0c, "KeyEvent size must match keyboard event copy");
struct NpcBehaviorServices {
@ -97,6 +112,20 @@ public:
SystemTimerProcessEntry* createSystemTimerProcess(u8 activeGroup, u16 (&groupCounts)[32]);
KeyboardProcessEntry* createKeyboardProcess(u8 activeGroup, u16 (&groupCounts)[32]);
KeyDaemonProcessEntry* createKeyDaemonProcess(u8 activeGroup, u16 (&groupCounts)[32]);
ControllerProcessEntry* createControllerProcess(u8 activeGroup, u16 (&groupCounts)[32]);
AnimPrimitiveProcessEntry* createAnimPrimitiveProcess(u8 activeGroup, u16 itemNumber,
u16 animationNumber, u8 direction, const AnimationClip& clip, u16 (&groupCounts)[32]);
bool startAnimPrimitiveProcess(u16 processId, LiveFixedMapItems& items,
const AnimationClip& clip, u8 frameSkip = 0);
std::optional<bool> advanceGroundedAnimPrimitive(u16 processId, LiveFixedMapItems& items,
const AnimationClip& clip, const std::vector<ShapeTypeInfo>& shapes,
const FastAreaRange& fastArea);
bool queuePendingKeyEvent(const KeyEvent& event);
std::optional<KeyEvent> popPendingKeyEvent();
u8 pendingKeyEventCount() const;
bool pendingKeyEventOverflowed() const;
void dispatchPendingKeyEvents(
void (*deliver)(EntityDispatchEntryBase&, u16, u16, KeyEvent&, void*), void* context);
void deliverSystemTimerEvent();
u32 systemTimerTick() const;
void setSyncContext(bool enabled, u16 currentProcessId);
@ -136,9 +165,16 @@ private:
std::vector<std::unique_ptr<EntityDispatchEntryBase>> ownedProcesses_;
std::vector<std::unique_ptr<StandProcessEntry>> ownedStandProcesses_;
std::vector<std::unique_ptr<GravityProcessEntry>> ownedGravityProcesses_;
std::vector<std::unique_ptr<AnimPrimitiveProcessEntry>> ownedAnimPrimitiveProcesses_;
std::unique_ptr<SystemTimerProcessEntry> systemTimerProcess_;
std::unique_ptr<KeyboardProcessEntry> keyboardProcess_;
std::unique_ptr<KeyDaemonProcessEntry> keyDaemonProcess_;
std::unique_ptr<ControllerProcessEntry> controllerProcess_;
std::vector<u16> keyboardSubscriberIds_;
std::array<KeyEvent, 32> pendingKeyEvents_{};
u8 nextKeyEventOffset_ = 0;
u8 keyEventOffset_ = 0;
bool pendingKeyEventOverflowed_ = false;
u16 systemTimerProcessId_ = 0xffff;
std::vector<u8> itemProcessPresence_;
std::vector<u8> itemProcessTypes_;

View file

@ -10,6 +10,7 @@ namespace remorse {
struct ShapeTypeInfo;
struct WorldRect;
struct GlobObject;
class ProcessKernel;
struct FixedMapEntry {
@ -77,6 +78,8 @@ struct FixedMapArchive {
std::optional<FixedMapArchive> loadFixedMapArchive(const std::filesystem::path& path);
std::optional<FixedMap> loadFixedMap(const FixedMapArchive& archive, u32 mapIndex);
std::optional<std::vector<StagedFixedMapItem>> stageFixedMapItems(const FixedMap& map);
std::optional<StagedFixedMapItem> findTeleportEgg(
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes, u8 eggId);
std::optional<std::vector<StagedContainedFixedMapItem>> stageContainedFixedMapItems(
const FixedMap& map, const std::vector<ShapeTypeInfo>& shapes);
std::optional<StagedFixedMapItem> nearestStagedFixedMapItem(
@ -99,16 +102,30 @@ std::optional<std::vector<u16>> dispatchStagedItemGrab(const StagedFixedMapItem&
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes,
ProcessKernel& kernel, u16 (&groupCounts)[32], u32 timerTick);
struct NpcAnimationState {
u16 lastAnimation = 0xffff;
u8 frame = 0;
u8 moreFlags = 0;
};
class LiveFixedMapItems {
public:
explicit LiveFixedMapItems(std::vector<StagedFixedMapItem> items,
std::vector<StagedContainedFixedMapItem> containedItems = {});
bool initializeAvatar();
bool teleportAvatar(const StagedFixedMapItem& egg, u8 mapNumber);
const StagedFixedMapItem* findItem(u16 itemNumber) const;
const std::vector<StagedFixedMapItem>& mapItems() const noexcept { return items_; }
const NpcAnimationState* findNpcAnimation(u16 itemNumber) const;
NpcAnimationState* editNpcAnimation(u16 itemNumber);
u16 containedParent(u16 itemNumber) const;
std::optional<StagedFixedMapItem> nearestItem(s32 worldX, s32 worldY, s32 maxDistance) const;
std::optional<std::vector<u16>> sweepCandidateIds(const WorldRect& area, u16 excludedItemNumber) const;
std::optional<u16> allocateItem(StagedFixedMapItem item);
bool insertItem(StagedFixedMapItem item);
std::optional<std::vector<u16>> hatchGlobEgg(u16 eggItemNumber, const GlobObject& glob,
const std::vector<ShapeTypeInfo>& shapes);
bool isGlobHatched(u16 eggItemNumber) const;
bool moveItem(u16 itemNumber, u16 x, u16 y, u8 z);
std::optional<std::vector<u16>> grabItem(u16 itemNumber, const std::vector<ShapeTypeInfo>& shapes,
ProcessKernel& kernel, u16 (&groupCounts)[32], u32 timerTick) const;
@ -118,7 +135,10 @@ public:
private:
std::vector<StagedFixedMapItem> items_;
std::optional<StagedFixedMapItem> avatar_;
std::vector<NpcAnimationState> npcAnimations_;
std::vector<bool> allocatedIds_;
std::vector<bool> hatchedGlobIds_;
std::vector<u16> parentById_;
u16 nextFreeItemNumber_ = 0x100;
};

View file

@ -3,6 +3,9 @@
#include "remorse/animation_archive.h"
#include "remorse/compat.h"
#include <algorithm>
#include <vector>
namespace remorse {
struct WorldPositionD {
@ -33,6 +36,46 @@ inline std::optional<u8> controllerDirectionFromScan(u8 scanCode)
}
}
struct ControllerMovementRequest {
u8 animation = 0;
u8 direction = 14;
};
class ControllerMovementState {
public:
void handleDirectionalKey(u8 scanCode, u16 modifiers, bool pressed)
{
modifiers_ = modifiers;
const auto direction = controllerDirectionFromScan(scanCode);
if (!direction) {
return;
}
const auto held = std::find(heldScans_.begin(), heldScans_.end(), scanCode);
if (held != heldScans_.end()) {
heldScans_.erase(held);
}
if (pressed && (modifiers & 0x20) == 0) {
heldScans_.push_back(scanCode);
}
}
ControllerMovementRequest request() const
{
if (heldScans_.empty()) {
return {0, lastDirection_};
}
lastDirection_ = *controllerDirectionFromScan(heldScans_.back());
return {static_cast<u8>(controllerWalkRequested(modifiers_) ? 1 : 3), lastDirection_};
}
void clear() { heldScans_.clear(); }
private:
std::vector<u8> heldScans_;
u16 modifiers_ = 0;
mutable u8 lastDirection_ = 14;
};
inline std::optional<AnimationDisplacement> hostMovementStep(
const AnimationFrameMetadata& metadata, u8 direction, bool rotateDirection)
{

View file

@ -6,7 +6,13 @@
#include "remorse/compat.h"
#include "remorse/file_system.h"
#include "remorse/fixed_map.h"
#include "remorse/glob_archive.h"
#include "remorse/palette.h"
#include "remorse/shape_archive.h"
#include "remorse/type_flags.h"
#include <map>
namespace remorse {
@ -17,6 +23,8 @@ struct WorldRect {
s32 maxY = 0;
};
class LiveFixedMapItems;
struct WorldPoint {
s32 x = 0;
s32 y = 0;
@ -53,7 +61,22 @@ struct RenderedMapImage {
std::vector<RgbColor> pixels;
};
struct MapSceneRenderer {
FixedMap map;
std::vector<GlobObject> globs;
ShapeArchive shapes;
Palette256 palette;
std::vector<ShapeTypeInfo> typeFlags;
std::map<std::pair<u32, u32>, DecodedShapeFrame> decodedFrames;
std::optional<RenderedMapImage> render(const MapRenderOptions& options,
const LiveFixedMapItems* liveItems = nullptr);
};
std::optional<MapSceneRenderer> loadMapSceneRenderer(const GameDataRoot& root, u32 mapIndex);
std::optional<RenderedMapImage> renderMapPreview(const GameDataRoot& root, const MapRenderOptions& options);
std::optional<RenderedMapImage> renderLiveMapPreview(const GameDataRoot& root,
const MapRenderOptions& options, const LiveFixedMapItems& items);
ScreenPoint projectToScreen(const WorldPoint& point);
bool writeBmp24(const std::filesystem::path& path, const RenderedMapImage& image);

View file

@ -0,0 +1,30 @@
#pragma once
#include <array>
#include <cstddef>
#include <optional>
#include <vector>
#include "remorse/compat.h"
namespace remorse {
struct UsecodeCallFrame {
u16 offset = 0;
u16 segment = 0;
};
class UsecodeInterpreterState {
public:
static std::optional<UsecodeInterpreterState> initialize(
const std::vector<u8>& itemParameter);
bool pushCodeAddress(u16 offset, u16 segment);
std::array<u8, 0xcc> valueStack{};
std::size_t stackTop = 0xcc;
std::array<UsecodeCallFrame, 32> callFrames{};
u16 callFrameCount = 0;
u16 stackLimit = 199;
};
} // namespace remorse