Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9706462
Fix middle mouse button click detection to use real-time instead of f…
bobtista Nov 11, 2025
899a8ef
Fix keyboard repeat delay to use real-time instead of frames
bobtista Nov 11, 2025
1cee053
tweak(input): Reduce keyboard repeat delay from 333ms to 250ms for sn…
bobtista Dec 3, 2025
3d504dd
refactor(input): Use Msec naming convention for millisecond variables
bobtista Dec 4, 2025
94fa484
perf(input): Reduce timeGetTime() calls in keyboard input processing
bobtista Dec 4, 2025
7de0c1b
refactor(input): Move KEY_REPEAT_INTERVAL_MSEC constant to improve co…
bobtista Dec 4, 2025
86d31f4
docs(input): Clarify sequence field usage in KeyboardIO struct
bobtista Dec 4, 2025
ad295cc
refactor(input): Convert mouse movement tracking from frames to real-…
bobtista Dec 4, 2025
04c096a
revert(input): Restore KEY_REPEAT_DELAY to original 333ms timing
bobtista Dec 4, 2025
2838b28
fix(input): Correct keyboard repeat interval math to match original b…
bobtista Dec 4, 2025
f33d3a0
refactor(input): Remove obsolete sequence field from keyboard input s…
bobtista Dec 4, 2025
3c4f14a
refactor(input): Simplify timeGetTime calls
bobtista Dec 4, 2025
2e3f0bd
fix(input): Restore multi-key repeat prevention with time-based logic
bobtista Dec 4, 2025
e98ea02
perf(input): Gate timeGetTime call behind key down check in repeat logic
bobtista Dec 4, 2025
03d984d
perf(input): Reuse timeGetTime value in middle mouse button handlers
bobtista Dec 10, 2025
627657a
refactor(input): Move KEY_REPEAT_INTERVAL_MSEC to class enum
bobtista Dec 10, 2025
22c8223
refactor(input): Remove unused m_inputFrame vars and rename mouse fra…
bobtista Dec 12, 2025
f1034fa
nit: Clarify comment for mouse button state changed fields
bobtista Dec 12, 2025
870dc28
perf(input): Use DirectInput timestamp for key down time and update c…
bobtista Dec 13, 2025
cf2a6d6
fix: Remove double empty line to match GeneralsMD formatting
bobtista Dec 13, 2025
2453557
refactor(input): Use MSEC_PER_SECOND constant in LookAtXlat
bobtista Dec 19, 2025
f52de9f
style(input): Format keyboard repeat enum across multiple lines
bobtista Dec 19, 2025
7c64dfc
refactor(input): Rename mouse button state changed variables
bobtista Dec 19, 2025
b6c9028
refactor(input): Use MSEC_PER_SECOND constant in LookAtXlat
bobtista Dec 19, 2025
8f84f20
style(input): Format keyboard repeat enum across multiple lines
bobtista Dec 19, 2025
ea94ee7
refactor(input): Rename mouse button state changed variables
bobtista Dec 19, 2025
eca1f26
fix(input): Move timing constant comments to correct lines
bobtista Dec 20, 2025
2d14d5b
fix(input): Remove side effects from hasMouseMovedRecently
bobtista Dec 20, 2025
7a27d25
fix(input): Use unsigned subtraction for keyboard repeat timing
bobtista Dec 20, 2025
c0465ba
refactor(input): Replace mouse button state change flags with MBS_Non…
bobtista Dec 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Generals/Code/GameEngine/Include/GameClient/Keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct KeyboardIO
UnsignedByte key; // KeyDefType, key data
UnsignedByte status; // StatusType, above
UnsignedShort state; // KEY_STATE_* in KeyDefs.h
UnsignedInt sequence; // sequence info from DirectX used for order
UnsignedInt keyDownTimeMsec; // real-time in milliseconds when key went down

};

