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 ...@@ -17,22 +17,31 @@ victim_mass : 1
map_load_timer : 0 map_load_timer : 0
test_ui : false test_ui : false
mapGenDebug : false mapGenDebug : false
player_move_left_key : A move_up_key1 : w
player_move_left_key2 : Left move_up_key2 : up
player_move_left_cbutton : LEFT move_up_controller_axis : left_y_positiv
player_move_left_caxis : RIGHTX move_down_key1 : s
player_move_right_key : D move_down_key2 : down
player_move_right_key2 : Right move_down_controller_axis : left_y_negativ
player_move_right_cbutton : RIGHT move_left_key1 : a
player_move_right_caxis : RIGHTX move_left_key2 : left
beam_normal_key : Q move_left_controller_axis : left_x_positiv
beam_normal_mbutton : Left move_right_key1 : d
beam_normal_caxis : LEFTTRIGGER move_right_key2 : right
beam_inverse_key : E move_right_controller_axis : left_x_negativ
beam_inverse_mbutton : Right beam_normal_mouse_button : left
beam_inverse_caxis : RIGHTTRIGGER beam_normal_controller_axis : trigger_left
place_item_key : Space beam_inverse_mouse_button : right
place_item_mbutton : Middle beam_inverse_controller_axis : trigger_right
place_item_cbutton : A 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_key : Escape
state_switch_cbutton : START state_switch_controller_button : START
...@@ -32,18 +32,6 @@ namespace gdw{ ...@@ -32,18 +32,6 @@ namespace gdw{
bool active = false; 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 { struct inputMappingStruct {
unsigned int type = 0; unsigned int type = 0;
bool negativAxis = false; bool negativAxis = false;
...@@ -89,42 +77,43 @@ namespace gdw{ ...@@ -89,42 +77,43 @@ namespace gdw{
* should called once per game loop, at the end*/ * should called once per game loop, at the end*/
void reset(); void reset();
bool addMapping(std::string name);
void calcPosition(float delta); void calcPosition(float delta);
/**Returns true every frame, as long as it is down - NOT FOR MULTI CONTROLLER*/ /**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*/ /**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*/ /**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.*/ /**Returns true every frame, as long as the key is down.*/
private: private:
int isKeyDown(SDL_Keycode key); int isKeyDown(SDL_Keycode key);
int isKeyDown(inputMapping key); int isKeyDown(std::string key);
/**Returns true once the key is pressed*/ /**Returns true once the key is pressed*/
bool isKeyPressed(SDL_Keycode key); bool isKeyPressed(SDL_Keycode key);
bool isKeyPressed(inputMapping key); bool isKeyPressed(std::string key);
/**Returns true once the key is released*/ /**Returns true once the key is released*/
bool isKeyReleased(SDL_Keycode key); 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.*/ /**Returns true every frame, as long as the mouse button is down.*/
bool isMouseButtonDown(int button); bool isMouseButtonDown(int button);
bool isMouseButtonDown(inputMapping button); bool isMouseButtonDown(std::string button);
/**Returns true once the mouse button is pressed*/ /**Returns true once the mouse button is pressed*/
bool isMouseButtonPressed(int button); bool isMouseButtonPressed(int button);
bool isMouseButtonPressed(inputMapping button); bool isMouseButtonPressed(std::string button);
/**Returns true once the mouse button is released*/ /**Returns true once the mouse button is released*/
bool isMouseButtonReleased(int button); bool isMouseButtonReleased(int button);
bool isMouseButtonReleased(inputMapping button); bool isMouseButtonReleased(std::string button);
public: public:
/**Returns a glm::vec2 with the x and y motion of the mouse wheel /**Returns a glm::vec2 with the x and y motion of the mouse wheel
...@@ -150,25 +139,25 @@ namespace gdw{ ...@@ -150,25 +139,25 @@ namespace gdw{
private: private:
bool isControllerButtonDown(SDL_GameControllerButton button, int nr = 0); bool isControllerButtonDown(SDL_GameControllerButton button, int nr = 0);
public: 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*/ /**Returns true once the controller button is pressed*/
private: private:
bool isControllerButtonPressed(SDL_GameControllerButton button, int nr = 0); bool isControllerButtonPressed(SDL_GameControllerButton button, int nr = 0);
public: 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*/ /**Returns true once the controller button is released*/
private: private:
bool isControllerButtonReleased(SDL_GameControllerButton button, int nr = 0); bool isControllerButtonReleased(SDL_GameControllerButton button, int nr = 0);
public: 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*/ /**Returns the value of that axis as a float between -1 and 1*/
private: private:
float controllerAxis(SDL_GameControllerAxis axis, int nr = 0); float controllerAxis(SDL_GameControllerAxis axis, int nr = 0);
public: 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*/ /**Returns number of aktiv controllers*/
int controllerCount() noexcept {return controllers_.size();}; int controllerCount() noexcept {return controllers_.size();};
...@@ -179,14 +168,12 @@ namespace gdw{ ...@@ -179,14 +168,12 @@ namespace gdw{
std::shared_ptr<const asset> controllerDB_; std::shared_ptr<const asset> controllerDB_;
std::unordered_map<int, controller> controllers_; std::unordered_map<int, controller> controllers_;
std::map<gdw::inputMapping, gdw::inputMappingStruct> mappings_; std::map<std::string, gdw::inputMappingStruct> mappings_;
void makeMappings();
bool isMappingOk(inputMappingStruct mapping, std::string name);
SDL_Keycode getKeyCodeByMapping(inputMapping id, int nr); SDL_Keycode getKeyCodeByMapping(std::string id, int nr);
int getMButtonCodeByMapping(inputMapping id); int getMButtonCodeByMapping(std::string id);
SDL_GameControllerButton getCButtonCodeByMapping(inputMapping id); SDL_GameControllerButton getCButtonCodeByMapping(std::string id);
SDL_GameControllerAxis getCAxisCodeByMapping(inputMapping id); SDL_GameControllerAxis getCAxisCodeByMapping(std::string id);
int getMButtonFromName(std::string name); int getMButtonFromName(std::string name);
SDL_Keycode getKeyFromName(std::string name); SDL_Keycode getKeyFromName(std::string name);
......
...@@ -43,13 +43,13 @@ namespace gdw { ...@@ -43,13 +43,13 @@ namespace gdw {
} }
void AudioEventHandler::playStateUpdate(float deltaTime) { 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->channels["ship"] = this->engine.audio().queue_sound("engine", -1);
this->engine.audio().sound_volume(40, this->channels["ship"]); this->engine.audio().sound_volume(40, this->channels["ship"]);
this->playerMoving = true; 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->engine.audio().stop_sound(this->channels["ship"], 800);
this->playerMoving = false; this->playerMoving = false;
......
...@@ -47,6 +47,8 @@ namespace gdw { ...@@ -47,6 +47,8 @@ namespace gdw {
rendering_system_ = make_unique<gdw::rendering_system>(*this); rendering_system_ = make_unique<gdw::rendering_system>(*this);
ui_system_ = make_unique<gdw::ui_system>(*this); ui_system_ = make_unique<gdw::ui_system>(*this);
game_state_machine_ = make_unique<gdw::game_state_machine>(*this); game_state_machine_ = make_unique<gdw::game_state_machine>(*this);
input_->addMapping("state_switch");
} }
engine::~engine() noexcept { engine::~engine() noexcept {
...@@ -56,7 +58,7 @@ namespace gdw { ...@@ -56,7 +58,7 @@ namespace gdw {
void engine::update(float delta_time) { void engine::update(float delta_time) {
physics_system_->update(1.f/60.f); //Update fix 60 Hz physics_system_->update(1.f/60.f); //Update fix 60 Hz
game_state_machine_->update(delta_time); game_state_machine_->update(delta_time);
graphics_system_->begin(); graphics_system_->begin();
rendering_system_->update(delta_time); rendering_system_->update(delta_time);
ui_system_->render(delta_time); ui_system_->render(delta_time);
......
...@@ -48,14 +48,14 @@ namespace gdw { ...@@ -48,14 +48,14 @@ namespace gdw {
} }
void credits_state::update(float dt) { 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>(); this->engine_.game_state_machine().change_state<menu_state>();
if (this->rootElement->y_px() <= (this->rootElement->height_px() + this->engine_.graphics_system().height()) * -1) { if (this->rootElement->y_px() <= (this->rootElement->height_px() + this->engine_.graphics_system().height()) * -1) {
this->rootElement->y(this->uiManager->getElementById("credits")->height()); this->rootElement->y(this->uiManager->getElementById("credits")->height());
this->topMargin = 0.5f/100*5; this->topMargin = 0.5f/100*5;
} }
double scrollAmount = this->engine_.input().isDown(inputMapping::beam_normal) ? 0.005 : 0.001; double scrollAmount = this->engine_.input().isDown("beam_normal") ? 0.005 : 0.001;
scrollAmount = this->engine_.input().isDown(inputMapping::beam_inverse) ? 0.010 : scrollAmount; scrollAmount = this->engine_.input().isDown("beam_inverse") ? 0.010 : scrollAmount;
this->rootElement->y(this->rootElement->y() - scrollAmount); this->rootElement->y(this->rootElement->y() - scrollAmount);
} }
......
...@@ -71,7 +71,7 @@ void play_state::update(float dt) { ...@@ -71,7 +71,7 @@ void play_state::update(float dt) {
engine_.game_play_system().update(dt); engine_.game_play_system().update(dt);
this->engine_.audioEventHandler().playStateUpdate(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>(); this->engine_.game_state_machine().change_state<menu_state>();
} }
......
...@@ -40,6 +40,7 @@ namespace gdw { ...@@ -40,6 +40,7 @@ namespace gdw {
glm::vec3 game_input_manager::get_world_mouse_pos() { glm::vec3 game_input_manager::get_world_mouse_pos() {
auto& input = engine_.input(); auto& input = engine_.input();
input.addMapping("test");
auto& level_manager = engine_.game_play_system().level_manager(); auto& level_manager = engine_.game_play_system().level_manager();
float x = (input.mousePos().x/engine_.graphics_system().width()) * 2.0f -1; float x = (input.mousePos().x/engine_.graphics_system().width()) * 2.0f -1;
...@@ -78,19 +79,19 @@ namespace gdw { ...@@ -78,19 +79,19 @@ namespace gdw {
constexpr float rotation_speed = 7.f; constexpr float rotation_speed = 7.f;
constexpr float turn_rate_modifier = 4.5f; constexpr float turn_rate_modifier = 4.5f;
/*if (input.isPressed(inputMapping::input_test)){ if (input.isPressed("test")){
log << "input_test pressed" << std::endl; log << "input test pressed" << std::endl;
} }
if (input.isDown(inputMapping::input_test)){ if (input.isDown("test")){
log << "input_test down" << std::endl; log << "input test down" << std::endl;
} }
if (input.isReleased(inputMapping::input_test)){ if (input.isReleased("test")){
log << "input_test released" << std::endl; 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 orientation = player->rotation()*glm::vec3(0,0,1);
auto diff = std::abs(orientation.x - (-1.f)) + std::abs(orientation.z - (0.f)); 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); auto clamped = glm::clamp(diff/turn_rate_modifier, 0.f, 1.f);
...@@ -103,7 +104,7 @@ namespace gdw { ...@@ -103,7 +104,7 @@ namespace gdw {
move->add_angular_force(glm::vec3(0.f, -rotation_speed*(std::pow(diff, 1.4f)) , 0.f)); 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 orientation = player->rotation()*glm::vec3(0,0,1);
auto diff = std::abs(orientation.x - (1.f)) + std::abs(orientation.z - (0.f)); 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); auto clamped = glm::clamp(diff/turn_rate_modifier, 0.f, 1.f);
...@@ -117,7 +118,7 @@ namespace gdw { ...@@ -117,7 +118,7 @@ namespace gdw {
} }
// SET ITEM WITH SPACE KEY // 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()); engine_.game_play_system().player_item_manager().place_item(get_world_mouse_pos());
} }
} }
...@@ -138,24 +139,24 @@ namespace gdw { ...@@ -138,24 +139,24 @@ namespace gdw {
level_manager.set_weapon(weapon_type::portal_gun); 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); 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); engine_.audioEventHandler().trigger(AudioEventHandler::TRAKTORBEAM_REVERSE_DEACTIVATED);
} }
if(input.isPressed(inputMapping::beam_inverse)) { if(input.isPressed("beam_inverse")) {
engine_.audioEventHandler().trigger(AudioEventHandler::TRAKTORBEAM_ACTIVATED); engine_.audioEventHandler().trigger(AudioEventHandler::TRAKTORBEAM_ACTIVATED);
} }
if(input.isReleased(inputMapping::beam_inverse)) { if(input.isReleased("beam_inverse")) {
engine_.audioEventHandler().trigger(AudioEventHandler::TRAKTORBEAM_DEACTIVATED); engine_.audioEventHandler().trigger(AudioEventHandler::TRAKTORBEAM_DEACTIVATED);
} }
//LEFT && RIGHT CLICK //LEFT && RIGHT CLICK
switch(level_manager.weapon()) { switch(level_manager.weapon()) {
case weapon_type::tractor_beam: { 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 intersection_point = get_world_mouse_pos();
auto cannon = level_manager.cannon(); auto cannon = level_manager.cannon();
...@@ -168,7 +169,7 @@ namespace gdw { ...@@ -168,7 +169,7 @@ namespace gdw {
ray r(cannon_pos + offset, intersection_point); ray r(cannon_pos + offset, intersection_point);
auto ray_unnormalized = glm::vec3(1.f); auto ray_unnormalized = glm::vec3(1.f);
if (input.isDown(inputMapping::beam_normal)) { if (input.isDown("beam_normal")) {
ray_unnormalized = r.source - r.destination; ray_unnormalized = r.source - r.destination;
} else { } else {
ray_unnormalized = r.destination - r.source; ray_unnormalized = r.destination - r.source;
...@@ -184,7 +185,7 @@ namespace gdw { ...@@ -184,7 +185,7 @@ namespace gdw {
process_beam_collision(r, ray_unnormalized, beam_velocity, ray_length_, asteroid_hit, portal_type, remaining_length); 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_; 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)); render_ray(&r, offset, ray_length, 0.18f, false, glm::vec3(0.5f, 0.6f, 0.9f));
} else { } else {
...@@ -200,7 +201,7 @@ namespace gdw { ...@@ -200,7 +201,7 @@ namespace gdw {
portal_type = -1; portal_type = -1;
ray_length_ = remaining_length; ray_length_ = remaining_length;
process_beam_collision(r2, ray_unnormalized, beam_velocity, ray_length_, asteroid_hit, portal_type, 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)); render_ray(&r2, offset, remaining_length, 0.18f, false, glm::vec3(0,0,1));
} else { } else {
render_ray(&r2, offset, remaining_length, 0.18f, true, glm::vec3(1,0,0)); render_ray(&r2, offset, remaining_length, 0.18f, true, glm::vec3(1,0,0));
...@@ -215,7 +216,7 @@ namespace gdw { ...@@ -215,7 +216,7 @@ namespace gdw {
portal_type = -1; portal_type = -1;
ray_length_ = remaining_length; ray_length_ = remaining_length;
process_beam_collision(r2, ray_unnormalized, beam_velocity, ray_length_, asteroid_hit, portal_type, 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)); render_ray(&r2, offset, remaining_length, 0.18f, false, glm::vec3(0,0,1));
} else { } else {
render_ray(&r2, offset, remaining_length, 0.18f, true, glm::vec3(1,0,0)); render_ray(&r2, offset, remaining_length, 0.18f, true, glm::vec3(1,0,0));
...@@ -230,13 +231,13 @@ namespace gdw { ...@@ -230,13 +231,13 @@ namespace gdw {
break; break;
} }
case weapon_type::portal_gun: { 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(); 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); 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); level_manager.create_yellow_portal(intersection_point);
} }
break; break;
......
...@@ -10,7 +10,6 @@ namespace gdw{ ...@@ -10,7 +10,6 @@ namespace gdw{
controllers_(),mappings_(){ controllers_(),mappings_(){
keyState_ = SDL_GetKeyboardState(NULL); keyState_ = SDL_GetKeyboardState(NULL);
controllerDB_ = engine.asset_manager().load(engine.asset_manager().native_name(controllerDBPath_)); controllerDB_ = engine.asset_manager().load(engine.asset_manager().native_name(controllerDBPath_));
makeMappings();
ccursor = getCCursorFromName(engine_.getConfig().get<std::string>("controller_cursor","RIGHT")); ccursor = getCCursorFromName(engine_.getConfig().get<std::string>("controller_cursor","RIGHT"));
controllerUse = engine_.getConfig().get<bool>("use_controller",false); controllerUse = engine_.getConfig().get<bool>("use_controller",false);
...@@ -20,120 +19,50 @@ namespace gdw{ ...@@ -20,120 +19,50 @@ namespace gdw{
//SDL_SetCursor(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR)); //SDL_SetCursor(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR));
if(controllerUse)SDL_ShowCursor(SDL_FALSE); if(controllerUse)SDL_ShowCursor(SDL_FALSE);
}
/** if you add here, add also in enum inputMapping in input.hpp addMapping("move_left");
* addMapping("move_right");
* key names: http://wiki.libsdl.org/SDL_Keycode?highlight=%28%5CbCategoryEnum%5Cb%29%7C%28CategoryKeyboard%29 addMapping("place_item");
* getKeyFromName(std::string) addMapping("beam_normal");
* addMapping("beam_inverse");
* mouse button names: Left, Right, Middle, Mouse4, Mouse5 addMapping("button_click");
* getMButtonFromName(std::string) }
*
* controller button names: http://wiki.libsdl.org/SDL_GameControllerButton bool input::addMapping(std::string name){
* without 'SDL_CONTROLLER_BUTTON_' bool ok = false;
* except for dpad: dpad_up is 'up', dpad_down is 'down', dpad_left is 'left', dpad_right is 'right' inputMappingStruct ims;
* getCButtonFromName(std::string) std::string s = engine_.getConfig().get<std::string>(name + "_key1","none");
* if(s != "none"){
* controller axis names: http://wiki.libsdl.org/SDL_GameControllerAxis without 'SDL_CONTROLLER_AXIS_' ims.keyCode1 = getKeyFromName(s);
* getCAxisFromName(std::string) ims.type += key1;
* caxis only supports isDown ok = true;
* if the axis should be true with negativ value than set 'negativAxis' to true (trigger can't become negativ) }
* s = engine_.getConfig().get<std::string>(name + "_key2","none");
* DON'T MISS TO ADD THE RIGHT TYPES ( key1 | mbutton | cbutton | caxis )! if(s != "none"){
* CAXIS DON'T TRIGGER 'PRESSED' OR 'RELEASED' IT ONLY TRIGGERS 'DOWN'! ims.keyCode2 = getKeyFromName(s);
*/ ims.type += key2;
void input::makeMappings(){ ok = true;
inputMappingStruct state_switch_; }
state_switch_.type = key1 + cbutton; s = engine_.getConfig().get<std::string>(name + "_mouse_button","none");
state_switch_.keyCode1 = getKeyFromName( if(s != "none"){
engine_.getConfig().get<std::string>("state_switch_key","Escape")); ims.mbuttonCode = getMButtonFromName(s);
state_switch_.cbuttonCode = getCButtonFromName( ims.type += mbutton;
engine_.getConfig().get<std::string>("state_switch_cbutton","START")); ok = true;
isMappingOk(state_switch_, "state_switch"); }
mappings_.emplace(inputMapping::state_switch, state_switch_); s = engine_.getConfig().get<std::string>(name + "_controller_button","none");
if(s != "none"){