Most of Game is generic, but not all. Split the InputMapper-

specific stuff apart into InputScheme.
This commit is contained in:
Glenn Maynard
2006-09-30 08:18:36 +00:00
parent 3460f79f54
commit 928e950006
4 changed files with 53 additions and 35 deletions
+4 -4
View File
@@ -4,14 +4,14 @@
#include "RageUtil.h" #include "RageUtil.h"
#include "PrefsManager.h" #include "PrefsManager.h"
int Game::GetNumGameplayButtons() const int InputScheme::GetNumGameplayButtons() const
{ {
int iIndexOfStart = ButtonNameToIndex( "Start" ); int iIndexOfStart = ButtonNameToIndex( "Start" );
ASSERT( iIndexOfStart != GameButton_Invalid ); ASSERT( iIndexOfStart != GameButton_Invalid );
return iIndexOfStart; return iIndexOfStart;
} }
GameButton Game::ButtonNameToIndex( const RString &sButtonName ) const GameButton InputScheme::ButtonNameToIndex( const RString &sButtonName ) const
{ {
for( int i=0; i<m_iButtonsPerController; i++ ) for( int i=0; i<m_iButtonsPerController; i++ )
if( stricmp(m_szButtonNames[i], sButtonName) == 0 ) if( stricmp(m_szButtonNames[i], sButtonName) == 0 )
@@ -20,7 +20,7 @@ GameButton Game::ButtonNameToIndex( const RString &sButtonName ) const
return GameButton_Invalid; return GameButton_Invalid;
} }
MenuButton Game::GameInputToMenuButton( GameInput GameI ) const MenuButton InputScheme::GameInputToMenuButton( GameInput GameI ) const
{ {
FOREACH_MenuButton(i) FOREACH_MenuButton(i)
if( m_DedicatedMenuButton[i] == GameI.button ) if( m_DedicatedMenuButton[i] == GameI.button )
@@ -36,7 +36,7 @@ MenuButton Game::GameInputToMenuButton( GameInput GameI ) const
return MenuButton_INVALID; // invalid GameInput return MenuButton_INVALID; // invalid GameInput
} }
void Game::MenuButtonToGameInputs( MenuButton MenuI, PlayerNumber pn, GameInput GameIout[4] ) const void InputScheme::MenuButtonToGameInputs( MenuButton MenuI, PlayerNumber pn, GameInput GameIout[4] ) const
{ {
ASSERT( MenuI != MenuButton_INVALID ); ASSERT( MenuI != MenuButton_INVALID );
+2 -10
View File
@@ -7,6 +7,7 @@
#include "MenuInput.h" #include "MenuInput.h"
#include "GameConstantsAndTypes.h" #include "GameConstantsAndTypes.h"
#include "RageInputDevice.h" #include "RageInputDevice.h"
#include "InputMapper.h"
struct lua_State; struct lua_State;
@@ -37,16 +38,7 @@ public:
const char *m_szName; const char *m_szName;
bool m_bCountNotesSeparately; // Count multiple notes in a row as separate notes or as one note bool m_bCountNotesSeparately; // Count multiple notes in a row as separate notes or as one note
int m_iButtonsPerController; InputScheme m_InputScheme;
int GetNumGameplayButtons() const;
char m_szButtonNames[NUM_GameButton][60]; // The name used by the button graphics system. e.g. "left", "right", "middle C", "snare"
GameButton m_DedicatedMenuButton[NUM_MenuButton];
GameButton m_SecondaryMenuButton[NUM_MenuButton];
DeviceButton m_iDefaultKeyboardKey[NUM_GameController][NUM_GameButton]; // default keyboard keys only have an effect the current game is this game
GameButton ButtonNameToIndex( const RString &sButtonName ) const;
MenuButton GameInputToMenuButton( GameInput GameI ) const;
void MenuButtonToGameInputs( MenuButton MenuI, PlayerNumber pn, GameInput GameIout[4] ) const;
TapNoteScore MapTapNoteScore( TapNoteScore tns ) const; TapNoteScore MapTapNoteScore( TapNoteScore tns ) const;
TapNoteScore m_mapW1To; TapNoteScore m_mapW1To;
+28 -21
View File
@@ -27,7 +27,6 @@ InputMapper* INPUTMAPPER = NULL; // global and accessable from anywhere in our p
InputMapper::InputMapper() InputMapper::InputMapper()
{ {
ReadMappingsFromDisk();
} }
@@ -52,12 +51,11 @@ void InputMapper::AddDefaultMappingsForCurrentGameIfUnmapped()
FOREACH_GameButton(j) FOREACH_GameButton(j)
ClearFromInputMap( GameInput(i, j), 2 ); ClearFromInputMap( GameInput(i, j), 2 );
const Game* pGame = GAMESTATE->GetCurrentGame();
FOREACH_GameController( c ) FOREACH_GameController( c )
{ {
for( int b=0; b<pGame->m_iButtonsPerController; b++ ) for( int b=0; b<m_pInputScheme->m_iButtonsPerController; b++ )
{ {
DeviceButton key = pGame->m_iDefaultKeyboardKey[c][b]; DeviceButton key = m_pInputScheme->m_iDefaultKeyboardKey[c][b];
if( key == NO_DEFAULT_KEY ) if( key == NO_DEFAULT_KEY )
continue; continue;
DeviceInput DeviceI( DEVICE_KEYBOARD, key ); DeviceInput DeviceI( DEVICE_KEYBOARD, key );
@@ -498,8 +496,6 @@ void InputMapper::AutoMapJoysticksForCurrentGame()
int iNumJoysticksMapped = 0; int iNumJoysticksMapped = 0;
const Game* pGame = GAMESTATE->m_pCurGame;
for( unsigned i=0; i<vDevices.size(); i++ ) for( unsigned i=0; i<vDevices.size(); i++ )
{ {
InputDevice id = vDevices[i].id; InputDevice id = vDevices[i].id;
@@ -508,7 +504,7 @@ void InputMapper::AutoMapJoysticksForCurrentGame()
{ {
const AutoJoyMapping& mapping = g_AutoJoyMappings[j]; const AutoJoyMapping& mapping = g_AutoJoyMappings[j];
if( pGame != GAMEMAN->StringToGameType(mapping.szGame) ) if( RString(m_pInputScheme->m_szName).CompareNoCase(mapping.szGame) )
continue; // games don't match continue; // games don't match
RString sDriverRegex = mapping.szDriverRegex; RString sDriverRegex = mapping.szDriverRegex;
@@ -534,6 +530,18 @@ void InputMapper::AutoMapJoysticksForCurrentGame()
} }
} }
void InputMapper::SetInputScheme( const InputScheme *pInputScheme )
{
m_pInputScheme = pInputScheme;
ReadMappingsFromDisk();
}
const InputScheme *InputMapper::GetInputScheme() const
{
return m_pInputScheme;
}
static const RString DEVICE_INPUT_SEPARATOR = ":"; // this isn't used in any key names static const RString DEVICE_INPUT_SEPARATOR = ":"; // this isn't used in any key names
void InputMapper::ReadMappingsFromDisk() void InputMapper::ReadMappingsFromDisk()
@@ -547,9 +555,7 @@ void InputMapper::ReadMappingsFromDisk()
LOG->Trace( "Couldn't open mapping file \"%s\": %s.", LOG->Trace( "Couldn't open mapping file \"%s\": %s.",
SpecialFiles::KEYMAPS_PATH.c_str(), ini.GetError().c_str() ); SpecialFiles::KEYMAPS_PATH.c_str(), ini.GetError().c_str() );
const Game *pGame = GAMESTATE->GetCurrentGame(); const XNode *Key = ini.GetChild( m_pInputScheme->m_szName );
const XNode *Key = ini.GetChild( pGame->m_szName );
if( Key ) if( Key )
{ {
@@ -559,7 +565,7 @@ void InputMapper::ReadMappingsFromDisk()
const RString &value = i->second; const RString &value = i->second;
GameInput GameI; GameInput GameI;
GameI.FromString( pGame, name ); GameI.FromString( m_pInputScheme, name );
vector<RString> sDeviceInputStrings; vector<RString> sDeviceInputStrings;
split( value, DEVICE_INPUT_SEPARATOR, sDeviceInputStrings, false ); split( value, DEVICE_INPUT_SEPARATOR, sDeviceInputStrings, false );
@@ -582,18 +588,21 @@ void InputMapper::SaveMappingsToDisk()
IniFile ini; IniFile ini;
ini.ReadFile( SpecialFiles::KEYMAPS_PATH ); ini.ReadFile( SpecialFiles::KEYMAPS_PATH );
const Game* pGame = GAMESTATE->GetCurrentGame();
// erase the key so that we overwrite everything for this game // erase the key so that we overwrite everything for this game
ini.DeleteKey( pGame->m_szName ); ini.DeleteKey( m_pInputScheme->m_szName );
XNode *pKey = ini.GetChild( m_pInputScheme->m_szName );
if( pKey != NULL )
ini.RemoveChild( pKey );
pKey = ini.AppendChild( m_pInputScheme->m_szName );
// iterate over our input map and write all mappings to the ini file // iterate over our input map and write all mappings to the ini file
FOREACH_GameController( i ) FOREACH_GameController( i )
{ {
for( int j=0; j<pGame->m_iButtonsPerController; j++ ) for( int j=0; j<m_pInputScheme->m_iButtonsPerController; j++ )
{ {
GameInput GameI( i, (GameButton)j ); GameInput GameI( i, (GameButton)j );
RString sNameString = GameI.ToString( pGame ); RString sNameString = GameI.ToString( m_pInputScheme );
vector<RString> asValues; vector<RString> asValues;
for( int slot = 0; slot < NUM_USER_GAME_TO_DEVICE_SLOTS; ++slot ) // don't save data from the last (keyboard automap) slot for( int slot = 0; slot < NUM_USER_GAME_TO_DEVICE_SLOTS; ++slot ) // don't save data from the last (keyboard automap) slot
@@ -604,7 +613,7 @@ void InputMapper::SaveMappingsToDisk()
RString sValueString = join( DEVICE_INPUT_SEPARATOR, asValues ); RString sValueString = join( DEVICE_INPUT_SEPARATOR, asValues );
ini.SetValue( pGame->m_szName, sNameString, sValueString ); pKey->AppendAttr( sNameString, sValueString );
} }
} }
@@ -771,8 +780,7 @@ PlayerNumber InputMapper::ControllerToPlayerNumber( GameController controller )
MenuButton InputMapper::GameToMenu( const GameInput &GameI ) MenuButton InputMapper::GameToMenu( const GameInput &GameI )
{ {
const Game* pGame = GAMESTATE->GetCurrentGame(); return m_pInputScheme->GameInputToMenuButton( GameI );
return pGame->GameInputToMenuButton( GameI );
} }
void InputMapper::MenuToGame( MenuButton MenuI, PlayerNumber pn, GameInput GameIout[4] ) void InputMapper::MenuToGame( MenuButton MenuI, PlayerNumber pn, GameInput GameIout[4] )
@@ -783,8 +791,7 @@ void InputMapper::MenuToGame( MenuButton MenuI, PlayerNumber pn, GameInput GameI
pn = PLAYER_INVALID; pn = PLAYER_INVALID;
} }
const Game* pGame = GAMESTATE->GetCurrentGame(); m_pInputScheme->MenuButtonToGameInputs( MenuI, pn, GameIout );
pGame->MenuButtonToGameInputs( MenuI, pn, GameIout );
} }
+19
View File
@@ -12,12 +12,30 @@ const int NUM_GAME_TO_DEVICE_SLOTS = 5; // five device inputs may map to one gam
const int NUM_SHOWN_GAME_TO_DEVICE_SLOTS = 3; const int NUM_SHOWN_GAME_TO_DEVICE_SLOTS = 3;
const int NUM_USER_GAME_TO_DEVICE_SLOTS = 2; const int NUM_USER_GAME_TO_DEVICE_SLOTS = 2;
class InputScheme
{
public:
const char *m_szName;
int m_iButtonsPerController;
char m_szButtonNames[NUM_GameButton][60]; // The name used by the button graphics system. e.g. "left", "right", "middle C", "snare"
GameButton m_DedicatedMenuButton[NUM_MenuButton];
GameButton m_SecondaryMenuButton[NUM_MenuButton];
DeviceButton m_iDefaultKeyboardKey[NUM_GameController][NUM_GameButton]; // default keyboard keys only have an effect the current game is this game
int GetNumGameplayButtons() const;
GameButton ButtonNameToIndex( const RString &sButtonName ) const;
MenuButton GameInputToMenuButton( GameInput GameI ) const;
void MenuButtonToGameInputs( MenuButton MenuI, PlayerNumber pn, GameInput GameIout[4] ) const;
};
class InputMapper class InputMapper
{ {
public: public:
InputMapper(); InputMapper();
~InputMapper(); ~InputMapper();
void SetInputScheme( const InputScheme *pInputScheme );
const InputScheme *GetInputScheme() const;
void ReadMappingsFromDisk(); void ReadMappingsFromDisk();
void SaveMappingsToDisk(); void SaveMappingsToDisk();
@@ -82,6 +100,7 @@ protected:
DeviceInput m_GItoDI[NUM_GameController][NUM_GameButton][NUM_GAME_TO_DEVICE_SLOTS]; DeviceInput m_GItoDI[NUM_GameController][NUM_GameButton][NUM_GAME_TO_DEVICE_SLOTS];
void UpdateTempDItoGI(); void UpdateTempDItoGI();
const InputScheme *m_pInputScheme;
}; };