Expand All @@ -86,7 +86,11 @@ struct KeyboardIO
class Keyboard : public SubsystemInterface
{

enum { KEY_REPEAT_DELAY = 10 };
enum
{
KEY_REPEAT_DELAY_MSEC = 333, // 10 frames at 30 FPS
KEY_REPEAT_INTERVAL_MSEC = 67 // ~2 frames at 30 FPS
};

public:

Expand Down Expand Up @@ -133,7 +137,6 @@ class Keyboard : public SubsystemInterface
Bool checkKeyRepeat( void ); ///< check for repeating keys
UnsignedByte getKeyStatusData( KeyDefType key ); ///< get key status
Bool getKeyStateBit( KeyDefType key, Int bit ); ///< get key state bit
UnsignedInt getKeySequenceData( KeyDefType key ); ///< get key sequence
void setKeyStateData( KeyDefType key, UnsignedByte data ); ///< get key state

UnsignedShort m_modifiers;
Expand Down Expand Up @@ -161,7 +164,6 @@ class Keyboard : public SubsystemInterface
WideChar shifted2;

} m_keyNames[ KEY_COUNT ];
UnsignedInt m_inputFrame; ///< frame input was gathered on

};

Expand Down
4 changes: 2 additions & 2 deletions Generals/Code/GameEngine/Include/GameClient/LookAtXlat.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ class LookAtTranslator : public GameMessageTranslator
Bool m_isRotating; // set to true if we are in the act of MMB rotating
Bool m_isPitching; // set to true if we are in the act of ALT pitch rotation
Bool m_isChangingFOV; // set to true if we are in the act of changing the field of view
UnsignedInt m_timestamp; // set when button goes down
UnsignedInt m_middleButtonDownTimeMsec; // real-time in milliseconds when middle button goes down
DrawableID m_lastPlaneID;
ViewLocation m_viewLocation[ MAX_VIEW_LOCS ];
ScrollType m_scrollType;
ScreenEdgeScrollMode m_screenEdgeScrollMode;
UnsignedInt m_lastMouseMoveFrame;
UnsignedInt m_lastMouseMoveTimeMsec; // real-time in milliseconds when mouse last moved

void setScrolling( ScrollType scrollType );
void stopScrolling( void );
Expand Down
9 changes: 2 additions & 7 deletions Generals/Code/GameEngine/Include/GameClient/Mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ enum GameMode CPP_11(: Int);

enum MouseButtonState CPP_11(: Int)
{
MBS_None = -1,
MBS_Up = 0,
MBS_Down,
MBS_DoubleClick,
Expand Down Expand Up @@ -105,17 +106,14 @@ struct MouseIO
user while - is down/toward user */
ICoord2D deltaPos; ///< overall change in mouse pointer this frame

MouseButtonState leftState; // button state: Up, Down, DoubleClick (Which is also down)
MouseButtonState leftState; // button state: None (no event), Up, Down, DoubleClick
Int leftEvent; // Most important event this frame
Int leftFrame; // last frame button state changed

MouseButtonState rightState;
Int rightEvent;
Int rightFrame;

MouseButtonState middleState;
Int middleEvent;
Int middleFrame;
};

class CursorInfo
Expand Down Expand Up @@ -393,9 +391,6 @@ class Mouse : public SubsystemInterface
Int m_minY; ///< mouse is locked to this region
Int m_maxY; ///< mouse is locked to this region

UnsignedInt m_inputFrame; ///< frame input was gathered on
UnsignedInt m_deadInputFrame; ///< Frame which last input occured

