本文原创版权归 博客园 flagship 所有,如有转载,请详细标明作者及原文出处,以示尊重!
作者:flagship
原文:3D引擎多线程:资源异步加载
class _DLL_Export Resource : public Base
{
public:
Resource();
virtual ~Resource();
// 是否过期
bool IsOutOfDate();
public:
// 是否就绪
virtual bool IsReady();
// 读取资源
virtual bool Load();
// 释放资源
virtual bool Release();
// 缓存资源
virtual bool Cache();
// 释放缓存
virtual void UnCache();
protected:
// 加载标记
bool m_bLoad;
// 完成标记
bool m_bReady;
private:
};
template <class T>
class _DLL_Export ResHandle
{
public:
ResHandle() { m_pResource = NULL; }
virtual ~ResHandle() {}
// 设置资源路径
void SetPath( wstring szPath )
{
Resource * pResource = ResourceManager::GetSingleton()->GetResource( Key( szPath ) );
if ( pResource != NULL )
{
m_pResource = (T *) pResource;
}
else
{
m_pResource = new T;
m_pResource->SetPath( szPath );
ResourceManager::GetSingleton()->AddResource( m_pResource );
}
}
// 模板实体类指针
T * GetImpliment() { return (T *) m_pResource; }
T * operator-> () { return (T *) m_pResource; }
protected:
// 模板实体类指针
Resource * m_pResource;
private:
};