Move ARR_LEN macro to misc_utils

This commit is contained in:
Abdelrahman Said 2024-06-22 20:41:23 +01:00
parent 9f4137dac9
commit 5908cf3063
3 changed files with 27 additions and 5 deletions

View File

@ -0,0 +1,6 @@
#ifndef MISC_UTILS_H
#define MISC_UTILS_H
#define ARR_LEN(ARR) sizeof(ARR) / sizeof(ARR[0])
#endif // !MISC_UTILS_H

View File

@ -1,3 +1,4 @@
#include "misc/misc_utils.h"
#include "rasteriser/rasteriser.h" #include "rasteriser/rasteriser.h"
#include "vector/vec.h" #include "vector/vec.h"
#include "window/window.h" #include "window/window.h"
@ -22,8 +23,22 @@ int main(void) {
// i32 h_min = ((i32)window.half_height) * -1; // i32 h_min = ((i32)window.half_height) * -1;
// i32 h_max = (i32)window.half_height; // i32 h_max = (i32)window.half_height;
vec2i_t a = {.x = -300, .y = 0}; line_t lines[] = {
vec2i_t b = {.x = 300, .y = 250}; (line_t){
(vec2i_t){.x = -300, .y = 0},
(vec2i_t){.x = 300, .y = 250},
},
(line_t){
(vec2i_t){.x = -200, .y = -100},
(vec2i_t){.x = 240, .y = 120},
},
(line_t){
(vec2i_t){.x = -50, .y = -200},
(vec2i_t){.x = 60, .y = 240},
},
};
u32 count = ARR_LEN(lines);
while (running) { while (running) {
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
@ -36,7 +51,9 @@ int main(void) {
clear_window(&window, bg); clear_window(&window, bg);
draw_line(&window, a, b, (colour_t){.colour = 0xffffffff}); for (u32 i = 0; i < count; ++i) {
draw_line(&window, lines[i], (colour_t){.colour = 0xffffffff});
}
swap_buffers(&window); swap_buffers(&window);
} }

View File

@ -1,7 +1,6 @@
#include "scene/scene.h" #include "scene/scene.h"
#include "c_cpp_aliases/aliases.h" #include "c_cpp_aliases/aliases.h"
#include "misc/misc_utils.h"
#define ARR_LEN(ARR) sizeof(ARR) / sizeof(ARR[0])
internal const sphere_t spheres[] = { internal const sphere_t spheres[] = {
(sphere_t){ (sphere_t){