Bläddra i källkod

Slight improvements in new Loader

Thomas Buck 10 år sedan
förälder
incheckning
a50a50ef23

+ 3
- 1
include/loader/Loader.h Visa fil

8
 #ifndef _LOADER_LOADER_H_
8
 #ifndef _LOADER_LOADER_H_
9
 #define _LOADER_LOADER_H_
9
 #define _LOADER_LOADER_H_
10
 
10
 
11
+#include <memory>
11
 #include <string>
12
 #include <string>
13
+
12
 #include "utils/binary.h"
14
 #include "utils/binary.h"
13
 
15
 
14
 class Loader {
16
 class Loader {
25
 
27
 
26
     static LoaderVersion checkFile(std::string f);
28
     static LoaderVersion checkFile(std::string f);
27
 
29
 
28
-    static Loader *createLoader(std::string f);
30
+    static std::unique_ptr<Loader> createLoader(std::string f);
29
 
31
 
30
     virtual ~Loader();
32
     virtual ~Loader();
31
 
33
 

+ 0
- 4
include/loader/LoaderTR1.h Visa fil

8
 #ifndef _LOADER_LOADER_TR1_H_
8
 #ifndef _LOADER_LOADER_TR1_H_
9
 #define _LOADER_LOADER_TR1_H_
9
 #define _LOADER_LOADER_TR1_H_
10
 
10
 
11
-#include <cstdint>
12
-
13
 #include "loader/Loader.h"
11
 #include "loader/Loader.h"
14
 
12
 
15
 class LoaderTR1 : public Loader {
13
 class LoaderTR1 : public Loader {
19
 
17
 
20
     virtual int load(std::string f);
18
     virtual int load(std::string f);
21
 
19
 
22
-
23
 private:
20
 private:
24
 
21
 
25
-
26
 };
22
 };
27
 
23
 
28
 #endif
24
 #endif

+ 0
- 9
include/loader/LoaderTR2.h Visa fil

8
 #ifndef _LOADER_LOADER_TR2_H_
8
 #ifndef _LOADER_LOADER_TR2_H_
9
 #define _LOADER_LOADER_TR2_H_
9
 #define _LOADER_LOADER_TR2_H_
10
 
10
 
11
-#include <cstdint>
12
-#include <array>
13
-
14
 #include "loader/Loader.h"
11
 #include "loader/Loader.h"
15
 
12
 
16
 class LoaderTR2 : public Loader {
13
 class LoaderTR2 : public Loader {
20
 
17
 
21
     virtual int load(std::string f);
18
     virtual int load(std::string f);
22
 
19
 
23
-
24
 private:
20
 private:
25
-
26
     void loadPaletteTextiles();
21
     void loadPaletteTextiles();
27
     void loadRooms();
22
     void loadRooms();
28
     void loadFloorData();
23
     void loadFloorData();
41
     void loadSoundMap();
36
     void loadSoundMap();
42
     void loadSoundDetails();
37
     void loadSoundDetails();
43
     void loadSampleIndices();
38
     void loadSampleIndices();
44
-
45
-    std::array<uint32_t, 256> palette; //!< RGBA, A unused
46
-    uint32_t numTextiles;
47
-    uint16_t **textiles; //!< numTextiles, 256 * 256 * 2 bytes, ARGB (MSB + 3x5bit)
48
 };
39
 };
49
 
40
 
50
 #endif
41
 #endif

+ 0
- 4
include/loader/LoaderTR3.h Visa fil

8
 #ifndef _LOADER_LOADER_TR3_H_
8
 #ifndef _LOADER_LOADER_TR3_H_
9
 #define _LOADER_LOADER_TR3_H_
9
 #define _LOADER_LOADER_TR3_H_
10
 
10
 
11
-#include <cstdint>
12
-
13
 #include "loader/Loader.h"
11
 #include "loader/Loader.h"
14
 
12
 
15
 class LoaderTR3 : public Loader {
13
 class LoaderTR3 : public Loader {
19
 
17
 
20
     virtual int load(std::string f);
18
     virtual int load(std::string f);
21
 
19
 
22
-
23
 private:
20
 private:
24
 
21
 
25
-
26
 };
22
 };
27
 
23
 
28
 #endif
24
 #endif

+ 3
- 5
src/Game.cpp Visa fil

79
 
79
 
80
     getConsole() << "Loading " << levelName << Console::endl;
80
     getConsole() << "Loading " << levelName << Console::endl;
81
 
81
 
82
-    Loader *loader = Loader::createLoader(level);
83
     int error = 0;
82
     int error = 0;
84
-    if (loader != NULL) {
83
+    auto loader = Loader::createLoader(level);
84
+    if (loader) {
85
         // First Loader test
85
         // First Loader test
86
         error = loader->load(level);
86
         error = loader->load(level);
87
         if (error != 0) {
87
         if (error != 0) {
88
-            delete loader;
89
             return error;
88
             return error;
90
         }
89
         }
91
 
90
 
92
         // And now...?
91
         // And now...?
93
 
92
 
94
-        delete loader;
95
         getConsole() << "Tried Loader..." << Console::endl;
93
         getConsole() << "Tried Loader..." << Console::endl;
96
     }
94
     }
97
 
95
 
98
-    if ((loader == NULL) || (error == 0)) {
96
+    if ((!loader) || (error == 0)) {
99
         // Old TombRaider level loader
97
         // Old TombRaider level loader
100
         error = mTombRaider.Load(levelName.c_str());
98
         error = mTombRaider.Load(levelName.c_str());
101
         if (error != 0)
99
         if (error != 0)

+ 2
- 2
src/loader/Loader.cpp Visa fil

34
     return TR_UNKNOWN;
34
     return TR_UNKNOWN;
35
 }
35
 }
36
 
36
 
37
-Loader *Loader::createLoader(std::string f) {
37
+std::unique_ptr<Loader> Loader::createLoader(std::string f) {
38
     LoaderVersion v = checkFile(f);
38
     LoaderVersion v = checkFile(f);
39
     switch (v) {
39
     switch (v) {
40
         case TR_1:
40
         case TR_1:
45
             return NULL;
45
             return NULL;
46
 
46
 
47
         case TR_2:
47
         case TR_2:
48
-            return new LoaderTR2();
48
+            return std::unique_ptr<Loader>(new LoaderTR2());
49
     }
49
     }
50
 }
50
 }
51
 
51
 

+ 11
- 12
src/loader/LoaderTR2.cpp Visa fil

5
  * \author xythobuz
5
  * \author xythobuz
6
  */
6
  */
7
 
7
 
8
+#include <array>
9
+#include <cstdint>
8
 #include <vector>
10
 #include <vector>
9
 
11
 
10
 #include "global.h"
12
 #include "global.h"
12
 #include "loader/LoaderTR2.h"
14
 #include "loader/LoaderTR2.h"
13
 
15
 
14
 LoaderTR2::LoaderTR2() {
16
 LoaderTR2::LoaderTR2() {
15
-    numTextiles = 0;
16
-    textiles = nullptr;
17
 }
17
 }
18
 
18
 
19
 LoaderTR2::~LoaderTR2() {
19
 LoaderTR2::~LoaderTR2() {
20
-    if (textiles != nullptr) {
21
-        for (unsigned int i = 0; i < numTextiles; i++)
22
-            delete [] textiles[i];
23
-        delete [] textiles;
24
-    }
25
 }
20
 }
26
 
21
 
27
 int LoaderTR2::load(std::string f) {
22
 int LoaderTR2::load(std::string f) {
98
     file.seek(file.tell() + 768); // Skip 8bit palette, 256 * 3 bytes
93
     file.seek(file.tell() + 768); // Skip 8bit palette, 256 * 3 bytes
99
 
94
 
100
     // Read the 16bit palette, 256 * 4 bytes, RGBA, A unused
95
     // Read the 16bit palette, 256 * 4 bytes, RGBA, A unused
96
+    std::array<uint32_t, 256> palette; //!< RGBA, A unused
101
     for (auto &x : palette)
97
     for (auto &x : palette)
102
         x = file.readU32();
98
         x = file.readU32();
103
 
99
 
104
-    numTextiles = file.readU32();
100
+    uint32_t numTextiles = file.readU32();
105
 
101
 
106
     file.seek(file.tell() + (numTextiles * 256 * 256)); // Skip 8bit textiles
102
     file.seek(file.tell() + (numTextiles * 256 * 256)); // Skip 8bit textiles
107
 
103
 
108
     // Read the 16bit textiles, numTextiles * 256 * 256 * 2 bytes
104
     // Read the 16bit textiles, numTextiles * 256 * 256 * 2 bytes
109
-    textiles = new uint16_t *[numTextiles];
105
+    std::vector<std::array<uint16_t, 256 * 256>> textiles;
110
     for (unsigned int i = 0; i < numTextiles; i++) {
106
     for (unsigned int i = 0; i < numTextiles; i++) {
111
-        textiles[i] = new uint16_t[256 * 256];
112
-        for (unsigned int j = 0; j < (256 * 256); j++) {
113
-            textiles[i][j] = file.readU16();
107
+        std::array<uint16_t, 256 * 256> arr;
108
+        for (auto &x : arr) {
109
+            x = file.readU16();
114
         }
110
         }
111
+        textiles.push_back(arr);
115
     }
112
     }
113
+
114
+    // TODO store palette and textiles somewhere
116
 }
115
 }
117
 
116
 
118
 void LoaderTR2::loadRooms() {
117
 void LoaderTR2::loadRooms() {

Laddar…
Avbryt
Spara