eco2d/code/foundation/src/dev/debug_draw.c

64 lines
1.7 KiB
C
Raw Normal View History

2023-01-15 15:59:33 +00:00
#include "dev/debug_draw.h"
#include "core/game.h"
2021-08-29 10:48:29 +00:00
static debug_draw_queue draw_queue = {0};
2023-07-27 09:53:35 +00:00
#if !defined(_DEBUG) || 0
2021-08-29 10:48:29 +00:00
static bool draw_is_enabled = false;
#else
static bool draw_is_enabled = true;
#endif
debug_draw_queue *debug_draw_samples(void) {
return &draw_queue;
}
void debug_draw_flush(void) {
draw_queue.num_entries = 0;
}
void debug_draw_enable(bool state) {
draw_is_enabled = state;
}
bool debug_draw_state(void) {
return draw_is_enabled;
}
2021-11-01 18:20:07 +00:00
static inline void debug_push_entry(debug_draw_entry entry) {
2021-08-29 10:48:29 +00:00
if (!draw_is_enabled) return;
2021-09-08 14:12:38 +00:00
if (game_get_kind() == GAMEKIND_HEADLESS) return;
2021-08-29 10:48:29 +00:00
ZPL_ASSERT(draw_queue.num_entries < DEBUG_DRAW_MAX_ENTRIES);
draw_queue.entries[draw_queue.num_entries++] = entry;
}
void debug_push_line(debug_v2 a, debug_v2 b, int32_t color) {
debug_push_entry((debug_draw_entry){
.kind = DDRAW_LINE,
.color = color,
2022-10-17 16:28:18 +00:00
2021-08-29 10:48:29 +00:00
.a = a,
.b = b,
});
}
void debug_push_circle(debug_v2 pos, float radius, int32_t color) {
debug_push_entry((debug_draw_entry){
.kind = DDRAW_CIRCLE,
.color = color,
2022-10-17 16:28:18 +00:00
2021-08-29 10:48:29 +00:00
.pos = pos,
.radius = radius,
});
}
void debug_push_rect(debug_v2 bmin, debug_v2 bmax, int32_t color) {
debug_push_entry((debug_draw_entry){
.kind = DDRAW_RECT,
.color = color,
2022-10-17 16:28:18 +00:00
2021-08-29 10:48:29 +00:00
.bmin = bmin,
.bmax = bmax,
});
2021-11-01 18:20:07 +00:00
}