improved somewhat joystick loading from config, and added debug logging to help find what's wrong with minibjorn's

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3318 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-03-30 01:15:52 +00:00
parent 7fe245040a
commit 9c727717aa
4 changed files with 28 additions and 14 deletions

View File

@ -148,8 +148,12 @@ void DeviceManager::checkForGamePad(const int sdl_id)
{
std::string name = SDL_JoystickName(sdl_id);
std::cout << "trying to find gamepad " << name.c_str() << std::endl;
for(unsigned int n=0; n<m_gamepad_amount; n++)
{
std::cout << "gamepad " << n << " is named " << m_gamepads[n].m_name.c_str() << std::endl;
if(m_gamepads[n].m_name == name)
{
m_gamepads[n].open(sdl_id);
@ -157,6 +161,7 @@ void DeviceManager::checkForGamePad(const int sdl_id)
}
}
std::cout << "couldn't find" << std::endl;
add(new GamePadDevice(sdl_id));
}

View File

@ -17,8 +17,10 @@ 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 << "\" ";
else if (m_type == DT_GAMEPAD) stream << "<gamepad name=\"" << m_name.c_str() << "\" ";
else std::cerr << "Warning, unknown input device type, skipping it\n";
stream << "owner=\"" << m_player << "\">\n\n";
@ -167,11 +169,13 @@ GamePadDevice::GamePadDevice(irr::io::IrrXMLReader* xml)
GamePadDevice::GamePadDevice(int sdlIndex)
{
m_type = DT_GAMEPAD;
m_name = SDL_JoystickName(sdlIndex);
m_deadzone = DEADZONE_JOYSTICK;
open(sdlIndex);
m_name = SDL_JoystickName(sdlIndex);
std::cout << "creating a device named " << m_name.c_str() << "\n";
loadDefaults();
} // GamePadDevice
// -----------------------------------------------------------------------------

View File

@ -29,12 +29,13 @@ class InputDevice
{
protected:
DeviceType m_type;
std::string m_name; // if device has a name; unused for keyboards since SDL can't tell keyboards apart
KeyBinding m_bindings[PA_COUNT];
std::string m_player;
public:
std::string m_name; // if device has a name; unused for keyboards since SDL can't tell keyboards apart
InputDevice();
DeviceType getType() const { return m_type; };
@ -60,7 +61,6 @@ class GamePadDevice : public InputDevice
void resetAxisDirection(const int axis, Input::AxisDirection direction, const int player);
public:
SDL_Joystick *m_sdlJoystick;
std::string m_name;
int m_deadzone;
int m_index;
Input::AxisDirection *m_prevAxisDirections;

View File

@ -67,17 +67,22 @@ m_mode(BOOTSTRAP), m_mouse_val_x(0), m_mouse_val_y(0)
m_device_manager->add( default_device );
m_device_manager->serialize();
}
// Prepare a list of connected joysticks.
const int numSticks = SDL_NumJoysticks();
std::cout << "SDL detects " << numSticks << " gamepads" << std::endl;
// TODO - detect if device is currently known and has an entry in the config
// the constructor below should only be used if not
for (int i = 0; i < numSticks; i++)
else
{
m_device_manager->checkForGamePad(i);
// Prepare a list of connected joysticks.
const int numSticks = SDL_NumJoysticks();
std::cout << "SDL detects " << numSticks << " gamepads" << std::endl;
// TODO - detect if device is currently known and has an entry in the config
// the constructor below should only be used if not
for (int i = 0; i < numSticks; i++)
{
m_device_manager->checkForGamePad(i);
}
// FIXME - for testing purposes (immediately save any new device we might meet)
m_device_manager->serialize();
}
}