-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_manager.h
169 lines (144 loc) · 6.08 KB
/
resource_manager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#pragma once
#include "stack_alloc.h"
#include "heap_alloc.h"
#include "load_texture.h"
#include "asset.h"
#include "model.h"
#include "mesh.h"
#include "anim.h"
#include "render_data.h"
#include "text.h"
#include "rid.h"
#include "motion_matching.h"
#include "resource_hash_table.h"
static const int RESOURCE_MAX_COUNT = 300;
const int MODEL_MAX_COUNT = RESOURCE_MAX_COUNT;
const int ANIMATION_MAX_COUNT = RESOURCE_MAX_COUNT;
const int MATERIAL_MAX_COUNT = RESOURCE_MAX_COUNT;
const int TEXTURE_MAX_COUNT = RESOURCE_MAX_COUNT;
const int SHADER_MAX_COUNT = RESOURCE_MAX_COUNT;
const int MM_CONTROLLER_COUNT = RESOURCE_MAX_COUNT;
namespace Resource
{
typedef resource_hash_table<Render::model*, MODEL_MAX_COUNT> model_hash_table;
typedef resource_hash_table<Anim::animation*, ANIMATION_MAX_COUNT> animation_group_hash_table;
typedef resource_hash_table<material*, MATERIAL_MAX_COUNT> material_hash_table;
typedef resource_hash_table<uint32_t, TEXTURE_MAX_COUNT> texture_hash_table;
typedef resource_hash_table<GLuint, SHADER_MAX_COUNT> shader_hash_table;
typedef resource_hash_table<mm_controller_data*, MM_CONTROLLER_COUNT> mm_controller_hash_table;
class resource_manager
{
asset_diff DiffedModels[RESOURCE_MAX_COUNT];
asset_diff DiffedAnimations[RESOURCE_MAX_COUNT];
asset_diff DiffedMaterials[RESOURCE_MAX_COUNT];
asset_diff DiffedTextures[RESOURCE_MAX_COUNT];
asset_diff DiffedScenes[RESOURCE_MAX_COUNT];
asset_diff DiffedShaders[RESOURCE_MAX_COUNT];
asset_diff DiffedMMParams[RESOURCE_MAX_COUNT];
asset_diff DiffedMMControllers[RESOURCE_MAX_COUNT];
int32_t DiffedModelCount;
int32_t DiffedAnimationCount;
int32_t DiffedMaterialCount;
int32_t DiffedTextureCount;
int32_t DiffedSceneCount;
int32_t DiffedShaderCount;
int32_t DiffedMMParamCount;
int32_t DiffedMMControllerCount;
file_stat ModelStats[RESOURCE_MAX_COUNT];
file_stat TextureStats[RESOURCE_MAX_COUNT];
file_stat AnimationStats[RESOURCE_MAX_COUNT];
file_stat MaterialStats[RESOURCE_MAX_COUNT];
file_stat SceneStats[RESOURCE_MAX_COUNT];
file_stat ShaderStats[RESOURCE_MAX_COUNT];
file_stat MMParamStats[RESOURCE_MAX_COUNT];
file_stat MMControllerStats[RESOURCE_MAX_COUNT];
bool LoadModel(rid RID);
bool LoadTexture(rid RID);
bool LoadAnimation(rid RID);
bool LoadMaterial(rid RID);
bool LoadShader(rid RID);
bool LoadMMController(rid RID);
void FreeModel(rid RID);
void FreeAnimation(rid RID);
void FreeShader(rid RID);
void FreeMMController(rid RID);
GLuint DefaultShaderID;
public:
Memory::heap_allocator ModelHeap;
Memory::heap_allocator AnimationHeap;
Memory::heap_allocator MMControllerHeap;
Memory::stack_allocator MaterialStack;
Memory::stack_allocator* TemporaryStack;
model_hash_table Models;
texture_hash_table Textures;
animation_group_hash_table Animations;
material_hash_table Materials;
shader_hash_table Shaders;
mm_controller_hash_table MMControllers;
path ModelPaths[RESOURCE_MAX_COUNT];
path TexturePaths[RESOURCE_MAX_COUNT];
path AnimationPaths[RESOURCE_MAX_COUNT];
path MaterialPaths[RESOURCE_MAX_COUNT];
path ShaderPaths[RESOURCE_MAX_COUNT];
path ScenePaths[RESOURCE_MAX_COUNT];
path MMParamPaths[RESOURCE_MAX_COUNT];
path MMControllerPaths[RESOURCE_MAX_COUNT];
int32_t ModelPathCount;
int32_t TexturePathCount;
int32_t AnimationPathCount;
int32_t MaterialPathCount;
int32_t ShaderPathCount;
int32_t ScenePathCount;
int32_t MMParamPathCount;
int32_t MMControllerPathCount;
rid UpdateOrCreateMMController(mm_controller_data* ControllerData, size_t Size,
const char* Path);
void AddMMControllerAnimationReferences(mm_controller_data* Controller);
rid CreateMaterial(material Material, const char* Path);
rid RegisterModel(const char* Path);
rid RegisterTexture(const char* Path);
rid RegisterAnimation(const char* Path);
rid RegisterMaterial(const char* Path);
rid RegisterShader(const char* Path);
rid RegisterMMController(const char* Path);
bool AssociateModelIDToPath(rid RID, const char* Path);
bool AssociateAnimationIDToPath(rid RID, const char* Path);
bool AssociateTextureIDToPath(rid RID, const char* Path);
bool AssociateMaterialIDToPath(rid RID, const char* Path);
bool AssociateMMControllerIDToPath(rid RID, const char* Path);
bool GetModelPathRID(rid* RID, const char* Path);
bool GetTexturePathRID(rid* RID, const char* Path);
bool GetAnimationPathRID(rid* RID, const char* Path);
bool GetMaterialPathRID(rid* RID, const char* Path);
bool GetMMControllerPathRID(rid* RID, const char* Path);
// TODO(Lukas) expand the GetPathRID API to do perform this as this use case is extremely common
// If fail to find path register with a new ID
rid ObtainModelPathRID(const char* Path);
rid ObtainTexturePathRID(const char* Path);
rid ObtainAnimationPathRID(const char* Path);
rid ObtainMaterialPathRID(const char* Path);
rid ObtainMMControllerPathRID(const char* Path);
int32_t GetTexturePathIndex(rid RID);
int32_t GetMaterialPathIndex(rid RID);
int32_t GetAnimationPathIndex(rid RID);
int32_t GetMMControllerPathIndex(rid RID);
Render::model* GetModel(rid RID);
uint32_t GetTexture(rid RID);
GLuint GetShader(rid RID);
Anim::animation* GetAnimation(rid RID);
material* GetMaterial(rid RID);
mm_controller_data* GetMMController(rid RID);
void WipeAllModelData();
void WipeAllMaterialData();
void WipeAllAnimationData();
void WipeAllTextureData();
void WipeAllShaderData();
void WipeAllMMControllerData();
void UpdateHardDriveAssetPathLists();
void DeleteUnused();
void ReloadModified();
void SortAllAssetDiffsPathsStats();
void Create(uint8_t* Memory, uint32_t TotalMemorySize, Memory::stack_allocator* TemporaryStack);
void SetDefaultShaderID(GLuint ShaderID);
};
}