Some code cleanup: made input data structure to follow the m_

notation, removed unnecessary include.
Added new field to input that stores the character (i.e. the
visual character) of a key (but it's not used yet).


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6504 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2010-11-11 20:59:49 +00:00
parent aeef2730f4
commit fc202a57f5
11 changed files with 56 additions and 38 deletions

View File

@ -45,7 +45,8 @@ const int CURRENT_CONFIG_VERSION = 8;
#include <vector>
#include <fstream>
#include "input/input.hpp"
#include "irrlicht.h"
#include "utils/constants.hpp"
#include "utils/no_copy.hpp"
#include "utils/ptr_vector.hpp"

View File

@ -43,7 +43,16 @@ irr::core::stringw Input::getInputAsString(const Input::InputType type, const in
s = "?";
switch(id)
{
{
#ifdef WIN32
case 186: s=";"; break;
case 191: s="/"; break;
case 192: s="`"; break;
case 219: s="["; break;
case 220: s="\\"; break;
case 221: s="]"; break;
case 222: s="'"; break;
#endif
case KEY_LBUTTON :
s = "left mouse button";
break;

View File

@ -56,13 +56,15 @@ struct Input
};
static const int IT_LAST = IT_MOUSEBUTTON;
InputType type;
int deviceID;
int btnID; // or axis ID for gamepads axes
int axisDirection;
InputType m_type;
int m_device_id;
int m_button_id; // or axis ID for gamepads axes
int m_axis_direction;
wchar_t m_character;
Input()
: type(IT_NONE), deviceID(0), btnID(0), axisDirection(0)
: m_type(IT_NONE), m_device_id(0), m_button_id(0),
m_axis_direction(0), m_character(0)
{
// Nothing to do.
}
@ -91,7 +93,8 @@ struct Input
* to the system.
*/
Input(InputType ntype, int deviceID , int btnID = 0, int axisDirection= 0)
: type(ntype), deviceID(deviceID), btnID(btnID), axisDirection(axisDirection)
: m_type(ntype), m_device_id(deviceID), m_button_id(btnID),
m_axis_direction(axisDirection)
{
// Nothing to do.
}

View File

@ -228,10 +228,10 @@ void InputManager::inputSensing(Input::InputType type, int deviceID, int btnID,
if (store_new)
{
m_sensed_input->type = type;
m_sensed_input->deviceID = deviceID;
m_sensed_input->btnID = btnID;
m_sensed_input->axisDirection = axisDirection;
m_sensed_input->m_type = type;
m_sensed_input->m_device_id = deviceID;
m_sensed_input->m_button_id= btnID;
m_sensed_input->m_axis_direction = axisDirection;
if (type == Input::IT_KEYBOARD && value > Input::MAX_VALUE/2)
{
@ -240,7 +240,8 @@ void InputManager::inputSensing(Input::InputType type, int deviceID, int btnID,
else if (type == Input::IT_KEYBOARD && value == 0)
{
// only notify on key release
if (m_sensed_input_high_kbd.find(m_sensed_input->btnID) != m_sensed_input_high_kbd.end())
if (m_sensed_input_high_kbd.find(m_sensed_input->m_button_id)
!= m_sensed_input_high_kbd.end())
{
OptionsScreenInput2::getInstance()->gotSensedInput(m_sensed_input);
return;
@ -282,7 +283,7 @@ void InputManager::inputSensing(Input::InputType type, int deviceID, int btnID,
}
else if ( abs(value) < Input::MAX_VALUE/8.0f && inverse_id_has_high_value )
{
m_sensed_input->axisDirection = (axisDirection?0:-1);
m_sensed_input->m_axis_direction= (axisDirection?0:-1);
OptionsScreenInput2::getInstance()->gotSensedInput(m_sensed_input);
}
}

View File

@ -28,6 +28,7 @@ using namespace irr;
class Kart;
class Item;
enum PlayerAction;
/** This is the base class for kart controller - that can be a player
* or a a robot.
@ -63,7 +64,7 @@ public:
virtual bool isPlayerController () const {return false;}
virtual bool isNetworkController() const {return false;}
/** Default: ignore actions. Only PlayerController get them. */
virtual void action (PlayerAction action, int value) {}
virtual void action (const PlayerAction &action, int value) {}
virtual const irr::core::stringw& getNamePostfix() const;
}; // Controller

View File

@ -138,7 +138,7 @@ void EndController::reset()
//-----------------------------------------------------------------------------
/** The end controller must forward 'fire' presses to the race gui.
*/
void EndController::action(PlayerAction action, int value)
void EndController::action(const PlayerAction &action, int value)
{
if(action!=PA_FIRE) return;
RaceResultGUI *race_result_gui = dynamic_cast<RaceResultGUI*>(World::getWorld()->getRaceGUI());

View File

@ -83,7 +83,7 @@ public:
* controller. This way e.g. highscores can still be assigned
* to the right player. */
virtual bool isPlayerController () const {return m_player!=NULL;}
virtual void action (PlayerAction action, int value);
virtual void action (const PlayerAction &action, int value);
}; // EndKart

View File

@ -113,7 +113,7 @@ void PlayerController::resetInputState()
* and if it's 0 it indicates that the corresponding button
* was released.
*/
void PlayerController::action(PlayerAction action, int value)
void PlayerController::action(const PlayerAction &action, int value)
{
switch (action)
{

View File

@ -51,7 +51,7 @@ public:
unsigned int player_index);
~PlayerController ();
void update (float);
void action (PlayerAction action, int value);
void action (const PlayerAction &action, int value);
void handleZipper ();
void collectedItem (const Item &item, int add_info=-1,
float previous_energy=0);

View File

@ -266,9 +266,9 @@ static std::string binding_to_set_button;
void OptionsScreenInput2::gotSensedInput(Input* sensedInput)
{
const bool keyboard = (m_config->getType() == DEVICE_CONFIG_TYPE_KEYBOARD &&
sensedInput->type == Input::IT_KEYBOARD);
const bool gamepad = (sensedInput->type == Input::IT_STICKMOTION ||
sensedInput->type == Input::IT_STICKBUTTON) &&
sensedInput->m_type == Input::IT_KEYBOARD);
const bool gamepad = (sensedInput->m_type == Input::IT_STICKMOTION ||
sensedInput->m_type == Input::IT_STICKBUTTON) &&
m_config->getType() == DEVICE_CONFIG_TYPE_GAMEPAD;
if (keyboard)
@ -276,11 +276,13 @@ void OptionsScreenInput2::gotSensedInput(Input* sensedInput)
if (UserConfigParams::m_verbosity>=5)
{
std::cout << "% Binding " << KartActionStrings[binding_to_set]
<< " : setting to keyboard key " << sensedInput->btnID << " \n\n";
<< " : setting to keyboard key " << sensedInput->m_button_id
<< " \n\n";
}
KeyboardConfig* keyboard = (KeyboardConfig*)m_config;
keyboard->setBinding(binding_to_set, Input::IT_KEYBOARD, sensedInput->btnID, Input::AD_NEUTRAL);
keyboard->setBinding(binding_to_set, Input::IT_KEYBOARD,
sensedInput->m_button_id, Input::AD_NEUTRAL);
// refresh display
updateInputButtons();
@ -290,16 +292,19 @@ void OptionsScreenInput2::gotSensedInput(Input* sensedInput)
if (UserConfigParams::m_verbosity>=5)
{
std::cout << "% Binding " << KartActionStrings[binding_to_set]
<< " : setting to gamepad #" << sensedInput->deviceID << " : ";
<< " : setting to gamepad #"
<< sensedInput->m_device_id<< " : ";
if (sensedInput->type == Input::IT_STICKMOTION)
if (sensedInput->m_type == Input::IT_STICKMOTION)
{
std::cout << "axis " << sensedInput->btnID << " direction "
<< (sensedInput->axisDirection == Input::AD_NEGATIVE ? "-" : "+") << "\n\n";
std::cout << "axis " << sensedInput->m_button_id<< " direction "
<< (sensedInput->m_axis_direction== Input::AD_NEGATIVE
? "-" : "+")
<< "\n\n";
}
else if (sensedInput->type == Input::IT_STICKBUTTON)
else if (sensedInput->m_type == Input::IT_STICKBUTTON)
{
std::cout << "button " << sensedInput->btnID << "\n\n";
std::cout << "button " << sensedInput->m_button_id<< "\n\n";
}
else
{
@ -308,8 +313,9 @@ void OptionsScreenInput2::gotSensedInput(Input* sensedInput)
}
GamepadConfig* config = (GamepadConfig*)m_config;
config->setBinding(binding_to_set, sensedInput->type, sensedInput->btnID,
(Input::AxisDirection)sensedInput->axisDirection);
config->setBinding(binding_to_set, sensedInput->m_type,
sensedInput->m_button_id,
(Input::AxisDirection)sensedInput->m_axis_direction);
// refresh display
updateInputButtons();

View File

@ -43,12 +43,9 @@
# define M_PI 3.14159265358979323846f /* As in Linux's math.h */
#endif
/* And we want float for everyone, not double */
const float M_PIf = 4.0f*atanf(1.0f);
#define NINETY_DEGREE_RAD (M_PIf/2.0f)
#define DEGREE_TO_RAD (M_PIf/180.0f)
#define RAD_TO_DEGREE (180.0f/M_PIf)
#define NINETY_DEGREE_RAD (M_PI/2.0f)
#define DEGREE_TO_RAD (M_PI/180.0f)
#define RAD_TO_DEGREE (180.0f/M_PI)
const int MAX_PLAYER_COUNT = 4;