ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
Toggle main menu visibility
载入中...
搜索中...
未找到
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
9
namespace
Shit
{
10
using
Json
= nlohmann::json;
11
13
struct
ProjectConfig
{
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
32
struct
ActionBinding
{
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
66
struct
InputMappingsConfig
{
67
std::unordered_map<std::string, ActionBinding>
actions
;
68
std::unordered_map<std::string, AxisBinding>
axes
;
69
};
70
77
class
SHIT_API
Config
{
78
public
:
79
bool
init
();
80
void
loadFromJson
(
const
Json
& j);
81
82
// --- 静态API ---
83
static
Config
&
GetInstance
();
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
Core.h
SHIT_API
#define SHIT_API
定义
Core.h:14
Log.h
Shit::Config::GetInstance
static Config & GetInstance()
Shit::Config::operator=
Config & operator=(const Config &)=delete
Shit::Config::operator=
Config & operator=(Config &&)=delete
Shit::Config::Config
Config(const Config &)=delete
Shit::Config::GetProjectConfig
static const ProjectConfig & GetProjectConfig()
定义
Config.h:85
Shit::Config::GetInputMappingsConfig
static const InputMappingsConfig & GetInputMappingsConfig()
定义
Config.h:87
Shit::Config::EngineContext
friend class EngineContext
定义
Config.h:95
Shit::Config::GetWindowConfig
static const WindowConfig & GetWindowConfig()
定义
Config.h:86
Shit::Config::Init
static bool Init()
定义
Config.h:84
Shit::Config::Config
Config(Config &&)=delete
Shit::Config::init
bool init()
加载 settings.json
Shit::Config::loadFromJson
void loadFromJson(const Json &j)
从 JSON 对象加载配置
Shit
定义
AudioPlayer.h:10
Shit::Json
nlohmann::json Json
定义
Config.h:10
Shit::ActionBinding
动作绑定配置
定义
Config.h:32
Shit::ActionBinding::keys
std::vector< std::string > keys
绑定的按键名(SDL scancode 名,如 "Space"/"Left Shift")
定义
Config.h:33
Shit::AxisBinding
轴绑定配置
定义
Config.h:42
Shit::AxisBinding::positive
std::vector< std::string > positive
正向按键
定义
Config.h:44
Shit::AxisBinding::negative
std::vector< std::string > negative
负向按键
定义
Config.h:43
Shit::InputMappingsConfig
输入映射配置
定义
Config.h:66
Shit::InputMappingsConfig::axes
std::unordered_map< std::string, AxisBinding > axes
轴绑定
定义
Config.h:68
Shit::InputMappingsConfig::actions
std::unordered_map< std::string, ActionBinding > actions
动作绑定
定义
Config.h:67
Shit::ProjectConfig
项目配置
定义
Config.h:13
Shit::ProjectConfig::name
std::string name
项目名称
定义
Config.h:14
Shit::WindowConfig
窗口配置
定义
Config.h:18
Shit::WindowConfig::targetFPS
unsigned int targetFPS
帧率上限
定义
Config.h:22
Shit::WindowConfig::height
unsigned int height
逻辑分辨率高度
定义
Config.h:21
Shit::WindowConfig::title
std::string title
窗口标题
定义
Config.h:19
Shit::WindowConfig::width
unsigned int width
逻辑分辨率宽度
定义
Config.h:20
include
ShitEngine
Core
Config.h
制作者
1.17.0