Procházet zdrojové kódy

Now it reads the map data from an external file. This is a good day.

Eiyeron Fulmincendii před 10 roky
rodič
revize
20cd2a1a22
6 změnil soubory, kde provedl 50 přidání a 66 odebrání
  1. binární
      data/out.wrf
  2. 17 49
      src/engine/main.cpp
  3. 10 17
      src/piaf/Archive.cpp
  4. 1 0
      src/piaf/Archive.h
  5. 3 0
      src/utility/misc.cpp
  6. 19 0
      src/utility/misc.h

binární
data/out.wrf


+ 17 - 49
src/engine/main.cpp

@@ -22,55 +22,20 @@ int main(int argc, char *argv[])
     // Archive arc(Quirks::solve_absolute_path("samples/one_file.wrf"));
     Archive arc(Quirks::solve_absolute_path("data/out.wrf").get());
     Texture tex(arc.get("ov.png"));
-    printf("%s\n", arc.get("test.txt").get());
-    uint16_t dungeonTest[] = {
-        21, 21,  1,   1,   1,   1,   21,  22,  21,  22, 21,  22,  21,  21,  1,   22,  21,
-        1,  22,  22,  22,  1,   21,  2,   3,   3,   3,  3,   3,   4,   21,  1,   22,  21,
-        22, 22,  21,  21,  21,  1,   22,  22,  22,  23, 108, 109, 109, 109, 24,  87,  4,
-        21, 21,  22,  5,   6,   6,   7,   1,   1,   22, 21,  21,  23,  66,  67,  108, 109,
-        24, 109, 25,  21,  22,  5,   132, 43,  43,  28, 1,   1,   21,  22,  1,   23,  25,
-        23, 109, 109, 108, 108, 25,  1,   1,   26,  42, 110, 48,  49,  22,  21,  1,   21,
-        21, 23,  87,  88,  109, 24,  109, 109, 25,  1,  1,   26,  43,  131, 6,   7,   21,
-        1,  22,  1,   21,  44,  67,  109, 24,  24,  24, 66,  46,  1,   22,  26,  27,  43,
-        42, 131, 7,   21,  22,  1,   22,  21,  44,  45, 45,  45,  45,  46,  1,   22,  1,
-        26, 27,  27,  43,  27,  28,  22,  21,  22,  21, 1,   21,  1,   22,  22,  21,  1,
-        21, 22,  1,   47,  48,  111, 42,  27,  28,  21, 21,  1,   21,  21,  22,  2,   3,
-        3,  4,   1,   2,   3,   4,   1,   5,   132, 27, 27,  28,  1,   1,   22,  1,   22,
-        21, 23,  24,  66,  46,  1,   23,  24,  25,  1,  26,  42,  42,  110, 49,  21,  22,
-        21, 22,  22,  2,   88,  24,  25,  2,   3,   88, 24,  87,  4,   26,  43,  110, 49,
-        21, 21,  1,   1,   1,   2,   88,  24,  24,  87, 88,  108, 24,  24,  109, 25,  47,
-        48, 49,  1,   22,  22,  21,  1,   21,  23,  24, 24,  24,  24,  24,  24,  24,  24,
-        24, 87,  4,   21,  21,  22,  22,  22,  22,  1,  21,  23,  24,  24,  109, 24,  24,
-        24, 24,  24,  108, 109, 25,  21,  21,  22,  22, 22,  22,  21,  21,  44,  45,  45,
-        67, 24,  24,  24,  66,  45,  45,  45,  46,  1,  22,  1,   22,  22,  22,  21,  22,
-        22, 22,  1,   44,  67,  108, 108, 25,  22,  22, 1,   22,  21,  22,  21,  21,  1,
-        21, 22,  1,   22,  22,  1,   22,  44,  45,  45, 46,  1,   1,   1,   1,   21,  21,
-        21, 21,  21,  21,  22,  21,  21,  21,  1,   21, 1,   22,  22,  22,  1,   21,  22,
-        21, 1,   1,   22,  21,  1,   1,   21,  1,   1,  21,  21,  21,  1,   22,  22,  1,
-        21, 22,  21,  22,  1,   22,  21,  21,  21,
-    };
-    uint16_t dungeonTest2[] = {
-        0, 0, 0, 0, 0,   0,   0,   0,   0,   0,  0,  0,  0,  0,  0,   0,   0,   0,   0, 0,
-        0, 0, 0, 0, 0,   0,   0,   0,   0,   0,  0,  0,  0,  0,  0,   0,   0,   0,   0, 0,
-        0, 0, 0, 0, 0,   52,  53,  54,  55,  0,  0,  0,  0,  0,  0,   0,   0,   0,   0, 0,
-        0, 0, 0, 0, 0,   73,  74,  75,  76,  0,  0,  0,  0,  0,  0,   0,   0,   0,   0, 0,
-        0, 0, 0, 0, 0,   157, 158, 140, 160, 0,  0,  0,  0,  0,  0,   0,   0,   0,   0, 0,
-        0, 0, 0, 0, 0,   178, 179, 161, 181, 0,  12, 14, 12, 14, 162, 163, 164, 0,   0, 0,
-        0, 0, 0, 0, 0,   0,   0,   0,   0,   0,  0,  0,  0,  0,  183, 184, 185, 0,   0, 0,
-        0, 0, 0, 0, 0,   0,   0,   0,   0,   0,  0,  0,  0,  0,  166, 0,   0,   186, 0, 0,
-        0, 0, 0, 0, 0,   0,   0,   0,   0,   0,  0,  0,  0,  0,  0,   0,   145, 167, 0, 0,
-        0, 0, 0, 0, 0,   0,   0,   0,   0,   0,  0,  0,  0,  0,  0,   0,   0,   0,   0, 0,
-        0, 0, 0, 0, 0,   0,   0,   0,   0,   0,  0,  0,  0,  0,  0,   0,   0,   0,   0, 0,
-        0, 0, 0, 0, 133, 134, 134, 135, 0,   0,  0,  0,  0,  0,  0,   0,   0,   0,   0, 0,
-        0, 0, 0, 0, 154, 155, 155, 71,  135, 39, 40, 41, 0,  0,  0,   0,   0,   0,   0, 0,
-        0, 0, 0, 0, 154, 155, 155, 155, 156, 60, 61, 62, 0,  0,  0,   0,   0,   0,   0, 0,
-        0, 0, 0, 0, 175, 176, 51,  155, 156, 81, 82, 83, 0,  0,  0,   0,   0,   0,   0, 0,
-        0, 0, 0, 0, 0,   0,   175, 176, 177, 0,  0,  0,  0,  0,  0,   0,   0,   0,   0, 0,
-        0, 0, 0, 0, 0,   0,   0,   0,   0,   0,  0,  0,  0,  0,  0,   0,   0,   0,   0, 0,
-        0, 0, 0, 0, 0,   0,   0,   0,   0,   0,  0,  0,  0,  0,  0,   0,   0,   0,   0, 0,
-        0, 0, 0, 0, 0,   0,   0,   0,   0,   0,  0,  0,  0,  0,  0,   0,   0,   0,   0, 0,
-        0, 0, 0, 0, 0,   0,   0,   0,   0,   0,  0,  0,  0,  0,  0,   0,   0,   0,   0, 0,
-    };
+    if(arc.has("ov.png"))
+        printf("%s\n", arc.get("test.txt").get());
+
+    const uint8_t* l1 = arc.get("l1.bin").get();
+    const uint8_t* l2 = arc.get("l2.bin").get();
+
+    uint16_t* dungeonTest = new uint16_t[arc.get("l1.bin").file_size];
+    uint16_t* dungeonTest2 = new uint16_t[arc.get("l1.bin").file_size];
+
+    for(unsigned i = 0; i < arc.get("l1.bin").file_size; i+=2)
+    {
+        dungeonTest[i/2] = read_big_endian_value<uint16_t>(&l1[i]);
+        dungeonTest2[i/2] = read_big_endian_value<uint16_t>(&l2[i]);
+    }
 
     Map map(20, 20, dungeonTest, dungeonTest2, tex);
     tinystl::vector<Frame> stripe21;
