only write config file when needed + other cleanup
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3322 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
ac8192e53f
commit
a32dd4c5aa
@ -142,9 +142,9 @@ bool DeviceManager::deserialize()
|
||||
|
||||
/**
|
||||
* Check if we already have a config object for joystick 'sdl_id' as reported by SDL
|
||||
* If yes, 'open' the gamepad instance. If no, create one.
|
||||
* If yes, 'open' the gamepad instance and returns false. If no, create on and return true.
|
||||
*/
|
||||
void DeviceManager::checkForGamePad(const int sdl_id)
|
||||
bool DeviceManager::checkForGamePad(const int sdl_id)
|
||||
{
|
||||
std::string name = SDL_JoystickName(sdl_id);
|
||||
|
||||
@ -158,18 +158,20 @@ void DeviceManager::checkForGamePad(const int sdl_id)
|
||||
{
|
||||
std::cout << "--> that's the one\n";
|
||||
m_gamepads[n].open(sdl_id);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "couldn't find this joystick, so creating a new one" << std::endl;
|
||||
add(new GamePadDevice(sdl_id));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void DeviceManager::serialize()
|
||||
{
|
||||
static std::string filepath = file_manager->getHomeDir() + "/input.config";
|
||||
std::cout << "writing " << filepath.c_str() << std::endl;
|
||||
|
||||
std::ofstream configfile;
|
||||
configfile.open (filepath.c_str());
|
||||
|
@ -26,7 +26,7 @@ public:
|
||||
void serialize();
|
||||
bool deserialize();
|
||||
|
||||
void checkForGamePad(const int sdl_id);
|
||||
bool checkForGamePad(const int sdl_id);
|
||||
};
|
||||
|
||||
|
||||
|
@ -17,8 +17,6 @@ InputDevice::InputDevice()
|
||||
// -----------------------------------------------------------------------------
|
||||
void InputDevice::serialize(std::ofstream& stream)
|
||||
{
|
||||
std::cout << "writing a gamepad named " << m_name.c_str() << std::endl;
|
||||
|
||||
if (m_type == DT_KEYBOARD) stream << "<keyboard ";
|
||||
else if (m_type == DT_GAMEPAD) stream << "<gamepad name=\"" << m_name.c_str() << "\" ";
|
||||
else std::cerr << "Warning, unknown input device type, skipping it\n";
|
||||
|
@ -57,6 +57,8 @@ m_mode(BOOTSTRAP), m_mouse_val_x(0), m_mouse_val_y(0)
|
||||
|
||||
m_device_manager = new DeviceManager();
|
||||
|
||||
bool something_new_to_write = false;
|
||||
|
||||
if(!m_device_manager->deserialize())
|
||||
{
|
||||
std::cerr << "Failed to read input config file, using defaults\n";
|
||||
@ -65,6 +67,8 @@ m_mode(BOOTSTRAP), m_mouse_val_x(0), m_mouse_val_y(0)
|
||||
KeyboardDevice* default_device = new KeyboardDevice();
|
||||
default_device->loadDefaults();
|
||||
m_device_manager->add( default_device );
|
||||
|
||||
something_new_to_write = true;
|
||||
}
|
||||
|
||||
// Prepare a list of connected joysticks.
|
||||
@ -76,11 +80,11 @@ m_mode(BOOTSTRAP), m_mouse_val_x(0), m_mouse_val_y(0)
|
||||
// the constructor below should only be used if not
|
||||
for (int i = 0; i < numSticks; i++)
|
||||
{
|
||||
m_device_manager->checkForGamePad(i);
|
||||
something_new_to_write = m_device_manager->checkForGamePad(i) || something_new_to_write;
|
||||
}
|
||||
|
||||
// immediately save any new device we might meet
|
||||
m_device_manager->serialize();
|
||||
// write config file if necessary
|
||||
if(something_new_to_write) m_device_manager->serialize();
|
||||
|
||||
}
|
||||
|
||||
@ -509,6 +513,7 @@ void InputManager::input()
|
||||
ev.jaxis.which, ev.jaxis.axis, value);
|
||||
}
|
||||
|
||||
// FIXME - AD_NEGATIVE/AD_POSITIVE are probably useless since value contains that info too
|
||||
if(value < 0)
|
||||
input(Input::IT_STICKMOTION, ev.jaxis.which, ev.jaxis.axis, Input::AD_NEGATIVE, value);
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user