-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.h
More file actions
87 lines (70 loc) · 2.85 KB
/
window.h
File metadata and controls
87 lines (70 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef WINDOW_H
#define WINDOW_H
#include <SDL.h>
#include <glad/glad.h>
#include <chrono> // 用于时间计算
#include <iostream> // 用于输出调试信息
// 包含项目中的其他核心组件
#include "scene.h"// 你的场景类
#include "uiSystem.h" // 你的 UI 系统
#include "camera.h" // Camera 类
#include "InputManager.h" // InputManager
#include "sceneObject.h" // 引入 ISceneObject 接口
// 包含命令模式相关的头文件
#include "Command.h"// 抽象命令基类 (需要 CameraCommand 继承 Command 并有 setDeltaTime 方法)
#include "moveCameraForwardCommand.h"
#include "moveCameraBackwardCommand.h"
#include "moveCameraLeftCommand.h"
#include "moveCameraRightCommand.h"
#include "moveCameraUpCommand.h"
#include "moveCameraDownCommand.h"
#include "processMouseMovementCommand.h"
#include "processMouseScrollCommand.h"
#include "toggleDebugModeCommand.h"
#include "pickObjectCommand.h" // 此命令需要改造以返回 ISceneObject*
#include "rotateCameraLeftCommand.h"
#include "rotateCameraRightCommand.h"
class Window {
public:
// 构造函数:初始化 SDL, OpenGL 上下文, GLAD, UI 系统, 场景和命令
Window(const char* title, int width, int height);
// 析构函数:清理所有资源 (SDL, OpenGL 上下文, UI 系统, 命令对象)
~Window();
// 更新帧率计数器和窗口标题
void updateFPS();
// 处理所有输入事件、更新游戏逻辑和摄像机状态。
void update();
// 渲染场景和 UI。
void render();
// 检查窗口是否仍在运行。
bool isRunning();
private:
SDL_Window* window_ = nullptr;
SDL_GLContext glContext_;
// FPS 相关成员变量
int fps_ = 0;
int frameCount_ = 0;
std::chrono::time_point<std::chrono::high_resolution_clock> lastFPSTime_;
// DeltaTime 相关成员变量
std::chrono::time_point<std::chrono::high_resolution_clock> lastFrameTime_;
float deltaTime_ = 0.0f; // 存储当前帧的 deltaTime (秒)
std::shared_ptr<Scene> scene_;
UiSystem* uiSystem_ = nullptr;
bool running_ = true;
// --- 命令对象指针 ---
MoveCameraForwardCommand* cmd_moveForward_ = nullptr;
MoveCameraBackwardCommand* cmd_moveBackward_ = nullptr;
MoveCameraLeftCommand* cmd_moveLeft_ = nullptr;
MoveCameraRightCommand* cmd_moveRight_ = nullptr;
MoveCameraUpCommand* cmd_moveUp_ = nullptr;
MoveCameraDownCommand* cmd_moveDown_ = nullptr;
RotateCameraLeftCommand* cmd_rotateLeft_ = nullptr;
RotateCameraRightCommand* cmd_rotateRight_ = nullptr;
ProcessMouseMovementCommand* cmd_mouseLook_ = nullptr;
ProcessMouseScrollCommand* cmd_mouseScroll_ = nullptr;
ToggleDebugModeCommand* cmd_toggleDebug_ = nullptr;
PickObjectCommand* cmd_pickObject_ = nullptr;
// 修改 pickedMesh_ 为 pickedObject_
ISceneObject* pickedObject_ = nullptr;
};
#endif // WINDOW_H