ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
Config.h
浏览该文件的文档.
1#pragma once
2#include <string>
3#include <nlohmann/json.hpp>
4#include "Log.h"
5#include "Core.h"
6
7namespace Shit {
8 using Json = nlohmann::json;
9
12 std::string name = "Example";
13 };
14
16 struct WindowConfig {
17 std::string title = "Example";
18 unsigned int width = 1280;
19 unsigned int height = 720;
20 unsigned int targetFPS = 144;
21 };
22
30 public:
31 bool init();
32 void loadFromJson(const Json& j);
33
34 // --- 静态API ---
36 inline static bool Init() { return GetInstance().init(); }
37 inline static const ProjectConfig& GetProjectConfig() { return GetInstance().m_projectConfig; }
38 inline static const WindowConfig& GetWindowConfig() { return GetInstance().m_windowConfig; }
39
40 Config(const Config&) = delete;
41 Config& operator=(const Config&) = delete;
42 Config(Config&&) = delete;
43 Config& operator=(Config&&) = delete;
44
45 private:
46 Config() = default;
47 ~Config() = default;
48
49 ProjectConfig m_projectConfig;
50 WindowConfig m_windowConfig;
51 };
52}
#define SHIT_API
定义 Core.h:12
static Config & GetInstance()
Config & operator=(const Config &)=delete
Config & operator=(Config &&)=delete
Config(const Config &)=delete
static const ProjectConfig & GetProjectConfig()
项目配置
定义 Config.h:37
static const WindowConfig & GetWindowConfig()
窗口配置
定义 Config.h:38
static bool Init()
定义 Config.h:36
Config(Config &&)=delete
bool init()
加载 settings.json
void loadFromJson(const Json &j)
从 JSON 对象加载配置
定义 AudioPlayer.h:9
nlohmann::json Json
定义 Config.h:8
项目配置
定义 Config.h:11
std::string name
项目名称
定义 Config.h:12
窗口配置
定义 Config.h:16
unsigned int targetFPS
帧率上限
定义 Config.h:20
unsigned int height
逻辑分辨率高度
定义 Config.h:19
std::string title
窗口标题
定义 Config.h:17
unsigned int width
逻辑分辨率宽度
定义 Config.h:18