From ea0e70e07e377a62b9e059a6dcec268e22f3f8b2 Mon Sep 17 00:00:00 2001 From: Michael Moroz Date: Fri, 27 Sep 2019 14:49:39 +0300 Subject: [PATCH] Working keyboard mapping --- src/Gamemodes.cpp | 43 +++++++--------- src/Gamemodes.h | 8 +-- src/Interface.cpp | 128 ++++++++++++++++++++++++++++------------------ src/Interface.h | 27 ++++++++-- src/Main.cpp | 24 +++++++-- src/Settings.h | 2 +- 6 files changed, 144 insertions(+), 88 deletions(-) diff --git a/src/Gamemodes.cpp b/src/Gamemodes.cpp index 616000ba..64e6f95f 100644 --- a/src/Gamemodes.cpp +++ b/src/Gamemodes.cpp @@ -309,27 +309,27 @@ void OpenControlMenu(Scene * scene, Overlays * overlays) controls.AddObject(&Text(LOCAL["Keyboard Controls"], LOCAL("default"), 50), Object::Allign::LEFT); controls.AddObject(&Box(800, 0), Object::Allign::CENTER); - controls.AddObject(&KeyMapper(LOCAL["UP"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[UP], 1200.f, 50.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); - controls.AddObject(&KeyMapper(LOCAL["DOWN"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[DOWN], 1200.f, 50.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); - controls.AddObject(&KeyMapper(LOCAL["LEFT"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[LEFT], 1200.f, 50.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); - controls.AddObject(&KeyMapper(LOCAL["RIGHT"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[RIGHT], 1200.f, 50.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); - controls.AddObject(&KeyMapper(LOCAL["VIEWUP"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[VIEWUP], 1200.f, 50.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); - controls.AddObject(&KeyMapper(LOCAL["VIEWDOWN"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[VIEWDOWN], 1200.f, 50.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); - controls.AddObject(&KeyMapper(LOCAL["VIEWLEFT"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[VIEWLEFT], 1200.f, 50.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); - controls.AddObject(&KeyMapper(LOCAL["VIEWRIGHT"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[VIEWRIGHT], 1200.f, 50.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); - controls.AddObject(&KeyMapper(LOCAL["PAUSE"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[PAUSE], 1200.f, 50.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); - controls.AddObject(&KeyMapper(LOCAL["RESTART"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[RESTART], 1200.f, 50.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); - controls.AddObject(&KeyMapper(LOCAL["SCREENSHOT"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[SCREENSHOT], 1200.f, 50.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["UP"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[UP], 800.f, 35.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["DOWN"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[DOWN], 800.f, 35.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["LEFT"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[LEFT], 800.f, 35.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["RIGHT"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[RIGHT], 800.f, 35.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["VIEWUP"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[VIEWUP], 800.f, 35.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["VIEWDOWN"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[VIEWDOWN], 800.f, 35.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["VIEWLEFT"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[VIEWLEFT], 800.f, 35.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["VIEWRIGHT"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[VIEWRIGHT], 800.f, 35.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["PAUSE"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[PAUSE], 800.f, 35.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["RESTART"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[RESTART], 800.f, 35.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["SCREENSHOT"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[SCREENSHOT], 800.f, 35.f, KeyMapper::MapperType::KEYBOARD), Object::Allign::LEFT); controls.AddObject(&Box(800, 0), Object::Allign::CENTER); controls.AddObject(&Text(LOCAL["Gamepad Controls"], LOCAL("default"), 50), Object::Allign::LEFT); controls.AddObject(&Box(800, 0), Object::Allign::CENTER); - controls.AddObject(&KeyMapper(LOCAL["JOYSTICK_MOVE_AXIS_X"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[JOYSTICK_MOVE_AXIS_X], 1200.f, 50.f, KeyMapper::MapperType::JOYSTICK_AXIS), Object::Allign::LEFT); - controls.AddObject(&KeyMapper(LOCAL["JOYSTICK_MOVE_AXIS_Y"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[JOYSTICK_MOVE_AXIS_Y], 1200.f, 50.f, KeyMapper::MapperType::JOYSTICK_AXIS), Object::Allign::LEFT); - controls.AddObject(&KeyMapper(LOCAL["JOYSTICK_VIEW_AXIS_X"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[JOYSTICK_VIEW_AXIS_X], 1200.f, 50.f, KeyMapper::MapperType::JOYSTICK_AXIS), Object::Allign::LEFT); - controls.AddObject(&KeyMapper(LOCAL["JOYSTICK_VIEW_AXIS_Y"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[JOYSTICK_VIEW_AXIS_Y], 1200.f, 50.f, KeyMapper::MapperType::JOYSTICK_AXIS), Object::Allign::LEFT); - controls.AddObject(&KeyMapper(LOCAL["JOYSTICK_EXIT"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[JOYSTICK_EXIT], 1200.f, 50.f, KeyMapper::MapperType::JOYSTICK_KEYS), Object::Allign::LEFT); - controls.AddObject(&KeyMapper(LOCAL["JOYSTICK_SCREENSHOT"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[JOYSTICK_SCREENSHOT], 1200.f, 50.f, KeyMapper::MapperType::JOYSTICK_KEYS), Object::Allign::LEFT); - controls.AddObject(&KeyMapper(LOCAL["JOYSTICK_RESTART"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[JOYSTICK_RESTART], 1200.f, 50.f, KeyMapper::MapperType::JOYSTICK_KEYS), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["JOYSTICK_MOVE_AXIS_X"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[JOYSTICK_MOVE_AXIS_X], 800.f, 35.f, KeyMapper::MapperType::JOYSTICK_AXIS), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["JOYSTICK_MOVE_AXIS_Y"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[JOYSTICK_MOVE_AXIS_Y], 800.f, 35.f, KeyMapper::MapperType::JOYSTICK_AXIS), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["JOYSTICK_VIEW_AXIS_X"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[JOYSTICK_VIEW_AXIS_X], 800.f, 35.f, KeyMapper::MapperType::JOYSTICK_AXIS), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["JOYSTICK_VIEW_AXIS_Y"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[JOYSTICK_VIEW_AXIS_Y], 800.f, 35.f, KeyMapper::MapperType::JOYSTICK_AXIS), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["JOYSTICK_EXIT"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[JOYSTICK_EXIT], 800.f, 35.f, KeyMapper::MapperType::JOYSTICK_KEYS), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["JOYSTICK_SCREENSHOT"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[JOYSTICK_SCREENSHOT], 800.f, 35.f, KeyMapper::MapperType::JOYSTICK_KEYS), Object::Allign::LEFT); + controls.AddObject(&KeyMapper(LOCAL["JOYSTICK_RESTART"], LOCAL["Waiting for input"], &SETTINGS.stg.control_mapping[JOYSTICK_RESTART], 800.f, 35.f, KeyMapper::MapperType::JOYSTICK_KEYS), Object::Allign::LEFT); AddGlobalObject(controls); } @@ -1330,12 +1330,6 @@ void InitializeATBWindows(float* fps, float *target_fps) TwAddVarRW(overlays_ptr->settings, "Mouse sensitivity", TW_TYPE_FLOAT, &SETTINGS.stg.mouse_sensitivity, "min=0.001 max=0.02 step=0.001 group='Control settings'"); TwAddVarRW(overlays_ptr->settings, "Wheel sensitivity", TW_TYPE_FLOAT, &SETTINGS.stg.wheel_sensitivity, "min=0.01 max=0.5 step=0.01 group='Control settings'"); TwAddVarRW(overlays_ptr->settings, "Windows touch controls(experimental)", TW_TYPE_BOOLCPP, &SETTINGS.stg.touch_mode, "group='Control settings' help='Use a touchscreen'"); - TwAddVarRO(overlays_ptr->settings, "Status", TW_TYPE_STDSTRING, &status_text, " label='STATUS' group='Control settings' "); - - TwAddButton(overlays_ptr->settings, "AXIS_X_M", SetButton, &key[0], "group='Control settings' label='Joystick - choose X movement axis' "); - TwAddButton(overlays_ptr->settings, "AXIS_Y_M", SetButton, &key[1], "group='Control settings' label='Joystick - choose Y movement axis' "); - TwAddButton(overlays_ptr->settings, "AXIS_X_V", SetButton, &key[2], "group='Control settings' label='Joystick - choose X view axis' "); - TwAddButton(overlays_ptr->settings, "AXIS_Y_V", SetButton, &key[3], "group='Control settings' label='Joystick - choose Y view axis' "); TwAddButton(overlays_ptr->settings, "Apply4", ApplySettings, NULL, "group='Control settings' label='Apply settings' "); int barPos1[2] = { 16, 250 }; @@ -1414,6 +1408,7 @@ void InitializeATBWindows(float* fps, float *target_fps) TwAddVarRO(debug, "Replay frame", TW_TYPE_INT32, &cur_frame, ""); TwAddVarRO(debug, "Replay mode", TW_TYPE_BOOLCPP, &replay, ""); TwAddVarRO(debug, "Recording mode", TW_TYPE_BOOLCPP, &recording, ""); + TwDefine("Debug_bar visible=false color='0 0 255' alpha=240 size='420 160' valueswidth=200"); #endif TwDefine(" GLOBAL fontsize=3 "); diff --git a/src/Gamemodes.h b/src/Gamemodes.h index 69e99f0c..950cbb35 100644 --- a/src/Gamemodes.h +++ b/src/Gamemodes.h @@ -100,12 +100,6 @@ void ApplyButton(int NUM, int MODE); void InitializeATBWindows(float * fps, float * target_fps); -template < typename T > std::string num2str(const T& n) -{ - std::ostringstream stm; - if (n < 10) stm << "0"; - stm << n; - return stm.str(); -} + diff --git a/src/Interface.cpp b/src/Interface.cpp index 86bd1590..47f9a636 100644 --- a/src/Interface.cpp +++ b/src/Interface.cpp @@ -1238,6 +1238,8 @@ void KeyMapper::operator=(KeyMapper & A) Box::operator=(A); this_type = A.this_type; key_ptr = A.key_ptr; + waiting = A.waiting; + wait_text = A.wait_text; CreateCallbacks(); } @@ -1246,69 +1248,95 @@ void KeyMapper::operator=(KeyMapper && A) Box::operator=(A); std::swap(this_type, A.this_type); std::swap(key_ptr, A.key_ptr); + waiting = A.waiting; + wait_text = A.wait_text; CreateCallbacks(); } void KeyMapper::CreateCallbacks() { - /*//use lambda funtion - this->objects[1].get()->objects[0].get()->SetMainCallbackFunction([parent = this](sf::RenderWindow * window, InputState & state) + //use a lambda function + this->objects[1].get()->SetMainCallbackFunction([parent = this](sf::RenderWindow * window, InputState & state) { - float inside_size = parent->objects[0].get()->defaultstate.inside_size; - float height_1 = parent->objects[1].get()->defaultstate.size.y - 2 * parent->objects[1].get()->defaultstate.margin; - float height_2 = parent->objects[1].get()->objects[0].get()->defaultstate.size.y; - float max_slide_scroll = height_1 - height_2; - //relative scroll coefficient - float rel_coef = (inside_size - height_1) / max_slide_scroll; - parent->ScrollBy(state.mouse_speed.y*rel_coef); - }, false); - - this->SetMainHoverFunction([parent = this](sf::RenderWindow * window, InputState & state) - { - //wheel scroll - if (state.wheel != 0.f) - { - float ds = 20.f; - parent->ScrollBy(-state.wheel*ds); - } + parent->waiting = true; + //get the text pointer out of the object pointer inside the parent + Text *text_ptr = static_cast(parent->objects[1].get()->objects[0].get()); + text_ptr->SetString(parent->wait_text); }); + this->SetMainDefaultFunction([parent = this](sf::RenderWindow * window, InputState & state) { - bool A = false; - - if (state.keys[sf::Keyboard::Up]) - { - parent->Cursor(-1); - A = 1; - } - - if (state.keys[sf::Keyboard::Down]) - { - parent->Cursor(1); - A = 1; - } - - if (state.keys[sf::Keyboard::Enter]) + if (parent->waiting) { - //run the callback function of the chosen object - A = parent->objects[0].get()->objects[parent->cursor_id].get()->RunCallback(window, state); - } - - if (A) parent->action_time = action_dt; - - A = false; - - if (state.key_press[sf::Keyboard::Up]) - { - parent->action_time = action_dt / 4; + if (state.key_press[sf::Keyboard::Escape]) + { + parent->SetKeyString(); //exit + } + else switch (parent->this_type) + { + case KEYBOARD: + if (state.isKeyPressed) + { + //search for the pressed key + for (sf::Keyboard::Key i = sf::Keyboard::A; i < sf::Keyboard::KeyCount; i = sf::Keyboard::Key(i + 1)) + { + if (state.keys[i]) //found + { + *(parent->key_ptr) = i; + parent->SetKeyString(); + break; + } + } + } + break; + case JOYSTICK_AXIS: + //search for the axis + for (int i = 0; i < sf::Joystick::AxisCount; i++) + { + if (abs(sf::Joystick::getAxisPosition(0, sf::Joystick::Axis(i))) > 0.5f ) + { + *(parent->key_ptr) = i; + parent->SetKeyString(); + break; + } + } + break; + case JOYSTICK_KEYS: + //search for the pressed joystick key + for (int i = 0; i < sf::Joystick::ButtonCount; i++) + { + if (sf::Joystick::isButtonPressed(0, i)) + { + *(parent->key_ptr) = i; + parent->SetKeyString(); + break; + } + } + + break; + } } + }); +} - if (state.key_press[sf::Keyboard::Down]) - { - parent->action_time = action_dt / 4; - } - });*/ +void KeyMapper::SetKeyString() +{ + Text *text_ptr = static_cast(objects[1].get()->objects[0].get()); + waiting = false; + sf::Keyboard::Key key = sf::Keyboard::Key(*key_ptr); + switch (this_type) + { + case KEYBOARD: + text_ptr->SetString(key_name(key)); + break; + case JOYSTICK_AXIS: + text_ptr->SetString("Axis " + num2str(*key_ptr)); + break; + case JOYSTICK_KEYS: + text_ptr->SetString("Key " + num2str(*key_ptr)); + break; + } } Object * KeyMapper::GetCopy() diff --git a/src/Interface.h b/src/Interface.h index e84f9906..d75d617c 100644 --- a/src/Interface.h +++ b/src/Interface.h @@ -34,6 +34,13 @@ static const std::string priority_png = "images/priority.png"; static const std::string done_png = "images/done.png"; extern int focused; +template < typename T > std::string num2str(const T& n) +{ + std::ostringstream stm; + if (n < 10) stm << "0"; + stm << n; + return stm.str(); +} struct ColorFloat { @@ -54,6 +61,7 @@ ColorFloat ToColorF(sf::Color a); struct InputState { + bool isKeyPressed; bool keys[sf::Keyboard::KeyCount] = { false }; bool key_press[sf::Keyboard::KeyCount] = { false }; bool mouse[3] = { false }; @@ -324,6 +332,9 @@ class Text : public Object Text(Text& A); Text(Text&& A); + template + void SetString(T str); + void operator=(Text& A); void operator=(Text&& A); @@ -342,6 +353,12 @@ inline Text::Text(T str, sf::Font & f, float size, sf::Color col) clone_states(); } +template +inline void Text::SetString(T str) +{ + text.get()->setString(str); +} + //a button class Button: public Box @@ -410,25 +427,29 @@ class KeyMapper : public Box void operator=(KeyMapper&& A); void CreateCallbacks(); + void SetKeyString(); virtual Object* GetCopy(); MapperType this_type; int *key_ptr; + bool waiting; + std::wstring wait_text; }; template -inline KeyMapper::KeyMapper(T label, T act_label, int * key, float w, float h, MapperType type, sf::Color color_active, sf::Color color_hover, sf::Color color_main) +inline KeyMapper::KeyMapper(T label, T act_label, int * key, float w, float h, MapperType type, sf::Color color_active, sf::Color color_hover, sf::Color color_main): waiting(false), this_type(type), wait_text(act_label) { SetSize(w, h); - this_type = type; SetBackgroundColor(color_main); Box LeftBox(0, 0, float(w * 0.5f), h-defaultstate.margin*2.f, sf::Color(0, 100, 200, 0)), RightBox(0, 0, float(w * 0.33f), h - defaultstate.margin * 2.f, sf::Color(0, 100, 200, 128)); LeftBox.AddObject(&Text(label, LOCAL("default"), h*0.7f, sf::Color::White), Allign::LEFT); - RightBox.AddObject(&Text(act_label, LOCAL("default"), h*0.7f, sf::Color::White), Allign::RIGHT); + RightBox.AddObject(&Text(act_label, LOCAL("default"), h*0.7f, sf::Color::White), Allign::CENTER); RightBox.activestate.color_main = color_active; hoverstate.color_main = color_hover; this->AddObject(&LeftBox,Allign::LEFT); this->AddObject(&RightBox, Allign::RIGHT); + key_ptr = key; + SetKeyString(); } diff --git a/src/Main.cpp b/src/Main.cpp index 44f21801..c7c9290a 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -41,7 +41,7 @@ //Graphics settings bool TOUCH_MODE = false; - +bool DEBUG_BAR = false; #if defined(_WIN32) int WinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR lpCmdLine, int nCmdShow) { @@ -274,6 +274,7 @@ int main(int argc, char *argv[]) { { const sf::Keyboard::Key keycode = event.key.code; all_keys[keycode] = true; + io_state.isKeyPressed = true; io_state.keys[keycode] = true; io_state.key_press[keycode] = true; if (event.key.code < 0 || event.key.code >= sf::Keyboard::KeyCount) { continue; } @@ -291,6 +292,11 @@ int main(int argc, char *argv[]) { credits_music.stop(); scene.StartNextLevel(); } + else if (keycode == sf::Keyboard::D && event.key.control) + { + DEBUG_BAR = !DEBUG_BAR; + TwDefine((std::string("Debug_bar visible=") + ((DEBUG_BAR) ? "true" : "false")).c_str()); + } else if (keycode == sf::Keyboard::Escape) { if (game_mode == MAIN_MENU) @@ -327,12 +333,18 @@ int main(int argc, char *argv[]) { } } } - else if (keycode == sf::Keyboard::R) + else if (keycode == SETTINGS.stg.control_mapping[RESTART]) { if (game_mode == PLAYING) { scene.ResetLevel(); } } + else if (keycode == SETTINGS.stg.control_mapping[PAUSE]) + { + if (game_mode == PLAYING) { + PauseGame(window, &overlays, &scene); + } + } else if (keycode == sf::Keyboard::F1) { if (game_mode == PLAYING) { @@ -340,7 +352,7 @@ int main(int argc, char *argv[]) { scene.EnbaleCheats(); } } - else if (keycode == sf::Keyboard::F5) + else if (keycode == SETTINGS.stg.control_mapping[SCREENSHOT]) { TakeScreenshot(); } @@ -593,6 +605,11 @@ int main(int argc, char *argv[]) { float cam_ud = float(-mouse_delta.y) * ms; cam_ud -= 0.05* ms *gamepad_state.axis_value[SETTINGS.stg.control_mapping[JOYSTICK_VIEW_AXIS_Y]]; cam_lr -= 0.05* ms *gamepad_state.axis_value[SETTINGS.stg.control_mapping[JOYSTICK_VIEW_AXIS_X]]; + + cam_ud += 5*ms * ( (all_keys[SETTINGS.stg.control_mapping[VIEWUP]] ? -1.0f : 0.0f) + + (all_keys[SETTINGS.stg.control_mapping[VIEWDOWN]] ? 1.0f : 0.0f) ); + cam_lr += 5*ms * ((all_keys[SETTINGS.stg.control_mapping[VIEWRIGHT]] ? -1.0f : 0.0f) + + (all_keys[SETTINGS.stg.control_mapping[VIEWLEFT]] ? 1.0f : 0.0f)); float cam_z = mouse_wheel * SETTINGS.stg.wheel_sensitivity; @@ -674,6 +691,7 @@ int main(int argc, char *argv[]) { io_state.dt = prev_s; io_state.time += io_state.dt; UpdateAllObjects(&window, io_state); + io_state.isKeyPressed = false; window.setView(default_window_view); if (!skip_frame) { diff --git a/src/Settings.h b/src/Settings.h index ee140d99..1ba52e20 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -85,8 +85,8 @@ struct MainSettings extern TwEnumVal resolutions[]; static const std::array default_control_mapping = { sf::Keyboard::W, sf::Keyboard::S, sf::Keyboard::A, sf::Keyboard::D, - sf::Keyboard::P, sf::Keyboard::R, sf::Keyboard::F5, sf::Keyboard::Up, sf::Keyboard::Down, sf::Keyboard::Left, sf::Keyboard::Right, + sf::Keyboard::P, sf::Keyboard::R, sf::Keyboard::F5, 1, 2, 3, 4, 1, 2, 3}; //an incomprehensible wall of default parameters static const MainSettings default_settings =