Enhance item handling and collision detection in remorse
- Introduced new functionality for staging and managing fixed map items, including the ability to build block chains and find candidates for item interactions. - Updated the main application logic to utilize staged item block chains for improved item finding and grabbing mechanics. - Added weight attribute to shape type information, allowing for more nuanced item interactions based on weight. - Enhanced collision tests to cover new item handling scenarios, including gravity sweeps and item grabbing. - Implemented additional tests for entity dispatch entries and fixed map items to ensure robustness of item spawning and movement logic. - Improved type flags loading to validate weight against binary data, ensuring consistency in item attributes.
This commit is contained in:
parent
c346b0e1a7
commit
b99fb59c12
15 changed files with 961 additions and 18 deletions
|
|
@ -16,6 +16,20 @@ struct CollisionBody {
|
|||
s32 extentZ = 0;
|
||||
};
|
||||
|
||||
struct GravitySweepPlan {
|
||||
WorldPoint destination{};
|
||||
s16 nextZSpeed = 0;
|
||||
};
|
||||
|
||||
struct SweepBoundsResult {
|
||||
WorldPoint destination{};
|
||||
u8 failedDirections = 0;
|
||||
bool failed = false;
|
||||
};
|
||||
|
||||
SweepBoundsResult clampAreaSweepBounds(WorldPoint from, WorldPoint destination);
|
||||
GravitySweepPlan planGravitySweep(WorldPoint location, s16 xSpeed, s16 ySpeed, s16 zSpeed,
|
||||
s16 gravity, u32 timeScale);
|
||||
CollisionBody makeCollisionBody(WorldPoint location, const ShapeTypeInfo& shapeInfo, bool flipped = false);
|
||||
bool collisionBodiesOverlap(const CollisionBody& left, const CollisionBody& right);
|
||||
bool canMoveCollisionBody(
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@
|
|||
|
||||
namespace remorse {
|
||||
|
||||
class LiveFixedMapItems;
|
||||
struct ShapeTypeInfo;
|
||||
struct WorldPoint;
|
||||
|
||||
CR_PACK_PUSH_1
|
||||
struct EntityDispatchEntryBase {
|
||||
u8 bytes[0x32];
|
||||
|
|
@ -18,6 +22,11 @@ struct StandProcessEntry {
|
|||
u8 extra[0x10];
|
||||
} CR_PACKED;
|
||||
|
||||
struct GravityProcessEntry {
|
||||
EntityDispatchEntryBase base;
|
||||
u8 extra[0x10];
|
||||
} CR_PACKED;
|
||||
|
||||
struct SystemTimerProcessEntry {
|
||||
EntityDispatchEntryBase base;
|
||||
u8 extra[0x18];
|
||||
|
|
@ -51,6 +60,7 @@ 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(GravityProcessEntry) == 0x42, "GravityProcessEntry 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");
|
||||
|
|
@ -71,6 +81,12 @@ public:
|
|||
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]);
|
||||
u16 hurlItem(u8 activeGroup, u16 itemNumber, s16 xs, s16 ys, s16 zs, s16 gravity,
|
||||
u32 timerTick, u16 (&groupCounts)[32]);
|
||||
bool runUnobstructedGravity(u16 processId, LiveFixedMapItems& items, u32 timeScale, u32 timerTick,
|
||||
bool (*approveSweep)(u16 itemNumber, const WorldPoint& from, const WorldPoint& to, void* context),
|
||||
void* context, const std::vector<ShapeTypeInfo>* shapes = nullptr,
|
||||
u16 (*groupCounts)[32] = nullptr);
|
||||
SystemTimerProcessEntry* createSystemTimerProcess(u8 activeGroup, u16 (&groupCounts)[32]);
|
||||
KeyboardProcessEntry* createKeyboardProcess(u8 activeGroup, u16 (&groupCounts)[32]);
|
||||
KeyDaemonProcessEntry* createKeyDaemonProcess(u8 activeGroup, u16 (&groupCounts)[32]);
|
||||
|
|
@ -93,6 +109,7 @@ public:
|
|||
u32 runTimedSchedulerPass(u8 activeGroup, void (*run)(EntityDispatchEntryBase&, void*), void* context,
|
||||
void (*afterScan)(void*) = nullptr, void* afterContext = nullptr);
|
||||
EntityDispatchEntryBase* processAt(u16 id) const;
|
||||
EntityDispatchEntryBase* findProcessForItemAndType(u16 itemNumber, u16 eventType) const;
|
||||
u16 allocationSizeAt(u16 id) const;
|
||||
const char* processNameAt(u16 id) const;
|
||||
bool itemHasProcess(u16 itemNumber) const;
|
||||
|
|
@ -111,6 +128,7 @@ private:
|
|||
std::vector<const char*> processNames_;
|
||||
std::vector<std::unique_ptr<EntityDispatchEntryBase>> ownedProcesses_;
|
||||
std::vector<std::unique_ptr<StandProcessEntry>> ownedStandProcesses_;
|
||||
std::vector<std::unique_ptr<GravityProcessEntry>> ownedGravityProcesses_;
|
||||
std::unique_ptr<SystemTimerProcessEntry> systemTimerProcess_;
|
||||
std::unique_ptr<KeyboardProcessEntry> keyboardProcess_;
|
||||
std::unique_ptr<KeyDaemonProcessEntry> keyDaemonProcess_;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
namespace remorse {
|
||||
|
||||
struct ShapeTypeInfo;
|
||||
class ProcessKernel;
|
||||
|
||||
struct FixedMapEntry {
|
||||
u16 x = 0;
|
||||
|
|
@ -34,6 +35,12 @@ struct StagedFixedMapItem {
|
|||
FixedMapEntry data;
|
||||
};
|
||||
|
||||
struct StagedContainedFixedMapItem {
|
||||
u16 itemNumber = 0;
|
||||
u16 parentItemNumber = 0;
|
||||
std::size_t recordIndex = 0;
|
||||
};
|
||||
|
||||
struct ItemFindArea {
|
||||
u16 minX = 0;
|
||||
u16 minY = 0;
|
||||
|
|
@ -41,6 +48,26 @@ struct ItemFindArea {
|
|||
u16 maxY = 0;
|
||||
};
|
||||
|
||||
struct StagedItemBlockChains {
|
||||
std::vector<u16> heads;
|
||||
std::vector<u16> next;
|
||||
};
|
||||
|
||||
struct ItemFindZCandidate {
|
||||
u16 itemNumber = 0;
|
||||
u8 matchType = 0;
|
||||
};
|
||||
|
||||
enum class ItemGrabActionKind {
|
||||
Hurl,
|
||||
CreateProcess
|
||||
};
|
||||
|
||||
struct ItemGrabAction {
|
||||
u16 itemNumber = 0;
|
||||
ItemGrabActionKind kind = ItemGrabActionKind::Hurl;
|
||||
};
|
||||
|
||||
struct FixedMapArchive {
|
||||
u32 mapCount = 0;
|
||||
std::vector<u8> bytes;
|
||||
|
|
@ -49,12 +76,43 @@ 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<std::vector<StagedContainedFixedMapItem>> stageContainedFixedMapItems(
|
||||
const FixedMap& map, const std::vector<ShapeTypeInfo>& shapes);
|
||||
std::optional<StagedFixedMapItem> nearestStagedFixedMapItem(
|
||||
const std::vector<StagedFixedMapItem>& items, s32 worldX, s32 worldY, s32 maxDistance);
|
||||
bool itemGrabCanCreateProcess(const StagedFixedMapItem& item);
|
||||
bool itemFallStartsHurl(const ShapeTypeInfo& shape);
|
||||
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);
|
||||
std::optional<StagedItemBlockChains> buildStagedItemBlockChains(const std::vector<StagedFixedMapItem>& items);
|
||||
std::vector<u16> itemFindCandidateOrder(const ItemFindArea& area, const StagedItemBlockChains& chains);
|
||||
std::optional<std::vector<ItemFindZCandidate>> itemFindZMatches(const StagedFixedMapItem& origin,
|
||||
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes, u8 zMatchFlags);
|
||||
std::optional<std::vector<ItemFindZCandidate>> itemGrabSearchCandidates(const StagedFixedMapItem& origin,
|
||||
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes);
|
||||
std::optional<std::vector<ItemGrabAction>> planItemGrabActions(const StagedFixedMapItem& origin,
|
||||
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes);
|
||||
std::optional<std::vector<u16>> dispatchStagedItemGrab(const StagedFixedMapItem& origin,
|
||||
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes,
|
||||
ProcessKernel& kernel, u16 (&groupCounts)[32], u32 timerTick);
|
||||
|
||||
class LiveFixedMapItems {
|
||||
public:
|
||||
explicit LiveFixedMapItems(std::vector<StagedFixedMapItem> items);
|
||||
const StagedFixedMapItem* findItem(u16 itemNumber) const;
|
||||
std::optional<StagedFixedMapItem> nearestItem(s32 worldX, s32 worldY, s32 maxDistance) const;
|
||||
bool insertItem(StagedFixedMapItem item);
|
||||
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;
|
||||
std::optional<std::vector<u16>> moveApprovedItem(u16 itemNumber, u16 x, u16 y, u8 z,
|
||||
const std::vector<ShapeTypeInfo>& shapes, ProcessKernel& kernel,
|
||||
u16 (&groupCounts)[32], u32 timerTick);
|
||||
|
||||
private:
|
||||
std::vector<StagedFixedMapItem> items_;
|
||||
};
|
||||
|
||||
} // namespace remorse
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ struct ShapeTypeInfo {
|
|||
u8 y = 0;
|
||||
u8 z = 0;
|
||||
u8 animationType = 0;
|
||||
u8 weight = 0;
|
||||
};
|
||||
|
||||
std::optional<std::vector<ShapeTypeInfo>> loadTypeFlags(const std::filesystem::path& path);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue