Skip to content

Commit 5b9176e

Browse files
committed
perf(input): Gate timeGetTime call behind key down check in repeat logic
1 parent ed61450 commit 5b9176e

File tree

2 files changed

+4
-2
lines changed
  • GeneralsMD/Code/GameEngine/Source/GameClient/Input
  • Generals/Code/GameEngine/Source/GameClient/Input

2 files changed

+4
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,14 @@ Bool Keyboard::checkKeyRepeat( void )
220220
// Scan Keyboard status array for first key down
221221
// long enough to repeat
222222
const UnsignedInt KEY_REPEAT_INTERVAL_MSEC = 67; // ~2 frames at 30 FPS
223-
UnsignedInt now = timeGetTime();
224223
for( key = 0; key < ARRAY_SIZE(m_keyStatus); key++ )
225224
{
226225

227226
if( BitIsSet( m_keyStatus[ key ].state, KEY_STATE_DOWN ) )
228227
{
229228

229+
UnsignedInt now = timeGetTime();
230+
230231
if( now - m_keyStatus[ key ].keyDownTimeMsec > Keyboard::KEY_REPEAT_DELAY_MSEC )
231232
{
232233
// Add key to this frame

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,14 @@ Bool Keyboard::checkKeyRepeat( void )
220220
// Scan Keyboard status array for first key down
221221
// long enough to repeat
222222
const UnsignedInt KEY_REPEAT_INTERVAL_MSEC = 67; // ~2 frames at 30 FPS
223-
UnsignedInt now = timeGetTime();
224223
for( key = 0; key < ARRAY_SIZE(m_keyStatus); key++ )
225224
{
226225

227226
if( BitIsSet( m_keyStatus[ key ].state, KEY_STATE_DOWN ) )
228227
{
229228

229+
UnsignedInt now = timeGetTime();
230+
230231
if( now - m_keyStatus[ key ].keyDownTimeMsec > Keyboard::KEY_REPEAT_DELAY_MSEC )
231232
{
232233
// Add key to this frame

0 commit comments

Comments
 (0)