Skip to content

Commit 36087ff

Browse files
authored
Customizable rate limit for cloak and vision when bound to mouse wheel (#1826)
* init * cleanup * a decent limit so game doesn't have to be restarted if set too big * reset on level load * default to 0
1 parent 819135f commit 36087ff

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

src/game/client/in_main.cpp

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,39 @@ void KeyDownHoldReplaceToggle( kbutton_t *b, const char *c )
456456
return; // still down
457457
b->state |= 1 + 2; // down + impulse down
458458
}
459+
460+
/*
461+
============
462+
KeyDown with a minimum time between any two keydowns of a button. Not intended to limit players, rather its to help players not accidentally execute actions bound to the mouse wheel more than once
463+
============
464+
*/
465+
ConVar cl_neo_mouse_wheel_action_cool_down("cl_neo_mouse_wheel_action_cool_down", "0", FCVAR_ARCHIVE, "If the mouse wheel is bound to an action with a mouse wheel delay, controls how long that delay is to prevent accidental activations of the action", true, 0, true, 1.f);
466+
static float nextMouseWheelUp = 0.f;
467+
static float nextMouseWheelDown = 0.f;
468+
void KeyDownWithMouseWheelDelay(kbutton_t* b, const char* c)
469+
{
470+
if (cl_neo_mouse_wheel_action_cool_down.GetFloat() > 0.f && c && c[0])
471+
{
472+
int k = atoi(&c[0]);
473+
if (k == MOUSE_WHEEL_UP)
474+
{
475+
if (gpGlobals->curtime < nextMouseWheelUp)
476+
{
477+
return;
478+
}
479+
nextMouseWheelUp = gpGlobals->curtime + cl_neo_mouse_wheel_action_cool_down.GetFloat();
480+
}
481+
else if (k == MOUSE_WHEEL_DOWN)
482+
{
483+
if (gpGlobals->curtime < nextMouseWheelDown)
484+
{
485+
return;
486+
}
487+
nextMouseWheelDown = gpGlobals->curtime + cl_neo_mouse_wheel_action_cool_down.GetFloat();
488+
}
489+
}
490+
KeyDown(b, c);
491+
}
459492
#endif // NEO
460493

461494
/*
@@ -630,10 +663,10 @@ void IN_LeanRightUp( const CCommand &args ) { KeyUp( &in_lean_right, args[1] );
630663
void IN_LeanRightDown(const CCommand& args) { KeyDown(&in_lean_right, args[1]); IN_LeanToggleReset(); }
631664

632665
void IN_ThermOpticUp(const CCommand &args) { KeyUp(&in_thermoptic, args[1]); }
633-
void IN_ThermOpticDown(const CCommand &args) { KeyDown(&in_thermoptic, args[1]); }
666+
void IN_ThermOpticDown(const CCommand &args) { KeyDownWithMouseWheelDelay(&in_thermoptic, args[1]); }
634667

635668
void IN_VisionUp(const CCommand &args) { KeyUp(&in_vision, args[1]); }
636-
void IN_VisionDown(const CCommand &args) { KeyDown(&in_vision, args[1]); }
669+
void IN_VisionDown(const CCommand &args) { KeyDownWithMouseWheelDelay(&in_vision, args[1]); }
637670

638671
void IN_SpecNextUp(const CCommand &args) { KeyUp(&in_spec_next, args[1]); }
639672
void IN_SpecNextDown(const CCommand &args) { KeyDown(&in_spec_next, args[1]); }
@@ -1945,5 +1978,9 @@ void CInput::LevelInit( void )
19451978
// Remove any IK information
19461979
m_EntityGroundContact.RemoveAll();
19471980
#endif
1981+
#ifdef NEO
1982+
nextMouseWheelUp = 0.f;
1983+
nextMouseWheelDown = 0.f;
1984+
#endif // NEO
19481985
}
19491986

0 commit comments

Comments
 (0)