Commit 6ff9f1ef authored by Benjamin 'Albsi' Albsmeier's avatar Benjamin 'Albsi' Albsmeier
Browse files

made the new nice input mapping save

parent bb5a281f
...@@ -38,15 +38,15 @@ namespace gdw { ...@@ -38,15 +38,15 @@ namespace gdw {
throw std::runtime_error("could not initialize SDL" + sdl_error); throw std::runtime_error("could not initialize SDL" + sdl_error);
} }
input_ = make_unique<gdw::input>(*this);
game_play_system_ = make_unique<gdw::game_play_system>(*this); game_play_system_ = make_unique<gdw::game_play_system>(*this);
physics_system_ = make_unique<gdw::physics_system>(*this); physics_system_ = make_unique<gdw::physics_system>(*this);
audio_ = make_unique<gdw::audio>(*this); audio_ = make_unique<gdw::audio>(*this);
audioEventHandler_ = make_unique<gdw::AudioEventHandler>(*this); audioEventHandler_ = make_unique<gdw::AudioEventHandler>(*this);
graphics_system_ = make_unique<gdw::graphics_system>(*this); graphics_system_ = make_unique<gdw::graphics_system>(*this);
input_ = make_unique<gdw::input>(*this);
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"); input_->addMapping("state_switch");
} }
......
...@@ -27,6 +27,13 @@ namespace gdw { ...@@ -27,6 +27,13 @@ namespace gdw {
const float game_input_manager::maximum_movement_distance = 13.0f; const float game_input_manager::maximum_movement_distance = 13.0f;
game_input_manager::game_input_manager(engine& engine):engine_(engine) { game_input_manager::game_input_manager(engine& engine):engine_(engine) {
auto& input = engine_.input();
//input.addMapping("test");
input.addMapping("move_left");
input.addMapping("move_right");
input.addMapping("place_item");
input.addMapping("beam_normal");
input.addMapping("beam_inverse");
} }
game_input_manager::~game_input_manager() { game_input_manager::~game_input_manager() {
...@@ -40,7 +47,6 @@ namespace gdw { ...@@ -40,7 +47,6 @@ 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;
...@@ -79,7 +85,7 @@ namespace gdw { ...@@ -79,7 +85,7 @@ 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("test")){ /*if (input.isPressed("test")){
log << "input test pressed" << std::endl; log << "input test pressed" << std::endl;
} }
...@@ -89,7 +95,7 @@ namespace gdw { ...@@ -89,7 +95,7 @@ namespace gdw {
if (input.isReleased("test")){ if (input.isReleased("test")){
log << "input test released" << std::endl; log << "input test released" << std::endl;
} }*/
if (input.isDown("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);
......
...@@ -19,50 +19,6 @@ namespace gdw{ ...@@ -19,50 +19,6 @@ 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);
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(){} input::~input(){}
...@@ -269,8 +225,46 @@ namespace gdw{ ...@@ -269,8 +225,46 @@ namespace gdw{
} }
//MAPPING //MAPPING
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;
}
int input::getKeyCodeByMapping(std::string id, int nr){ int input::getKeyCodeByMapping(std::string id, int nr){
auto it = mappings_.find(id); auto it = mappings_.find(id);
if(it == mappings_.end())return 0;
if(nr == 1){ if(nr == 1){
return (mappings_.at(it->first).type & key1) !=0? mappings_.at(it->first).keyCode1 : 0; return (mappings_.at(it->first).type & key1) !=0? mappings_.at(it->first).keyCode1 : 0;
}else if(nr == 2){ }else if(nr == 2){
...@@ -281,16 +275,19 @@ namespace gdw{ ...@@ -281,16 +275,19 @@ namespace gdw{
int input::getMButtonCodeByMapping(std::string id){ int input::getMButtonCodeByMapping(std::string id){
auto it = mappings_.find(id); auto it = mappings_.find(id);
if(it == mappings_.end())return -1;
return (mappings_.at(it->first).type & mbutton) !=0? mappings_.at(it->first).mbuttonCode : -1; return (mappings_.at(it->first).type & mbutton) !=0? mappings_.at(it->first).mbuttonCode : -1;
} }
SDL_GameControllerButton input::getCButtonCodeByMapping(std::string id){ SDL_GameControllerButton input::getCButtonCodeByMapping(std::string id){
auto it = mappings_.find(id); auto it = mappings_.find(id);
if(it == mappings_.end())return SDL_CONTROLLER_BUTTON_INVALID;
return (mappings_.at(it->first).type & cbutton) !=0? mappings_.at(it->first).cbuttonCode : SDL_CONTROLLER_BUTTON_INVALID; return (mappings_.at(it->first).type & cbutton) !=0? mappings_.at(it->first).cbuttonCode : SDL_CONTROLLER_BUTTON_INVALID;
} }
SDL_GameControllerAxis input::getCAxisCodeByMapping(std::string id){ SDL_GameControllerAxis input::getCAxisCodeByMapping(std::string id){
auto it = mappings_.find(id); auto it = mappings_.find(id);
if(it == mappings_.end())return SDL_CONTROLLER_AXIS_INVALID;
return (mappings_.at(it->first).type & caxis) !=0? mappings_.at(it->first).caxisCode : SDL_CONTROLLER_AXIS_INVALID; return (mappings_.at(it->first).type & caxis) !=0? mappings_.at(it->first).caxisCode : SDL_CONTROLLER_AXIS_INVALID;
} }
...@@ -343,6 +340,7 @@ namespace gdw{ ...@@ -343,6 +340,7 @@ namespace gdw{
//RETURN //RETURN
bool input::isPressed(std::string id){ bool input::isPressed(std::string id){
auto it = mappings_.find(id); auto it = mappings_.find(id);
if(it == mappings_.end())return false;
if((mappings_.at(it->first).type & key1) != 0){ if((mappings_.at(it->first).type & key1) != 0){
if(isKeyPressed(mappings_.at(it->first).keyCode1)){ if(isKeyPressed(mappings_.at(it->first).keyCode1)){
return true; return true;
...@@ -379,6 +377,7 @@ namespace gdw{ ...@@ -379,6 +377,7 @@ namespace gdw{
bool input::isDown(std::string id){ bool input::isDown(std::string id){
auto it = mappings_.find(id); auto it = mappings_.find(id);
if(it == mappings_.end())return false;
if((mappings_.at(it->first).type & key1) != 0){ if((mappings_.at(it->first).type & key1) != 0){
if(isKeyDown(mappings_.at(it->first).keyCode1)){ if(isKeyDown(mappings_.at(it->first).keyCode1)){
return true; return true;
...@@ -415,6 +414,7 @@ namespace gdw{ ...@@ -415,6 +414,7 @@ namespace gdw{
bool input::isReleased(std::string id){ bool input::isReleased(std::string id){
auto it = mappings_.find(id); auto it = mappings_.find(id);
if(it == mappings_.end())return false;
if((mappings_.at(it->first).type & key1) != 0){ if((mappings_.at(it->first).type & key1) != 0){
if(isKeyReleased(mappings_.at(it->first).keyCode1)){ if(isKeyReleased(mappings_.at(it->first).keyCode1)){
return true; return true;
......
...@@ -43,6 +43,8 @@ namespace gdw { ...@@ -43,6 +43,8 @@ namespace gdw {
//NVGFrameBuffer_ = nvgluCreateFramebuffer( NVGContext_, engine_.graphics_system().width(), engine_.graphics_system().height(), 0); //NVGFrameBuffer_ = nvgluCreateFramebuffer( NVGContext_, engine_.graphics_system().width(), engine_.graphics_system().height(), 0);
width(engine_.graphics_system().width()); width(engine_.graphics_system().width());
height(engine_.graphics_system().height()); height(engine_.graphics_system().height());
engine_.input().addMapping("button_click");
} }
ui_system::~ui_system(){ ui_system::~ui_system(){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment