CSEngine
Loading...
Searching...
No Matches
ResMgr.cpp
1#include "ResMgr.h"
2#include "CameraMgr.h"
3#include "MemoryMgr.h"
4#include "EngineCore.h"
5#include "../Util/AssetsDef.h"
6
7#ifdef __ANDROID__
8#include <Util/SafeLog.h>
9#endif
10
11using namespace CSE;
12
13ResMgr::ResMgr() = default;
14
15ResMgr::~ResMgr() {
16 Exterminate();
17}
18
19void ResMgr::Init() {
20 InitResource();
21}
22
23void ResMgr::InitResource() {
24 //Make Asset Manager
25 if(m_assetManager == nullptr)
26 m_assetManager = new AssetMgr();
27
28 //Load Assets
29 m_assetManager->LoadAssets(Settings::IsAssetsPacked());
30}
31
32void ResMgr::Exterminate() {
33 SAFE_DELETE(m_assetManager);
34}
35
36void ResMgr::Remove(SResource* m_object) {
38 CORE->GetCore(MemoryMgr)->ReleaseObject(m_object, true);
39}
40
41int ResMgr::GetStringHash(const std::string& str) {
42 auto result = std::find(m_stringIds.begin(), m_stringIds.end(), str);
43 if (result != m_stringIds.end())
44 return result - m_stringIds.begin();
45
46 m_stringIds.push_back(str);
47 return m_stringIds.size() - 1;
48}
49
50AssetMgr::AssetReference* ResMgr::GetAssetReference(std::string name) const {
51 return m_assetManager->GetAsset(name);
52}
53
54SResource* ResMgr::GetSResource(std::string name) const {
55 if(m_objects.count(name) > 0) return Get(name);
56 make_lower(name);
57 for (const auto& pair : m_objects) {
58 const auto& res = pair.second;
59 if (make_lower_copy(res->GetName()) == name)
60 return res;
61 if (make_lower_copy(res->GetAbsoluteID()) == name)
62 return res;
63 }
64 return nullptr;
65}
66
67std::list<AssetMgr::AssetReference*> ResMgr::GetAssetReferences(AssetMgr::TYPE type) const {
68 return m_assetManager->GetAssets(type);
69}
70
71#ifdef __ANDROID__
72
73void ResMgr::SetAssetManager(AAssetManager* obj) {
74 SafeLog::Log("SetAssetManager");
75 //Make Asset Manager
76 if(m_assetManager == nullptr)
77 m_assetManager = new AssetMgr();
78 m_assetManager->SetAssetManager(obj);
79}
80
81
82AAssetManager* ResMgr::GetAssetManager() {
83 return m_assetManager->GetAssetManager();
84}
85
86void ResMgr::SetEnv(JNIEnv *obj) {
87 m_assetManager->SetEnv(obj);
88}
89
90JNIEnv *ResMgr::GetEnv() {
91 return m_assetManager->GetEnv();
92}
93
94#endif