40 Resources::ResourceId
CreateResource(
const ResourceName& res, std::function<
void(
const Resources::ResourceId)> success =
nullptr, std::function<
void(
const Resources::ResourceId)> failed =
nullptr,
bool immediate =
false,
bool stream =
true);
42 Resources::ResourceId
CreateResource(
const ResourceName& res,
const Util::StringAtom& tag, std::function<
void(
const Resources::ResourceId)> success =
nullptr, std::function<
void(
const Resources::ResourceId)> failed =
nullptr,
bool immediate =
false,
bool stream =
true);
44 template<
class METADATA> Resources::ResourceId
CreateResource(
const ResourceName& res,
const METADATA& metaData, std::function<
void(
const Resources::ResourceId)> success =
nullptr, std::function<
void(
const Resources::ResourceId)> failed =
nullptr,
bool immediate =
false,
bool stream =
true);
46 template<
class METADATA> Resources::ResourceId
CreateResource(
const ResourceName& res,
const METADATA& metaData,
const Util::StringAtom& tag, std::function<
void(
const Resources::ResourceId)> success =
nullptr, std::function<
void(
const Resources::ResourceId)> failed =
nullptr,
bool immediate =
false,
bool stream =
true);
54 void ReloadResource(
const ResourceName& res, std::function<
void(
const Resources::ResourceId)> success =
nullptr, std::function<
void(
const Resources::ResourceId)> failed =
nullptr);
56 void SetMinLod(
const ResourceId&
id,
float lod,
bool immediate);
58 void CreateResourceListener(
const ResourceId&
id, std::function<
void(
const Resources::ResourceId)> success, std::function<
void(
const Resources::ResourceId)> failed =
nullptr);
72 bool HasResource(
const Resources::ResourceId
id)
const;
102inline Resources::ResourceId
105 , std::function<
void(
const Resources::ResourceId)> success
106 , std::function<
void(
const Resources::ResourceId)> failed
111 return this->
CreateResource(
id,
"", success, failed, immediate, stream);
119inline Resources::ResourceId
123 , std::function<
void(
const Resources::ResourceId)> success
124 , std::function<
void(
const Resources::ResourceId)> failed
131 IndexT i = this->extensionMap.FindIndex(ext);
136 Resources::ResourceId
id = loader->CreateResource(res,
nullptr, 0, tag, success, failed, immediate, stream);
143template<
class METADATA>
144inline Resources::ResourceId
147 ,
const METADATA& metaData
148 , std::function<
void(
const Resources::ResourceId)> success
149 , std::function<
void(
const Resources::ResourceId)> failed
154 return this->
CreateResource(res, metaData,
"", success, failed, immediate, stream);
160template<
class METADATA>
161inline Resources::ResourceId
164 ,
const METADATA& metaData
166 , std::function<
void(
const Resources::ResourceId)> success
167 , std::function<
void(
const Resources::ResourceId)> failed
179 Resources::ResourceId
id = loader->CreateResource(res, &metaData,
sizeof(METADATA), tag, success, failed, immediate, stream);
196 loader->ReloadResource(res, success, failed);
206 const Ids::Id8 loaderid =
id.loaderIndex;
213 loader->SetMinLod(
id, lod, immediate);
221 const ResourceId&
id,
222 std::function<
void(
const Resources::ResourceId)> success,
223 std::function<
void(
const Resources::ResourceId)> failed
227 const Ids::Id8 loaderid =
id.loaderIndex;
233 loader->CreateListener(
id, success, failed);
244 const Ids::Id8 loaderid =
id.loaderIndex;
251 loader->DiscardResource(
id);
263 return loader->GetName(
id.resourceId);
275 return loader->GetTag(
id.resourceId);
287 return loader->GetState(
id.resourceId);
299 return loader->GetUsage(
id.resourceId);
308 if (this->
loaders.Size() <=
id.loaderIndex)
return false;
311 if (loader->HasResource(
id))
return true;
319inline const Resources::ResourceId
323 for (i = 0; i < this->
loaders.Size(); i++)
325 Resources::ResourceId
id = this->
loaders[i]->GetId(name);
326 if (
id != Resources::ResourceId::Invalid())
return id;
328 return Resources::ResourceId::Invalid();
334template <
class POOL_TYPE>
338 static_assert(std::is_base_of<ResourceLoader, POOL_TYPE>::value,
"Type requested is not a stream pool");
342 return static_cast<POOL_TYPE*
>(this->
loaders[i].get());
345 n_error(
"No loader registered for this type");
352inline Resources::ResourceId
356 , std::function<
void(
const Resources::ResourceId)> success =
nullptr
357 , std::function<
void(
const Resources::ResourceId)> failed =
nullptr
358 ,
bool immediate =
false
362 return ResourceServer::Instance()->CreateResource(res, tag, success, failed, immediate, stream);
368template <
class METADATA>
369inline Resources::ResourceId
372 ,
const METADATA& metaData
374 , std::function<
void(
const Resources::ResourceId)> success =
nullptr
375 , std::function<
void(
const Resources::ResourceId)> failed =
nullptr
376 ,
bool immediate =
false
380 return ResourceServer::Instance()->CreateResource(res, metaData, tag, success, failed, immediate, stream);
389 , std::function<
void(
const Resources::ResourceId)> success
390 , std::function<
void(
const Resources::ResourceId)> failed =
nullptr
393 return ResourceServer::Instance()->CreateResourceListener(
id, success, failed);
400SetMinLod(
const ResourceId&
id,
float lod,
bool immediate)
402 return ResourceServer::Instance()->SetMinLod(
id, lod, immediate);
411 ResourceServer::Instance()->DiscardResource(
id);
420 return ResourceServer::Instance()->ReloadResource(res);
429 ResourceServer::Instance()->WaitForLoaderThread();
435template <
class POOL_TYPE>
439 static_assert(std::is_base_of<ResourceLoader, POOL_TYPE>::value,
"Template argument is not a ResourceCache type!");
440 return ResourceServer::Instance()->GetStreamLoader<POOL_TYPE>();
The common base class of Nebula.
Definition refcounted.h:38
Nebula's runtime type information for one class.
Definition rtti.h:27
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
const Ptr< DERIVED > & downcast() const
type-safe downcast operator to other smart pointer
Definition ptr.h:392
State
Definition resource.h:26
Definition resourceloader.h:60
Definition resourceserver.h:22
void SetMinLod(const ResourceId &id, float lod, bool immediate)
stream in a new LOD
Definition resourceserver.h:203
__DeclareClass(ResourceServer)
void Close()
close manager
Definition resourceserver.cc:53
__DeclareInterfaceSingleton(ResourceServer)
void CreateResourceListener(const ResourceId &id, std::function< void(const Resources::ResourceId)> success, std::function< void(const Resources::ResourceId)> failed=nullptr)
Create single-fire listener for resource. When resource is loaded, the callbacks will be invoked and ...
Definition resourceserver.h:220
void Open()
open manager
Definition resourceserver.cc:41
Resources::ResourceId CreateResource(const ResourceName &res, std::function< void(const Resources::ResourceId)> success=nullptr, std::function< void(const Resources::ResourceId)> failed=nullptr, bool immediate=false, bool stream=true)
create a new resource (stream-managed), which will be loaded at some later point, if not already load...
ResourceServer()
constructor
Definition resourceserver.cc:22
Util::Dictionary< Util::StringAtom, IndexT > extensionMap
Definition resourceserver.h:90
Util::Dictionary< const Core::Rtti *, IndexT > typeMap
Definition resourceserver.h:91
Resources::ResourceId CreateResource(const ResourceName &res, const Util::StringAtom &tag, std::function< void(const Resources::ResourceId)> success=nullptr, std::function< void(const Resources::ResourceId)> failed=nullptr, bool immediate=false, bool stream=true)
overload which also takes an identifying tag, which is used to group-discard resources
const Resources::ResourceId GetId(const Resources::ResourceName &name) const
get id from name
Definition resourceserver.h:320
void DiscardResources(const Util::StringAtom &tag)
discard all resources by tag (stream-managed)
Definition resourceserver.cc:139
bool HasResource(const Resources::ResourceId id) const
check if resource id is valid
Definition resourceserver.h:306
void RegisterStreamLoader(const Util::StringAtom &ext, const Core::Rtti &loaderClass)
register a stream pool, which takes an extension and the RTTI of the resource type to create
Definition resourceserver.cc:93
void DiscardResource(const Resources::ResourceId res)
discard resource (stream-managed)
Definition resourceserver.h:241
virtual ~ResourceServer()
destructor
Definition resourceserver.cc:31
Core::Rtti * GetType(const Resources::ResourceId id)
get type of resource pool this resource was allocated with
Definition resourceserver.cc:173
void ReloadResource(const ResourceName &res, std::function< void(const Resources::ResourceId)> success=nullptr, std::function< void(const Resources::ResourceId)> failed=nullptr)
reload resource
Definition resourceserver.h:187
const Resources::ResourceName GetName(const Resources::ResourceId id) const
get resource name
Definition resourceserver.h:258
Util::Array< Ptr< ResourceLoader > > loaders
Definition resourceserver.h:92
const Resource::State GetState(const Resources::ResourceId id) const
get resource state
Definition resourceserver.h:282
static int32_t UniquePoolCounter
Definition resourceserver.h:94
const SizeT GetUsage(const Resources::ResourceId id) const
get usage
Definition resourceserver.h:294
bool HasPendingResources()
returns true if there are pending resources in-flight
Definition resourceserver.cc:153
const Util::StringAtom GetTag(const Resources::ResourceId id) const
get tag resource was first registered with
Definition resourceserver.h:270
void LoadDefaultResources()
goes through all pools and sets up their default resources
Definition resourceserver.cc:110
POOL_TYPE * GetStreamLoader() const
get stream pool for later use
Definition resourceserver.h:336
bool open
Definition resourceserver.h:89
void WaitForLoaderThread()
Wait for all loader threads.
Definition resourceserver.cc:188
Nebula's dynamic array class.
Definition array.h:60
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
IndexT FindIndex(const KEYTYPE &key) const
find index of key/value pair (InvalidIndex if doesn't exist)
Definition dictionary.h:355
VALUETYPE & ValueAtIndex(IndexT index)
access to value at given index
Definition dictionary.h:408
A StringAtom.
Definition stringatom.h:22
String AsString() const
get containted string as string object (SLOW!!!)
Definition stringatom.h:372
void __cdecl n_error(const char *msg,...)
This function is called when a serious situation is encountered which requires abortion of the applic...
Definition debug.cc:138
#define n_assert_fmt(exp, msg,...)
Definition debug.h:53
#define n_assert(exp)
Definition debug.h:50
uint8_t Id8
Definition id.h:141
A resource is a container for some type of file which is loaded.
Definition resource.cc:9
Resources::ResourceId CreateResource(const ResourceName &res, const Util::StringAtom &tag, std::function< void(const Resources::ResourceId)> success=nullptr, std::function< void(const Resources::ResourceId)> failed=nullptr, bool immediate=false, bool stream=true)
Definition resourceserver.h:353
POOL_TYPE * GetStreamLoader()
Definition resourceserver.h:437
void DiscardResource(const Resources::ResourceId id)
Definition resourceserver.h:409
@ Update
Definition resourceloader.h:53
void WaitForLoaderThread()
Definition resourceserver.h:427
void ReloadResource(const ResourceName &res)
Definition resourceserver.h:418
Util::StringAtom ResourceName
Definition resourceid.h:33
void SetMinLod(const ResourceId &id, float lod, bool immediate)
Definition resourceserver.h:400
void CreateResourceListener(const ResourceId &id, std::function< void(const Resources::ResourceId)> success, std::function< void(const Resources::ResourceId)> failed=nullptr)
Definition resourceserver.h:387
id
Definition resourceid.h:37
Nebula's universal string class.
Definition string.h:50
const char * AsCharPtr() const
return contents as character pointer
Definition string.h:540
String GetFileExtension() const
get filename extension without dot
Definition string.cc:964
static const int InvalidIndex
Definition types.h:54
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48