bringing gamepad input a bit more in. help me with testing please - i can somewhat fake gamepad input with some utility but it's not too handy
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3310 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
13e8e2faf9
commit
34f8e281d7
@ -60,6 +60,9 @@ IrrDriver::IrrDriver()
|
||||
fprintf(stderr, "Couldn't initialise irrlicht device. Quitting.\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
m_device->getVideoDriver()->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS,true);
|
||||
|
||||
// Stores the new file system pointer.
|
||||
file_manager->setDevice(m_device);
|
||||
m_device->setWindowCaption(L"SuperTuxKart");
|
||||
@ -88,6 +91,7 @@ scene::IAnimatedMesh *IrrDriver::getAnimatedMesh(const std::string &filename)
|
||||
} // getAnimatedMesh
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/** Loads a non-animated mesh and returns a pointer to it.
|
||||
* \param filename File to load.
|
||||
*/
|
||||
|
@ -31,7 +31,7 @@ bool DeviceManager::mapInputToPlayerAndAction( Input::InputType type, int id0, i
|
||||
{
|
||||
for(unsigned int n=0; n<m_keyboard_amount; n++)
|
||||
{
|
||||
if( m_keyboards[n].hasBinding(id0, id1, id2, action) ) return true;
|
||||
if( m_keyboards[n].hasBinding(id0, action) ) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -45,9 +45,10 @@ bool DeviceManager::mapInputToPlayerAndAction( Input::InputType type, int id0, i
|
||||
}
|
||||
else if(type == Input::IT_STICKMOTION)
|
||||
{
|
||||
// std::cout << "stick motion, ID=" <<id0 << " axis=" << id1 << " value=" << value << std::endl;
|
||||
for(unsigned int n=0; n<m_gamepad_amount; n++)
|
||||
{
|
||||
if( m_gamepads[n].m_index == id0 && m_gamepads[n].hasBinding(id1 /* axis */, value, action) ) return true;
|
||||
if( /*m_gamepads[n].m_index == id0 &&*/ m_gamepads[n].hasBinding(id1 /* axis */, value, action) ) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -5,35 +5,47 @@ InputDevice::InputDevice()
|
||||
{
|
||||
for(int n=0; n<PA_COUNT; n++)
|
||||
{
|
||||
m_bindings[n].id0 = 0;
|
||||
m_bindings[n].id1 = 0;
|
||||
m_bindings[n].id2 = 0;
|
||||
m_bindings[n].id = -1;
|
||||
m_bindings[n].type = Input::IT_NONE;
|
||||
m_bindings[n].dir = Input::AD_NEGATIVE;
|
||||
}
|
||||
|
||||
m_player = "default";
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
KeyboardDevice::KeyboardDevice()
|
||||
{
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void KeyboardDevice::loadDefaults()
|
||||
{
|
||||
m_bindings[PA_NITRO].id0 = SDLK_SPACE;
|
||||
m_bindings[PA_ACCEL].id0 = SDLK_UP;
|
||||
m_bindings[PA_BRAKE].id0 = SDLK_DOWN;
|
||||
m_bindings[PA_LEFT].id0 = SDLK_LEFT;
|
||||
m_bindings[PA_RIGHT].id0 = SDLK_RIGHT;
|
||||
m_bindings[PA_DRIFT].id0 = SDLK_LSHIFT;
|
||||
m_bindings[PA_RESCUE].id0 = SDLK_ESCAPE;
|
||||
m_bindings[PA_FIRE].id0 = SDLK_LALT;
|
||||
m_bindings[PA_LOOK_BACK].id0 = SDLK_b;
|
||||
}
|
||||
m_bindings[PA_NITRO].id = SDLK_SPACE;
|
||||
m_bindings[PA_ACCEL].id = SDLK_UP;
|
||||
m_bindings[PA_BRAKE].id = SDLK_DOWN;
|
||||
m_bindings[PA_LEFT].id = SDLK_LEFT;
|
||||
m_bindings[PA_RIGHT].id = SDLK_RIGHT;
|
||||
m_bindings[PA_DRIFT].id = SDLK_LSHIFT;
|
||||
m_bindings[PA_RESCUE].id = SDLK_ESCAPE;
|
||||
m_bindings[PA_FIRE].id = SDLK_LALT;
|
||||
m_bindings[PA_LOOK_BACK].id = SDLK_b;
|
||||
|
||||
m_bindings[PA_NITRO].type = Input::IT_KEYBOARD;
|
||||
m_bindings[PA_ACCEL].type = Input::IT_KEYBOARD;
|
||||
m_bindings[PA_BRAKE].type = Input::IT_KEYBOARD;
|
||||
m_bindings[PA_LEFT].type = Input::IT_KEYBOARD;
|
||||
m_bindings[PA_RIGHT].type = Input::IT_KEYBOARD;
|
||||
m_bindings[PA_DRIFT].type = Input::IT_KEYBOARD;
|
||||
m_bindings[PA_RESCUE].type = Input::IT_KEYBOARD;
|
||||
m_bindings[PA_FIRE].type = Input::IT_KEYBOARD;
|
||||
m_bindings[PA_LOOK_BACK].type = Input::IT_KEYBOARD;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
/** checks if this key belongs to this belongs. if yes, sets action and returns true; otherwise returns false */
|
||||
bool KeyboardDevice::hasBinding(int id0, int id1, int id2, PlayerAction* action /* out */)
|
||||
bool KeyboardDevice::hasBinding(const int key_id, PlayerAction* action /* out */) const
|
||||
{
|
||||
for(int n=0; n<PA_COUNT; n++)
|
||||
{
|
||||
if(m_bindings[n].id0 == id0)
|
||||
if(m_bindings[n].id == key_id)
|
||||
{
|
||||
*action = (PlayerAction)n;
|
||||
return true;
|
||||
@ -50,8 +62,6 @@ bool KeyboardDevice::hasBinding(int id0, int id1, int id2, PlayerAction* action
|
||||
GamePadDevice::GamePadDevice(int sdlIndex)
|
||||
{
|
||||
m_type = DT_GAMEPAD;
|
||||
|
||||
|
||||
m_sdlJoystick = SDL_JoystickOpen(sdlIndex);
|
||||
|
||||
m_id = SDL_JoystickName(sdlIndex);
|
||||
@ -64,14 +74,80 @@ GamePadDevice::GamePadDevice(int sdlIndex)
|
||||
|
||||
m_deadzone = DEADZONE_JOYSTICK;
|
||||
|
||||
m_index = -1;
|
||||
//m_index = -1;
|
||||
|
||||
loadDefaults();
|
||||
} // GamePadDevice
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
bool GamePadDevice::hasBinding(int axis, int value, PlayerAction* action /* out */)
|
||||
void GamePadDevice::loadDefaults()
|
||||
{
|
||||
/*
|
||||
TODO
|
||||
m_bindings[PA_NITRO]
|
||||
m_bindings[PA_DRIFT]
|
||||
m_bindings[PA_RESCUE]
|
||||
m_bindings[PA_FIRE]
|
||||
m_bindings[PA_LOOK_BACK]
|
||||
*/
|
||||
|
||||
m_bindings[PA_ACCEL].type = Input::IT_STICKMOTION;
|
||||
m_bindings[PA_ACCEL].id = 1;
|
||||
m_bindings[PA_ACCEL].dir = Input::AD_NEGATIVE;
|
||||
|
||||
m_bindings[PA_BRAKE].type = Input::IT_STICKMOTION;
|
||||
m_bindings[PA_BRAKE].id = 1;
|
||||
m_bindings[PA_BRAKE].dir = Input::AD_POSITIVE;
|
||||
|
||||
m_bindings[PA_LEFT].type = Input::IT_STICKMOTION;
|
||||
m_bindings[PA_LEFT].id = 0;
|
||||
m_bindings[PA_LEFT].dir = Input::AD_NEGATIVE;
|
||||
|
||||
m_bindings[PA_RIGHT].type = Input::IT_STICKMOTION;
|
||||
m_bindings[PA_RIGHT].id = 0;
|
||||
m_bindings[PA_RIGHT].dir = Input::AD_POSITIVE;
|
||||
|
||||
|
||||
/*
|
||||
set(GA_CURSOR_UP,
|
||||
Input(Input::IT_STICKMOTION, 0, 1, Input::AD_NEGATIVE));
|
||||
set(GA_CURSOR_DOWN,
|
||||
Input(Input::IT_STICKMOTION, 0, 1, Input::AD_POSITIVE));
|
||||
set(GA_CURSOR_LEFT,
|
||||
Input(Input::IT_STICKMOTION, 0, 0, Input::AD_NEGATIVE));
|
||||
set(GA_CURSOR_RIGHT,
|
||||
Input(Input::IT_STICKMOTION, 0, 0, Input::AD_POSITIVE));
|
||||
set(GA_CLEAR_MAPPING,
|
||||
Input(Input::IT_STICKBUTTON, 0, 2));
|
||||
set(GA_ENTER,
|
||||
Input(Input::IT_STICKBUTTON, 0, 0),
|
||||
set(GA_LEAVE,
|
||||
Input(Input::IT_STICKBUTTON, 0, 1),
|
||||
|
||||
Input::IT_KEYBOARD
|
||||
*/
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
bool GamePadDevice::hasBinding(const int axis, const int value, PlayerAction* action /* out */) const
|
||||
{
|
||||
if(value > -m_deadzone && value < m_deadzone) return false; // within deadzone
|
||||
|
||||
for(int n=0; n<PA_COUNT; n++)
|
||||
{
|
||||
if(m_bindings[n].id == axis)
|
||||
{
|
||||
if(m_bindings[n].dir == Input::AD_NEGATIVE && value < 0)
|
||||
{
|
||||
*action = (PlayerAction)n;
|
||||
return true;
|
||||
}
|
||||
else if(m_bindings[n].dir == Input::AD_POSITIVE && value > 0)
|
||||
{
|
||||
*action = (PlayerAction)n;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}// next device
|
||||
|
||||
return false;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -13,7 +13,12 @@ enum DeviceType
|
||||
|
||||
struct KeyBinding
|
||||
{
|
||||
int id0, id1, id2;
|
||||
Input::InputType type;
|
||||
|
||||
// key for keyboards, axis for gamepads
|
||||
int id;
|
||||
|
||||
Input::AxisDirection dir; // for gamepads
|
||||
};
|
||||
|
||||
class InputDevice
|
||||
@ -23,6 +28,8 @@ protected:
|
||||
|
||||
KeyBinding m_bindings[PA_COUNT];
|
||||
|
||||
std::string m_player;
|
||||
|
||||
public:
|
||||
InputDevice();
|
||||
|
||||
@ -35,7 +42,7 @@ public:
|
||||
KeyboardDevice();
|
||||
|
||||
/** checks if this key belongs to this belongs. if yes, sets action and returns true; otherwise returns false */
|
||||
bool hasBinding(int id0, int id1, int id2, PlayerAction* action /* out */);
|
||||
bool hasBinding(const int key_id, PlayerAction* action /* out */) const;
|
||||
|
||||
void loadDefaults();
|
||||
};
|
||||
@ -50,7 +57,9 @@ public:
|
||||
Input::AxisDirection *m_prevAxisDirections;
|
||||
|
||||
/** checks if this key belongs to this belongs. if yes, sets action and returns true; otherwise returns false */
|
||||
bool hasBinding(int axis, int value, PlayerAction* action /* out */);
|
||||
bool hasBinding(const int axis, const int value, PlayerAction* action /* out */) const;
|
||||
|
||||
void loadDefaults();
|
||||
|
||||
GamePadDevice(int sdlIndex);
|
||||
~GamePadDevice();
|
||||
|
@ -76,6 +76,8 @@ void InputManager::initGamePadDevices()
|
||||
// Prepare a list of connected joysticks.
|
||||
const int numSticks = SDL_NumJoysticks();
|
||||
|
||||
std::cout << "SDL detects " << numSticks << " gamepads" << std::endl;
|
||||
|
||||
for (int i = 0; i < numSticks; i++)
|
||||
m_device_manager->add(new GamePadDevice(i));
|
||||
|
||||
@ -496,20 +498,20 @@ void InputManager::input()
|
||||
case SDL_JOYAXISMOTION:
|
||||
if(user_config->m_gamepad_debug)
|
||||
{
|
||||
printf("axis motion: which %d axis %d value %d\n",
|
||||
printf("axis motion: which=%d axis=%d value=%d\n",
|
||||
ev.jaxis.which, ev.jaxis.axis, ev.jaxis.value);
|
||||
}
|
||||
|
||||
if(ev.jaxis.value < 0)
|
||||
{
|
||||
/* TODO - bring back those weird axis tricks. would be cool if
|
||||
/* // TODO - bring back those weird axis tricks. would be cool if
|
||||
// they could happen inside the GamePadDevice class, for encapsulation
|
||||
if (m_stick_infos[ev.jaxis.which]->m_prevAxisDirections[ev.jaxis.axis] == Input::AD_POSITIVE)
|
||||
{
|
||||
input(Input::IT_STICKMOTION, !m_mode ? 0 : stickIndex, ev.jaxis.axis, Input::AD_POSITIVE, 0);
|
||||
}
|
||||
*/
|
||||
input(Input::IT_STICKMOTION, !m_mode ? 0 : stickIndex, ev.jaxis.axis, Input::AD_NEGATIVE, -ev.jaxis.value);
|
||||
input(Input::IT_STICKMOTION, ev.jaxis.which, ev.jaxis.axis, Input::AD_NEGATIVE, -ev.jaxis.value);
|
||||
//m_stick_infos[ev.jaxis.which]->m_prevAxisDirections[ev.jaxis.axis] = Input::AD_NEGATIVE;
|
||||
}
|
||||
else
|
||||
@ -521,7 +523,8 @@ void InputManager::input()
|
||||
input(Input::IT_STICKMOTION, !m_mode ? 0 : stickIndex, ev.jaxis.axis, Input::AD_NEGATIVE, 0);
|
||||
}
|
||||
*/
|
||||
input(Input::IT_STICKMOTION, !m_mode ? 0 : stickIndex, ev.jaxis.axis, Input::AD_POSITIVE, ev.jaxis.value);
|
||||
// TODO - set stickIndex
|
||||
input(Input::IT_STICKMOTION, ev.jaxis.which, ev.jaxis.axis, Input::AD_POSITIVE, ev.jaxis.value);
|
||||
//m_stick_infos[ev.jaxis.which]->m_prevAxisDirections[ev.jaxis.axis] = Input::AD_POSITIVE;
|
||||
}
|
||||
|
||||
|
@ -936,7 +936,7 @@ void Track::loadTrack(const std::string &filename)
|
||||
if(m_sky_textures.size()!=6)
|
||||
{
|
||||
fprintf(stderr, "A skybox needs 6 textures, but %d are specified\n",
|
||||
m_sky_textures.size());
|
||||
(int)m_sky_textures.size());
|
||||
fprintf(stderr, "in '%s'.\n", filename.c_str());
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user