Skip to content

Commit 1982920

Browse files
committed
Improved walkpath auto crouch
1 parent f088716 commit 1982920

File tree

5 files changed

+28
-22
lines changed

5 files changed

+28
-22
lines changed

Entities/AHuman.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,17 +2233,17 @@ void AHuman::PreControllerUpdate()
22332233
if (m_pFGLeg && (!m_pBGLeg || !(m_Paths[FGROUND][WALK].PathEnded() && BGLegProg < 0.5F) || m_StrideStart)) {
22342234
// Reset the stride timer if the path is about to restart.
22352235
if (m_Paths[FGROUND][WALK].PathEnded() || m_Paths[FGROUND][WALK].PathIsAtStart()) { m_StrideTimer.Reset(); }
2236-
Vector jointPos = m_Pos + RotateOffset(m_pFGLeg->GetParentOffset()) + Vector(0.0F, -m_WalkPathYOffset);
2237-
m_ArmClimbing[BGROUND] = !m_pFGFootGroup->PushAsLimb(jointPos, m_Vel, m_WalkAngle[FGROUND], m_Paths[FGROUND][WALK], deltaTime, &restarted, false, Vector(0.0F, m_Paths[FGROUND][WALK].GetLowestY()));
2236+
Vector jointPos = m_Pos + RotateOffset(m_pFGLeg->GetParentOffset());
2237+
m_ArmClimbing[BGROUND] = !m_pFGFootGroup->PushAsLimb(jointPos, m_Vel, m_WalkAngle[FGROUND], m_Paths[FGROUND][WALK], deltaTime, &restarted, false, Vector(0.0F, m_Paths[FGROUND][WALK].GetLowestY()), Vector(0.0F, -m_WalkPathYOffset));
22382238
} else {
22392239
m_ArmClimbing[BGROUND] = false;
22402240
}
22412241
if (m_pBGLeg && (!m_pFGLeg || !(m_Paths[BGROUND][WALK].PathEnded() && FGLegProg < 0.5F))) {
22422242
m_StrideStart = false;
22432243
// Reset the stride timer if the path is about to restart.
22442244
if (m_Paths[BGROUND][WALK].PathEnded() || m_Paths[BGROUND][WALK].PathIsAtStart()) { m_StrideTimer.Reset(); }
2245-
Vector jointPos = m_Pos + RotateOffset(m_pBGLeg->GetParentOffset()) + Vector(0.0F, -m_WalkPathYOffset);
2246-
m_ArmClimbing[FGROUND] = !m_pBGFootGroup->PushAsLimb(jointPos, m_Vel, m_WalkAngle[BGROUND], m_Paths[BGROUND][WALK], deltaTime, &restarted, false, Vector(0.0F, m_Paths[BGROUND][WALK].GetLowestY()));
2245+
Vector jointPos = m_Pos + RotateOffset(m_pBGLeg->GetParentOffset());
2246+
m_ArmClimbing[FGROUND] = !m_pBGFootGroup->PushAsLimb(jointPos, m_Vel, m_WalkAngle[BGROUND], m_Paths[BGROUND][WALK], deltaTime, &restarted, false, Vector(0.0F, m_Paths[BGROUND][WALK].GetLowestY()), Vector(0.0F, -m_WalkPathYOffset));
22472247
} else {
22482248
if (m_pBGLeg) { m_pBGFootGroup->FlailAsLimb(m_Pos, RotateOffset(m_pBGLeg->GetParentOffset()), m_pBGLeg->GetMaxLength(), m_PrevVel, m_AngularVel, m_pBGLeg->GetMass(), deltaTime); }
22492249
m_ArmClimbing[FGROUND] = false;
@@ -2382,13 +2382,13 @@ void AHuman::PreControllerUpdate()
23822382
m_Paths[BGROUND][ARMCRAWL].Terminate();
23832383

23842384
if (m_pFGLeg) {
2385-
Vector jointPos = m_Pos.GetFloored() + m_pFGLeg->GetParentOffset().GetXFlipped(m_HFlipped) + Vector(0.0F, -m_WalkPathYOffset);
2386-
m_pFGFootGroup->PushAsLimb(jointPos, m_Vel, m_WalkAngle[FGROUND], m_Paths[FGROUND][STAND], deltaTime, nullptr, !m_pBGLeg, Vector(0.0F, m_Paths[FGROUND][STAND].GetLowestY()));
2385+
Vector jointPos = m_Pos.GetFloored() + m_pFGLeg->GetParentOffset().GetXFlipped(m_HFlipped);
2386+
m_pFGFootGroup->PushAsLimb(jointPos, m_Vel, m_WalkAngle[FGROUND], m_Paths[FGROUND][STAND], deltaTime, nullptr, !m_pBGLeg, Vector(0.0F, m_Paths[FGROUND][STAND].GetLowestY()), Vector(0.0F, -m_WalkPathYOffset));
23872387
}
23882388

23892389
if (m_pBGLeg) {
2390-
Vector jointPos = m_Pos.GetFloored() + m_pBGLeg->GetParentOffset().GetXFlipped(m_HFlipped) + Vector(0.0F, -m_WalkPathYOffset);
2391-
m_pBGFootGroup->PushAsLimb(jointPos, m_Vel, m_WalkAngle[BGROUND], m_Paths[BGROUND][STAND], deltaTime, nullptr, !m_pFGLeg, Vector(0.0F, m_Paths[FGROUND][STAND].GetLowestY()));
2390+
Vector jointPos = m_Pos.GetFloored() + m_pBGLeg->GetParentOffset().GetXFlipped(m_HFlipped);
2391+
m_pBGFootGroup->PushAsLimb(jointPos, m_Vel, m_WalkAngle[BGROUND], m_Paths[BGROUND][STAND], deltaTime, nullptr, !m_pFGLeg, Vector(0.0F, m_Paths[FGROUND][STAND].GetLowestY()), Vector(0.0F, -m_WalkPathYOffset));
23922392
}
23932393
}
23942394
}

