remove the assumption that game is ran from cwd at root

This commit is contained in:
2024-10-07 13:22:25 +03:00
parent 6cbfc8a5fb
commit 93aa8ff2b4
5 changed files with 37 additions and 10 deletions

View File

@ -7,7 +7,7 @@
#include <dlfcn.h>
#define GAME_OBJECT_PATH "./libgame.so"
#define GAME_OBJECT_NAME "libgame.so"
#define MODIFIED_TICKS_MERGED 10
@ -21,6 +21,7 @@ static uint64_t last_tick_modified;
static bool loaded_after_modification = true;
static SDL_mutex *lock;
static char *game_object_path;
static void load_game_object(void) {
/* needs to be closed otherwise symbols aren't resolved again */
@ -31,7 +32,7 @@ static void load_game_object(void) {
game_end_callback = NULL;
}
void *new_handle = dlopen(GAME_OBJECT_PATH, RTLD_LAZY);
void *new_handle = dlopen(game_object_path, RTLD_LAZY);
if (!new_handle) {
log_critical("Hot Reload Error: Cannot open game code shared object (%s)", dlerror());
goto ERR_OPENING_SO;
@ -95,10 +96,12 @@ static void watcher_callback(XWATCHER_FILE_EVENT event,
void game_object_load(void) {
SDL_asprintf(&game_object_path, "%s%s", ctx.base_dir, GAME_OBJECT_NAME);
watcher = xWatcher_create();
xWatcher_reference dir;
dir.path = GAME_OBJECT_PATH;
dir.path = game_object_path;
dir.callback_func = watcher_callback;
xWatcher_appendFile(watcher, &dir);