summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/include/engine/core/platform.h9
-rw-r--r--src/core/include/engine/engine.h3
-rw-r--r--src/core/src/loop.c21
-rw-r--r--src/rendering/include/engine/rendering/platform.h2
-rw-r--r--src/rendering/include/engine/rendering/platform_glfw.h2
-rw-r--r--src/rendering/include/engine/rendering/rendering.h9
-rw-r--r--src/rendering/include/engine/rendering/window.h2
-rw-r--r--src/rendering/src/rendering.c21
-rw-r--r--src/rendering/src/window.c24
-rw-r--r--src/resources/include/engine/resources/model.h1
-rw-r--r--src/utils/CMakeLists.txt2
-rw-r--r--src/utils/include/engine/utils.h4
-rw-r--r--src/utils/include/engine/utils/fov.h6
-rw-r--r--src/utils/include/engine/utils/vector.h39
-rw-r--r--src/utils/src/fov.c28
-rw-r--r--src/utils/src/misc.c6
-rw-r--r--src/utils/src/vector.c32
17 files changed, 57 insertions, 154 deletions
diff --git a/src/core/include/engine/core/platform.h b/src/core/include/engine/core/platform.h
index 327bf02..7faf901 100644
--- a/src/core/include/engine/core/platform.h
+++ b/src/core/include/engine/core/platform.h
@@ -5,12 +5,13 @@
extern "C" {
#endif
+#include <cglm/ivec2.h>
+
#include <engine/core/types.h>
#include <engine/core/memory.h>
#include <engine/ctrl/input.h>
#include <engine/rendering/window.h>
#include <engine/resources.h>
-#include <engine/utils/vector.h>
#define NUM_GLOBAL_BINDINGS 1
@@ -30,10 +31,10 @@ typedef struct Instance {
/* TODO: Move mouse data to input ctx/bindings */
/* TODO: Move input ctx/bindings to window */
/* TODO: Move cam to window->renderer */
- v2_i32 mouse_pos;
+ ivec2 mouse_pos;
- v2_i32 mousedown;
- v2_i32 mouseup;
+ ivec2 mousedown;
+ ivec2 mouseup;
bool mouse_lclick;
bool mouse_rclick;
diff --git a/src/core/include/engine/engine.h b/src/core/include/engine/engine.h
index d0a61f2..aa4eff6 100644
--- a/src/core/include/engine/engine.h
+++ b/src/core/include/engine/engine.h
@@ -17,7 +17,6 @@ extern "C" {
#include <engine/core/state.h>
#include <engine/ctrl/input.h>
#include <engine/utils/stack.h>
-#include <engine/utils/vector.h>
typedef struct {
u32 texture_id;
@@ -27,7 +26,7 @@ typedef struct {
#include <engine/rendering/window.h>
#include <engine/core/platform.h>
-#include <cglm/cglm.h>
+#include <cglm/ivec2.h>
/* Essential functions */
Instance* engine_init(const char* windowtitle, i32 windowWidth, i32 windowHeight,
diff --git a/src/core/src/loop.c b/src/core/src/loop.c
index cd264a7..a17f540 100644
--- a/src/core/src/loop.c
+++ b/src/core/src/loop.c
@@ -4,7 +4,8 @@
#include <string.h>
#include <stdbool.h>
-#include <cglm/cglm.h>
+#include <cglm/ivec2.h>
+#include <cglm/cam.h>
#define STB_IMAGE_IMPLEMENTATION
#include <stb/stb_image.h>
@@ -91,14 +92,6 @@ i32 cmp_int(const void* a, const void* b) {
return *x - *y;
}
-//v2_i32 get_canvas_size(void* window) {
-// v2_i32 realsize;
-// glfwGetWindowSize(window, &(realsize.x), &(realsize.y));
-//
-// /* Set logical render size */
-// return realsize;
-//}
-
/* Creates the window, initializes IO, Rendering, Fonts and engine-specific
* resources. */
Instance* engine_init(const char* windowtitle, i32 windowWidth, i32 windowHeight,
@@ -114,7 +107,7 @@ Instance* engine_init(const char* windowtitle, i32 windowWidth, i32 windowHeight
INFO("Starting with pid %lu", pid);
}
#endif
- v2_i32 windowsize = (v2_i32){.x = windowWidth, .y = windowHeight};
+ ivec2 windowsize = {windowWidth, windowHeight};
Instance* p = (Instance*)calloc(1, sizeof(Instance));
Window* w = (Window*)calloc(1, sizeof(Window));
@@ -123,7 +116,7 @@ Instance* engine_init(const char* windowtitle, i32 windowWidth, i32 windowHeight
Resources* resources = calloc(1, sizeof(Resources));
// TODO: Initialize them :)
- w = Platform_GLFW.window_init(p, windowtitle, (ivec2){windowsize.x, windowsize.y}, flags);
+ w = Platform_GLFW.window_init(p, windowtitle, (ivec2){windowsize[0], windowsize[1]}, flags);
p->window = w;
p->quit = false;
@@ -142,8 +135,10 @@ Instance* engine_init(const char* windowtitle, i32 windowWidth, i32 windowHeight
/* Getting the mouse coords now resolves the issue where a click "isn't
* registered" when the mouse isn't moved before the user clicks */
- p->mousedown = (v2_i32){-1, -1};
- p->mouseup = (v2_i32){-1, -1};
+ p->mousedown[0] = -1;
+ p->mousedown[1] = -1;
+ p->mouseup[0] = -1;
+ p->mouseup[1] = -1;
p->mouse_lclick = false;
p->mouse_rclick = false;
diff --git a/src/rendering/include/engine/rendering/platform.h b/src/rendering/include/engine/rendering/platform.h
index 5d2408e..9497fdb 100644
--- a/src/rendering/include/engine/rendering/platform.h
+++ b/src/rendering/include/engine/rendering/platform.h
@@ -5,7 +5,7 @@
extern "C" {
#endif
-#include <cglm/cglm.h>
+#include <cglm/ivec2.h>
#include <engine/core/types.h>
// TODO: We only need the window once all the garbage in Instance is cleaned up.
diff --git a/src/rendering/include/engine/rendering/platform_glfw.h b/src/rendering/include/engine/rendering/platform_glfw.h
index cbc3520..056d130 100644
--- a/src/rendering/include/engine/rendering/platform_glfw.h
+++ b/src/rendering/include/engine/rendering/platform_glfw.h
@@ -5,7 +5,7 @@
extern "C" {
#endif
-#include <cglm/cglm.h>
+#include <cglm/ivec2.h>
#include <engine/core/types.h>
#include <engine/rendering/platform.h>
diff --git a/src/rendering/include/engine/rendering/rendering.h b/src/rendering/include/engine/rendering/rendering.h
index d338778..5badec7 100644
--- a/src/rendering/include/engine/rendering/rendering.h
+++ b/src/rendering/include/engine/rendering/rendering.h
@@ -6,10 +6,9 @@ extern "C" {
#endif
#include <engine/core/types.h>
-#include <engine/utils/vector.h>
#include <engine/rendering/window.h>
-#include <cglm/cglm.h>
+#include <cglm/ivec2.h>
/* Definitions */
#define RGBA(_r, _g, _b, _a) ((Engine_color){.r = _r, .g = _g, .b = _b, .a = _a})
@@ -34,7 +33,7 @@ typedef struct {
typedef struct {
u32 texture_id;
- v2_i32 coord;
+ ivec2 coord;
} Sprite;
typedef enum {
@@ -230,8 +229,8 @@ void r_reset_camera(Camera* c);
//void window_size_callback(GLFWwindow* window, i32 width, i32 height);
-void engine_draw_sprite(Sprite* s, v2_i32* pos, f32 scale);
-void engine_draw_sprite_ex(Sprite* s, v2_i32* pos, f32 scale,
+void engine_draw_sprite(Sprite* s, ivec2* pos, f32 scale);
+void engine_draw_sprite_ex(Sprite* s, ivec2* pos, f32 scale,
Engine_color colormod);
void engine_draw_model(RenderObject* o, vec3 pos);
diff --git a/src/rendering/include/engine/rendering/window.h b/src/rendering/include/engine/rendering/window.h
index 83384bc..10d4ddd 100644
--- a/src/rendering/include/engine/rendering/window.h
+++ b/src/rendering/include/engine/rendering/window.h
@@ -5,7 +5,7 @@
extern "C" {
#endif
-#include <cglm/cglm.h>
+#include <cglm/ivec2.h>
#include <engine/core/types.h>
diff --git a/src/rendering/src/rendering.c b/src/rendering/src/rendering.c
index 424d3d5..b96e85a 100644
--- a/src/rendering/src/rendering.c
+++ b/src/rendering/src/rendering.c
@@ -3,6 +3,9 @@
#include <glad/gl.h>
#include <GLFW/glfw3.h>
+#include <cglm/cam.h>
+#include <cglm/vec2.h>
+#include <cglm/mat4.h>
#include <engine/engine.h>
@@ -593,7 +596,7 @@ void r_reset_camera(Camera* c) {
}
}
-void engine_draw_sprite(Sprite* s, v2_i32* pos, f32 scale) {
+void engine_draw_sprite(Sprite* s, ivec2* pos, f32 scale) {
if (drawcall_len + 1 >= drawcall_limit) return;
#ifdef _DEBUG
if (s == NULL) __asm__("int3;");
@@ -602,14 +605,14 @@ void engine_draw_sprite(Sprite* s, v2_i32* pos, f32 scale) {
(RenderDrawCall){.type = RenderDrawCallType_Sprite,
.data.sprite = {
.sprite = s,
- .x = pos->x,
- .y = pos->y,
+ .x = *pos[0],
+ .y = *pos[1],
.scale = scale,
//.mod = {0xFF, 0xFF, 0xFF, 0xFF},
}};
}
-void engine_draw_sprite_ex(Sprite* s, v2_i32* pos, f32 scale,
+void engine_draw_sprite_ex(Sprite* s, ivec2* pos, f32 scale,
Engine_color colormod) {
if (drawcall_len + 1 >= drawcall_limit) return;
#ifdef _DEBUG
@@ -619,8 +622,8 @@ void engine_draw_sprite_ex(Sprite* s, v2_i32* pos, f32 scale,
.type = RenderDrawCallType_Sprite,
.data.sprite = {
.sprite = s,
- .x = pos->x,
- .y = pos->y,
+ .x = *pos[0],
+ .y = *pos[1],
.scale = scale,
//.mod = {colormod.r, colormod.g, colormod.b, colormod.a},
}};
@@ -650,9 +653,9 @@ Sprite sprite_new(u64 tid, u8 coord) {
//((struct Resources*)GLOBAL_PLATFORM->data)->textures[tid]->tilesize;
return (Sprite){
.texture_id = (u32)tid,
- (v2_i32){
- .x = ts * (coord & 0x0F),
- .y = ts * ((coord & 0xF0) >> 4),
+ {
+ ts * (coord & 0x0F),
+ ts * ((coord & 0xF0) >> 4),
}};
}
diff --git a/src/rendering/src/window.c b/src/rendering/src/window.c
index e784158..e78ede0 100644
--- a/src/rendering/src/window.c
+++ b/src/rendering/src/window.c
@@ -1,4 +1,3 @@
-#include <stdio.h>
#include <time.h>
/* TODO: REMOVE THIS INCLUSION */
@@ -15,21 +14,10 @@
#undef GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
-#include <cglm/cglm.h>
+#include <cglm/ivec2.h>
extern Instance* GLOBAL_PLATFORM;
-
-/* Should honestly just write my own */
-static inline u64 glfw_gettime_msec(void) {
- return (u64)(glfwGetTime() * 1000.0);
-}
-
-/* Should honestly just write my own */
-static inline u64 glfw_gettime_usec(void) {
- return (u64)(glfwGetTime() * 1000000.0);
-}
-
static inline u64 platform_get_time_usec(void) {
struct timespec t;
int res = clock_gettime(CLOCK_MONOTONIC, &t);
@@ -60,13 +48,3 @@ void get_mousepos(double *x, double *y) {
}
}
-
-bool window_should_close(Window* w) {
- switch(w->framework) {
- case WINDOW_FRAMEWORK_GLFW:
- return glfwWindowShouldClose(w->window);
- break;
- default:
- return false;
- }
-}
diff --git a/src/resources/include/engine/resources/model.h b/src/resources/include/engine/resources/model.h
index c608729..a2fb29c 100644
--- a/src/resources/include/engine/resources/model.h
+++ b/src/resources/include/engine/resources/model.h
@@ -6,7 +6,6 @@ extern "C" {
#endif
#include <engine/core/types.h>
-#include <cglm/cglm.h>
typedef enum {
Model_error,
diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt
index 5e4d0d9..6acdba1 100644
--- a/src/utils/CMakeLists.txt
+++ b/src/utils/CMakeLists.txt
@@ -4,8 +4,8 @@ add_library(daw_utils
src/hashmap.c
src/misc.c
src/stack.c
- src/vector.c
)
target_compile_options(daw_utils PUBLIC ${BUILD_OPTS})
target_include_directories(daw_utils PRIVATE ${DAW_INCLUDE_DIRS})
+target_link_libraries(daw_utils PRIVATE cglm)
diff --git a/src/utils/include/engine/utils.h b/src/utils/include/engine/utils.h
index aa1343b..5096aa4 100644
--- a/src/utils/include/engine/utils.h
+++ b/src/utils/include/engine/utils.h
@@ -6,7 +6,7 @@ extern "C" {
#endif
#include <engine/core/types.h>
-#include <engine/utils/vector.h>
+#include <cglm/ivec2.h>
#define MIN(a, b) ((a < b) ? (a) : (b))
#define MAX(a, b) ((a > b) ? (a) : (b))
@@ -31,7 +31,7 @@ u32 hash(char* str);
/* Masks surrounding tiles of a kernel size of 3x3 */
/* In reality we only need 9 bits for this, but I think I had a reason for using
* i32 */
-i32* kernmap(const void* map, i32* dstmap, const v2_i32 mapsize,
+i32* kernmap(const void* map, i32* dstmap, const ivec2 mapsize,
predicate_t* predicate);
/* Returns an index from the given weights. */
diff --git a/src/utils/include/engine/utils/fov.h b/src/utils/include/engine/utils/fov.h
index 50df8fa..be64a9e 100644
--- a/src/utils/include/engine/utils/fov.h
+++ b/src/utils/include/engine/utils/fov.h
@@ -6,8 +6,8 @@ extern "C" {
#endif
#include <engine/core/types.h>
-#include <engine/utils/vector.h>
#include <stdbool.h>
+#include <cglm/ivec2.h>
/* `fov_shadowcast`: */
/* map: your 2D enum tile grid
@@ -18,9 +18,9 @@ extern "C" {
* distance to the source. range: visibility range/radius. src: 2D
* point to calculate FOV from
* */
-void fov_shadowcast(const void* map, const v2_i32 mapsize,
+void fov_shadowcast(const void* map, const ivec2 mapsize,
bool (*visblocking)(const void*), i32* lightmap,
- const i32 range, v2_i32 src);
+ const i32 range, const ivec2 src);
#ifdef __cplusplus
}
diff --git a/src/utils/include/engine/utils/vector.h b/src/utils/include/engine/utils/vector.h
deleted file mode 100644
index 7f4c4a4..0000000
--- a/src/utils/include/engine/utils/vector.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#ifndef VECTOR_H
-#define VECTOR_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <engine/core/types.h>
-
-#include <stdbool.h>
-#include <stdio.h>
-
-typedef struct {
- i32 x;
- i32 y;
-} v2_i32;
-
-bool v2_i32_eq(const v2_i32 a, const v2_i32 b);
-
-v2_i32 v2_i32_add(v2_i32 a, v2_i32 b);
-v2_i32 v2_i32_add_i(v2_i32 a, i32 b);
-v2_i32 v2_i32_sub(v2_i32 a, v2_i32 b);
-v2_i32 v2_i32_sub_i(v2_i32 a, i32 b);
-v2_i32 v2_i32_div(v2_i32 a, v2_i32 b);
-v2_i32 v2_i32_div_i(v2_i32 a, i32 b);
-v2_i32 v2_i32_mul(v2_i32 a, v2_i32 b);
-v2_i32 v2_i32_mul_i(v2_i32 a, i32 b);
-v2_i32 v2_i32_mod(v2_i32 a, v2_i32 b);
-v2_i32 v2_i32_mod_i(v2_i32 a, i32 b);
-v2_i32 v2_i32_max(v2_i32 a, v2_i32 b);
-v2_i32 v2_i32_min(v2_i32 a, v2_i32 b);
-v2_i32 v2_i32_lerp(f32 dt, v2_i32 a, v2_i32 b);
-
-void v2_i32_fprintf(FILE* stream, v2_i32 a);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/src/utils/src/fov.c b/src/utils/src/fov.c
index 6cd4c49..90df5af 100644
--- a/src/utils/src/fov.c
+++ b/src/utils/src/fov.c
@@ -3,9 +3,9 @@
#include <math.h>
#include <stdint.h>
-void fov_shadowcast_rec(const void* map, const v2_i32 mapsize,
+void fov_shadowcast_rec(const void* map, const ivec2 mapsize,
bool (*visblocking)(const void*), i32* lightmap,
- const i32 range, v2_i32 src, const i32 row, f32 start,
+ const i32 range, ivec2 src, const i32 row, f32 start,
const f32 end, const i8 xx, const i8 xy, const i8 yx,
const i8 yy) {
@@ -23,8 +23,8 @@ void fov_shadowcast_rec(const void* map, const v2_i32 mapsize,
while (dx <= 0) {
dx += 1;
- const i32 mapx = src.x + dx * xx + dy * xy;
- const i32 mapy = src.y + dx * yx + dy * yy;
+ const i32 mapx = src[0] + dx * xx + dy * xy;
+ const i32 mapy = src[1] + dx * yx + dy * yy;
const f32 slope_l = (((f32)dx) - 0.5f) / (((f32)dy) + 0.5f);
const f32 slope_r = (((f32)dx) + 0.5f) / (((f32)dy) - 0.5f);
@@ -34,13 +34,13 @@ void fov_shadowcast_rec(const void* map, const v2_i32 mapsize,
if (dx * dx + dy * dy < range_2) {
/* set as visible */
- if (mapx >= 0 && mapx < (long)mapsize.x && mapy >= 0 &&
- mapy < (long)mapsize.y) {
+ if (mapx >= 0 && mapx < (long)mapsize[0] && mapy >= 0 &&
+ mapy < (long)mapsize[1]) {
// TODO: Calculate proper dist from source
- 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],
+ i32 x_2 = (src[0] - mapx) * (src[0] - mapx);
+ i32 y_2 = (src[1] - mapy) * (src[1] - mapy);
+ lightmap[mapy * mapsize[0] + mapx] =
+ MAX(lightmap[mapy * mapsize[0] + mapx],
(i32)(range - sqrt((f64)(x_2 + y_2))));
}
}
@@ -50,7 +50,7 @@ void fov_shadowcast_rec(const void* map, const v2_i32 mapsize,
const bool is_blocked = visblocking(
(void*)((u64)map
+ sizeof(i32) /* ~ enum size */
- * (usize)(mapsize.x * mapy + mapx) /* index */
+ * (usize)(mapsize[0] * mapy + mapx) /* index */
));
if (blocked) {
@@ -74,9 +74,9 @@ void fov_shadowcast_rec(const void* map, const v2_i32 mapsize,
/* http://www.roguebasin.com/index.php?title=FOV_using_recursive_shadowcasting
*/
-void fov_shadowcast(const void* map, const v2_i32 mapsize,
+void fov_shadowcast(const void* map, const ivec2 mapsize,
bool (*visblocking)(const void*), i32* lightmap,
- const i32 range, const v2_i32 src) {
+ const i32 range, const ivec2 src) {
const i8 m[4][8] = {
{1, 0, 0, -1, -1, 0, 0, 1},
@@ -91,5 +91,5 @@ void fov_shadowcast(const void* map, const v2_i32 mapsize,
}
/* The center is the most lit square */
- lightmap[src.y * mapsize.x + src.x] = range;
+ lightmap[src[1] * mapsize[0] + src[0]] = range;
}
diff --git a/src/utils/src/misc.c b/src/utils/src/misc.c
index 09094ec..063efbf 100644
--- a/src/utils/src/misc.c
+++ b/src/utils/src/misc.c
@@ -26,10 +26,10 @@ u32 hash(char* str) {
/* Populates dstmap
* on success: return pointer to dstmap
* on failure: return NULL */
-i32* kernmap(const void* map, i32* dstmap, const v2_i32 mapsize,
+i32* kernmap(const void* map, i32* dstmap, const ivec2 mapsize,
predicate_t* predicate) {
- const usize w = (usize)mapsize.x;
- const usize h = (usize)mapsize.y;
+ const usize w = (usize)mapsize[0];
+ const usize h = (usize)mapsize[1];
i32 mask[w * h];
if (w * h < 1) return NULL;
diff --git a/src/utils/src/vector.c b/src/utils/src/vector.c
deleted file mode 100644
index 5fedb1f..0000000
--- a/src/utils/src/vector.c
+++ /dev/null
@@ -1,32 +0,0 @@
-#include <engine/utils.h>
-#include <engine/utils/vector.h>
-
-bool v2_i32_eq(const v2_i32 a, const v2_i32 b) {
- return (a.x == b.x) && (a.y == b.y);
-}
-v2_i32 v2_i32_add(v2_i32 a, v2_i32 b) { return (v2_i32){a.x + b.x, a.y + b.y}; }
-v2_i32 v2_i32_add_i(v2_i32 a, i32 b) { return (v2_i32){a.x + b, a.y + b}; }
-v2_i32 v2_i32_sub(v2_i32 a, v2_i32 b) { return (v2_i32){a.x - b.x, a.y - b.y}; }
-v2_i32 v2_i32_sub_i(v2_i32 a, i32 b) { return (v2_i32){a.x - b, a.y - b}; }
-v2_i32 v2_i32_div(v2_i32 a, v2_i32 b) { return (v2_i32){a.x / b.x, a.y / b.y}; }
-v2_i32 v2_i32_div_i(v2_i32 a, i32 b) { return (v2_i32){a.x / b, a.y / b}; }
-v2_i32 v2_i32_mul(v2_i32 a, v2_i32 b) { return (v2_i32){a.x * b.x, a.y * b.y}; }
-v2_i32 v2_i32_mul_i(v2_i32 a, i32 b) { return (v2_i32){a.x * b, a.y * b}; }
-v2_i32 v2_i32_mod(v2_i32 a, v2_i32 b) { return (v2_i32){a.x % b.x, a.y % b.y}; }
-v2_i32 v2_i32_mod_i(v2_i32 a, i32 b) { return (v2_i32){a.x % b, a.y % b}; }
-v2_i32 v2_i32_max(v2_i32 a, v2_i32 b) {
- return (v2_i32){MAX(a.x, b.x), MAX(a.y, b.y)};
-}
-v2_i32 v2_i32_min(v2_i32 a, v2_i32 b) {
- return (v2_i32){MIN(a.x, b.x), MIN(a.y, b.y)};
-}
-v2_i32 v2_i32_lerp(f32 dt, v2_i32 a, v2_i32 b) {
- return (v2_i32){
- .x = lerp(dt, (f32)a.x, (f32)b.x),
- .y = lerp(dt, (f32)a.y, (f32)b.y),
- };
-}
-
-void v2_i32_fprintf(FILE* stream, v2_i32 a) {
- fprintf(stream, "<%d,%d>", a.x, a.y);
-}