소스 검색

Using Tinystl's string and added nspire's implementation of path solver. It should work now

Eiyeron Fulmincendii 10 년 전
부모
커밋
b668888782
6개의 변경된 파일54개의 추가작업 그리고 9개의 파일을 삭제
  1. 7 1
      platform/include/Quirks.h
  2. 34 1
      platform/nspire/Quirks.cpp
  3. 7 1
      platform/sfml/Quirks.cpp
  4. 2 3
      src/engine/main.cpp
  5. 2 1
      src/piaf/Archive.cpp
  6. 2 2
      src/piaf/Archive.h

+ 7 - 1
platform/include/Quirks.h

@@ -1,12 +1,18 @@
 #ifndef INCLUDE_QUIRKS_H
 #define INCLUDE_QUIRKS_H
 
+#include <TINYSTL/string.h>
+
 namespace WalrusRPG
 {
     namespace Quirks
     {
-        void init();
+        void init(const char *argv_0);
         void deinit();
+
+        // Relative path to absolute path resolving.
+        // Exists because at this time Ndless doesn't support relative paths.
+        tinystl::string solve_absolute_path(const char *path);
     }
 }
 

+ 34 - 1
platform/nspire/Quirks.cpp

@@ -1,15 +1,48 @@
+#include <cstddef>
+#include <cstring>
+#include <TINYSTL/string.h>
 #include "Quirks.h"
 #include "Interrupts.h"
 
+
 using namespace WalrusRPG;
 using namespace Nspire;
+using tinystl::string;
+
+namespace
+{
+    static char* base_path = nullptr;
+}
 
-void Quirks::init()
+void Quirks::init(const char *argv_0)
 {
     Interrupts::init();
+    // Find last '/' occurence and remove the trailing characters
+    // so we get rid of the executable name.
+    int last_slash_occurence = -1;
+    for (unsigned i = 0; argv_0[i] != '\0'; i++)
+    {
+        if (argv_0[i] == '/')
+            last_slash_occurence = i;
+    }
+    if( last_slash_occurence > 0)
+    {
+        base_path = new char[last_slash_occurence+2];
+        strncpy(base_path, argv_0, last_slash_occurence);
+        base_path[last_slash_occurence] = '/';
+        base_path[last_slash_occurence+1] = '\0';
+    }
 }
 
 void Quirks::deinit()
 {
     Interrupts::off();
+    delete[] base_path;
+}
+
+string Quirks::solve_absolute_path(const char *path)
+{
+    string str;
+    str.append(base_path, path);
+    return str;
 }

+ 7 - 1
platform/sfml/Quirks.cpp

@@ -1,11 +1,17 @@
 #include "Quirks.h"
 
 using namespace WalrusRPG;
+using tinystl::string;
 
-void Quirks::init()
+void Quirks::init(const char *argv_0)
 {
 }
 
 void Quirks::deinit()
 {
 }
+
+string Quirks::solve_absolute_path(const char* path)
+{
+    return path;
+}

+ 2 - 3
src/engine/main.cpp

@@ -13,13 +13,12 @@ using WalrusRPG::PIAF::Archive;
 int main(int argc, char *argv[])
 {
     UNUSED(argc);
-    UNUSED(argv);
 
     Graphics::init();
     Timing::init();
-    Quirks::init();
+    Quirks::init(argv[0]);
 
-    // Archive arc("samples/one_file.wrf");
+    // Archive arc(Quirks::solve_absolute_path("samples/one_file.wrf"));
 
     uint16_t dungeonTest[] = {
         21, 21,  1,   1,   1,   1,   21,  22,  21,  22, 21,  22,  21,  21,  1,   22,  21,

+ 2 - 1
src/piaf/Archive.cpp

@@ -3,6 +3,7 @@
 #include <cstdio>
 #include <zlib.h>
 
+using tinystl::string;
 using WalrusRPG::PIAF::Archive;
 using WalrusRPG::PIAF::File;
 using WalrusRPG::PIAF::FileEntry;
@@ -41,7 +42,7 @@ namespace
     }
 }
 
-Archive::Archive(std::string &filepath) : Archive(filepath.c_str())
+Archive::Archive(string &filepath) : Archive(filepath.c_str())
 {
 }
 

+ 2 - 2
src/piaf/Archive.h

@@ -3,7 +3,7 @@
 
 #include <cstdint>
 #include <cstdio>
-#include <string>
+#include <TINYSTL/string.h>
 
 namespace WalrusRPG
 {
@@ -59,7 +59,7 @@ namespace WalrusRPG
           public:
             // RAII stuff
             Archive(const char *filepath);
-            Archive(std::string &filepath);
+            Archive(tinystl::string &filepath);
             ~Archive();
 
             FileEntry get_file_entry(char *filename);