- 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.
90 lines
No EOL
4 KiB
C++
90 lines
No EOL
4 KiB
C++
#include "remorse/collision.h"
|
|
|
|
#include <cassert>
|
|
|
|
int main()
|
|
{
|
|
const auto outsideBounds = remorse::clampAreaSweepBounds({10, 20, 10}, {-3, 0x8000, 252});
|
|
assert(outsideBounds.destination.x == 0 && outsideBounds.destination.y == 0x7fff &&
|
|
outsideBounds.destination.z == 250 && outsideBounds.failedDirections == 7 &&
|
|
outsideBounds.failed);
|
|
const auto belowFloor = remorse::clampAreaSweepBounds({10, 20, 10}, {10, 20, -3});
|
|
assert(belowFloor.destination.z == 0 && belowFloor.failedDirections == 4 && !belowFloor.failed);
|
|
const auto withinBounds = remorse::clampAreaSweepBounds({10, 20, 10}, {12, 23, 11});
|
|
assert(withinBounds.failedDirections == 0 && !withinBounds.failed);
|
|
const auto gravityStep = remorse::planGravitySweep({100, 200, 250}, 3, -2, 4, 2, 3);
|
|
assert(gravityStep.destination.x == 109 && gravityStep.destination.y == 194);
|
|
assert(gravityStep.destination.z == 6 && gravityStep.nextZSpeed == -2);
|
|
const auto slowStep = remorse::planGravitySweep({100, 200, 0}, 3, -2, -4, 2, 0);
|
|
assert(slowStep.destination.x == 103 && slowStep.destination.y == 198);
|
|
assert(slowStep.destination.z == 252 && slowStep.nextZSpeed == -6);
|
|
const auto cappedStep = remorse::planGravitySweep({100, 200, 0}, 3, -2, 4, 2, 5);
|
|
assert(cappedStep.destination.x == 112 && cappedStep.destination.y == 192);
|
|
assert(cappedStep.destination.z == 16 && cappedStep.nextZSpeed == -4);
|
|
|
|
const remorse::CollisionBody actor{{100, 100, 0}, 96, 96, 80};
|
|
const remorse::CollisionBody wall{{300, 100, 0}, 64, 96, 128};
|
|
assert(!remorse::collisionBodiesOverlap(actor, wall));
|
|
assert(remorse::canMoveCollisionBody(actor, {200, 100, 0}, {wall}));
|
|
assert(!remorse::canMoveCollisionBody(actor, {260, 100, 0}, {wall}));
|
|
assert(!remorse::canMoveCollisionBody(actor, {400, 100, 0}, {wall}));
|
|
|
|
const remorse::CollisionBody floorBelow{{300, 100, -20}, 64, 96, 20};
|
|
const remorse::CollisionBody overhead{{300, 100, 80}, 64, 96, 32};
|
|
assert(!remorse::collisionBodiesOverlap(actor, floorBelow));
|
|
assert(!remorse::collisionBodiesOverlap(actor, overhead));
|
|
|
|
const remorse::CollisionBody initiallyOverlapping{{250, 100, 0}, 96, 96, 80};
|
|
assert(remorse::canMoveCollisionBody(initiallyOverlapping, {200, 100, 0}, {wall}));
|
|
assert(!remorse::canMoveCollisionBody(initiallyOverlapping, {400, 100, 0}, {wall}));
|
|
|
|
remorse::ShapeTypeInfo actorInfo;
|
|
actorInfo.x = 3;
|
|
actorInfo.y = 3;
|
|
actorInfo.z = 10;
|
|
actorInfo.flags = 0x2;
|
|
const remorse::CollisionBody authoredActor = remorse::makeCollisionBody({100, 100, 0}, actorInfo);
|
|
assert(authoredActor.extentX == 96);
|
|
assert(authoredActor.extentY == 96);
|
|
assert(authoredActor.extentZ == 80);
|
|
|
|
remorse::ShapeTypeInfo obstacleInfo;
|
|
obstacleInfo.x = 2;
|
|
obstacleInfo.y = 4;
|
|
obstacleInfo.z = 8;
|
|
const remorse::CollisionBody flipped = remorse::makeCollisionBody({300, 300, 0}, obstacleInfo, true);
|
|
assert(flipped.extentX == 128);
|
|
assert(flipped.extentY == 64);
|
|
|
|
remorse::FixedMap map;
|
|
remorse::FixedMapEntry solid;
|
|
solid.x = 500;
|
|
solid.y = 600;
|
|
solid.shape = 1;
|
|
map.entries.push_back(solid);
|
|
remorse::FixedMapEntry globParent;
|
|
globParent.x = 0x480;
|
|
globParent.y = 0x640;
|
|
globParent.shape = 2;
|
|
globParent.quality = 7;
|
|
map.entries.push_back(globParent);
|
|
|
|
std::vector<remorse::ShapeTypeInfo> shapeTypes(4);
|
|
shapeTypes[1] = obstacleInfo;
|
|
shapeTypes[1].flags = 0x2;
|
|
shapeTypes[2].family = 3;
|
|
shapeTypes[2].flags = 0x2;
|
|
shapeTypes[3] = obstacleInfo;
|
|
shapeTypes[3].flags = 0x2;
|
|
|
|
remorse::GlobObject glob;
|
|
glob.index = 7;
|
|
glob.entries.push_back(remorse::GlobObjectEntry{2, 3, 4, 3, 0});
|
|
const auto bodies = remorse::collectMapCollisionBodies(map, shapeTypes, {glob});
|
|
assert(bodies.size() == 2);
|
|
assert(bodies[0].location.x == 500 && bodies[0].location.y == 600);
|
|
assert(bodies[1].location.x == (0x480 & ~0x3ff) + 2 * 4 + 2);
|
|
assert(bodies[1].location.y == (0x640 & ~0x3ff) + 3 * 4 + 2);
|
|
assert(bodies[1].location.z == 4);
|
|
return 0;
|
|
} |