From 78d07f005876cdfd3caf8144c455e8ae9ff77d76 Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Thu, 4 Dec 2025 11:07:10 -0500 Subject: pke: actual exe path, child process launch tweaks --- src/game.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index f56e129..1fc8d17 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -28,9 +28,32 @@ #include #include #include +#include #include #include +void game_get_executable_path(); + +#ifdef _WIN32 +#include +void game_get_executable_path() { + char buf[512]; + size_t result = GetModuleFileNameA(NULL, buf, 512); + // TODO leaky + char *val = (char*)malloc(strlen(buf)+1); + strcpy(val, buf); + pkeSettings.executable_path = val; +} +#else +void game_get_executable_path() { + auto path = std::filesystem::canonical("/proc/self/exe"); + // TODO leaky + char *val = (char*)malloc(strlen(path.c_str())+1); + strcpy(val, path.c_str()); + pkeSettings.executable_path = val; +} +#endif + void Game_Init(); void Game_Tick(double delta); void Game_Teardown(); @@ -100,11 +123,11 @@ void Game_Tick(double delta) { window_tick_late(delta); } -void pke_game_main_init(PKEWindowProperties windowProps, const char *executablePath, PKEPluginInterface *plugins, unsigned int n_plugins) { +void pke_game_main_init(PKEWindowProperties windowProps, PKEPluginInterface *plugins, unsigned int n_plugins) { fprintf(stdout, "[%s] pke_game_main_init Entering.\n", __FILE__); unsigned int u; - pkeSettings.executablePath = executablePath; + game_get_executable_path(); Game_Init(); pk_ev_init(pkeSettings.mem_bkt.game); @@ -333,9 +356,9 @@ void pke_game_main_teardown() { fprintf(stdout, "[%s] pke_game_main_teardown Exiting.\n", __FILE__); } -void Game_Main(PKEWindowProperties windowProps, const char *executablePath) { +void Game_Main(PKEWindowProperties windowProps) { - pke_game_main_init(windowProps, executablePath, nullptr, 0); + pke_game_main_init(windowProps); pke_game_main_load(); -- cgit v1.2.3