summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/include/engine/utils/hashmap.h6
-rw-r--r--src/utils/include/engine/utils/stack.h4
-rw-r--r--src/utils/src/fov.c11
-rw-r--r--src/utils/src/hashmap.c2
-rw-r--r--src/utils/src/misc.c22
-rw-r--r--src/utils/src/stack.c4
6 files changed, 25 insertions, 24 deletions
diff --git a/src/utils/include/engine/utils/hashmap.h b/src/utils/include/engine/utils/hashmap.h
index d8fdbf2..0113ce5 100644
--- a/src/utils/include/engine/utils/hashmap.h
+++ b/src/utils/include/engine/utils/hashmap.h
@@ -11,7 +11,7 @@ extern "C" {
#include <engine/core/memory.h>
#include <engine/utils/list.h>
-i32 lolhash(const usize s, i32 v);
+usize lolhash(const usize s, usize v);
/* Define a linked list before using this */
/* Example: DEFINE_LLIST(i32) */
@@ -23,7 +23,7 @@ i32 lolhash(const usize s, i32 v);
} hashmap_##type; \
\
type* hashmap_##type##_lookup(hashmap_##type* hmap, const type* val) { \
- const i32 idx = lolhash(64, type_to_int(val)); \
+ const usize idx = lolhash(64, type_to_int(val)); \
List_##type* head = &hmap->elems[idx]; \
while (head != NULL) { \
if (!cmp(&(head->value), val)) return &(head->value); \
@@ -34,7 +34,7 @@ i32 lolhash(const usize s, i32 v);
\
void hashmap_##type##_insert(memory* m, hashmap_##type* hmap, \
const type* val) { \
- const i32 idx = lolhash(64, type_to_int(val)); \
+ const usize idx = lolhash(64, type_to_int(val)); \
List_##type* head = &(hmap->elems[idx]); \
\
/* This is highly dependant on whether the memory is zero-initialized */ \
diff --git a/src/utils/include/engine/utils/stack.h b/src/utils/include/engine/utils/stack.h
index b8e1807..b4caf5f 100644
--- a/src/utils/include/engine/utils/stack.h
+++ b/src/utils/include/engine/utils/stack.h
@@ -8,7 +8,7 @@ extern "C" {
#include <engine/core/types.h>
typedef struct {
- isize head; /* current number of elements */
+ usize head; /* current number of elements */
const usize elem_size; /* size in bytes of each element */
usize size; /* current memory size used by the stack */
const usize chunk_size; /* size of which the stack increases when running out
@@ -24,7 +24,7 @@ void stack_free(Stack* s);
void* stack_pop(Stack* s);
void stack_push(Stack* s, void* elem);
void* stack_peek(Stack* s);
-isize stack_size(const Stack* s);
+usize stack_size(const Stack* s);
void stack_swap(Stack* s, Stack* t);
#ifdef __cplusplus
diff --git a/src/utils/src/fov.c b/src/utils/src/fov.c
index 7bd27e2..6cd4c49 100644
--- a/src/utils/src/fov.c
+++ b/src/utils/src/fov.c
@@ -37,19 +37,20 @@ void fov_shadowcast_rec(const void* map, const v2_i32 mapsize,
if (mapx >= 0 && mapx < (long)mapsize.x && mapy >= 0 &&
mapy < (long)mapsize.y) {
// TODO: Calculate proper dist from source
- f32 x_2 = (src.x - mapx) * (src.x - mapx);
- f32 y_2 = (src.y - mapy) * (src.y - mapy);
+ i32 x_2 = (src.x - mapx) * (src.x - mapx);
+ i32 y_2 = (src.y - mapy) * (src.y - mapy);
lightmap[mapy * mapsize.x + mapx] =
MAX(lightmap[mapy * mapsize.x + mapx],
- range - sqrt((f32)(x_2 + y_2)));
+ (i32)(range - sqrt((f64)(x_2 + y_2))));
}
}
/* sizeof(i32) is the size of enums */
/* -- unless the compiler doesn't follow standard behaviour */
const bool is_blocked = visblocking(
- (void*)((u64)map + sizeof(i32) /* ~ enum size */
- * (mapsize.x * mapy + mapx) /* index */
+ (void*)((u64)map
+ + sizeof(i32) /* ~ enum size */
+ * (usize)(mapsize.x * mapy + mapx) /* index */
));
if (blocked) {
diff --git a/src/utils/src/hashmap.c b/src/utils/src/hashmap.c
index 61c5e43..f7784d5 100644
--- a/src/utils/src/hashmap.c
+++ b/src/utils/src/hashmap.c
@@ -2,4 +2,4 @@
/* Currently, this is a "works, but very poorly" placeholder implementation.
* Should be avoided in practice */
-i32 lolhash(const usize s, i32 v) { return v % s; }
+usize lolhash(const usize s, usize v) { return v % s; }
diff --git a/src/utils/src/misc.c b/src/utils/src/misc.c
index 290c417..09094ec 100644
--- a/src/utils/src/misc.c
+++ b/src/utils/src/misc.c
@@ -11,13 +11,13 @@
f32 lerp(f32 dt, f32 a, f32 b) { return (a * (1.0f - dt)) + (b * dt); }
i32 int_lerp(f32 dt, i32 a, i32 b) {
- return ((f32)a * (1.0f - dt)) + ((f32)b * dt);
+ return (i32)((f32)a * (1.0f - dt)) + (i32)((f32)b * dt);
}
u32 hash(char* str) {
u32 sum = 0;
while (*str != '\0') {
- sum ^= (*str) * 0xdeece66d + 0xb;
+ sum ^= (u32)(*str) * 0xdeece66d + 0xb;
str++;
}
return sum;
@@ -28,20 +28,20 @@ u32 hash(char* str) {
* on failure: return NULL */
i32* kernmap(const void* map, i32* dstmap, const v2_i32 mapsize,
predicate_t* predicate) {
- const i32 w = mapsize.x;
- const i32 h = mapsize.y;
+ const usize w = (usize)mapsize.x;
+ const usize h = (usize)mapsize.y;
i32 mask[w * h];
if (w * h < 1) return NULL;
- for (i32 i = 0; i < w * h; i++) {
+ for (usize i = 0; i < w * h; i++) {
mask[i] = predicate((void*)((u64)map + sizeof(i32) * i)) ? 1 : 0;
}
- for (i32 y = 1; y < h - 1; y++) {
- for (i32 x = 1; x < w - 1; x++) {
- const i32 global_idx = (y * w) + x;
- const i32 offs = global_idx - w - 1;
+ for (usize y = 1; y < h - 1; y++) {
+ for (usize x = 1; x < w - 1; x++) {
+ const usize global_idx = (y * w) + x;
+ const usize offs = global_idx - w - 1;
i32 _sum = 0;
i32 shift = 0;
@@ -51,8 +51,8 @@ i32* kernmap(const void* map, i32* dstmap, const v2_i32 mapsize,
/* ....|3|4|5|....*/
/* ....|6|7|8|....*/
/* Where `4` is in the center, MASK_C */
- for (i32 yy = offs; yy <= offs + w + w; yy += w) {
- for (i32 xx = yy; xx < yy + 3; xx++) {
+ for (usize yy = offs; yy <= offs + w + w; yy += w) {
+ for (usize xx = yy; xx < yy + 3; xx++) {
_sum = _sum | (mask[xx] << shift++);
}
}
diff --git a/src/utils/src/stack.c b/src/utils/src/stack.c
index a5fc419..a7cb16d 100644
--- a/src/utils/src/stack.c
+++ b/src/utils/src/stack.c
@@ -57,7 +57,7 @@ void* stack_peek(Stack* s) {
return (u8*)s->data + ((s->head - 1) * s->elem_size);
}
-isize stack_size(const Stack* s) { return s->head; }
+usize stack_size(const Stack* s) { return s->head; }
void stack_swap(Stack* s, Stack* t) {
if (s->size > t->size) {
@@ -70,7 +70,7 @@ void stack_swap(Stack* s, Stack* t) {
ERROR("Failed to allocate memory for stack swapping!");
exit(EXIT_FAILURE);
}
- isize shead = s->head;
+ usize shead = s->head;
memcpy(tmp, s->data, s->size);
memcpy(s->data, t->data, t->size);