fix: 修复InputManager中文注释警告和完善Update逻辑
- InputManager.h: 移除中文注释修复C4819警告 - InputManager.h: 添加缺失的vector和unordered_map头文件 - InputManager.cpp: Update()现正确清除m_keyDownThisFrame状态 - InputManager.cpp: ProcessKeyDown/Up添加修饰键参数 - WindowsInputModule: 传递alt/ctrl/shift修饰键状态
This commit is contained in:
@@ -4,6 +4,8 @@
|
|||||||
#include "InputEvent.h"
|
#include "InputEvent.h"
|
||||||
#include "InputAxis.h"
|
#include "InputAxis.h"
|
||||||
#include "Math/Vector2.h"
|
#include "Math/Vector2.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace XCEngine {
|
namespace XCEngine {
|
||||||
namespace Input {
|
namespace Input {
|
||||||
@@ -16,8 +18,6 @@ public:
|
|||||||
void Shutdown();
|
void Shutdown();
|
||||||
void Update(float deltaTime);
|
void Update(float deltaTime);
|
||||||
|
|
||||||
// ============ 轮询接口 ============
|
|
||||||
|
|
||||||
bool IsKeyDown(KeyCode key) const;
|
bool IsKeyDown(KeyCode key) const;
|
||||||
bool IsKeyUp(KeyCode key) const;
|
bool IsKeyUp(KeyCode key) const;
|
||||||
bool IsKeyPressed(KeyCode key) const;
|
bool IsKeyPressed(KeyCode key) const;
|
||||||
@@ -32,8 +32,6 @@ public:
|
|||||||
int GetTouchCount() const;
|
int GetTouchCount() const;
|
||||||
TouchState GetTouch(int index) const;
|
TouchState GetTouch(int index) const;
|
||||||
|
|
||||||
// ============ 轴接口 (参考 Unity) ============
|
|
||||||
|
|
||||||
float GetAxis(const Containers::String& axisName) const;
|
float GetAxis(const Containers::String& axisName) const;
|
||||||
float GetAxisRaw(const Containers::String& axisName) const;
|
float GetAxisRaw(const Containers::String& axisName) const;
|
||||||
|
|
||||||
@@ -45,18 +43,14 @@ public:
|
|||||||
void RegisterButton(const Containers::String& name, KeyCode key);
|
void RegisterButton(const Containers::String& name, KeyCode key);
|
||||||
void ClearAxes();
|
void ClearAxes();
|
||||||
|
|
||||||
// ============ 事件接口 ============
|
|
||||||
|
|
||||||
Core::Event<const KeyEvent&>& OnKeyEvent() { return m_onKeyEvent; }
|
Core::Event<const KeyEvent&>& OnKeyEvent() { return m_onKeyEvent; }
|
||||||
Core::Event<const MouseButtonEvent&>& OnMouseButton() { return m_onMouseButton; }
|
Core::Event<const MouseButtonEvent&>& OnMouseButton() { return m_onMouseButton; }
|
||||||
Core::Event<const MouseMoveEvent&>& OnMouseMove() { return m_onMouseMove; }
|
Core::Event<const MouseMoveEvent&>& OnMouseMove() { return m_onMouseMove; }
|
||||||
Core::Event<const MouseWheelEvent&>& OnMouseWheel() { return m_onMouseWheel; }
|
Core::Event<const MouseWheelEvent&>& OnMouseWheel() { return m_onMouseWheel; }
|
||||||
Core::Event<const TextInputEvent&>& OnTextInput() { return m_onTextInput; }
|
Core::Event<const TextInputEvent&>& OnTextInput() { return m_onTextInput; }
|
||||||
|
|
||||||
// ============ 内部方法(供 PlatformInputModule 调用) ============
|
void ProcessKeyDown(KeyCode key, bool repeat, bool alt, bool ctrl, bool shift, bool meta);
|
||||||
|
void ProcessKeyUp(KeyCode key, bool alt, bool ctrl, bool shift, bool meta);
|
||||||
void ProcessKeyDown(KeyCode key, bool repeat);
|
|
||||||
void ProcessKeyUp(KeyCode key);
|
|
||||||
void ProcessMouseMove(int x, int y, int deltaX, int deltaY);
|
void ProcessMouseMove(int x, int y, int deltaX, int deltaY);
|
||||||
void ProcessMouseButton(MouseButton button, bool pressed, int x, int y);
|
void ProcessMouseButton(MouseButton button, bool pressed, int x, int y);
|
||||||
void ProcessMouseWheel(float delta, int x, int y);
|
void ProcessMouseWheel(float delta, int x, int y);
|
||||||
|
|||||||
@@ -62,8 +62,16 @@ void InputManager::Update(float deltaTime) {
|
|||||||
if (!m_initialized) return;
|
if (!m_initialized) return;
|
||||||
|
|
||||||
m_keyDownLastFrame = m_keyDownThisFrame;
|
m_keyDownLastFrame = m_keyDownThisFrame;
|
||||||
|
m_keyDownThisFrame.clear();
|
||||||
|
m_keyDownThisFrame.resize(256, false);
|
||||||
|
|
||||||
m_mouseButtonDownLastFrame = m_mouseButtonDownThisFrame;
|
m_mouseButtonDownLastFrame = m_mouseButtonDownThisFrame;
|
||||||
|
m_mouseButtonDownThisFrame.clear();
|
||||||
|
m_mouseButtonDownThisFrame.resize(5, false);
|
||||||
|
|
||||||
m_buttonDownLastFrame = m_buttonDownThisFrame;
|
m_buttonDownLastFrame = m_buttonDownThisFrame;
|
||||||
|
m_buttonDownThisFrame.clear();
|
||||||
|
m_buttonDownThisFrame.resize(32, false);
|
||||||
|
|
||||||
m_mouseDelta = Math::Vector2::Zero();
|
m_mouseDelta = Math::Vector2::Zero();
|
||||||
m_mouseScrollDelta = 0.0f;
|
m_mouseScrollDelta = 0.0f;
|
||||||
@@ -203,7 +211,7 @@ void InputManager::ClearAxes() {
|
|||||||
m_buttons.clear();
|
m_buttons.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::ProcessKeyDown(KeyCode key, bool repeat) {
|
void InputManager::ProcessKeyDown(KeyCode key, bool repeat, bool alt, bool ctrl, bool shift, bool meta) {
|
||||||
if (!m_initialized) return;
|
if (!m_initialized) return;
|
||||||
|
|
||||||
size_t index = GetKeyIndex(key);
|
size_t index = GetKeyIndex(key);
|
||||||
@@ -215,15 +223,15 @@ void InputManager::ProcessKeyDown(KeyCode key, bool repeat) {
|
|||||||
KeyEvent event;
|
KeyEvent event;
|
||||||
event.keyCode = key;
|
event.keyCode = key;
|
||||||
event.type = repeat ? KeyEvent::Repeat : KeyEvent::Down;
|
event.type = repeat ? KeyEvent::Repeat : KeyEvent::Down;
|
||||||
event.alt = false;
|
event.alt = alt;
|
||||||
event.ctrl = false;
|
event.ctrl = ctrl;
|
||||||
event.shift = false;
|
event.shift = shift;
|
||||||
event.meta = false;
|
event.meta = meta;
|
||||||
|
|
||||||
m_onKeyEvent.Invoke(event);
|
m_onKeyEvent.Invoke(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::ProcessKeyUp(KeyCode key) {
|
void InputManager::ProcessKeyUp(KeyCode key, bool alt, bool ctrl, bool shift, bool meta) {
|
||||||
if (!m_initialized) return;
|
if (!m_initialized) return;
|
||||||
|
|
||||||
size_t index = GetKeyIndex(key);
|
size_t index = GetKeyIndex(key);
|
||||||
@@ -234,10 +242,10 @@ void InputManager::ProcessKeyUp(KeyCode key) {
|
|||||||
KeyEvent event;
|
KeyEvent event;
|
||||||
event.keyCode = key;
|
event.keyCode = key;
|
||||||
event.type = KeyEvent::Up;
|
event.type = KeyEvent::Up;
|
||||||
event.alt = false;
|
event.alt = alt;
|
||||||
event.ctrl = false;
|
event.ctrl = ctrl;
|
||||||
event.shift = false;
|
event.shift = shift;
|
||||||
event.meta = false;
|
event.meta = meta;
|
||||||
|
|
||||||
m_onKeyEvent.Invoke(event);
|
m_onKeyEvent.Invoke(event);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,16 +97,26 @@ void WindowsInputModule::ProcessKeyDown(WPARAM wParam, LPARAM lParam) {
|
|||||||
bool repeat = (lParam & (1 << 30)) != 0;
|
bool repeat = (lParam & (1 << 30)) != 0;
|
||||||
KeyCode keyCode = VKCodeToKeyCode(static_cast<int>(wParam));
|
KeyCode keyCode = VKCodeToKeyCode(static_cast<int>(wParam));
|
||||||
|
|
||||||
|
bool alt = (GetKeyState(VK_MENU) & 0x8000) != 0;
|
||||||
|
bool ctrl = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
|
||||||
|
bool shift = (GetKeyState(VK_SHIFT) & 0x8000) != 0;
|
||||||
|
bool meta = false;
|
||||||
|
|
||||||
if (keyCode != KeyCode::None) {
|
if (keyCode != KeyCode::None) {
|
||||||
InputManager::Get().ProcessKeyDown(keyCode, repeat);
|
InputManager::Get().ProcessKeyDown(keyCode, repeat, alt, ctrl, shift, meta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowsInputModule::ProcessKeyUp(WPARAM wParam) {
|
void WindowsInputModule::ProcessKeyUp(WPARAM wParam) {
|
||||||
KeyCode keyCode = VKCodeToKeyCode(static_cast<int>(wParam));
|
KeyCode keyCode = VKCodeToKeyCode(static_cast<int>(wParam));
|
||||||
|
|
||||||
|
bool alt = (GetKeyState(VK_MENU) & 0x8000) != 0;
|
||||||
|
bool ctrl = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
|
||||||
|
bool shift = (GetKeyState(VK_SHIFT) & 0x8000) != 0;
|
||||||
|
bool meta = false;
|
||||||
|
|
||||||
if (keyCode != KeyCode::None) {
|
if (keyCode != KeyCode::None) {
|
||||||
InputManager::Get().ProcessKeyUp(keyCode);
|
InputManager::Get().ProcessKeyUp(keyCode, alt, ctrl, shift, meta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user