Skip to content

Commit

Permalink
Merge pull request OpenEnroth#1534 from pskelton/todos
Browse files Browse the repository at this point in the history
Renaming speed -> velocity
  • Loading branch information
pskelton authored Mar 1, 2024
2 parents 435c963 + da220b2 commit 75a3748
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 163 deletions.
4 changes: 2 additions & 2 deletions src/Application/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ void Game::processQueuedMessages() {
SaveGame(1, 0);

pParty->pos = Vec3f(-17331, 12547, 465); // respawn point in Harmondale
pParty->speed = Vec3f();
pParty->velocity = Vec3f();
pParty->_viewYaw = 0;
pParty->uFallStartZ = pParty->pos.z;
pParty->_viewPitch = 0;
Expand Down Expand Up @@ -2034,7 +2034,7 @@ void Game::gameLoop() {
Source = pLocationName;
pParty->uFallStartZ = pParty->pos.z;
pParty->_viewPitch = 0;
pParty->speed = Vec3f();
pParty->velocity = Vec3f();
// change map
if (pCurrentMapName != Source) {
pCurrentMapName = Source;
Expand Down
74 changes: 37 additions & 37 deletions src/Engine/Graphics/Collisions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ void ProcessActorCollisionsBLV(Actor &actor, bool isAboveGround, bool isFlying)
collision_state.position_lo = actor.pos.toFloat() + Vec3f(0, 0, actor.radius + 1);
collision_state.position_hi = actor.pos.toFloat() + Vec3f(0, 0, actor.height - actor.radius - 1);
collision_state.position_hi.z = std::max(collision_state.position_hi.z, collision_state.position_lo.z);
collision_state.velocity = actor.speed.toFloat();
collision_state.velocity = actor.velocity.toFloat();
collision_state.uSectorID = actor.sectorId;
if (collision_state.PrepareAndCheckIfStationary())
break;
Expand Down Expand Up @@ -661,8 +661,8 @@ void ProcessActorCollisionsBLV(Actor &actor, bool isAboveGround, bool isFlying)

if (type == OBJECT_Character) {
if (actor.GetActorsRelation(0) != HOSTILITY_FRIENDLY) {
actor.speed.y = 0;
actor.speed.x = 0;
actor.velocity.y = 0;
actor.velocity.x = 0;

if (pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Active()) {
pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Reset();
Expand All @@ -673,42 +673,42 @@ void ProcessActorCollisionsBLV(Actor &actor, bool isAboveGround, bool isFlying)
}

if (type == OBJECT_Decoration) {
int speed = integer_sqrt(actor.speed.x * actor.speed.x + actor.speed.y * actor.speed.y);
int speed = integer_sqrt(actor.velocity.x * actor.velocity.x + actor.velocity.y * actor.velocity.y);
int angle = TrigLUT.atan2(actor.pos.x - pLevelDecorations[id].vPosition.x, actor.pos.y - pLevelDecorations[id].vPosition.y); // Face away from the decoration.
actor.speed.x = TrigLUT.cos(angle) * speed;
actor.speed.y = TrigLUT.sin(angle) * speed;
actor.velocity.x = TrigLUT.cos(angle) * speed;
actor.velocity.y = TrigLUT.sin(angle) * speed;
}

if (type == OBJECT_Face) {
BLVFace *face = &pIndoor->pFaces[id];

collision_state.ignored_face_id = collision_state.pid.id();
if (pIndoor->pFaces[id].uPolygonType == POLYGON_Floor) {
actor.speed.z = 0;
actor.velocity.z = 0;
actor.pos.z = pIndoor->pVertices[face->pVertexIDs[0]].z + 1;
if (actor.speed.lengthSqr() < 400) {
actor.speed.x = 0;
actor.speed.y = 0;
if (actor.velocity.lengthSqr() < 400) {
actor.velocity.x = 0;
actor.velocity.y = 0;
continue; // TODO(captainurist): drop this continue
}
} else {
float velocityDotNormal = dot(face->facePlane.normal, actor.speed.toFloat());
float velocityDotNormal = dot(face->facePlane.normal, actor.velocity.toFloat());
velocityDotNormal = std::max(std::abs(velocityDotNormal), collision_state.speed / 8);
actor.speed += (velocityDotNormal * face->facePlane.normal).toInt();
actor.velocity += (velocityDotNormal * face->facePlane.normal).toInt();
if (face->uPolygonType != POLYGON_InBetweenFloorAndWall && face->uPolygonType != POLYGON_Floor) {
float overshoot = collision_state.radius_lo - face->facePlane.signedDistanceTo(actor.pos.toFloat());
if (overshoot > 0)
actor.pos += (overshoot * pIndoor->pFaces[id].facePlane.normal).toInt();
actor.yawAngle = TrigLUT.atan2(actor.speed.x, actor.speed.y);
actor.yawAngle = TrigLUT.atan2(actor.velocity.x, actor.velocity.y);
}
}
if (pIndoor->pFaces[id].uAttributes & FACE_TriggerByMonster)
eventProcessor(pIndoor->pFaceExtras[pIndoor->pFaces[id].uFaceExtraID].uEventID, Pid(), 1);
}

actor.speed.x = fixpoint_mul(58500, actor.speed.x);
actor.speed.y = fixpoint_mul(58500, actor.speed.y);
actor.speed.z = fixpoint_mul(58500, actor.speed.z);
actor.velocity.x = fixpoint_mul(58500, actor.velocity.x);
actor.velocity.y = fixpoint_mul(58500, actor.velocity.y);
actor.velocity.z = fixpoint_mul(58500, actor.velocity.z);
}
}

Expand All @@ -725,7 +725,7 @@ void ProcessActorCollisionsODM(Actor &actor, bool isFlying) {
collision_state.position_lo = actor.pos.toFloat() + Vec3f(0, 0, actorRadius + 1);
collision_state.position_hi = actor.pos.toFloat() + Vec3f(0, 0, actor.height - actorRadius - 1);
collision_state.position_hi.z = std::max(collision_state.position_hi.z, collision_state.position_lo.z);
collision_state.velocity = actor.speed.toFloat();
collision_state.velocity = actor.velocity.toFloat();
collision_state.uSectorID = 0;
if (collision_state.PrepareAndCheckIfStationary())
break;
Expand Down Expand Up @@ -783,8 +783,8 @@ void ProcessActorCollisionsODM(Actor &actor, bool isFlying) {

if (type == OBJECT_Character) {
if (actor.GetActorsRelation(0) != HOSTILITY_FRIENDLY) {
actor.speed.y = 0;
actor.speed.x = 0;
actor.velocity.y = 0;
actor.velocity.x = 0;

if (pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Active()) {
pParty->pPartyBuffs[PARTY_BUFF_INVISIBILITY].Reset();
Expand All @@ -795,43 +795,43 @@ void ProcessActorCollisionsODM(Actor &actor, bool isFlying) {
}

if (type == OBJECT_Decoration) {
int speed = integer_sqrt(actor.speed.x * actor.speed.x + actor.speed.y * actor.speed.y);
int speed = integer_sqrt(actor.velocity.x * actor.velocity.x + actor.velocity.y * actor.velocity.y);
int angle = TrigLUT.atan2(actor.pos.x - pLevelDecorations[id].vPosition.x, actor.pos.y - pLevelDecorations[id].vPosition.y);
actor.speed.x = TrigLUT.cos(angle) * speed;
actor.speed.y = TrigLUT.sin(angle) * speed;
actor.velocity.x = TrigLUT.cos(angle) * speed;
actor.velocity.y = TrigLUT.sin(angle) * speed;
}

if (type == OBJECT_Face) {
const ODMFace *face = &pOutdoor->face(collision_state.pid);

if (!face->Ethereal()) {
if (face->uPolygonType == POLYGON_Floor) {
actor.speed.z = 0;
actor.velocity.z = 0;
actor.pos.z = pOutdoor->model(collision_state.pid).pVertices[face->pVertexIDs[0]].z + 1;
if (actor.speed.lengthSqr() < 400) {
actor.speed.y = 0;
actor.speed.x = 0;
if (actor.velocity.lengthSqr() < 400) {
actor.velocity.y = 0;
actor.velocity.x = 0;
}
} else {
float velocityDotNormal = dot(face->facePlane.normal, actor.speed.toFloat());
float velocityDotNormal = dot(face->facePlane.normal, actor.velocity.toFloat());
// TODO(captainurist): in BLV code we have std::abs(velocityDotNormal) here, and adding std::abs affects traces.
// Note that not all copies of this code have std::abs. Why?
velocityDotNormal = std::max(velocityDotNormal, collision_state.speed / 8);

actor.speed += (velocityDotNormal * face->facePlane.normal).toInt();
actor.velocity += (velocityDotNormal * face->facePlane.normal).toInt();
if (face->uPolygonType != POLYGON_InBetweenFloorAndWall) {
float overshoot = collision_state.radius_lo - face->facePlane.signedDistanceTo(actor.pos.toFloat());
if (overshoot > 0)
actor.pos += (overshoot * face->facePlane.normal).toInt();
actor.yawAngle = TrigLUT.atan2(actor.speed.x, actor.speed.y);
actor.yawAngle = TrigLUT.atan2(actor.velocity.x, actor.velocity.y);
}
}
}
}

actor.speed.x = fixpoint_mul(58500, actor.speed.x);
actor.speed.y = fixpoint_mul(58500, actor.speed.y);
actor.speed.z = fixpoint_mul(58500, actor.speed.z);
actor.velocity.x = fixpoint_mul(58500, actor.velocity.x);
actor.velocity.y = fixpoint_mul(58500, actor.velocity.y);
actor.velocity.z = fixpoint_mul(58500, actor.velocity.z);
}
}

Expand All @@ -846,7 +846,7 @@ void ProcessPartyCollisionsBLV(int sectorId, int min_party_move_delta_sqr, int *
for (unsigned i = 0; i < 5; i++) {
collision_state.position_hi = pParty->pos + Vec3f(0, 0, pParty->height - collision_state.radius_lo);
collision_state.position_lo = pParty->pos + Vec3f(0, 0, collision_state.radius_lo);
collision_state.velocity = pParty->speed;
collision_state.velocity = pParty->velocity;

collision_state.uSectorID = sectorId;
Duration dt; // zero means use actual dt
Expand Down Expand Up @@ -915,7 +915,7 @@ void ProcessPartyCollisionsBLV(int sectorId, int min_party_move_delta_sqr, int *
}

// Set party to move along this new sliding vector
pParty->speed = newDirection * dot(newDirection, pParty->speed);
pParty->velocity = newDirection * dot(newDirection, pParty->velocity);
// Skip reducing party speed
continue;
}
Expand Down Expand Up @@ -947,10 +947,10 @@ void ProcessPartyCollisionsBLV(int sectorId, int min_party_move_delta_sqr, int *

// Push away from the surface and add a touch down for better slide
if (bFaceSlopeTooSteep)
pParty->speed += Vec3f(pFace->facePlane.normal.x, pFace->facePlane.normal.y, -2) * 10;
pParty->velocity += Vec3f(pFace->facePlane.normal.x, pFace->facePlane.normal.y, -2) * 10;

// set movement speed along sliding plane
pParty->speed = newDirection * dot(newDirection, pParty->speed);
pParty->velocity = newDirection * dot(newDirection, pParty->velocity);

if (pParty->floor_face_id != collision_state.pid.id() && pFace->Pressure_Plate())
*faceEvent = pIndoor->pFaceExtras[pFace->uFaceExtraID].uEventID;
Expand All @@ -964,7 +964,7 @@ void ProcessPartyCollisionsBLV(int sectorId, int min_party_move_delta_sqr, int *
}

// ~0.9x reduce party speed and try again
pParty->speed *= 0.89263916f; // was 58500 fp
pParty->velocity *= 0.89263916f; // was 58500 fp
}
}

Expand Down
Loading

0 comments on commit 75a3748

Please sign in to comment.