From d38deeef3af2316a666f8fc0173940bd769b748e Mon Sep 17 00:00:00 2001 From: onelin Date: Sat, 1 Nov 2025 00:55:42 +0100 Subject: Flatten project structure This will make it easier to break up the code into smaller chunks again later. One would think doing this seems fun to me at this point. --- src/window.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/window.c (limited to 'src/window.c') diff --git a/src/window.c b/src/window.c new file mode 100644 index 0000000..ea42678 --- /dev/null +++ b/src/window.c @@ -0,0 +1,82 @@ +#include + +/* TODO: REMOVE THIS INCLUSION */ +#include + +#include +#include + +#define ENGINE_RENDERING_WINDOW_H_EXCLUDE_EXTERNS +#include +#undef ENGINE_RENDERING_WINDOW_H_EXCLUDE_EXTERNS + +#include + +#undef GLFW_INCLUDE_NONE +#include + +#include + +extern Instance* GLOBAL_PLATFORM; + +static inline u64 platform_get_time_usec(void) { + struct timespec t; + int res = clock_gettime(CLOCK_MONOTONIC, &t); + if (res != 0) { + // TODO: Check errno + WARN("Failed to get system time"); + } + return (u64)(t.tv_sec * 1000000 + t.tv_nsec / 1000); +} + +/* wrapper to get time in ms */ +u64 (*get_time)(void) = platform_get_time_usec; + + +#define DAW_WINDOW_VSYNC (1 << 0) +#define DAW_WINDOW_FULLSCREEN (1 << 1) +#define DAW_WINDOW_RESIZEABLE (1 << 2) + +// Wrapper to get a specific window and set up related structures. +// What the fuck is this doing here. +Window* Window_new(const struct Platform* p, const char *restrict title, Window_framework framework, Window_renderer renderer, ivec2 size, u32 flags) { + Window* w = NULL; + + switch (framework) { + case WINDOW_FRAMEWORK_GLFW: + switch (renderer) { + case WINDOW_RENDERER_OPENGL: + /* For now, pass instance as NULL, fix it once all the necessary bs is + * out of struct Instance */ + w = p->window_init(title, size, flags); + + w->bindings = NULL; + w->bindings_sz = 0; + w->bindings_len = 0; + + /// TODO + //w->cam = &default_camera; + return w; + break; + default: + ERROR("Unsupported renderer."); + } + break; + default: + ERROR("Unsupported framework."); + } + return NULL; +} + +void get_mousepos(double *x, double *y) { + Window* w = GLOBAL_PLATFORM->window; + + switch(w->framework) { + case WINDOW_FRAMEWORK_GLFW: + glfwGetCursorPos(GLOBAL_PLATFORM->window->window, x, y); + break; + default: + ERROR("get_mouse_pos not implemented for chosen framework."); + } + +} -- cgit v1.3