feat: expand editor scripting asset and viewport flow

This commit is contained in:
2026-04-03 13:22:30 +08:00
parent ed8c27fde2
commit a05d0b80a2
124 changed files with 10397 additions and 1737 deletions

View File

@@ -16,10 +16,12 @@ void InputManager::Initialize(void* platformWindowHandle) {
m_keyDownThisFrame.resize(256, false);
m_keyDownLastFrame.resize(256, false);
m_keyUpThisFrame.resize(256, false);
m_keyDown.resize(256, false);
m_mouseButtonDownThisFrame.resize(5, false);
m_mouseButtonDownLastFrame.resize(5, false);
m_mouseButtonUpThisFrame.resize(5, false);
m_mouseButtonDown.resize(5, false);
m_buttonDownThisFrame.resize(32, false);
@@ -39,14 +41,21 @@ void InputManager::Initialize(void* platformWindowHandle) {
}
void InputManager::Shutdown() {
m_mousePosition = Math::Vector2::Zero();
m_mouseDelta = Math::Vector2::Zero();
m_mouseScrollDelta = 0.0f;
m_touches.clear();
if (!m_initialized) return;
m_keyDownThisFrame.clear();
m_keyDownLastFrame.clear();
m_keyUpThisFrame.clear();
m_keyDown.clear();
m_mouseButtonDownThisFrame.clear();
m_mouseButtonDownLastFrame.clear();
m_mouseButtonUpThisFrame.clear();
m_mouseButtonDown.clear();
m_axes.clear();
@@ -64,10 +73,14 @@ void InputManager::Update(float deltaTime) {
m_keyDownLastFrame = m_keyDownThisFrame;
m_keyDownThisFrame.clear();
m_keyDownThisFrame.resize(256, false);
m_keyUpThisFrame.clear();
m_keyUpThisFrame.resize(256, false);
m_mouseButtonDownLastFrame = m_mouseButtonDownThisFrame;
m_mouseButtonDownThisFrame.clear();
m_mouseButtonDownThisFrame.resize(5, false);
m_mouseButtonUpThisFrame.clear();
m_mouseButtonUpThisFrame.resize(5, false);
m_buttonDownLastFrame = m_buttonDownThisFrame;
m_buttonDownThisFrame.clear();
@@ -104,6 +117,13 @@ bool InputManager::IsKeyPressed(KeyCode key) const {
return m_keyDownThisFrame[index] && !m_keyDownLastFrame[index];
}
bool InputManager::IsKeyReleased(KeyCode key) const {
if (!m_initialized) return false;
size_t index = GetKeyIndex(key);
if (index >= m_keyUpThisFrame.size()) return false;
return m_keyUpThisFrame[index];
}
Math::Vector2 InputManager::GetMousePosition() const {
return m_mousePosition;
}
@@ -135,6 +155,13 @@ bool InputManager::IsMouseButtonClicked(MouseButton button) const {
return m_mouseButtonDownThisFrame[index] && !m_mouseButtonDownLastFrame[index];
}
bool InputManager::IsMouseButtonReleased(MouseButton button) const {
if (!m_initialized) return false;
size_t index = GetMouseButtonIndex(button);
if (index >= m_mouseButtonUpThisFrame.size()) return false;
return m_mouseButtonUpThisFrame[index];
}
int InputManager::GetTouchCount() const {
return static_cast<int>(m_touches.size());
}
@@ -170,10 +197,10 @@ float InputManager::GetAxisRaw(const Containers::String& axisName) const {
const auto& axis = it->second;
float value = 0.0f;
if (axis.GetPositiveKey() != KeyCode::None && IsKeyPressed(axis.GetPositiveKey())) {
if (axis.GetPositiveKey() != KeyCode::None && IsKeyDown(axis.GetPositiveKey())) {
value += 1.0f;
}
if (axis.GetNegativeKey() != KeyCode::None && IsKeyPressed(axis.GetNegativeKey())) {
if (axis.GetNegativeKey() != KeyCode::None && IsKeyDown(axis.GetNegativeKey())) {
value -= 1.0f;
}
@@ -194,8 +221,34 @@ bool InputManager::GetButtonDown(const Containers::String& buttonName) const {
bool InputManager::GetButtonUp(const Containers::String& buttonName) const {
auto it = m_buttons.find(buttonName);
if (it == m_buttons.end()) return true;
return IsKeyUp(it->second);
if (it == m_buttons.end()) return false;
return IsKeyReleased(it->second);
}
bool InputManager::IsAnyKeyDown() const {
if (!m_initialized) return false;
return std::any_of(
m_keyDown.begin(),
m_keyDown.end(),
[](bool isDown) { return isDown; })
|| std::any_of(
m_mouseButtonDown.begin(),
m_mouseButtonDown.end(),
[](bool isDown) { return isDown; });
}
bool InputManager::IsAnyKeyPressed() const {
if (!m_initialized) return false;
return std::any_of(
m_keyDownThisFrame.begin(),
m_keyDownThisFrame.end(),
[](bool isPressed) { return isPressed; })
|| std::any_of(
m_mouseButtonDownThisFrame.begin(),
m_mouseButtonDownThisFrame.end(),
[](bool isPressed) { return isPressed; });
}
void InputManager::RegisterAxis(const InputAxis& axis) {
@@ -238,6 +291,7 @@ void InputManager::ProcessKeyUp(KeyCode key, bool alt, bool ctrl, bool shift, bo
if (index >= m_keyDown.size()) return;
m_keyDown[index] = false;
m_keyUpThisFrame[index] = true;
KeyEvent event;
event.keyCode = key;
@@ -274,6 +328,8 @@ void InputManager::ProcessMouseButton(MouseButton button, bool pressed, int x, i
m_mouseButtonDown[index] = pressed;
if (pressed) {
m_mouseButtonDownThisFrame[index] = true;
} else {
m_mouseButtonUpThisFrame[index] = true;
}
MouseButtonEvent event;