Browse Source

Trying out new Loader

Thomas Buck 9 years ago
parent
commit
de2306f27a

+ 4
- 0
ChangeLog.md View File

@@ -2,8 +2,12 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20140813 ]
6
+    * Added LoaderTR1, LoaderTR3 stubs
7
+
5 8
     [ 20140812 ]
6 9
     * Started implementing new level file loader, currently TR2 only
10
+    * Trigger new Loader when possible, but fallback to old TombRaider
7 11
 
8 12
     [ 20140811 ]
9 13
     * New Font API, allows drawing strings with line-wrapping

+ 0
- 3
TODO.md View File

@@ -3,9 +3,6 @@
3 3
 ## General
4 4
 
5 5
 * Move to newer OpenGL (GL ES or 2.1 or 3.x or 4.x?)
6
-* Endian dependence ugly, shouldn't dereference to different types?
7
-    * TombRaider.h/cpp structs aren't aligned... unportable to some big endian & other archs?!
8
-    * Maybe replace loader with [VT](http://icculus.org/vt/), also used by OpenTomb.
9 6
 * Don't use C-Style code, try to replace with C++ lib
10 7
     * Use std::strings
11 8
 * Mesh has 2 different approaches of storing the same data (eg. mColors and mColorArray), but half of ‘em isn’t implemented. Unify this, probably even combining Mesh and StaticMesh...

+ 29
- 0
include/loader/LoaderTR1.h View File

@@ -0,0 +1,29 @@
1
+/*!
2
+ * \file include/loader/LoaderTR1.h
3
+ * \brief TR1 level file loader
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _LOADER_LOADER_TR1_H_
9
+#define _LOADER_LOADER_TR1_H_
10
+
11
+#include <cstdint>
12
+
13
+#include "loader/Loader.h"
14
+
15
+class LoaderTR1 : public Loader {
16
+public:
17
+    LoaderTR1();
18
+    virtual ~LoaderTR1();
19
+
20
+    virtual int load(std::string f);
21
+
22
+
23
+private:
24
+
25
+
26
+};
27
+
28
+#endif
29
+

+ 29
- 0
include/loader/LoaderTR3.h View File

@@ -0,0 +1,29 @@
1
+/*!
2
+ * \file include/loader/LoaderTR3.h
3
+ * \brief TR3 level file loader
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _LOADER_LOADER_TR3_H_
9
+#define _LOADER_LOADER_TR3_H_
10
+
11
+#include <cstdint>
12
+
13
+#include "loader/Loader.h"
14
+
15
+class LoaderTR3 : public Loader {
16
+public:
17
+    LoaderTR3();
18
+    virtual ~LoaderTR3();
19
+
20
+    virtual int load(std::string f);
21
+
22
+
23
+private:
24
+
25
+
26
+};
27
+
28
+#endif
29
+

+ 52
- 31
src/Game.cpp View File

@@ -14,6 +14,7 @@
14 14
 #include "Camera.h"
15 15
 #include "Console.h"
16 16
 #include "Game.h"
17
+#include "loader/Loader.h"
17 18
 #include "OpenRaider.h"
18 19
 #include "Render.h"
19 20
 #include "Sound.h"
@@ -77,40 +78,60 @@ int Game::loadLevel(const char *level) {
77 78
     levelName = level;
78 79
 
79 80
     getConsole() << "Loading " << levelName << Console::endl;
80
-    int error = mTombRaider.Load(levelName.c_str());
81
-    if (error != 0)
82
-        return error;
83
-
84
-    // If required, load the external sound effect file MAIN.SFX into TombRaider
85
-    if ((mTombRaider.getEngine() == TR_VERSION_2) || (mTombRaider.getEngine() == TR_VERSION_3)) {
86
-        std::string tmp(levelName);
87
-        size_t pos = tmp.rfind('/');
88
-        tmp.erase(pos + 1);
89
-        tmp += "MAIN.SFX";
90
-        error = mTombRaider.loadSFX(tmp.c_str());
91
-        if (error != 0)
92
-            getConsole() << "Could not load " << tmp << Console::endl;
93
-    }
94 81
 
95
-    // Process data
96
-    processTextures();
97
-    processRooms();
98
-    processModels();
99
-    processSprites();
100
-    processMoveables();
101
-    processPakSounds();
82
+    Loader *loader = Loader::createLoader(level);
83
+    int error = 0;
84
+    if (loader != NULL) {
85
+        // First Loader test
86
+        error = loader->load(level);
87
+        if (error != 0) {
88
+            delete loader;
89
+            return error;
90
+        }
102 91
 
103
-    mTombRaider.reset();
92
+        // And now...?
104 93
 
105
-    if (mLara == -1) {
106
-        //! \todo Cutscene support
107
-        getConsole() << "Can't find Lara entity in level pak!" << Console::endl;
108
-        destroy();
109
-        return -1;
110
-    } else {
111
-        mLoaded = true;
112
-        getRender().setMode(Render::modeVertexLight);
113
-        return 0;
94
+        delete loader;
95
+        getConsole() << "Tried Loader..." << Console::endl;
96
+    }
97
+
98
+    if ((loader == NULL) || (error == 0)) {
99
+        // Old TombRaider level loader
100
+        error = mTombRaider.Load(levelName.c_str());
101
+        if (error != 0)
102
+            return error;
103
+
104
+        // If required, load the external sound effect file MAIN.SFX into TombRaider
105
+        if ((mTombRaider.getEngine() == TR_VERSION_2) || (mTombRaider.getEngine() == TR_VERSION_3)) {
106
+            std::string tmp(levelName);
107
+            size_t pos = tmp.rfind('/');
108
+            tmp.erase(pos + 1);
109
+            tmp += "MAIN.SFX";
110
+            error = mTombRaider.loadSFX(tmp.c_str());
111
+            if (error != 0)
112
+                getConsole() << "Could not load " << tmp << Console::endl;
113
+        }
114
+
115
+        // Process data
116
+        processTextures();
117
+        processRooms();
118
+        processModels();
119
+        processSprites();
120
+        processMoveables();
121
+        processPakSounds();
122
+
123
+        mTombRaider.reset();
124
+
125
+        if (mLara == -1) {
126
+            //! \todo Cutscene support
127
+            getConsole() << "Can't find Lara entity in level pak!" << Console::endl;
128
+            destroy();
129
+            return -1;
130
+        } else {
131
+            mLoaded = true;
132
+            getRender().setMode(Render::modeVertexLight);
133
+            return 0;
134
+        }
114 135
     }
115 136
 }
116 137
 

+ 2
- 0
src/loader/CMakeLists.txt View File

@@ -1,6 +1,8 @@
1 1
 # Source files
2 2
 set (LOADER_SRCS ${LOADER_SRCS} "Loader.cpp")
3
+set (LOADER_SRCS ${LOADER_SRCS} "LoaderTR1.cpp")
3 4
 set (LOADER_SRCS ${LOADER_SRCS} "LoaderTR2.cpp")
5
+set (LOADER_SRCS ${LOADER_SRCS} "LoaderTR3.cpp")
4 6
 
5 7
 # Add library
6 8
 add_library (OpenRaider_loader OBJECT ${LOADER_SRCS})

+ 26
- 0
src/loader/LoaderTR1.cpp View File

@@ -0,0 +1,26 @@
1
+/*!
2
+ * \file src/loader/LoaderTR1.cpp
3
+ * \brief TR1 level file loader
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include "global.h"
9
+#include "loader/LoaderTR1.h"
10
+
11
+LoaderTR1::LoaderTR1() {
12
+}
13
+
14
+LoaderTR1::~LoaderTR1() {
15
+}
16
+
17
+int LoaderTR1::load(std::string f) {
18
+    if (file.open(f.c_str()) != 0) {
19
+        return 1; // Could not open file
20
+    }
21
+
22
+
23
+
24
+    return 1; // stub
25
+}
26
+

+ 1
- 1
src/loader/LoaderTR2.cpp View File

@@ -5,6 +5,7 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
+#include "global.h"
8 9
 #include "loader/LoaderTR2.h"
9 10
 
10 11
 LoaderTR2::LoaderTR2() {
@@ -15,7 +16,6 @@ LoaderTR2::LoaderTR2() {
15 16
 
16 17
 LoaderTR2::~LoaderTR2() {
17 18
     delete [] palette;
18
-    palette = nullptr;
19 19
 
20 20
     if (textiles != nullptr) {
21 21
         for (unsigned int i = 0; i < numTextiles; i++)

+ 26
- 0
src/loader/LoaderTR3.cpp View File

@@ -0,0 +1,26 @@
1
+/*!
2
+ * \file src/loader/LoaderTR3.cpp
3
+ * \brief TR3 level file loader
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include "global.h"
9
+#include "loader/LoaderTR3.h"
10
+
11
+LoaderTR3::LoaderTR3() {
12
+}
13
+
14
+LoaderTR3::~LoaderTR3() {
15
+}
16
+
17
+int LoaderTR3::load(std::string f) {
18
+    if (file.open(f.c_str()) != 0) {
19
+        return 1; // Could not open file
20
+    }
21
+
22
+
23
+
24
+    return 1; // stub
25
+}
26
+

Loading…
Cancel
Save