Add comprehensive tests for entity dispatch, file system, fixed map, flex archive, isometric controls, and crash setup
- Enhance `entity_dispatch_entry_tests.cpp` with additional assertions for event type checks, group ID increments, and error handling. - Refactor `file_system_tests.cpp` to streamline probe execution and enhance output validation. - Extend `fixed_map_tests.cpp` to cover retail map loading, item classification, and process creation scenarios. - Introduce new checks in `flex_archive_tests.cpp` for usecode loading and event handling, ensuring robust validation of game data. - Add tests in `isometric_controls_tests.cpp` for controller direction mapping based on scan codes. - Implement `test_crash_setup.cpp` to initialize crash diagnostics for improved error handling during tests.
This commit is contained in:
parent
202679f857
commit
c346b0e1a7
17 changed files with 1207 additions and 92 deletions
|
|
@ -67,8 +67,10 @@ struct NpcBehaviorServices {
|
|||
|
||||
class ProcessKernel {
|
||||
public:
|
||||
static constexpr u16 maxTrackedItemNumber = 0x23ff;
|
||||
EntityDispatchEntryBase* createProcess(u8 activeGroup, u16 (&groupCounts)[32]);
|
||||
StandProcessEntry* createStandProcess(u8 activeGroup, u16 npcNumber, u16 (&groupCounts)[32]);
|
||||
EntityDispatchEntryBase* createItemProcess(u8 activeGroup, u16 itemNumber, u16 (&groupCounts)[32]);
|
||||
SystemTimerProcessEntry* createSystemTimerProcess(u8 activeGroup, u16 (&groupCounts)[32]);
|
||||
KeyboardProcessEntry* createKeyboardProcess(u8 activeGroup, u16 (&groupCounts)[32]);
|
||||
KeyDaemonProcessEntry* createKeyDaemonProcess(u8 activeGroup, u16 (&groupCounts)[32]);
|
||||
|
|
@ -76,16 +78,25 @@ public:
|
|||
u32 systemTimerTick() const;
|
||||
void setSyncContext(bool enabled, u16 currentProcessId);
|
||||
void setMarkNewProcesses(bool enabled);
|
||||
void setActiveGroup(u8 groupId);
|
||||
u8 activeGroup() const;
|
||||
bool groupSelectionPending() const;
|
||||
void refreshActiveGroup(const u16 (&groupCounts)[32]);
|
||||
void setLastAllocationSize(u16 size);
|
||||
u16 addProcess(EntityDispatchEntryBase& entry);
|
||||
void clearProcessSlot(u16 id);
|
||||
void terminateProcess(u16 id, u16 (&groupCounts)[32]);
|
||||
void clearTerminatedProcesses();
|
||||
void setProcessSourceType(EntityDispatchEntryBase& entry, u16 itemNumber);
|
||||
void setProcessEventTypeChecked(EntityDispatchEntryBase& entry, u16 eventType);
|
||||
void scanRunnableProcesses(u8 activeGroup, void (*run)(EntityDispatchEntryBase&, void*), void* context, u32 timerTick = 0);
|
||||
u32 runTimedSchedulerPass(u8 activeGroup, void (*run)(EntityDispatchEntryBase&, void*), void* context,
|
||||
void (*afterScan)(void*) = nullptr, void* afterContext = nullptr);
|
||||
EntityDispatchEntryBase* processAt(u16 id) const;
|
||||
u16 allocationSizeAt(u16 id) const;
|
||||
const char* processNameAt(u16 id) const;
|
||||
bool itemHasProcess(u16 itemNumber) const;
|
||||
u8 itemProcessTypes(u16 itemNumber) const;
|
||||
u16 processCount() const;
|
||||
u16 terminatedProcessCount() const;
|
||||
u16 newlyCreatedCount() const;
|
||||
|
|
@ -93,6 +104,8 @@ public:
|
|||
|
||||
private:
|
||||
void releaseOwnedProcess(u16 id);
|
||||
void refreshItemPresence(u16 itemNumber);
|
||||
void refreshItemProcessType(u16 itemNumber, u16 eventType);
|
||||
std::vector<EntityDispatchEntryBase*> processes_;
|
||||
std::vector<u16> allocationSizes_;
|
||||
std::vector<const char*> processNames_;
|
||||
|
|
@ -103,11 +116,14 @@ private:
|
|||
std::unique_ptr<KeyDaemonProcessEntry> keyDaemonProcess_;
|
||||
u16 systemTimerProcessId_ = 0xffff;
|
||||
std::vector<u8> itemProcessPresence_;
|
||||
std::vector<u8> itemProcessTypes_;
|
||||
u16 lastAllocationSize_ = 0;
|
||||
u16 processCount_ = 0;
|
||||
u16 terminatedProcessCount_ = 0;
|
||||
u16 newlyCreatedCount_ = 0;
|
||||
u16 currentProcessId_ = 0;
|
||||
u8 activeGroup_ = 1;
|
||||
bool groupSelectionPending_ = false;
|
||||
bool syncEnabled_ = false;
|
||||
bool markNewProcesses_ = false;
|
||||
};
|
||||
|
|
@ -119,7 +135,7 @@ public:
|
|||
|
||||
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 incrementGroupId(EntityDispatchEntryBase& entry, ProcessKernel& kernel, u16 (&groupCounts)[32]);
|
||||
static void setSourceType(EntityDispatchEntryBase& entry, u16 sourceType);
|
||||
static void setEventTypeChecked(EntityDispatchEntryBase& entry, u16 eventType);
|
||||
static void sleep(EntityDispatchEntryBase& entry, u32 timerTick, u32 duration);
|
||||
|
|
@ -136,6 +152,15 @@ public:
|
|||
static void run(StandProcessEntry& entry, const NpcBehaviorServices& services, u32 timerTick);
|
||||
};
|
||||
|
||||
class ItemProcess {
|
||||
public:
|
||||
static constexpr u16 runOffset = 0x0078;
|
||||
static constexpr u16 vtableOffset = 0x102f;
|
||||
|
||||
static void run(EntityDispatchEntryBase& entry, ProcessKernel& kernel, u16 (&groupCounts)[32],
|
||||
void (*release)(u16 itemNumber, u32 eventMask, u16 eventId, void*), void* context);
|
||||
};
|
||||
|
||||
class SystemTimerProcess {
|
||||
public:
|
||||
static u32 tick(const SystemTimerProcessEntry& entry);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
namespace remorse {
|
||||
|
||||
struct ShapeTypeInfo;
|
||||
|
||||
struct FixedMapEntry {
|
||||
u16 x = 0;
|
||||
u16 y = 0;
|
||||
|
|
@ -26,6 +28,19 @@ struct FixedMap {
|
|||
std::vector<FixedMapEntry> entries;
|
||||
};
|
||||
|
||||
struct StagedFixedMapItem {
|
||||
u16 itemNumber = 0;
|
||||
std::size_t recordIndex = 0;
|
||||
FixedMapEntry data;
|
||||
};
|
||||
|
||||
struct ItemFindArea {
|
||||
u16 minX = 0;
|
||||
u16 minY = 0;
|
||||
u16 maxX = 0;
|
||||
u16 maxY = 0;
|
||||
};
|
||||
|
||||
struct FixedMapArchive {
|
||||
u32 mapCount = 0;
|
||||
std::vector<u8> bytes;
|
||||
|
|
@ -33,5 +48,13 @@ 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> nearestStagedFixedMapItem(
|
||||
const std::vector<StagedFixedMapItem>& items, s32 worldX, s32 worldY, s32 maxDistance);
|
||||
bool itemGrabCanCreateProcess(const StagedFixedMapItem& item);
|
||||
u8 classifyItemFindZMatch(const StagedFixedMapItem& origin, const ShapeTypeInfo& originShape,
|
||||
const StagedFixedMapItem& candidate, const ShapeTypeInfo& candidateShape, u8 zMatchFlags);
|
||||
ItemFindArea itemFindAreaAroundItem(const StagedFixedMapItem& origin, const ShapeTypeInfo& originShape);
|
||||
std::vector<u16> itemFindBlockOrder(const ItemFindArea& area);
|
||||
|
||||
} // namespace remorse
|
||||
|
|
|
|||
|
|
@ -17,6 +17,22 @@ inline bool controllerWalkRequested(u16 modifiers)
|
|||
return shiftDown == capsLockOn;
|
||||
}
|
||||
|
||||
inline std::optional<u8> controllerDirectionFromScan(u8 scanCode)
|
||||
{
|
||||
// Controller_PickNextAnimByKeyevent (1130:12d6), directional keys with Num Lock off.
|
||||
switch (scanCode) {
|
||||
case 0x47: return u8{12};
|
||||
case 0x48: return u8{14};
|
||||
case 0x49: return u8{0};
|
||||
case 0x4b: return u8{10};
|
||||
case 0x4d: return u8{2};
|
||||
case 0x4f: return u8{8};
|
||||
case 0x50: return u8{6};
|
||||
case 0x51: return u8{4};
|
||||
default: return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
inline std::optional<AnimationDisplacement> hostMovementStep(
|
||||
const AnimationFrameMetadata& metadata, u8 direction, bool rotateDirection)
|
||||
{
|
||||
|
|
|
|||
54
rebuild/remorse/include/remorse/usecode_archive.h
Normal file
54
rebuild/remorse/include/remorse/usecode_archive.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#pragma once
|
||||
|
||||
#include "remorse/flex_archive.h"
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace remorse {
|
||||
|
||||
struct UsecodeClass {
|
||||
u32 classId = 0;
|
||||
std::string name;
|
||||
u32 codeBase = 0;
|
||||
std::vector<u8> bytes;
|
||||
};
|
||||
|
||||
struct UsecodeEventBody {
|
||||
u16 length = 0;
|
||||
u32 relativeOffset = 0;
|
||||
std::vector<u8> bytes;
|
||||
};
|
||||
|
||||
struct UsecodeClassBases {
|
||||
u16 regularShape = 0;
|
||||
u16 npc = 0;
|
||||
u16 unknownEgg = 0;
|
||||
};
|
||||
|
||||
struct UsecodeItemIdentity {
|
||||
u16 itemNumber = 0;
|
||||
u16 shape = 0;
|
||||
u16 status = 0;
|
||||
u16 quality = 0;
|
||||
u8 family = 0;
|
||||
bool isNpc = false;
|
||||
};
|
||||
|
||||
struct EligibleUsecodeEvent {
|
||||
u16 classId = 0;
|
||||
std::string className;
|
||||
UsecodeEventBody body;
|
||||
};
|
||||
|
||||
u16 selectUsecodeClassId(const UsecodeItemIdentity& item, const UsecodeClassBases& bases);
|
||||
std::optional<std::vector<u8>> loadUsecodeOwnerRows(const FlexArchive& archive);
|
||||
bool ownerRowAllowsEvent(const std::vector<u8>& ownerRows, u16 classId, u32 eventMask);
|
||||
std::optional<UsecodeClass> loadUsecodeClass(const FlexArchive& archive, u32 classId);
|
||||
std::optional<UsecodeEventBody> readUsecodeEventBody(const UsecodeClass& usecodeClass, u32 eventId);
|
||||
std::optional<EligibleUsecodeEvent> selectEligibleUsecodeEvent(const FlexArchive& archive,
|
||||
const std::vector<u8>& ownerRows, const UsecodeItemIdentity& item,
|
||||
const UsecodeClassBases& bases, u32 eventMask, u16 eventId);
|
||||
|
||||
} // namespace remorse
|
||||
Loading…
Add table
Add a link
Reference in a new issue