Namespace list functions
This commit is contained in:
parent
ab469b8f37
commit
f72568c135
@ -17,12 +17,12 @@
|
|||||||
u64 count; \
|
u64 count; \
|
||||||
} LIST_TYPE_NAME(T)
|
} LIST_TYPE_NAME(T)
|
||||||
|
|
||||||
#define create_list(T) \
|
#define list_create(T) \
|
||||||
(LIST_TYPE_NAME(T) *)_create_list(sizeof(T), BASE_LIST_CAPACITY)
|
(LIST_TYPE_NAME(T) *)_create_list(sizeof(T), BASE_LIST_CAPACITY)
|
||||||
#define create_list_with_capacity(T, CAPACITY) \
|
#define list_create_with_capacity(T, CAPACITY) \
|
||||||
(LIST_TYPE_NAME(T) *)_create_list(sizeof(T), CAPACITY)
|
(LIST_TYPE_NAME(T) *)_create_list(sizeof(T), CAPACITY)
|
||||||
|
|
||||||
#define destroy_list(T, LP) \
|
#define list_destroy(T, LP) \
|
||||||
do { \
|
do { \
|
||||||
munmap(LP->items, sizeof(T) * LP->capacity); \
|
munmap(LP->items, sizeof(T) * LP->capacity); \
|
||||||
LP->items = NULL; \
|
LP->items = NULL; \
|
||||||
@ -31,7 +31,7 @@
|
|||||||
munmap(LP, sizeof(LIST_TYPE_NAME(T))); \
|
munmap(LP, sizeof(LIST_TYPE_NAME(T))); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define append(T, LP, ITEM) \
|
#define list_append(T, LP, ITEM) \
|
||||||
do { \
|
do { \
|
||||||
if (LP->count + 1 >= LP->capacity) { \
|
if (LP->count + 1 >= LP->capacity) { \
|
||||||
u64 new_capacity = LP->capacity * 2; \
|
u64 new_capacity = LP->capacity * 2; \
|
||||||
@ -50,7 +50,7 @@
|
|||||||
LP->items[(LP->count)++] = ITEM; \
|
LP->items[(LP->count)++] = ITEM; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define get(LP, IDX) LP->items[IDX]
|
#define list_get(LP, IDX) LP->items[IDX]
|
||||||
|
|
||||||
MAKE_LIST_TYPE(void);
|
MAKE_LIST_TYPE(void);
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ void draw_line(window_t *wnd, line_t line, colour_t colour) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i32 x = x0; x <= x1; ++x) {
|
for (i32 x = x0; x <= x1; ++x) {
|
||||||
set_pixel(wnd, x, (i32)(get(values, x - x0)), colour);
|
set_pixel(wnd, x, (i32)(list_get(values, x - x0)), colour);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (line.p1.y < line.p0.y) {
|
if (line.p1.y < line.p0.y) {
|
||||||
@ -41,25 +41,25 @@ void draw_line(window_t *wnd, line_t line, colour_t colour) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i32 y = y0; y <= y1; ++y) {
|
for (i32 y = y0; y <= y1; ++y) {
|
||||||
set_pixel(wnd, (i32)(get(values, y - y0)), y, colour);
|
set_pixel(wnd, (i32)(list_get(values, y - y0)), y, colour);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy_list(f32, values);
|
list_destroy(f32, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal list_float_t *interpolate(i32 i0, f32 d0, i32 i1, f32 d1) {
|
internal list_float_t *interpolate(i32 i0, f32 d0, i32 i1, f32 d1) {
|
||||||
list_float_t *values;
|
list_float_t *values;
|
||||||
if (i0 == i1) {
|
if (i0 == i1) {
|
||||||
values = create_list_with_capacity(f32, 20);
|
values = list_create_with_capacity(f32, 20);
|
||||||
if (values) {
|
if (values) {
|
||||||
append(f32, values, d0);
|
list_append(f32, values, d0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
values = create_list(f32);
|
values = list_create(f32);
|
||||||
if (!values) {
|
if (!values) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ internal list_float_t *interpolate(i32 i0, f32 d0, i32 i1, f32 d1) {
|
|||||||
f32 d = d0;
|
f32 d = d0;
|
||||||
|
|
||||||
for (i32 i = i0; i <= i1; ++i) {
|
for (i32 i = i0; i <= i1; ++i) {
|
||||||
append(f32, values, d);
|
list_append(f32, values, d);
|
||||||
d += a;
|
d += a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user