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

made input mappings nicer

parent 3e51b91c
......@@ -17,22 +17,31 @@ victim_mass : 1
map_load_timer : 0
test_ui : false
mapGenDebug : false
player_move_left_key : A
player_move_left_key2 : Left
player_move_left_cbutton : LEFT
player_move_left_caxis : RIGHTX
player_move_right_key : D
player_move_right_key2 : Right
player_move_right_cbutton : RIGHT
player_move_right_caxis : RIGHTX
beam_normal_key : Q
beam_normal_mbutton : Left
beam_normal_caxis : LEFTTRIGGER
beam_inverse_key : E
beam_inverse_mbutton : Right
beam_inverse_caxis : RIGHTTRIGGER
place_item_key : Space
place_item_mbutton : Middle
place_item_cbutton : A
move_up_key1 : w
move_up_key2 : up
move_up_controller_axis : left_y_positiv
move_down_key1 : s
move_down_key2 : down
move_down_controller_axis : left_y_negativ
move_left_key1 : a
move_left_key2 : left
move_left_controller_axis : left_x_positiv
move_right_key1 : d
move_right_key2 : right
move_right_controller_axis : left_x_negativ
beam_normal_mouse_button : left
beam_normal_controller_axis : trigger_left
beam_inverse_mouse_button : right
beam_inverse_controller_axis : trigger_right
place_item_key1 : Space
place_item_mouse_button : Middle
place_item_controller_button : A
test_key1 : t
test_key2 : h
test_mouse_button : middel
test_controller_button : back
test_controller_axis : right_y_positiv
exit_key1 : f12
exit_controller_button : home
state_switch_key : Escape
state_switch_cbutton : START
state_switch_controller_button : START
......@@ -32,18 +32,6 @@ namespace gdw{
bool active = false;
};
//if you add here, add also a mapping in makeMapping() in input.cpp
enum class inputMapping {
input_test,
state_switch,
player_move_left,
player_move_right,
beam_normal,
beam_inverse,
place_item,
button_click
};
struct inputMappingStruct {
unsigned int type = 0;
bool negativAxis = false;
......@@ -89,42 +77,43 @@ namespace gdw{
* should called once per game loop, at the end*/
void reset();
bool addMapping(std::string name);
void calcPosition(float delta);
/**Returns true every frame, as long as it is down - NOT FOR MULTI CONTROLLER*/
bool isPressed(inputMapping id);
bool isPressed(std::string id);
/**Returns true once it is pressed - NOT FOR MULTI CONTROLLER*/
bool isDown(inputMapping id);
bool isDown(std::string id);
/**Returns true once it is released - NOT FOR MULTI CONTROLLER*/
bool isReleased(inputMapping id);
bool isReleased(std::string id);
/**Returns true every frame, as long as the key is down.*/
private:
int isKeyDown(SDL_Keycode key);
int isKeyDown(inputMapping key);
int isKeyDown(std::string key);
/**Returns true once the key is pressed*/
bool isKeyPressed(SDL_Keycode key);
bool isKeyPressed(inputMapping key);
bool isKeyPressed(std::string key);
/**Returns true once the key is released*/
bool isKeyReleased(SDL_Keycode key);
bool isKeyReleased(inputMapping key);
bool isKeyReleased(std::string key);
/**Returns true every frame, as long as the mouse button is down.*/
bool isMouseButtonDown(int button);
bool isMouseButtonDown(inputMapping button);
bool isMouseButtonDown(std::string button);
/**Returns true once the mouse button is pressed*/
bool isMouseButtonPressed(int button);
bool isMouseButtonPressed(inputMapping button);
bool isMouseButtonPressed(std::string button);
/**Returns true once the mouse button is released*/
bool isMouseButtonReleased(int button);
bool isMouseButtonReleased(inputMapping button);
bool isMouseButtonReleased(std::string button);
public:
/**Returns a glm::vec2 with the x and y motion of the mouse wheel
......@@ -150,25 +139,25 @@ namespace gdw{
private:
bool isControllerButtonDown(SDL_GameControllerButton button, int nr = 0);
public:
bool isControllerButtonDown(inputMapping button, int nr = 0) noexcept {return isControllerButtonDown(getCButtonCodeByMapping(button), nr);};
bool isControllerButtonDown(std::string button, int nr = 0) noexcept {return isControllerButtonDown(getCButtonCodeByMapping(button), nr);};
/**Returns true once the controller button is pressed*/
private:
bool isControllerButtonPressed(SDL_GameControllerButton button, int nr = 0);
public:
bool isControllerButtonPressed(inputMapping button, int nr = 0) noexcept {return isControllerButtonPressed(getCButtonCodeByMapping(button), nr);};
bool isControllerButtonPressed(std::string button, int nr = 0) noexcept {return isControllerButtonPressed(getCButtonCodeByMapping(button), nr);};
/**Returns true once the controller button is released*/
private:
bool isControllerButtonReleased(SDL_GameControllerButton button, int nr = 0);
public:
bool isControllerButtonReleased(inputMapping button, int nr = 0) noexcept {return isControllerButtonReleased(getCButtonCodeByMapping(button), nr);};
bool isControllerButtonReleased(std::string button, int nr = 0) noexcept {return isControllerButtonReleased(getCButtonCodeByMapping(button), nr);};
/**Returns the value of that axis as a float between -1 and 1*/
private:
float controllerAxis(SDL_GameControllerAxis axis, int nr = 0);
public:
float controllerAxis(inputMapping axis, int nr = 0) noexcept {return controllerAxis(getCAxisCodeByMapping(axis), nr);};
float controllerAxis(std::string axis, int nr = 0) noexcept {return controllerAxis(getCAxisCodeByMapping(axis), nr);};
/**Returns number of aktiv controllers*/
int controllerCount() noexcept {return controllers_.size();};
......@@ -179,14 +168,12 @@ namespace gdw{
std::shared_ptr<const asset> controllerDB_;
std::unordered_map<int, controller> controllers_;
std::map<gdw::inputMapping, gdw::inputMappingStruct> mappings_;
void makeMappings();
bool isMappingOk(inputMappingStruct mapping, std::string name);
std::map<std::string, gdw::inputMappingStruct> mappings_;
SDL_Keycode getKeyCodeByMapping(inputMapping id, int nr);
int getMButtonCodeByMapping(inputMapping id);
SDL_GameControllerButton getCButtonCodeByMapping(inputMapping id);
SDL_GameControllerAxis getCAxisCodeByMapping(inputMapping id);
SDL_Keycode getKeyCodeByMapping(std::string id, int nr);
int getMButtonCodeByMapping(std::string id);
SDL_GameControllerButton getCButtonCodeByMapping(std::string id);
SDL_GameControllerAxis getCAxisCodeByMapping(std::string id);
int getMButtonFromName(std::string name);
SDL_Keycode getKeyFromName(std::string name);
......
......@@ -43,13 +43,13 @@ namespace gdw {
}
void AudioEventHandler::playStateUpdate(float deltaTime) {
if ((this->engine.input().isPressed(inputMapping::player_move_left) || this->engine.input().isPressed(inputMapping::player_move_right)) && !this->playerMoving) {
if ((this->engine.input().isPressed("move_left") || this->engine.input().isPressed("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().isDown(inputMapping::player_move_left) && !this->engine.input().isDown(inputMapping::player_move_right) && this->playerMoving) {
if (!this->engine.input().isDown("move_left") && !this->engine.input().isDown("move_right") && this->playerMoving) {
this->engine.audio().stop_sound(this->channels["ship"], 800);
this->playerMoving = false;
......
......@@ -47,6 +47,8 @@ namespace gdw {
rendering_system_ = make_unique<gdw::rendering_system>(*this);
ui_system_ = make_unique<gdw::ui_system>(*this);
game_state_machine_ = make_unique<gdw::game_state_machine>(*this);
input_->addMapping("state_switch");
}
engine::~engine() noexcept {
......
......@@ -48,14 +48,14 @@ namespace gdw {
}
void credits_state::update(float dt) {
if (this->engine_.input().isPressed(inputMapping::state_switch))
if (this->engine_.input().isPressed("state_switch"))
this->engine_.game_state_machine().change_state<menu_state>();
if (this->rootElement->y_px() <= (this->rootElement->height_px() + this->engine_.graphics_system().height()) * -1) {
this->rootElement->y(this->uiManager->getElementById("credits")->height());
this->topMargin = 0.5f/100*5;
}
double scrollAmount = this->engine_.input().isDown(inputMapping::beam_normal) ? 0.005 : 0.001;
scrollAmount = this->engine_.input().isDown(inputMapping::beam_inverse) ? 0.010 : scrollAmount;
double scrollAmount = this->engine_.input().isDown("beam_normal") ? 0.005 : 0.001;
scrollAmount = this->engine_.input().isDown("beam_inverse") ? 0.010 : scrollAmount;
this->rootElement->y(this->rootElement->y() - scrollAmount);
}
......
......@@ -71,7 +71,7 @@ void play_state::update(float dt) {
engine_.game_play_system().update(dt);
this->engine_.audioEventHandler().playStateUpdate(dt);
if (this->engine_.input().isPressed(inputMapping::state_switch))
if (this->engine_.input().isPressed("state_switch"))
this->engine_.game_state_machine().change_state<menu_state>();
}
......
......@@ -40,6 +40,7 @@ namespace gdw {
glm::vec3 game_input_manager::get_world_mouse_pos() {
auto& input = engine_.input();
input.addMapping("test");
auto& level_manager = engine_.game_play_system().level_manager();
float x = (input.mousePos().x/engine_.graphics_system().width()) * 2.0f -1;
......@@ -78,19 +79,19 @@ namespace gdw {
constexpr float rotation_speed = 7.f;
constexpr float turn_rate_modifier = 4.5f;
/*if (input.isPressed(inputMapping::input_test)){
log << "input_test pressed" << std::endl;
if (input.isPressed("test")){
log << "input test pressed" << std::endl;
}
if (input.isDown(inputMapping::input_test)){
log << "input_test down" << std::endl;
if (input.isDown("test")){
log << "input test down" << std::endl;
}
if (input.isReleased(inputMapping::input_test)){
log << "input_test released" << std::endl;
}*/
if (input.isReleased("test")){
log << "input test released" << std::endl;
}
if (input.isDown(inputMapping::player_move_left) && player->position().x > -maximum_movement_distance) {
if (input.isDown("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);
......@@ -103,7 +104,7 @@ namespace gdw {
move->add_angular_force(glm::vec3(0.f, -rotation_speed*(std::pow(diff, 1.4f)) , 0.f));
}
if (engine_.input().isDown(inputMapping::player_move_right) && player->position().x < maximum_movement_distance) {
if (engine_.input().isDown("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);
......@@ -117,7 +118,7 @@ namespace gdw {
}
// SET ITEM WITH SPACE KEY
if (input.isDown(inputMapping::place_item)) {
if (input.isDown("place_item")) {
engine_.game_play_system().player_item_manager().place_item(get_world_mouse_pos());
}
}
......@@ -138,24 +139,24 @@ namespace gdw {
level_manager.set_weapon(weapon_type::portal_gun);
}
if(input.isPressed(inputMapping::beam_normal)) {
if(input.isPressed("beam_normal")) {
engine_.audioEventHandler().trigger(AudioEventHandler::TRAKTORBEAM_REVERSE_ACTIVATED);
}
if(input.isReleased(inputMapping::beam_normal)) {
if(input.isReleased("beam_normal")) {
engine_.audioEventHandler().trigger(AudioEventHandler::TRAKTORBEAM_REVERSE_DEACTIVATED);
}
if(input.isPressed(inputMapping::beam_inverse)) {
if(input.isPressed("beam_inverse")) {
engine_.audioEventHandler().trigger(AudioEventHandler::TRAKTORBEAM_ACTIVATED);
}
if(input.isReleased(inputMapping::beam_inverse)) {
if(input.isReleased("beam_inverse")) {
engine_.audioEventHandler().trigger(AudioEventHandler::TRAKTORBEAM_DEACTIVATED);
}
//LEFT && RIGHT CLICK
switch(level_manager.weapon()) {
case weapon_type::tractor_beam: {
if(input.isDown(inputMapping::beam_normal) || input.isDown(inputMapping::beam_inverse)) {
if(input.isDown("beam_normal") || input.isDown("beam_inverse")) {
auto intersection_point = get_world_mouse_pos();
auto cannon = level_manager.cannon();
......@@ -168,7 +169,7 @@ namespace gdw {
ray r(cannon_pos + offset, intersection_point);
auto ray_unnormalized = glm::vec3(1.f);
if (input.isDown(inputMapping::beam_normal)) {
if (input.isDown("beam_normal")) {
ray_unnormalized = r.source - r.destination;
} else {
ray_unnormalized = r.destination - r.source;
......@@ -184,7 +185,7 @@ namespace gdw {
process_beam_collision(r, ray_unnormalized, beam_velocity, ray_length_, asteroid_hit, portal_type, remaining_length);
if (input.isDown(inputMapping::beam_normal)) {
if (input.isDown("beam_normal")) {
auto ray_length = (std::abs(ray_length_ - 0.f) < 0.001f)? glm::length(ray_unnormalized): ray_length_;
render_ray(&r, offset, ray_length, 0.18f, false, glm::vec3(0.5f, 0.6f, 0.9f));
} else {
......@@ -200,7 +201,7 @@ namespace gdw {
portal_type = -1;
ray_length_ = remaining_length;
process_beam_collision(r2, ray_unnormalized, beam_velocity, ray_length_, asteroid_hit, portal_type, remaining_length);
if (input.isDown(inputMapping::beam_normal)) {
if (input.isDown("beam_normal")) {
render_ray(&r2, offset, remaining_length, 0.18f, false, glm::vec3(0,0,1));
} else {
render_ray(&r2, offset, remaining_length, 0.18f, true, glm::vec3(1,0,0));
......@@ -215,7 +216,7 @@ namespace gdw {
portal_type = -1;
ray_length_ = remaining_length;
process_beam_collision(r2, ray_unnormalized, beam_velocity, ray_length_, asteroid_hit, portal_type, remaining_length);
if (input.isDown(inputMapping::beam_normal)) {
if (input.isDown("beam_normal")) {
render_ray(&r2, offset, remaining_length, 0.18f, false, glm::vec3(0,0,1));
} else {
render_ray(&r2, offset, remaining_length, 0.18f, true, glm::vec3(1,0,0));
......@@ -230,13 +231,13 @@ namespace gdw {
break;
}
case weapon_type::portal_gun: {
if(input.isDown(inputMapping::beam_normal) || input.isDown(inputMapping::beam_inverse)) {
if(input.isDown("beam_normal") || input.isDown("beam_inverse")) {
auto intersection_point = get_world_mouse_pos();
if(input.isDown(inputMapping::beam_normal))
if(input.isDown("beam_normal"))
level_manager.create_blue_portal(intersection_point);
if(input.isDown(inputMapping::beam_inverse))
if(input.isDown("beam_inverse"))
level_manager.create_yellow_portal(intersection_point);
}
break;
......
......@@ -10,7 +10,6 @@ namespace gdw{
controllers_(),mappings_(){
keyState_ = SDL_GetKeyboardState(NULL);
controllerDB_ = engine.asset_manager().load(engine.asset_manager().native_name(controllerDBPath_));
makeMappings();
ccursor = getCCursorFromName(engine_.getConfig().get<std::string>("controller_cursor","RIGHT"));
controllerUse = engine_.getConfig().get<bool>("use_controller",false);
......@@ -20,120 +19,50 @@ namespace gdw{
//SDL_SetCursor(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR));
if(controllerUse)SDL_ShowCursor(SDL_FALSE);
}
/** if you add here, add also in enum inputMapping 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)
* caxis only supports isDown
* if the axis should be true with negativ value than set 'negativAxis' to true (trigger can't become negativ)
*
* DON'T MISS TO ADD THE RIGHT TYPES ( key1 | mbutton | cbutton | caxis )!
* CAXIS DON'T TRIGGER 'PRESSED' OR 'RELEASED' IT ONLY TRIGGERS 'DOWN'!
*/
void input::makeMappings(){
inputMappingStruct state_switch_;
state_switch_.type = key1 + cbutton;
state_switch_.keyCode1 = getKeyFromName(
engine_.getConfig().get<std::string>("state_switch_key","Escape"));
state_switch_.cbuttonCode = getCButtonFromName(
engine_.getConfig().get<std::string>("state_switch_cbutton","START"));
isMappingOk(state_switch_, "state_switch");
mappings_.emplace(inputMapping::state_switch, state_switch_);
inputMappingStruct input_test_;
input_test_.type = key1 + key2 + mbutton + cbutton + caxis;
input_test_.keyCode1 = getKeyFromName(
engine_.getConfig().get<std::string>("input_test_key","O"));
input_test_.keyCode2 = getKeyFromName(
engine_.getConfig().get<std::string>("input_test_key","P"));
input_test_.cbuttonCode = getCButtonFromName(
engine_.getConfig().get<std::string>("input_test_cbutton","BACK"));
input_test_.mbuttonCode = getMButtonFromName(
engine_.getConfig().get<std::string>("input_test_mbutton","Middle"));
input_test_.caxisCode = getCAxisFromName(
engine_.getConfig().get<std::string>("input_test_caxis","TRIGGERLEFT"));
isMappingOk(input_test_, "input_test");
mappings_.emplace(inputMapping::input_test, input_test_);
inputMappingStruct player_move_left_;
player_move_left_.type = key1 + key2 + cbutton + caxis;
player_move_left_.keyCode1 = getKeyFromName(
engine_.getConfig().get<std::string>("player_move_left_key","A"));
player_move_left_.keyCode2 = getKeyFromName(
engine_.getConfig().get<std::string>("player_move_left_key2","A"));
player_move_left_.cbuttonCode = getCButtonFromName(
engine_.getConfig().get<std::string>("player_move_left_cbutton","LEFT"));
player_move_left_.caxisCode = getCAxisFromName(
engine_.getConfig().get<std::string>("player_move_left_caxis","RIGHTX"));
player_move_left_.negativAxis = true;
isMappingOk(player_move_left_, "player_move_left");
mappings_.emplace(inputMapping::player_move_left, player_move_left_);
inputMappingStruct player_move_right_;
player_move_right_.type = key1 + key2 + cbutton + caxis;
player_move_right_.keyCode1 = getKeyFromName(
engine_.getConfig().get<std::string>("player_move_right_key","D"));
player_move_right_.keyCode2 = getKeyFromName(
engine_.getConfig().get<std::string>("player_move_right_key2","A"));
player_move_right_.cbuttonCode = getCButtonFromName(
engine_.getConfig().get<std::string>("player_move_right_cbutton","RIGHT"));
player_move_right_.caxisCode = getCAxisFromName(
engine_.getConfig().get<std::string>("player_move_right_caxis","RIGHTX"));
isMappingOk(player_move_right_, "player_move_right");
mappings_.emplace(inputMapping::player_move_right, player_move_right_);
inputMappingStruct place_item_;
place_item_.type = key1 + mbutton + cbutton;
place_item_.keyCode1 = getKeyFromName(
engine_.getConfig().get<std::string>("place_item_key","Space"));
place_item_.mbuttonCode = getMButtonFromName(
engine_.getConfig().get<std::string>("place_item_mbutton","Middle"));
place_item_.cbuttonCode = getCButtonFromName(
engine_.getConfig().get<std::string>("place_item_cbutton","A"));
isMappingOk(place_item_, "place_item");
mappings_.emplace(inputMapping::place_item, place_item_);
inputMappingStruct beam_normal_;
beam_normal_.type = key1 + mbutton + caxis;
beam_normal_.mbuttonCode = getMButtonFromName(
engine_.getConfig().get<std::string>("beam_normal_mouse","Left"));
beam_normal_.keyCode1 = getKeyFromName(
engine_.getConfig().get<std::string>("beam_normal_key","Q"));
beam_normal_.caxisCode = getCAxisFromName(
engine_.getConfig().get<std::string>("beam_normal_caxis","LEFTTRIGGER"));
isMappingOk(beam_normal_, "beam_normal");
mappings_.emplace(inputMapping::beam_normal, beam_normal_);
inputMappingStruct button_click_;
button_click_.type = mbutton ;
button_click_.mbuttonCode = getMButtonFromName(
engine_.getConfig().get<std::string>("button_click_mouse","Left"));
isMappingOk(button_click_, "button_click");
mappings_.emplace(inputMapping::button_click, button_click_);
inputMappingStruct beam_inverse_;
beam_inverse_.type = key1 + mbutton + caxis;
beam_inverse_.mbuttonCode = getMButtonFromName(
engine_.getConfig().get<std::string>("beam_inverse_mouse","Right"));
beam_inverse_.keyCode1 = getKeyFromName(
engine_.getConfig().get<std::string>("beam_inverse_key","E"));
beam_inverse_.caxisCode = getCAxisFromName(
engine_.getConfig().get<std::string>("beam_inverse_caxis","RIGHTTRIGGER"));
isMappingOk(beam_inverse_, "beam_inverse");
mappings_.emplace(inputMapping::beam_inverse, beam_inverse_);
addMapping("move_left");
addMapping("move_right");
addMapping("place_item");
addMapping("beam_normal");
addMapping("beam_inverse");
addMapping("button_click");
}
bool input::addMapping(std::string name){
bool ok = false;
inputMappingStruct ims;
std::string s = engine_.getConfig().get<std::string>(name + "_key1","none");
if(s != "none"){
ims.keyCode1 = getKeyFromName(s);
ims.type += key1;
ok = true;
}
s = engine_.getConfig().get<std::string>(name + "_key2","none");
if(s != "none"){
ims.keyCode2 = getKeyFromName(s);
ims.type += key2;
ok = true;
}
s = engine_.getConfig().get<std::string>(name + "_mouse_button","none");
if(s != "none"){
ims.mbuttonCode = getMButtonFromName(s);
ims.type += mbutton;
ok = true;
}
s = engine_.getConfig().get<std::string>(name + "_controller_button","none");
if(s != "none"){
ims.cbuttonCode = getCButtonFromName(s);
ims.type += cbutton;
ok = true;
}
s = engine_.getConfig().get<std::string>(name + "_controller_axis","none");
if(s != "none"){
ims.caxisCode = getCAxisFromName(s);
ims.type += caxis;
ok = true;
}
mappings_.emplace(name, ims);
return ok;
}
input::~input(){}
......@@ -340,7 +269,7 @@ namespace gdw{
}
//MAPPING
int input::getKeyCodeByMapping(inputMapping id, int nr){
int input::getKeyCodeByMapping(std::string id, int nr){
auto it = mappings_.find(id);
if(nr == 1){
return (mappings_.at(it->first).type & key1) !=0? mappings_.at(it->first).keyCode1 : 0;
......@@ -350,17 +279,17 @@ namespace gdw{
return 0;
}
int input::getMButtonCodeByMapping(inputMapping id){
int input::getMButtonCodeByMapping(std::string id){
auto it = mappings_.find(id);
return (mappings_.at(it->first).type & mbutton) !=0? mappings_.at(it->first).mbuttonCode : -1;
}
SDL_GameControllerButton input::getCButtonCodeByMapping(inputMapping id){
SDL_GameControllerButton input::getCButtonCodeByMapping(std::string id){
auto it = mappings_.find(id);
return (mappings_.at(it->first).type & cbutton) !=0? mappings_.at(it->first).cbuttonCode : SDL_CONTROLLER_BUTTON_INVALID;
}
SDL_GameControllerAxis input::getCAxisCodeByMapping(inputMapping id){
SDL_GameControllerAxis input::getCAxisCodeByMapping(std::string id){
auto it = mappings_.find(id);
return (mappings_.at(it->first).type & caxis) !=0? mappings_.at(it->first).caxisCode : SDL_CONTROLLER_AXIS_INVALID;
}
......@@ -412,7 +341,7 @@ namespace gdw{
}
//RETURN
bool input::isPressed(inputMapping id){
bool input::isPressed(std::string id){
auto it = mappings_.find(id);
if((mappings_.at(it->first).type & key1) != 0){
if(isKeyPressed(mappings_.at(it->first).keyCode1)){
......@@ -448,7 +377,7 @@ namespace gdw{
return false;
}
bool input::isDown(inputMapping id){
bool input::isDown(std::string id){
auto it = mappings_.find(id);
if((mappings_.at(it->first).type & key1) != 0){
if(isKeyDown(mappings_.at(it->first).keyCode1)){
......@@ -484,7 +413,7 @@ namespace gdw{
return false;
}
bool input::isReleased(inputMapping id){
bool input::isReleased(std::string id){
auto it = mappings_.find(id);
if((mappings_.at(it->first).type & key1) != 0){
if(isKeyReleased(mappings_.at(it->first).keyCode1)){
......@@ -524,7 +453,7 @@ namespace gdw{
return keyState_[SDL_GetScancodeFromKey(key)];
}
int input::isKeyDown(inputMapping key){
int input::isKeyDown(std::string key){
return isKeyDown(getKeyCodeByMapping(key, 1)) || isKeyDown(getKeyCodeByMapping(key, 2));
}