blob: 091fe504a5645a0d83897b7b4892943dddae17b1 (
plain)
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
|
#include "toBeSorted/arc_managers/layout_arc_manager.h"
#include "d/d_heap.h"
LayoutArcManager *LayoutArcManager::sInstance;
LayoutArcManager::LayoutArcManager() {
sInstance = this;
}
LayoutArcManager::~LayoutArcManager() {
sInstance = nullptr;
}
void LayoutArcManager::init(EGG::Heap *heap) {
mArcTable.init(16, &ArcCallbackHandler::sInstance, heap);
}
bool LayoutArcManager::loadLayoutArcFromDisk(const char *object, EGG::Heap *heap) {
if (heap == nullptr) {
heap = dHeap::layoutResHeap.heap;
}
return mArcTable.getArcOrLoadFromDisk(object, "Layout", 0, heap);
}
dArcResult_e LayoutArcManager::ensureLoaded1(const char *object) {
return mArcTable.ensureLoadedMaybe2(object);
}
dArcResult_e LayoutArcManager::ensureLoaded2(const char *object) {
return mArcTable.ensureLoadedMaybe(object);
}
bool LayoutArcManager::hasEntry(const char *object) {
return mArcTable.hasEntry(object);
}
bool LayoutArcManager::decrement(const char *path) {
return mArcTable.decreaseRefCount(path);
}
void *LayoutArcManager::getData(const char *oarcName, const char *fileName) {
return mArcTable.getDataFromOarc(oarcName, fileName);
}
void *LayoutArcManager::getLoadedData(const char *path) {
return mArcTable.getLoadedArcData(path);
}
bool LayoutArcManager::create(EGG::Heap *heap) {
new (heap, 0x04) LayoutArcManager();
if (GetInstance() == nullptr) {
return false;
}
GetInstance()->init(heap);
return true;
}
LayoutArcControl::~LayoutArcControl() {
if (mLayoutArcs != nullptr) {
release();
}
}
void LayoutArcControl::set(const char *const *layoutArcs, s32 numArcs) {
mLayoutArcs = layoutArcs;
mNumArcs = numArcs;
}
bool LayoutArcControl::load(EGG::Heap *heap) const {
if (mLayoutArcs == nullptr) {
return true;
}
const char *const *ptr = mLayoutArcs;
for (int i = 0; i < mNumArcs; i++) {
LayoutArcManager::GetInstance()->loadLayoutArcFromDisk(*ptr, heap);
ptr++;
}
return true;
}
bool LayoutArcControl::allLoaded() const {
if (mLayoutArcs == nullptr) {
return true;
}
const char *const *ptr = mLayoutArcs;
for (int i = 0; i < mNumArcs; i++) {
dArcResult_e res = LayoutArcManager::GetInstance()->ensureLoaded1(*ptr);
if (res != D_ARC_RESULT_OK) {
return false;
}
ptr++;
}
return true;
}
bool LayoutArcControl::release() {
if (mLayoutArcs == nullptr) {
return true;
}
const char *const *ptr = mLayoutArcs;
for (int i = 0; i < mNumArcs; i++) {
dArcResult_e res = LayoutArcManager::GetInstance()->ensureLoaded2(*ptr);
if (res != D_ARC_RESULT_ERROR_NOT_FOUND && res != D_ARC_RESULT_OK) {
return false;
}
ptr++;
}
ptr = mLayoutArcs;
for (int i = 0; i < mNumArcs; i++) {
LayoutArcManager::GetInstance()->decrement(*ptr);
ptr++;
}
mLayoutArcs = nullptr;
return true;
}
|