Refactor collision handling and item management in the Remorse project
- Introduced new structures for handling sweep impacts and collision results, including SweepItemImpact, SweepCandidateImpact, and SweepCollisionResult. - Implemented functions to check if a world point or sweep footprint is within a defined fast area. - Enhanced LiveFixedMapItems to manage contained items and support item allocation with parent-child relationships. - Updated collision detection logic to handle solid item impacts and collect sweep impacts from live items. - Added tests for new collision functionalities, including sweep impact resolution and candidate selection. - Modified existing tests to validate new item management features and ensure proper integration with the collision system.
This commit is contained in:
parent
b99fb59c12
commit
b3975ca41b
8 changed files with 467 additions and 8 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "remorse\fixed_map.h"
|
||||
|
|
@ -27,10 +28,48 @@ struct SweepBoundsResult {
|
|||
bool failed = false;
|
||||
};
|
||||
|
||||
struct SweepItemImpact {
|
||||
WorldPoint resolved{};
|
||||
u8 failedDirections = 0;
|
||||
};
|
||||
|
||||
struct SweepCandidateImpact {
|
||||
u16 itemNumber = 0;
|
||||
SweepItemImpact impact{};
|
||||
};
|
||||
|
||||
struct SweepCollisionResult {
|
||||
WorldPoint destination{};
|
||||
u16 firstCollision = 0;
|
||||
u8 failedDirections = 0;
|
||||
};
|
||||
|
||||
struct FastAreaRange {
|
||||
s32 minSum = 0;
|
||||
s32 maxSum = 0;
|
||||
s32 minDifference = 0;
|
||||
s32 maxDifference = 0;
|
||||
};
|
||||
|
||||
bool isWorldPointInFastArea(s32 x, s32 y, const FastAreaRange& range);
|
||||
bool isSweepFootprintInFastArea(WorldPoint from, WorldPoint destination,
|
||||
s32 extentX, s32 extentY, const FastAreaRange& range);
|
||||
WorldRect areaSweepCandidateBounds(WorldPoint from, WorldPoint destination, s32 extentX, s32 extentY);
|
||||
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);
|
||||
CollisionBody makeSweepItemBody(WorldPoint location, const ShapeTypeInfo& shapeInfo, bool flipped = false);
|
||||
std::optional<SweepItemImpact> sweepSolidItemImpact(
|
||||
const CollisionBody& moving, WorldPoint destination, const CollisionBody& obstacle);
|
||||
std::optional<std::vector<SweepCandidateImpact>> collectSolidSweepImpacts(
|
||||
const LiveFixedMapItems& items, u16 movingItemNumber, WorldPoint destination,
|
||||
const std::vector<ShapeTypeInfo>& shapes, const FastAreaRange& fastArea);
|
||||
SweepCollisionResult selectSolidSweepImpact(WorldPoint from, WorldPoint destination,
|
||||
const std::vector<SweepCandidateImpact>& impacts);
|
||||
std::optional<SweepCollisionResult> resolveSolidLiveSweep(
|
||||
const LiveFixedMapItems& items, u16 movingItemNumber, WorldPoint destination,
|
||||
const std::vector<ShapeTypeInfo>& shapes, const FastAreaRange& fastArea);
|
||||
bool collisionBodiesOverlap(const CollisionBody& left, const CollisionBody& right);
|
||||
bool canMoveCollisionBody(
|
||||
const CollisionBody& body,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
namespace remorse {
|
||||
|
||||
struct ShapeTypeInfo;
|
||||
struct WorldRect;
|
||||
class ProcessKernel;
|
||||
|
||||
struct FixedMapEntry {
|
||||
|
|
@ -100,9 +101,13 @@ std::optional<std::vector<u16>> dispatchStagedItemGrab(const StagedFixedMapItem&
|
|||
|
||||
class LiveFixedMapItems {
|
||||
public:
|
||||
explicit LiveFixedMapItems(std::vector<StagedFixedMapItem> items);
|
||||
explicit LiveFixedMapItems(std::vector<StagedFixedMapItem> items,
|
||||
std::vector<StagedContainedFixedMapItem> containedItems = {});
|
||||
const StagedFixedMapItem* findItem(u16 itemNumber) const;
|
||||
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);
|
||||
bool moveItem(u16 itemNumber, u16 x, u16 y, u8 z);
|
||||
std::optional<std::vector<u16>> grabItem(u16 itemNumber, const std::vector<ShapeTypeInfo>& shapes,
|
||||
|
|
@ -113,6 +118,9 @@ public:
|
|||
|
||||
private:
|
||||
std::vector<StagedFixedMapItem> items_;
|
||||
std::vector<bool> allocatedIds_;
|
||||
std::vector<u16> parentById_;
|
||||
u16 nextFreeItemNumber_ = 0x100;
|
||||
};
|
||||
|
||||
} // namespace remorse
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue