forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 246
bugfix(physics): Fix diagonal movement speed discrepancy #3003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
xezon
wants to merge
10
commits into
TheSuperHackers:main
Choose a base branch
from
xezon:xezon/fix-diagonal-movement-speed
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+394
−42
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
11903cc
bugfix(physics): Fix diagonal movement speed discrepancy
xezon d822138
Preserve legacy speeds for scripted movements
xezon 9345a8c
Polish comments
xezon a9ca29b
Add more comments
xezon ff25f08
Fix Locomotor speeds
xezon 71c9f53
Optimize speed compensation values
xezon 2979988
Improve retail forward speed during cinematics
xezon 39eb2c0
Rename defines and allow to compile out the forward speed scaling
xezon 1b00149
Code Review fixes
xezon 4a53a88
Simplify comments, remove obsolete forward declare
xezon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,10 +139,21 @@ class LocomotorTemplate : public Overridable | |
|
|
||
| void validate(); | ||
|
|
||
| protected: | ||
| private: | ||
|
|
||
| /// TheSuperHackers @bugfix Speeds authored in INI are understated by the forward speed the Locomotor measures | ||
| /// itself with, by up to 1/sqrt(2) in 2d and 1/sqrt(3) in 3d, which is what made objects move faster on diagonal | ||
| /// headings than on axis aligned ones. Each authored speed therefore also gets a "scaled" twin, in world distance | ||
| /// per logic frame, computed once at INI load. These accessors hand out whichever of the two the mover should be | ||
| /// commanded with. They all return the authored value in retail compatible builds. | ||
| Real getActualMaxSpeed() const; | ||
| Real getActualMaxSpeedDamaged() const; | ||
| Real getActualMinSpeed() const; | ||
| Real getActualMinTurnSpeed() const; | ||
|
|
||
| /// Scale a speed that has no stored counterpart because it was not authored on this template. | ||
| Real scaleSpeed(Real speed) const; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This maybe should be behind macro. |
||
|
|
||
| private: | ||
| /** | ||
| Units check: | ||
|
|
||
|
|
@@ -163,6 +174,12 @@ class LocomotorTemplate : public Overridable | |
| Real m_liftDamaged; ///< max lift when damaged | ||
| Real m_braking; ///< max braking (deceleration) | ||
| Real m_minTurnSpeed; ///< we must be going >= this speed in order to turn | ||
| #if USE_RETAIL_PHYSICS_FORWARD_SPEED_AVERAGE() | ||
| Real m_maxSpeedScaled; ///< compensated max speed | ||
| Real m_maxSpeedDamagedScaled;///< compensated speed when "damaged" | ||
| Real m_minSpeedScaled; ///< compensated min speed; we should never brake past this | ||
| Real m_minTurnSpeedScaled; ///< compensated min turn speed; we must be going >= this speed in order to turn | ||
| #endif | ||
| Real m_preferredHeight; ///< our preferred height (if flying) | ||
| Real m_preferredHeightDamping; ///< how aggressively to adjust to preferred height: 1.0 = very much so, 0.1 = gradually, etc | ||
| Real m_circlingRadius; ///< for flying things, the radius at which they circle their "maintain" destination. (pos = cw, neg = ccw, 0 = smallest possible) | ||
|
|
@@ -258,7 +275,8 @@ class Locomotor : public MemoryPoolObject, public Snapshot | |
| LocomotorSurfaceTypeMask getLegalSurfaces() const { return m_template->m_surfaces; } | ||
|
|
||
| AsciiString getTemplateName() const { return m_template->m_name;} | ||
| Real getMinSpeed() const { return m_template->m_minSpeed;} | ||
| Real getMinSpeed() const; | ||
| Real getMinTurnSpeed() const; | ||
| Real getAccelPitchLimit() const { return m_template->m_accelPitchLimit;} ///< Maximum amount we will pitch up or down under acceleration (including recoil.) | ||
| Real getDecelPitchLimit() const { return m_template->m_decelPitchLimit;} ///< Maximum amount we will pitch down under deceleration (including recoil.) | ||
| Real getBounceKick() const { return m_template->m_bounceKick;} ///< How much simulating rough terrain "bounces" a wheel up. | ||
|
|
@@ -310,7 +328,11 @@ class Locomotor : public MemoryPoolObject, public Snapshot | |
| { | ||
| DEBUG_ASSERTCRASH(!(speed <= 0.0f && m_template->m_appearance == LOCO_THRUST), ("THRUST locos may not have zero speeds!")); | ||
| m_maxSpeed = speed; | ||
| #if USE_RETAIL_PHYSICS_FORWARD_SPEED_AVERAGE() | ||
| m_maxSpeedScaled = m_template->scaleSpeed(speed); | ||
| #endif | ||
| } | ||
| void setMaxSpeedToMinSpeed() { setMaxSpeed(m_template->m_minSpeed); } | ||
| void setMaxAcceleration(Real accel) { m_maxAccel = accel; } | ||
| void setMaxBraking(Real braking) { m_maxBraking = braking; } | ||
| void setMaxTurnRate(Real turn) { m_maxTurnRate = turn; } | ||
|
|
@@ -367,8 +389,9 @@ class Locomotor : public MemoryPoolObject, public Snapshot | |
| void startMove(); ///< Indicates that a move is starting, primarily to reset the donut timer. jba. | ||
|
|
||
| protected: | ||
| Real getMaxSpeedOverride() const; | ||
|
|
||
| void moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed); | ||
| void moveTowardsPositionLegsWander(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed); | ||
| void moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed); | ||
| void moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed); | ||
| void moveTowardsPositionTreads(Object* obj, PhysicsBehavior *physics, const Coord3D& goalPos, Real onPathDistToGoal, Real desiredSpeed); | ||
|
|
@@ -445,6 +468,9 @@ class Locomotor : public MemoryPoolObject, public Snapshot | |
| Real m_brakingFactor; | ||
| Real m_maxLift; | ||
| Real m_maxSpeed; | ||
| #if USE_RETAIL_PHYSICS_FORWARD_SPEED_AVERAGE() | ||
| Real m_maxSpeedScaled; | ||
| #endif | ||
| Real m_maxAccel; | ||
| Real m_maxBraking; | ||
| Real m_maxTurnRate; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this comment