Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pskelton committed Nov 16, 2023
1 parent 21aaf55 commit ee8decf
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 33 deletions.
37 changes: 16 additions & 21 deletions src/Engine/Graphics/Collisions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,11 @@ static bool CollideWithCylinder(const Vec3f &center_lo, float radius, float heig

float newdist, intersection;
if (CollideWithLine(vert1, vert2, radius, collision_state.adjusted_move_distance, &newdist, &intersection, true)) {
// form a normal on the cylinder for use later
Vec3f newpos = collision_state.position_lo + dir * newdist;
Vec3f dir = center_lo - newpos;
dir.normalize();
Vec3f colpos = newpos + dir * collision_state.radius_lo;
Vec3f dirc = center_lo - newpos;
dirc.normalize();
Vec3f colpos = newpos + dirc * collision_state.radius_lo;
collision_state.collisionPos = colpos;
Vec3f colnorm = Vec3f(-dir.x, -dir.y, 0);
colnorm.normalize();
collision_state.collisionNorm = colnorm;

// set collision paramas
collision_state.adjusted_move_distance = newdist;
Expand Down Expand Up @@ -881,7 +877,6 @@ void ProcessPartyCollisionsBLV(int sectorId, int min_party_move_delta_sqr, int *
int adjusted_floor_z = GetIndoorFloorZ((adjusted_pos + Vec3f(0, 0, collision_state.radius_lo)).toInt(), &collision_state.uSectorID, faceId);
if (adjusted_floor_z == -30000 || adjusted_floor_z - pParty->pos.z > 128) {
// intended world position isnt valid so dont move there
int testadjusted_floor_z = GetIndoorFloorZ(pParty->pos.toInt(), &collision_state.uSectorID, faceId);
return; // TODO: whaaa?
}

Expand All @@ -902,15 +897,16 @@ void ProcessPartyCollisionsBLV(int sectorId, int min_party_move_delta_sqr, int *
// TODO(pskelton): common to odm/blv so extract
Vec3f newdirection;
if (collision_state.adjusted_move_distance > 0.0f) {
// Create new sliding plane from collisio
// Create new sliding plane from collision
Vec3f slideplaneorigin = collision_state.collisionPos;
Vec3f slideplanenormal = collision_state.collisionNorm;
float slideplanedist = -(dot(slideplaneorigin, slideplanenormal));
Vec3f dirc = pLevelDecorations[collision_state.pid.id()].vPosition.toFloat() - slideplaneorigin;
Vec3f slideplanenormal = Vec3f(-dirc.x, -dirc.y, 0);
slideplanenormal.normalize();

// Form a sliding vector that is parallel to sliding movement
// Take where you wouldve ended up without collisions and move that onto the slide plane by adding the normal
// Start point to new destination is a vector along the slide plane
float destplanedist = dot(collision_state.new_position_lo, slideplanenormal) + slideplanedist;
float destplanedist = dot(collision_state.new_position_lo - slideplaneorigin, slideplanenormal);
Vec3f newdestination = collision_state.new_position_lo - destplanedist * slideplanenormal;
newdirection = newdestination - collision_state.collisionPos;
newdirection.z = 0;
Expand Down Expand Up @@ -938,8 +934,7 @@ void ProcessPartyCollisionsBLV(int sectorId, int min_party_move_delta_sqr, int *
Vec3f slideplaneorigin = collision_state.collisionPos;
Vec3f slideplanenormal = adjusted_pos + Vec3f(0, 0, collision_state.radius_lo) - slideplaneorigin;
slideplanenormal.normalize();
float slideplanedist = -(dot(slideplaneorigin, slideplanenormal));
float distfromdestpointtoplane = dot(collision_state.new_position_lo, slideplanenormal) + slideplanedist;
float distfromdestpointtoplane = dot(collision_state.new_position_lo - slideplaneorigin, slideplanenormal);
Vec3f newdestination = collision_state.new_position_lo - distfromdestpointtoplane * slideplanenormal;
Vec3f newdirection = newdestination - collision_state.collisionPos;

Expand Down Expand Up @@ -1070,15 +1065,16 @@ void ProcessPartyCollisionsODM(Vec3f *partyNewPos, Vec3f *partyInputSpeed, bool
// TODO(pskelton): common to odm/blv so extract
Vec3f newdirection;
if (collision_state.adjusted_move_distance > 0.0f) {
// Create new sliding plane from collisio
// Create new sliding plane from collision
Vec3f slideplaneorigin = collision_state.collisionPos;
Vec3f slideplanenormal = collision_state.collisionNorm;
float slideplanedist = -(dot(slideplaneorigin, slideplanenormal));
Vec3f dirc = pLevelDecorations[collision_state.pid.id()].vPosition.toFloat() - slideplaneorigin;
Vec3f slideplanenormal = Vec3f(-dirc.x, -dirc.y, 0);
slideplanenormal.normalize();

// Form a sliding vector that is parallel to sliding movement
// Take where you wouldve ended up without collisions and move that onto the slide plane by adding the normal
// Start point to new destination is a vector along the slide plane
float destplanedist = dot(collision_state.new_position_lo, slideplanenormal) + slideplanedist;
float destplanedist = dot(collision_state.new_position_lo - slideplaneorigin, slideplanenormal);
Vec3f newdestination = collision_state.new_position_lo - destplanedist * slideplanenormal;
newdirection = newdestination - collision_state.collisionPos;
newdirection.z = 0;
Expand Down Expand Up @@ -1110,8 +1106,7 @@ void ProcessPartyCollisionsODM(Vec3f *partyNewPos, Vec3f *partyInputSpeed, bool
Vec3f slideplaneorigin = collision_state.collisionPos;
Vec3f slideplanenormal = newPosLow + Vec3f(0, 0, collision_state.radius_lo) - slideplaneorigin;
slideplanenormal.normalize();
float slideplanedist = -(dot(slideplaneorigin, slideplanenormal));
float distfromdestpointtoplane = dot(collision_state.new_position_lo, slideplanenormal) + slideplanedist;
float distfromdestpointtoplane = dot(collision_state.new_position_lo - slideplaneorigin, slideplanenormal);
Vec3f newdestination = collision_state.new_position_lo - distfromdestpointtoplane * slideplanenormal;
Vec3f newdirection = newdestination - collision_state.collisionPos;

Expand Down Expand Up @@ -1148,7 +1143,7 @@ bool hasShorterSolution(const float a, const float b, const float c, const float
return false; // no real solutions - No intersection points.
}

d = sqrt(d);
d = std::sqrt(d);
float alpha1 = (-b - d) / (2 * a);
float alpha2 = (-b + d) / (2 * a);

Expand Down
7 changes: 3 additions & 4 deletions src/Engine/Graphics/Collisions.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ struct CollisionState {
BBoxf bbox;

Vec3f collisionPos; // Point at which nearest collision occurs (touching radii)
Vec3f collisionNorm; // Normal vector outwards of collision if known
};

extern CollisionState collision_state;
Expand Down Expand Up @@ -126,13 +125,13 @@ void ProcessPartyCollisionsODM(Vec3f* partyNewPos, Vec3f* partyInputSpeed, bool*

/**
* Finds whether this quadratic (of the form AX^2 + BX + C = 0) can be solved and if the solution is smaller
* than out current solution.
* than out current solution. Returns true if a smaller non negative solution is found.
*
* @param a A component of quadratic.
* @param b B component of quadratic.
* @param c C component of quadratic.
* @param curSoln Current movement distance along the `dir` axis.
* @param[out] outNewSoln New movement distance along the 'dir' axis on true. This value is not set if the function
* @param curSoln Current input smallest solution to test against.
* @param[out] outNewSoln New smallest non negative solution. This value is not set if the function
* returns false.
* @param inside If you want collision with any point inside radius - for cylinder decorations/party
* @return True if the quadratic has a valid solution that is smaller than the input curSoln.
Expand Down
16 changes: 10 additions & 6 deletions src/Engine/Graphics/Indoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ int IndoorLocation::GetSector(int sX, int sY, int sZ) {
int FoundFaceStore[5] = { 0 };
int NumFoundFaceStore = 0;
int backupboundingsector{ 0 };
std::vector<int> foundSectors;
std::optional<int> foundSector;
bool singleSectorFound = false;

// loop through sectors
for (uint i = 1; i < pSectors.size(); ++i) {
Expand All @@ -402,8 +403,12 @@ int IndoorLocation::GetSector(int sX, int sY, int sZ) {
if (!FloorsAndPortals) continue;
if (!pSector->pFloors) continue;

if (std::find(foundSectors.begin(), foundSectors.end(), i) == foundSectors.end())
foundSectors.push_back(i);
if (!foundSector) {
foundSector = i;
singleSectorFound = true;
} else if (*foundSector != i) {
singleSectorFound = false;
}

// loop over check faces
for (uint z = 0; z < FloorsAndPortals; ++z) {
Expand All @@ -430,8 +435,7 @@ int IndoorLocation::GetSector(int sX, int sY, int sZ) {
return this->pFaces[FoundFaceStore[0]].uSectorID;

// only one sector found
if (foundSectors.size() == 1)
return foundSectors[0];
if (singleSectorFound) return *foundSector;

// No face found - outside of level
if (!NumFoundFaceStore) {
Expand All @@ -446,7 +450,7 @@ int IndoorLocation::GetSector(int sX, int sY, int sZ) {

// when multiple possibilities are found - cycle through and use the closer one to party
int pSectorID = 0, backupID = 0;
int MinZDist = 0xFFFFFFu, backupDist = 0xFFFFFFu;
int MinZDist = INT32_MAX, backupDist = INT32_MAX;
if (NumFoundFaceStore > 0) {
int CalcZDist = MinZDist;
for (int s = 0; s < NumFoundFaceStore; ++s) {
Expand Down
2 changes: 1 addition & 1 deletion test/Bin/GameTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if(OE_BUILD_TESTS)
ExternalProject_Add(OpenEnroth_TestData
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/test_data_tmp
GIT_REPOSITORY https://github.com/OpenEnroth/OpenEnroth_TestData.git
GIT_TAG 192799169f065752399028ba942b46d4126cb5a7
GIT_TAG f09ea6205b972eb02c20a90619d0ade6cc02d551
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/test_data
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
Expand Down
3 changes: 2 additions & 1 deletion test/Bin/GameTest/GameTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1762,7 +1762,8 @@ GAME_TEST(Issues, Issue1331) {
EXPECT_EQ(pParty->pCharacters[2].GetBowItem()->special_enchantment, ITEM_ENCHANTMENT_TITAN_SLAYING);
EXPECT_EQ(pParty->pCharacters[2].GetRangedDamageString(), "41 - 45");
auto damageRange = hpsTape.reversed().adjacentDeltas().flattened().filtered([] (int damage) { return damage > 0; }).minMax();
EXPECT_EQ(damageRange, tape(/*1 * 2*/ 3 /*TODO WHY?*/, (43 + 13) * 2));
// 2 -> 3 change here can happen. This just means that the Titans' physical resistance was never "lucky enough" to roll the damage down to 1 two times in a row.
EXPECT_EQ(damageRange, tape(/*1 * 2*/ 3, (43 + 13) * 2));
}

GAME_TEST(Issues, Issue1338) {
Expand Down

0 comments on commit ee8decf

Please sign in to comment.