-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPResource.cpp
137 lines (128 loc) · 3.32 KB
/
SPResource.cpp
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
#include "SPResource.h"
#include "Graphic/SPMesh.h"
#include "Graphic/SPTexture.h"
#include "Graphic/SPRenderer.h"
#include "Utility/Pei.Utility.h"
using namespace Pei::Utility;
namespace Pei
{
Graphic::SPMesh* lastMesh = 0;
Graphic::SPTexture* lastTexture = 0;
Graphic::SPRenderer* lastRenderer = 0;
SPResource::SPResource(SPResource::Types type)
{
this->name = "";
this->type = type;
this->resGroupID = SPResourceManager::resGroupID;
switch(type)
{
case SPResource::Type_Mesh :
if(lastMesh)
lastMesh->next = (Graphic::SPMesh*)this;
this->prev = lastMesh;
lastMesh = (Graphic::SPMesh*)this;
this->next = 0;
break;
case SPResource::Type_Texture :
if(lastTexture)
lastTexture->next = (Graphic::SPTexture*)this;
this->prev = lastTexture;
lastTexture = (Graphic::SPTexture*)this;
this->next = 0;
break;
case SPResource::Type_Renderer :
if(lastRenderer)
lastRenderer->next = (Graphic::SPRenderer*)this;
this->prev = lastRenderer;
lastRenderer = (Graphic::SPRenderer*)this;
this->next = 0;
break;
}
}
//------------------------------------------------------
std::string SPResourceManager::basePath = "Res\\";
unsigned char SPResourceManager::resGroupID = 0;
void SPResourceManager::releaseAllResources()
{
SPResource* current = lastMesh;
while(current){current->releaseRes();current = current->prev;}
current = lastTexture;
while(current){current->releaseRes();current = current->prev;}
current = lastRenderer;
while(current){current->releaseRes();current = current->prev;}
}
void SPResourceManager::reloadAllResources()
{
SPResource* current = lastMesh;
while(current){current->reloadRes();current = current->prev;}
current = lastTexture;
while(current){current->reloadRes();current = current->prev;}
current = lastRenderer;
while(current){current->reloadRes();current = current->prev;}
}
Graphic::SPMesh* SPResourceManager::GetMesh(const char* name)
{
if(name)
{
Graphic::SPMesh* current = lastMesh;
while(current)
{
if(current->name.compare(name) == 0)
return current;
current = (Graphic::SPMesh*)current->prev;
}
return new Graphic::SPMesh(name);
}
return 0;
}
Graphic::SPTexture* SPResourceManager::GetTexture(const char* name)
{
if(name)
{
Graphic::SPTexture* current = lastTexture;
while(current)
{
if(current->name.compare(name) == 0)
return current;
current = (Graphic::SPTexture*)current->prev;
}
return new Graphic::SPTexture(name);
}
return 0;
}
void SPResourceManager::RemoveResources(unsigned char resGroupID)
{
SPResource* current = lastMesh;
while(current)
{
if(current->resGroupID == resGroupID)
{
if(current->next)
current->next->prev = current->prev;
if(current->prev)
current->prev->next = current->next;
Graphic::SPMesh* temp = (Graphic::SPMesh*)current;
current = current->prev;
delete temp;
continue;
}
current = current->prev;
}
current = lastTexture;
while(current)
{
if(current->resGroupID == resGroupID)
{
if(current->next)
current->next->prev = current->prev;
if(current->prev)
current->prev->next = current->next;
Graphic::SPTexture* temp = (Graphic::SPTexture*)current;
current = current->prev;
delete temp;
continue;
}
current = current->prev;
}
}
}