@@ -88,6 +53,9 @@ int main(int argc, char *argv[])
     Quirks::deinit();
     Timing::deinit();
     Graphics::deinit();
+
+    delete[] dungeonTest;
+    delete[] dungeonTest2;
     return 0;
 
 }

+ 10 - 17
src/piaf/Archive.cpp

@@ -4,6 +4,7 @@
 #include <zlib.h>
 #include "Archive.h"
 #include "Quirks.h"
+#include "utility/misc.h"
 
 using tinystl::string;
 using WalrusRPG::PIAF::ARCHIVE_VERSION;
@@ -14,23 +15,7 @@ using WalrusRPG::PIAF::CompressionType;
 
 namespace
 {
-    /**
-     * Read big endian integer value in binary data array. Depends on the size
-     * of the given type, so using standardized types like stdint's is highly
-     * suggested.
-     *
-     * Also doesn't check for being in bounds of the array.
-     */
-      template <typename T> T read_big_endian_value(void *ptr)
-    {
-        T result = 0;
-        uint8_t *data = (uint8_t *) ptr;
-        // No, memcpy isn't working here because endianness issues.
-        for (unsigned i = 0; i < sizeof(T); i++)
-            // Writing each byte of value in order
-            result |= data[i] << (8 * (sizeof(T) - 1 - i));
-        return result;
-    }
+
 
     // Must get a pointer on the file table.
     /**
@@ -216,6 +201,14 @@ Archive::~Archive()
 
 }
 
+bool Archive::has(const char *filename)
+{
+    for (unsigned index = 0; index < nb_files; index++)
+        if (strncmp(filename, entries[index].filename, 8) == 0)
+            return true;
+    return false;
+}
+
 /**
  * Returns the stored file's data from giving a filename.
  */

+ 1 - 0
src/piaf/Archive.h

@@ -64,6 +64,7 @@ namespace WalrusRPG
             Archive(const char *filepath);
             Archive(tinystl::string &filepath);
             ~Archive();
+            bool has(const char *filename);
             File get(const char *filename);
 
         };

+ 3 - 0
src/utility/misc.cpp

@@ -0,0 +1,3 @@
+#include "misc.h"
+#include <cstdint>
+

+ 19 - 0
src/utility/misc.h

@@ -1,6 +1,8 @@
 #ifndef INCLUDE_MISC_H
 #define INCLUDE_MISC_H
 
+#include <cstdint>
+
 #define UNUSED(expr) (void)(expr)
 
 #define abs(x) ((x) < 0 ? -(x) : (x))
@@ -9,4 +11,21 @@
 
 #define in_range(x, a, b) (((x) >= (a)) && ((x) < (b)))
 
+/**
+ * Read big endian integer value in binary data array. Depends on the size
+ * of the given type, so using standardized types like stdint's is highly
+ * suggested.
+ *
+ * Also doesn't check for being in bounds of the array.
+ */
+  template <typename T> T read_big_endian_value(const void *ptr)
+{
+    T result = 0;
+    uint8_t *data = (uint8_t *) ptr;
+    // No, memcpy isn't working here because endianness issues.
+    for (unsigned i = 0; i < sizeof(T); i++)
+        // Writing each byte of value in order
+        result |= data[i] << (8 * (sizeof(T) - 1 - i));
+    return result;
+}
 #endif