From 6bb0c2f134cce5d97f08652c70caa489c6eead61 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 6 Mar 2025 23:11:45 +1100 Subject: [PATCH] rework entry into linux entry --- build.sh | 2 +- src/entry_linux.c | 18 ++++++ src/{main.h => entry_linux.h} | 4 ++ src/game.c | 13 +++-- src/game.h | 101 ++++++++++++++++++++++++++++++++++ src/main.c | 12 ---- src/platform.h | 4 +- src/platform_linux.c | 13 +++++ src/platform_linux.h | 2 + 9 files changed, 148 insertions(+), 21 deletions(-) create mode 100644 src/entry_linux.c rename src/{main.h => entry_linux.h} (87%) delete mode 100644 src/main.c diff --git a/build.sh b/build.sh index 80cf11c..ec682b6 100755 --- a/build.sh +++ b/build.sh @@ -18,7 +18,7 @@ if [ ! -v render_flag ]; then render_flag="-DSTG_VULKAN_RENDERER"; vulka auto_compile_flags="${render_flag}" # source files -source_files="../src/main.c" +source_files="../src/entry_linux.c" # includes include_flags="-I../src/ -I../external/ -L." diff --git a/src/entry_linux.c b/src/entry_linux.c new file mode 100644 index 0000000..86b9b24 --- /dev/null +++ b/src/entry_linux.c @@ -0,0 +1,18 @@ +#ifdef __linux__ + +#include "entry_linux.h" + +#include "platform.c" +#include "util.c" +#include "arena.c" +#include "render.c" +#include "game.c" + +int main(int argc, char **argv) +{ + Assert(CreatePlatformWindow(), "Failed to initialize the window"); + InitializeGame(); + Run(); +} + +#endif // __linux__ diff --git a/src/main.h b/src/entry_linux.h similarity index 87% rename from src/main.h rename to src/entry_linux.h index 3dfdb7c..dbf11a7 100644 --- a/src/main.h +++ b/src/entry_linux.h @@ -1,3 +1,5 @@ +#ifdef __linux__ + #pragma once #define STB_SPRINTF_IMPLEMENTATION @@ -15,3 +17,5 @@ #include "game.h" int main(int argc, char **argv); + +#endif // __linux__ diff --git a/src/game.c b/src/game.c index 8d642aa..6e0cca1 100644 --- a/src/game.c +++ b/src/game.c @@ -1,18 +1,19 @@ -static void Run() +static void InitializeGame() { - InitPlatform(); - - u8 *mem = (u8 *)MemAllocZeroed(MB(512)); - Arena *arena = CreateArenaDebug(mem, MB(512), __LINE__); + // Will keep adjusting memory as needed + u8 *mem = (u8 *)MemAllocZeroed(MB(32)); + Arena *arena = CreateArenaDebug(mem, MB(32), __LINE__); isize renderer_mem_size = MB(8); rawptr renderer_mem = ArenaAlloc(arena, renderer_mem_size); Arena *renderer_arena = CreateArenaDebug(renderer_mem, MB(8), __LINE__); - Assert(CreateSystemWindow(), "Failed to initialize the window"); Assert(InitRenderer(renderer_arena), "Failed to initialize the renderer"); +} +static void Run() +{ b32 quit = false; while (!quit) { diff --git a/src/game.h b/src/game.h index 39005fd..e562156 100644 --- a/src/game.h +++ b/src/game.h @@ -1,5 +1,106 @@ #pragma once +typedef enum KeyboardInput_e +{ + KB_A, + KB_B, + KB_C, + KB_D, + KB_E, + KB_F, + KB_G, + KB_H, + KB_I, + KB_J, + KB_K, + KB_L, + KB_M, + KB_N, + KB_O, + KB_P, + KB_Q, + KB_R, + KB_S, + KB_T, + KB_U, + KB_V, + KB_W, + KB_X, + KB_Y, + KB_Z, + KB_0, + KB_1, + KB_2, + KB_3, + KB_4, + KB_5, + KB_6, + KB_7, + KB_8, + KB_9, + KB_NUM_0, + KB_NUM_1, + KB_NUM_2, + KB_NUM_3, + KB_NUM_4, + KB_NUM_5, + KB_NUM_6, + KB_NUM_7, + KB_NUM_8, + KB_NUM_9, + KB_NUM_LOCK, + KB_NUM_SLASH, + KB_NUM_STAR, + KB_NUM_MIN + KB_NUM_PLUS + KB_NUM_ENTER, + KB_NUM_DEL, + KB_INSERT, + KB_DELETE, + KB_HOME, + KB_PAGE_UP, + KB_PAGE_DOWN, + KB_PRINT_SCREEN, + KB_SCROLL_LOCK, + KB_COMMA, + KB_PERIOD, + KB_BACK_SLASH, + KB_FORWARD_SLASH, + KB_MINUS, + KB_PLUS, + KB_F1, + KB_F2, + KB_F3, + KB_F4, + KB_F5, + KB_F6, + KB_F7, + KB_F8, + KB_F9, + KB_F10, + KB_F11, + KB_F12, + KB_UP, + KB_DOWN, + KB_LEFT, + KB_RIGHT, + KB_LEFT_CTRL, + KB_LEFT_ALT, + KB_LEFT_SHIFT, + KB_TAB, + KB_CAPS_LOCK, + KB_LEFT_SUPER, + KB_RIGHT_SUPER, + KB_ENTER, + KB_TILDE, + KB_ESC, + KB_SEMI_COLON, + KB_QUOTE, + KB_LEFT_BRACE, + KB_RIGHT_BRACE, + KB_BACK_SPACE +}; + static void Run(); static b32 HandleEvents(); static b32 WaitForAndHandleEvent(); diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 4802c68..0000000 --- a/src/main.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "main.h" - -#include "platform.c" -#include "util.c" -#include "arena.c" -#include "render.c" -#include "game.c" - -int main(int argc, char **argv) -{ - Run(); -} diff --git a/src/platform.h b/src/platform.h index 0be156f..b01bc8d 100644 --- a/src/platform.h +++ b/src/platform.h @@ -61,11 +61,11 @@ i32 Printfln(const char *fmt, ...); i32 EPrintf(const char *fmt, ...); // Window Functions -b32 CreateSystemWindow(); +b32 CreatePlatformWindow(); b32 GetWindowEvent(WindowEvent *event); void WaitForWindowEvent(WindowEvent *event); WindowSize GetWindowSize(); -b32 NeedWindowResize() +b32 NeedWindowResize(); b32 ShouldQuit(); // Directory Functions diff --git a/src/platform_linux.c b/src/platform_linux.c index 577c81a..584aee0 100644 --- a/src/platform_linux.c +++ b/src/platform_linux.c @@ -5,6 +5,8 @@ static Window linux_window = { .h = 1080, }; + + // Init b32 _LoadLib(const char *name, Library *out_lib) @@ -353,3 +355,14 @@ u8 *OSOpenFile(const char *) return bytes; } + +b32 _NeedWindowResize() +{ + return false; +} + +b32 _ShouldQuit() +{ + return false; +} + diff --git a/src/platform_linux.h b/src/platform_linux.h index 044e8a1..fda8fe4 100644 --- a/src/platform_linux.h +++ b/src/platform_linux.h @@ -139,4 +139,6 @@ b32 CheckSyscallErr(void *ptr); // Write Utils i32 Write(int fd, void const *str, isize count); +b32 _NeedWindowResize(); +b32 _ShouldQuit();