Add debugging helpers

Francesco Pasa 10 months ago

CMakeLists.txt   M +1 -1

122 # Library
123 add_library(
124         alba STATIC src/glfw_surface.c src/window.c src/dynarray.c src/drawing.c src/text.c
125-        src/atlas.c ${hashmap_SOURCE_DIR}/hashmap.c
126+        src/atlas.c ${hashmap_SOURCE_DIR}/hashmap.c src/helpers.c
127         ${CMAKE_BINARY_DIR}/shaders/shaders.o ${CMAKE_BINARY_DIR}/data/Roboto-Regular.o
128 )
129 target_include_directories(alba PRIVATE src)

include/alba.h   M +7

22 void dynarray_release(const DynArray* array);
23 void dynarray_clear(DynArray* array);
24 void dynarray_sort(const DynArray* array, uint32_t (*is_before_pivot)(void* pivot, void* elem));
25+void dynarray_print(const DynArray* array, void (*print_element)(void* element));
26 
27 // Misc
28 typedef struct
30     float r, g, b, a;
31 } AlbaColor;
32 
33+void color_print(const AlbaColor* color);
34+
35 typedef struct
36 {
37     float x, y;
38 } AlbaVector;
39 
40+void vector_print(const AlbaVector* vector);
41+
42 typedef struct
43 {
44     AlbaColor color;
45     AlbaVector uv;
46 } AlbaAttribute;
47 
48+void attribute_print(const AlbaAttribute* attribute);
49+
50 // Window
51 typedef struct
52 {

src/helpers.c   A +22

 1+#include "alba.h"
 2+
 3+#include <stdio.h>
 4+
 5+void color_print(const AlbaColor* color)
 6+{
 7+    printf("AlbaColor{%f, %f, %f, %f}\n", color->r, color->g, color->b, color->a);
 8+}
 9+
10+void vector_print(const AlbaVector* vector)
11+{
12+    printf("AlbaVector{%f, %f}\n", vector->x, vector->y);
13+}
14+
15+void attribute_print(const AlbaAttribute* attribute)
16+{
17+    printf("AlbaAttribute{\n    ");
18+    color_print(&attribute->color);
19+    printf("    ");
20+    vector_print(&attribute->uv);
21+    printf("}\n");
22+}