From 71853e03e7e2f8d7f63b98314b54442342011f8d Mon Sep 17 00:00:00 2001 From: Zach Charo Date: Fri, 6 Aug 2021 21:24:46 +0000 Subject: [PATCH 1/5] raindrop smearing fixed at high fps --- src/extras/screendroplets.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extras/screendroplets.cpp b/src/extras/screendroplets.cpp index 2485386b..e462c9a1 100644 --- a/src/extras/screendroplets.cpp +++ b/src/extras/screendroplets.cpp @@ -404,7 +404,7 @@ ScreenDroplets::ProcessCameraMovement(void) CVector camPos = camMat->pos; CVector camUp = camMat->at; ms_camMoveDelta = camPos - ms_prevCamPos; - ms_camMoveDist = ms_camMoveDelta.Magnitude(); + ms_camMoveDist = ms_camMoveDelta.Magnitude() / CTimer::GetTimeStepFix(); ms_prevCamUp = camUp; ms_prevCamPos = camPos; -- 2.45.2 From bb300a96b54e5995f73c6d63197f36d791004e8b Mon Sep 17 00:00:00 2001 From: Zach Charo Date: Sat, 7 Aug 2021 04:24:10 +0000 Subject: [PATCH 2/5] vehicle collisions and sprinting on steep grades helps with ped<->vehicle collisions and sprinting on steep grades at high framerates --- src/peds/Ped.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 3ccae5d0..173f2c3a 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -1540,6 +1540,12 @@ CPed::UpdatePosition(void) velocityChange = velocityChange * (changeMult / speedChange); } } + +#ifdef FIX_BUGS + //helps with ped<->vehicle collisions and sprinting on steep grades at high framerates + velocityChange *= CTimer::GetTimeStepFix(); +#endif + m_vecMoveSpeed.x += velocityChange.x; m_vecMoveSpeed.y += velocityChange.y; } -- 2.45.2 From 2b7f8ebfcc9a9e4facce59211dc22805c1c26ae3 Mon Sep 17 00:00:00 2001 From: Zach Charo Date: Sat, 7 Aug 2021 00:06:01 -0500 Subject: [PATCH 3/5] make vehicle freecam work better at high fps Fixes FOV, Angle limit, and rotation speed at high FPS to more closely match behavior at 30fps locked. --- src/core/Cam.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/core/Cam.cpp b/src/core/Cam.cpp index ecfade74..cd1c9835 100644 --- a/src/core/Cam.cpp +++ b/src/core/Cam.cpp @@ -4892,12 +4892,12 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, if (isCar || isBike) { // 0.4f: CAR_FOV_START_SPEED if (DotProduct(car->GetForward(), car->m_vecMoveSpeed) > 0.4f) - FOV += (DotProduct(car->GetForward(), car->m_vecMoveSpeed) - 0.4f) * CTimer::GetTimeStep(); + FOV += (DotProduct(car->GetForward(), car->m_vecMoveSpeed) - 0.4f) * (CTimer::GetTimeStep() / CTimer::GetTimeStepFix()); } if (FOV > DefaultFOV) // 0.98f: CAR_FOV_FADE_MULT - FOV = Pow(0.98f, CTimer::GetTimeStep()) * (FOV - DefaultFOV) + DefaultFOV; + FOV = Pow(0.98f, CTimer::GetTimeStep() / CTimer::GetTimeStepFix()) * (FOV - DefaultFOV) + DefaultFOV; FOV = Clamp(FOV, DefaultFOV, DefaultFOV + 30.0f); } @@ -4965,8 +4965,8 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, else if (velocityRightHeading > camRightHeading + PI) velocityRightHeading = velocityRightHeading - TWOPI; - float betaChangeMult1 = CTimer::GetTimeStep() * CARCAM_SET[camSetArrPos][10]; - float betaChangeLimit = CTimer::GetTimeStep() * CARCAM_SET[camSetArrPos][11]; + float betaChangeMult1 = (CTimer::GetTimeStep() / CTimer::GetTimeStepFix()) * CARCAM_SET[camSetArrPos][10]; + float betaChangeLimit = (CTimer::GetTimeStep() / CTimer::GetTimeStepFix()) * CARCAM_SET[camSetArrPos][11]; float betaChangeMult2 = (car->m_vecMoveSpeed - DotProduct(car->m_vecMoveSpeed, Front) * Front).Magnitude(); @@ -5028,8 +5028,8 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, } else { targetAlpha = maxAlphaAllowed; } - float maxAlphaBlendAmount = CTimer::GetTimeStep() * CARCAM_SET[camSetArrPos][6]; - float targetAlphaBlendAmount = (1.0f - Pow(CARCAM_SET[camSetArrPos][5], CTimer::GetTimeStep())) * (targetAlpha - Alpha); + float maxAlphaBlendAmount = (CTimer::GetTimeStep() / CTimer::GetTimeStepFix()) * CARCAM_SET[camSetArrPos][6]; + float targetAlphaBlendAmount = (1.0f - Pow(CARCAM_SET[camSetArrPos][5], CTimer::GetTimeStep() / CTimer::GetTimeStepFix())) * (targetAlpha - Alpha); if (targetAlphaBlendAmount <= maxAlphaBlendAmount) { if (targetAlphaBlendAmount < -maxAlphaBlendAmount) targetAlphaBlendAmount = -maxAlphaBlendAmount; @@ -5038,7 +5038,7 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, } // Using GetCarGun(LR/UD) will give us same unprocessed RightStick value as SA - float stickX = -(pad->GetCarGunLeftRight()); + float stickX = -pad->GetCarGunLeftRight(); float stickY = -pad->GetCarGunUpDown(); // In SA this is for not let num2/num8 move camera when Keyboard & Mouse controls are used. @@ -5125,7 +5125,7 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, float betaSpeedFromStickX = xMovement * CARCAM_SET[camSetArrPos][12]; float newAngleSpeedMaxBlendAmount = CARCAM_SET[camSetArrPos][9]; - float angleChangeStep = Pow(CARCAM_SET[camSetArrPos][8], CTimer::GetTimeStep()); + float angleChangeStep = Pow(CARCAM_SET[camSetArrPos][8], CTimer::GetTimeStepFix()); float targetBetaWithStickBlendAmount = betaSpeedFromStickX + (targetBeta - Beta) / Max(CTimer::GetTimeStep(), 1.0f); if (targetBetaWithStickBlendAmount < -newAngleSpeedMaxBlendAmount) @@ -5135,7 +5135,7 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, float angleChangeStepLeft = 1.0f - angleChangeStep; BetaSpeed = targetBetaWithStickBlendAmount * angleChangeStepLeft + angleChangeStep * BetaSpeed; - if (Abs(BetaSpeed) < 0.0001f) + if (Abs(BetaSpeed) < 0.0001f * CTimer::GetTimeStepFix()) BetaSpeed = 0.0f; float betaChangePerFrame; @@ -5176,7 +5176,7 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, AlphaSpeed = maxAlphaSpeed; } - if (Abs(AlphaSpeed) < 0.0001f) + if (Abs(AlphaSpeed) < 0.0001f * CTimer::GetTimeStepFix()) AlphaSpeed = 0.0f; float alphaWithSpeedAccounted; @@ -5200,12 +5200,12 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, } // Prevent unsignificant angle changes - if (Abs(lastAlpha - Alpha) < 0.0001f) + if (Abs(lastAlpha - Alpha) < 0.0001f * CTimer::GetTimeStepFix()) Alpha = lastAlpha; lastAlpha = Alpha; - if (Abs(lastBeta - Beta) < 0.0001f) + if (Abs(lastBeta - Beta) < 0.0001f * CTimer::GetTimeStepFix()) Beta = lastBeta; lastBeta = Beta; -- 2.45.2 From a30ff24bad57fe587b25ce297c51ac1afc085f6b Mon Sep 17 00:00:00 2001 From: Zach Charo Date: Sat, 7 Aug 2021 22:09:17 -0500 Subject: [PATCH 4/5] Update car-follow free cam Added frameTime variable to Process_FollowCar_SA, and update references to GetTimeStepFix() to instead use frameTime. Fixes a crash that happens when pausing and unpausing with the timestepfix adjusted freecam active --- src/core/Cam.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/core/Cam.cpp b/src/core/Cam.cpp index cd1c9835..d72f5b9d 100644 --- a/src/core/Cam.cpp +++ b/src/core/Cam.cpp @@ -4878,6 +4878,7 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, } float nextDistance = Max(newDistance, minDistForVehType); + static float frameTime = CTimer::GetTimeStepFix(); CA_MAX_DISTANCE = newDistance; CA_MIN_DISTANCE = 3.5f; @@ -4892,12 +4893,12 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, if (isCar || isBike) { // 0.4f: CAR_FOV_START_SPEED if (DotProduct(car->GetForward(), car->m_vecMoveSpeed) > 0.4f) - FOV += (DotProduct(car->GetForward(), car->m_vecMoveSpeed) - 0.4f) * (CTimer::GetTimeStep() / CTimer::GetTimeStepFix()); + FOV += (DotProduct(car->GetForward(), car->m_vecMoveSpeed) - 0.4f) * (CTimer::GetTimeStep() / frameTime); } if (FOV > DefaultFOV) // 0.98f: CAR_FOV_FADE_MULT - FOV = Pow(0.98f, CTimer::GetTimeStep() / CTimer::GetTimeStepFix()) * (FOV - DefaultFOV) + DefaultFOV; + FOV = Pow(0.98f, CTimer::GetTimeStep() / frameTime) * (FOV - DefaultFOV) + DefaultFOV; FOV = Clamp(FOV, DefaultFOV, DefaultFOV + 30.0f); } @@ -4965,8 +4966,8 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, else if (velocityRightHeading > camRightHeading + PI) velocityRightHeading = velocityRightHeading - TWOPI; - float betaChangeMult1 = (CTimer::GetTimeStep() / CTimer::GetTimeStepFix()) * CARCAM_SET[camSetArrPos][10]; - float betaChangeLimit = (CTimer::GetTimeStep() / CTimer::GetTimeStepFix()) * CARCAM_SET[camSetArrPos][11]; + float betaChangeMult1 = (CTimer::GetTimeStep() / frameTime) * CARCAM_SET[camSetArrPos][10]; + float betaChangeLimit = (CTimer::GetTimeStep() / frameTime) * CARCAM_SET[camSetArrPos][11]; float betaChangeMult2 = (car->m_vecMoveSpeed - DotProduct(car->m_vecMoveSpeed, Front) * Front).Magnitude(); @@ -5028,8 +5029,8 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, } else { targetAlpha = maxAlphaAllowed; } - float maxAlphaBlendAmount = (CTimer::GetTimeStep() / CTimer::GetTimeStepFix()) * CARCAM_SET[camSetArrPos][6]; - float targetAlphaBlendAmount = (1.0f - Pow(CARCAM_SET[camSetArrPos][5], CTimer::GetTimeStep() / CTimer::GetTimeStepFix())) * (targetAlpha - Alpha); + float maxAlphaBlendAmount = (CTimer::GetTimeStep() / frameTime) * CARCAM_SET[camSetArrPos][6]; + float targetAlphaBlendAmount = (1.0f - Pow(CARCAM_SET[camSetArrPos][5], (CTimer::GetTimeStep() / frameTime))) * (targetAlpha - Alpha); if (targetAlphaBlendAmount <= maxAlphaBlendAmount) { if (targetAlphaBlendAmount < -maxAlphaBlendAmount) targetAlphaBlendAmount = -maxAlphaBlendAmount; @@ -5125,7 +5126,7 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, float betaSpeedFromStickX = xMovement * CARCAM_SET[camSetArrPos][12]; float newAngleSpeedMaxBlendAmount = CARCAM_SET[camSetArrPos][9]; - float angleChangeStep = Pow(CARCAM_SET[camSetArrPos][8], CTimer::GetTimeStepFix()); + float angleChangeStep = Pow(CARCAM_SET[camSetArrPos][8], frameTime); float targetBetaWithStickBlendAmount = betaSpeedFromStickX + (targetBeta - Beta) / Max(CTimer::GetTimeStep(), 1.0f); if (targetBetaWithStickBlendAmount < -newAngleSpeedMaxBlendAmount) @@ -5135,7 +5136,7 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, float angleChangeStepLeft = 1.0f - angleChangeStep; BetaSpeed = targetBetaWithStickBlendAmount * angleChangeStepLeft + angleChangeStep * BetaSpeed; - if (Abs(BetaSpeed) < 0.0001f * CTimer::GetTimeStepFix()) + if (Abs(BetaSpeed) < 0.0001f * frameTime) BetaSpeed = 0.0f; float betaChangePerFrame; @@ -5176,7 +5177,7 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, AlphaSpeed = maxAlphaSpeed; } - if (Abs(AlphaSpeed) < 0.0001f * CTimer::GetTimeStepFix()) + if (Abs(AlphaSpeed) < 0.0001f * frameTime) AlphaSpeed = 0.0f; float alphaWithSpeedAccounted; @@ -5200,12 +5201,12 @@ CCam::Process_FollowCar_SA(const CVector& CameraTarget, float TargetOrientation, } // Prevent unsignificant angle changes - if (Abs(lastAlpha - Alpha) < 0.0001f * CTimer::GetTimeStepFix()) + if (Abs(lastAlpha - Alpha) < 0.0001f * frameTime) Alpha = lastAlpha; lastAlpha = Alpha; - if (Abs(lastBeta - Beta) < 0.0001f * CTimer::GetTimeStepFix()) + if (Abs(lastBeta - Beta) < 0.0001f * frameTime) Beta = lastBeta; lastBeta = Beta; -- 2.45.2 From 10f42aa2b97583b5c242f674adbaaaff1e6ec1fa Mon Sep 17 00:00:00 2001 From: ZLau92 Date: Sun, 8 Aug 2021 21:57:41 -0500 Subject: [PATCH 5/5] revert physics changes. They ain't right. --- src/peds/Ped.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 173f2c3a..3ccae5d0 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -1540,12 +1540,6 @@ CPed::UpdatePosition(void) velocityChange = velocityChange * (changeMult / speedChange); } } - -#ifdef FIX_BUGS - //helps with ped<->vehicle collisions and sprinting on steep grades at high framerates - velocityChange *= CTimer::GetTimeStepFix(); -#endif - m_vecMoveSpeed.x += velocityChange.x; m_vecMoveSpeed.y += velocityChange.y; } -- 2.45.2