SpiecsEngine
 
Loading...
Searching...
No Matches

◆ Load()

template<typename T >
template<typename Ty , typename ... Args>
std::shared_ptr< T > Spices::ResourcePool< T >::Load ( const std::string & path,
Args... args )
inlinestatic

Load a resource by path. When we need a resource, we call this API. Load if resource is not found.

Template Parameters
TyResource specific Class.
ArgsResource Construct Parameters.
Parameters
[in]pathResource file path in disk.
Returns
Returns resource smart pointer.

Definition at line 120 of file ResourcePool.h.

121 {
123
124 {
125 std::unique_lock<std::shared_mutex> lock(m_Mutex);
126
127 if (m_Resources.find(path) == m_Resources.end())
128 {
129 std::function<std::any()> fn = [&]() -> std::any {
130 T* inst = new Ty(std::forward<Args>(args)...);
131 return std::shared_ptr<T>(inst);
132 };
133
134 m_Resources[path] = std::make_unique<Resource>(fn);
135 }
136
137 }
138
139 return m_Resources[path]->GetResource<T>();
140 }
#define SPICES_PROFILE_ZONE
static std::unordered_map< std::string, std::unique_ptr< Resource > > m_Resources
Static variable stores all specific resources in a basic type Pool.
static std::shared_mutex m_Mutex
Mutex for this pool.
Spices::ClassTraitsTest inst