Bool m_inputMovesAbsolute; /**< if TRUE, when processing mouse position
chanages the movement will be done treating
the coords as ABSOLUTE positions and NOT
Expand Down
38 changes: 17 additions & 21 deletions Generals/Code/GameEngine/Source/GameClient/Input/Keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ void Keyboard::updateKeys( void )

m_keyStatus[ m_keys[ index ].key ].state = m_keys[ index ].state;
m_keyStatus[ m_keys[ index ].key ].status = m_keys[ index ].status;
m_keyStatus[ m_keys[ index ].key ].sequence = m_inputFrame;

// Update key down time for new key presses
if( BitIsSet( m_keys[ index ].state, KEY_STATE_DOWN ) )
{
m_keyStatus[ m_keys[ index ].key ].keyDownTimeMsec = m_keys[ index ].keyDownTimeMsec;
}

// prevent ALT-TAB from causing a TAB event
if( m_keys[ index ].key == KEY_TAB )
Expand Down Expand Up @@ -195,7 +200,7 @@ void Keyboard::updateKeys( void )
}

//-------------------------------------------------------------------------------------------------
/** check key repeat sequences, TRUE is returned if repeat is occurring */
/** check key repeat timing, TRUE is returned if repeat is occurring */
//-------------------------------------------------------------------------------------------------
Bool Keyboard::checkKeyRepeat( void )
{
Expand All @@ -220,7 +225,13 @@ Bool Keyboard::checkKeyRepeat( void )
if( BitIsSet( m_keyStatus[ key ].state, KEY_STATE_DOWN ) )
{

if( (m_inputFrame - m_keyStatus[ key ].sequence) > Keyboard::KEY_REPEAT_DELAY )
const UnsignedInt now = timeGetTime();
const UnsignedInt keyDownTime = m_keyStatus[ key ].keyDownTimeMsec;

// Unsigned subtraction handles wraparound correctly
const UnsignedInt elapsedMsec = now - keyDownTime;

if( elapsedMsec > Keyboard::KEY_REPEAT_DELAY_MSEC )
{
// Add key to this frame
m_keys[ index ].key = (UnsignedByte)key;
Expand All @@ -232,10 +243,10 @@ Bool Keyboard::checkKeyRepeat( void )

// Set all keys as new to prevent multiple keys repeating
for( index = 0; index< NUM_KEYS; index++ )
m_keyStatus[ index ].sequence = m_inputFrame;
m_keyStatus[ index ].keyDownTimeMsec = now;

// Set repeated key so it will repeat again in two frames
m_keyStatus[ key ].sequence = m_inputFrame - (Keyboard::KEY_REPEAT_DELAY + 2);
// Set repeated key so it will repeat again after the interval
m_keyStatus[ key ].keyDownTimeMsec = now - (Keyboard::KEY_REPEAT_DELAY_MSEC + Keyboard::KEY_REPEAT_INTERVAL_MSEC);

retVal = TRUE;
break; // exit for key
Expand Down Expand Up @@ -694,7 +705,6 @@ Keyboard::Keyboard( void )
m_shift2Key = KEY_NONE;

memset( m_keyNames, 0, sizeof( m_keyNames ) );
m_inputFrame = 0;

}

Expand All @@ -714,9 +724,6 @@ void Keyboard::init( void )
// initialize the key names
initKeyNames();

// first input frame
m_inputFrame = 0;

}

//-------------------------------------------------------------------------------------------------
Expand All @@ -733,9 +740,6 @@ void Keyboard::reset( void )
void Keyboard::update( void )
{

// increment input frame
m_inputFrame++;

// update the key data
updateKeys();

Expand Down Expand Up @@ -819,14 +823,6 @@ Bool Keyboard::getKeyStateBit( KeyDefType key, Int bit )
return (m_keyStatus[ key ].state & bit) ? 1 : 0;
}

//-------------------------------------------------------------------------------------------------
/** return the sequence data for the given key */
//-------------------------------------------------------------------------------------------------
UnsignedInt Keyboard::getKeySequenceData( KeyDefType key )
{
return m_keyStatus[ key ].sequence;
}

//-------------------------------------------------------------------------------------------------
/** set the key status data */
//-------------------------------------------------------------------------------------------------
Expand Down
29 changes: 4 additions & 25 deletions Generals/Code/GameEngine/Source/GameClient/Input/Mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@ void Mouse::updateMouseData( )
else
m_eventsThisFrame = 0;

if( index != 0 )
m_deadInputFrame = m_inputFrame;

}

//-------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -221,7 +218,7 @@ void Mouse::processMouseEvent( Int index )
m_currMouse.wheelPos += m_mouseEvents[ index ].wheelPos;

// Check Left Mouse State
if( m_mouseEvents[ index ].leftFrame )
if( m_mouseEvents[ index ].leftState != MBS_None )
{
if( m_currMouse.leftState != m_mouseEvents[ index ].leftState )
{
Expand All @@ -231,21 +228,18 @@ void Mouse::processMouseEvent( Int index )
// Mouse Down
m_currMouse.leftEvent = GWM_LEFT_DOWN;
m_currMouse.leftState = MBS_Down;
m_currMouse.leftFrame = m_inputFrame;
}
else if ( m_mouseEvents[ index ].leftState == MBS_DoubleClick )
{
// Mouse Double Click
m_currMouse.leftEvent = GWM_LEFT_DOUBLE_CLICK;
m_currMouse.leftState = MBS_DoubleClick;
m_currMouse.leftFrame = m_inputFrame;
}
else
{
// Mouse Up
m_currMouse.leftEvent = GWM_LEFT_UP;
m_currMouse.leftState = MBS_Up;
m_currMouse.leftFrame = m_inputFrame;
}
}
}
Expand All @@ -257,7 +251,7 @@ void Mouse::processMouseEvent( Int index )
}

