Unify input behind Engine::Input facade; fix Ctrl+P and Pause button
New Engine/Core/Input.h/.cpp: static input facade with a Key/MouseButton enum (values map to GLFW key codes internally) so scripts and game logic no longer touch GLFW directly - window backend becomes swappable and the facade is the surface to expose when embedding scripting later. Wired up in Application's constructor; Camera (editor camera WASD/RMB/MMB), the WASDMove script and SandboxApp key handling now query Input only. Ctrl+P hotkey fix: the !m_Playing guard made the hotkey dead exactly when it was needed - after pressing Play. Now toggles both ways. Toolbar Pause button now reads "Resume" while paused (tooltip follows).
This commit is contained in:
@@ -12,15 +12,16 @@
|
||||
|
||||
#include <Engine/Scripting/Script.h>
|
||||
#include <Engine/Core/Application.h>
|
||||
#include <Engine/Core/Window.h>
|
||||
#include <Engine/Core/Input.h>
|
||||
#include <Engine/Renderer/Renderer.h>
|
||||
#include <Engine/Renderer/EditorCamera.h>
|
||||
#include <Engine/Physics/PhysicsWorld.h>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
using namespace Engine; // Input 门面(统一输入入口)
|
||||
|
||||
namespace {
|
||||
|
||||
class WASDMove final : public Engine::Scripting::ScriptBehavior {
|
||||
@@ -29,7 +30,8 @@ namespace {
|
||||
|
||||
void OnUpdate(float dt) override {
|
||||
// 位移方向 = 视线水平投影(W 前进 / A 左 / D 右),UE Scene
|
||||
// view 移动惯例;Y 锁 0(升降/跳跃归物理或将来扩展)
|
||||
// view 移动惯例;Y 锁 0(升降/跳跃归物理或将来扩展)。
|
||||
// 键鼠查询统一走 Input 门面(脚本层零 GLFW 依赖)
|
||||
const glm::quat cq = App().GetRenderer()
|
||||
.GetEditorCamera()
|
||||
.GetTransform()
|
||||
@@ -37,12 +39,11 @@ namespace {
|
||||
const glm::vec3 fwd = cq * glm::vec3(0.0f, 0.0f, -1.0f);
|
||||
const glm::vec3 right = cq * glm::vec3(1.0f, 0.0f, 0.0f);
|
||||
|
||||
auto& win = App().GetWindow();
|
||||
glm::vec3 move(0.0f);
|
||||
if (win.IsKeyPressed(GLFW_KEY_W)) move += fwd;
|
||||
if (win.IsKeyPressed(GLFW_KEY_S)) move -= fwd;
|
||||
if (win.IsKeyPressed(GLFW_KEY_D)) move += right;
|
||||
if (win.IsKeyPressed(GLFW_KEY_A)) move -= right;
|
||||
if (Input::IsKeyDown(Input::Key::W)) move += fwd;
|
||||
if (Input::IsKeyDown(Input::Key::S)) move -= fwd;
|
||||
if (Input::IsKeyDown(Input::Key::D)) move += right;
|
||||
if (Input::IsKeyDown(Input::Key::A)) move -= right;
|
||||
move.y = 0.0f;
|
||||
if (glm::length(move) > 1e-4f) {
|
||||
move = glm::normalize(move);
|
||||
|
||||
Reference in New Issue
Block a user