rework entry into linux entry

This commit is contained in:
Matthew 2025-03-06 23:11:45 +11:00
parent 662f1d9027
commit 6bb0c2f134
9 changed files with 148 additions and 21 deletions

View File

@ -18,7 +18,7 @@ if [ ! -v render_flag ]; then render_flag="-DSTG_VULKAN_RENDERER"; vulka
auto_compile_flags="${render_flag}" auto_compile_flags="${render_flag}"
# source files # source files
source_files="../src/main.c" source_files="../src/entry_linux.c"
# includes # includes
include_flags="-I../src/ -I../external/ -L." include_flags="-I../src/ -I../external/ -L."

18
src/entry_linux.c Normal file
View File

@ -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__

View File

@ -1,3 +1,5 @@
#ifdef __linux__
#pragma once #pragma once
#define STB_SPRINTF_IMPLEMENTATION #define STB_SPRINTF_IMPLEMENTATION
@ -15,3 +17,5 @@
#include "game.h" #include "game.h"
int main(int argc, char **argv); int main(int argc, char **argv);
#endif // __linux__

View File

@ -1,18 +1,19 @@
static void Run() static void InitializeGame()
{ {
InitPlatform(); // Will keep adjusting memory as needed
u8 *mem = (u8 *)MemAllocZeroed(MB(32));
u8 *mem = (u8 *)MemAllocZeroed(MB(512)); Arena *arena = CreateArenaDebug(mem, MB(32), __LINE__);
Arena *arena = CreateArenaDebug(mem, MB(512), __LINE__);
isize renderer_mem_size = MB(8); isize renderer_mem_size = MB(8);
rawptr renderer_mem = ArenaAlloc(arena, renderer_mem_size); rawptr renderer_mem = ArenaAlloc(arena, renderer_mem_size);
Arena *renderer_arena = CreateArenaDebug(renderer_mem, MB(8), __LINE__); 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"); Assert(InitRenderer(renderer_arena), "Failed to initialize the renderer");
}
static void Run()
{
b32 quit = false; b32 quit = false;
while (!quit) while (!quit)
{ {

View File

@ -1,5 +1,106 @@
#pragma once #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 void Run();
static b32 HandleEvents(); static b32 HandleEvents();
static b32 WaitForAndHandleEvent(); static b32 WaitForAndHandleEvent();

View File

@ -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();
}

View File

@ -61,11 +61,11 @@ i32 Printfln(const char *fmt, ...);
i32 EPrintf(const char *fmt, ...); i32 EPrintf(const char *fmt, ...);
// Window Functions // Window Functions
b32 CreateSystemWindow(); b32 CreatePlatformWindow();
b32 GetWindowEvent(WindowEvent *event); b32 GetWindowEvent(WindowEvent *event);
void WaitForWindowEvent(WindowEvent *event); void WaitForWindowEvent(WindowEvent *event);
WindowSize GetWindowSize(); WindowSize GetWindowSize();
b32 NeedWindowResize() b32 NeedWindowResize();
b32 ShouldQuit(); b32 ShouldQuit();
// Directory Functions // Directory Functions

View File

@ -5,6 +5,8 @@ static Window linux_window = {
.h = 1080, .h = 1080,
}; };
// Init // Init
b32 _LoadLib(const char *name, Library *out_lib) b32 _LoadLib(const char *name, Library *out_lib)
@ -353,3 +355,14 @@ u8 *OSOpenFile(const char *)
return bytes; return bytes;
} }
b32 _NeedWindowResize()
{
return false;
}
b32 _ShouldQuit()
{
return false;
}

View File

@ -139,4 +139,6 @@ b32 CheckSyscallErr(void *ptr);
// Write Utils // Write Utils
i32 Write(int fd, void const *str, isize count); i32 Write(int fd, void const *str, isize count);
b32 _NeedWindowResize();
b32 _ShouldQuit();