// Check Right Mouse State
if( m_mouseEvents[ index ].rightFrame )
if( m_mouseEvents[ index ].rightState != MBS_None )
{
if( m_currMouse.rightState != m_mouseEvents[ index ].rightState )
{
Expand All @@ -267,21 +261,18 @@ void Mouse::processMouseEvent( Int index )
// Mouse Down
m_currMouse.rightEvent = GWM_RIGHT_DOWN;
m_currMouse.rightState = MBS_Down;
m_currMouse.rightFrame = m_inputFrame;
}
else if( m_mouseEvents[ index ].rightState == MBS_DoubleClick )
{
// Mouse Double Click
m_currMouse.rightEvent = GWM_RIGHT_DOUBLE_CLICK;
m_currMouse.rightState = MBS_DoubleClick;
m_currMouse.rightFrame = m_inputFrame;
}
else
{
// Mouse Up
m_currMouse.rightEvent = GWM_RIGHT_UP;
m_currMouse.rightState = MBS_Up;
m_currMouse.rightFrame = m_inputFrame;
}
}
}
Expand All @@ -293,7 +284,7 @@ void Mouse::processMouseEvent( Int index )
}

// Check Middle Mouse State
if( m_mouseEvents[ index ].middleFrame )
if( m_mouseEvents[ index ].middleState != MBS_None )
{
if( m_currMouse.middleState != m_mouseEvents[index].middleState )
{
Expand All @@ -302,20 +293,17 @@ void Mouse::processMouseEvent( Int index )
{
m_currMouse.middleEvent = GWM_MIDDLE_DOWN;
m_currMouse.middleState = MBS_Down;
m_currMouse.middleFrame = m_inputFrame;
}
else if( m_mouseEvents[index].middleState == MBS_DoubleClick )
{
m_currMouse.middleEvent = GWM_MIDDLE_DOUBLE_CLICK;
m_currMouse.middleState = MBS_DoubleClick;
m_currMouse.middleFrame = m_inputFrame;
}
else
{
// Mouse Up
m_currMouse.middleEvent = GWM_MIDDLE_UP;
m_currMouse.middleState = MBS_Up;
m_currMouse.middleFrame = m_inputFrame;
}
}
}
Expand All @@ -328,7 +316,7 @@ void Mouse::processMouseEvent( Int index )

m_currMouse.deltaPos.x = m_currMouse.pos.x - m_prevMouse.pos.x;
m_currMouse.deltaPos.y = m_currMouse.pos.y - m_prevMouse.pos.y;
// DEBUG_LOG(("Mouse dx %d, dy %d, index %d, frame %d", m_currMouse.deltaPos.x, m_currMouse.deltaPos.y, index, m_inputFrame));
// DEBUG_LOG(("Mouse dx %d, dy %d, index %d", m_currMouse.deltaPos.x, m_currMouse.deltaPos.y, index));
// // check if mouse is still and flag tooltip
// if( ((dx*dx) + (dy*dy)) < CURSOR_MOVE_TOL_SQ )
// {
Expand Down Expand Up @@ -474,9 +462,6 @@ Mouse::Mouse( void )
m_maxY = 0;
m_eventsThisFrame = 0;

m_inputFrame = 0;
m_deadInputFrame =0;

m_inputMovesAbsolute = FALSE;

m_currentCursor = ARROW;
Expand Down Expand Up @@ -590,9 +575,6 @@ void Mouse::init( void )
m_minY = 0;
m_maxY = 599;

m_inputFrame = 0;
m_deadInputFrame =0;

m_inputMovesAbsolute = FALSE;
m_eventsThisFrame = 0;

Expand Down Expand Up @@ -676,9 +658,6 @@ void Mouse::reset( void )
void Mouse::update( void )
{

// increment input frame
m_inputFrame++;

// update the mouse data
updateMouseData( );

Expand Down
Loading
Loading