Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 7 additions & 2 deletions Generals/Code/GameEngine/Include/GameClient/KeyDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
/** The key tables */
//=============================================================================

enum KeyDefType CPP_11(: Int)
enum KeyDefType CPP_11(: UnsignedByte)
{
// keypad keys ----------------------------------------------------------------
KEY_KP0 = DIK_NUMPAD0,
Expand Down Expand Up @@ -224,10 +224,15 @@ enum KeyDefType CPP_11(: Int)

// specials -------------------------------------------------------------------
KEY_NONE = 0x00, ///< to report end of key stream
KEY_LOST = 0xFF ///< to report lost keyboard focus
KEY_LOST = 0xFF, ///< to report lost keyboard focus

};

enum
{
KEY_COUNT = 256
};

// state for keyboard IO ------------------------------------------------------
enum
{
Expand Down
30 changes: 16 additions & 14 deletions Generals/Code/GameEngine/Include/GameClient/Keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@
struct KeyboardIO
{

enum StatusType
enum StatusType CPP_11(: UnsignedByte)
{
STATUS_UNUSED = 0x00, // Key has not been used
STATUS_USED = 0x01 // Key has been eaten
};

UnsignedByte key; // key data
void setUsed() { status = STATUS_USED; }

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
Expand All @@ -91,7 +93,7 @@ class Keyboard : public SubsystemInterface
Keyboard( void );
virtual ~Keyboard( void );

// you may extend the functionanilty of these for your device
// you may extend the functionality of these for your device
virtual void init( void ); /**< initialize the keyboard, only extend this
functionality, do not replace */
virtual void reset( void ); ///< Reset keyboard system
Expand All @@ -111,10 +113,11 @@ class Keyboard : public SubsystemInterface
// access methods for key data
void resetKeys( void ); ///< reset the state of the keys
KeyboardIO *getFirstKey( void ); ///< get first key ready for processing
void setKeyStatusData( UnsignedByte key,
KeyboardIO *findKey( KeyDefType key, KeyboardIO::StatusType status ); ///< get key ready for processing, can return NULL
void setKeyStatusData( KeyDefType key,
KeyboardIO::StatusType data ); ///< set key status
WideChar translateKey( WideChar keyCode ); ///< translte key code to printable UNICODE char
WideChar getPrintableKey( UnsignedByte key, Int state );
WideChar translateKey( WideChar keyCode ); ///< translate key code to printable UNICODE char
WideChar getPrintableKey( KeyDefType key, Int state );
enum { MAX_KEY_STATES = 3};
protected:

Expand All @@ -126,10 +129,10 @@ class Keyboard : public SubsystemInterface
void initKeyNames( void ); ///< initialize the key names table
void updateKeys( void ); ///< update the state of our key data
Bool checkKeyRepeat( void ); ///< check for repeating keys
UnsignedByte getKeyStatusData( UnsignedByte key ); ///< get key status
Bool getKeyStateBit( UnsignedByte key, Int bit ); ///< get key state bit
UnsignedInt getKeySequenceData( UnsignedByte key ); ///< get key sequence
void setKeyStateData( UnsignedByte key, UnsignedByte data ); ///< get key state
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;
// internal keyboard data members
Expand All @@ -142,21 +145,20 @@ class Keyboard : public SubsystemInterface
//Bool m_rControlState; // 1 if right control is down
//Bool m_lAltState; // 1 if left alt is down
//Bool m_rAltState; // 1 if right alt is down
UnsignedByte m_shift2Key; // what key is the secondary shift key
KeyDefType m_shift2Key; // what key is the secondary shift key

enum { NUM_KEYS = 256 };
KeyboardIO m_keys[ NUM_KEYS ]; ///< the keys
KeyboardIO m_keyStatus[ NUM_KEYS ]; ///< the key status flags
KeyboardIO m_keyStatus[ KEY_COUNT ]; ///< the key status flags

enum { KEY_NAMES_COUNT = 256 };
struct
{

WideChar stdKey;
WideChar shifted;
WideChar shifted2;

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

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
#include "GameClient/GameWindowManager.h"
#include "GameClient/Gadget.h"
#include "GameClient/GameText.h"
#include "GameClient/Keyboard.h"
#include "GameClient/MapUtil.h"
#include "GameClient/Shell.h"
#include "GameClient/KeyDefs.h"
Expand Down Expand Up @@ -640,6 +641,18 @@ void PlayMovieAndBlock(AsciiString movieTitle)
TheWritableGlobalData->m_loadScreenRender = TRUE;
while (videoStream->frameIndex() < videoStream->frameCount() - 1)
{
// TheSuperHackers @feature User can now skip video by pressing ESC
if (TheKeyboard)
{
TheKeyboard->UPDATE();
KeyboardIO *io = TheKeyboard->findKey(KEY_ESC, KeyboardIO::STATUS_UNUSED);
if (io && BitIsSet(io->state, KEY_STATE_DOWN))
{
io->setUsed();
break;
}
}

TheGameEngine->serviceWindowsOS();

if(!videoStream->isFrameReady())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ WindowMsgHandledType GadgetListBoxInput( GameWindow *window, UnsignedInt msg,
continue;
for(j = 0; j < TheKeyboard->MAX_KEY_STATES; ++j)
{
if(dString->getText().getCharAt(0) == TheKeyboard->getPrintableKey(mData1, j))
if(dString->getText().getCharAt(0) == TheKeyboard->getPrintableKey((KeyDefType)mData1, j))
{
list->selectPos = position;
Int prevPos = getListboxTopEntry(list);
Expand Down
13 changes: 13 additions & 0 deletions Generals/Code/GameEngine/Source/GameClient/GUI/LoadScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "Common/AudioAffect.h"

#include "GameClient/LoadScreen.h"
#include "GameClient/Keyboard.h"
#include "GameClient/Shell.h"
#include "GameClient/GameWindowManager.h"
#include "GameClient/GadgetProgressBar.h"
Expand Down Expand Up @@ -490,6 +491,18 @@ void SinglePlayerLoadScreen::init( GameInfo *game )
Int shiftedPercent = -FRAME_FUDGE_ADD + 1;
while (m_videoStream->frameIndex() < m_videoStream->frameCount() - 1 )
{
// TheSuperHackers @feature User can now skip video by pressing ESC
if (TheKeyboard)
{
TheKeyboard->UPDATE();
KeyboardIO *io = TheKeyboard->findKey(KEY_ESC, KeyboardIO::STATUS_UNUSED);
if (io && BitIsSet(io->state, KEY_STATE_DOWN))
{
io->setUsed();
break;
}
}

TheGameEngine->serviceWindowsOS();

if(!m_videoStream->isFrameReady())
Expand Down
37 changes: 25 additions & 12 deletions Generals/Code/GameEngine/Source/GameClient/Input/Keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Keyboard *TheKeyboard = NULL;
void Keyboard::createStreamMessages( void )
{

// santiy
// sanity
if( TheMessageStream == NULL )
return;

Expand Down Expand Up @@ -89,6 +89,7 @@ void Keyboard::createStreamMessages( void )
}

// next key please
key->setUsed();
key++;

}
Expand Down Expand Up @@ -213,7 +214,7 @@ Bool Keyboard::checkKeyRepeat( void )

// Scan Keyboard status array for first key down
// long enough to repeat
for( key = 0; key < 256; key++ )
for( key = 0; key < ARRAY_SIZE(m_keyStatus); key++ )
{

if( BitIsSet( m_keyStatus[ key ].state, KEY_STATE_DOWN ) )
Expand Down Expand Up @@ -261,7 +262,7 @@ void Keyboard::initKeyNames( void )
/*
* Initialize the keyboard key-names array.
*/
for( i = 0; i < KEY_NAMES_COUNT; i++ )
for( i = 0; i < ARRAY_SIZE(m_keyNames); i++ )
{

m_keyNames[ i ].stdKey = L'\0';
Expand Down Expand Up @@ -765,42 +766,56 @@ KeyboardIO *Keyboard::getFirstKey( void )
return &m_keys[ 0 ];
}

//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
KeyboardIO *Keyboard::findKey( KeyDefType key, KeyboardIO::StatusType status )
{
for (KeyboardIO *io = getFirstKey(); io->key != KEY_NONE; ++io)
{
if (io->key == key && io->status == status)
{
return io;
}
}
return NULL;
}

//-------------------------------------------------------------------------------------------------
/** return the key status for the specified key */
//-------------------------------------------------------------------------------------------------
UnsignedByte Keyboard::getKeyStatusData( UnsignedByte key )
UnsignedByte Keyboard::getKeyStatusData( KeyDefType key )
{
return m_keyStatus[ key ].status;
}

//-------------------------------------------------------------------------------------------------
/** Get the key state data as a Bool for the specified key */
//-------------------------------------------------------------------------------------------------
Bool Keyboard::getKeyStateBit( UnsignedByte key, Int bit )
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( UnsignedByte key )
UnsignedInt Keyboard::getKeySequenceData( KeyDefType key )
{
return m_keyStatus[ key ].sequence;
}

//-------------------------------------------------------------------------------------------------
/** set the key status data */
//-------------------------------------------------------------------------------------------------
void Keyboard::setKeyStatusData( UnsignedByte key, KeyboardIO::StatusType data )
void Keyboard::setKeyStatusData( KeyDefType key, KeyboardIO::StatusType data )
{
m_keyStatus[ key ].status = data;
}

//-------------------------------------------------------------------------------------------------
/** set the key state data */
//-------------------------------------------------------------------------------------------------
void Keyboard::setKeyStateData( UnsignedByte key, UnsignedByte data )
void Keyboard::setKeyStateData( KeyDefType key, UnsignedByte data )
{
m_keyStatus[ key ].state = data;
}
Expand Down Expand Up @@ -973,16 +988,14 @@ Bool Keyboard::isAlt()
}


WideChar Keyboard::getPrintableKey( UnsignedByte key, Int state )
WideChar Keyboard::getPrintableKey( KeyDefType key, Int state )
{
if((key < 0 || key >=KEY_NAMES_COUNT) || ( state < 0 || state >= MAX_KEY_STATES))
if((key < 0 || key >= ARRAY_SIZE(m_keyNames)) || ( state < 0 || state >= MAX_KEY_STATES))
return L'\0';
if(state == 0)
return m_keyNames[key].stdKey;
else if(state == 1)
return m_keyNames[key].shifted;
else
return m_keyNames[key].shifted2;


}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ GameMessageDisposition HotKeyTranslator::translateGameMessage(const GameMessage
}
if(newModState != 0)
return disp;
WideChar key = TheKeyboard->getPrintableKey(msg->getArgument(0)->integer, 0);
WideChar key = TheKeyboard->getPrintableKey((KeyDefType)msg->getArgument(0)->integer, 0);
UnicodeString uKey;
uKey.concat(key);
AsciiString aKey;
Expand Down
9 changes: 7 additions & 2 deletions GeneralsMD/Code/GameEngine/Include/GameClient/KeyDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
/** The key tables */
//=============================================================================

enum KeyDefType CPP_11(: Int)
enum KeyDefType CPP_11(: UnsignedByte)
{
// keypad keys ----------------------------------------------------------------
KEY_KP0 = DIK_NUMPAD0,
Expand Down Expand Up @@ -224,10 +224,15 @@ enum KeyDefType CPP_11(: Int)

// specials -------------------------------------------------------------------
KEY_NONE = 0x00, ///< to report end of key stream
KEY_LOST = 0xFF ///< to report lost keyboard focus
KEY_LOST = 0xFF, ///< to report lost keyboard focus

};

enum
{
KEY_COUNT = 256
};

// state for keyboard IO ------------------------------------------------------
enum
{
Expand Down
Loading
Loading