12 #ifndef __CU_SCENE_MANAGER_H__
13 #define __CU_SCENE_MANAGER_H__
14 #include <unordered_map>
21 #pragma mark Scene Manager
47 #pragma mark Activation/Deactivation
96 #pragma mark Loader Attachment
112 size_t hash =
typeid(T).hash_code();
113 auto it = _handlers.find(hash);
114 if (it != _handlers.end()) {
117 _handlers[hash] = loader;
119 if (_active && !loader->
isActive()) {
121 }
else if (!_active && loader->
isActive()) {
136 size_t hash =
typeid(T).hash_code();
137 return _handlers.find(hash) != _handlers.end();
151 size_t hash =
typeid(T).hash_code();
152 auto it = _handlers.find(hash);
153 if (it == _handlers.end()) {
156 it->second->release();
157 _handlers.erase(hash);
170 for(
auto it = _handlers.begin(); it != _handlers.end(); ++it) {
171 it->second->release();
185 size_t hash =
typeid(T).hash_code();
186 auto it = _handlers.find(hash);
187 if (it == _handlers.end()) {
188 CCASSERT(
false,
"No loader assigned for given type");
196 #pragma mark Loading/Unloading
209 size_t loadCount()
const;
224 size_t waitCount()
const;
252 size_t size = loadCount()+waitCount();
253 return (size == 0 ? 0.0f : ((
float)loadCount())/size);
266 T*
get(std::string key)
const {
267 size_t hash =
typeid(T).hash_code();
268 auto it = _handlers.find(hash);
269 if (it == _handlers.end()) {
270 CCASSERT(
false,
"No loader assigned for given type");
274 return ((
Loader<T>*)it->second)->get(key);
292 T*
load(std::string key, std::string source) {
293 size_t hash =
typeid(T).hash_code();
294 auto it = _handlers.find(hash);
295 if (it != _handlers.end()) {
297 return ref->
load(key,source);
300 CCASSERT(
false,
"No loader assigned for given type");
319 size_t hash =
typeid(T).hash_code();
320 auto it = _handlers.find(hash);
321 if (it != _handlers.end()) {
322 it->second->loadAsync(key,source);
326 CCASSERT(
false,
"No loader assigned for given type");
341 size_t hash =
typeid(T).hash_code();
342 auto it = _handlers.find(hash);
343 if (it != _handlers.end()) {
344 it->second->unload(key);
348 CCASSERT(
false,
"No loader assigned for given type");
359 for(
auto it = _handlers.begin(); it != _handlers.end(); ++it) {
360 it->second->unloadAll();
365 CC_CONSTRUCTOR_ACCESS:
366 #pragma mark Initializers
377 ~
SceneManager() {
if (_active) { stop(); } detachAll(); }
virtual void start()
Definition: CULoader.h:66
T * load(std::string key, std::string source)
Definition: CUSceneManager.h:292
std::unordered_map< size_t, BaseLoader * > _handlers
Definition: CUSceneManager.h:44
bool detach()
Definition: CUSceneManager.h:150
void loadAsync(std::string key, std::string source)
Definition: CUSceneManager.h:318
Definition: CUSceneManager.h:33
bool _active
Definition: CUSceneManager.h:41
bool isAttached()
Definition: CUSceneManager.h:135
bool isComplete() const
Definition: CUSceneManager.h:235
bool isActive() const
Definition: CUSceneManager.h:93
bool attach(Loader< T > *loader)
Definition: CUSceneManager.h:111
void detachAll()
Definition: CUSceneManager.h:169
virtual void stop()
Definition: CULoader.h:82
Definition: CULoader.h:237
float progress() const
Definition: CUSceneManager.h:251
Loader< T > * access()
Definition: CUSceneManager.h:184
void unloadAll()
Definition: CUSceneManager.h:358
virtual T * load(std::string key, std::string source)
Definition: CULoader.h:310
bool isActive() const
Definition: CULoader.h:92
void unload(std::string key)
Definition: CUSceneManager.h:340