Tearing input apart : the current input module plain won't cut it for our needs. It works per-player, we now want it per-device. It also did messy stuff like like using a hardcoded variable for each player instead of passing playing ID as parameter, etc. So I'm tearing it apart. Consequence for now : only keyboard and mouse work, and it's not configurable, and it's not loaded from config files. More to come, obviously...
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3291 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -23,19 +23,19 @@
|
||||
#include "actionmap.hpp"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ActionMap::putEntry(Input input, GameAction ga)
|
||||
void ActionMap::addStaticEntry(Input input, StaticAction ga)
|
||||
{
|
||||
inputMap[key(input)] = ga;
|
||||
} // putEntry
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GameAction ActionMap::getEntry(Input input)
|
||||
StaticAction ActionMap::getStaticEntry(Input input)
|
||||
{
|
||||
return inputMap[key(input)];
|
||||
} // getEntry
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GameAction ActionMap::getEntry(Input::InputType type, int id0, int id1, int id2)
|
||||
StaticAction ActionMap::getStaticEntry(Input::InputType type, int id0, int id1, int id2)
|
||||
{
|
||||
return inputMap[key(type, id0, id1, id2)];
|
||||
} // getEntry
|
||||
|
||||
@@ -34,16 +34,17 @@ class ActionMap
|
||||
|
||||
void clear();
|
||||
|
||||
void putEntry(Input, GameAction);
|
||||
|
||||
GameAction getEntry(Input);
|
||||
GameAction getEntry(Input::InputType, int, int, int);
|
||||
void addStaticEntry(Input, StaticAction);
|
||||
void addPlayerEntry(Input, PlayerAction);
|
||||
|
||||
StaticAction getStaticEntry(Input);
|
||||
StaticAction getStaticEntry(Input::InputType, int, int, int);
|
||||
|
||||
private:
|
||||
inline Key key(Input);
|
||||
Key key(Input::InputType, int, int, int);
|
||||
|
||||
std::map<Key, GameAction> inputMap;
|
||||
std::map<Key, StaticAction> inputMap;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ public:
|
||||
~RaceGUI();
|
||||
void update(float dt);
|
||||
void select() {}
|
||||
void handleKartAction(KartAction ka, int value);
|
||||
void handleKartAction(PlayerAction ka, int value);
|
||||
void addMessage(const std::string &m, const Kart *kart, float time,
|
||||
int fonst_size, int red=255, int green=0, int blue=255);
|
||||
|
||||
|
||||
@@ -88,21 +88,24 @@ struct Input
|
||||
//FIXME: KartAction and Gameaction should probably go in their own files.
|
||||
//When adding any action at the beginning or at the end, remember to update
|
||||
//the KA_FIRST and/or KA_LAST constants.
|
||||
enum KartAction {
|
||||
KA_LEFT,
|
||||
KA_RIGHT,
|
||||
KA_ACCEL,
|
||||
KA_BRAKE,
|
||||
KA_NITRO,
|
||||
KA_DRIFT,
|
||||
KA_RESCUE,
|
||||
KA_FIRE,
|
||||
KA_LOOK_BACK
|
||||
enum PlayerAction
|
||||
{
|
||||
PA_FIRST = -1,
|
||||
|
||||
PA_LEFT = 0,
|
||||
PA_RIGHT,
|
||||
PA_ACCEL,
|
||||
PA_BRAKE,
|
||||
PA_NITRO,
|
||||
PA_DRIFT,
|
||||
PA_RESCUE,
|
||||
PA_FIRE,
|
||||
PA_LOOK_BACK,
|
||||
|
||||
PA_COUNT
|
||||
};
|
||||
const int KA_FIRST = KA_LEFT;
|
||||
const int KA_LAST = KA_LOOK_BACK;
|
||||
const int KC_COUNT = (KA_LAST + 1);
|
||||
static std::string KartActionStrings[KC_COUNT] = {std::string("left"),
|
||||
|
||||
static std::string KartActionStrings[PA_COUNT] = {std::string("left"),
|
||||
std::string("right"),
|
||||
std::string("accel"),
|
||||
std::string("brake"),
|
||||
@@ -112,7 +115,7 @@ static std::string KartActionStrings[KC_COUNT] = {std::string("left"),
|
||||
std::string("fire"),
|
||||
std::string("lookBack")};
|
||||
|
||||
enum GameAction
|
||||
enum StaticAction
|
||||
{
|
||||
// Below this are synthetic game actions which are never triggered through
|
||||
// an input device.
|
||||
@@ -138,47 +141,6 @@ enum GameAction
|
||||
GA_CURSOR_LEFT,
|
||||
GA_CURSOR_RIGHT,
|
||||
|
||||
// The following game actions occur when in ingame mode (= within a race).
|
||||
|
||||
GA_P1_LEFT,
|
||||
GA_P1_RIGHT,
|
||||
GA_P1_ACCEL,
|
||||
GA_P1_BRAKE,
|
||||
GA_P1_NITRO,
|
||||
GA_P1_DRIFT,
|
||||
GA_P1_RESCUE,
|
||||
GA_P1_FIRE,
|
||||
GA_P1_LOOK_BACK,
|
||||
|
||||
GA_P2_LEFT,
|
||||
GA_P2_RIGHT,
|
||||
GA_P2_ACCEL,
|
||||
GA_P2_BRAKE,
|
||||
GA_P2_NITRO,
|
||||
GA_P2_DRIFT,
|
||||
GA_P2_RESCUE,
|
||||
GA_P2_FIRE,
|
||||
GA_P2_LOOK_BACK,
|
||||
|
||||
GA_P3_LEFT,
|
||||
GA_P3_RIGHT,
|
||||
GA_P3_ACCEL,
|
||||
GA_P3_BRAKE,
|
||||
GA_P3_NITRO,
|
||||
GA_P3_DRIFT,
|
||||
GA_P3_RESCUE,
|
||||
GA_P3_FIRE,
|
||||
GA_P3_LOOK_BACK,
|
||||
|
||||
GA_P4_LEFT,
|
||||
GA_P4_RIGHT,
|
||||
GA_P4_ACCEL,
|
||||
GA_P4_BRAKE,
|
||||
GA_P4_NITRO,
|
||||
GA_P4_DRIFT,
|
||||
GA_P4_RESCUE,
|
||||
GA_P4_FIRE,
|
||||
GA_P4_LOOK_BACK,
|
||||
|
||||
GA_TOGGLE_FULLSCREEN, // Switch between windowed/fullscreen mode
|
||||
GA_LEAVE_RACE, // Switch from race to menu.
|
||||
@@ -191,6 +153,8 @@ enum GameAction
|
||||
GA_DEBUG_HISTORY
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* Some constants to make future changes more easier to handle. If you use
|
||||
* any of the GameAction constants to mark the beginning or end of a range
|
||||
* or denote a count then something is wrong with your code. ;)
|
||||
@@ -208,9 +172,6 @@ const int GA_COUNT = (GA_DEBUG_HISTORY + 1);
|
||||
const int GA_FIRST_MENU = GA_ENTER;
|
||||
const int GA_LAST_MENU = GA_CURSOR_RIGHT;
|
||||
|
||||
/* The range of GameAction constants that is used while in ingame (race) mode. */
|
||||
const int GA_FIRST_INGAME = GA_P1_LEFT;
|
||||
const int GA_LAST_INGAME = GA_DEBUG_HISTORY;
|
||||
|
||||
/* The range of GameAction constants which are used ingame but are considered
|
||||
* fixed and their Inputs should not be used by the players.
|
||||
@@ -218,13 +179,5 @@ const int GA_LAST_INGAME = GA_DEBUG_HISTORY;
|
||||
const int GA_FIRST_INGAME_FIXED = GA_TOGGLE_FULLSCREEN;
|
||||
const int GA_LAST_INGAME_FIXED = GA_DEBUG_HISTORY;
|
||||
|
||||
/** The range of GameAction constants that defines the mapping
|
||||
for the players kart actions. Besides that these are the actions
|
||||
whose mappings are changeable by the user (via menu & config file).
|
||||
When looking for conflicting mappings only the user changeable
|
||||
GameAction constants are regarded.
|
||||
*/
|
||||
const int GA_FIRST_KARTACTION = GA_P1_LEFT;
|
||||
const int GA_LAST_KARTACTION = GA_P4_LOOK_BACK;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -55,7 +55,7 @@ InputManager *input_manager;
|
||||
/** Initialise SDL.
|
||||
*/
|
||||
InputManager::InputManager()
|
||||
: m_sensed_input(0), m_action_map(0), m_stick_infos(0),
|
||||
: m_sensed_input(0), m_stick_infos(0),
|
||||
m_mode(BOOTSTRAP), m_mouse_val_x(0), m_mouse_val_y(0)
|
||||
{
|
||||
initStickInfos();
|
||||
@@ -169,7 +169,7 @@ InputManager::~InputManager()
|
||||
|
||||
#define MAX_VALUE 32768
|
||||
|
||||
void postIrrLichtMouseEvent(irr::EMOUSE_INPUT_EVENT type, const int x, const int y)
|
||||
void InputManager::postIrrLichtMouseEvent(irr::EMOUSE_INPUT_EVENT type, const int x, const int y)
|
||||
{
|
||||
irr::SEvent::SMouseInput evt;
|
||||
|
||||
@@ -185,7 +185,77 @@ void postIrrLichtMouseEvent(irr::EMOUSE_INPUT_EVENT type, const int x, const int
|
||||
}
|
||||
|
||||
|
||||
void handleGameAction(GameAction ga, int value)
|
||||
void InputManager::handleStaticAction(StaticAction ga, int value)
|
||||
{
|
||||
if (value)
|
||||
return;
|
||||
|
||||
static int isWireframe = false;
|
||||
|
||||
switch (ga)
|
||||
{
|
||||
case GA_DEBUG_ADD_BOWLING:
|
||||
if (race_manager->getNumPlayers() ==1 )
|
||||
{
|
||||
Kart* kart = RaceManager::getWorld()->getLocalPlayerKart(0);
|
||||
// kart->setPowerup(POWERUP_BUBBLEGUM, 10000);
|
||||
kart->attach(ATTACH_ANVIL, 5);
|
||||
}
|
||||
break;
|
||||
case GA_DEBUG_ADD_MISSILE:
|
||||
if (race_manager->getNumPlayers() ==1 )
|
||||
{
|
||||
Kart* kart = RaceManager::getPlayerKart(0);
|
||||
kart->setPowerup(POWERUP_PLUNGER, 10000);
|
||||
}
|
||||
break;
|
||||
case GA_DEBUG_ADD_HOMING:
|
||||
if (race_manager->getNumPlayers() ==1 )
|
||||
{
|
||||
Kart* kart = RaceManager::getPlayerKart(0);
|
||||
kart->setPowerup(POWERUP_CAKE, 10000);
|
||||
}
|
||||
break;
|
||||
case GA_DEBUG_TOGGLE_FPS:
|
||||
user_config->m_display_fps = !user_config->m_display_fps;
|
||||
if(user_config->m_display_fps)
|
||||
{
|
||||
getRaceGUI()->resetFPSCounter();
|
||||
}
|
||||
break;
|
||||
case GA_DEBUG_TOGGLE_WIREFRAME:
|
||||
glPolygonMode(GL_FRONT_AND_BACK, isWireframe ? GL_FILL : GL_LINE);
|
||||
isWireframe = ! isWireframe;
|
||||
break;
|
||||
#ifndef WIN32
|
||||
// For now disable F9 toggling fullscreen, since windows requires
|
||||
// to reload all textures, display lists etc. Fullscreen can
|
||||
// be toggled from the main menu (options->display).
|
||||
case GA_TOGGLE_FULLSCREEN:
|
||||
SDLManager::toggleFullscreen(false); // 0: do not reset textures
|
||||
// Fall through to put the game into pause mode.
|
||||
#endif
|
||||
case GA_LEAVE_RACE:
|
||||
// TODO - show race menu
|
||||
/*
|
||||
RaceManager::getWorld()->pause();
|
||||
menu_manager->pushMenu(MENUID_RACEMENU);
|
||||
*/
|
||||
break;
|
||||
case GA_DEBUG_HISTORY:
|
||||
history->Save();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
} // switch
|
||||
}
|
||||
|
||||
void InputManager::handlePlayerAction(PlayerAction pa, const int playerNo, int value)
|
||||
{
|
||||
RaceManager::getWorld()->getLocalPlayerKart(playerNo)->action(pa, value);
|
||||
}
|
||||
/*
|
||||
void InputManager::handleGameAction(GameAction ga, int value)
|
||||
{
|
||||
static int isWireframe = false;
|
||||
|
||||
@@ -259,10 +329,10 @@ void handleGameAction(GameAction ga, int value)
|
||||
#endif
|
||||
case GA_LEAVE_RACE:
|
||||
// TODO - show race menu
|
||||
/*
|
||||
RaceManager::getWorld()->pause();
|
||||
menu_manager->pushMenu(MENUID_RACEMENU);
|
||||
*/
|
||||
|
||||
// RaceManager::getWorld()->pause();
|
||||
// menu_manager->pushMenu(MENUID_RACEMENU);
|
||||
|
||||
break;
|
||||
case GA_DEBUG_HISTORY:
|
||||
history->Save();
|
||||
@@ -272,8 +342,49 @@ void handleGameAction(GameAction ga, int value)
|
||||
} // switch
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// TODO
|
||||
bool mapToPlayerAndAction( Input::InputType type, int id0, int id1, int id2, int* player, PlayerAction* action )
|
||||
{
|
||||
// TODO - auto-detect from device
|
||||
*player = 0;
|
||||
|
||||
if(type == Input::IT_KEYBOARD)
|
||||
{
|
||||
// TODO - make configurable. detect device. choose right configuration for device and player
|
||||
if( id0 == SDLK_SPACE ) *action = PA_NITRO;
|
||||
else if( id0 == SDLK_UP ) *action = PA_ACCEL;
|
||||
else if( id0 == SDLK_DOWN ) *action = PA_BRAKE;
|
||||
else if( id0 == SDLK_LEFT ) *action = PA_LEFT;
|
||||
else if( id0 == SDLK_RIGHT ) *action = PA_RIGHT;
|
||||
else if( id0 == SDLK_LSHIFT ) *action = PA_DRIFT;
|
||||
else if( id0 == SDLK_ESCAPE ) *action = PA_RESCUE;
|
||||
else if( id0 == SDLK_LALT ) *action = PA_FIRE;
|
||||
else if( id0 == SDLK_b ) *action = PA_LOOK_BACK;
|
||||
else return false;
|
||||
}
|
||||
else if(type == Input::IT_MOUSEBUTTON)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if(type == Input::IT_STICKBUTTON)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if(type == Input::IT_STICKMOTION)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Handles the conversion from some input to a GameAction and its distribution
|
||||
* to the currently active menu.
|
||||
@@ -291,6 +402,7 @@ void InputManager::input(Input::InputType type, int id0, int id1, int id2,
|
||||
int value)
|
||||
{
|
||||
|
||||
// menu navigation. TODO : enable navigation with gamepads
|
||||
if(!StateManager::isGameState())
|
||||
{
|
||||
//http://irrlicht.sourceforge.net/docu/classirr_1_1_irrlicht_device.html#bf859e39f017b0403c6ed331e48e01df
|
||||
@@ -324,9 +436,16 @@ void InputManager::input(Input::InputType type, int id0, int id1, int id2,
|
||||
}
|
||||
|
||||
}
|
||||
// in-game event handling
|
||||
else
|
||||
{
|
||||
GameAction ga = m_action_map->getEntry(type, id0, id1, id2);
|
||||
int player;
|
||||
PlayerAction action;
|
||||
|
||||
const bool action_found = mapToPlayerAndAction( type, id0, id1, id2, &player, &action );
|
||||
|
||||
//GameAction ga = m_action_map->getEntry(type, id0, id1, id2);
|
||||
#if 0 // TODO - input sensing
|
||||
// Act different in input sensing mode.
|
||||
if (m_mode >= INPUT_SENSE_PREFER_AXIS &&
|
||||
m_mode <= INPUT_SENSE_PREFER_BUTTON)
|
||||
@@ -369,20 +488,11 @@ void InputManager::input(Input::InputType type, int id0, int id1, int id2,
|
||||
handleGameAction(GA_SENSE_COMPLETE, 0);
|
||||
}
|
||||
} // if m_mode==INPUT_SENSE_PREFER_{AXIS,BUTTON}
|
||||
else if (ga != GA_NULL)
|
||||
else
|
||||
#endif
|
||||
if (action_found)
|
||||
{
|
||||
if(type==Input::IT_MOUSEBUTTON)
|
||||
{
|
||||
// If a mouse button is pressed, make sure that the
|
||||
// widget the mouse is on is actually highlighted (since
|
||||
// the highlighted widget is selected!)
|
||||
int x, y;
|
||||
SDL_GetMouseState( &x, &y );
|
||||
y = SDL_GetVideoSurface()->h - y;
|
||||
//menu->inputPointer( x, y );
|
||||
}
|
||||
|
||||
handleGameAction(ga, value);
|
||||
handlePlayerAction(action, player, value);
|
||||
}
|
||||
}
|
||||
} // input
|
||||
@@ -656,8 +766,8 @@ void InputManager::setMode(InputDriverMode new_mode)
|
||||
case INGAME:
|
||||
// Leaving ingame mode.
|
||||
|
||||
if (m_action_map)
|
||||
delete m_action_map;
|
||||
//if (m_action_map)
|
||||
// delete m_action_map;
|
||||
|
||||
// Reset the helper values for the relative mouse movement
|
||||
// supresses to the notification of them as an input.
|
||||
@@ -670,7 +780,7 @@ void InputManager::setMode(InputDriverMode new_mode)
|
||||
// Leaving boot strap mode.
|
||||
|
||||
// Installs the action map for the menu.
|
||||
m_action_map = user_config->newMenuActionMap();
|
||||
// m_action_map = user_config->newMenuActionMap();
|
||||
|
||||
m_mode = MENU;
|
||||
|
||||
@@ -711,11 +821,11 @@ void InputManager::setMode(InputDriverMode new_mode)
|
||||
// We must be in menu mode now in order to switch.
|
||||
assert (m_mode == MENU);
|
||||
|
||||
if (m_action_map)
|
||||
delete m_action_map;
|
||||
//if (m_action_map)
|
||||
// delete m_action_map;
|
||||
|
||||
// Installs the action map for the ingame mode.
|
||||
m_action_map = user_config->newIngameActionMap();
|
||||
// m_action_map = user_config->newIngameActionMap();
|
||||
|
||||
SDLManager::hidePointer();
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <irrlicht.h>
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
@@ -60,7 +61,7 @@ private:
|
||||
* axis which was pushed the furthest when sensing input. */
|
||||
int m_max_sensed_input;
|
||||
Input::InputType m_max_sensed_type;
|
||||
ActionMap *m_action_map;
|
||||
//ActionMap *m_action_map;
|
||||
StickInfo **m_stick_infos;
|
||||
InputDriverMode m_mode;
|
||||
|
||||
@@ -71,6 +72,9 @@ private:
|
||||
int m_mouse_val_x, m_mouse_val_y;
|
||||
|
||||
void input(Input::InputType, int, int, int, int);
|
||||
void postIrrLichtMouseEvent(irr::EMOUSE_INPUT_EVENT type, const int x, const int y);
|
||||
void handleStaticAction(StaticAction ga, int value);
|
||||
void handlePlayerAction(PlayerAction pa, const int playerNo, int value);
|
||||
public:
|
||||
InputManager();
|
||||
~InputManager();
|
||||
|
||||
@@ -101,11 +101,11 @@ void PlayerKart::resetInputState()
|
||||
* and if it's 0 it indicates that the corresponding button
|
||||
* was released.
|
||||
*/
|
||||
void PlayerKart::action(KartAction action, int value)
|
||||
void PlayerKart::action(PlayerAction action, int value)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case KA_LEFT:
|
||||
case PA_LEFT:
|
||||
m_steer_val_l = -value;
|
||||
if (value)
|
||||
m_steer_val = -value;
|
||||
@@ -113,7 +113,7 @@ void PlayerKart::action(KartAction action, int value)
|
||||
m_steer_val = m_steer_val_r;
|
||||
|
||||
break;
|
||||
case KA_RIGHT:
|
||||
case PA_RIGHT:
|
||||
m_steer_val_r = value;
|
||||
if (value)
|
||||
m_steer_val = value;
|
||||
@@ -121,7 +121,7 @@ void PlayerKart::action(KartAction action, int value)
|
||||
m_steer_val = m_steer_val_l;
|
||||
|
||||
break;
|
||||
case KA_ACCEL:
|
||||
case PA_ACCEL:
|
||||
m_prev_accel = value;
|
||||
if(value)
|
||||
{
|
||||
@@ -134,7 +134,7 @@ void PlayerKart::action(KartAction action, int value)
|
||||
m_controls.m_brake = m_prev_brake;
|
||||
}
|
||||
break;
|
||||
case KA_BRAKE:
|
||||
case PA_BRAKE:
|
||||
m_prev_brake = value!=0;
|
||||
if(value)
|
||||
{
|
||||
@@ -147,21 +147,22 @@ void PlayerKart::action(KartAction action, int value)
|
||||
m_controls.m_accel = m_prev_accel/32768.0f;
|
||||
}
|
||||
break;
|
||||
case KA_NITRO:
|
||||
case PA_NITRO:
|
||||
m_controls.m_nitro = (value!=0);
|
||||
break;
|
||||
case KA_RESCUE:
|
||||
case PA_RESCUE:
|
||||
m_controls.m_rescue = (value!=0);
|
||||
break;
|
||||
case KA_FIRE:
|
||||
case PA_FIRE:
|
||||
m_controls.m_fire = (value!=0);
|
||||
break;
|
||||
case KA_LOOK_BACK:
|
||||
case PA_LOOK_BACK:
|
||||
m_controls.m_look_back = (value!=0);
|
||||
break;
|
||||
case KA_DRIFT:
|
||||
case PA_DRIFT:
|
||||
m_controls.m_drift = (value!=0);
|
||||
break;
|
||||
default: assert(false);
|
||||
}
|
||||
|
||||
} // action
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
int earlyStartPenalty () {return m_penalty_time>0; }
|
||||
Player *getPlayer () {return m_player; }
|
||||
void update (float);
|
||||
void action (KartAction action, int value);
|
||||
void action (PlayerAction action, int value);
|
||||
void handleZipper ();
|
||||
void collectedItem (const Item &item, int add_info=-1);
|
||||
virtual void crashed (Kart *k);
|
||||
|
||||
@@ -23,14 +23,14 @@
|
||||
#include <string>
|
||||
#include "input.hpp"
|
||||
|
||||
extern const char *sKartAction2String[KA_LAST+1];
|
||||
extern const char *sKartAction2String[PA_COUNT];
|
||||
|
||||
/*class for managing player name and control configuration*/
|
||||
class Player
|
||||
{
|
||||
private:
|
||||
std::string m_name;
|
||||
Input m_action_map[KA_LAST+1];
|
||||
Input m_action_map[PA_COUNT];
|
||||
int m_last_kart_id;
|
||||
|
||||
public:
|
||||
|
||||
@@ -143,65 +143,67 @@ void UserConfig::setDefaults()
|
||||
memset(m_input_map, 0, sizeof(m_input_map));
|
||||
|
||||
/* general game input settings */
|
||||
set(GA_ENTER,
|
||||
setStaticAction(GA_ENTER,
|
||||
Input(Input::IT_KEYBOARD, SDLK_RETURN),
|
||||
Input(Input::IT_KEYBOARD, SDLK_SPACE),
|
||||
Input(Input::IT_STICKBUTTON, 0, 0),
|
||||
Input(Input::IT_MOUSEBUTTON, 1));
|
||||
set(GA_LEAVE,
|
||||
setStaticAction(GA_LEAVE,
|
||||
Input(Input::IT_KEYBOARD, SDLK_ESCAPE),
|
||||
Input(Input::IT_STICKBUTTON, 0, 1),
|
||||
Input(Input::IT_MOUSEBUTTON, 2),
|
||||
Input(Input::IT_MOUSEBUTTON, 3));
|
||||
set(GA_CURSOR_UP,
|
||||
setStaticAction(GA_CURSOR_UP,
|
||||
Input(Input::IT_KEYBOARD, SDLK_UP),
|
||||
Input(Input::IT_MOUSEBUTTON, 4),
|
||||
Input(Input::IT_STICKMOTION, 0, 1, Input::AD_NEGATIVE));
|
||||
set(GA_CURSOR_DOWN,
|
||||
setStaticAction(GA_CURSOR_DOWN,
|
||||
Input(Input::IT_KEYBOARD, SDLK_DOWN),
|
||||
Input(Input::IT_MOUSEBUTTON, 5),
|
||||
Input(Input::IT_STICKMOTION, 0, 1, Input::AD_POSITIVE));
|
||||
set(GA_CURSOR_LEFT,
|
||||
setStaticAction(GA_CURSOR_LEFT,
|
||||
Input(Input::IT_KEYBOARD, SDLK_LEFT),
|
||||
Input(Input::IT_STICKMOTION, 0, 0, Input::AD_NEGATIVE));
|
||||
set(GA_CURSOR_RIGHT,
|
||||
setStaticAction(GA_CURSOR_RIGHT,
|
||||
Input(Input::IT_KEYBOARD, SDLK_RIGHT),
|
||||
Input(Input::IT_STICKMOTION, 0, 0, Input::AD_POSITIVE));
|
||||
set(GA_CLEAR_MAPPING,
|
||||
setStaticAction(GA_CLEAR_MAPPING,
|
||||
Input(Input::IT_KEYBOARD, SDLK_BACKSPACE),
|
||||
Input(Input::IT_STICKBUTTON, 0, 2));
|
||||
set(GA_INC_SCROLL_SPEED,
|
||||
setStaticAction(GA_INC_SCROLL_SPEED,
|
||||
Input(Input::IT_KEYBOARD, SDLK_PLUS));
|
||||
set(GA_INC_SCROLL_SPEED_FAST,
|
||||
setStaticAction(GA_INC_SCROLL_SPEED_FAST,
|
||||
Input(Input::IT_KEYBOARD, SDLK_PAGEDOWN));
|
||||
set(GA_DEC_SCROLL_SPEED,
|
||||
setStaticAction(GA_DEC_SCROLL_SPEED,
|
||||
Input(Input::IT_KEYBOARD, SDLK_MINUS));
|
||||
set(GA_DEC_SCROLL_SPEED_FAST,
|
||||
setStaticAction(GA_DEC_SCROLL_SPEED_FAST,
|
||||
Input(Input::IT_KEYBOARD, SDLK_PAGEUP));
|
||||
set(GA_TOGGLE_FULLSCREEN,
|
||||
setStaticAction(GA_TOGGLE_FULLSCREEN,
|
||||
Input(Input::IT_KEYBOARD, SDLK_F9));
|
||||
set(GA_LEAVE_RACE,
|
||||
setStaticAction(GA_LEAVE_RACE,
|
||||
Input(Input::IT_KEYBOARD, SDLK_ESCAPE));
|
||||
#ifdef DEBUG
|
||||
set(GA_DEBUG_ADD_BOWLING,
|
||||
setStaticAction(GA_DEBUG_ADD_BOWLING,
|
||||
Input(Input::IT_KEYBOARD, SDLK_F1));
|
||||
set(GA_DEBUG_ADD_MISSILE,
|
||||
setStaticAction(GA_DEBUG_ADD_MISSILE,
|
||||
Input(Input::IT_KEYBOARD, SDLK_F2));
|
||||
set(GA_DEBUG_ADD_HOMING,
|
||||
setStaticAction(GA_DEBUG_ADD_HOMING,
|
||||
Input(Input::IT_KEYBOARD, SDLK_F3));
|
||||
#endif
|
||||
set(GA_DEBUG_TOGGLE_FPS,
|
||||
setStaticAction(GA_DEBUG_TOGGLE_FPS,
|
||||
Input(Input::IT_KEYBOARD, SDLK_F12));
|
||||
set(GA_DEBUG_TOGGLE_WIREFRAME,
|
||||
setStaticAction(GA_DEBUG_TOGGLE_WIREFRAME,
|
||||
Input(Input::IT_KEYBOARD, SDLK_F11));
|
||||
set(GA_DEBUG_HISTORY,
|
||||
setStaticAction(GA_DEBUG_HISTORY,
|
||||
Input(Input::IT_KEYBOARD, SDLK_F10));
|
||||
|
||||
|
||||
// TODO: The following should become a static
|
||||
// array. This allows:
|
||||
// a) resetting to default values
|
||||
// b) prevent loading those defaults if config file contains any bindings
|
||||
|
||||
|
||||
#if 0
|
||||
/* Player 1 default input settings */
|
||||
set(GA_P1_LEFT, Input(Input::IT_KEYBOARD, SDLK_LEFT));
|
||||
set(GA_P1_RIGHT, Input(Input::IT_KEYBOARD, SDLK_RIGHT));
|
||||
@@ -253,7 +255,7 @@ void UserConfig::setDefaults()
|
||||
set(GA_P4_FIRE, Input(Input::IT_KEYBOARD, SDLK_PERIOD));
|
||||
set(GA_P4_LOOK_BACK, Input(Input::IT_KEYBOARD, SDLK_SLASH));
|
||||
#endif
|
||||
|
||||
#endif
|
||||
} // setDefaults
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -336,7 +338,8 @@ void UserConfig::loadConfig(const std::string& filename)
|
||||
// This will initialise the last input configuration with the
|
||||
// default values from the current (=default) player input
|
||||
// device configuration.
|
||||
readLastInputConfigurations(NULL);
|
||||
// TODO - input I/O
|
||||
// readLastInputConfigurations(NULL);
|
||||
|
||||
delete root;
|
||||
return;
|
||||
@@ -489,23 +492,27 @@ void UserConfig::loadConfig(const std::string& filename)
|
||||
} // configFileVersion <= 4
|
||||
|
||||
// Retrieves a player's INPUT configuration
|
||||
for(int ka=KA_FIRST; ka<=KA_LAST; ka++)
|
||||
// TODO - input config I/O
|
||||
/*
|
||||
for(int ka=PA_FIRST+1; ka<PA_COUNT; ka++)
|
||||
{
|
||||
readPlayerInput(reader, KartActionStrings[ka],
|
||||
readPlayerInput(reader, KartActionStrings[ka],
|
||||
(KartAction)ka, i);
|
||||
}
|
||||
*/
|
||||
// Leave those in for backwards compatibility (i.e. config files
|
||||
// with jump/wheelie). If jump/wheelie are not defined, nothing
|
||||
// happens (the same input is read again).
|
||||
readPlayerInput(reader, nitro_name, KA_NITRO, i);
|
||||
readPlayerInput(reader, drift_name, KA_DRIFT, i);
|
||||
//readPlayerInput(reader, nitro_name, KA_NITRO, i);
|
||||
//readPlayerInput(reader, drift_name, KA_DRIFT, i);
|
||||
} // for i < PLAYERS
|
||||
|
||||
// Read the last input device configurations. It is important that this
|
||||
// happens after reading the player config, since if no last config
|
||||
// is given, the last config is initialised with the current player
|
||||
// config.
|
||||
readLastInputConfigurations(lisp);
|
||||
// TODO - input I/O
|
||||
// readLastInputConfigurations(lisp);
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
@@ -556,6 +563,8 @@ void UserConfig::readStickConfigs(const lisp::Lisp *r)
|
||||
* configuration.
|
||||
* \param reader The lisp reader.
|
||||
*/
|
||||
#if 0
|
||||
// TODO - input I/O
|
||||
void UserConfig::readLastInputConfigurations(const lisp::Lisp *reader)
|
||||
{
|
||||
const lisp::Lisp* nodeReader = reader
|
||||
@@ -597,7 +606,6 @@ void UserConfig::readLastInputConfigurations(const lisp::Lisp *reader)
|
||||
} // for ka=KA_FIRST, KA_LAST
|
||||
} // for i<count
|
||||
} // readLastInputConfigurations
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void UserConfig::readPlayerInput(const lisp::Lisp *r, const std::string &node,
|
||||
KartAction ka, int playerIndex)
|
||||
@@ -676,7 +684,7 @@ Input UserConfig::readInput(const lisp::Lisp* nodeReader)
|
||||
}
|
||||
return input;
|
||||
} // readInput
|
||||
|
||||
#endif
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Write settings to config file. */
|
||||
void UserConfig::saveConfig(const std::string& filename)
|
||||
@@ -746,7 +754,8 @@ void UserConfig::saveConfig(const std::string& filename)
|
||||
writer->write("server-port", m_server_port);
|
||||
|
||||
writeStickConfigs(writer);
|
||||
writeLastInputConfigurations(writer);
|
||||
// TODO - input I/O
|
||||
// writeLastInputConfigurations(writer);
|
||||
|
||||
// Write unlock information back
|
||||
writer->beginList("unlock-info");
|
||||
@@ -769,11 +778,13 @@ void UserConfig::saveConfig(const std::string& filename)
|
||||
writer->writeComment("optional");
|
||||
writer->write("lastKartId", m_player[i].getLastKartId());
|
||||
|
||||
/* TODO - input I/O
|
||||
for(int ka=KA_FIRST; ka<=KA_LAST; ka++)
|
||||
{
|
||||
writePlayerInput(writer, KartActionStrings[ka]+"\t",
|
||||
(KartAction)ka, i);
|
||||
}
|
||||
*/
|
||||
writer->endList(temp);
|
||||
} // for i
|
||||
|
||||
@@ -820,6 +831,8 @@ void UserConfig::writeStickConfigs(lisp::Writer *writer)
|
||||
} // writeStickConfigs
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
#if 0
|
||||
// TODO - input I/O
|
||||
/** Saves the last configuration for each used input device to the player
|
||||
* config file.
|
||||
* \param writer The config file writer object.
|
||||
@@ -912,7 +925,7 @@ void UserConfig::writeInput(lisp::Writer *writer, const Input &input)
|
||||
break;
|
||||
}
|
||||
} // writeInput
|
||||
|
||||
#endif
|
||||
// -----------------------------------------------------------------------------
|
||||
std::string UserConfig::getInputAsString(const Input &input)
|
||||
{
|
||||
@@ -957,7 +970,8 @@ std::string UserConfig::getInputAsString(const Input &input)
|
||||
} // GetKeyAsString
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
std::string UserConfig::getMappingAsString(GameAction ga)
|
||||
#if 0
|
||||
std::string UserConfig::getMappingAsString(StaticAction ga)
|
||||
{
|
||||
if (m_input_map[ga].count &&
|
||||
m_input_map[ga].inputs[0].type)
|
||||
@@ -974,7 +988,7 @@ std::string UserConfig::getMappingAsString(GameAction ga)
|
||||
} // getMappingAsString
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
std::string UserConfig::getMappingAsString(int playerIndex, KartAction ka)
|
||||
std::string UserConfig::getMappingAsString(int playerIndex, StaticAction ka)
|
||||
{
|
||||
return getMappingAsString((GameAction) (GA_FIRST_KARTACTION
|
||||
+ playerIndex * KC_COUNT + ka) );
|
||||
@@ -1002,22 +1016,22 @@ void UserConfig::unsetDuplicates(GameAction ga, const Input &i)
|
||||
}
|
||||
}
|
||||
} // unsetDuplicates
|
||||
|
||||
#endif
|
||||
// -----------------------------------------------------------------------------
|
||||
void UserConfig::set(GameAction ga, const Input &i)
|
||||
void UserConfig::setStaticAction(StaticAction ga, const Input &i)
|
||||
{
|
||||
m_input_map[ga].count = 1;
|
||||
m_input_map[ga].inputs[0] = i;
|
||||
} // set(1 input)
|
||||
// -----------------------------------------------------------------------------
|
||||
void UserConfig::set(GameAction ga, const Input &i0, const Input &i1)
|
||||
void UserConfig::setStaticAction(StaticAction ga, const Input &i0, const Input &i1)
|
||||
{
|
||||
m_input_map[ga].count = 2;
|
||||
m_input_map[ga].inputs[0] = i0;
|
||||
m_input_map[ga].inputs[1] = i1;
|
||||
} // set(2 inputs)
|
||||
// -----------------------------------------------------------------------------
|
||||
void UserConfig::set(GameAction ga, const Input &i0, const Input &i1, const Input &i2)
|
||||
void UserConfig::setStaticAction(StaticAction ga, const Input &i0, const Input &i1, const Input &i2)
|
||||
{
|
||||
m_input_map[ga].count = 3;
|
||||
m_input_map[ga].inputs[0] = i0;
|
||||
@@ -1025,7 +1039,7 @@ void UserConfig::set(GameAction ga, const Input &i0, const Input &i1, const Inpu
|
||||
m_input_map[ga].inputs[2] = i2;
|
||||
} //set(3 inputs)
|
||||
// -----------------------------------------------------------------------------
|
||||
void UserConfig::set(GameAction ga, const Input &i0, const Input &i1,
|
||||
void UserConfig::setStaticAction(StaticAction ga, const Input &i0, const Input &i1,
|
||||
const Input &i2, const Input &i3)
|
||||
{
|
||||
m_input_map[ga].count = 4;
|
||||
@@ -1036,12 +1050,14 @@ void UserConfig::set(GameAction ga, const Input &i0, const Input &i1,
|
||||
} // set(4 inputs)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void UserConfig::setInput(GameAction ga, const Input &input)
|
||||
void UserConfig::setInput(PlayerAction ga, const Input &input)
|
||||
{
|
||||
// TODO - per-player input
|
||||
|
||||
// Removes the input from all mappings where it occurs.
|
||||
unsetDuplicates(ga, input);
|
||||
// unsetDuplicates(ga, input);
|
||||
|
||||
set(ga, input);
|
||||
//set(ga, input);
|
||||
} // setInput
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -1051,10 +1067,11 @@ void UserConfig::setInput(GameAction ga, const Input &input)
|
||||
* something else).
|
||||
* \param player_index Player index 0, ..., max
|
||||
*/
|
||||
#if 0 // TODO
|
||||
std::string UserConfig::getInputDeviceName(int player_index) const
|
||||
{
|
||||
std::string config_name;
|
||||
const Input &left_input = getInput(player_index, KA_LEFT);
|
||||
const Input &left_input = getInput(player_index, PA_LEFT);
|
||||
switch(left_input.type)
|
||||
{
|
||||
case Input::IT_KEYBOARD : { // config name: keyboard+player_index
|
||||
@@ -1140,29 +1157,33 @@ void UserConfig::clearInput(int playerIndex, KartAction ka)
|
||||
m_input_map[(GameAction) (GA_FIRST_KARTACTION + playerIndex * KC_COUNT + ka)]
|
||||
.count = 0;
|
||||
} // clearInput
|
||||
|
||||
#endif
|
||||
// -----------------------------------------------------------------------------
|
||||
ActionMap *UserConfig::newActionMap(const int from, const int to)
|
||||
{
|
||||
ActionMap *am = new ActionMap();
|
||||
|
||||
/* TODO
|
||||
for (int i = from; i <= to; i++)
|
||||
{
|
||||
const int count = m_input_map[i].count;
|
||||
for (int j = 0;j < count; j++)
|
||||
am->putEntry(m_input_map[i].inputs[j], (GameAction) i);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
return am;
|
||||
} // newActionMap
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
#if 0 // TODO
|
||||
ActionMap *UserConfig::newMenuActionMap()
|
||||
{
|
||||
return newActionMap(GA_FIRST_MENU, GA_LAST_MENU);
|
||||
} // newMenuActionMap
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
ActionMap *UserConfig::newIngameActionMap()
|
||||
{
|
||||
// This is rather unfriendly hack but work quite effective:
|
||||
@@ -1175,6 +1196,9 @@ ActionMap *UserConfig::newIngameActionMap()
|
||||
|
||||
// TODO: Reorder ingame GameAction values so that they start with
|
||||
// the fixed ones. This would allow simpler looking code here.
|
||||
|
||||
ActionMap *am = newActionMap(PA_FIRST, PA_LAST);
|
||||
|
||||
|
||||
GameAction gaEnd = GA_NULL;
|
||||
|
||||
@@ -1201,12 +1225,14 @@ ActionMap *UserConfig::newIngameActionMap()
|
||||
|
||||
return am;
|
||||
} // newIngameActionMap
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Determines whether the given Input is used in a mapping where it is marked
|
||||
* as fixed. This allows the input driver to discard the mapping and not
|
||||
* allow the user to use it.
|
||||
*/
|
||||
#if 0 // TODO
|
||||
bool UserConfig::isFixedInput(Input::InputType type, int id0, int id1, int id2)
|
||||
{
|
||||
for (int i = GA_FIRST_INGAME_FIXED; i <= GA_LAST_INGAME_FIXED; i++)
|
||||
@@ -1222,3 +1248,4 @@ bool UserConfig::isFixedInput(Input::InputType type, int id0, int id1, int id2)
|
||||
|
||||
return false;
|
||||
} // isFixedInput
|
||||
#endif
|
||||
|
||||
@@ -74,7 +74,7 @@ private:
|
||||
// device (i.e. keyboard, joystick, ...)
|
||||
struct InputConfiguration
|
||||
{
|
||||
Input m_input[KC_COUNT];
|
||||
Input m_input[PA_COUNT];
|
||||
};
|
||||
// The mapping of input device name to the last used configuration.
|
||||
// Note that std::map can not be used with Input[KC_COUNT] as 2nd
|
||||
@@ -121,11 +121,14 @@ private:
|
||||
int m_background_index;
|
||||
|
||||
void readStickConfigs(const lisp::Lisp *);
|
||||
void readLastInputConfigurations(const lisp::Lisp *);
|
||||
|
||||
void writeStickConfigs(lisp::Writer *);
|
||||
#if 0
|
||||
// TODO - input I/O
|
||||
|
||||
void writeLastInputConfigurations(lisp::Writer *);
|
||||
|
||||
void readLastInputConfigurations(const lisp::Lisp *);
|
||||
|
||||
void readPlayerInput(const lisp::Lisp *,
|
||||
const std::string& node,
|
||||
KartAction ka,
|
||||
@@ -148,25 +151,25 @@ private:
|
||||
GameAction);
|
||||
|
||||
void writeInput(lisp::Writer *writer, const Input &input);
|
||||
|
||||
#endif
|
||||
/** Iterates through the input mapping and unsets all
|
||||
* where the given input occurs.
|
||||
*
|
||||
* This makes sure an input is not bound multiple times.
|
||||
*/
|
||||
void unsetDuplicates(GameAction, const Input &);
|
||||
void unsetDuplicates(PlayerAction, const Input &);
|
||||
|
||||
/** Creates an GameAction->Input mapping with one Input */
|
||||
void set(GameAction, const Input &);
|
||||
void setStaticAction(StaticAction, const Input &);
|
||||
|
||||
/** Creates an GameAction->Input mapping with two Inputs */
|
||||
void set(GameAction, const Input &, const Input &);
|
||||
void setStaticAction(StaticAction, const Input &, const Input &);
|
||||
|
||||
/** Creates an GameAction->Input mapping with three Inputs */
|
||||
void set(GameAction, const Input &, const Input &, const Input &);
|
||||
void setStaticAction(StaticAction, const Input &, const Input &, const Input &);
|
||||
|
||||
/** Creates an GameAction->Input mapping with four Inputs */
|
||||
void set(GameAction, const Input &, const Input &, const Input &, const Input &);
|
||||
void setStaticAction(StaticAction, const Input &, const Input &, const Input &, const Input &);
|
||||
|
||||
std::string getInputAsString(const Input &);
|
||||
|
||||
@@ -180,7 +183,7 @@ private:
|
||||
*
|
||||
* For use when reading from file.
|
||||
*/
|
||||
void setInput(GameAction, const Input &);
|
||||
void setInput(PlayerAction, const Input &);
|
||||
|
||||
public:
|
||||
enum UC_Mode {UC_ENABLE, UC_DISABLE, UC_TEMPORARY_DISABLE};
|
||||
@@ -257,13 +260,15 @@ public:
|
||||
const std::vector<StickConfig *>
|
||||
*getStickConfigs() const { return &m_stickconfigs; }
|
||||
|
||||
|
||||
#if 0
|
||||
// TODO - and does that really belong in user config?
|
||||
/** Retrieves a human readable string of the mapping for a GameAction */
|
||||
std::string getMappingAsString(GameAction);
|
||||
std::string getMappingAsString(StaticAction);
|
||||
/** Retrieves a human readable string of the mapping for the given
|
||||
* player and KartAction.
|
||||
*/
|
||||
std::string getMappingAsString(int, KartAction);
|
||||
std::string getMappingAsString(int, StaticAction);
|
||||
|
||||
|
||||
/** Sets the Input for the given Player and KartAction. Includes a check
|
||||
* for duplicates and automatic removing of the other candidate(s).
|
||||
@@ -273,19 +278,22 @@ public:
|
||||
void setInput(int player_number, KartAction ka, const Input &i0);
|
||||
const Input &getInput(int player_index, KartAction ka) const;
|
||||
|
||||
|
||||
/** Clears the mapping for a given Player and KartAction. */
|
||||
void clearInput(int, KartAction);
|
||||
bool isFixedInput(Input::InputType, int, int, int);
|
||||
#endif
|
||||
|
||||
const std::string
|
||||
&getWarning() { return m_warning; }
|
||||
void resetWarning() { m_warning=""; }
|
||||
void setWarning(std::string& warning) { m_warning=warning; }
|
||||
|
||||
/** Creates ActionMap for use in menu mode. */
|
||||
ActionMap *newMenuActionMap();
|
||||
//ActionMap *newMenuActionMap();
|
||||
|
||||
/** Creates ActionMap for use in ingame mode. */
|
||||
ActionMap *newIngameActionMap();
|
||||
//ActionMap *newIngameActionMap();
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user