Eiyeron Fulmincendii 10 lat temu
rodzic
commit
a213ca7ff2

+ 4 - 4
platform/nspire/Quirks.cpp

@@ -12,7 +12,7 @@ using tinystl::string;
 
 namespace
 {
-    static char* base_path = nullptr;
+    static char *base_path = nullptr;
 }
 
 void Quirks::init(const char *argv_0)
@@ -26,12 +26,12 @@ void Quirks::init(const char *argv_0)
         if (argv_0[i] == '/')
             last_slash_occurence = i;
     }
-    if( last_slash_occurence > 0)
+    if (last_slash_occurence > 0)
     {
-        base_path = new char[last_slash_occurence+2];
+        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';
+        base_path[last_slash_occurence + 1] = '\0';
     }
 }
 

+ 16 - 13
platform/nspire/Texure.cpp

@@ -26,34 +26,37 @@ namespace
 
 Texture::Texture(File entry)
 {
-    unsigned char* pic;
+    unsigned char *pic;
     unsigned width, height;
 
-    signed result = lodepng_decode_memory(&pic, &width, &height, (unsigned char*)entry.get(), entry.file_size, LCT_RGBA, 8);
+    signed result =
+        lodepng_decode_memory(&pic, &width, &height, (unsigned char *) entry.get(),
+                              entry.file_size, LCT_RGBA, 8);
     UNUSED(result);
-    
+
     data = new uint16_t[width * height + 3];
     data[0] = width;
     data[1] = height;
     bool transparency_set(false);
-    for(unsigned y = 0; y < height; y++)
+    for (unsigned y = 0; y < height; y++)
     {
-        for (unsigned x = 0; x < width; x++) {
-            bool is_transparent = (pic[(y*width + x)*4+3] == 0);
-            if(is_transparent && transparency_set)
+        for (unsigned x = 0; x < width; x++)
+        {
+            bool is_transparent = (pic[(y * width + x) * 4 + 3] == 0);
+            if (is_transparent && transparency_set)
             {
-                data[y*width + x+3] = data[2];
+                data[y * width + x + 3] = data[2];
                 continue;
             }
-            uint16_t color = (pic[(y*width + x)*4]>>3)<<11;
-            color |= (pic[(y*width + x)*4 + 1]>>2)<<5;
-            color |= (pic[(y*width + x)*4 + 2]>>3);
-            if(is_transparent && !transparency_set)
+            uint16_t color = (pic[(y * width + x) * 4] >> 3) << 11;
+            color |= (pic[(y * width + x) * 4 + 1] >> 2) << 5;
+            color |= (pic[(y * width + x) * 4 + 2] >> 3);
+            if (is_transparent && !transparency_set)
             {
                 data[2] = color;
                 transparency_set = true;
             }
-            data[y*width + x+3] = color;
+            data[y * width + x + 3] = color;
         }
     }
     delete[] pic;

+ 1 - 1
platform/sfml/Quirks.cpp

@@ -16,7 +16,7 @@ void Quirks::deinit()
 
 std::unique_ptr<char> Quirks::solve_absolute_path(const char *path)
 {
-    std::unique_ptr<char> result(new char[strlen(path)]); 
+    std::unique_ptr<char> result(new char[strlen(path)]);
     strcpy(result.get(), path);
     return result;
 }

+ 2 - 5
platform/sfml/Texture.cpp

@@ -11,8 +11,7 @@
 
 using WalrusRPG::Graphics::Pixel;
 
-TEXTURE::Texture(char *data)
-:data()
+TEXTURE::Texture(char *data) : data()
 {
     uint16_t *data_16 = (uint16_t *) data;
     this->data.create(data_16[0], data_16[1]);
@@ -32,11 +31,9 @@ TEXTURE::Texture(char *data)
     this->data.update(pixels);
 
     free(pixels);
-
 }
 
-TEXTURE::Texture(WalrusRPG::PIAF::File entry)
-:data()
+TEXTURE::Texture(WalrusRPG::PIAF::File entry) : data()
 {
     // UNUSED(data);
     // TOOD : load from PIAF

+ 7 - 8
src/engine/main.cpp

@@ -25,17 +25,17 @@ int main(int argc, char *argv[])
     WalrusRPG::PIAF::File f1 = arc.get("l1.bin");
     WalrusRPG::PIAF::File f2 = arc.get("l2.bin");
 
-    const uint8_t* l1 = f1.get();
-    const uint8_t* l2 = f2.get();
+    const uint8_t *l1 = f1.get();
+    const uint8_t *l2 = f2.get();
 
     // TODO better map reading.
-    uint16_t* dungeonTest = new uint16_t[f1.file_size/2+1];
-    uint16_t* dungeonTest2 = new uint16_t[f1.file_size/2+1];
+    uint16_t *dungeonTest = new uint16_t[f1.file_size / 2 + 1];
+    uint16_t *dungeonTest2 = new uint16_t[f1.file_size / 2 + 1];
 
-    for(unsigned i = 0; i < f1.file_size/2; i++)
+    for (unsigned i = 0; i < f1.file_size / 2; i++)
     {
-        dungeonTest[i] = read_big_endian_value<uint16_t>(&l1[i*2]);
-        dungeonTest2[i] = read_big_endian_value<uint16_t>(&l2[i*2]);
+        dungeonTest[i] = read_big_endian_value<uint16_t>(&l1[i * 2]);
+        dungeonTest2[i] = read_big_endian_value<uint16_t>(&l2[i * 2]);
     }
 
     Map map(20, 20, dungeonTest, dungeonTest2, tex);
@@ -58,5 +58,4 @@ int main(int argc, char *argv[])
     delete[] dungeonTest;
     delete[] dungeonTest2;
     return 0;
-
 }

+ 2 - 1
src/map/Map.cpp

@@ -12,7 +12,8 @@ using WalrusRPG::Graphics::Texture;
 
 // Graphics::Texture tex_overworld((char *) overworld);
 
-MAP::Map(int width, int height, uint16_t *layer0, uint16_t *layer1, Texture& tex) : anim(), tex(tex)
+MAP::Map(int width, int height, uint16_t *layer0, uint16_t *layer1, Texture &tex)
+    : anim(), tex(tex)
 {
     this->renderer = new TileRenderer(tex, 16, 16);
     this->width = width;

+ 2 - 1
src/map/Map.h

@@ -25,7 +25,8 @@ namespace WalrusRPG
         TileRenderer *renderer;
         // TODO?: add a boolean/getter to know if a second layer exist?
       public:
-        Map(int width, int height, uint16_t *layer0, uint16_t *layer1, WalrusRPG::Graphics::Texture& tex);
+        Map(int width, int height, uint16_t *layer0, uint16_t *layer1,
+            WalrusRPG::Graphics::Texture &tex);
         ~Map();
         void render(Camera &camera, unsigned dt);
         void update(unsigned dt);

+ 18 - 23
src/piaf/Archive.cpp

@@ -21,15 +21,14 @@ using namespace Nspire;
 #endif
 namespace
 {
-
-
     // Must get a pointer on the file table.
     /**
      * Reads the file table from given data pointer to an empty FileEntry
      * array long enough and a given number of files to load.
      * The pointer must directly access the file entry region of the archive.
      */
-    void load_file_table(File *entries, uint32_t *data_offsets, char *data, uint32_t nb_files)
+    void load_file_table(File *entries, uint32_t *data_offsets, char *data,
+                         uint32_t nb_files)
     {
         for (unsigned index = 0; index < nb_files; index++)
         {
@@ -64,10 +63,11 @@ Archive::Archive(string &filepath) : Archive(filepath.c_str())
 }
 
 
-Archive::Archive(const char *filepath) : file(nullptr), entries(nullptr), files_data(nullptr), files_loaded(nullptr)
+Archive::Archive(const char *filepath)
+    : file(nullptr), entries(nullptr), files_data(nullptr), files_loaded(nullptr)
 {
 #if NSPIRE
-    Interrupts::off();   
+    Interrupts::off();
 #endif
     // Null pointer exception trigger
     if (filepath == nullptr)
@@ -109,7 +109,6 @@ Archive::Archive(const char *filepath) : file(nullptr), entries(nullptr), files_
         // So we coudln't load the whole header.
         // TODO : check flags and return correct exceptions
         // fprintf(stderr, "Error loading header\n");
-
     }
     // Check if the magic cookie is the same.
     // It's a first way to detect if the file is correctly an archive.
@@ -132,10 +131,10 @@ Archive::Archive(const char *filepath) : file(nullptr), entries(nullptr), files_
     version = read_big_endian_value<uint32_t>(&header_container[16]);
     if (version != ARCHIVE_VERSION)
     {
-         // std::exception up;
-         // throw up; // haha
+        // std::exception up;
+        // throw up; // haha
     }
-    
+
 
     // At this point, the archive header looks unaltered and we finally can parse
     // and load the header.
@@ -173,10 +172,10 @@ Archive::Archive(const char *filepath) : file(nullptr), entries(nullptr), files_
         entries = new File[nb_files];
         // Parse and story the filetable.
 
-        files_data = new uint8_t*[nb_files];
+        files_data = new uint8_t *[nb_files];
         files_loaded = new bool[nb_files];
         files_data_offset = new uint32_t[nb_files];
-        for(unsigned i = 0; i < nb_files; i++)
+        for (unsigned i = 0; i < nb_files; i++)
         {
             files_data[i] = nullptr;
             files_loaded[i] = false;
@@ -185,8 +184,6 @@ Archive::Archive(const char *filepath) : file(nullptr), entries(nullptr), files_
 
         load_file_table(entries, files_data_offset, file_entry_data, nb_files);
         delete[] file_entry_data;
-
-
     }
 #if NSPIRE
     Interrupts::init();
@@ -200,11 +197,11 @@ Archive::~Archive()
     if (entries != nullptr)
         delete[] entries;
 
-    if(files_data != nullptr)
+    if (files_data != nullptr)
     {
-        for(unsigned i = 0; i < nb_files; i++)
+        for (unsigned i = 0; i < nb_files; i++)
         {
-            if(files_data[i] != nullptr)
+            if (files_data[i] != nullptr)
             {
                 delete[] files_data[i];
             }
@@ -233,10 +230,10 @@ File Archive::get(const char *filename)
         if (strncmp(filename, entries[index].filename, 8) == 0)
         {
             // On demand load
-            if(!files_loaded[index])
+            if (!files_loaded[index])
             {
- #if NSPIRE
-               Interrupts::off();
+#if NSPIRE
+                Interrupts::off();
 #endif
                 uint8_t *data = new uint8_t[entries[index].file_size];
                 fseek(file, files_data_offset[index] + 32 + 24 * nb_files, SEEK_SET);
@@ -262,14 +259,12 @@ File Archive::get(const char *filename)
     // throw not found exception
 }
 
-File::File(uint8_t *data): data(data)
+File::File(uint8_t *data) : data(data)
 {
-
 }
 
 File::File() : data(nullptr)
 {
-
 }
 
 
@@ -277,7 +272,7 @@ File::~File()
 {
 }
 
-const uint8_t* File::get()
+const uint8_t *File::get()
 {
     return data;
 }

+ 5 - 6
src/piaf/Archive.h

@@ -28,8 +28,9 @@ namespace WalrusRPG
 
         class File
         {
-        protected:
-            const uint8_t* data;
+          protected:
+            const uint8_t *data;
+
           public:
             friend class Archive;
             char filename[9]; // 8 + a \0 in case of printing
@@ -41,8 +42,7 @@ namespace WalrusRPG
             File(uint8_t *data);
             File();
             ~File();
-            const uint8_t* get();
-
+            const uint8_t *get();
         };
 
         class Archive
@@ -55,7 +55,7 @@ namespace WalrusRPG
             File *entries;
             uint8_t **files_data;
             bool *files_loaded;
-            uint32_t* files_data_offset;
+            uint32_t *files_data_offset;
 
 
           public:
@@ -66,7 +66,6 @@ namespace WalrusRPG
             ~Archive();
             bool has(const char *filename);
             File get(const char *filename);
-
         };
     }
 }

+ 1 - 1
src/render/SpriteRenderer.cpp

@@ -23,7 +23,7 @@ void SPRITERENDERER::render(const unsigned id, const Rect &rect)
     Graphics::put_sprite(tilesheet, rect.x, rect.y, sprites[id]);
 }
 
-void SPRITERENDERER::render(const unsigned id, const Rect &rect, const Pixel& tint)
+void SPRITERENDERER::render(const unsigned id, const Rect &rect, const Pixel &tint)
 {
     Graphics::put_sprite_tint(tilesheet, rect.x, rect.y, sprites[id], tint);
 }

+ 2 - 1
src/render/SpriteRenderer.h

@@ -18,7 +18,8 @@ namespace WalrusRPG
         SpriteRenderer(WalrusRPG::Graphics::Texture tilesheet);
         void add_sprite(unsigned id, WalrusRPG::Utils::Rect rect);
         virtual void render(const unsigned id, const WalrusRPG::Utils::Rect &rect);
-        void render(const unsigned id, const WalrusRPG::Utils::Rect &rect, const WalrusRPG::Graphics::Pixel& tint);
+        void render(const unsigned id, const WalrusRPG::Utils::Rect &rect,
+                    const WalrusRPG::Graphics::Pixel &tint);
     };
 }
 

+ 0 - 1
src/render/Text.cpp

@@ -48,4 +48,3 @@ void TEXT::print_format(unsigned x, unsigned y, const std::string &format, ...)
 {
     TEXT::print_format(x, y, format.c_str());
 }
-

+ 1 - 1
src/render/TileRenderer.cpp

@@ -5,7 +5,7 @@
 using namespace WalrusRPG;
 using namespace WalrusRPG::Utils;
 
-TILERENDERER::TileRenderer(WalrusRPG::Graphics::Texture& _tilesheet, unsigned tile_width,
+TILERENDERER::TileRenderer(WalrusRPG::Graphics::Texture &_tilesheet, unsigned tile_width,
                            unsigned tile_height)
     : tilesheet(_tilesheet), tile_width(tile_width), tile_height(tile_height)
 {

+ 1 - 1
src/render/TileRenderer.h

@@ -15,7 +15,7 @@ namespace WalrusRPG
         unsigned tile_height;
 
       public:
-        TileRenderer(WalrusRPG::Graphics::Texture& tilesheet, unsigned tile_width,
+        TileRenderer(WalrusRPG::Graphics::Texture &tilesheet, unsigned tile_width,
                      unsigned tile_height);
         void render(const unsigned id, const WalrusRPG::Utils::Rect &rect);
 

+ 0 - 1
src/utility/misc.cpp

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

+ 1 - 1
src/utility/misc.h

@@ -16,7 +16,7 @@
  *
  * Also doesn't check for being in bounds of the array.
  */
-  template <typename T> T read_big_endian_value(const void *ptr)
+template <typename T> T read_big_endian_value(const void *ptr)
 {
     T result = 0;
     uint8_t *data = (uint8_t *) ptr;