Implement gravity resolution and fast area calculations in collision handling
This commit is contained in:
parent
b3975ca41b
commit
2e16b2d524
8 changed files with 301 additions and 26 deletions
|
|
@ -328,9 +328,9 @@ The bounded staged dispatcher can now issue those actions against the host proce
|
|||
|
||||
The host-owned item move now follows `Item_MoveToPoint` (`10a0:1945`) through `ItemCache_Push`/`ItemCache_Poptocoords` (`10a8:1ced/1df5`) for two bounded cache effects: a moved item becomes the destination block's newest head, even when staying in the same block, and Z above `0xfa` is clamped. Caller-supplied item IDs can also be inserted at a block head. The host free-ID allocator uses the source `0x100..0x27ff` range, skips staged direct and contained records, and fails without mutation when exhausted. The window reserves staged contained IDs and retains their parent links; placing one in the world clears its parent while its children remain linked. Synthetic nested/exhaustion and retail-map tests pass. This does not yet implement returning freed IDs to the list, live inventory/container transfers, fast-area status, or viewport side effects.
|
||||
|
||||
The supported horizontal `GravityProcess_Run` path now issues `Item_Grab` at the old item position when Z speed is zero and X/Y speed is nonzero, then asks the injected sweep to approve movement. As in the source order, a refused sweep can leave a newly requested item process behind while the item stays put. The earlier no-mutation guarantee for a refused sweep applies only to the nonzero-Z path, which does not issue that request. The stationary zero-speed fall search, collision response, and automatic scheduler dispatch are still unported; a caller must provide shapes, group counts, and the sweep decision for this host-only branch.
|
||||
The supported horizontal `GravityProcess_Run` path now issues `Item_Grab` at the old item position when Z speed is zero and X/Y speed is nonzero, then asks the injected sweep to approve movement. As in the source order, a refused sweep can leave a newly requested item process behind while the item stays put. The earlier no-mutation guarantee for a refused sweep applies only to the nonzero-Z path, which does not issue that request. This callback-based unobstructed runner does not handle the stationary zero-speed fall search or collision response; a caller must provide shapes, group counts, and sweep approval.
|
||||
|
||||
The standalone `AreaSearch_SweepTestPt` bounds stage (`10e0:0b39`) clamps X/Y to `0..0x7fff` and Z to `0..0xfa`, reports failed-direction bits `1/2/4`, and distinguishes a horizontal hard failure from Z clamping. The source's `World_MapBlockInFastArea` (`10a8:0000`) rotated block predicate and eight-corner start/destination footprint gate are now testable with an explicit fast-area range. The sweep's item-iterator rectangle and live candidate query follow inclusive X/Y filtering and Y-then-X block order. The per-item sweep uses 16-unit X/Y extents, 8-unit Z extents with the source zero-height fallback, and six axis-face tests that report one-unit-before-contact points and failed-direction bits. A read-only live collector combines those tests with candidate order, shape solidity and flip flags, and an explicit fast-area range. The host now selects a solid hit in source order when any axis is strictly closer, retains the earlier hit on a tie, and accumulates direction bits across contacts; a live entry point returns the resulting point and first colliding item. Synthetic tests cover both directions on all axes, self-exclusion, non-solid items, chain order, flipped shapes, and candidate selection. It does not handle damaging-only or floor contacts, maintain live fast-area state, or drive gravity movement. The gravity runner still requires an explicit approved sweep callback.
|
||||
The standalone `AreaSearch_SweepTestPt` bounds stage (`10e0:0b39`) clamps X/Y to `0..0x7fff` and Z to `0..0xfa`, reports failed-direction bits `1/2/4`, and distinguishes a horizontal hard failure from Z clamping. The source's `World_MapBlockInFastArea` (`10a8:0000`) rotated block predicate and eight-corner start/destination footprint gate are testable with an explicit fast-area range. `World_CalcFastAreaLimits` (`10a8:0048`) now supplies the source sum ±5 / difference ±3 block window from a world center. The window refreshes a player-centered host range after movement and dispatches any owned gravity processes through its timed scheduler; it still does not create gravity entries or repaint moved map items in the static preview. The sweep's item-iterator rectangle and live candidate query follow inclusive X/Y filtering and Y-then-X block order. The per-item sweep uses 16-unit X/Y extents, 8-unit Z extents with the source zero-height fallback, and six axis-face tests that report one-unit-before-contact points and failed-direction bits. A read-only live collector combines those tests with candidate order, shape solidity and flip flags. The host selects a solid hit in source order when any axis is strictly closer, retains the earlier hit on a tie, and accumulates direction bits across contacts. Damaging-only face contacts are recorded in candidate order without blocking the resolved point. With an explicitly enabled floor-gap limit, the host also identifies the closest solid support beneath the destination footprint for source limits 0 and 9; this support metadata does not change the destination. The resolved sweep now reports fast-area failure at the original point with direction bits 1/2 and clamps out-of-range Z with bit 4; the gravity runner conservatively rejects these unsupported responses before mutation. `runResolvedGravity` moves an owned item to a solid-hit point after its strict process wake, damps and reverses horizontal speed on collision, and sleeps the process again. `scanResolvedGravity` dispatches this bounded runner through the host scheduler; tests verify a wall impact, a later move away, and no repeat within the same tick. The remaining gaps are vertical collision response, item status/cache writes, collision events, stationary fall search, and an actual window gravity producer and moving-item renderer. Original runtime parity remains unverified.
|
||||
|
||||
Original DOS debugging and runtime verification are postponed indefinitely until requested again. The DOSBox-X debugger session has been stopped; do not treat a live trace as a prerequisite for the source-port work below. Keep unverified parity claims labeled as such.
|
||||
|
||||
|
|
@ -339,8 +339,8 @@ Next source-port checks, in call-chain order:
|
|||
1. Keep the `0x23ff/0x2400` process item boundary until source-derived allocation limits support changing it; do not infer a wider live table from staged map IDs.
|
||||
2. Port the remaining scheduler interval/group transitions behind host timing boundaries using static code evidence, with runtime parity explicitly deferred.
|
||||
3. Port free-ID return/reuse and live container transfers while preserving contained parent/child links and process ownership.
|
||||
4. Add damaging-only and mode-dependent floor contacts, then combine the solid-hit result with bounds and fast-area failures before enabling collision-driven movement.
|
||||
5. Port the `GravityProcess_Run` area sweep, collision responses, and item-cache position/status writes to make created gravity entries move real items after their sleep.
|
||||
4. Carry source sweep mode flags through callers and implement vertical collision responses for supported item/status branches; bounds and fast-area failures are now explicit but conservatively rejected by gravity.
|
||||
5. Extend scheduled gravity with item status/cache writes and collision events; add a real window gravity producer and dynamic item renderer before claiming visible gameplay movement.
|
||||
6. Connect the approved-move `Item_Grab` path to a ported `Item_LegalMoveToPointWithCollisionInfo` sweep and item-cache lifecycle, without changing the separate Windows `F` release fixture.
|
||||
7. Lift `EntityVmContext::CreateFromSlotIndex` (`1420:0eec`) and its interpreter initialization; keep release event-body lookup diagnostic until the VM executes it.
|
||||
|
||||
|
|
|
|||
|
|
@ -36,12 +36,18 @@ struct SweepItemImpact {
|
|||
struct SweepCandidateImpact {
|
||||
u16 itemNumber = 0;
|
||||
SweepItemImpact impact{};
|
||||
bool damaging = false;
|
||||
std::optional<u8> floorGap;
|
||||
};
|
||||
|
||||
struct SweepCollisionResult {
|
||||
WorldPoint destination{};
|
||||
u16 firstCollision = 0;
|
||||
u8 failedDirections = 0;
|
||||
std::vector<u16> damagingContacts;
|
||||
u16 supportItem = 0;
|
||||
std::optional<u8> supportGap;
|
||||
bool failed = false;
|
||||
};
|
||||
|
||||
struct FastAreaRange {
|
||||
|
|
@ -51,6 +57,7 @@ struct FastAreaRange {
|
|||
s32 maxDifference = 0;
|
||||
};
|
||||
|
||||
FastAreaRange calculateFastAreaRange(WorldPoint center);
|
||||
bool isWorldPointInFastArea(s32 x, s32 y, const FastAreaRange& range);
|
||||
bool isSweepFootprintInFastArea(WorldPoint from, WorldPoint destination,
|
||||
s32 extentX, s32 extentY, const FastAreaRange& range);
|
||||
|
|
@ -62,14 +69,16 @@ CollisionBody makeCollisionBody(WorldPoint location, const ShapeTypeInfo& shapeI
|
|||
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(
|
||||
std::optional<std::vector<SweepCandidateImpact>> collectSweepItemImpacts(
|
||||
const LiveFixedMapItems& items, u16 movingItemNumber, WorldPoint destination,
|
||||
const std::vector<ShapeTypeInfo>& shapes, const FastAreaRange& fastArea);
|
||||
const std::vector<ShapeTypeInfo>& shapes, const FastAreaRange& fastArea,
|
||||
std::optional<u8> floorGapLimit = std::nullopt);
|
||||
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);
|
||||
const std::vector<ShapeTypeInfo>& shapes, const FastAreaRange& fastArea,
|
||||
std::optional<u8> floorGapLimit = std::nullopt);
|
||||
bool collisionBodiesOverlap(const CollisionBody& left, const CollisionBody& right);
|
||||
bool canMoveCollisionBody(
|
||||
const CollisionBody& body,
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ namespace remorse {
|
|||
class LiveFixedMapItems;
|
||||
struct ShapeTypeInfo;
|
||||
struct WorldPoint;
|
||||
struct FastAreaRange;
|
||||
|
||||
CR_PACK_PUSH_1
|
||||
struct EntityDispatchEntryBase {
|
||||
|
|
@ -87,6 +88,12 @@ public:
|
|||
bool (*approveSweep)(u16 itemNumber, const WorldPoint& from, const WorldPoint& to, void* context),
|
||||
void* context, const std::vector<ShapeTypeInfo>* shapes = nullptr,
|
||||
u16 (*groupCounts)[32] = nullptr);
|
||||
bool runResolvedGravity(u16 processId, LiveFixedMapItems& items,
|
||||
const std::vector<ShapeTypeInfo>& shapes, const FastAreaRange& fastArea,
|
||||
u32 timeScale, u32 timerTick, u16 (&groupCounts)[32]);
|
||||
u32 scanResolvedGravity(u8 activeGroup, LiveFixedMapItems& items,
|
||||
const std::vector<ShapeTypeInfo>& shapes, const FastAreaRange& fastArea,
|
||||
u32 timeScale, u32 timerTick, u16 (&groupCounts)[32]);
|
||||
SystemTimerProcessEntry* createSystemTimerProcess(u8 activeGroup, u16 (&groupCounts)[32]);
|
||||
KeyboardProcessEntry* createKeyboardProcess(u8 activeGroup, u16 (&groupCounts)[32]);
|
||||
KeyDaemonProcessEntry* createKeyDaemonProcess(u8 activeGroup, u16 (&groupCounts)[32]);
|
||||
|
|
|
|||
|
|
@ -78,6 +78,15 @@ void appendSolidBody(std::vector<CollisionBody>& bodies, const std::vector<Shape
|
|||
|
||||
} // namespace
|
||||
|
||||
FastAreaRange calculateFastAreaRange(WorldPoint center)
|
||||
{
|
||||
const s32 blockX = center.x >> 9;
|
||||
const s32 blockY = center.y >> 9;
|
||||
const s32 sum = blockX + blockY;
|
||||
const s32 difference = blockX - blockY;
|
||||
return {sum - 5, sum + 5, difference - 3, difference + 3};
|
||||
}
|
||||
|
||||
bool isWorldPointInFastArea(s32 x, s32 y, const FastAreaRange& range)
|
||||
{
|
||||
if (x < 0 || x > 0x7fff || y < 0 || y > 0x7fff) {
|
||||
|
|
@ -219,9 +228,10 @@ std::optional<SweepItemImpact> sweepSolidItemImpact(
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<std::vector<SweepCandidateImpact>> collectSolidSweepImpacts(
|
||||
std::optional<std::vector<SweepCandidateImpact>> collectSweepItemImpacts(
|
||||
const LiveFixedMapItems& items, u16 movingItemNumber, WorldPoint destination,
|
||||
const std::vector<ShapeTypeInfo>& shapes, const FastAreaRange& fastArea)
|
||||
const std::vector<ShapeTypeInfo>& shapes, const FastAreaRange& fastArea,
|
||||
std::optional<u8> floorGapLimit)
|
||||
{
|
||||
const auto* movingItem = items.findItem(movingItemNumber);
|
||||
if (movingItem == nullptr || movingItem->data.shape >= shapes.size() ||
|
||||
|
|
@ -248,13 +258,27 @@ std::optional<std::vector<SweepCandidateImpact>> collectSolidSweepImpacts(
|
|||
return std::nullopt;
|
||||
}
|
||||
const auto& shape = shapes[item->data.shape];
|
||||
if ((shape.flags & solidFlag) == 0) {
|
||||
continue;
|
||||
}
|
||||
const auto obstacle = makeSweepItemBody({item->data.x, item->data.y, item->data.z},
|
||||
shape, (item->data.flags & flippedFlag) != 0);
|
||||
std::optional<u8> floorGap;
|
||||
const s32 gap = destination.z - item->data.z - obstacle.extentZ;
|
||||
if (floorGapLimit && (shape.flags & solidFlag) != 0 && gap >= 0 &&
|
||||
gap <= *floorGapLimit &&
|
||||
destination.x - movingBody.extentX + 1 <= item->data.x &&
|
||||
item->data.x - obstacle.extentX + 1 <= destination.x &&
|
||||
destination.y - movingBody.extentY + 1 <= item->data.y &&
|
||||
item->data.y - obstacle.extentY + 1 <= destination.y) {
|
||||
floorGap = static_cast<u8>(gap);
|
||||
}
|
||||
if ((shape.flags & (solidFlag | 0x40)) == 0) {
|
||||
continue;
|
||||
}
|
||||
if (const auto impact = sweepSolidItemImpact(movingBody, destination, obstacle)) {
|
||||
impacts.push_back({itemNumber, *impact});
|
||||
impacts.push_back({itemNumber,
|
||||
{impact->resolved, (shape.flags & solidFlag) != 0 ? impact->failedDirections : u8{0}},
|
||||
(shape.flags & 0x40) != 0, floorGap});
|
||||
} else if (floorGap) {
|
||||
impacts.push_back({itemNumber, {}, false, floorGap});
|
||||
}
|
||||
}
|
||||
return impacts;
|
||||
|
|
@ -265,9 +289,16 @@ SweepCollisionResult selectSolidSweepImpact(WorldPoint from, WorldPoint destinat
|
|||
{
|
||||
SweepCollisionResult result{destination};
|
||||
for (const auto& candidate : impacts) {
|
||||
if (candidate.floorGap && (!result.supportGap || *candidate.floorGap <= *result.supportGap)) {
|
||||
result.supportItem = candidate.itemNumber;
|
||||
result.supportGap = candidate.floorGap;
|
||||
}
|
||||
if (candidate.damaging) {
|
||||
result.damagingContacts.push_back(candidate.itemNumber);
|
||||
}
|
||||
result.failedDirections |= candidate.impact.failedDirections;
|
||||
const auto& point = candidate.impact.resolved;
|
||||
if (candidate.itemNumber != 0 &&
|
||||
if (candidate.itemNumber != 0 && candidate.impact.failedDirections != 0 &&
|
||||
(std::abs(static_cast<std::int64_t>(point.x) - from.x) <
|
||||
std::abs(static_cast<std::int64_t>(result.destination.x) - from.x) ||
|
||||
std::abs(static_cast<std::int64_t>(point.y) - from.y) <
|
||||
|
|
@ -283,19 +314,31 @@ SweepCollisionResult selectSolidSweepImpact(WorldPoint from, WorldPoint destinat
|
|||
|
||||
std::optional<SweepCollisionResult> resolveSolidLiveSweep(
|
||||
const LiveFixedMapItems& items, u16 movingItemNumber, WorldPoint destination,
|
||||
const std::vector<ShapeTypeInfo>& shapes, const FastAreaRange& fastArea)
|
||||
const std::vector<ShapeTypeInfo>& shapes, const FastAreaRange& fastArea,
|
||||
std::optional<u8> floorGapLimit)
|
||||
{
|
||||
const auto* movingItem = items.findItem(movingItemNumber);
|
||||
if (movingItem == nullptr) {
|
||||
if (movingItem == nullptr || movingItem->data.shape >= shapes.size()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
const auto impacts = collectSolidSweepImpacts(items, movingItemNumber, destination,
|
||||
shapes, fastArea);
|
||||
const WorldPoint from{movingItem->data.x, movingItem->data.y, movingItem->data.z};
|
||||
const auto bounds = clampAreaSweepBounds(from, destination);
|
||||
const auto body = makeSweepItemBody(from, shapes[movingItem->data.shape],
|
||||
(movingItem->data.flags & flippedFlag) != 0);
|
||||
if (!isSweepFootprintInFastArea(from, destination, body.extentX, body.extentY, fastArea)) {
|
||||
SweepCollisionResult result{from};
|
||||
result.failedDirections = static_cast<u8>(bounds.failedDirections | 3);
|
||||
result.failed = true;
|
||||
return result;
|
||||
}
|
||||
const auto impacts = collectSweepItemImpacts(items, movingItemNumber, bounds.destination,
|
||||
shapes, fastArea, floorGapLimit);
|
||||
if (!impacts) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return selectSolidSweepImpact({movingItem->data.x, movingItem->data.y, movingItem->data.z},
|
||||
destination, *impacts);
|
||||
auto result = selectSolidSweepImpact(from, bounds.destination, *impacts);
|
||||
result.failedDirections |= bounds.failedDirections;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool collisionBodiesOverlap(const CollisionBody& left, const CollisionBody& right)
|
||||
|
|
|
|||
|
|
@ -233,6 +233,86 @@ bool ProcessKernel::runUnobstructedGravity(u16 processId, LiveFixedMapItems& ite
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ProcessKernel::runResolvedGravity(u16 processId, LiveFixedMapItems& items,
|
||||
const std::vector<ShapeTypeInfo>& shapes, const FastAreaRange& fastArea,
|
||||
u32 timeScale, u32 timerTick, u16 (&groupCounts)[32])
|
||||
{
|
||||
const auto* process = processAt(processId);
|
||||
if (process == nullptr || allocationSizeAt(processId) != sizeof(GravityProcessEntry) ||
|
||||
(process->bytes[0x16] & 0x08) != 0 || (process->bytes[0x19] & 0x10) != 0 ||
|
||||
std::none_of(ownedGravityProcesses_.begin(), ownedGravityProcesses_.end(),
|
||||
[process](const auto& owned) { return &owned->base == process; })) {
|
||||
return false;
|
||||
}
|
||||
const u16 itemNumber = readLe16(*process, 0x04);
|
||||
const auto* item = items.findItem(itemNumber);
|
||||
const auto zSpeed = static_cast<s16>(readLe16(*process, 0x36));
|
||||
if (item == nullptr || item->data.z > 250) {
|
||||
return false;
|
||||
}
|
||||
if (zSpeed == 0 &&
|
||||
((readLe16(*process, 0x32) == 0 && readLe16(*process, 0x34) == 0) ||
|
||||
!items.grabItem(itemNumber, shapes, *this, groupCounts, timerTick))) {
|
||||
return false;
|
||||
}
|
||||
const WorldPoint from{item->data.x, item->data.y, item->data.z};
|
||||
const auto step = planGravitySweep(from, static_cast<s16>(readLe16(*process, 0x32)),
|
||||
static_cast<s16>(readLe16(*process, 0x34)), zSpeed,
|
||||
static_cast<s16>(readLe16(*process, 0x38)), timeScale);
|
||||
const auto sweep = resolveSolidLiveSweep(items, itemNumber, step.destination, shapes, fastArea);
|
||||
if (!sweep || sweep->failed || (sweep->failedDirections & 4) != 0) {
|
||||
return false;
|
||||
}
|
||||
const auto& resolved = sweep->destination;
|
||||
if (!items.moveItem(itemNumber, static_cast<u16>(resolved.x),
|
||||
static_cast<u16>(resolved.y), static_cast<u8>(resolved.z))) {
|
||||
return false;
|
||||
}
|
||||
auto* mutableProcess = processAt(processId);
|
||||
auto nextZSpeed = step.nextZSpeed;
|
||||
if (sweep->failedDirections != 0) {
|
||||
const auto damped = [](s16 speed) {
|
||||
return static_cast<s16>((static_cast<s32>(speed) + (speed < 0 ? 1 : 0)) >> 2);
|
||||
};
|
||||
nextZSpeed = damped(nextZSpeed);
|
||||
for (const u8 axis : {u8{1}, u8{2}}) {
|
||||
const u16 offset = axis == 1 ? 0x32 : 0x34;
|
||||
const s16 speed = static_cast<s16>(readLe16(*mutableProcess, offset));
|
||||
const s16 response = static_cast<s16>((sweep->failedDirections & axis) != 0 ?
|
||||
-damped(speed) : damped(speed));
|
||||
writeLe16(*mutableProcess, offset, static_cast<u16>(response));
|
||||
}
|
||||
}
|
||||
writeLe16(*mutableProcess, 0x36, static_cast<u16>(nextZSpeed));
|
||||
EntityDispatchEntry::sleep(*mutableProcess, timerTick, 4 * std::clamp(timeScale, 1u, 4u));
|
||||
return true;
|
||||
}
|
||||
|
||||
u32 ProcessKernel::scanResolvedGravity(u8 activeGroup, LiveFixedMapItems& items,
|
||||
const std::vector<ShapeTypeInfo>& shapes, const FastAreaRange& fastArea,
|
||||
u32 timeScale, u32 timerTick, u16 (&groupCounts)[32])
|
||||
{
|
||||
struct ScanContext {
|
||||
ProcessKernel& kernel;
|
||||
LiveFixedMapItems& items;
|
||||
const std::vector<ShapeTypeInfo>& shapes;
|
||||
const FastAreaRange& fastArea;
|
||||
u32 timeScale;
|
||||
u32 timerTick;
|
||||
u16 (&groupCounts)[32];
|
||||
u32 moved = 0;
|
||||
} context{*this, items, shapes, fastArea, timeScale, timerTick, groupCounts};
|
||||
scanRunnableProcesses(activeGroup, [](EntityDispatchEntryBase& process, void* state) {
|
||||
auto& scan = *static_cast<ScanContext*>(state);
|
||||
if (readLe16(process, 0x00) == 0x0610 &&
|
||||
scan.kernel.runResolvedGravity(readLe16(process, 0x02), scan.items,
|
||||
scan.shapes, scan.fastArea, scan.timeScale, scan.timerTick, scan.groupCounts)) {
|
||||
++scan.moved;
|
||||
}
|
||||
}, &context, timerTick);
|
||||
return context.moved;
|
||||
}
|
||||
|
||||
SystemTimerProcessEntry* ProcessKernel::createSystemTimerProcess(u8 activeGroup, u16 (&groupCounts)[32])
|
||||
{
|
||||
if (systemTimerProcess_ != nullptr) {
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ struct AppState {
|
|||
std::vector<std::uint8_t> viewPixels;
|
||||
remorse::WorldPoint spawn{};
|
||||
remorse::WorldPoint playerWorld{};
|
||||
remorse::FastAreaRange fastArea{};
|
||||
remorse::s32 minWorldX = 0;
|
||||
remorse::s32 minWorldY = 0;
|
||||
remorse::s32 maxWorldX = 0;
|
||||
|
|
@ -272,6 +273,7 @@ void loadSceneAsync(HWND window, AppState& state)
|
|||
std::lock_guard<std::mutex> lock(state.sceneMutex);
|
||||
state.spawn = spawn;
|
||||
state.playerWorld = spawn;
|
||||
state.fastArea = remorse::calculateFastAreaRange(spawn);
|
||||
state.playerCollisionBody = remorse::makeCollisionBody(spawn, (*shapeTypes)[1]);
|
||||
state.collisionBodies = std::move(collisionBodies);
|
||||
state.shapeTypes = *shapeTypes;
|
||||
|
|
@ -646,6 +648,12 @@ void updatePlayer(HWND window, AppState& state)
|
|||
}
|
||||
}
|
||||
}, &app);
|
||||
} else if (entry.bytes[0] == 0x10 && entry.bytes[1] == 0x06 && app.liveItems) {
|
||||
const remorse::u16 processId = static_cast<remorse::u16>(entry.bytes[2] |
|
||||
(static_cast<remorse::u16>(entry.bytes[3]) << 8));
|
||||
app.diagnosticKernel.runResolvedGravity(processId, *app.liveItems,
|
||||
app.shapeTypes, app.fastArea, 1, app.diagnosticKernel.systemTimerTick(),
|
||||
app.diagnosticGroupCounts);
|
||||
}
|
||||
}, &state);
|
||||
state.diagnosticKernel.refreshActiveGroup(state.diagnosticGroupCounts);
|
||||
|
|
@ -697,6 +705,7 @@ void updatePlayer(HWND window, AppState& state)
|
|||
if (withinMapBounds && withinSceneBounds && remorse::canMoveCollisionBody(
|
||||
state.playerCollisionBody, destination, state.collisionBodies)) {
|
||||
state.playerWorld = destination;
|
||||
state.fastArea = remorse::calculateFastAreaRange(destination);
|
||||
state.playerCollisionBody.location = destination;
|
||||
state.playerOffsetX = nextOffsetX;
|
||||
state.playerOffsetY = nextOffsetY;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,14 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
const auto centeredArea = remorse::calculateFastAreaRange({512, 512, 0});
|
||||
assert(centeredArea.minSum == -3 && centeredArea.maxSum == 7 &&
|
||||
centeredArea.minDifference == -3 && centeredArea.maxDifference == 3);
|
||||
assert(remorse::isWorldPointInFastArea(512, 512, centeredArea));
|
||||
assert(!remorse::isWorldPointInFastArea(4096, 512, centeredArea));
|
||||
const auto beforeBlockCrossing = remorse::calculateFastAreaRange({511, 512, 0});
|
||||
assert(beforeBlockCrossing.minSum == centeredArea.minSum - 1 &&
|
||||
beforeBlockCrossing.minDifference == centeredArea.minDifference - 1);
|
||||
const remorse::FastAreaRange fastArea{2, 4, 0, 2};
|
||||
assert(remorse::isWorldPointInFastArea(512, 512, fastArea));
|
||||
assert(!remorse::isWorldPointInFastArea(-1, 512, fastArea));
|
||||
|
|
@ -126,7 +134,7 @@ int main()
|
|||
sweepShapes[2].flags = 2;
|
||||
sweepShapes[3] = sweepShapes[1];
|
||||
const remorse::FastAreaRange allBlocks{-128, 128, -128, 128};
|
||||
const auto liveImpacts = remorse::collectSolidSweepImpacts(liveSweepItems, 0x100,
|
||||
const auto liveImpacts = remorse::collectSweepItemImpacts(liveSweepItems, 0x100,
|
||||
{700, 512, 0}, sweepShapes, allBlocks);
|
||||
assert(liveImpacts && liveImpacts->size() == 1);
|
||||
assert((*liveImpacts)[0].itemNumber == 0x101 &&
|
||||
|
|
@ -139,7 +147,7 @@ int main()
|
|||
sweepShapes[2].y = 4;
|
||||
wallItem.data.flags = 0x20;
|
||||
remorse::LiveFixedMapItems flippedSweepItems({movingItem, wallItem, nextWall, harmlessItem});
|
||||
const auto flippedImpacts = remorse::collectSolidSweepImpacts(flippedSweepItems, 0x100,
|
||||
const auto flippedImpacts = remorse::collectSweepItemImpacts(flippedSweepItems, 0x100,
|
||||
{700, 512, 0}, sweepShapes, allBlocks);
|
||||
assert(flippedImpacts && flippedImpacts->size() == 2);
|
||||
assert((*flippedImpacts)[0].itemNumber == 0x103 && (*flippedImpacts)[0].impact.resolved.x == 654);
|
||||
|
|
@ -152,8 +160,18 @@ int main()
|
|||
{700, 512, 0}, sweepShapes, allBlocks);
|
||||
assert(resolvedLive && resolvedLive->firstCollision == 0x101 &&
|
||||
resolvedLive->destination.x == 576 && resolvedLive->failedDirections == 1);
|
||||
assert(!remorse::resolveSolidLiveSweep(flippedSweepItems, 0x100,
|
||||
{700, 512, 0}, sweepShapes, {2, 2, 0, 0}));
|
||||
const auto outsideFastArea = remorse::resolveSolidLiveSweep(flippedSweepItems, 0x100,
|
||||
{700, 512, 0}, sweepShapes, {2, 2, 0, 0});
|
||||
assert(outsideFastArea && outsideFastArea->failed &&
|
||||
outsideFastArea->destination.x == 512 && outsideFastArea->failedDirections == 3);
|
||||
const auto outsideWorld = remorse::resolveSolidLiveSweep(flippedSweepItems, 0x100,
|
||||
{-1, 512, 0}, sweepShapes, allBlocks);
|
||||
assert(outsideWorld && outsideWorld->failed && outsideWorld->failedDirections == 3 &&
|
||||
outsideWorld->destination.x == 512);
|
||||
const auto aboveCeiling = remorse::resolveSolidLiveSweep(flippedSweepItems, 0x100,
|
||||
{512, 512, 251}, sweepShapes, allBlocks);
|
||||
assert(aboveCeiling && !aboveCeiling->failed && aboveCeiling->failedDirections == 4 &&
|
||||
aboveCeiling->destination.z == 250);
|
||||
const auto noImpact = remorse::selectSolidSweepImpact({512, 512, 0}, {700, 512, 0}, {});
|
||||
assert(noImpact.firstCollision == 0 && noImpact.destination.x == 700 &&
|
||||
noImpact.failedDirections == 0);
|
||||
|
|
@ -168,9 +186,49 @@ int main()
|
|||
{700, 700, 0}, mixedAxisImpacts);
|
||||
assert(mixedAxis.firstCollision == 0x103 && mixedAxis.destination.x == 550 &&
|
||||
mixedAxis.destination.y == 550 && mixedAxis.failedDirections == 3);
|
||||
assert(!remorse::collectSolidSweepImpacts(liveSweepItems, 0x100,
|
||||
sweepShapes[3].flags = 0x40;
|
||||
remorse::LiveFixedMapItems damagingItems({movingItem, harmlessItem});
|
||||
const auto damageOnly = remorse::resolveSolidLiveSweep(damagingItems, 0x100,
|
||||
{700, 512, 0}, sweepShapes, allBlocks);
|
||||
assert(damageOnly && damageOnly->firstCollision == 0 &&
|
||||
damageOnly->destination.x == 700 && damageOnly->failedDirections == 0 &&
|
||||
(damageOnly->damagingContacts == std::vector<remorse::u16>{0x102}));
|
||||
movingItem.data.z = 32;
|
||||
wallItem.data.x = 512;
|
||||
wallItem.data.z = 16;
|
||||
remorse::LiveFixedMapItems floorItems({movingItem, wallItem});
|
||||
const auto floorDisabled = remorse::resolveSolidLiveSweep(floorItems, 0x100,
|
||||
{512, 512, 32}, sweepShapes, allBlocks);
|
||||
assert(floorDisabled && floorDisabled->supportItem == 0);
|
||||
const auto floorTouch = remorse::resolveSolidLiveSweep(floorItems, 0x100,
|
||||
{512, 512, 32}, sweepShapes, allBlocks, remorse::u8{0});
|
||||
assert(floorTouch && floorTouch->supportItem == 0x101 && floorTouch->supportGap == 0 &&
|
||||
floorTouch->destination.z == 32 && floorTouch->firstCollision == 0);
|
||||
const auto floorStep = remorse::resolveSolidLiveSweep(floorItems, 0x100,
|
||||
{512, 512, 41}, sweepShapes, allBlocks, remorse::u8{9});
|
||||
assert(floorStep && floorStep->supportGap == 9 && floorStep->destination.z == 41);
|
||||
const auto floorTooFar = remorse::resolveSolidLiveSweep(floorItems, 0x100,
|
||||
{512, 512, 42}, sweepShapes, allBlocks, remorse::u8{9});
|
||||
assert(floorTooFar && !floorTooFar->supportGap);
|
||||
auto lowerFloor = wallItem;
|
||||
lowerFloor.itemNumber = 0x104;
|
||||
lowerFloor.data.z = 17;
|
||||
remorse::LiveFixedMapItems layeredFloorItems({movingItem, wallItem, lowerFloor});
|
||||
const auto closestFloor = remorse::resolveSolidLiveSweep(layeredFloorItems, 0x100,
|
||||
{512, 512, 41}, sweepShapes, allBlocks, remorse::u8{9});
|
||||
assert(closestFloor && closestFloor->supportItem == 0x104 && closestFloor->supportGap == 8);
|
||||
lowerFloor.data.x = 650;
|
||||
remorse::LiveFixedMapItems distantFloorItems({movingItem, lowerFloor});
|
||||
const auto outsideFootprint = remorse::resolveSolidLiveSweep(distantFloorItems, 0x100,
|
||||
{512, 512, 37}, sweepShapes, allBlocks, remorse::u8{9});
|
||||
assert(outsideFootprint && !outsideFootprint->supportGap);
|
||||
sweepShapes[2].flags = 0x40;
|
||||
const auto damagingFloor = remorse::resolveSolidLiveSweep(floorItems, 0x100,
|
||||
{512, 512, 32}, sweepShapes, allBlocks, remorse::u8{0});
|
||||
assert(damagingFloor && !damagingFloor->supportGap);
|
||||
assert(!remorse::collectSweepItemImpacts(liveSweepItems, 0x100,
|
||||
{700, 512, 0}, sweepShapes, {2, 2, 0, 0}));
|
||||
assert(!remorse::collectSolidSweepImpacts(liveSweepItems, 0x105,
|
||||
assert(!remorse::collectSweepItemImpacts(liveSweepItems, 0x105,
|
||||
{700, 512, 0}, sweepShapes, allBlocks));
|
||||
|
||||
remorse::FixedMap map;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#include "remorse/collision.h"
|
||||
#include "remorse/entity_dispatch_entry.h"
|
||||
#include "remorse/fixed_map.h"
|
||||
#include "remorse/map_renderer.h"
|
||||
|
|
@ -583,6 +584,74 @@ int main()
|
|||
horizontalKernel.processCount() == 6);
|
||||
assert(horizontalKernel.processAt(horizontalId)->bytes[0x36] == 0xfe &&
|
||||
horizontalKernel.processAt(horizontalId)->bytes[0x37] == 0xff);
|
||||
remorse::ProcessKernel resolvedKernel;
|
||||
remorse::u16 resolvedGroups[32]{};
|
||||
for (int index = 0; index < 3; ++index) {
|
||||
resolvedKernel.createProcess(1, resolvedGroups);
|
||||
}
|
||||
remorse::StagedFixedMapItem movingGravityItem = fallingItem;
|
||||
movingGravityItem.data.x = 512;
|
||||
movingGravityItem.data.y = 512;
|
||||
movingGravityItem.data.z = 80;
|
||||
movingGravityItem.data.shape = 1;
|
||||
auto gravityWall = movingGravityItem;
|
||||
gravityWall.itemNumber = 0x101;
|
||||
gravityWall.data.x = 600;
|
||||
gravityWall.data.shape = 2;
|
||||
remorse::LiveFixedMapItems resolvedItems({movingGravityItem, gravityWall});
|
||||
std::vector<remorse::ShapeTypeInfo> resolvedShapes(3);
|
||||
resolvedShapes[1].x = resolvedShapes[1].y = resolvedShapes[1].z = 2;
|
||||
resolvedShapes[2] = resolvedShapes[1];
|
||||
resolvedShapes[2].flags = 2;
|
||||
const remorse::FastAreaRange resolvedFastArea{-128, 128, -128, 128};
|
||||
const auto resolvedId = resolvedKernel.hurlItem(1, 0x100, 100, 0, 2, 2, 0, resolvedGroups);
|
||||
assert(!resolvedKernel.runResolvedGravity(resolvedId, resolvedItems,
|
||||
resolvedShapes, resolvedFastArea, 1, 0, resolvedGroups));
|
||||
resolvedKernel.scanRunnableProcesses(1, countGravityRun, &gravityRuns, 21);
|
||||
assert(resolvedKernel.runResolvedGravity(resolvedId, resolvedItems,
|
||||
resolvedShapes, resolvedFastArea, 1, 21, resolvedGroups));
|
||||
assert(resolvedItems.findItem(0x100)->data.x == 568 &&
|
||||
resolvedItems.findItem(0x100)->data.z == 81);
|
||||
const auto* resolvedProcess = resolvedKernel.processAt(resolvedId);
|
||||
assert(resolvedProcess->bytes[0x32] == 0xe7 && resolvedProcess->bytes[0x33] == 0xff &&
|
||||
resolvedProcess->bytes[0x36] == 0 && (resolvedProcess->bytes[0x19] & 0x10) != 0 &&
|
||||
resolvedProcess->bytes[0x0e] == 4);
|
||||
assert(!resolvedKernel.runResolvedGravity(resolvedId, resolvedItems,
|
||||
resolvedShapes, resolvedFastArea, 1, 22, resolvedGroups));
|
||||
resolvedKernel.scanRunnableProcesses(1, countGravityRun, &gravityRuns, 26);
|
||||
assert(!resolvedKernel.runResolvedGravity(resolvedId, resolvedItems,
|
||||
resolvedShapes, {2, 2, 0, 0}, 1, 26, resolvedGroups));
|
||||
assert(resolvedItems.findItem(0x100)->data.x == 568 &&
|
||||
resolvedKernel.processAt(resolvedId)->bytes[0x32] == 0xe7);
|
||||
assert(resolvedKernel.runResolvedGravity(resolvedId, resolvedItems,
|
||||
resolvedShapes, resolvedFastArea, 1, 26, resolvedGroups));
|
||||
assert(resolvedItems.findItem(0x100)->data.x == 543 &&
|
||||
resolvedItems.findItem(0x100)->data.z == 81 &&
|
||||
resolvedKernel.processAt(resolvedId)->bytes[0x36] == 0xfe);
|
||||
assert(resolvedKernel.scanResolvedGravity(1, resolvedItems, resolvedShapes,
|
||||
resolvedFastArea, 1, 30, resolvedGroups) == 0);
|
||||
assert(resolvedKernel.scanResolvedGravity(1, resolvedItems, resolvedShapes,
|
||||
resolvedFastArea, 1, 31, resolvedGroups) == 1);
|
||||
assert(resolvedItems.findItem(0x100)->data.x == 518 &&
|
||||
resolvedItems.findItem(0x100)->data.z == 79);
|
||||
assert(resolvedKernel.scanResolvedGravity(1, resolvedItems, resolvedShapes,
|
||||
resolvedFastArea, 1, 31, resolvedGroups) == 0);
|
||||
remorse::ProcessKernel verticalKernel;
|
||||
remorse::u16 verticalGroups[32]{};
|
||||
for (int index = 0; index < 3; ++index) {
|
||||
verticalKernel.createProcess(1, verticalGroups);
|
||||
}
|
||||
movingGravityItem.data.z = 40;
|
||||
gravityWall.data.x = 512;
|
||||
gravityWall.data.z = 20;
|
||||
remorse::LiveFixedMapItems verticalItems({movingGravityItem, gravityWall});
|
||||
const auto verticalId = verticalKernel.hurlItem(1, 0x100, 0, 0, -20, 2, 0, verticalGroups);
|
||||
verticalKernel.scanRunnableProcesses(1, countGravityRun, &gravityRuns, 21);
|
||||
assert(!verticalKernel.runResolvedGravity(verticalId, verticalItems,
|
||||
resolvedShapes, resolvedFastArea, 1, 21, verticalGroups));
|
||||
assert(verticalItems.findItem(0x100)->data.z == 40 &&
|
||||
verticalKernel.processAt(verticalId)->bytes[0x36] == 0xec &&
|
||||
(verticalKernel.processAt(verticalId)->bytes[0x19] & 0x10) == 0);
|
||||
gravityKernel.terminateProcess(gravityId, gravityGroups);
|
||||
assert(gravityKernel.findProcessForItemAndType(0x100, 0x203) == nullptr);
|
||||
gravityKernel.clearTerminatedProcesses();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue