diff --git a/doc/samples/btphystest.cpp b/doc/samples/btphystest.cpp index 29405073..3047bf25 100644 --- a/doc/samples/btphystest.cpp +++ b/doc/samples/btphystest.cpp @@ -77,11 +77,6 @@ void BtPhysTest::InitApp() m_loc_dp = .0f; #endif //CAT_MODE - m_profile.register_default_keys(); - m_controller = new Controller("Default"); - m_controller->Init(m_profile); - Ticker::Ref(m_controller); - /* Create a camera that matches the settings of XNA BtPhysTest */ m_camera = new Camera(); @@ -304,7 +299,6 @@ BtPhysTest::~BtPhysTest() { Scene& scene = Scene::GetScene(); scene.PopCamera(m_camera); - Ticker::Unref(m_controller); Ticker::Unref(m_light1); Ticker::Unref(m_light2); @@ -401,7 +395,7 @@ void BtPhysTest::tick_game(float seconds) auto context = Debug::DrawContext::New(Color::white, 1.f); Debug::DrawGrid(vec3::zero, vec3::axis_x, vec3::axis_y, vec3::axis_z, 10.f); - if (m_controller->WasKeyReleasedThisFrame((int)input::key::SC_Escape)) + if (input::keyboard()->key_released(input::key::SC_Escape)) Ticker::Shutdown(); m_loop_value += seconds; @@ -578,6 +572,8 @@ void BtPhysTest::tick_game(float seconds) #if USE_CHARACTER { + auto keyboard = input::keyboard(); + for (int i = 0; i < m_character_list.count(); i++) { PhysicsObject* PhysObj = m_character_list[i]; @@ -585,15 +581,15 @@ void BtPhysTest::tick_game(float seconds) mat4 CtlrMx = Character->GetTransform(); vec3 movement(0.f); - movement.z = (m_controller->IsKeyPressed(input::key::SC_Right) ? 1.f : 0.f) - - (m_controller->IsKeyPressed(input::key::SC_Left) ? 1.f : 0.f); - movement.x = (m_controller->IsKeyPressed(input::key::SC_Up) ? 1.f : 0.f) - - (m_controller->IsKeyPressed(input::key::SC_Down) ? 1.f : 0.f); - movement.y = (m_controller->IsKeyPressed(input::key::SC_PageUp) ? 1.f : 0.f) - - (m_controller->IsKeyPressed(input::key::SC_PageDown) ? 1.f : 0.f); + movement.z = (keyboard->key(input::key::SC_Right) ? 1.f : 0.f) + - (keyboard->key(input::key::SC_Left) ? 1.f : 0.f); + movement.x = (keyboard->key(input::key::SC_Up) ? 1.f : 0.f) + - (keyboard->key(input::key::SC_Down) ? 1.f : 0.f); + movement.y = (keyboard->key(input::key::SC_PageUp) ? 1.f : 0.f) + - (keyboard->key(input::key::SC_PageDown) ? 1.f : 0.f); vec3 CharMove = movement * seconds * vec3(4.f, 10.f, 4.f); - if (m_controller->WasKeyReleasedThisFrame(input::key::SC_Space)) + if (input::keyboard()->key_released(input::key::SC_Space)) Character->Jump(); Character->SetMovementForFrame(CharMove); diff --git a/doc/samples/btphystest.h b/doc/samples/btphystest.h index 0aec8361..d34552da 100644 --- a/doc/samples/btphystest.h +++ b/doc/samples/btphystest.h @@ -93,8 +93,6 @@ private: std::shared_ptr m_cat_shader; CatShaderData* m_cat_sdata; Camera* m_camera; - Controller* m_controller; - InputProfile m_profile; Light* m_light1; Light* m_light2; int m_init_status; diff --git a/doc/tutorial/07_input.cpp b/doc/tutorial/07_input.cpp index 5fdd7518..71ab22ba 100644 --- a/doc/tutorial/07_input.cpp +++ b/doc/tutorial/07_input.cpp @@ -28,38 +28,13 @@ public: { m_controller = new Controller("Default"); -# ifdef OLD_SCHOOL - m_controller->SetInputCount(KEY_MAX, AXIS_MAX); - - auto keyboard = input::keyboard(); - m_controller->GetKey(KEY_MANUAL_ROTATION).Bind(g_name_keyboard, "Space"); - - auto mouse = input::mouse(); - if (mouse) - { - m_controller->GetKey(KEY_DRAG_MESH).Bind(g_name_mouse, "Left"); - m_controller->GetAxis(AXIS_DRAG_PITCH).Bind(g_name_mouse, "Y"); - m_controller->GetAxis(AXIS_DRAG_YAW).Bind(g_name_mouse, "X"); - } - - m_joystick = InputDevice::Get(g_name_joystick(1)); - if (m_joystick) - { - m_controller->GetAxis(AXIS_PITCH).Bind(g_name_joystick(1), "Axis2"); - m_controller->GetAxis(AXIS_YAW).Bind(g_name_joystick(1), "Axis1"); - } -# else m_profile - << InputProfile::KeyboardKey(KEY_MANUAL_ROTATION, "Space") - << InputProfile::MouseKey(KEY_DRAG_MESH, "Left") << InputProfile::JoystickAxis(1, AXIS_PITCH, "Axis2") << InputProfile::JoystickAxis(1, AXIS_YAW, "Axis1") << InputProfile::MouseAxis(AXIS_DRAG_PITCH, "Y") << InputProfile::MouseAxis(AXIS_DRAG_YAW, "X"); m_controller->Init(m_profile); - m_joystick = InputDevice::GetJoystick(1); -# endif //OLD_SCHOOL m_pitch_angle = 0; m_yaw_angle = 0; @@ -103,24 +78,22 @@ public: { WorldEntity::tick_game(seconds); + auto mouse = input::mouse(); + auto keyboard = input::keyboard(); + /* Handle keyboard */ - if (m_controller->WasKeyPressedThisFrame(KEY_MANUAL_ROTATION)) + if (keyboard->key_pressed(input::key::SC_Space)) m_autorot = !m_autorot; /* Handle joystick */ - if (m_joystick) - { - if (lol::abs(m_controller->GetAxisValue(AXIS_PITCH)) > 0.2f) - m_pitch_angle += m_controller->GetAxisValue(AXIS_PITCH) * seconds; - if (lol::abs(m_controller->GetAxisValue(AXIS_YAW)) > 0.2f) - m_yaw_angle += m_controller->GetAxisValue(AXIS_YAW) * seconds; - } + if (lol::abs(m_controller->GetAxisValue(AXIS_PITCH)) > 0.2f) + m_pitch_angle += m_controller->GetAxisValue(AXIS_PITCH) * seconds; + if (lol::abs(m_controller->GetAxisValue(AXIS_YAW)) > 0.2f) + m_yaw_angle += m_controller->GetAxisValue(AXIS_YAW) * seconds; /* Handle mouse */ if (true) { - auto mouse = input::mouse(); - if (mouse->button(input::button::BTN_Left)) { mouse->capture(true); @@ -207,13 +180,6 @@ public: } private: - enum - { - KEY_MANUAL_ROTATION, - KEY_DRAG_MESH, - KEY_MAX - }; - enum { AXIS_DRAG_PITCH, @@ -223,7 +189,6 @@ private: AXIS_MAX }; - InputDevice *m_joystick; Controller *m_controller; InputProfile m_profile; diff --git a/doc/tutorial/09_sound.cpp b/doc/tutorial/09_sound.cpp index e1cff512..4f9c1fff 100644 --- a/doc/tutorial/09_sound.cpp +++ b/doc/tutorial/09_sound.cpp @@ -28,11 +28,6 @@ public: for (auto &val : m_streams) val = -1; - m_controller = new Controller("Default"); - m_profile << InputProfile::KeyboardKey(0, "Space") - << InputProfile::MouseKey(1, "Left"); - m_controller->Init(m_profile); - m_text = new Text("SPACE for sine wave, Left Click for white noise", "data/font/ascii.png"); m_text->SetPos(vec3(5, 5, 1)); @@ -65,9 +60,14 @@ public: { WorldEntity::tick_game(seconds); + auto mouse = input::mouse(); + auto keyboard = input::keyboard(); + for (int i = 0; i < 2; ++i) { - if (!m_controller->WasKeyPressedThisFrame(i)) + if (i == 0 && !keyboard->key_pressed(input::key::SC_Space)) + continue; + if (i == 1 && !mouse->button_pressed(input::button::BTN_Left)) continue; if (m_streams[i] < 0) @@ -92,10 +92,6 @@ public: private: int m_streams[2]; - - Controller *m_controller; - InputProfile m_profile; - Text *m_text; }; diff --git a/doc/tutorial/11_fractal.cpp b/doc/tutorial/11_fractal.cpp index c854fc00..57a63529 100644 --- a/doc/tutorial/11_fractal.cpp +++ b/doc/tutorial/11_fractal.cpp @@ -42,13 +42,6 @@ public: m_texel_settings = vec4(1.0, 1.0, 2.0, 2.0) / (vec4)m_size.xyxy; m_screen_settings = vec4(1.0, 1.0, 0.5, 0.5) * (vec4)m_size.xyxy; - m_controller = new Controller("Default"); - m_profile << InputProfile::MouseKey(0, "Left") - << InputProfile::MouseKey(1, "Right") - << InputProfile::MouseKey(2, "Middle") - << InputProfile::KeyboardKey(3, "Space"); - m_controller->Init(m_profile); - /* Window size decides the world aspect ratio. For instance, 640×480 * will be mapped to (-0.66,-0.5) - (0.66,0.5). */ m_window_size = Video::GetSize(); @@ -157,12 +150,15 @@ public: { WorldEntity::tick_game(seconds); - ivec2 mousepos = input::mouse()->get_cursor_pixel(0); + auto mouse = input::mouse(); + auto keyboard = input::keyboard(); + + ivec2 mousepos = mouse->get_cursor_pixel(0); int prev_frame = (m_frame + 4) % 4; m_frame = (m_frame + 1) % 4; - if (m_controller->WasKeyPressedThisFrame(3)) + if (keyboard->key_pressed(input::key::SC_Space)) { m_julia = !m_julia; if (m_julia) @@ -180,7 +176,7 @@ public: rcmplx worldmouse = m_view.center + rcmplx(ScreenToWorldOffset((vec2)mousepos)); - if (m_controller->IsKeyPressed(2)) + if (mouse->button(input::button::BTN_Middle)) { if (!m_drag) { @@ -208,8 +204,8 @@ public: } } - bool hold_right = m_controller->IsKeyPressed(0); - bool hold_left = m_controller->IsKeyPressed(1); + bool hold_right = mouse->button(input::button::BTN_Right); + bool hold_left = mouse->button(input::button::BTN_Left); if ((hold_right || hold_left) && mousepos.x != -1) { double zoom = hold_right ? -0.5 : 0.5; @@ -564,10 +560,6 @@ private: vec4 m_texel_settings, m_screen_settings; mat4 m_zoom_settings; - // Input support - Controller *m_controller; - InputProfile m_profile; - #if LOL_FEATURE_THREADS /* Worker threads */ thread *m_threads[MAX_THREADS]; diff --git a/src/lol-core.vcxproj.filters b/src/lol-core.vcxproj.filters old mode 100755 new mode 100644 diff --git a/src/ui/controller.cpp b/src/ui/controller.cpp index 8e76fa56..fda5d524 100644 --- a/src/ui/controller.cpp +++ b/src/ui/controller.cpp @@ -282,31 +282,6 @@ AxisBinding& Controller::GetAxis(int index) return m_axis_bindings[index]; } -// Key methods: should not go directly to binding -bool Controller::IsKeyPressed(int index) const -{ - auto key = m_key_bindings.find(index); - return key != m_key_bindings.end() && key->second.IsPressed(); -} - -bool Controller::IsKeyReleased(int index) const -{ - auto key = m_key_bindings.find(index); - return key != m_key_bindings.end() && key->second.IsReleased(); -} - -bool Controller::WasKeyPressedThisFrame(int index) const -{ - auto key = m_key_bindings.find(index); - return key != m_key_bindings.end() && key->second.WasPressedThisFrame(); -} - -bool Controller::WasKeyReleasedThisFrame(int index) const -{ - auto key = m_key_bindings.find(index); - return key != m_key_bindings.end() && key->second.WasReleasedThisFrame(); -} - //Axis methods: should not go directly to binding ----------------------------- float Controller::GetAxisValue(int index) const { diff --git a/src/ui/controller.h b/src/ui/controller.h index 08921c11..3fc6f6b2 100644 --- a/src/ui/controller.h +++ b/src/ui/controller.h @@ -30,10 +30,6 @@ protected: bool IsPressed() const { return m_current; } /** Indicates wheither the key is currently up */ bool IsReleased() const { return !m_current; } - /** Indicates wheither the key has just been pressed */ - bool WasPressedThisFrame() const { return m_current && !m_previous; } - /** Indicates wheither the key has just been released */ - bool WasReleasedThisFrame() const { return !m_current && m_previous; } public: //Binding methods --------------------------------------------------------- @@ -322,16 +318,6 @@ public: AxisBinding& GetAxis(int index); AxisBinding const& GetAxis(int index) const; - /** Key methods: should not go directly to binding */ - /** Indicates wheither the key is currently down */ - bool IsKeyPressed(int index) const; - /** Indicates wheither the key is currently up */ - bool IsKeyReleased(int index) const; - /** Indicates wheither the key has just been pressed */ - bool WasKeyPressedThisFrame(int index) const; - /** Indicates wheither the key has just been released */ - bool WasKeyReleasedThisFrame(int index) const; - /** Axis methods: should not go directly to binding */ /** Gets the current absolute value of this axis */ float GetAxisValue(int index) const; diff --git a/src/ui/sdl-input.cpp b/src/ui/sdl-input.cpp index 97cb9a16..e80cbd98 100644 --- a/src/ui/sdl-input.cpp +++ b/src/ui/sdl-input.cpp @@ -176,18 +176,12 @@ void SdlInput::tick(float seconds) if (event.type == SDL_KEYDOWN) { auto sc2 = sc; - switch (sc) - { - case input::key::SC_CapsLock: + if (sc == input::key::SC_CapsLock) sc2 = input::key::SC_CapsLockStatus; - break; - case input::key::SC_ScrollLock: + else if (sc == input::key::SC_ScrollLock) sc2 = input::key::SC_ScrollLockStatus; - break; - case input::key::SC_NumLockClear: + else if (sc == input::key::SC_NumLockClear) sc2 = input::key::SC_NumLockClearStatus; - break; - } keyboard->internal_set_key(sc2, !keyboard->key(sc2)); } LOL_ATTR_FALLTHROUGH