Procházet zdrojové kódy

Comment and cleaning

Eiyeron Fulmincendii před 9 roky
rodič
revize
412e42bdf5

+ 2 - 0
platform/include/Logger.h

@@ -2,6 +2,8 @@
 #define INCLUDE_LOGGER_H
 namespace WalrusRPG
 {
+    // Logging function to show content on screen (with IMGUI branch), console or
+    // eventually in a file (for nspire?)
     namespace Logger
     {
         void log(const char *fmt, ...);

+ 2 - 1
platform/include/Texture.h

@@ -21,13 +21,14 @@ namespace WalrusRPG
         {
           private:
           public:
+            // Mmmh, the smell of that awesome platform-based hack.
             texture_data_t data;
 
             Texture(WalrusRPG::PIAF::File entry);
             Texture(char *data);
             ~Texture();
             // Getters
-            WalrusRPG::Utils::Rect get_dimensions();
+            const WalrusRPG::Utils::Rect get_dimensions();
             const WalrusRPG::Graphics::Pixel get_pixel(unsigned x, unsigned y);
         };
     }

+ 4 - 4
platform/nspire/Texure.cpp

@@ -8,8 +8,8 @@
 using WalrusRPG::Graphics::Black;
 using WalrusRPG::Graphics::Pixel;
 using WalrusRPG::Graphics::Texture;
-using WalrusRPG::Utils::Rect;
 using WalrusRPG::PIAF::File;
+using WalrusRPG::Utils::Rect;
 
 namespace
 {
@@ -72,12 +72,12 @@ Texture::~Texture()
     // delete (data);
 }
 
-Rect Texture::get_dimensions()
+const Rect Texture::get_dimensions()
 {
-    return Rect(0, 0, data[0], data[1]);
+    return {0, 0, data[0], data[1]};
 }
 
 const Pixel Texture::get_pixel(unsigned x, unsigned y)
 {
-    return Pixel(data[2 + data[0] * y + x]);
+    return {data[2 + data[0] * y + x]};
 }

+ 7 - 0
platform/sfml/Logger.cpp

@@ -6,6 +6,10 @@ using namespace WalrusRPG;
 
 namespace
 {
+    // TODO : Find a better name
+    /**
+     * Prints the timestamp and the message category/type.
+     */
     void print_premessage(const char *type)
     {
         char date_buffer[256];
@@ -15,6 +19,9 @@ namespace
     }
 }
 
+// NOTE : I really wish there would be a better way to handle these stupid va_lists. So
+// much redundant code...
+
 void Logger::log(const char *fmt, ...)
 {
     print_premessage("  [LOG]");

+ 6 - 4
platform/sfml/Texture.cpp

@@ -9,6 +9,8 @@
 
 using namespace WalrusRPG::Graphics; /*Texture*/
 using WalrusRPG::Graphics::Pixel;
+using WalrusRPG::PIAF::File;
+using WalrusRPG::Utils::Rect;
 
 Texture::Texture(char *data) : data()
 {
@@ -44,16 +46,16 @@ Texture::~Texture()
 {
 }
 
-WalrusRPG::Utils::Rect Texture::get_dimensions()
+const Rect Texture::get_dimensions()
 {
     sf::Vector2u size = data.getSize();
-    return WalrusRPG::Utils::Rect(0, 0, size.x, size.y);
+    return {0, 0, size.x, size.y};
 }
 
-const WalrusRPG::Graphics::Pixel Texture::get_pixel(unsigned x, unsigned y)
+const Pixel Texture::get_pixel(unsigned x, unsigned y)
 {
     UNUSED(x);
     UNUSED(y);
     // TODO : return the actual value
-    return WalrusRPG::Graphics::Pixel(0);
+    return {0};
 }

+ 13 - 0
src/engine/StateMachine.cpp

@@ -17,6 +17,9 @@ using WalrusRPG::States::State;
 
 namespace
 {
+    /**
+     * Debug function showing a button state.
+     */
     void draw_button(signed x, signed y, KeyState state)
     {
         put_horizontal_line(x + 1, x + 5, y, Gray);
@@ -39,6 +42,9 @@ namespace
                 break;
         }
     }
+    /**
+     * Draws WRPG's buttons states.
+     */
     void draw_buttons()
     {
         draw_button(0, 24, key_get_state(Key::K_L));
@@ -56,6 +62,7 @@ namespace
         draw_button(56, 36, key_get_state(Key::K_A));
     }
 
+    // State stack. Pointer because polymorphism.
     static tinystl::vector<WalrusRPG::States::State *> stack;
 
 } /* namespace */
@@ -78,6 +85,7 @@ void StateMachine::push(State *state)
 
 void StateMachine::pop()
 {
+    // Mmmh, should StateMachine manage the state's destruction?...
     delete stack.back();
     stack.pop_back();
 }
@@ -89,6 +97,8 @@ void StateMachine::run()
     unsigned last_update = 0, update_stamp, update_time;
     unsigned last_frame = 0, frame_stamp, frame_time;
 
+    // TODO : Better way to handle FPS while not breaking anything. There are some issues
+    // if the update loop takes too much time.
     while (!stack.empty())
     {
         update_stamp = Timing::gettime();
@@ -102,6 +112,7 @@ void StateMachine::run()
             frame_stamp = Timing::gettime();
             frame_time = frame_stamp - last_frame;
             Graphics::frame_begin();
+            // Update the current state
             stack.back()->render(100 * frame_time / TIMER_FREQ);
             last_frame = frame_stamp;
 
@@ -111,10 +122,12 @@ void StateMachine::run()
                 Text::print_format(0, 240 - 8, "%ufps, %uups", TIMER_FREQ / frame_time,
                                    TIMER_FREQ / update_time);
             }
+            // TODO : use a boolean to show/hide and to avoid that frigging wanring.
             // draw_buttons();
             Graphics::frame_end();
         }
 
+        // TODO : better exit handling.
         if (Input::key_pressed(Key::K_SELECT))
         {
             while (Input::key_down(Key::K_SELECT))

+ 5 - 0
src/engine/StateMachine.h

@@ -6,12 +6,17 @@
 
 namespace WalrusRPG
 {
+    // StateMachine is the core system of WRPG.
+    // It stores the main game states and update the current one.
     namespace StateMachine
     {
         void init();
         void deinit();
         void push(WalrusRPG::States::State *state);
         void pop();
+        /**
+         * The main Update/Render loop of the engine.
+         */
         void run();
     };
 }

+ 3 - 0
src/render/Font.cpp

@@ -63,6 +63,9 @@ void Font::draw(uint16_t x, uint16_t y, const char c, const Pixel &col) const
                     chars[c2].dimensions, col);
 }
 
+// Note : I wonder if clang/g++ compiles correctly inlines with dynamic functions or
+// stuff... Because damn the duplicated code.
+
 void Font::draw(uint16_t x, uint16_t y, const char *str) const
 {
     for (unsigned i = 0; str[i] && x < 320; i++)

+ 5 - 0
src/render/Font.h

@@ -21,9 +21,14 @@ namespace WalrusRPG
         class Font
         {
           public:
+            // Font height.
             uint8_t baseline;
+            // Variable to override space's rendering width.
             uint8_t space_width;
+            // Character dimensions/offset container.
             CharacterParameters chars[256];
+            // Font texture
+            // TODO?: Determine if using a reference or a variable.
             WalrusRPG::Graphics::Texture &font_tex;
 
             Font(WalrusRPG::Graphics::Texture &font_tex,

+ 2 - 0
src/render/Text.h

@@ -7,6 +7,8 @@ namespace WalrusRPG
 {
     namespace Graphics
     {
+        // TODO?: Rename it for something more related? It was first to draw debug
+        // content, it's not even really that useful as there is the Font system now.
         namespace Text
         {
             void init();