CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::Resource Class Referenceabstract

A base class that all resources must extend from. More...

#include <CeresEngine/Resource/Resource.hpp>

Inheritance diagram for CeresEngine::Resource:
CeresEngine::IReflectable CeresEngine::TResource< AudioClip > CeresEngine::TResource< Font > CeresEngine::TResource< Material > CeresEngine::TResource< Mesh > CeresEngine::TResource< ResourceObject< T > > CeresEngine::TResource< Scene > CeresEngine::TResource< Shader > CeresEngine::TResource< Terrain > CeresEngine::TResource< Text > CeresEngine::TResource< Texture > CeresEngine::TResource< T, Base >

Public Member Functions

virtual CE_DISABLE_WARNING_MISSING_OVERRIDE ::CeresEngine::ClassInfo getClassInfo () noexcept
 
virtual ::CeresEngine::ClassInfo getClassInfo () const noexcept
 
 Resource ()
 Default constructor for the Resource class.
 
 Resource (ResourceData &data)
 Creates a new Resource instance by passing a ResourceData instance.
 
virtual ~Resource () noexcept=default
 Resource virtual destructor.
 
ResourceManagergetResourceManager () const noexcept
 
HResource getResourceHandle () const noexcept
 Generates a hash for the provided type.
 
UUID getResourceID () const noexcept
 
HResource getParentResource () const noexcept
 A parent resource to which this resource is attached to.
 
SPtr< ResourceMetadatagetResourceMetadata () const noexcept
 A pointer to the user-defined resource metadata.
 
const PackagePtrgetPackage () const noexcept
 The package from which the resource was loaded from.
 
template<typename T = Resource>
SPtr< TgetShared () noexcept
 Gets a shared pointer to the resource.
 
template<typename T = Resource>
SPtr< const TgetShared () const noexcept
 Gets a shared pointer to the resource.
 
virtual const ResourceTypeInfogetResourceType () const noexcept=0
 Returns the resource type information descriptor.
 
 Resource (ResourceData &data, InputStream &dataStream)
 Creates a new resource by reading data from dataStream.
 
virtual void serialize (OutputStream &dataStream) const =0
 Serializes a resource by writing data to dataStream.
 
- Public Member Functions inherited from CeresEngine::IReflectable
virtual ~IReflectable () noexcept=default
 

Static Public Member Functions

template<typename Processor >
static constexpr void reflect (Processor &&RTTI)
 Executes the given processor for every field of the struct.
 

Protected Member Functions

HResourceStream createStream (const ResourceStreamFlags &flags=ResourceStreamFlag::Default)
 Creates a new resource stream.
 
void destroyStream (HResourceStream &stream)
 Destroys a stream.
 
void markAsDirty ()
 Marks the resource as dirty.
 

Private Attributes

ResourceDataPtr mData = nullptr
 A pointer to the ResourceData object provided by the manager.
 

Friends

class ResourceManager
 

Detailed Description

A base class that all resources must extend from.

Constructor & Destructor Documentation

◆ Resource() [1/3]

CeresEngine::Resource::Resource ( )

Default constructor for the Resource class.

◆ Resource() [2/3]

CeresEngine::Resource::Resource ( ResourceData data)
inlineexplicit

Creates a new Resource instance by passing a ResourceData instance.

This is usually done when constructing the resource using ResourceManager::create.

◆ ~Resource()

virtual CeresEngine::Resource::~Resource ( )
virtualdefaultnoexcept

Resource virtual destructor.

◆ Resource() [3/3]

CeresEngine::Resource::Resource ( ResourceData data,
InputStream dataStream 
)
inlineexplicit

Creates a new resource by reading data from dataStream.

Member Function Documentation

◆ createStream()

HResourceStream CeresEngine::Resource::createStream ( const ResourceStreamFlags flags = ResourceStreamFlag::Default)
protected

Creates a new resource stream.

Parameters
streamIDThe ID of the stream to be created or replaced.
Returns
An async task that will return the newly created resource stream.

◆ destroyStream()

void CeresEngine::Resource::destroyStream ( HResourceStream stream)
protected

Destroys a stream.

◆ getClassInfo() [1/2]

◆ getClassInfo() [2/2]

◆ getPackage()

const PackagePtr & CeresEngine::Resource::getPackage ( ) const
inlinenoexcept

The package from which the resource was loaded from.

Can be nullptr if the resource is not contained in a package.

◆ getParentResource()

HResource CeresEngine::Resource::getParentResource ( ) const
inlinenoexcept

A parent resource to which this resource is attached to.

This will ensure that the parent resource remains alive for as long as the children is referenced somewhere.

◆ getResourceHandle()

HResource CeresEngine::Resource::getResourceHandle ( ) const
inlinenoexcept

Generates a hash for the provided type.

Type must have a std::hash specialization.

Template Parameters
Tthe type to be hashed
Parameters
vThe value to be hashed
Returns
The hashed value

◆ getResourceID()

UUID CeresEngine::Resource::getResourceID ( ) const
inlinenoexcept

◆ getResourceManager()

ResourceManager * CeresEngine::Resource::getResourceManager ( ) const
inlinenoexcept

◆ getResourceMetadata()

SPtr< ResourceMetadata > CeresEngine::Resource::getResourceMetadata ( ) const
inlinenoexcept

A pointer to the user-defined resource metadata.

Can be freely changed by the user to store metadata for the package. The metadata will be serialized alongside the resource and can be loaded separatedly from the resource. This allows quickly fetching data from the resource and let the user determine if it needs to be loaded or not.

◆ getResourceType()

◆ getShared() [1/2]

template<typename T = Resource>
SPtr< const T > CeresEngine::Resource::getShared ( ) const
inlinenoexcept

Gets a shared pointer to the resource.

◆ getShared() [2/2]

template<typename T = Resource>
SPtr< T > CeresEngine::Resource::getShared ( )
inlinenoexcept

Gets a shared pointer to the resource.

◆ markAsDirty()

void CeresEngine::Resource::markAsDirty ( )
protected

Marks the resource as dirty.

◆ reflect()

template<typename Processor >
static constexpr void CeresEngine::Resource::reflect ( Processor &&  RTTI)
inlinestaticconstexpr

Executes the given processor for every field of the struct.

Parameters
RTTIThe processor to be ran for every field.

◆ serialize()

Friends And Related Symbol Documentation

◆ ResourceManager

Member Data Documentation

◆ mData

ResourceDataPtr CeresEngine::Resource::mData = nullptr
private

A pointer to the ResourceData object provided by the manager.

This object contains metadata and allow the stream to access information about itself.

The resource data is the main entry point to resource data streams and sub- resources.


The documentation for this class was generated from the following file: