From e75561b3821355593867761fe013847c0311d282 Mon Sep 17 00:00:00 2001 From: Night Owl Date: Thu, 12 Apr 2018 00:43:25 +0500 Subject: [PATCH] Add autojump from OpenAG. --- cl_dll/input.cpp | 30 ++++++++++++++++++++++++++++++ pm_shared/pm_shared.c | 10 ++++++++++ 2 files changed, 40 insertions(+) diff --git a/cl_dll/input.cpp b/cl_dll/input.cpp index 2e07f7ac..2bd27719 100644 --- a/cl_dll/input.cpp +++ b/cl_dll/input.cpp @@ -73,7 +73,14 @@ cvar_t *cl_yawspeed; cvar_t *cl_pitchspeed; cvar_t *cl_anglespeedkey; cvar_t *cl_vsmoothing; +cvar_t *cl_autojump; +extern "C" +{ + int g_onground = false; + int g_inwater = false; + int g_walking = true; // Movetype == MOVETYPE_WALK. Filters out noclip, being on ladder, etc. +} /* =============================================================================== @@ -842,6 +849,28 @@ void DLLEXPORT CL_CreateMove( float frametime, struct usercmd_s *cmd, int active // cmd->buttons = CL_ButtonBits( 1 ); + { + static bool s_jump_was_down_last_frame = false; + + if( cl_autojump->value != 0.0f ) + { + bool should_release_jump = ( !g_onground && !g_inwater && g_walking ); + + /* + * Spam pressing and releasing jump if we're stuck in a spot where jumping still results in + * being onground in the end of the frame. Without this check, +jump would remain held and + * when the player exits this spot they would have to release and press the jump button to + * start jumping again. This also helps with exiting water or ladder right onto the ground. + */ + if( s_jump_was_down_last_frame && g_onground && !g_inwater && g_walking ) + should_release_jump = true; + + if( should_release_jump ) + cmd->buttons &= ~IN_JUMP; + } + + s_jump_was_down_last_frame = ( ( cmd->buttons & IN_JUMP ) != 0 ); + } // Using joystick? if( in_joystick->value ) { @@ -1099,6 +1128,7 @@ void InitInput( void ) cl_pitchdown = gEngfuncs.pfnRegisterVariable( "cl_pitchdown", "89", 0 ); cl_vsmoothing = gEngfuncs.pfnRegisterVariable( "cl_vsmoothing", "0.05", FCVAR_ARCHIVE ); + cl_autojump = gEngfuncs.pfnRegisterVariable( "cl_autojump", "1", FCVAR_ARCHIVE ); m_pitch = gEngfuncs.pfnRegisterVariable( "m_pitch","0.022", FCVAR_ARCHIVE ); m_yaw = gEngfuncs.pfnRegisterVariable( "m_yaw","0.022", FCVAR_ARCHIVE ); diff --git a/pm_shared/pm_shared.c b/pm_shared/pm_shared.c index 641876eb..f477f197 100644 --- a/pm_shared/pm_shared.c +++ b/pm_shared/pm_shared.c @@ -2734,6 +2734,16 @@ void PM_Move( struct playermove_s *ppmove, int server ) { pmove->friction = 1.0f; } + +#ifdef CLIENT_DLL + extern int g_onground; + extern int g_inwater; + extern int g_walking; + + g_onground = ( pmove->onground != -1 ); + g_inwater = ( pmove->waterlevel > 1 ); + g_walking = ( pmove->movetype == MOVETYPE_WALK ); +#endif } int PM_GetInfo( int ent )