You.i Engine
YiAssetLoader.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2017. All rights reserved.
2 #ifndef _YI_ASSET_LOADER_H_
3 #define _YI_ASSET_LOADER_H_
4 
5 #include "asset/YiAssetLocator.h"
8 #include "thread/YiMutex.h"
9 
10 class CYIDecoderThread;
11 class CYIAsset;
12 class CYIAssetDecoder;
13 class CYIAssetLoadParams;
15 
40 {
41  friend class CYIDecoderThread;
42 
43 public:
44 
51  {
52  public:
53  virtual ~DecodeListener() {}
54 
65  virtual void OnDecodeComplete(int32_t nJobID, std::shared_ptr<CYIAsset> pAsset, int32_t nLoadStatus, void *pListenerPrivate) = 0;
66  };
67 
73 
77  virtual ~CYIAssetLoader();
78 
82  void AddDecoder(std::unique_ptr<CYIAssetDecoder> pDecoder);
83 
87  std::unique_ptr<CYIAssetDecoder> RemoveDecoder(const CYIAssetDecoder *pDecoder);
88 
92  static void SetAssetLocator(const CYIAssetLocator &rLocator);
93 
97  static const CYIAssetLocator &GetAssetLocator();
98 
99 
103  uint32_t GetDecoderCount();
104 
111  std::shared_ptr<CYIAsset> Load(const CYIRuntimeTypeInfo &assetType, const CYIString &filename, CYIAssetLoadParams *pLoadParams = nullptr);
112 
117  std::shared_ptr<CYIAsset> LoadFromPath(const CYIRuntimeTypeInfo &assetType, const CYIString &path, CYIAssetLoadParams *pLoadParams = nullptr);
118 
123  std::shared_ptr<CYIAsset> LoadFromPath(const CYIString &path, CYIAssetLoadParams *pLoadParams = nullptr);
124 
129  bool LoadFromPath(const std::shared_ptr<CYIAsset> &pAsset);
130 
135  std::shared_ptr<CYIAsset> Load(const CYIRuntimeTypeInfo &assetType, const uint8_t *pData, uint32_t nDataSize, CYIAssetLoadParams *pLoadParams = nullptr);
136 
147  int32_t LoadAsync(const CYIRuntimeTypeInfo &assetType, const CYIString &filename, CYIAssetLoadParams *pLoadParams, DecodeListener *pListener, void *pListenerPrivate);
148 
157  int32_t LoadAsyncFromPath(const CYIRuntimeTypeInfo &assetType, const CYIString &path, CYIAssetLoadParams *pLoadParams, DecodeListener *pListener, void *pListenerPrivate);
158 
166  int32_t LoadAsyncFromPath(const CYIString &path, CYIAssetLoadParams *pLoadParams, DecodeListener *pListener, void *pListenerPrivate);
167 
176  int32_t LoadAsync(const CYIRuntimeTypeInfo &assetType, const uint8_t *pData, uint32_t nDataSize, CYIAssetLoadParams *pLoadParams, DecodeListener *pListener, void *pListenerPrivate);
177 
182  void AbortAsyncLoad(int32_t nDecodeTaskID);
183 
187  uint32_t GetAsyncJobsCount();
188 
192  CYIString ProbeExtension(const CYIRuntimeTypeInfo &assetType, const uint8_t *pData, uint32_t nDataSize) const;
193 
197  CYIString ProbeExtension(const uint8_t *pData, uint32_t nDataSize) const;
198 
199 private:
200  CYIAssetDecoder *GetDecoder(const CYIRuntimeTypeInfo &assetType, const CYIString &path, const CYIAssetLoadParams *pLoadParams = nullptr);
201  CYIAssetDecoder *GetDecoder(const CYIRuntimeTypeInfo &assetType, const uint8_t *pData, uint32_t nDataSize, const CYIAssetLoadParams *pLoadParams = nullptr);
202  CYIAssetDecoder *GetDecoder(const std::shared_ptr<CYIAsset> &pAsset);
203 
204  int32_t StartAsyncLoad(const CYIRuntimeTypeInfo &assetType,
205  const CYIString &path,
206  const uint8_t *pData,
207  uint32_t nDataSize,
208  CYIAssetLoadParams *pLoadParams,
209  DecodeListener *pListener,
210  void *pListenerPrivate);
211 
212  void OnJobComplete(int32_t nJobID);
213 
214  static CYIAssetLoader *m_pSingleton;
215 
216  CYIMutex m_jobsMutex;
217  std::vector<std::unique_ptr<CYIAssetDecoder>> m_decoders;
218  std::map<int32_t, CYIDecoderThread *> m_decodingJobs;
219 
220  static CYIAssetLocator m_AssetLocator;
221 
222  int32_t m_nNextDecodingJobID;
223 
224  std::unique_ptr<CYILoadThreadManager> m_pLoadManager;
225 
227 };
228 
231 #endif // _YI_ASSET_LOADER_H_
#define YI_DISALLOW_COPY_AND_ASSIGN(TypeName)
Delete the copy constructor and assignment operator (and consequently the move constructor as well) ...
Definition: YiPredef.h:114
Listener interface for asynchronously decoded asset objects.
Definition: YiAssetLoader.h:50
Definition: YiMutex.h:110
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:35
A class that loads data in a pool of threads.
Definition: YiLoadThreadManager.h:37
virtual ~CYIAssetLoader()
The base class for an object accessible from script source code.
Definition: YiScriptableObject.h:28
virtual void OnDecodeComplete(int32_t nJobID, std::shared_ptr< CYIAsset > pAsset, int32_t nLoadStatus, void *pListenerPrivate)=0
friend class CYIDecoderThread
Definition: YiAssetLoader.h:41
virtual ~DecodeListener()
Definition: YiAssetLoader.h:53
int32_t LoadAsyncFromPath(const CYIRuntimeTypeInfo &assetType, const CYIString &path, CYIAssetLoadParams *pLoadParams, DecodeListener *pListener, void *pListenerPrivate)
Base class for decoders which can accept specialized parameter objects.
Definition: YiAssetLoadParams.h:16
std::shared_ptr< CYIAsset > LoadFromPath(const CYIRuntimeTypeInfo &assetType, const CYIString &path, CYIAssetLoadParams *pLoadParams=nullptr)
std::unique_ptr< CYIAssetDecoder > RemoveDecoder(const CYIAssetDecoder *pDecoder)
static void SetAssetLocator(const CYIAssetLocator &rLocator)
uint32_t GetDecoderCount()
CYIString ProbeExtension(const CYIRuntimeTypeInfo &assetType, const uint8_t *pData, uint32_t nDataSize) const
uint32_t GetAsyncJobsCount()
The abstract runtime representation of a C++ type.
Definition: YiRtti.h:48
void AbortAsyncLoad(int32_t nDecodeTaskID)
Definition: YiSignalHandler.h:174
void AddDecoder(std::unique_ptr< CYIAssetDecoder > pDecoder)
static const CYIAssetLocator & GetAssetLocator()
Base class for any asset. An asset provides functions for dynamically loading and unloading itself an...
Definition: YiAsset.h:33
std::shared_ptr< CYIAsset > Load(const CYIRuntimeTypeInfo &assetType, const CYIString &filename, CYIAssetLoadParams *pLoadParams=nullptr)
Base class for all specialized decoders.
Definition: YiAssetDecoder.h:22
int32_t LoadAsync(const CYIRuntimeTypeInfo &assetType, const CYIString &filename, CYIAssetLoadParams *pLoadParams, DecodeListener *pListener, void *pListenerPrivate)
Using a base file path, determines the path to an asset given a file name and an asset type...
Definition: YiAssetLocator.h:118
The asset loader provides an interface for loading asset objects, which in turn wrap resource objects...
Definition: YiAssetLoader.h:39