CSEngine
Loading...
Searching...
No Matches
ResMgr.h
1#pragma once
2
3#include "../MacroDef.h"
4#include "Base/SContainerList.h"
5#include "../Object/SResource.h"
6#include "AssetMgr.h"
7#include "Base/CoreBase.h"
8#include "Base/SContainerHash.h"
9#include <vector>
10
11#ifdef __ANDROID__
12#include <android/asset_manager.h>
13#include <android/asset_manager_jni.h>
14#endif
15
16namespace CSE {
17
18 class SObject;
19
20 class GLProgramHandle;
21
22 class SISurface;
23
24 class ResMgr : public CoreBase, public SContainerHash<SResource*> {
25 public:
26 explicit ResMgr();
27 ~ResMgr() override;
28
29 public:
30
31 void Init() override;
32
33 void InitResource();
34
35 void Exterminate();
36
37 void Remove(SResource* m_object) override;
38
39 template <class TYPE>
40 TYPE* GetObjectByHash(const std::string& hash) const;
41
42 SResource* GetSResource(std::string name) const;
43
44 int GetStringHash(const std::string& str);
45
46 AssetMgr::AssetReference* GetAssetReference(std::string name) const;
47
48 std::list<AssetMgr::AssetReference*> GetAssetReferences(AssetMgr::TYPE type) const;
49
50#ifdef __ANDROID__
51 void SetAssetManager(AAssetManager* obj);
52 AAssetManager* GetAssetManager();
53 void SetEnv(JNIEnv* obj);
54 JNIEnv* GetEnv();
55#endif
56
57 private:
58 AssetMgr* m_assetManager = nullptr;
59 std::vector<std::string> m_stringIds;
60
61 public:
62 friend class AssetMgr;
63 };
64
65 template <class TYPE>
66 TYPE* ResMgr::GetObjectByHash(const std::string& hash) const {
67 if(m_objects.count(hash) <= 0) return nullptr;
68
69 return static_cast<TYPE*>(Get(hash));
70 }
71}