Cornell Cocos
Cornell Extensions to Cocos2d
CUAssetManager.h
1 //
2 // CUAssetManager.h
3 // Cornell Extensions to Cocos2D
4 //
5 // This module provides a singleton class to support asset management. Assets
6 // should always be managed by a central loader. Cocos2D appears to have these
7 // things all over the place. This is a way to centralize everything.
8 //
9 // More importantly, this asset loader allows for scene management, which is not
10 // something available in the various asset loaders in Cocos2D. Scene management
11 // allows you to attach assets to a scene, and load and unload them for that scene.
12 //
13 // Author: Walker White
14 // Version: 12/3/15
15 //
16 #ifndef __CU_ASSET_MANAGER_H__
17 #define __CU_ASSET_MANAGER_H__
18 
19 #include <vector>
20 #include <cocos2d.h>
21 #include "CUSceneManager.h"
22 
23 using namespace std;
24 
25 NS_CC_BEGIN
26 
27 #pragma mark -
28 #pragma mark Asset Manager
29 
46 class CC_DLL AssetManager {
47 protected:
50 
52  std::vector<SceneManager*> _managers;
53 
55  int _scene;
56 
57 public:
58 #pragma Singleton Access
59 
64  static void init();
65 
72  static void shutdown();
73 
79  static AssetManager* getInstance() { return _gManager; }
80 
81 
82 #pragma Scene Management
83 
90  int createScene();
91 
97  void startScene(int scene);
98 
102  void startAll();
103 
109  void stopScene(int scene);
110 
114  void stopAll();
115 
125  void deleteScene(int scene);
126 
134  void deleteAll();
135 
144  bool hasScene(int scene) const { return scene < _managers.size() && _managers[scene] != nullptr; }
145 
146 
147 #pragma Scene Access
148 
156  int getCurrentIndex() const { return _scene; }
157 
165  void setCurrentIndex(int scene) { _scene = scene; }
166 
174  SceneManager* getCurrent() const { return (_scene >= 0 ? _managers.at(_scene) : nullptr); }
175 
185  SceneManager* at(int scene) const { return _managers.at(scene); }
186 
196  SceneManager* operator[](int scene) const { return _managers.at(scene); }
197 
198 private:
200  CC_DISALLOW_COPY_AND_ASSIGN(AssetManager);
201 
205  AssetManager() : _scene(-1) {}
206 
212  ~AssetManager() { stopAll(); deleteAll();}
213 };
214 
215 NS_CC_END
216 #endif /* defined(__CU_ASSET_MANAGER_H__) */
static AssetManager * getInstance()
Definition: CUAssetManager.h:79
std::vector< SceneManager * > _managers
Definition: CUAssetManager.h:52
Definition: CUSceneManager.h:33
SceneManager * operator[](int scene) const
Definition: CUAssetManager.h:196
bool hasScene(int scene) const
Definition: CUAssetManager.h:144
SceneManager * getCurrent() const
Definition: CUAssetManager.h:174
SceneManager * at(int scene) const
Definition: CUAssetManager.h:185
static AssetManager * _gManager
Definition: CUAssetManager.h:49
void setCurrentIndex(int scene)
Definition: CUAssetManager.h:165
int getCurrentIndex() const
Definition: CUAssetManager.h:156
Definition: CUAssetManager.h:46
int _scene
Definition: CUAssetManager.h:55