bringing gamepad back in (won't work in game but will be detected, watch terminal)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3422 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
87a274fc77
commit
6ed09ea3c5
@ -1,4 +1,5 @@
|
||||
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "input/device_manager.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include <iostream>
|
||||
@ -10,19 +11,74 @@ DeviceManager::DeviceManager()
|
||||
m_keyboard_amount = 0;
|
||||
m_gamepad_amount = 0;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
bool DeviceManager::initGamePadSupport()
|
||||
{
|
||||
// Prepare a list of connected joysticks.
|
||||
std::cout << "====================\nGamePad/Joystick detection and configuration\n====================\n";
|
||||
|
||||
irr_driver->getDevice()->activateJoysticks(m_irrlicht_gamepads);
|
||||
|
||||
const int numSticks = m_irrlicht_gamepads.size();
|
||||
std::cout << "irrLicht detects " << numSticks << " gamepads" << std::endl;
|
||||
|
||||
bool something_new_to_write = false;
|
||||
|
||||
// check if it's a new gamepad. If so, add it to the file.
|
||||
for (int i = 0; i < numSticks; i++)
|
||||
{
|
||||
std::cout << m_irrlicht_gamepads[i].Name.c_str() << " : "
|
||||
<< m_irrlicht_gamepads[i].Axes << " axes , "
|
||||
<< m_irrlicht_gamepads[i].Buttons << " buttons\n";
|
||||
|
||||
if(checkForGamePad(i)) something_new_to_write = true;
|
||||
}
|
||||
|
||||
std::cout << "====================\n";
|
||||
|
||||
return something_new_to_write;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
/**
|
||||
* Check if we already have a config object for joystick 'sdl_id' as reported by SDL
|
||||
* If yes, 'open' the gamepad. If no, create one. Returns whether a new gamepad was created.
|
||||
*/
|
||||
bool DeviceManager::checkForGamePad(const int irr_id)
|
||||
{
|
||||
std::string name = m_irrlicht_gamepads[irr_id].Name.c_str();
|
||||
|
||||
std::cout << "trying to find gamepad " << name.c_str() << std::endl;
|
||||
|
||||
for(unsigned int n=0; n<m_gamepad_amount; n++)
|
||||
{
|
||||
std::cout << " (checking...) I remember that gamepad #" << n << " is named " << m_gamepads[n].m_name.c_str() << std::endl;
|
||||
|
||||
// FIXME - don't check only name, but also number of axes and buttons?
|
||||
if(m_gamepads[n].m_name == name)
|
||||
{
|
||||
std::cout << "--> that's the one currently connected\n";
|
||||
m_gamepads[n].open(irr_id, m_gamepads[n].m_name, m_irrlicht_gamepads[irr_id].Axes );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "couldn't find this joystick, so creating a new one" << std::endl;
|
||||
add(new GamePadDevice(irr_id, m_irrlicht_gamepads[irr_id].Name.c_str(), m_irrlicht_gamepads[irr_id].Axes ));
|
||||
return true;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void DeviceManager::add(KeyboardDevice* d)
|
||||
{
|
||||
m_keyboards.push_back(d);
|
||||
m_keyboard_amount = m_keyboards.size();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void DeviceManager::add(GamePadDevice* d)
|
||||
{
|
||||
m_gamepads.push_back(d);
|
||||
m_gamepad_amount = m_gamepads.size();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
bool DeviceManager::mapInputToPlayerAndAction( Input::InputType type, int id0, int id1, int id2, int value,
|
||||
int* player /* out */, PlayerAction* action /* out */ )
|
||||
{
|
||||
@ -58,7 +114,7 @@ bool DeviceManager::mapInputToPlayerAndAction( Input::InputType type, int id0, i
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
bool DeviceManager::deserialize()
|
||||
{
|
||||
static std::string filepath = file_manager->getHomeDir() + "/input.config";
|
||||
@ -135,37 +191,7 @@ bool DeviceManager::deserialize()
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we already have a config object for joystick 'sdl_id' as reported by SDL
|
||||
* If yes, 'open' the gamepad instance and returns false. If no, create on and return true.
|
||||
*/
|
||||
bool DeviceManager::checkForGamePad(const int sdl_id)
|
||||
{
|
||||
// FIXME - replace with non-SDL code
|
||||
/*
|
||||
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 << " (checking...) gamepad " << n << " is named " << m_gamepads[n].m_name.c_str() << std::endl;
|
||||
|
||||
if(m_gamepads[n].m_name == name)
|
||||
{
|
||||
std::cout << "--> that's the one\n";
|
||||
m_gamepads[n].open(sdl_id);
|
||||
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";
|
||||
|
@ -9,6 +9,8 @@ class DeviceManager
|
||||
ptr_vector<KeyboardDevice, HOLD> m_keyboards;
|
||||
ptr_vector<GamePadDevice, HOLD> m_gamepads;
|
||||
|
||||
core::array<SJoystickInfo> m_irrlicht_gamepads;
|
||||
|
||||
unsigned int m_keyboard_amount;
|
||||
unsigned int m_gamepad_amount;
|
||||
|
||||
@ -26,6 +28,9 @@ public:
|
||||
void serialize();
|
||||
bool deserialize();
|
||||
|
||||
/* returns whether a new gamepad was detected */
|
||||
bool initGamePadSupport();
|
||||
|
||||
bool checkForGamePad(const int sdl_id);
|
||||
};
|
||||
|
||||
|
@ -192,30 +192,27 @@ GamePadDevice::GamePadDevice(irr::io::IrrXMLReader* xml)
|
||||
* (defaults will be used)
|
||||
* \param sdlIndex Index of stick.
|
||||
*/
|
||||
GamePadDevice::GamePadDevice(int sdlIndex)
|
||||
GamePadDevice::GamePadDevice(const int irrIndex, const std::string name, const int axis_count)
|
||||
{
|
||||
m_type = DT_GAMEPAD;
|
||||
m_deadzone = DEADZONE_JOYSTICK;
|
||||
|
||||
open(sdlIndex);
|
||||
|
||||
// FIXME - replace with non-SDL code
|
||||
// m_name = SDL_JoystickName(sdlIndex);
|
||||
open(irrIndex, name, axis_count);
|
||||
m_name = name;
|
||||
|
||||
loadDefaults();
|
||||
} // GamePadDevice
|
||||
// -----------------------------------------------------------------------------
|
||||
void GamePadDevice::open(const int sdl_id)
|
||||
void GamePadDevice::open(const int irrIndex, const std::string name, const int axis_count)
|
||||
{
|
||||
// FIXME - replace with non-SDL code
|
||||
// m_sdlJoystick = SDL_JoystickOpen(sdl_id);
|
||||
const int count = 1; // SDL_JoystickNumAxes(m_sdlJoystick);
|
||||
m_prevAxisDirections = new Input::AxisDirection[count];
|
||||
m_prevAxisDirections = new Input::AxisDirection[axis_count];
|
||||
|
||||
std::cout << "(i) This gamepad has " << count << " axes\n";
|
||||
std::cout << "(i) This gamepad has " << axis_count << " axes\n";
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
for (int i = 0; i < axis_count; i++)
|
||||
m_prevAxisDirections[i] = Input::AD_NEUTRAL;
|
||||
|
||||
m_index = irrIndex;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void GamePadDevice::loadDefaults()
|
||||
|
@ -68,11 +68,11 @@ public:
|
||||
The 'player' id passed is simply to know where to send 'axis reset's when necessary*/
|
||||
bool hasBinding(Input::InputType type, const int id, const int value, const int player, PlayerAction* action /* out */);
|
||||
|
||||
void open(const int sdl_id);
|
||||
void open(const int irrIndex, const std::string name, const int axis_count);
|
||||
|
||||
void loadDefaults();
|
||||
|
||||
GamePadDevice(int sdlIndex);
|
||||
GamePadDevice(const int irrIndex, const std::string name, const int axis_number);
|
||||
GamePadDevice(irr::io::IrrXMLReader* xml);
|
||||
|
||||
~GamePadDevice();
|
||||
|
@ -52,7 +52,6 @@ InputManager::InputManager()
|
||||
: m_sensed_input(0),
|
||||
m_mode(BOOTSTRAP), m_mouse_val_x(0), m_mouse_val_y(0)
|
||||
{
|
||||
|
||||
m_device_manager = new DeviceManager();
|
||||
|
||||
m_timer_in_use = false;
|
||||
@ -72,16 +71,9 @@ m_mode(BOOTSTRAP), m_mouse_val_x(0), m_mouse_val_y(0)
|
||||
something_new_to_write = true;
|
||||
}
|
||||
|
||||
// Prepare a list of connected joysticks.
|
||||
// FIXME - replace with non-SDL code
|
||||
const int numSticks = 0; //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++)
|
||||
if(m_device_manager->initGamePadSupport() /* returns whether a new gamepad was detected */)
|
||||
{
|
||||
something_new_to_write = m_device_manager->checkForGamePad(i) || something_new_to_write;
|
||||
something_new_to_write = true;
|
||||
}
|
||||
|
||||
// write config file if necessary
|
||||
@ -99,10 +91,8 @@ void InputManager::update(float dt)
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Initialises joystick/gamepad info.
|
||||
/** Previous code to initialise joystick/gamepad info.
|
||||
*/
|
||||
void InputManager::initGamePadDevices()
|
||||
{
|
||||
|
||||
/*
|
||||
m_stick_infos = new GamePadDevice *[numSticks];
|
||||
@ -184,18 +174,14 @@ void InputManager::initGamePadDevices()
|
||||
|
||||
delete si;
|
||||
*/
|
||||
} // initGamePadDevices
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Destructor. Frees all data structures.
|
||||
*/
|
||||
InputManager::~InputManager()
|
||||
{
|
||||
|
||||
delete m_device_manager;
|
||||
|
||||
// FIXME LEAK: delete m_action_map if defined
|
||||
|
||||
} // ~InputManager
|
||||
|
||||
|
||||
|
@ -74,7 +74,7 @@ private:
|
||||
public:
|
||||
InputManager();
|
||||
~InputManager();
|
||||
void initGamePadDevices();
|
||||
// void initGamePadDevices();
|
||||
|
||||
//void input();
|
||||
void input(const irr::SEvent& event);
|
||||
|
@ -59,7 +59,7 @@ MainLoop::~MainLoop()
|
||||
*/
|
||||
void MainLoop::run()
|
||||
{
|
||||
IrrlichtDevice* device = GUIEngine::getDevice();
|
||||
IrrlichtDevice* device = irr_driver->getDevice();
|
||||
|
||||
bool music_on = false;
|
||||
m_curr_time = device->getTimer()->getRealTime(); // SDL_GetTicks();
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "gui/font.hpp"
|
||||
*/
|
||||
#include "gui/race_gui.hpp"
|
||||
#include "gui/engine.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
@ -79,7 +79,7 @@ namespace SDLManager
|
||||
*/
|
||||
void showPointer()
|
||||
{
|
||||
GUIEngine::getDevice()->getCursorControl()->setVisible(true);
|
||||
irr_driver->getDevice()->getCursorControl()->setVisible(true);
|
||||
// SDL_ShowCursor(SDL_ENABLE);
|
||||
} // showPointer
|
||||
|
||||
@ -88,7 +88,7 @@ namespace SDLManager
|
||||
*/
|
||||
void hidePointer()
|
||||
{
|
||||
GUIEngine::getDevice()->getCursorControl()->setVisible(true);
|
||||
irr_driver->getDevice()->getCursorControl()->setVisible(true);
|
||||
// SDL_ShowCursor(SDL_DISABLE);
|
||||
} // hidePointer
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user