Fix list type naming
This commit is contained in:
parent
d5a18828c5
commit
33b89a9e44
@ -8,8 +8,8 @@
|
|||||||
|
|
||||||
#define BASE_LIST_CAPACITY 1024
|
#define BASE_LIST_CAPACITY 1024
|
||||||
|
|
||||||
#define CONCAT(A, B, C) A##B##C
|
#define CONCAT(A, B) A##B
|
||||||
#define LIST_TYPE_NAME(T) CONCAT(list_, T, _t)
|
#define LIST_TYPE_NAME(T) CONCAT(list_, T)
|
||||||
|
|
||||||
#define MAKE_LIST_TYPE(T) \
|
#define MAKE_LIST_TYPE(T) \
|
||||||
typedef struct { \
|
typedef struct { \
|
||||||
@ -68,7 +68,7 @@
|
|||||||
|
|
||||||
MAKE_LIST_TYPE(void);
|
MAKE_LIST_TYPE(void);
|
||||||
|
|
||||||
list_void_t *_create_list(Arena *arena, u64 size, u64 count);
|
list_void *_create_list(Arena *arena, u64 size, u64 count);
|
||||||
void *_alloc_for_list(Arena *arena, u64 size);
|
void *_alloc_for_list(Arena *arena, u64 size);
|
||||||
|
|
||||||
#endif // !TYPED_LIST_H
|
#endif // !TYPED_LIST_H
|
||||||
|
@ -5,16 +5,15 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
list_void_t *_create_list(Arena *arena, u64 size, u64 count) {
|
list_void *_create_list(Arena *arena, u64 size, u64 count) {
|
||||||
list_void_t *list =
|
list_void *list = (list_void *)_alloc_for_list(arena, sizeof(list_void));
|
||||||
(list_void_t *)_alloc_for_list(arena, sizeof(list_void_t));
|
|
||||||
if (!list) {
|
if (!list) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
list->items = (void *)_alloc_for_list(arena, size * count);
|
list->items = (void *)_alloc_for_list(arena, size * count);
|
||||||
if (!list->items) {
|
if (!list->items) {
|
||||||
munmap(list, sizeof(list_void_t));
|
munmap(list, sizeof(list_void));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memset(list->items, 0, sizeof(size * count));
|
memset(list->items, 0, sizeof(size * count));
|
||||||
|
@ -11,8 +11,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
internal list_float_t *interpolate(Arena *arena, i32 i0, f32 d0, i32 i1,
|
internal list_float *interpolate(Arena *arena, i32 i0, f32 d0, i32 i1, f32 d1);
|
||||||
f32 d1);
|
|
||||||
|
|
||||||
internal inline void order_triangle_points(triangle_t *triangle);
|
internal inline void order_triangle_points(triangle_t *triangle);
|
||||||
|
|
||||||
@ -34,16 +33,16 @@ void draw_filled_triangle(window_t *wnd, Arena *arena, triangle_t triangle) {
|
|||||||
i32 x2 = triangle.p2.x;
|
i32 x2 = triangle.p2.x;
|
||||||
i32 y2 = triangle.p2.y;
|
i32 y2 = triangle.p2.y;
|
||||||
|
|
||||||
list_float_t *x01 = interpolate(arena, y0, x0, y1, x1);
|
list_float *x01 = interpolate(arena, y0, x0, y1, x1);
|
||||||
list_float_t *x12 = interpolate(arena, y1, x1, y2, x2);
|
list_float *x12 = interpolate(arena, y1, x1, y2, x2);
|
||||||
list_float_t *x02 = interpolate(arena, y0, x0, y2, x2);
|
list_float *x02 = interpolate(arena, y0, x0, y2, x2);
|
||||||
list_float_t *x012 = NULL;
|
list_float *x012 = NULL;
|
||||||
|
|
||||||
list_pop(x01); // Last element of x01 is a duplicate of first element in x12
|
list_pop(x01); // Last element of x01 is a duplicate of first element in x12
|
||||||
list_merge(f32, arena, x012, x01, x12);
|
list_merge(f32, arena, x012, x01, x12);
|
||||||
|
|
||||||
list_float_t *x_left;
|
list_float *x_left;
|
||||||
list_float_t *x_right;
|
list_float *x_right;
|
||||||
u64 middle = (u64)(floorf((f32)(x02->count) / 2.0f));
|
u64 middle = (u64)(floorf((f32)(x02->count) / 2.0f));
|
||||||
if (list_get(x02, middle) < list_get(x012, middle)) {
|
if (list_get(x02, middle) < list_get(x012, middle)) {
|
||||||
x_left = x02;
|
x_left = x02;
|
||||||
@ -72,10 +71,10 @@ void draw_shaded_triangle(window_t *wnd, Arena *arena, triangle_t triangle) {
|
|||||||
i32 x2 = triangle.p2.x;
|
i32 x2 = triangle.p2.x;
|
||||||
i32 y2 = triangle.p2.y;
|
i32 y2 = triangle.p2.y;
|
||||||
|
|
||||||
list_float_t *x01 = interpolate(arena, y0, x0, y1, x1);
|
list_float *x01 = interpolate(arena, y0, x0, y1, x1);
|
||||||
list_float_t *x12 = interpolate(arena, y1, x1, y2, x2);
|
list_float *x12 = interpolate(arena, y1, x1, y2, x2);
|
||||||
list_float_t *x02 = interpolate(arena, y0, x0, y2, x2);
|
list_float *x02 = interpolate(arena, y0, x0, y2, x2);
|
||||||
list_float_t *x012 = NULL;
|
list_float *x012 = NULL;
|
||||||
|
|
||||||
list_pop(x01); // Last element of x01 is a duplicate of first element in x12
|
list_pop(x01); // Last element of x01 is a duplicate of first element in x12
|
||||||
list_merge(f32, arena, x012, x01, x12);
|
list_merge(f32, arena, x012, x01, x12);
|
||||||
@ -83,18 +82,18 @@ void draw_shaded_triangle(window_t *wnd, Arena *arena, triangle_t triangle) {
|
|||||||
f32 h0 = triangle.h0;
|
f32 h0 = triangle.h0;
|
||||||
f32 h1 = triangle.h1;
|
f32 h1 = triangle.h1;
|
||||||
f32 h2 = triangle.h2;
|
f32 h2 = triangle.h2;
|
||||||
list_float_t *h01 = interpolate(arena, y0, h0, y1, h1);
|
list_float *h01 = interpolate(arena, y0, h0, y1, h1);
|
||||||
list_float_t *h12 = interpolate(arena, y1, h1, y2, h2);
|
list_float *h12 = interpolate(arena, y1, h1, y2, h2);
|
||||||
list_float_t *h02 = interpolate(arena, y0, h0, y2, h2);
|
list_float *h02 = interpolate(arena, y0, h0, y2, h2);
|
||||||
list_float_t *h012 = NULL;
|
list_float *h012 = NULL;
|
||||||
|
|
||||||
list_pop(h01); // Last element of h01 is a duplicate of first element in h12
|
list_pop(h01); // Last element of h01 is a duplicate of first element in h12
|
||||||
list_merge(f32, arena, h012, h01, h12);
|
list_merge(f32, arena, h012, h01, h12);
|
||||||
|
|
||||||
list_float_t *x_left;
|
list_float *x_left;
|
||||||
list_float_t *x_right;
|
list_float *x_right;
|
||||||
list_float_t *h_left;
|
list_float *h_left;
|
||||||
list_float_t *h_right;
|
list_float *h_right;
|
||||||
u64 middle = (u64)(floorf((f32)(x02->count) / 2.0f));
|
u64 middle = (u64)(floorf((f32)(x02->count) / 2.0f));
|
||||||
if (list_get(x02, middle) < list_get(x012, middle)) {
|
if (list_get(x02, middle) < list_get(x012, middle)) {
|
||||||
x_left = x02;
|
x_left = x02;
|
||||||
@ -108,7 +107,7 @@ void draw_shaded_triangle(window_t *wnd, Arena *arena, triangle_t triangle) {
|
|||||||
h_right = h02;
|
h_right = h02;
|
||||||
}
|
}
|
||||||
|
|
||||||
list_float_t *h_segment = NULL;
|
list_float *h_segment = NULL;
|
||||||
i32 index = -1;
|
i32 index = -1;
|
||||||
i64 xl = -1;
|
i64 xl = -1;
|
||||||
i64 xr = -1;
|
i64 xr = -1;
|
||||||
@ -128,7 +127,7 @@ void draw_shaded_triangle(window_t *wnd, Arena *arena, triangle_t triangle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void draw_line(window_t *wnd, Arena *arena, line_t line, colour_t colour) {
|
void draw_line(window_t *wnd, Arena *arena, line_t line, colour_t colour) {
|
||||||
list_float_t *values = NULL;
|
list_float *values = NULL;
|
||||||
|
|
||||||
if (abs(line.p1.x - line.p0.x) > abs(line.p1.y - line.p0.y)) {
|
if (abs(line.p1.x - line.p0.x) > abs(line.p1.y - line.p0.y)) {
|
||||||
if (line.p1.x < line.p0.x) {
|
if (line.p1.x < line.p0.x) {
|
||||||
@ -169,9 +168,8 @@ void draw_line(window_t *wnd, Arena *arena, line_t line, colour_t colour) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal list_float_t *interpolate(Arena *arena, i32 i0, f32 d0, i32 i1,
|
internal list_float *interpolate(Arena *arena, i32 i0, f32 d0, i32 i1, f32 d1) {
|
||||||
f32 d1) {
|
list_float *values;
|
||||||
list_float_t *values;
|
|
||||||
if (i0 == i1) {
|
if (i0 == i1) {
|
||||||
values = list_create_with_capacity(f32, arena, 20);
|
values = list_create_with_capacity(f32, arena, 20);
|
||||||
if (values) {
|
if (values) {
|
||||||
|
Loading…
Reference in New Issue
Block a user