Extra2D/Extra2D/include/extra2d/core/scene-graph/Scene.h

121 lines
2.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <extra2d/core/scene-graph/Node.h>
#include <vector>
#include <string>
namespace extra2d {
/**
* @brief 场景类
*
* 管理场景图的根节点和场景生命周期。
* 参考 Cocos Creator 的 Scene 设计。
*/
class Scene : public Object {
public:
/**
* @brief 创建场景
* @param name 场景名称
* @return 场景引用
*/
static Ref<Scene> create(const std::string& name = "Scene");
/**
* @brief 构造函数
* @param name 场景名称
*/
explicit Scene(const std::string& name = "Scene");
/**
* @brief 析构函数
*/
~Scene() override;
// ==================== 根节点管理 ====================
/**
* @brief 获取根节点
* @return 根节点指针
*/
Node* getRoot();
/**
* @brief 获取根节点const 版本)
* @return 根节点指针
*/
const Node* getRoot() const;
// ==================== 节点查找 ====================
/**
* @brief 通过名称查找节点
* @param name 节点名称
* @return 找到的节点,如果未找到返回 nullptr
*/
Node* getNodeByName(const std::string& name);
/**
* @brief 通过标签查找节点
* @param tag 标签值
* @return 找到的节点,如果未找到返回 nullptr
*/
Node* getNodeByTag(i32 tag);
/**
* @brief 通过路径查找节点
* @param path 路径字符串
* @return 找到的节点,如果未找到返回 nullptr
*/
Node* getNodeByPath(const std::string& path);
// ==================== 更新和渲染 ====================
/**
* @brief 更新场景
* @param dt 帧间隔时间
*/
void update(f32 dt);
/**
* @brief 渲染场景
*/
void render();
/**
* @brief 晚期更新
* @param dt 帧间隔时间
*/
void lateUpdate(f32 dt);
// ==================== 生命周期 ====================
/**
* @brief 场景激活时调用
*/
void onActivate();
/**
* @brief 场景停用时调用
*/
void onDeactivate();
// ==================== 销毁 ====================
/**
* @brief 销毁场景
* @return 销毁成功返回 true
*/
bool destroy() override;
protected:
/**
* @brief 销毁时的回调
*/
void onDestroy() override;
Ref<Node> root_;
};
} // namespace extra2d