Skip to content

Commit 54e20f5

Browse files
committed
perf(input): Reduce timeGetTime() calls in keyboard input processing
1 parent fe6b2c3 commit 54e20f5

File tree

1 file changed

+6
-1
lines changed
  • Generals/Code/GameEngine/Source/GameClient/Input

1 file changed

+6
-1
lines changed

Generals/Code/GameEngine/Source/GameClient/Input/Keyboard.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ void Keyboard::updateKeys( void )
130130
}
131131
while( m_keys[ index++ ].key != KEY_NONE );
132132

133+
// Get current time once for all key updates
134+
UnsignedInt now = 0;
135+
133136
// update keyboard status array
134137
index = 0;
135138
while( m_keys[ index ].key != KEY_NONE )
@@ -145,7 +148,9 @@ void Keyboard::updateKeys( void )
145148
// Update key down time for new key presses
146149
if( BitIsSet( m_keys[ index ].state, KEY_STATE_DOWN ) )
147150
{
148-
m_keyStatus[ m_keys[ index ].key ].keyDownTimeMsec = timeGetTime();
151+
if( !now )
152+
now = timeGetTime();
153+
m_keyStatus[ m_keys[ index ].key ].keyDownTimeMsec = now;
149154
}
150155

151156
// prevent ALT-TAB from causing a TAB event

0 commit comments

Comments
 (0)