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 AssetMgr {
20 public:
21 enum TYPE {
22 NONE, TEX_2D, TEX_CUBEMAP, FRAMEBUFFER, MATERIAL, DAE, PREFAB, SCENE, SCRIPT, TXT, SHADER, SHADER_HANDLE, INI
23 };
24
26 std::string name_path;
27 std::string path;
28 std::string name;
29 std::string id;
30 std::string hash;
31 std::string name_full;
32 std::string extension;
33 TYPE type = NONE;
34 };
35 public:
36 AssetMgr();
37
38 ~AssetMgr();
39
40 void Exterminate();
41
42 void LoadAssets(bool isPacked);
43
44 AssetReference* GetAsset(const std::string& name) const;
45
46 std::list<AssetMgr::AssetReference*> GetAssets(TYPE type) const;
47
48 static std::string LoadAssetFile(const std::string& path);
49
50 static std::string GetAssetHash(const std::string& path);
51
52#ifdef __ANDROID__
53 void SetAssetManager(AAssetManager* obj);
54 AAssetManager* GetAssetManager();
55 void SetEnv(JNIEnv* obj);
56 JNIEnv* GetEnv();
57#endif
58
59 private:
60 void ReadDirectory(const std::string& path);
61 void ReadPackage(const std::string& path);
62
63 AssetReference* CreateAsset(const std::string& path, const std::string& name_full, std::string name = "");
64
65 void SetType();
66
67 static AssetReference* AppendSubName(AssetReference* asset, const std::string& sub_name);
68
69 private:
70 std::list<AssetReference*> m_assetsList;
71 std::unordered_map<std::string, AssetReference*> m_assets;
72 zip_t* m_zip = nullptr;
73#ifdef __ANDROID__
74 AAssetManager* m_assetManager;
75 JNIEnv* m_env = nullptr;
76#endif
77#if defined(__ANDROID__) || defined(IOS)
78 std::string m_package_raw;
79#endif
80 };
81
82}
Definition zip.cpp:88