Entities/AtomGroup.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ namespace RTE {
12141214

12151215
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
12161216

1217-
bool AtomGroup::PushAsLimb(const Vector &jointPos, const Vector &velocity, const Matrix &rotation, LimbPath &limbPath, const float travelTime, bool *restarted, bool affectRotation, Vector rotationOffset) {
1217+
bool AtomGroup::PushAsLimb(const Vector &jointPos, const Vector &velocity, const Matrix &rotation, LimbPath &limbPath, const float travelTime, bool *restarted, bool affectRotation, Vector rotationOffset, Vector positionOffset) {
12181218
RTEAssert(m_OwnerMOSR, "Tried to push-as-limb an AtomGroup that has no parent!");
12191219

12201220
bool didWrap = false;
@@ -1234,6 +1234,7 @@ namespace RTE {
12341234
limbPath.SetJointVel(velocity);
12351235
limbPath.SetRotation(rotation);
12361236
limbPath.SetRotationOffset(rotationOffset);
1237+
limbPath.SetPositionOffset(positionOffset);
12371238
limbPath.SetFrameTime(travelTime);
12381239

12391240
Vector limbDist = g_SceneMan.ShortestDistance(adjustedJointPos, m_LimbPos, g_SceneMan.SceneWrapsX());

Entities/AtomGroup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,9 @@ namespace RTE {
289289
/// <param name="restarted">Pointer to a bool which gets set to true if the LimbPath got restarted during this push. It does NOT get initialized to false!</param>
290290
/// <param name="affectRotation">Whether the forces created by this should have rotational leverage on the owner or only have translational effect.</param>
291291
/// <param name="rotationOffset">The position, relative to the owning actor's position, that we should rotate around.</param>
292+
/// <param name="rotationOffset">The positional offset to apply to our limb path.</param>
292293
/// <returns>Whether the LimbPath passed in could start free of terrain or not.</returns>
293-
bool PushAsLimb(const Vector &jointPos, const Vector &velocity, const Matrix &rotation, LimbPath &limbPath, const float travelTime, bool *restarted = nullptr, bool affectRotation = true, Vector rotationOffset = Vector());
294+
bool PushAsLimb(const Vector &jointPos, const Vector &velocity, const Matrix &rotation, LimbPath &limbPath, const float travelTime, bool *restarted = nullptr, bool affectRotation = true, Vector rotationOffset = Vector(), Vector positionOffset = Vector());
294295

295296
/// <summary>
296297
/// Makes this AtomGroup travel as a lifeless limb, constrained to a radius around the joint pin in the center.

Entities/LimbPath.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void LimbPath::Clear()
4242
m_JointVel.Reset();
4343
m_Rotation.Reset();
4444
m_RotationOffset.Reset();
45+
m_PositionOffset.Reset();
4546
m_TimeLeft = 0.0;
4647
m_PathTimer.Reset();
4748
m_SegTimer.Reset();
@@ -188,7 +189,7 @@ int LimbPath::ReadProperty(const std::string_view &propName, Reader &reader)
188189

189190

190191
Vector LimbPath::RotatePoint(const Vector &point) const {
191-
Vector offset = m_RotationOffset.GetXFlipped(m_HFlipped);
192+
Vector offset = (m_RotationOffset + m_PositionOffset).GetXFlipped(m_HFlipped);
192193
return ((point - offset) * m_Rotation) + offset;
193194
}
194195

@@ -246,7 +247,7 @@ void LimbPath::Destroy(bool notInherited)
246247

247248
Vector LimbPath::GetProgressPos()
248249
{
249-
Vector returnVec(m_Start);
250+
Vector returnVec(m_Start + m_PositionOffset);
250251
if (IsStaticPoint()) {
251252
return m_JointPos + RotatePoint(returnVec);
252253
}
@@ -273,7 +274,7 @@ Vector LimbPath::GetProgressPos()
273274

274275
Vector LimbPath::GetCurrentSegTarget()
275276
{
276-
Vector returnVec(m_Start);
277+
Vector returnVec(m_Start + m_PositionOffset);
277278
if (IsStaticPoint()) {
278279
return m_JointPos + RotatePoint(returnVec);
279280
}
@@ -561,14 +562,11 @@ bool LimbPath::RestartFree(Vector &limbPos, MOID MOIDToIgnore, int ignoreTeam)
561562
m_SegProgress = 0;
562563
bool found = false;
563564
float result = 0;
564-
565-
g_SceneMan.GetTerrain()->LockBitmaps();
566-
acquire_bitmap(g_SceneMan.GetMOIDBitmap());
567565

568566
if (IsStaticPoint())
569567
{
570568
Vector notUsed;
571-
Vector targetPos = m_JointPos + RotatePoint(m_Start);
569+
Vector targetPos = m_JointPos + RotatePoint(m_Start + m_PositionOffset);
572570
Vector beginPos = targetPos;
573571
// TODO: don't hardcode the beginpos
574572
beginPos.m_Y -= 24;
@@ -590,14 +588,14 @@ bool LimbPath::RestartFree(Vector &limbPos, MOID MOIDToIgnore, int ignoreTeam)
590588
int i = 0;
591589
for (; i < m_StartSegCount; ++i)
592590
{
593-
result = g_SceneMan.CastObstacleRay(GetProgressPos(), RotatePoint(*m_CurrentSegment), notUsed, limbPos, MOIDToIgnore, ignoreTeam, g_MaterialGrass);
591+
result = g_SceneMan.CastObstacleRay(GetProgressPos(), RotatePoint(*m_CurrentSegment + m_PositionOffset), notUsed, limbPos, MOIDToIgnore, ignoreTeam, g_MaterialGrass);
594592

595593
// If we found an obstacle after the first pixel, report the current segment as the starting one and that there is free space here
596594
if (result > 0)
597595
{
598596
// Set accurate segment progress
599597
// TODO: See if this is a good idea, or if we should just set it to 0 and set limbPos to the start of current segment
600-
m_SegProgress = g_SceneMan.ShortestDistance(GetProgressPos(), limbPos).GetMagnitude() / (*m_CurrentSegment).GetMagnitude();
598+
m_SegProgress = g_SceneMan.ShortestDistance(GetProgressPos(), limbPos).GetMagnitude() / (*m_CurrentSegment + m_PositionOffset).GetMagnitude();
601599
limbPos = GetProgressPos();
602600
// m_SegProgress = 0;
603601
m_Ended = false;
@@ -639,8 +637,6 @@ bool LimbPath::RestartFree(Vector &limbPos, MOID MOIDToIgnore, int ignoreTeam)
639637
found = true;
640638
}
641639
}
642-
release_bitmap(g_SceneMan.GetMOIDBitmap());
643-
g_SceneMan.GetTerrain()->UnlockBitmaps();
644640

645641
if (found)
646642
{
@@ -689,7 +685,7 @@ void LimbPath::Draw(BITMAP *pTargetBitmap,
689685
const Vector &targetPos,
690686
unsigned char color) const
691687
{
692-
Vector prevPoint = m_Start;
688+
Vector prevPoint = m_Start + m_PositionOffset;
693689
Vector nextPoint = prevPoint;
694690
for (std::deque<Vector>::const_iterator itr = m_Segments.begin(); itr != m_Segments.end(); ++itr)
695691
{

Entities/LimbPath.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,12 @@ ClassInfoGetters;
494494
/// <param name="rotationOffset">The new rotation offset, in local space.</param>
495495
void SetRotationOffset(const Vector& rotationOffset) { m_RotationOffset = rotationOffset; }
496496

497+
/// <summary>
498+
/// Sets the new position offset.
499+
/// </summary>
500+
/// <param name="rotationOffset">The new position offset, in local space.</param>
501+
void SetPositionOffset(const Vector& positionOffset) { m_PositionOffset = positionOffset; }
502+
497503

498504
//////////////////////////////////////////////////////////////////////////////////////////
499505
// Method: FrameDone
@@ -666,6 +672,8 @@ ClassInfoGetters;
666672
Matrix m_Rotation;
667673
// The point we should be rotated around, in local space.
668674
Vector m_RotationOffset;
675+
// The offset to apply to our walkpath position, in local space.
676+
Vector m_PositionOffset;
669677

670678
// If GetNextTimeSeg() couldn't use up all frame time because the current segment
671679
// ended,this var stores the remainder of time that should be used to progress

0 commit comments

Comments
 (0)