This repository has been archived by the owner on May 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Creating a Resource Type
adam4813 edited this page Mar 2, 2014
·
1 revision
Creating a resource is straight forward and takes 3 steps.
- Include
ResourceSystem.h
and inherit fromResourceBase
- Implement the virtual method
bool Initialize(const std::vector<Property> &properties);
- Add the following methods in the header file:
template <> inline const char* GetTypeName<MyType>() { return "MyType"; } // Human readable name
template <> inline const unsigned int GetTypeID<MyTpe>() { return 1000; } // ID number used internally
- Call
resource::ResourceSystem::GetInstace()->Register<MyType>();
After you have setup your resource type you can load or create resources of that type.
If you can provide the type at compile time, you can call resource::ResourceSystem::GetInstace()->Create<MyType>(std::string name, std::vector<Property> properties);
where name is the name of the resource, and properties is the creation properties.
If you don't know the type at compile time and instead load it at runtime, you can call
-
resource::ResourceSystem::GetInstace()->GetTypeIDFromName(std::string name);
Where name is the name of the type defined in GetTypeName. -
resource::ResourceSystem::GetInstace()->Load(ID, std::string name, std::vector<Property> properties);
Where ID is the ID retrieved in the above step, name is the name of the resource, and properties is the creation properties.
If the resource is already loaded you can call resource::ResourceSystem::GetInstace()->Get<MyType>(std::string name);
Where name is the name of the resource.