49 #ifndef __CU_GENERIC_LOADER_H__
50 #define __CU_GENERIC_LOADER_H__
51 #include <cugl/assets/CULoader.h>
52 #include <cugl/assets/CUAsset.h>
94 if (asset !=
nullptr) {
95 success = asset->materialize();
101 if (callback !=
nullptr) {
102 callback(key,success);
126 virtual bool read(
const std::string& key,
const std::string& source,
133 bool success =
false;
134 if (
_loader ==
nullptr || !async) {
135 std::shared_ptr<T> asset = std::make_shared<T>();
136 if (asset->preload(source)) {
141 std::shared_ptr<T> asset = std::make_shared<T>();
142 if (!asset->preload(source)) {
177 virtual bool read(
const std::shared_ptr<JsonValue>& json,
179 std::string key = json->key();
185 bool success =
false;
186 if (
_loader ==
nullptr || !async) {
187 std::shared_ptr<T> asset = std::make_shared<T>();
188 if (asset->preload(json)) {
193 std::shared_ptr<T> asset = std::make_shared<T>();
194 if (!asset->preload(json)) {
209 #pragma mark Constructors
244 static std::shared_ptr<GenericLoader<T>>
alloc() {
245 std::shared_ptr<GenericLoader<T>> result = std::make_shared<GenericLoader<T>>();
246 return (result->init() ? result :
nullptr);
261 std::shared_ptr<GenericLoader> result = std::make_shared<GenericLoader>();
262 return (result->init(threads) ? result :
nullptr);
std::shared_ptr< ThreadPool > _loader
Definition: CULoader.h:102
static std::shared_ptr< GenericLoader< T > > alloc(const std::shared_ptr< GenericLoader< T >> &threads)
Definition: CUGenericLoader.h:260
GenericLoader()
Definition: CUGenericLoader.h:216
std::unordered_set< std::string > _queue
Definition: CULoader.h:681
std::unordered_map< std::string, std::shared_ptr< T > > _assets
Definition: CULoader.h:678
std::function< void(const std::string &key, bool success)> LoaderCallback
Definition: CULoader.h:81
static std::shared_ptr< GenericLoader< T > > alloc()
Definition: CUGenericLoader.h:244
static Application * get()
Definition: CUApplication.h:247
virtual bool read(const std::shared_ptr< JsonValue > &json, LoaderCallback callback, bool async) override
Definition: CUGenericLoader.h:177
Uint32 schedule(std::function< bool()> callback, Uint32 time=0)
virtual bool read(const std::string &key, const std::string &source, LoaderCallback callback, bool async) override
Definition: CUGenericLoader.h:126
Definition: CULoader.h:675
Definition: CUGenericLoader.h:69
Definition: CUAnimationNode.h:52
bool materialize(const std::string &key, const std::shared_ptr< T > &asset, LoaderCallback callback)
Definition: CUGenericLoader.h:92
void dispose() override
Definition: CUGenericLoader.h:228