Commit b7da45bb authored by Benjamin 'Albsi' Albsmeier's avatar Benjamin 'Albsi' Albsmeier
Browse files

the input now allow to handle a key, a mouse button and a controller button in the same way

parent 41a335da
......@@ -17,9 +17,13 @@ victim_mass : 1
map_load_timer : 0
mapGenDebug : false
player_move_left_key : A
player_move_left_cbutton : LEFT
player_move_right_cbutton : RIGHT
player_move_right_key : D
beam_normal_mouse : Left
beam_inverse_mouse : Right
beam_normal_mbutton : Left
beam_inverse_mbutton : Right
beam_normal_key : Q
beam_inverse_key : E
place_item_key : Space
state_switch_key : Esc
test_ui : false
......@@ -35,19 +35,12 @@ namespace gdw{
place_item
};
enum class inputType{
key,
mouse,
controller_button,
key_and_controller_button/*,
controller_axis*/
};
struct inputMapingStruct {
inputType type;
SDL_Keycode keyCode;
int mouseCode;
SDL_GameControllerButton controllerCode;
unsigned int type = 0;
SDL_Keycode keyCode = -1;
int mbuttonCode = -1;
SDL_GameControllerButton cbuttonCode = SDL_CONTROLLER_BUTTON_INVALID;
SDL_GameControllerAxis caxisCode = SDL_CONTROLLER_AXIS_INVALID;
};
class engine;
......@@ -56,6 +49,15 @@ namespace gdw{
std::string controllerDBPath_ = "input/gamecontrollerdb.txt";
static float constexpr controllerAxisMax_ = 32767.f;
static float constexpr controllerAxisDeadZone_ = .3f;
/**inputMapingStruct.type for key*/
static unsigned int constexpr key = 0x1;
/**inputMapingStruct.type for mouse button*/
static unsigned int constexpr mbutton = 0x2;
/**inputMapingStruct.type for controller button*/
static unsigned int constexpr cbutton = 0x4;
/**inputMapingStruct.type for controller axis*/
static unsigned int constexpr caxis = 0x8;
public:
input(engine& engine);
~input();
......@@ -68,42 +70,36 @@ namespace gdw{
* should called once per game loop, at the end*/
void reset();
bool isPressed(inputMaping id);
bool isDown(inputMaping id);
bool isReleased(inputMaping id);
/**Returns true every frame, as long as the key is down.*/
private:
int isKeyDown(SDL_Keycode key) noexcept {return keyState_[SDL_GetScancodeFromKey(key)];};
public:
int isKeyDown(inputMaping key) noexcept {return isKeyDown(getKeyCodeByMaping(key));};
/**Returns true once the key is pressed*/
private:
bool isKeyPressed(SDL_Keycode key) noexcept {return keyMap_[key]==1;};
public:
bool isKeyPressed(inputMaping key) noexcept {return isKeyPressed(getKeyCodeByMaping(key));};
/**Returns true once the key is released*/
private:
bool isKeyReleased(SDL_Keycode key) noexcept {return keyReleasedMap_[key] && !keyState_[SDL_GetScancodeFromKey(key)];};
public:
bool isKeyReleased(inputMaping key) noexcept {return isKeyReleased(getKeyCodeByMaping(key));};
/**Returns true every frame, as long as the mouse button is down.*/
private:
bool isMouseButtonDown(int button) noexcept {return SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(button);};
public:
bool isMouseButtonDown(inputMaping button);
/**Returns true once the mouse button is pressed*/
private:
bool isMouseButtonPressed(int button) noexcept {return mouseMap_[button]==1;};
public:
bool isMouseButtonPressed(inputMaping button);
/**Returns true once the mouse button is released*/
private:
bool isMouseButtonReleased(int button) noexcept {return mouseReleasedMap_[button];};
public:
bool isMouseButtonReleased(inputMaping button);
public:
/**Returns a glm::vec2 with the x and y motion of the mouse wheel
* y is the motion a nomal mouse wheel can perform*/
glm::vec2 mouseWheel()noexcept{return mousePos_;};
......@@ -124,20 +120,28 @@ namespace gdw{
int mousePosY()noexcept{return mousePos_.y;};
/**Returns true every frame, as long as the controller button is down.*/
private:
bool isControllerButtonDown(SDL_GameControllerButton button, int nr = 0);
bool isControllerButtonDown(inputMaping button, int nr = 0) noexcept {return isControllerButtonDown(getControllerButtonCodeByMaping(button), nr);};
public:
bool isControllerButtonDown(inputMaping button, int nr = 0) noexcept {return isControllerButtonDown(getCButtonCodeByMaping(button), nr);};
/**Returns true once the controller button is pressed*/
private:
bool isControllerButtonPressed(SDL_GameControllerButton button, int nr = 0);
bool isControllerButtonPressed(inputMaping button, int nr = 0) noexcept {return isControllerButtonPressed(getControllerButtonCodeByMaping(button), nr);};
public:
bool isControllerButtonPressed(inputMaping button, int nr = 0) noexcept {return isControllerButtonPressed(getCButtonCodeByMaping(button), nr);};
/**Returns true once the controller button is released*/
private:
bool isControllerButtonReleased(SDL_GameControllerButton button, int nr = 0);
bool isControllerButtonReleased(inputMaping button, int nr = 0) noexcept {return isControllerButtonReleased(getControllerButtonCodeByMaping(button), nr);};
public:
bool isControllerButtonReleased(inputMaping button, int nr = 0) noexcept {return isControllerButtonReleased(getCButtonCodeByMaping(button), nr);};
/**Returns the value of that axis as a float between -1 and 1*/
private:
float controllerAxis(SDL_GameControllerAxis axis, int nr = 0);
//float controllerAxis(inputMaping axis, int nr = 0) noexcept {return getControllerAxisCodeByMaping(getControllerAxisCodeByMaping(axis), nr);};
public:
float controllerAxis(inputMaping axis, int nr = 0) noexcept {return controllerAxis(getCAxisCodeByMaping(axis), nr);};
/**Returns number of aktiv controllers*/
int controllerCount() noexcept {return controllers_.size();};
......@@ -150,13 +154,16 @@ namespace gdw{
std::map<gdw::inputMaping, gdw::inputMapingStruct> mapings_;
void makeMapings();
void addMaping(inputMaping id, inputType type, SDL_Keycode keyCode = -1, int mouseCode = -1, SDL_GameControllerButton controllerCode = SDL_CONTROLLER_BUTTON_INVALID);
SDL_Keycode getKeyCodeByMaping(inputMaping id);
int getMouseButtonCodeByMaping(inputMaping id);
SDL_GameControllerButton getControllerButtonCodeByMaping(inputMaping id);
SDL_GameControllerAxis getControllerAxisCodeByMaping(inputMaping id);
int getMouseButtonFromName(std::string name);
int getMButtonCodeByMaping(inputMaping id);
SDL_GameControllerButton getCButtonCodeByMaping(inputMaping id);
SDL_GameControllerAxis getCAxisCodeByMaping(inputMaping id);
int getMButtonFromName(std::string name);
SDL_Keycode getKeyFromName(std::string name);
SDL_GameControllerButton getCButtonFromName(std::string name);
SDL_GameControllerAxis getCAxisFromName(std::string name);
controller controller_;
engine &engine_;
......@@ -185,30 +192,30 @@ namespace gdw{
//CONTROLLER
void controllerUp(const SDL_ControllerButtonEvent &e);
void controllerDown(const SDL_ControllerButtonEvent &e);
void controllerAdd(const SDL_ControllerDeviceEvent &e);
void controllerRemove(const SDL_ControllerDeviceEvent &e);
void controllerRemapped(const SDL_ControllerDeviceEvent &e);
void controllerAxis(const SDL_ControllerAxisEvent &e);
void controllerAdded(const SDL_ControllerDeviceEvent &e);
void controllerRemoved(const SDL_ControllerDeviceEvent &e);
void controllerRemapped(const SDL_ControllerDeviceEvent &e) noexcept {log << "[input] controllerRemapped was triggerd but is not handelt" << std::endl;};
void controllerAxis(const SDL_ControllerAxisEvent &e) noexcept {/*handelt on another way, see: float controllerAxis(SDL_GameControllerAxis axis, int nr)*/};
//TEXTINPUT
void textEdit(const SDL_TextEditingEvent &e);
void textInput(const SDL_TextInputEvent &e);
void textEdit(const SDL_TextEditingEvent &e) noexcept {log << "[input] textInput was triggerd but is not handelt" << std::endl;};
void textInput(const SDL_TextInputEvent &e) noexcept {/*spams the log on every key input - not handelt*/};
//TOUCH
void touchMotion(const SDL_TouchFingerEvent &e);
void touchDown(const SDL_TouchFingerEvent &e);
void touchUp(const SDL_TouchFingerEvent &e);
void touchGesture(const SDL_MultiGestureEvent &e);
void touchComplexGesture(const SDL_DollarGestureEvent &e);
void touchGestureRecord(const SDL_DollarGestureEvent &e);
void touchMotion(const SDL_TouchFingerEvent &e) noexcept {log << "[input] touchMotion was triggerd but is not handelt" << std::endl;};
void touchDown(const SDL_TouchFingerEvent &e) noexcept {log << "[input] touchDown was triggerd but is not handelt" << std::endl;};
void touchUp(const SDL_TouchFingerEvent &e) noexcept {log << "[input] touchUp was triggerd but is not handelt" << std::endl;};
void touchGesture(const SDL_MultiGestureEvent &e) noexcept {log << "[input] touchGesture was triggerd but is not handelt" << std::endl;};
void touchComplexGesture(const SDL_DollarGestureEvent &e) noexcept {log << "[input] touchComplexGesture was triggerd but is not handelt" << std::endl;};
void touchGestureRecord(const SDL_DollarGestureEvent &e) noexcept {log << "[input] touchGestureRecord was triggerd but is not handelt" << std::endl;};
//JOYSTICK
void joyAdded(const SDL_JoyDeviceEvent &e);
void joyRemoved(const SDL_JoyDeviceEvent &e);
void joyHat(const SDL_JoyHatEvent &e);
void joyDown(const SDL_JoyButtonEvent &e);
void joyUp(const SDL_JoyButtonEvent &e);
void joyBall(const SDL_JoyBallEvent &e);
void joyAxis(const SDL_JoyAxisEvent &e);
void joyAdded(const SDL_JoyDeviceEvent &e) noexcept {/*controllerAdded*/};
void joyRemoved(const SDL_JoyDeviceEvent &e) noexcept {/*controllerRemoved*/};
void joyHat(const SDL_JoyHatEvent &e) noexcept {/*controllerDown / controllerUp*/};
void joyDown(const SDL_JoyButtonEvent &e) noexcept {/*controllerDown*/};
void joyUp(const SDL_JoyButtonEvent &e) noexcept {/*controllerUp*/};
void joyBall(const SDL_JoyBallEvent &e) noexcept {log << "[input] joyBall was triggerd but is not handelt" << std::endl;};
void joyAxis(const SDL_JoyAxisEvent &e) noexcept {/*controllerAxis*/};
//DROP
void drop(const SDL_DropEvent &e);
void drop(const SDL_DropEvent &e) noexcept {log << "[input] drop was triggerd but is not handelt" << std::endl;};
};
}
......
......@@ -43,12 +43,12 @@ namespace gdw {
}
void AudioEventHandler::playStateUpdate(float deltaTime) {
if ((this->engine.input().isKeyPressed(inputMaping::player_move_left) || this->engine.input().isKeyPressed(inputMaping::player_move_right)) && !this->playerMoving) {
if ((this->engine.input().isPressed(inputMaping::player_move_left) || this->engine.input().isPressed(inputMaping::player_move_right)) && !this->playerMoving) {
this->channels["ship"] = this->engine.audio().queue_sound("engine", -1);
this->engine.audio().sound_volume(40, this->channels["ship"]);
this->playerMoving = true;
}
if (!this->engine.input().isKeyDown(inputMaping::player_move_left) && !this->engine.input().isKeyDown(inputMaping::player_move_right) && this->playerMoving) {
if (!this->engine.input().isDown(inputMaping::player_move_left) && !this->engine.input().isDown(inputMaping::player_move_right) && this->playerMoving) {
this->engine.audio().stop_sound(this->channels["ship"], 600);
this->playerMoving = false;
}
......
......@@ -21,7 +21,7 @@ void menu_state::on_enter() {
}
void menu_state::update(float dt) {
if (this->engine_.input().isKeyPressed(inputMaping::state_switch))
if (this->engine_.input().isPressed(inputMaping::state_switch))
this->engine_.game_state_machine().change_state<play_state>();
}
......
......@@ -58,7 +58,7 @@ void play_state::update(float dt) {
this->engine_.audioEventHandler().playStateUpdate(dt);
if (this->engine_.input().isKeyPressed(inputMaping::state_switch))
if (this->engine_.input().isPressed(inputMaping::state_switch))
this->engine_.game_state_machine().change_state<menu_state>();
}
......
......@@ -76,11 +76,7 @@ namespace gdw {
constexpr float rotation_speed = 7.f;
constexpr float turn_rate_modifier = 4.5f;
if(input.isKeyPressed(inputMaping::place_item)){
log << "place_item" << std::endl;
}
if (input.isKeyDown(inputMaping::player_move_left) && player->position().x > -maximum_movement_distance) {
if (input.isDown(inputMaping::player_move_left) && player->position().x > -maximum_movement_distance) {
auto orientation = player->rotation()*glm::vec3(0,0,1);
auto diff = std::abs(orientation.x - (-1.f)) + std::abs(orientation.z - (0.f));
auto clamped = glm::clamp(diff/turn_rate_modifier, 0.f, 1.f);
......@@ -93,7 +89,7 @@ namespace gdw {
move->add_angular_force(glm::vec3(0.f, -rotation_speed*(std::pow(diff, 1.4f)) , 0.f));
}
if (engine_.input().isKeyDown(inputMaping::player_move_right) && player->position().x < maximum_movement_distance) {
if (engine_.input().isDown(inputMaping::player_move_right) && player->position().x < maximum_movement_distance) {
auto orientation = player->rotation()*glm::vec3(0,0,1);
auto diff = std::abs(orientation.x - (1.f)) + std::abs(orientation.z - (0.f));
auto clamped = glm::clamp(diff/turn_rate_modifier, 0.f, 1.f);
......@@ -107,7 +103,7 @@ namespace gdw {
}
// SET ITEM WITH SPACE KEY
if (input.isKeyDown(inputMaping::place_item)) {
if (input.isDown(inputMaping::place_item)) {
engine_.game_play_system().player_item_manager().place_item(get_world_mouse_pos());
}
}
......@@ -127,21 +123,21 @@ namespace gdw {
cam->position(cam->position()+glm::vec3(0,-1.f,-1.f));
}
if(input.isMouseButtonPressed(inputMaping::beam_normal)) {
if(input.isPressed(inputMaping::beam_normal)) {
engine_.audioEventHandler().trigger(AudioEventHandler::TRAKTORBEAM_REVERSE_ACTIVATED);
}
if(input.isMouseButtonReleased(inputMaping::beam_normal)) {
if(input.isReleased(inputMaping::beam_normal)) {
engine_.audioEventHandler().trigger(AudioEventHandler::TRAKTORBEAM_REVERSE_DEACTIVATED);
}
if(input.isMouseButtonPressed(inputMaping::beam_inverse)) {
if(input.isPressed(inputMaping::beam_inverse)) {
engine_.audioEventHandler().trigger(AudioEventHandler::TRAKTORBEAM_ACTIVATED);
}
if(input.isMouseButtonReleased(inputMaping::beam_inverse)) {
if(input.isReleased(inputMaping::beam_inverse)) {
engine_.audioEventHandler().trigger(AudioEventHandler::TRAKTORBEAM_REVERSE_DEACTIVATED);
}
//LEFT && RIGHT CLICK
if(input.isMouseButtonDown(inputMaping::beam_normal) || input.isMouseButtonDown(inputMaping::beam_inverse)) {
if(input.isDown(inputMaping::beam_normal) || input.isDown(inputMaping::beam_inverse)) {
auto intersection_point = get_world_mouse_pos();
auto cannon = level_manager.cannon();
......@@ -165,7 +161,7 @@ namespace gdw {
rot *= glm::quat(qw,qx,qy,qz);
auto ray_unnormalized = glm::vec3(1.f);
if (input.isMouseButtonDown(inputMaping::beam_normal)) {
if (input.isDown(inputMaping::beam_normal)) {
ray_unnormalized = r.source - r.destination;
} else {
ray_unnormalized = r.destination - r.source;
......@@ -199,7 +195,7 @@ namespace gdw {
}
}
if (input.isMouseButtonDown(inputMaping::beam_normal)) {
if (input.isDown(inputMaping::beam_normal)) {
auto ray_length = (std::abs(ray_length_ - 0.f) < 0.001f)? glm::length(ray_unnormalized): ray_length_;
engine_.rendering_system().render_trakor_beam(r.source, rot, ray_length, 1.f, false);
} else {
......
......@@ -12,36 +12,61 @@ namespace gdw{
makeMapings();
}
//if you add here, add also in enum inputMaping in input.hpp
/** if you add here, add also in enum inputMaping in input.hpp
*
* key names: http://wiki.libsdl.org/SDL_Keycode?highlight=%28%5CbCategoryEnum%5Cb%29%7C%28CategoryKeyboard%29
* getKeyFromName(std::string)
*
* mouse button names: Left, Right, Middle, Mouse4, Mouse5
* getMButtonFromName(std::string)
*
* controller button names: http://wiki.libsdl.org/SDL_GameControllerButton
* without 'SDL_CONTROLLER_BUTTON_'
* except for dpad: dpad_up is 'up', dpad_down is 'down', dpad_left is 'left', dpad_right is 'right'
* getCButtonFromName(std::string)
*
* controller axis names: http://wiki.libsdl.org/SDL_GameControllerAxis without 'SDL_CONTROLLER_AXIS_'
* getCAxisFromName(std::string)
*
* DON'T USE A CONTROLLER AXIS LIKE A BUTTON OR A KEY IT WILL NOT WORK
* DON'T MISS TO ADD THE RIGHT TYPES
*/
void input::makeMapings(){
//EXAMPLE:
//
//addMaping(inputMaping::inputMaping,
// inputType, [key, mouse, controller_button, key_and_controller_button]
// getKeyFromName(engine_.getConfig().get<std::string>("player_move_left_key","A")),
// getMouseButtonFromName(engine_.getConfig().get<std::string>("beam_normal_mouse","Left")),
// getControllerButtonFromName(engine_.getConfig().get<std::string>("player_move_left_controller","A")));
addMaping(inputMaping::state_switch,
inputType::key,
getKeyFromName(engine_.getConfig().get<std::string>("state_switch_key","Esc")));
addMaping(inputMaping::player_move_left,
inputType::key,
getKeyFromName(engine_.getConfig().get<std::string>("player_move_left_key","A")));
addMaping(inputMaping::player_move_right,
inputType::key,
getKeyFromName(engine_.getConfig().get<std::string>("player_move_right_key","D")));
addMaping(inputMaping::beam_normal,
inputType::mouse,
-1,
getMouseButtonFromName(engine_.getConfig().get<std::string>("beam_normal_mouse","Left")));
addMaping(inputMaping::beam_inverse,
inputType::mouse,
-1,
getMouseButtonFromName(engine_.getConfig().get<std::string>("beam_inverse_mouse","Right")));
addMaping(inputMaping::place_item,
inputType::key,
getKeyFromName(engine_.getConfig().get<std::string>("place_item_key","Space")));
//KEYS
inputMapingStruct state_switch_;
state_switch_.type += key;
state_switch_.keyCode = getKeyFromName(engine_.getConfig().get<std::string>("state_switch_key","Esc"));
mapings_.emplace(inputMaping::state_switch, state_switch_);
inputMapingStruct player_move_left_;
player_move_left_.type += key + cbutton;
player_move_left_.keyCode = getKeyFromName(engine_.getConfig().get<std::string>("player_move_left_key","A"));
player_move_left_.cbuttonCode = getCButtonFromName(engine_.getConfig().get<std::string>("player_move_left_cbutton","X"));
mapings_.emplace(inputMaping::player_move_left, player_move_left_);
inputMapingStruct player_move_right_;
player_move_right_.type += key + cbutton;
player_move_right_.keyCode = getKeyFromName(engine_.getConfig().get<std::string>("player_move_right_key","D"));
player_move_right_.cbuttonCode = getCButtonFromName(engine_.getConfig().get<std::string>("player_move_right_cbutton","B"));
mapings_.emplace(inputMaping::player_move_right, player_move_right_);
inputMapingStruct place_item_;
place_item_.type += key;
place_item_.keyCode = getKeyFromName(engine_.getConfig().get<std::string>("place_item_key","Space"));
mapings_.emplace(inputMaping::place_item, place_item_);
//MOUSE
inputMapingStruct beam_normal_;
beam_normal_.type += mbutton + key;
beam_normal_.mbuttonCode = getMButtonFromName(engine_.getConfig().get<std::string>("beam_normal_mouse","Left"));
beam_normal_.keyCode = getKeyFromName(engine_.getConfig().get<std::string>("beam_normal_key","Q"));
mapings_.emplace(inputMaping::beam_normal, beam_normal_);
inputMapingStruct beam_inverse_;
beam_inverse_.type += mbutton + key;
beam_inverse_.mbuttonCode = getMButtonFromName(engine_.getConfig().get<std::string>("beam_inverse_mouse","Right"));
beam_inverse_.keyCode = getKeyFromName(engine_.getConfig().get<std::string>("beam_inverse_key","E"));
mapings_.emplace(inputMaping::beam_inverse, beam_inverse_);
}
input::~input(){}
......@@ -59,8 +84,8 @@ namespace gdw{
//CONTROLLER
case SDL_CONTROLLERBUTTONDOWN: controllerDown(e.cbutton); break;
case SDL_CONTROLLERBUTTONUP: controllerUp(e.cbutton); break;
case SDL_CONTROLLERDEVICEADDED: controllerAdd(e.cdevice); break;
case SDL_CONTROLLERDEVICEREMOVED: controllerRemove(e.cdevice); break;
case SDL_CONTROLLERDEVICEADDED: controllerAdded(e.cdevice); break;
case SDL_CONTROLLERDEVICEREMOVED: controllerRemoved(e.cdevice); break;
case SDL_CONTROLLERDEVICEREMAPPED: controllerRemapped(e.cdevice); break;
case SDL_CONTROLLERAXISMOTION: controllerAxis(e.caxis); break;
//TEXTINPUT
......@@ -131,7 +156,8 @@ namespace gdw{
}
}
void input::controllerAdd(const SDL_ControllerDeviceEvent &e){
void input::controllerAdded(const SDL_ControllerDeviceEvent &e){
log << "[input] controllerAdded was triggerd" << std::endl;
if(SDL_IsGameController(e.which)){
controller c;
c.controllerNr = e.which;
......@@ -147,80 +173,9 @@ namespace gdw{
}
}
void input::controllerRemove(const SDL_ControllerDeviceEvent &e){
log << "[input] SDL_CONTROLLERDEVICEREMOVED was triggerd but is not handelt" << std::endl;
}
void input::controllerRemapped(const SDL_ControllerDeviceEvent &e){
log << "[input] SDL_CONTROLLERDEVICEREMAPPED was triggerd but is not handelt" << std::endl;
}
void input::controllerAxis(const SDL_ControllerAxisEvent &e){
//handelt on another way, see: float controllerAxis(SDL_GameControllerAxis axis, int nr)
}
void input::textEdit(const SDL_TextEditingEvent &e){
log << "[input] SDL_TEXTEDITING was triggerd but is not handelt" << std::endl;
}
void input::textInput(const SDL_TextInputEvent &e){
//spams the log on every key input //not handelt
}
void input::touchMotion(const SDL_TouchFingerEvent &e){
log << "[input] SDL_FINGERMOTION was triggerd but is not handelt" << std::endl;
}
void input::touchDown(const SDL_TouchFingerEvent &e){
log << "[input] SDL_FINGERDOWN was triggerd but is not handelt" << std::endl;
}
void input::touchUp(const SDL_TouchFingerEvent &e){
log << "[input] SDL_FINGERUP was triggerd but is not handelt" << std::endl;
}
void input::touchGesture(const SDL_MultiGestureEvent &e){
log << "[input] SDL_MULTIGESTURE was triggerd but is not handelt" << std::endl;
}
void input::touchComplexGesture(const SDL_DollarGestureEvent &e){
log << "[input] SDL_DOLLARGESTURE was triggerd but is not handelt" << std::endl;
}
void input::controllerRemoved(const SDL_ControllerDeviceEvent &e){
log << "[input] controllerRemove was triggerd but is not handelt" << std::endl;
void input::touchGestureRecord(const SDL_DollarGestureEvent &e){
log << "[input] SDL_DOLLARRECORD was triggerd but is not handelt" << std::endl;
}
void input::joyAdded(const SDL_JoyDeviceEvent &e){
log << "[input] SDL_JOYDEVICEADDED was triggerd but is not handelt" << std::endl;
}
void input::joyRemoved(const SDL_JoyDeviceEvent &e){
log << "[input] SDL_JOYDEVICEREMOVED was triggerd but is not handelt" << std::endl;
}
void input::joyHat(const SDL_JoyHatEvent &e){
log << "[input] SDL_JOYHATMOTION was triggerd but is not handelt" << std::endl;
}
void input::joyDown(const SDL_JoyButtonEvent &e){
log << "[input] SDL_JOYBUTTONDOWN was triggerd but is not handelt" << std::endl;
}
void input::joyUp(const SDL_JoyButtonEvent &e){
log << "[input] SDL_JOYBUTTONUP was triggerd but is not handelt" << std::endl;
}
void input::joyBall(const SDL_JoyBallEvent &e){
log << "[input] SDL_JOYBALLMOTION was triggerd but is not handelt" << std::endl;
}
void input::joyAxis(const SDL_JoyAxisEvent &e){
log << "[input] SDL_JOYAXISMOTION was triggerd but is not handelt" << std::endl;
}
void input::drop(const SDL_DropEvent &e){
log << "[input] SDL_DROPFILE was triggerd but is not handelt" << std::endl;
}
//RESET
......@@ -249,41 +204,32 @@ namespace gdw{
}
//MAPING
void input::addMaping(inputMaping id, inputType type, SDL_Keycode keyCode, int mouseCode, SDL_GameControllerButton controllerCode){
inputMapingStruct s;
s.type = type;
s.keyCode = keyCode;
s.mouseCode = mouseCode;
s.controllerCode = controllerCode;
mapings_.emplace(id, s);
}
int input::getKeyCodeByMaping(inputMaping id){
return mapings_[id].type == inputType::key || mapings_[id].type == inputType::key_and_controller_button ? mapings_[id].keyCode : -1;
return (mapings_[id].type & key) !=0? mapings_[id].keyCode : -1;
}
int input::getMouseButtonCodeByMaping(inputMaping id){
return mapings_[id].type == inputType::mouse ? mapings_[id].mouseCode : -1;
int input::getMButtonCodeByMaping(inputMaping id){
return (mapings_[id].type & mbutton) !=0? mapings_[id].mbuttonCode : -1;
}
SDL_GameControllerButton input::getControllerButtonCodeByMaping(inputMaping id){
return mapings_[id].type == inputType::controller_button || mapings_[id].type == inputType::key_and_controller_button ? mapings_[id].controllerCode : SDL_CONTROLLER_BUTTON_INVALID;
SDL_GameControllerButton input::getCButtonCodeByMaping(inputMaping id){
return (mapings_[id].type & cbutton) !=0? mapings_[id].cbuttonCode : SDL_CONTROLLER_BUTTON_INVALID;
}
/*int input::getControllerAxisCodeByMaping(inputMaping id){
return -1;//mapings_[id].type == controller_axis ? mapings_[id].sdlCode : -1;
}*/
SDL_GameControllerAxis input::getCAxisCodeByMaping(inputMaping id){
return (mapings_[id].type & caxis) !=0? mapings_[id].caxisCode : SDL_CONTROLLER_AXIS_INVALID;
}
int input::getMouseButtonFromName(std::string name){
if(name == "Left"){
int input::getMButtonFromName(std::string name){
if(name == "Left" || name == "left" || name == "LEFT"){
return SDL_BUTTON_LEFT;
}else if(name == "Right"){
}else if(name == "Right" || name == "right" || name == "RIGHT"){
return SDL_BUTTON_RIGHT;
}else if(name == "Middle"){
}else if(name == "Middle" || name == "middle" || name == "MIDDLE"){
return SDL_BUTTON_MIDDLE;
}else if(name == "Mouse4"){
}else if(name == "Mouse4" || name == "mouse4" || name == "MOUSE4"){
return SDL_BUTTON_X1;
}else if(name == "Mouse5"){
}else if(name == "Mouse5" || name == "mouse5" || name == "MOUSE5"){
return SDL_BUTTON_X2;
}else{
return -1;
......@@ -294,19 +240,108 @@ namespace gdw{
return SDL_GetKeyFromName(name.c_str());
}
SDL_GameControllerButton input::getCButtonFromName(std::string name){
if(name == "LEFT" || name == "left" || name == "Left"){
return SDL_CONTROLLER_BUTTON_DPAD_LEFT;
}else if(name == "RIGHT" || name == "right" || name == "Right"){
return SDL_CONTROLLER_BUTTON_DPAD_RIGHT;
}else if(name == "UP" || name == "up" || name == "Up"){
return SDL_CONTROLLER_BUTTON_DPAD_UP;
}else if(name == "DOWN" || name == "down" || name == "Down"){
return SDL_CONTROLLER_BUTTON_DPAD_DOWN;
}
return SDL_GameControllerGetButtonFromString(name.c_str());
}
SDL_