2025-09-15 11:28:54 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
|
#include "EngineFrame/Scene/Scene.h"
|
|
|
|
|
|
#include "Tool/RefPtr.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
|
|
#include <SDL_image.h>
|
|
|
|
|
|
#include <SDL_mixer.h>
|
|
|
|
|
|
#include <SDL_ttf.h>
|
|
|
|
|
|
#include <switch.h>
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
#include <functional>
|
2025-09-19 12:18:57 +08:00
|
|
|
|
#include <GLES3/gl3.h> // 假设使用 OpenGL ES 3.0,根据需求替换为 GLES2/gl2.h
|
2025-09-15 11:28:54 +08:00
|
|
|
|
|
|
|
|
|
|
// some switch buttons
|
|
|
|
|
|
#define JOY_A 0
|
|
|
|
|
|
#define JOY_B 1
|
|
|
|
|
|
#define JOY_X 2
|
|
|
|
|
|
#define JOY_Y 3
|
|
|
|
|
|
#define JOY_PLUS 10
|
|
|
|
|
|
#define JOY_MINUS 11
|
|
|
|
|
|
#define JOY_LEFT 12
|
|
|
|
|
|
#define JOY_UP 13
|
|
|
|
|
|
#define JOY_RIGHT 14
|
|
|
|
|
|
#define JOY_DOWN 15
|
|
|
|
|
|
|
|
|
|
|
|
class Debug_Actor;
|
|
|
|
|
|
|
|
|
|
|
|
class Game
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
// 删除拷贝构造和赋值运算符,确保无法复制
|
|
|
|
|
|
Game(const Game &) = delete;
|
|
|
|
|
|
Game &operator=(const Game &) = delete;
|
|
|
|
|
|
|
|
|
|
|
|
// 移动构造和赋值也删除,避免意外转移
|
|
|
|
|
|
Game(Game &&) = delete;
|
|
|
|
|
|
Game &operator=(Game &&) = delete;
|
|
|
|
|
|
|
|
|
|
|
|
// 全局访问点
|
|
|
|
|
|
static Game &GetInstance()
|
|
|
|
|
|
{
|
|
|
|
|
|
static Game instance; // 局部静态变量,保证只初始化一次
|
|
|
|
|
|
return instance;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Init(std::function<void()> CallBack);
|
|
|
|
|
|
void Run();
|
|
|
|
|
|
void HandleEvents(SDL_Event *e);
|
|
|
|
|
|
void Update(float deltaTime);
|
|
|
|
|
|
void Render(float deltaTime);
|
|
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
|
|
|
|
// 切换场景
|
|
|
|
|
|
void ChangeScene(RefPtr<Scene> scene);
|
|
|
|
|
|
// 设定UI层场景对象
|
|
|
|
|
|
void ChangeUIScene(RefPtr<Scene> scene);
|
|
|
|
|
|
|
|
|
|
|
|
SDL_Renderer *GetRenderer();
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
// 构造函数和析构函数设为私有,防止外部创建和销毁
|
|
|
|
|
|
Game();
|
|
|
|
|
|
~Game();
|
|
|
|
|
|
|
|
|
|
|
|
// 游戏是否运行
|
|
|
|
|
|
bool m_isRunning = true;
|
|
|
|
|
|
// 窗口
|
|
|
|
|
|
SDL_Window *m_window;
|
|
|
|
|
|
// 渲染器
|
|
|
|
|
|
SDL_Renderer *m_renderer;
|
|
|
|
|
|
|
|
|
|
|
|
// 游戏层场景
|
|
|
|
|
|
RefPtr<Scene> m_scene;
|
|
|
|
|
|
// UI层场景
|
|
|
|
|
|
RefPtr<Scene> m_uiScene;
|
|
|
|
|
|
|
|
|
|
|
|
// 屏幕宽高
|
|
|
|
|
|
int Screen_W = 1280;
|
|
|
|
|
|
int Screen_H = 720;
|
|
|
|
|
|
|
|
|
|
|
|
// 帧数
|
|
|
|
|
|
int m_fps = 10000;
|
|
|
|
|
|
u32 m_frameTime;
|
|
|
|
|
|
float m_deltaTime;
|
|
|
|
|
|
// 新增:帧率统计变量
|
|
|
|
|
|
u32 m_frameCount; // 每秒内的帧数计数器
|
|
|
|
|
|
u32 m_lastFpsPrintTime; // 上一次输出帧率的时间(毫秒,基于 SDL_GetTicks())
|
|
|
|
|
|
|
|
|
|
|
|
// 调试信息Actor
|
|
|
|
|
|
RefPtr<Debug_Actor> m_DebugInfoActor;
|
|
|
|
|
|
};
|