From a32dd4c5aa8365db8bba24500c6c287377d4fe83 Mon Sep 17 00:00:00 2001 From: auria Date: Mon, 30 Mar 2009 01:42:12 +0000 Subject: [PATCH] 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 --- src/input/device_manager.cpp | 8 +++++--- src/input/device_manager.hpp | 2 +- src/input/input_device.cpp | 2 -- src/input/input_manager.cpp | 11 ++++++++--- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/input/device_manager.cpp b/src/input/device_manager.cpp index 4c9398e63..7207b3015 100644 --- a/src/input/device_manager.cpp +++ b/src/input/device_manager.cpp @@ -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()); diff --git a/src/input/device_manager.hpp b/src/input/device_manager.hpp index ac2d93c80..7b71f3e98 100644 --- a/src/input/device_manager.hpp +++ b/src/input/device_manager.hpp @@ -26,7 +26,7 @@ public: void serialize(); bool deserialize(); - void checkForGamePad(const int sdl_id); + bool checkForGamePad(const int sdl_id); }; diff --git a/src/input/input_device.cpp b/src/input/input_device.cpp index bcb5a41e3..45dca063c 100644 --- a/src/input/input_device.cpp +++ b/src/input/input_device.cpp @@ -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 << "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