]> git.lizzy.rs Git - nothing.git/commitdiff
(#450) Render debug details for platforms
authorMetin Ozyildirim <metinozyildirim@trakya.edu.tr>
Sat, 14 Dec 2019 22:46:08 +0000 (22:46 +0000)
committerMetin Ozyildirim <metinozyildirim@trakya.edu.tr>
Tue, 24 Dec 2019 21:29:36 +0000 (21:29 +0000)
src/game/level/platforms.c
src/math/extrema.h

index 55b98682b6f4b191e78a448f9a1f5257adadeb11..e066d1a34e1827893868df30ba7beaaefb082e0e 100644 (file)
@@ -11,6 +11,7 @@
 #include "system/nth_alloc.h"
 #include "system/log.h"
 #include "game/level/level_editor/rect_layer.h"
+#include "math/extrema.h"
 
 struct Platforms {
     Lt *lt;
@@ -59,17 +60,57 @@ void destroy_platforms(Platforms *platforms)
     RETURN_LT0(platforms->lt);
 }
 
-/* TODO(#450): platforms do not render their ids in debug mode */
 int platforms_render(const Platforms *platforms,
                      const Camera *camera)
 {
     for (size_t i = 0; i < platforms->rects_size; ++i) {
+        Rect platform_rect = platforms->rects[i];
         if (camera_fill_rect(
                 camera,
-                platforms->rects[i],
+                platform_rect,
                 platforms->colors[i]) < 0) {
             return -1;
         }
+
+        char debug_text[256];
+        snprintf(debug_text, 256,
+            "id:%zd\n"
+            "x:%.2f\n"
+            "y:%.2f\n"
+            "w:%.2f\n"
+            "h:%.2f\n",
+            i, platform_rect.x, platform_rect.y, platform_rect.w, platform_rect.h);
+
+        Vec2f text_pos = (Vec2f){.x = platform_rect.x, .y = platform_rect.y};
+        Rect text_rect = sprite_font_boundary_box(text_pos, vec(2.0f, 2.0f), debug_text);
+
+        Rect world_viewport = camera_view_port(camera);
+        Rect viewport = camera_view_port_screen(camera);
+        
+        if (rects_overlap(
+                camera_rect(
+                    camera,
+                    platform_rect),
+                viewport) &&
+            camera_is_point_visible(
+                camera,
+                text_pos) == false) {
+            if (platform_rect.w > text_rect.w){
+                text_pos.x = MAX(float, MIN(float, world_viewport.x, platform_rect.x + platform_rect.w - text_rect.w),
+                                        platform_rect.x);
+            }
+            if (platform_rect.h > text_rect.h){
+                text_pos.y = MAX(float, MIN(float, world_viewport.y, platform_rect.y + platform_rect.h - text_rect.h),
+                                        platform_rect.y);
+            }
+        }
+
+        if (camera_render_debug_text(
+                camera,
+                debug_text,
+                text_pos) < 0) {
+            return -1;
+        }
     }
 
     return 0;
index d06229422d86b681efa4f8e5a301a5113eff0db8..1f49bd28ce4cfa2686fb140ee88abef05dadef0b 100644 (file)
@@ -9,6 +9,7 @@
         return a > b ? a : b;                   \
     }                                           \
 
+MAX_INSTANCE(float)
 MAX_INSTANCE(int64_t)
 MAX_INSTANCE(size_t)
 #define MAX(type, a, b) max_##type(a, b)
@@ -19,6 +20,7 @@ MAX_INSTANCE(size_t)
         return a < b ? a : b;                   \
     }                                           \
 
+MIN_INSTANCE(float)
 MIN_INSTANCE(int64_t)
 MIN_INSTANCE(size_t)
 #define MIN(type, a, b) min_##type(a, b)