fix slightly excessive memory usage
This commit is contained in:
@@ -16,6 +16,13 @@
|
|||||||
static Preference<CString> g_sLastSeenInputDevices( "LastSeenInputDevices", "" );
|
static Preference<CString> g_sLastSeenInputDevices( "LastSeenInputDevices", "" );
|
||||||
static Preference<bool> g_bAutoMapOnJoyChange( "AutoMapOnJoyChange", true );
|
static Preference<bool> g_bAutoMapOnJoyChange( "AutoMapOnJoyChange", true );
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
// lookup for efficiency from a DeviceInput to a GameInput
|
||||||
|
// This is repopulated every time m_PItoDI changes by calling UpdateTempDItoPI().
|
||||||
|
map<DeviceInput, GameInput> g_tempDItoGI;
|
||||||
|
};
|
||||||
|
|
||||||
InputMapper* INPUTMAPPER = NULL; // global and accessable from anywhere in our program
|
InputMapper* INPUTMAPPER = NULL; // global and accessable from anywhere in our program
|
||||||
|
|
||||||
InputMapper::InputMapper()
|
InputMapper::InputMapper()
|
||||||
@@ -27,6 +34,7 @@ InputMapper::InputMapper()
|
|||||||
InputMapper::~InputMapper()
|
InputMapper::~InputMapper()
|
||||||
{
|
{
|
||||||
SaveMappingsToDisk();
|
SaveMappingsToDisk();
|
||||||
|
g_tempDItoGI.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputMapper::ClearAllMappings()
|
void InputMapper::ClearAllMappings()
|
||||||
@@ -607,7 +615,7 @@ bool InputMapper::ClearFromInputMap( const GameInput &GameI, int iSlotIndex )
|
|||||||
|
|
||||||
bool InputMapper::IsMapped( const DeviceInput &DeviceI )
|
bool InputMapper::IsMapped( const DeviceInput &DeviceI )
|
||||||
{
|
{
|
||||||
return m_tempDItoGI[DeviceI.device][DeviceI.button].IsValid();
|
return g_tempDItoGI.find(DeviceI) != g_tempDItoGI.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputMapper::IsMapped( const GameInput &GameI )
|
bool InputMapper::IsMapped( const GameInput &GameI )
|
||||||
@@ -622,17 +630,8 @@ bool InputMapper::IsMapped( const GameInput &GameI )
|
|||||||
|
|
||||||
void InputMapper::UpdateTempDItoGI()
|
void InputMapper::UpdateTempDItoGI()
|
||||||
{
|
{
|
||||||
// clear out m_tempDItoGI
|
// repopulate g_tempDItoGI
|
||||||
FOREACH_InputDevice( d )
|
g_tempDItoGI.clear();
|
||||||
{
|
|
||||||
for( int b=0; b<NUM_DeviceButton; b++ )
|
|
||||||
{
|
|
||||||
m_tempDItoGI[d][b].MakeInvalid();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// repopulate m_tempDItoGI
|
|
||||||
for( int n=0; n<MAX_GAME_CONTROLLERS; n++ )
|
for( int n=0; n<MAX_GAME_CONTROLLERS; n++ )
|
||||||
{
|
{
|
||||||
for( int b=0; b<MAX_GAME_BUTTONS; b++ )
|
for( int b=0; b<MAX_GAME_BUTTONS; b++ )
|
||||||
@@ -643,7 +642,7 @@ void InputMapper::UpdateTempDItoGI()
|
|||||||
DeviceInput DeviceI = m_GItoDI[n][b][s];
|
DeviceInput DeviceI = m_GItoDI[n][b][s];
|
||||||
|
|
||||||
if( DeviceI.IsValid() )
|
if( DeviceI.IsValid() )
|
||||||
m_tempDItoGI[DeviceI.device][DeviceI.button] = GameI;
|
g_tempDItoGI[DeviceI] = GameI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -651,7 +650,7 @@ void InputMapper::UpdateTempDItoGI()
|
|||||||
|
|
||||||
bool InputMapper::DeviceToGame( const DeviceInput &DeviceI, GameInput& GameI ) // return true if there is a mapping from device to pad
|
bool InputMapper::DeviceToGame( const DeviceInput &DeviceI, GameInput& GameI ) // return true if there is a mapping from device to pad
|
||||||
{
|
{
|
||||||
GameI = m_tempDItoGI[DeviceI.device][DeviceI.button];
|
GameI = g_tempDItoGI[DeviceI];
|
||||||
return GameI.controller != GAME_CONTROLLER_INVALID;
|
return GameI.controller != GAME_CONTROLLER_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,9 +80,6 @@ protected:
|
|||||||
// all the DeviceInputs that map to a GameInput
|
// all the DeviceInputs that map to a GameInput
|
||||||
DeviceInput m_GItoDI[MAX_GAME_CONTROLLERS][MAX_GAME_BUTTONS][NUM_GAME_TO_DEVICE_SLOTS];
|
DeviceInput m_GItoDI[MAX_GAME_CONTROLLERS][MAX_GAME_BUTTONS][NUM_GAME_TO_DEVICE_SLOTS];
|
||||||
|
|
||||||
// lookup for efficiency from a DeviceInput to a GameInput
|
|
||||||
// This is repopulated every time m_PItoDI changes by calling UpdateTempDItoPI().
|
|
||||||
GameInput m_tempDItoGI[NUM_INPUT_DEVICES][NUM_DeviceButton];
|
|
||||||
void UpdateTempDItoGI();
|
void UpdateTempDItoGI();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user