CSEngine
Loading...
Searching...
No Matches
AssetMgr.h
1//
2// Created by ounols on 19. 6. 6.
3//
4//참조 : https://codingcoding.tistory.com/900
5#pragma once
6
7
8#include <string>
9#include <list>
10#include <unordered_map>
11#include "../Util/Loader/ZIP/zip.h"
12#ifdef __ANDROID__
13#include <android/asset_manager.h>
14#include <jni.h>
15#endif
16
17namespace CSE {
18
19 class SResource;
20
21 class AssetMgr {
22 public:
23 enum TYPE {
24 NONE, TEX_2D, TEX_CUBEMAP, FRAMEBUFFER, MATERIAL, DAE, PREFAB, SCENE, SCRIPT, TXT, SHADER, SHADER_HANDLE, INI
25 };
26
28 std::string name_path;
29 std::string path;
30 std::string name;
31 std::string id;
32 std::string hash;
33 std::string name_full;
34 std::string extension;
35 std::string class_type;
36 TYPE type = NONE;
37 SResource* resource;
38 };
39 public:
40 AssetMgr();
41
42 ~AssetMgr();
43
44 void Exterminate();
45
46 void LoadAssets(bool isPacked);
47
48 AssetReference* GetAsset(const std::string& name) const;
49
50 std::list<AssetMgr::AssetReference*> GetAssets(TYPE type) const;
51
52 static std::string LoadAssetFile(const std::string& path);
53
54 static std::string GetAssetHash(const std::string& path);
55
56#ifdef __CSE_EDITOR__
57 std::list<AssetMgr::AssetReference*> GetAllAssets() const {
58 return m_assetsList;
59 }
60#endif
61
62#ifdef __ANDROID__
63 void SetAssetManager(AAssetManager* obj);
64 AAssetManager* GetAssetManager();
65 void SetEnv(JNIEnv* obj);
66 JNIEnv* GetEnv();
67#endif
68
69 private:
70 void ReadDirectory(const std::string& path);
71 void ReadPackage(const std::string& path);
72
73 AssetReference* CreateAsset(const std::string& path, const std::string& name_full, std::string name = "");
74 AssetReference* CreateAssetFolder(const std::string& path, const std::string& name_full);
75
76 void SetType();
77
78 static AssetReference* AppendSubName(AssetReference* asset, const std::string& sub_name);
79
80 private:
81 std::list<AssetReference*> m_assetsList;
82 std::unordered_map<std::string, AssetReference*> m_assets;
83 zip_t* m_zip = nullptr;
84#ifdef __ANDROID__
85 AAssetManager* m_assetManager;
86 JNIEnv* m_env = nullptr;
87#endif
88#if defined(__ANDROID__) || defined(IOS)
89 std::string m_package_raw;
90#endif
91 };
92}
Definition zip.cpp:88