Eiyeron Fulmincendii пре 9 година
родитељ
комит
deacb21272

+ 1 - 1
platform/nspire/rules.mk

@@ -4,7 +4,7 @@ SRCS_C += $(wildcard $(nspire_LOCAL_PATH)/platform/*.c)
 SRCS_CPP += $(wildcard $(nspire_LOCAL_PATH)/*.cpp)
 INCLUDE += $(nspire_LOCAL_PATH)/public
 
-CFLAGS_COMMON += -marm -DNSPIRE=1
+CFLAGS_COMMON += -marm -DTARGET_NSPIRE=1
 YCM_EXTRA_CFLAGS := -m32 -I$(NDLESS_GIT)/ndless-sdk/include -I$(HOME)/.ndless/include
 
 CC = nspire-gcc

+ 1 - 1
platform/sfml/rules.mk

@@ -6,7 +6,7 @@ INCLUDE += $(sfml_LOCAL_PATH)/public
 
 LDFLAGS += -lstdc++ -lsfml-window -lsfml-graphics -lsfml-system
 
-CFLAGS_COMMON += -DSFML=1
+CFLAGS_COMMON += -DTARGET_SFML=1
 
 CC = clang
 CPP = clang++

+ 2 - 2
src/input/Input.cpp

@@ -20,7 +20,7 @@ struct KeyBuffer
 struct KeyBuffer key_states[Key::K_SIZE] = {{false, false}};
 
 // TODO: make these software-mappable
-#ifdef SFML
+#ifdef TARGET_SFML
 using sf::Keyboard;
 InputMap key_map[] = {
     {Key::K_A, Keyboard::W},          {Key::K_B, Keyboard::X},
@@ -32,7 +32,7 @@ InputMap key_map[] = {
     {Key::K_START, Keyboard::Return}, {Key::K_SELECT, Keyboard::BackSpace},
 };
 #endif
-#ifdef NSPIRE
+#ifdef TARGET_NSPIRE
 static InputMap key_map[] = {
     {Key::K_A, KEY_NSPIRE_CTRL},    {Key::K_B, KEY_NSPIRE_SHIFT},
     {Key::K_L, KEY_NSPIRE_TAB},     {Key::K_R, KEY_NSPIRE_MENU},

+ 9 - 8
src/piaf/Archive.cpp

@@ -17,7 +17,7 @@ using WalrusRPG::PIAF::FileType;
 using WalrusRPG::PIAF::CompressionType;
 using namespace WalrusRPG::PIAF;
 
-#if NSPIRE
+#if TARGET_NSPIRE
 using namespace Nspire;
 #endif
 namespace
@@ -67,7 +67,7 @@ Archive::Archive(string &filepath) : Archive(filepath.c_str())
 Archive::Archive(const char *filepath)
     : file(nullptr), entries(nullptr), files_data(nullptr), files_loaded(nullptr)
 {
-#if NSPIRE
+#if TARGET_NSPIRE
     Interrupts::off();
 #endif
     // Null pointer exception trigger
@@ -148,7 +148,6 @@ Archive::Archive(const char *filepath)
     uint64_t calculated_data_size = filesize - 32 - 24 * nb_files;
     if (data_size != calculated_data_size)
     {
-        // T0D0 : throw wrong size exception
         // fprintf(stderr, "Bad data size : expected %u, got %lld\n", data_size,
         // calculated_data_size);
         throw PIAF::PIAFException("Data size mismatch", __LINE__, filepath);
@@ -162,12 +161,14 @@ Archive::Archive(const char *filepath)
             read_big_endian_value<uint32_t>(&header_container[12]);
         char *file_entry_data = new char[24 * nb_files];
         fseek(file, 32, SEEK_SET);
-        fread(file_entry_data, sizeof(char), 24 * nb_files, file);
+        if (fread(file_entry_data, sizeof(char), 24 * nb_files, file) < 24 * nb_files)
+        {
+            throw PIAF::PIAFException("Can't read file entry data", __LINE__, filepath);
+        }
         // Compare and trigger an exception if the checksum doesn't match.
         if (expected_filetable_checksum !=
             crc32(0L, (unsigned char *) file_entry_data, 24 * nb_files))
         {
-            // TODO : checksum exception
             // fprintf(stderr, "Bad filetable checksum\n");
             throw PIAF::PIAFException("Bad Filetable checksum", __LINE__, filepath);
         }
@@ -188,7 +189,7 @@ Archive::Archive(const char *filepath)
         load_file_table(entries, files_data_offset, file_entry_data, nb_files);
         delete[] file_entry_data;
     }
-#if NSPIRE
+#if TARGET_NSPIRE
     Interrupts::init();
 #endif
 }
@@ -235,7 +236,7 @@ File Archive::get(const char *filename)
             // On demand load
             if (!files_loaded[index])
             {
-#if NSPIRE
+#if TARGET_NSPIRE
                 Interrupts::off();
 #endif
                 uint8_t *data = new uint8_t[entries[index].file_size];
@@ -252,7 +253,7 @@ File Archive::get(const char *filename)
                     entries[index].data = data;
                 }
                 files_loaded[index] = true;
-#if NSPIRE
+#if TARGET_NSPIRE
                 Interrupts::init();
 #endif
             }

+ 1 - 1
src/render/Animator.cpp

@@ -8,7 +8,7 @@ namespace
     unsigned get_animation_duration(const WalrusRPG::Animation &anim)
     {
         unsigned duration = 0;
-        for (unsigned index = 0; index < anim.stripe.size(); index++)
+        for (unsigned index = 0, end = anim.stripe.size(); index < end; index++)
         {
             duration += anim.stripe[index].duration;
         }

+ 23 - 5
src/render/Camera.cpp

@@ -7,11 +7,8 @@ using namespace WalrusRPG;
 using WalrusRPG::Input::Key;
 
 Camera::Camera(signed x, signed y)
+    : x(x), y(y), render_area_width(320), render_area_height(240)
 {
-    this->x = x;
-    this->y = y;
-    render_area_width = 320;
-    render_area_height = 240;
 }
 
 Camera::~Camera()
@@ -60,6 +57,27 @@ signed Camera::get_y() const
     return this->y;
 }
 
+void Camera::set_center_x(signed x)
+{
+    this->x = x - render_area_width / 2;
+}
+
+signed Camera::get_center_x() const
+{
+    return this->x - render_area_height / 2;
+}
+
+void Camera::set_center_y(signed y)
+{
+    this->y = y - render_area_height / 2;
+}
+
+signed Camera::get_center_y() const
+{
+    return this->y - render_area_height / 2;
+}
+
+
 bool Camera::is_visible(const WalrusRPG::Utils::Rect &object) const
 {
     if ((in_range(object.x, x, x + (signed) render_area_width) ||
@@ -75,4 +93,4 @@ bool Camera::is_visible(const WalrusRPG::Utils::Rect &object) const
     {
         return false;
     }
-}
+}

+ 6 - 0
src/render/Camera.h

@@ -24,6 +24,7 @@ namespace WalrusRPG
 
       public:
         Camera(signed x, signed y);
+
         ~Camera();
         // This doesn't need any render as it's the utility which helps rendering. Unless
         // you want to show debnug things.
@@ -35,6 +36,11 @@ namespace WalrusRPG
         void set_y(signed y);
         signed get_y() const;
 
+        void set_center_x(signed x);
+        signed get_center_x() const;
+        void set_center_y(signed y);
+        signed get_center_y() const;
+
         // Can you see me, senpai ? >.<
         bool is_visible(const WalrusRPG::Utils::Rect &object) const;
     };

+ 1 - 1
src/textbox/Textbox.cpp

@@ -183,7 +183,7 @@ void Textbox::render(unsigned dt)
     if (buffer_index < 0)
         return;
     current_color = 0xFFFF;
-    put_rectangle(dimensions, Graphics::DarkGray);
+    put_rectangle(dimensions, Graphics::Black);
     // signed cur_x_max = cur_x + dimensions.width;
     unsigned global_index = global_string_offset;
     for (unsigned l = 0; l < nb_lines; l++)