ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
Config.h
浏览该文件的文档.
1#pragma once
2#include <string>
3#include <unordered_map>
4#include <vector>
5#include <nlohmann/json.hpp>
6#include "Log.h"
7#include "Core.h"
8
9namespace Shit {
10 using Json = nlohmann::json;
11
14 std::string name = "Example";
15 };
16
18 struct WindowConfig {
19 std::string title = "Example";
20 unsigned int width = 1280;
21 unsigned int height = 720;
22 unsigned int targetFPS = 144;
23 };
24
33 std::vector<std::string> keys;
34 };
35
42 struct AxisBinding {
43 std::vector<std::string> negative;
44 std::vector<std::string> positive;
45 };
46
67 std::unordered_map<std::string, ActionBinding> actions;
68 std::unordered_map<std::string, AxisBinding> axes;
69 };
70
78 public:
79 bool init();
80 void loadFromJson(const Json& j);
81
82 // --- 静态API ---
84 inline static bool Init() { return GetInstance().init(); }
85 inline static const ProjectConfig& GetProjectConfig() { return GetInstance().m_projectConfig; }
86 inline static const WindowConfig& GetWindowConfig() { return GetInstance().m_windowConfig; }
87 inline static const InputMappingsConfig& GetInputMappingsConfig() { return GetInstance().m_inputMappings; }
88
89 Config(const Config&) = delete;
90 Config& operator=(const Config&) = delete;
91 Config(Config&&) = delete;
92 Config& operator=(Config&&) = delete;
93
94 private:
95 friend class EngineContext;
96 Config() = default;
97 ~Config() = default;
98
99 ProjectConfig m_projectConfig;
100 WindowConfig m_windowConfig;
101 InputMappingsConfig m_inputMappings;
102 };
103} // namespace Shit
#define SHIT_API
定义 Core.h:14
static Config & GetInstance()
Config & operator=(const Config &)=delete
Config & operator=(Config &&)=delete
Config(const Config &)=delete
static const ProjectConfig & GetProjectConfig()
定义 Config.h:85
static const InputMappingsConfig & GetInputMappingsConfig()
定义 Config.h:87
friend class EngineContext
定义 Config.h:95
static const WindowConfig & GetWindowConfig()
定义 Config.h:86
static bool Init()
定义 Config.h:84
Config(Config &&)=delete
bool init()
加载 settings.json
void loadFromJson(const Json &j)
从 JSON 对象加载配置
定义 AudioPlayer.h:10
nlohmann::json Json
定义 Config.h:10
动作绑定配置
定义 Config.h:32
std::vector< std::string > keys
绑定的按键名(SDL scancode 名,如 "Space"/"Left Shift")
定义 Config.h:33
轴绑定配置
定义 Config.h:42
std::vector< std::string > positive
正向按键
定义 Config.h:44
std::vector< std::string > negative
负向按键
定义 Config.h:43
输入映射配置
定义 Config.h:66
std::unordered_map< std::string, AxisBinding > axes
轴绑定
定义 Config.h:68
std::unordered_map< std::string, ActionBinding > actions
动作绑定
定义 Config.h:67
项目配置
定义 Config.h:13
std::string name
项目名称
定义 Config.h:14
窗口配置
定义 Config.h:18
unsigned int targetFPS
帧率上限
定义 Config.h:22
unsigned int height
逻辑分辨率高度
定义 Config.h:21
std::string title
窗口标题
定义 Config.h:19
unsigned int width
逻辑分辨率宽度
定义 Config.h:20