Kaynağa Gözat

Slight improvements in new Loader

Thomas Buck 10 yıl önce
ebeveyn
işleme
a50a50ef23

+ 3
- 1
include/loader/Loader.h Dosyayı Görüntüle

@@ -8,7 +8,9 @@
8 8
 #ifndef _LOADER_LOADER_H_
9 9
 #define _LOADER_LOADER_H_
10 10
 
11
+#include <memory>
11 12
 #include <string>
13
+
12 14
 #include "utils/binary.h"
13 15
 
14 16
 class Loader {
@@ -25,7 +27,7 @@ public:
25 27
 
26 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 32
     virtual ~Loader();
31 33
 

+ 0
- 4
include/loader/LoaderTR1.h Dosyayı Görüntüle

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

+ 0
- 9
include/loader/LoaderTR2.h Dosyayı Görüntüle

@@ -8,9 +8,6 @@
8 8
 #ifndef _LOADER_LOADER_TR2_H_
9 9
 #define _LOADER_LOADER_TR2_H_
10 10
 
11
-#include <cstdint>
12
-#include <array>
13
-
14 11
 #include "loader/Loader.h"
15 12
 
16 13
 class LoaderTR2 : public Loader {
@@ -20,9 +17,7 @@ public:
20 17
 
21 18
     virtual int load(std::string f);
22 19
 
23
-
24 20
 private:
25
-
26 21
     void loadPaletteTextiles();
27 22
     void loadRooms();
28 23
     void loadFloorData();
@@ -41,10 +36,6 @@ private:
41 36
     void loadSoundMap();
42 37
     void loadSoundDetails();
43 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 41
 #endif

+ 0
- 4
include/loader/LoaderTR3.h Dosyayı Görüntüle

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

+ 3
- 5
src/Game.cpp Dosyayı Görüntüle

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

+ 2
- 2
src/loader/Loader.cpp Dosyayı Görüntüle

@@ -34,7 +34,7 @@ Loader::LoaderVersion Loader::checkFile(std::string f) {
34 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 38
     LoaderVersion v = checkFile(f);
39 39
     switch (v) {
40 40
         case TR_1:
@@ -45,7 +45,7 @@ Loader *Loader::createLoader(std::string f) {
45 45
             return NULL;
46 46
 
47 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 Dosyayı Görüntüle

@@ -5,6 +5,8 @@
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
+#include <array>
9
+#include <cstdint>
8 10
 #include <vector>
9 11
 
10 12
 #include "global.h"
@@ -12,16 +14,9 @@
12 14
 #include "loader/LoaderTR2.h"
13 15
 
14 16
 LoaderTR2::LoaderTR2() {
15
-    numTextiles = 0;
16
-    textiles = nullptr;
17 17
 }
18 18
 
19 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 22
 int LoaderTR2::load(std::string f) {
@@ -98,21 +93,25 @@ void LoaderTR2::loadPaletteTextiles() {
98 93
     file.seek(file.tell() + 768); // Skip 8bit palette, 256 * 3 bytes
99 94
 
100 95
     // Read the 16bit palette, 256 * 4 bytes, RGBA, A unused
96
+    std::array<uint32_t, 256> palette; //!< RGBA, A unused
101 97
     for (auto &x : palette)
102 98
         x = file.readU32();
103 99
 
104
-    numTextiles = file.readU32();
100
+    uint32_t numTextiles = file.readU32();
105 101
 
106 102
     file.seek(file.tell() + (numTextiles * 256 * 256)); // Skip 8bit textiles
107 103
 
108 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 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 117
 void LoaderTR2::loadRooms() {

Loading…
İptal
Kaydet