summaryrefslogtreecommitdiff
path: root/src/wmresourcemng.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/wmresourcemng.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/wmresourcemng.cpp b/src/wmresourcemng.cpp
new file mode 100644
index 0000000..4a71753
--- /dev/null
+++ b/src/wmresourcemng.cpp
@@ -0,0 +1,78 @@
+#include "worldmap.h"
+
+
+
+
+dWMResourceMng_c::dWMResourceMng_c() {
+ hasSetPath = false;
+ isSetLoaded = false;
+ isLoadingComplete = false;
+}
+
+dWMResourceMng_c::~dWMResourceMng_c() {
+ if (isSetLoaded) {
+ for (int i = 0; i < setData->count; i++) {
+ resLoaders[i].unload();
+ }
+
+ delete[] resLoaders;
+ }
+
+ setLoader.unload();
+}
+
+
+
+bool dWMResourceMng_c::isLoaded() {
+ return isLoadingComplete;
+}
+
+
+bool dWMResourceMng_c::loadSet(const char *setName) {
+ if (isLoadingComplete)
+ return true;
+
+ // only start the loading process if we haven't done that already
+ if (!isSetLoaded) {
+ if (!hasSetPath) {
+ snprintf(setPath, sizeof(setPath), "/Maps/%s.fileset", setName);
+ hasSetPath = true;
+ }
+
+ void *result = setLoader.load(setPath);
+ if (result == 0)
+ return false;
+
+ // cool, we've got it, now load everything here
+ setData = (WMResSetHeader*)result;
+
+ resLoaders = new dDvdLoader_c[setData->count];
+
+ isSetLoaded = true;
+ }
+
+ // now try to load every resource
+ // if even ONE of them fails, then don't return true
+ bool isLoadingComplete = true;
+
+ for (int i = 0; i < setData->count; i++) {
+ isLoadingComplete &= (resLoaders[i].load(setData->getName(i)) != 0);
+ }
+
+ // if they are ALL loaded, then we'll return true!
+ return isLoadingComplete;
+}
+
+
+void *dWMResourceMng_c::operator[](u32 key) {
+ if (!isLoadingComplete)
+ return 0;
+
+ for (int i = 0; i < setData->count; i++) {
+ if (key == setData->entries[i].key)
+ return resLoaders[i].buffer;
+ }
+
+ return 0;
+}
+