ShitEngine
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
Scene类 参考

场景类 更多...

#include <Scene.h>

Public 成员函数

 Scene (const std::string &name)
 ~Scene ()
 Scene (const Scene &)=delete
Sceneoperator= (const Scene &)=delete
 Scene (Scene &&)=delete
Sceneoperator= (Scene &&)=delete
virtual void init ()
 注册默认系统(BehaviorSystem + RenderSystem + UIRenderSystem),幂等
void update ()
 更新所有 System + 处理延迟操作
virtual void destroy ()
 销毁所有对象与系统
bool hasSystems () const
 是否已注册任何 System(SceneManager 用于自动初始化,防止漏调 init() 导致空场景)
void addGameObject (std::unique_ptr< GameObject > &&gameObject)
 延迟添加 GameObject(帧末生效)
GameObjectcreateGameObject (const std::string &name)
 创建并添加 GameObject
GameObjectinstantiate (const Prefab &prefab, const std::string &name="")
 从预制体实例化
void removeGameObject (GameObject *gameObject)
 按指针标记销毁
void removeGameObjectByName (const std::string &name)
 按名称标记销毁
bool registerComponent (Component *component)
 组件挂载广播(组件 onAttach 调用)。分发给可处理的系统,返回是否有系统认领。
void unregisterComponent (Component *component)
 组件卸下广播(组件 onDetach 调用)。
template<typename T>
T * registerSystem ()
template<typename T>
void unregisterSystem ()
template<typename T>
T * getSystem ()
template<typename T>
bool hasSystem ()
const std::string & getName () const
std::vector< std::unique_ptr< GameObject > > & getGameObjects ()
void setName (const std::string &name)

详细描述

场景类

场景是游戏世界的容器,管理所有 GameObject、System 的生命周期。 通过 SceneManager 的栈机制实现场景切换(主菜单→游戏→暂停)。

使用方式: auto scene = std::make_unique<Scene>("level1"); scene->init(); // 注册默认 BehaviorSystem + RenderSystem + UIRenderSystem auto* player = scene->createGameObject("player"); SceneManager::LoadScene(std::move(scene));

构造及析构函数说明

◆ Scene() [1/3]

Scene ( const std::string & name)
explicit

◆ ~Scene()

~Scene ( )

◆ Scene() [2/3]

Scene ( const Scene & )
delete

◆ Scene() [3/3]

Scene ( Scene && )
delete

成员函数说明

◆ addGameObject()

void addGameObject ( std::unique_ptr< GameObject > && gameObject)

延迟添加 GameObject(帧末生效)

◆ createGameObject()

GameObject * createGameObject ( const std::string & name)

创建并添加 GameObject

◆ destroy()

virtual void destroy ( )
virtual

销毁所有对象与系统

◆ getGameObjects()

std::vector< std::unique_ptr< GameObject > > & getGameObjects ( )
inline

◆ getName()

const std::string & getName ( ) const
inline

◆ getSystem()

template<typename T>
T * getSystem ( )
inline

◆ hasSystem()

template<typename T>
bool hasSystem ( )
inline

◆ hasSystems()

bool hasSystems ( ) const
inline

是否已注册任何 System(SceneManager 用于自动初始化,防止漏调 init() 导致空场景)

◆ init()

virtual void init ( )
virtual

注册默认系统(BehaviorSystem + RenderSystem + UIRenderSystem),幂等

◆ instantiate()

GameObject * instantiate ( const Prefab & prefab,
const std::string & name = "" )

从预制体实例化

◆ operator=() [1/2]

Scene & operator= ( const Scene & )
delete

◆ operator=() [2/2]

Scene & operator= ( Scene && )
delete

◆ registerComponent()

bool registerComponent ( Component * component)

组件挂载广播(组件 onAttach 调用)。分发给可处理的系统,返回是否有系统认领。

◆ registerSystem()

template<typename T>
T * registerSystem ( )
inline

◆ removeGameObject()

void removeGameObject ( GameObject * gameObject)

按指针标记销毁

◆ removeGameObjectByName()

void removeGameObjectByName ( const std::string & name)

按名称标记销毁

◆ setName()

void setName ( const std::string & name)
inline

◆ unregisterComponent()

void unregisterComponent ( Component * component)

组件卸下广播(组件 onDetach 调用)。

◆ unregisterSystem()

template<typename T>
void unregisterSystem ( )
inline

◆ update()

void update ( )

更新所有 System + 处理延迟操作


该类的文档由以下文件生成: