summaryrefslogtreecommitdiff
path: root/src/wmresourcemng.cpp
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2011-03-12 23:17:12 +0100
committerTreeki <treeki@gmail.com>2011-03-12 23:17:12 +0100
commit7d4e4c0b34a613dd3c0220475ae4e448197522c1 (patch)
tree4f5cee367de3fdef4f9a7c84af59ffe76a2bb1c3 /src/wmresourcemng.cpp
downloadkamek-7d4e4c0b34a613dd3c0220475ae4e448197522c1.tar.gz
kamek-7d4e4c0b34a613dd3c0220475ae4e448197522c1.zip
initial commit. now I can start playing with stuff!
Diffstat (limited to 'src/wmresourcemng.cpp')
-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;
+}
+