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

资源基类 —— 所有引擎资产(Texture / Font / Audio / 自定义类型)的统一封装 更多...

#include <Resource.h>

类 Resource 继承关系图:
Audio Font Texture

Public 成员函数

 Resource (std::string path)
virtual ~Resource ()=default
 Resource (const Resource &)=delete
Resource & operator= (const Resource &)=delete
const std::string & getPath () const
ResourceState getState () const
bool isLoaded () const
const std::string & getError () const
 Failed 时的诊断信息
std::uint64_t getUuid () const
 会话级 uuid(进程内随机,不落盘)
virtual bool load ()=0
 加载底层句柄(子类实现;失败记录 m_error 并返回 false,内部已打日志)
virtual void release ()
 释放底层句柄(幂等;子类析构与管理器回收时调用;基类无句柄可释放)

Protected 属性

std::string m_path
std::string m_error
ResourceState m_state = ResourceState::Unloaded

详细描述

资源基类 —— 所有引擎资产(Texture / Font / Audio / 自定义类型)的统一封装

所有权模型:管理器独占(缓存持 unique_ptr),调用方借用指针。 缓存生命周期 = 整个引擎会话(Game::Destroy 统一销毁),销毁顺序集中受控 (音频先于 mixer、纹理先于 Renderer、再 SDL_Quit)——因此借用裸指针安全。 将来热重载应走 load() 原地重载(同一 wrapper 换内部句柄),借用指针保持有效。

扩展新资源类型:继承本类实现 load()/release(),再特化 ResourceManager.h 中的 ResourceTraits<T> 即接入缓存/uuid 查询/全量清理——管理器零改动。

构造及析构函数说明

◆ Resource() [1/2]

Resource ( std::string path)
inlineexplicit

◆ ~Resource()

virtual ~Resource ( )
virtualdefault

◆ Resource() [2/2]

Resource ( const Resource & )
delete

成员函数说明

◆ getError()

const std::string & getError ( ) const
inline

Failed 时的诊断信息

◆ getPath()

const std::string & getPath ( ) const
inline

◆ getState()

ResourceState getState ( ) const
inline

◆ getUuid()

std::uint64_t getUuid ( ) const
inline

会话级 uuid(进程内随机,不落盘)

◆ isLoaded()

bool isLoaded ( ) const
inline

◆ load()

virtual bool load ( )
pure virtual

加载底层句柄(子类实现;失败记录 m_error 并返回 false,内部已打日志)

在 Audio, Font , 以及 Texture 内被实现.

◆ operator=()

Resource & operator= ( const Resource & )
delete

◆ release()

virtual void release ( )
inlinevirtual

释放底层句柄(幂等;子类析构与管理器回收时调用;基类无句柄可释放)

被 Audio, Font , 以及 Texture 重载.

类成员变量说明

◆ m_error

std::string m_error
protected

◆ m_path

std::string m_path
protected

◆ m_state


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