Skip to content

Commit 28eb5b5

Browse files
committed
perf(input): Use DirectInput timestamp for key down time and update comment
1 parent 9db2477 commit 28eb5b5

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void Keyboard::updateKeys( void )
144144
// Update key down time for new key presses
145145
if( BitIsSet( m_keys[ index ].state, KEY_STATE_DOWN ) )
146146
{
147-
m_keyStatus[ m_keys[ index ].key ].keyDownTimeMsec = timeGetTime();
147+
m_keyStatus[ m_keys[ index ].key ].keyDownTimeMsec = m_keys[ index ].keyDownTimeMsec;
148148
}
149149

150150
// prevent ALT-TAB from causing a TAB event
@@ -200,7 +200,7 @@ void Keyboard::updateKeys( void )
200200
}
201201

202202
//-------------------------------------------------------------------------------------------------
203-
/** check key repeat sequences, TRUE is returned if repeat is occurring */
203+
/** check key repeat timing, TRUE is returned if repeat is occurring */
204204
//-------------------------------------------------------------------------------------------------
205205
Bool Keyboard::checkKeyRepeat( void )
206206
{

Generals/Code/GameEngineDevice/Source/Win32Device/GameClient/Win32DIKeyboard.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,15 @@ void DirectInputKeyboard::getKey( KeyboardIO *key )
319319
// and not a bit set of the up/down state, this is the "start"
320320
// of building this "key"
321321
//
322-
key->state = (( kbdat.dwData & 0x0080 ) ? KEY_STATE_DOWN : KEY_STATE_UP);
322+
if( kbdat.dwData & 0x0080 )
323+
{
324+
key->state = KEY_STATE_DOWN;
325+
key->keyDownTimeMsec = kbdat.dwTimeStamp;
326+
}
327+
else
328+
{
329+
key->state = KEY_STATE_UP;
330+
}
323331

324332
// set status as unused (unprocessed)
325333
key->status = KeyboardIO::STATUS_UNUSED;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void Keyboard::updateKeys( void )
144144
// Update key down time for new key presses
145145
if( BitIsSet( m_keys[ index ].state, KEY_STATE_DOWN ) )
146146
{
147-
m_keyStatus[ m_keys[ index ].key ].keyDownTimeMsec = timeGetTime();
147+
m_keyStatus[ m_keys[ index ].key ].keyDownTimeMsec = m_keys[ index ].keyDownTimeMsec;
148148
}
149149

150150
// prevent ALT-TAB from causing a TAB event
@@ -200,7 +200,7 @@ void Keyboard::updateKeys( void )
200200
}
201201

202202
//-------------------------------------------------------------------------------------------------
203-
/** check key repeat sequences, TRUE is returned if repeat is occurring */
203+
/** check key repeat timing, TRUE is returned if repeat is occurring */
204204
//-------------------------------------------------------------------------------------------------
205205
Bool Keyboard::checkKeyRepeat( void )
206206
{

GeneralsMD/Code/GameEngineDevice/Source/Win32Device/GameClient/Win32DIKeyboard.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,15 @@ void DirectInputKeyboard::getKey( KeyboardIO *key )
319319
// and not a bit set of the up/down state, this is the "start"
320320
// of building this "key"
321321
//
322-
key->state = (( kbdat.dwData & 0x0080 ) ? KEY_STATE_DOWN : KEY_STATE_UP);
322+
if( kbdat.dwData & 0x0080 )
323+
{
324+
key->state = KEY_STATE_DOWN;
325+
key->keyDownTimeMsec = kbdat.dwTimeStamp;
326+
}
327+
else
328+
{
329+
key->state = KEY_STATE_UP;
330+
}
323331

324332
// set status as unused (unprocessed)
325333
key->status = KeyboardIO::STATUS_UNUSED;

0 commit comments

Comments
 (0)