Day 21 complete.

This commit is contained in:
2026-03-18 17:02:29 -07:00
parent b7cf0164c6
commit 92c5a75c05
3 changed files with 45 additions and 19 deletions
+33 -13
View File
@@ -325,7 +325,7 @@ static F32 SDLGetSecondsElapsed(U64 Start, U64 End)
}
typedef struct sdl_game_code {
void *GameCode;
void *GameCodeDLL;
void (*UpdateAndRender)(game_memory *, game_input *, game_offscreen_buffer *, game_sound_output_buffer *);
B32 IsValid;
@@ -335,25 +335,35 @@ static sdl_game_code SDLLoadGameCode()
{
sdl_game_code Result = {0};
Result.GameCode = dlopen("./libhandmade.so", RTLD_NOW);
if(Result.GameCode) {
Result.UpdateAndRender = (void(*)(game_memory *, game_input *, game_offscreen_buffer *, game_sound_output_buffer *))dlsym(Result.GameCode, "UpdateAndRender");
Result.GameCodeDLL = dlopen("./libhandmade.so", RTLD_NOW);
if(Result.GameCodeDLL) {
Result.UpdateAndRender = (void(*)(game_memory *, game_input *, game_offscreen_buffer *, game_sound_output_buffer *))dlsym(Result.GameCodeDLL, "UpdateAndRender");
if(!Result.UpdateAndRender) {
// TODO: Diagnostic.
fprintf(stderr, "%s\n", dlerror());
// TODO: Diagnostic. dlerror()
}
Result.IsValid = Result.UpdateAndRender ? TRUE : FALSE;
} else {
// TODO: Diagnostic.
fprintf(stderr, "%s\n", dlerror());
// TODO: Diagnostic. dlerror()
}
if(!Result.IsValid) {
Result.UpdateAndRender = NULL;
}
return Result;
}
static void SDLUnloadGameCode(sdl_game_code *GameCode)
{
if(GameCode->GameCodeDLL)
dlclose(GameCode->GameCodeDLL); // NOTE: Might fail.
GameCode->IsValid = FALSE;
GameCode->UpdateAndRender = NULL;
}
S32 main(S32 argc, char *argv[])
{
sdl_game_code Game = SDLLoadGameCode();
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_AUDIO)) {
/* TODO: This didn't work . . . */
}
@@ -404,9 +414,9 @@ S32 main(S32 argc, char *argv[])
GameMemory.PermanentStorage = mmap(BaseAddress, TotalStorageSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
GameMemory.TransientStorage = (U8 *)(GameMemory.PermanentStorage) + GameMemory.PermanentStorageSize;
GameMemory.DEBUGPlatformReadEntireFile = DEBUGPlatformReadEntireFile;
GameMemory.DEBUGPlatformWriteEntireFile = DEBUGPlatformWriteEntireFile;
GameMemory.DEBUGPlatformFreeFileMemory = DEBUGPlatformFreeFileMemory;
GameMemory.DEBUGPlatformReadEntireFile = &DEBUGPlatformReadEntireFile;
GameMemory.DEBUGPlatformWriteEntireFile = &DEBUGPlatformWriteEntireFile;
GameMemory.DEBUGPlatformFreeFileMemory = &DEBUGPlatformFreeFileMemory;
if(SoundOutput.Samples && GameMemory.PermanentStorage && GameMemory.TransientStorage) {
game_input Input[2];
@@ -421,6 +431,9 @@ S32 main(S32 argc, char *argv[])
U64 LastCycleCount;
#endif
sdl_game_code Game = SDLLoadGameCode();
U32 LoadCounter = 0;
while(GlobalRunning) {
LastCounter = SDLGetWallClock();
@@ -432,6 +445,13 @@ S32 main(S32 argc, char *argv[])
S32 GameUpdateHz = MonitorRefreshHz / 2;
F32 TargetSecondsPerFrame = 1.0f / (F32)GameUpdateHz;
if(LoadCounter > (U32)(GameUpdateHz * 2)) {
SDLUnloadGameCode(&Game);
Game = SDLLoadGameCode();
LoadCounter = 0;
}
LoadCounter++;
game_controller_input *OldKeyboardController = GetController(OldInput, 0);
game_controller_input *NewKeyboardController = GetController(NewInput, 0);
game_controller_input ZeroController = {0};