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,4 +1,5 @@
#include "remorse/fixed_map.h"
#include "remorse/glob_archive.h"
#include "remorse/entity_dispatch_entry.h"
#include "remorse/file_system.h"
@ -153,6 +154,23 @@ std::optional<std::vector<StagedFixedMapItem>> stageFixedMapItems(const FixedMap
return items;
}
std::optional<StagedFixedMapItem> findTeleportEgg(
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes, u8 eggId)
{
std::optional<StagedFixedMapItem> match;
for (const auto& item : items) {
if (item.data.shape >= shapes.size() || shapes[item.data.shape].family != 8 ||
item.data.frame != 1 || (item.data.quality & 0xff) != eggId) {
continue;
}
if (match) {
return std::nullopt;
}
match = item;
}
return match;
}
std::optional<std::vector<StagedContainedFixedMapItem>> stageContainedFixedMapItems(
const FixedMap& map, const std::vector<ShapeTypeInfo>& shapes)
{
@ -415,7 +433,7 @@ std::optional<std::vector<u16>> dispatchStagedItemGrab(const StagedFixedMapItem&
LiveFixedMapItems::LiveFixedMapItems(std::vector<StagedFixedMapItem> items,
std::vector<StagedContainedFixedMapItem> containedItems)
: items_(std::move(items)), allocatedIds_(0x2800), parentById_(0x2800)
: items_(std::move(items)), allocatedIds_(0x2800), hatchedGlobIds_(0x2800), parentById_(0x2800)
{
if (!buildStagedItemBlockChains(items_)) {
throw std::invalid_argument("invalid live item IDs or coordinates");
@ -439,8 +457,36 @@ LiveFixedMapItems::LiveFixedMapItems(std::vector<StagedFixedMapItem> items,
}
}
bool LiveFixedMapItems::initializeAvatar()
{
if (avatar_) {
return false;
}
avatar_.emplace();
avatar_->itemNumber = 1;
avatar_->data.shape = 1;
avatar_->data.npcNumber = 1;
npcAnimations_.resize(2);
return true;
}
bool LiveFixedMapItems::teleportAvatar(const StagedFixedMapItem& egg, u8 mapNumber)
{
if (!avatar_) {
return false;
}
avatar_->data.x = egg.data.x;
avatar_->data.y = egg.data.y;
avatar_->data.z = egg.data.z;
avatar_->data.mapNumber = mapNumber;
return true;
}
const StagedFixedMapItem* LiveFixedMapItems::findItem(u16 itemNumber) const
{
if (itemNumber == 1) {
return avatar_ ? &*avatar_ : nullptr;
}
for (const auto& item : items_) {
if (item.itemNumber == itemNumber) {
return &item;
@ -449,6 +495,19 @@ const StagedFixedMapItem* LiveFixedMapItems::findItem(u16 itemNumber) const
return nullptr;
}
const NpcAnimationState* LiveFixedMapItems::findNpcAnimation(u16 itemNumber) const
{
const auto* item = findItem(itemNumber);
return itemNumber < npcAnimations_.size() && item != nullptr && item->data.npcNumber != 0
? &npcAnimations_[itemNumber] : nullptr;
}
NpcAnimationState* LiveFixedMapItems::editNpcAnimation(u16 itemNumber)
{
return const_cast<NpcAnimationState*>(
static_cast<const LiveFixedMapItems*>(this)->findNpcAnimation(itemNumber));
}
u16 LiveFixedMapItems::containedParent(u16 itemNumber) const
{
return itemNumber < parentById_.size() ? parentById_[itemNumber] : 0;
@ -517,11 +576,64 @@ bool LiveFixedMapItems::insertItem(StagedFixedMapItem item)
return true;
}
std::optional<std::vector<u16>> LiveFixedMapItems::hatchGlobEgg(u16 eggItemNumber,
const GlobObject& glob, const std::vector<ShapeTypeInfo>& shapes)
{
const auto* egg = findItem(eggItemNumber);
if (!egg || egg->data.shape >= shapes.size() || shapes[egg->data.shape].family != 3 ||
egg->data.quality == 0 || egg->data.quality != glob.index ||
isGlobHatched(eggItemNumber)) {
return std::nullopt;
}
std::vector<StagedFixedMapItem> children;
children.reserve(glob.entries.size());
for (const auto& entry : glob.entries) {
StagedFixedMapItem child;
child.recordIndex = static_cast<std::size_t>(-1);
child.data.x = static_cast<u16>((egg->data.x & ~0x1ff) + entry.x * 2 + 1);
child.data.y = static_cast<u16>((egg->data.y & ~0x1ff) + entry.y * 2 + 1);
child.data.z = static_cast<u8>(egg->data.z + entry.z);
child.data.shape = entry.shape;
child.data.frame = entry.frame;
child.data.flags = 0x82;
if (entry.shape == 0 || child.data.x > 0x7fff || child.data.y > 0x7fff) {
return std::nullopt;
}
children.push_back(child);
}
const std::size_t freeCount = static_cast<std::size_t>(std::count(
allocatedIds_.begin() + nextFreeItemNumber_, allocatedIds_.end(), false));
if (freeCount < children.size()) {
return std::nullopt;
}
std::vector<u16> childIds;
childIds.reserve(children.size());
for (auto& child : children) {
childIds.push_back(*allocateItem(child));
}
hatchedGlobIds_[eggItemNumber] = true;
return childIds;
}
bool LiveFixedMapItems::isGlobHatched(u16 eggItemNumber) const
{
return eggItemNumber < hatchedGlobIds_.size() && hatchedGlobIds_[eggItemNumber];
}
bool LiveFixedMapItems::moveItem(u16 itemNumber, u16 x, u16 y, u8 z)
{
if (x > 0x7fff || y > 0x7fff) {
return false;
}
if (itemNumber == 1) {
if (!avatar_) {
return false;
}
avatar_->data.x = x;
avatar_->data.y = y;
avatar_->data.z = std::min<u8>(z, 0xfa);
return true;
}
const auto item = std::find_if(items_.begin(), items_.end(), [itemNumber](const auto& candidate) {
return candidate.itemNumber == itemNumber;
});