| @@ -317,7 +317,7 @@ void BtPhysTest::TickGame(float seconds) | |||||
| } | } | ||||
| if (m_controller->GetKey(KEY_QUIT).JustReleased()) | |||||
| if (m_controller->WasKeyReleased(KEY_QUIT)) | |||||
| Ticker::Shutdown(); | Ticker::Shutdown(); | ||||
| m_loop_value += seconds; | m_loop_value += seconds; | ||||
| @@ -500,15 +500,15 @@ void BtPhysTest::TickGame(float seconds) | |||||
| mat4 CtlrMx = Character->GetTransform(); | mat4 CtlrMx = Character->GetTransform(); | ||||
| vec3 movement(0.f); | vec3 movement(0.f); | ||||
| movement.z = (m_controller->GetKey(KEY_MOVE_RIGHT).IsPressed() ? 1.f : 0.f) | |||||
| - (m_controller->GetKey(KEY_MOVE_LEFT).IsPressed() ? 1.f : 0.f); | |||||
| movement.x = (m_controller->GetKey(KEY_MOVE_FORWARD).IsPressed() ? 1.f : 0.f) | |||||
| - (m_controller->GetKey(KEY_MOVE_BACK).IsPressed() ? 1.f : 0.f); | |||||
| movement.y = (m_controller->GetKey(KEY_MOVE_UP).IsPressed() ? 1.f : 0.f) | |||||
| - (m_controller->GetKey(KEY_MOVE_DOWN).IsPressed() ? 1.f : 0.f); | |||||
| movement.z = (m_controller->IsKeyPressed(KEY_MOVE_RIGHT) ? 1.f : 0.f) | |||||
| - (m_controller->IsKeyPressed(KEY_MOVE_LEFT) ? 1.f : 0.f); | |||||
| movement.x = (m_controller->IsKeyPressed(KEY_MOVE_FORWARD) ? 1.f : 0.f) | |||||
| - (m_controller->IsKeyPressed(KEY_MOVE_BACK) ? 1.f : 0.f); | |||||
| movement.y = (m_controller->IsKeyPressed(KEY_MOVE_UP) ? 1.f : 0.f) | |||||
| - (m_controller->IsKeyPressed(KEY_MOVE_DOWN) ? 1.f : 0.f); | |||||
| vec3 CharMove = movement * seconds * vec3(4.f, 10.f, 4.f); | vec3 CharMove = movement * seconds * vec3(4.f, 10.f, 4.f); | ||||
| if (m_controller->GetKey(KEY_MOVE_JUMP).JustReleased()) | |||||
| if (m_controller->WasKeyReleased(KEY_MOVE_JUMP)) | |||||
| Character->Jump(); | Character->Jump(); | ||||
| Character->SetMovementForFrame(CharMove); | Character->SetMovementForFrame(CharMove); | ||||
| @@ -248,13 +248,13 @@ public: | |||||
| } | } | ||||
| #if NO_NACL_EM_INPUT | #if NO_NACL_EM_INPUT | ||||
| bool KeyReleased(MVKeyboardList index) { return (HAS_KBOARD && m_controller->GetKey(index).JustReleased()); } | |||||
| bool KeyPressed(MVKeyboardList index) { return (HAS_KBOARD && m_controller->GetKey(index).JustPressed()); } | |||||
| bool KeyDown(MVKeyboardList index) { return (HAS_KBOARD && m_controller->GetKey(index).IsPressed()); } | |||||
| bool KeyReleased(MVMouseKeyList index) { return (HAS_MOUSE && m_controller->GetKey(index).JustReleased()); } | |||||
| bool KeyPressed(MVMouseKeyList index) { return (HAS_MOUSE && m_controller->GetKey(index).JustPressed()); } | |||||
| bool KeyDown(MVMouseKeyList index) { return (HAS_MOUSE && m_controller->GetKey(index).IsPressed()); } | |||||
| float AxisValue(MVMouseAxisList index) { return (HAS_MOUSE)?(m_controller->GetAxis(index).GetValue()):(0.f); } | |||||
| bool KeyReleased(MVKeyboardList index) { return (HAS_KBOARD && m_controller->WasKeyReleased(index)); } | |||||
| bool KeyPressed(MVKeyboardList index) { return (HAS_KBOARD && m_controller->WasKeyPressed(index)); } | |||||
| bool KeyDown(MVKeyboardList index) { return (HAS_KBOARD && m_controller->IsKeyPressed(index)); } | |||||
| bool KeyReleased(MVMouseKeyList index) { return (HAS_MOUSE && m_controller->WasKeyReleased(index)); } | |||||
| bool KeyPressed(MVMouseKeyList index) { return (HAS_MOUSE && m_controller->WasKeyPressed(index)); } | |||||
| bool KeyDown(MVMouseKeyList index) { return (HAS_MOUSE && m_controller->IsKeyPressed(index)); } | |||||
| float AxisValue(MVMouseAxisList index) { return (HAS_MOUSE) ? (m_controller->GetAxisValue(index)) : (0.f); } | |||||
| #endif //NO_NACL_EM_INPUT | #endif //NO_NACL_EM_INPUT | ||||
| void Init() | void Init() | ||||
| @@ -107,27 +107,27 @@ public: | |||||
| /* Handle keyboard */ | /* Handle keyboard */ | ||||
| if (m_keyboard) | if (m_keyboard) | ||||
| { | { | ||||
| if (m_controller->GetKey(KEY_MANUAL_ROTATION).JustPressed()) | |||||
| if (m_controller->WasKeyPressed(KEY_MANUAL_ROTATION)) | |||||
| m_autorot = !m_autorot; | m_autorot = !m_autorot; | ||||
| } | } | ||||
| /* Handle joystick */ | /* Handle joystick */ | ||||
| if (m_joystick) | if (m_joystick) | ||||
| { | { | ||||
| if (lol::abs(m_controller->GetAxis(AXIS_PITCH).GetValue()) > 0.2f) | |||||
| m_pitch_angle += m_controller->GetAxis(AXIS_PITCH).GetValue() * seconds * 100; | |||||
| if (lol::abs(m_controller->GetAxis(AXIS_YAW).GetValue()) > 0.2f) | |||||
| m_yaw_angle += m_controller->GetAxis(AXIS_YAW).GetValue() * seconds * 100; | |||||
| if (lol::abs(m_controller->GetAxisValue(AXIS_PITCH)) > 0.2f) | |||||
| m_pitch_angle += m_controller->GetAxisValue(AXIS_PITCH) * seconds * 100; | |||||
| if (lol::abs(m_controller->GetAxisValue(AXIS_YAW)) > 0.2f) | |||||
| m_yaw_angle += m_controller->GetAxisValue(AXIS_YAW) * seconds * 100; | |||||
| } | } | ||||
| /* Handle mouse */ | /* Handle mouse */ | ||||
| if (m_mouse) | if (m_mouse) | ||||
| { | { | ||||
| if (m_controller->GetKey(KEY_DRAG_MESH).IsPressed()) | |||||
| if (m_controller->IsKeyPressed(KEY_DRAG_MESH)) | |||||
| { | { | ||||
| InputDevice::CaptureMouse(true); | InputDevice::CaptureMouse(true); | ||||
| m_pitch_angle -= m_controller->GetAxis(AXIS_DRAG_PITCH).GetValue() * seconds * 100; | |||||
| m_yaw_angle += m_controller->GetAxis(AXIS_DRAG_YAW).GetValue() * seconds * 100; | |||||
| m_pitch_angle -= m_controller->GetAxisValue(AXIS_DRAG_PITCH) * seconds * 100; | |||||
| m_yaw_angle += m_controller->GetAxisValue(AXIS_DRAG_YAW) * seconds * 100; | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| @@ -78,7 +78,7 @@ public: | |||||
| { | { | ||||
| //Shutdown logic | //Shutdown logic | ||||
| if (m_controller->GetKey(KEY_ESC).JustReleased()) | |||||
| if (m_controller->WasKeyReleased(KEY_ESC)) | |||||
| Ticker::Shutdown(); | Ticker::Shutdown(); | ||||
| } | } | ||||
| @@ -169,16 +169,16 @@ public: | |||||
| { | { | ||||
| //Shutdown logic | //Shutdown logic | ||||
| if (m_controller->GetKey(KEY_POP).JustReleased()) | |||||
| if (m_controller->WasKeyReleased(KEY_POP)) | |||||
| voronoi_points.Pop(); | voronoi_points.Pop(); | ||||
| else if (m_controller->GetKey(KEY_PUSH).JustReleased()) | |||||
| else if (m_controller->WasKeyReleased(KEY_PUSH)) | |||||
| voronoi_points.Push(vec3(rand<float>(512.f), rand<float>(512.f), .0f), | voronoi_points.Push(vec3(rand<float>(512.f), rand<float>(512.f), .0f), | ||||
| vec2(64.f + rand<float>(64.f), 64.f + rand<float>(64.f))); | vec2(64.f + rand<float>(64.f), 64.f + rand<float>(64.f))); | ||||
| else if (m_controller->GetKey(KEY_F1).JustReleased()) | |||||
| else if (m_controller->WasKeyReleased(KEY_F1)) | |||||
| m_cur_fbo = SrcVoronoiFbo; | m_cur_fbo = SrcVoronoiFbo; | ||||
| else if (m_controller->GetKey(KEY_F2).JustReleased()) | |||||
| else if (m_controller->WasKeyReleased(KEY_F2)) | |||||
| m_cur_fbo = VoronoiFbo; | m_cur_fbo = VoronoiFbo; | ||||
| else if (m_controller->GetKey(KEY_F3).JustReleased()) | |||||
| else if (m_controller->WasKeyReleased(KEY_F3)) | |||||
| { | { | ||||
| voronoi_points.Empty(); | voronoi_points.Empty(); | ||||
| if (mode == 0) | if (mode == 0) | ||||
| @@ -197,15 +197,15 @@ void LolImGui::TickGame(float seconds) | |||||
| switch (i) | switch (i) | ||||
| { | { | ||||
| default: | default: | ||||
| io.KeysDown[i] = m_controller->GetKey(i).IsPressed(); | |||||
| io.KeysDown[i] = m_controller->IsKeyPressed(i); | |||||
| break; | break; | ||||
| case LolImGuiKey::LShift: | case LolImGuiKey::LShift: | ||||
| case LolImGuiKey::RShift: | case LolImGuiKey::RShift: | ||||
| io.KeyShift = (io.KeyShift || m_controller->GetKey(i).IsPressed()); | |||||
| io.KeyShift = (io.KeyShift || m_controller->IsKeyPressed(i)); | |||||
| break; | break; | ||||
| case LolImGuiKey::LCtrl: | case LolImGuiKey::LCtrl: | ||||
| case LolImGuiKey::RCtrl: | case LolImGuiKey::RCtrl: | ||||
| io.KeyCtrl = (io.KeyCtrl || m_controller->GetKey(i).IsPressed()); | |||||
| io.KeyCtrl = (io.KeyCtrl || m_controller->IsKeyPressed(i)); | |||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| @@ -223,17 +223,17 @@ void LolImGui::TickGame(float seconds) | |||||
| cursor.y = 1.f - cursor.y; | cursor.y = 1.f - cursor.y; | ||||
| cursor *= video_size; | cursor *= video_size; | ||||
| io.MousePos = ImVec2(cursor.x, cursor.y); | io.MousePos = ImVec2(cursor.x, cursor.y); | ||||
| io.MouseWheel = m_controller->GetAxis(LolImGuiAxis::Scroll).GetValue(); | |||||
| io.MouseWheel = m_controller->GetAxisValue(LolImGuiAxis::Scroll); | |||||
| for (int i = LolImGuiKey::MOUSE_KEY_START; i < LolImGuiKey::MOUSE_KEY_END; ++i) | for (int i = LolImGuiKey::MOUSE_KEY_START; i < LolImGuiKey::MOUSE_KEY_END; ++i) | ||||
| { | { | ||||
| switch (i) | switch (i) | ||||
| { | { | ||||
| default: | default: | ||||
| io.MouseDown[i - LolImGuiKey::MOUSE_KEY_START] = m_controller->GetKey(i).IsPressed(); | |||||
| io.MouseDown[i - LolImGuiKey::MOUSE_KEY_START] = m_controller->IsKeyPressed(i); | |||||
| break; | break; | ||||
| case LolImGuiKey::Focus: | case LolImGuiKey::Focus: | ||||
| if (m_controller->GetKey(i).IsPressed()) | |||||
| if (m_controller->IsKeyPressed(i)) | |||||
| io.MousePos = ImVec2(-1.f, -1.f); | io.MousePos = ImVec2(-1.f, -1.f); | ||||
| break; | break; | ||||
| } | } | ||||
| @@ -295,13 +295,49 @@ bool Controller::IsLayerActive() | |||||
| //GetKeys/Axis stuff ---------------------------------------------------------- | //GetKeys/Axis stuff ---------------------------------------------------------- | ||||
| KeyBinding& Controller::GetKey(int index) | KeyBinding& Controller::GetKey(int index) | ||||
| { | { | ||||
| //#error do something better IsLayerActive() | |||||
| return m_keys[index]; | |||||
| } | |||||
| KeyBinding const& Controller::GetKey(int index) const | |||||
| { | |||||
| return m_keys[index]; | return m_keys[index]; | ||||
| } | } | ||||
| AxisBinding& Controller::GetAxis(int index) | AxisBinding& Controller::GetAxis(int index) | ||||
| { | { | ||||
| return m_axis[index]; | return m_axis[index]; | ||||
| } | } | ||||
| AxisBinding const& Controller::GetAxis(int index) const | |||||
| { | |||||
| return m_axis[index]; | |||||
| } | |||||
| //Key methods: should not go directly to binding ------------------------------ | |||||
| bool Controller::IsKeyPressed(int index) const | |||||
| { | |||||
| //#error do something better IsLayerActive() | |||||
| return GetKey(index).IsPressed(); | |||||
| } | |||||
| bool Controller::IsKeyReleased(int index) const | |||||
| { | |||||
| return GetKey(index).IsReleased(); | |||||
| } | |||||
| bool Controller::WasKeyPressed(int index) const | |||||
| { | |||||
| return GetKey(index).WasKeyPressed(); | |||||
| } | |||||
| bool Controller::WasKeyReleased(int index) const | |||||
| { | |||||
| return GetKey(index).WasKeyReleased(); | |||||
| } | |||||
| //Axis methods: should not go directly to binding ----------------------------- | |||||
| float Controller::GetAxisValue(int index) const | |||||
| { | |||||
| return GetAxis(index).GetValue(); | |||||
| } | |||||
| float Controller::GetAxisDelta(int index) const | |||||
| { | |||||
| return GetAxis(index).GetDelta(); | |||||
| } | |||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| Controller* Controller::Get(String const &name) | Controller* Controller::Get(String const &name) | ||||
| @@ -16,22 +16,25 @@ namespace lol | |||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| class KeyBinding | class KeyBinding | ||||
| { | { | ||||
| friend class Controller; | |||||
| public: | public: | ||||
| KeyBinding() | KeyBinding() | ||||
| : m_current(false), | : m_current(false), | ||||
| m_previous(false) | m_previous(false) | ||||
| {} | {} | ||||
| protected: | |||||
| //Status methods ---------------------------------------------------------- | //Status methods ---------------------------------------------------------- | ||||
| /** Indicates wheither the key is currently down */ | /** Indicates wheither the key is currently down */ | ||||
| bool IsPressed() const { return m_current; } | bool IsPressed() const { return m_current; } | ||||
| /** Indicates wheither the key is currently up */ | /** Indicates wheither the key is currently up */ | ||||
| bool IsReleased() const { return !m_current; } | bool IsReleased() const { return !m_current; } | ||||
| /** Indicates wheither the key has just been pressed */ | /** Indicates wheither the key has just been pressed */ | ||||
| bool JustPressed() const { return m_current && !m_previous; } | |||||
| bool WasKeyPressed() const { return m_current && !m_previous; } | |||||
| /** Indicates wheither the key has just been released */ | /** Indicates wheither the key has just been released */ | ||||
| bool JustReleased() const { return !m_current && m_previous; } | |||||
| bool WasKeyReleased() const { return !m_current && m_previous; } | |||||
| public: | |||||
| //Binding methods --------------------------------------------------------- | //Binding methods --------------------------------------------------------- | ||||
| /** Bind a physical device and key */ | /** Bind a physical device and key */ | ||||
| void Bind(const String& device_name, const String& key_name); | void Bind(const String& device_name, const String& key_name); | ||||
| @@ -67,25 +70,26 @@ protected: | |||||
| bool m_current; | bool m_current; | ||||
| /** Value at the current frame */ | /** Value at the current frame */ | ||||
| bool m_previous; | bool m_previous; | ||||
| friend class Controller; | |||||
| }; | }; | ||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| class AxisBinding | class AxisBinding | ||||
| { | { | ||||
| friend class Controller; | |||||
| public: | public: | ||||
| AxisBinding() | AxisBinding() | ||||
| : m_current(0.0f), | : m_current(0.0f), | ||||
| m_previous(0.0f) | m_previous(0.0f) | ||||
| {} | {} | ||||
| protected: | |||||
| //Status methods ---------------------------------------------------------- | //Status methods ---------------------------------------------------------- | ||||
| /** Gets the current absolute value of this axis */ | /** Gets the current absolute value of this axis */ | ||||
| float GetValue() const { return m_current; } | float GetValue() const { return m_current; } | ||||
| /** Gets the current delta value of this axis */ | /** Gets the current delta value of this axis */ | ||||
| float GetDelta() const { return m_current - m_previous; } | float GetDelta() const { return m_current - m_previous; } | ||||
| public: | |||||
| //Binding methods --------------------------------------------------------- | //Binding methods --------------------------------------------------------- | ||||
| /** Bind a physical device and axis */ | /** Bind a physical device and axis */ | ||||
| void Bind(const String& device_name, const String& axis_name); | void Bind(const String& device_name, const String& axis_name); | ||||
| @@ -132,8 +136,6 @@ protected: | |||||
| array<const InputDevice*, int, int> m_keybindings; | array<const InputDevice*, int, int> m_keybindings; | ||||
| float m_current; | float m_current; | ||||
| float m_previous; | float m_previous; | ||||
| friend class Controller; | |||||
| }; | }; | ||||
| //------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
| @@ -348,8 +350,27 @@ public: | |||||
| /** GetKeys/Axis stuff */ | /** GetKeys/Axis stuff */ | ||||
| KeyBinding& GetKey(int index); | KeyBinding& GetKey(int index); | ||||
| KeyBinding const& GetKey(int index) const; | |||||
| AxisBinding& GetAxis(int index); | 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 WasKeyPressed(int index) const; | |||||
| /** Indicates wheither the key has just been released */ | |||||
| bool WasKeyReleased(int index) const; | |||||
| /** Axis methods: should not go directly to binding */ | |||||
| /** Gets the current absolute value of this axis */ | |||||
| float GetAxisValue(int index) const; | |||||
| /** Gets the current delta value of this axis */ | |||||
| float GetAxisDelta(int index) const; | |||||
| /** Get named controller */ | |||||
| static Controller* Get(String const &name); | static Controller* Get(String const &name); | ||||
| protected: | protected: | ||||