|
ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
|
引擎上下文:持有全部子系统实例 更多...
#include <EngineContext.h>
Public 成员函数 | |
| EngineContext ()=default | |
| ~EngineContext ()=default | |
| EngineContext (const EngineContext &)=delete | |
| EngineContext & | operator= (const EngineContext &)=delete |
| EngineContext (EngineContext &&)=delete | |
| EngineContext & | operator= (EngineContext &&)=delete |
静态 Public 成员函数 | |
| static EngineContext & | current () |
| 当前活动上下文;未设置时懒创建一个进程默认上下文(与旧单例行为一致) | |
| static void | setCurrent (EngineContext *ctx) |
| 切换到指定上下文(多实例/编辑器预览用) | |
| static void | resetCurrent () |
| 恢复进程默认上下文 | |
引擎上下文:持有全部子系统实例
替代原先 12 个进程级单例的"引擎只能有一个实例"限制。一个进程可创建多个 EngineContext(编辑器进程内预览、多实例对比、单元测试),每个拥有独立的 Window/Input/Renderer/SceneManager 等完整子系统。静态门面(如 Shit::Input::IsKeyDown)转发到当前上下文(EngineContext::current())。
用法: // 单实例(默认,行为与旧单例一致)——无需手动创建,第一次 current() 时懒创建 Shit::Game::Init(); Shit::Game::Run(); Shit::Game::Destroy();
// 多实例(编辑器预览) Shit::EngineContext preview; Shit::EngineContext::setCurrent(&preview); Shit::Game::Init(); // 初始化 preview 的子系统 // ... 运行 ... Shit::Game::Destroy(); Shit::EngineContext::setCurrent(&editorCtx); // 切回编辑器上下文
|
default |
|
default |
|
delete |
|
delete |
|
static |
当前活动上下文;未设置时懒创建一个进程默认上下文(与旧单例行为一致)
|
delete |
|
delete |
|
static |
恢复进程默认上下文
|
static |
切换到指定上下文(多实例/编辑器预览用)
| AudioPlayer audio |
| Config config |
| EventBus eventBus |
| Game game |
| Input input |
| Renderer renderer |
| ResourceManager resources |
| SceneManager sceneManager |
| TextInputGate textInputGate |
| Time time |
| TypeRegistry typeRegistry |
| Window window |