summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/include/engine/engine.h2
-rw-r--r--src/core/src/loop.c24
-rw-r--r--src/rendering/include/engine/rendering/window.h2
-rw-r--r--src/rendering/src/gl.c10
-rw-r--r--src/rendering/src/rendering.c17
-rw-r--r--src/rendering/src/window.c39
-rw-r--r--src/resources/src/model.c2
-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
13 files changed, 77 insertions, 68 deletions
diff --git a/src/core/include/engine/engine.h b/src/core/include/engine/engine.h
index 51228fb..0b1a540 100644
--- a/src/core/include/engine/engine.h
+++ b/src/core/include/engine/engine.h
@@ -49,7 +49,7 @@ void render_add_unit(RenderUnit* u);
void delay(uint64_t ms);
// file operations
-isize f_get_sz(FILE* f);
+usize f_get_sz(FILE* f);
#ifdef __cplusplus
diff --git a/src/core/src/loop.c b/src/core/src/loop.c
index 1c1ec52..076dc05 100644
--- a/src/core/src/loop.c
+++ b/src/core/src/loop.c
@@ -124,7 +124,7 @@ Platform* engine_init(const char* windowtitle, i32 windowWidth, i32 windowHeight
w = init_window_glfw(windowtitle, (ivec2){windowsize.x, windowsize.y}, flags);
// Dont forget to init the renderer
- init_render_opengl(w);
+ init_render_opengl(w, flags);
//{ /* Resource loading */
@@ -371,13 +371,13 @@ i32 engine_run(Platform* p, StateType initial_state, void* state_arg) {
printf(" FPS: %.1f"
"\tticks: %lu"
- "\tframetime: %luμs"
- "\trendertime: %luμs"
+ "\tframetime: %lu.%lums"
+ "\trendertime: %lu.%lums"
"\n"
, ((f64)(ticks - last_fps_ticks)) / ((f64)dt_measurement / 1000000.0)
, ticks
- , dt
- , rendertime_dt
+ , dt / 1000 , dt % 1000
+ , rendertime_dt / 1000 , rendertime_dt % 1000
);
last_fps_measurement = frame_end;
@@ -421,7 +421,7 @@ void engine_fps_max(Platform* p, u16 cap) {
p->fps_target = cap;
}
-isize f_get_sz(FILE* f) {
+usize f_get_sz(FILE* f) {
if (f == NULL) {
ERROR("File was null!");
return 0;
@@ -430,22 +430,28 @@ isize f_get_sz(FILE* f) {
const isize pos = ftell(f);
if (pos == -1) {
ERROR("Failed to determine file size (%d): %s", errno, strerror(errno));
+ return 0;
}
const i32 err = fseek(f, 0, SEEK_END);
if (err != 0) {
- if (err == ESPIPE) return 0;
- ERROR("Failed to determine file size!");
+ if (err == ESPIPE) {
+ ERROR("File is a pipe");
+ } else {
+ ERROR("Failed to determine file size!");
+ }
+ return 0;
}
const isize size = ftell(f);
if (size == -1) {
ERROR("Failed to determine file size (%d): %s", errno, strerror(errno));
+ return 0;
}
// Reset the position to the position prior to calling f_get_sz
fseek(f, pos, SEEK_SET);
- return size;
+ return (usize)size;
}
diff --git a/src/rendering/include/engine/rendering/window.h b/src/rendering/include/engine/rendering/window.h
index fff7bc6..561afd6 100644
--- a/src/rendering/include/engine/rendering/window.h
+++ b/src/rendering/include/engine/rendering/window.h
@@ -41,7 +41,7 @@ Window* init_window_glfw(const char* windowtitle, ivec2 windowsize, const u32 fl
void destroy_window(Window* w);
// Renderer intializer(s)
-void init_render_opengl(Window* w);
+void init_render_opengl(Window* w, const u32 flags);
void get_mousepos(double *x, double *y);
diff --git a/src/rendering/src/gl.c b/src/rendering/src/gl.c
index eec56e2..636c70f 100644
--- a/src/rendering/src/gl.c
+++ b/src/rendering/src/gl.c
@@ -56,7 +56,7 @@ Shader compile_shader(const char* file_path, const ShaderType shader_type) {
LOG("CREATED SHADER ID %d", shaderID);
if(file != NULL) {
- const i64 size = f_get_sz(file);
+ const usize size = f_get_sz(file);
source = calloc((usize)size + 1, sizeof(char));
@@ -240,11 +240,11 @@ RenderObject RenderObject_new(
/* For each buffer in the shader, */
/* The shader should be generalied, */
for (usize i = 0; i < num_buffers; i++) {
- const isize sz = buffers[i].size_elem * buffers[i].count;
+ const usize sz = buffers[i].size_elem * buffers[i].count;
gl->GenBuffers(1, &(buffers[i].buffername));
gl->BindBuffer(GL_ARRAY_BUFFER, buffers[i].buffername);
- gl->BufferData(GL_ARRAY_BUFFER, sz, buffers[i].data, GL_STATIC_DRAW);
+ gl->BufferData(GL_ARRAY_BUFFER, (isize)sz, buffers[i].data, GL_STATIC_DRAW);
}
o.shader = *shader;
@@ -259,11 +259,7 @@ RenderObject RenderObject_new(
return o;
}
-void RenderObject_generateBuffers(RenderObject *o) {
-}
-
ShaderType guess_shadertype_from_filename(const char *restrict fname) {
- u32 stype = 0;
const usize path_len = strlen(fname);
if (path_len <= 4) {
diff --git a/src/rendering/src/rendering.c b/src/rendering/src/rendering.c
index 81a9e11..f646297 100644
--- a/src/rendering/src/rendering.c
+++ b/src/rendering/src/rendering.c
@@ -51,10 +51,7 @@ int renderbatch_new(RenderBatch* renderbatch, usize count) {
return -1;
}
- if (count < 0) {
- ERROR("count must be a positive integer!");
- return -1;
- } else if (count == 0) {
+ if (count == 0) {
// Just allocate enough for a couple hundred
count = 255;
}
@@ -235,7 +232,6 @@ void render_present(Window* w) {
* this whole present GL specific? assign it as a fn ptr in the Window struct? */
GladGLContext *restrict gl = w->context;
Camera c = *GLOBAL_PLATFORM->cam;
- const f32 ratio = (float)w->windowsize[0] / (float)w->windowsize[1];
mat4 view; // view
vec3 angle; // viewing angle / direction of the camera
@@ -353,17 +349,6 @@ void r_set_camera(Camera* c) {
GLOBAL_PLATFORM->cam = c;
}
-void engine_window_resize_pointers(i32* w, i32* h) {
- //GLOBAL_PLATFORM->window->game_w = w;
- GLOBAL_PLATFORM->window->windowsize[0] = *w;
- GLOBAL_PLATFORM->window->windowsize[1] = *h;
-}
-
-void engine_window_resize_pointers_reset(void) {
- //GLOBAL_PLATFORM->window->game_w = NULL;
- //GLOBAL_PLATFORM->window->game_h = NULL;
-}
-
void engine_draw_sprite(Sprite* s, v2_i32* pos, f32 scale) {
if (drawcall_len + 1 >= drawcall_limit) return;
#ifdef _DEBUG
diff --git a/src/rendering/src/window.c b/src/rendering/src/window.c
index d1fdbc7..49ff332 100644
--- a/src/rendering/src/window.c
+++ b/src/rendering/src/window.c
@@ -34,15 +34,16 @@ void glfw_err_callback(int code, const char* description) {
}
void window_resize_callback(GLFWwindow* window, int width, int height) {
+ (void)width; (void)height;
const GladGLContext* gl = GLOBAL_PLATFORM->window->context;
glfwSwapBuffers(window);
gl->Finish();
}
void window_size_callback(GLFWwindow* window, int width, int height) {
+ (void)window;
const GladGLContext* gl = GLOBAL_PLATFORM->window->context;
Camera* c = GLOBAL_PLATFORM->cam;
- glfwGetWindowSize(window, &width, &height);
gl->Viewport(0,0, width, height);
GLOBAL_PLATFORM->window->windowsize[0] = width;
GLOBAL_PLATFORM->window->windowsize[1] = height;
@@ -56,6 +57,7 @@ void window_size_callback(GLFWwindow* window, int width, int height) {
}
+/* This is very glfw specific */
GladGLContext* create_context(GLFWwindow *window) {
glfwMakeContextCurrent(window);
@@ -87,6 +89,9 @@ static inline u64 platform_get_time_usec(void) {
}
return (u64)(t.tv_sec * 1000000 + t.tv_nsec / 1000);
}
+#define DAW_WINDOW_VSYNC (1 << 0)
+#define DAW_WINDOW_FULLSCREEN (1 << 1)
+#define DAW_WINDOW_RESIZEABLE (1 << 2)
Window* init_window_glfw(
const char* windowtitle, ivec2 windowsize,
@@ -109,7 +114,10 @@ Window* init_window_glfw(
INFO_("initializing window...");
//glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
- glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
+ if (!(flags & DAW_WINDOW_RESIZEABLE)) {
+ glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
+ }
+
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
glfwWindowHint(GLFW_FLOATING, GLFW_TRUE);
@@ -128,8 +136,14 @@ Window* init_window_glfw(
#endif
/* "On Wayland specifically, you need to swap the buffers
- * of a window for it to become visible." */
- window = glfwCreateWindow(windowsize[0], windowsize[1], windowtitle, NULL, NULL);
+ * once of a window for it to become visible." */
+ {
+ GLFWmonitor* mon = NULL;
+ if (flags & DAW_WINDOW_FULLSCREEN) mon = glfwGetPrimaryMonitor();
+
+ window = glfwCreateWindow(windowsize[0], windowsize[1], windowtitle, mon, NULL);
+ }
+
if (window == NULL) {
ERROR("Failed to create GLFW window!\n");
const char *desc;
@@ -161,7 +175,7 @@ Window* init_window_glfw(
}
/* Initializes opengl using the window */
-void init_render_opengl(Window* w) {
+void init_render_opengl(Window* w, const u32 flags) {
if (w == NULL || w->window == NULL) {
ERROR("Window is not initialized");
return;
@@ -180,13 +194,22 @@ void init_render_opengl(Window* w) {
// This is GLFW specific
GladGLContext *ctx = create_context((GLFWwindow*)w->window);
- ctx->Viewport(0, 0, w->windowsize[0], w->windowsize[1]);
-
if (ctx == NULL) {
ERROR("Failed to create glad context");
exit(EXIT_FAILURE);
}
+ if (w->framework == WINDOW_FRAMEWORK_GLFW) {
+ if (flags & DAW_WINDOW_VSYNC) {
+ glfwSwapInterval(1);
+ } else {
+ glfwSwapInterval(0);
+ }
+
+
+ ctx->Viewport(0, 0, w->windowsize[0], w->windowsize[1]);
+ }
+
#ifdef _DEBUG
ctx->ClearColor((float)0x10 / 255.f, (float)0x0a / 255.f, (float)0x33 / 255.f, 0.f);
#else
@@ -198,8 +221,6 @@ void init_render_opengl(Window* w) {
ctx->Enable(GL_DEPTH_TEST);
ctx->DepthFunc(GL_LESS);
- glfwSwapInterval(0);
-
w->context = ctx;
w->renderer = WINDOW_RENDERER_OPENGL;
}
diff --git a/src/resources/src/model.c b/src/resources/src/model.c
index 65bb614..7244e63 100644
--- a/src/resources/src/model.c
+++ b/src/resources/src/model.c
@@ -30,7 +30,7 @@ Model load_model(const Asset_ModelSpec *restrict ms) {
ERROR("Failed to load file " TERM_COLOR_YELLOW "%s" TERM_COLOR_RESET, ms->path);
return (Model){.format = format};
}
- const isize filesz = f_get_sz(f);
+ const usize filesz = f_get_sz(f);
char* filecontets = calloc(filesz, sizeof(char));
fread(filecontets, sizeof(char), filesz, f);
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);