[Engine] Implemented Com_Clampi and simplified timeNudge
diff --git a/src/docs/Changelog b/src/docs/Changelog
index bf87a4b..b5bf02d 100644
--- a/src/docs/Changelog
+++ b/src/docs/Changelog
@@ -1,5 +1,7 @@
2021-04-04 Dusan Jocic <dusanjocic@msn.com>
* [Filesystem] Changed fs_debug logging option
+ * [Engine] Fix mouse locking issues when the mouse would lock at the center of your screen
+ * [Engine] Implemented Com_Clampi and simplified timeNudge
2021-04-03 Dusan Jocic <dusanjocic@msn>
* [RendererSystem} Addressed the problem with DPI inside the engine
diff --git a/src/engine/client/clientGame.cpp b/src/engine/client/clientGame.cpp
index cfcc94f..3f31df6 100644
--- a/src/engine/client/clientGame.cpp
+++ b/src/engine/client/clientGame.cpp
@@ -1204,38 +1204,25 @@ void idClientGameSystemLocal::SetCGameTime( void )
}
else
{
- // cl_timeNudge is a user adjustable cvar that allows more
+ // cl_timeNudge is a user adjustable convar that allows more
// or less latency to be added in the interest of better
// smoothness or better responsiveness.
- sint tn;
+ sint timeNudge;
- tn = cl_timeNudge->integer;
- if( tn < 0 && ( cl.snapServer.ps.pm_type == PM_SPECTATOR || cl.snapServer.ps.pm_flags & PMF_FOLLOW || clc.demoplaying ) )
+ timeNudge = cl_timeNudge->integer;
+ if( timeNudge < 0 && ( cl.snapServer.ps.pm_type == PM_SPECTATOR || cl.snapServer.ps.pm_flags & PMF_FOLLOW || clc.demoplaying ) )
{
- tn = 0;
+ // disable negative timeNudge when spectating
+ timeNudge = 0;
}
-#if 1//def _DEBUG
- if( tn < -900 )
- {
- tn = -900;
- }
- else if( tn > 900 )
- {
- tn = 900;
- }
+#ifdef _DEBUG
+ timeNudge = Com_Clampi( -900, 900, timeNudge );
#else
- if( tn < -2000 )
- {
- tn = -2000;
- }
- else if( tn > 2000 )
- {
- tn = 2000;
- }
+ timeNudge = Com_Clampi( -2000, 2000, timeNudge );
#endif
- cl.serverTime = cls.realtime + cl.serverTimeDelta - tn;
+ cl.serverTime = cls.realtime + cl.serverTimeDelta - timeNudge;
// guarantee that time will never flow backwards, even if
// serverTimeDelta made an adjustment or cl_timeNudge was changed
diff --git a/src/engine/platform/systemInput.cpp b/src/engine/platform/systemInput.cpp
index 1d8866f..5498c82 100644
--- a/src/engine/platform/systemInput.cpp
+++ b/src/engine/platform/systemInput.cpp
@@ -475,7 +475,7 @@ void idSystemLocal::GobbleMotionEvents( void )
if( val < 0 )
{
- Com_Printf( "IN_GobbleMotionEvents failed: %s\n", SDL_GetError() );
+ Com_Printf( "idSystemLocal::GobbleMotionEvents failed: %s\n", SDL_GetError() );
}
}
diff --git a/src/engine/qcommon/q_shared.cpp b/src/engine/qcommon/q_shared.cpp
index 2acc31e..095676e 100644
--- a/src/engine/qcommon/q_shared.cpp
+++ b/src/engine/qcommon/q_shared.cpp
@@ -53,6 +53,27 @@
/*
============
+Com_Clampi
+============
+*/
+sint Com_Clampi( sint min, sint max, sint value )
+{
+ if( value < min )
+ {
+ return min;
+ }
+
+ if( value > max )
+ {
+ return max;
+ }
+
+ return value;
+}
+
+
+/*
+============
Com_Clamp
============
*/
diff --git a/src/engine/qcommon/q_shared.hpp b/src/engine/qcommon/q_shared.hpp
index 8c47fac..2a63b5e 100644
--- a/src/engine/qcommon/q_shared.hpp
+++ b/src/engine/qcommon/q_shared.hpp
@@ -680,6 +680,8 @@ void MatrixTransformPoint( const matrix_t m, const vec3_t in, vec3_t
//=============================================
+//Dushan same as Com_Clamp just for integers
+sint Com_Clampi( sint min, sint max, sint value );
float32 Com_Clamp( float32 min, float32 max, float32 value );
valueType* Com_SkipTokens( valueType* s, sint numTokens, valueType* sep );
GitHub
sha: b2c72c4f