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-settings.hpp | 2 +- src/game.cpp | 31 +++++++++++++++++++++++++++---- src/game.hpp | 4 ++-- 3 files changed, 30 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/game-settings.hpp b/src/game-settings.hpp index 46f5d38..109e759 100644 --- a/src/game-settings.hpp +++ b/src/game-settings.hpp @@ -8,7 +8,7 @@ #include struct GameSettings { - const char *executablePath; + const char *executable_path; bool isGameRunning = true; bool isGamePaused = false; bool isShowingEditor = true; 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(); diff --git a/src/game.hpp b/src/game.hpp index b599c24..8d23eaf 100644 --- a/src/game.hpp +++ b/src/game.hpp @@ -4,9 +4,9 @@ #include "plugin-types.hpp" #include "window-types.hpp" -void Game_Main(PKEWindowProperties windowProps, const char *executablePath); +void Game_Main(PKEWindowProperties windowProps); -void pke_game_main_init(PKEWindowProperties windowProps, const char *executablePath, PKEPluginInterface *interfaces = nullptr, unsigned int n_interfaces = 0); +void pke_game_main_init(PKEWindowProperties windowProps, PKEPluginInterface *interfaces = nullptr, unsigned int n_interfaces = 0); void pke_game_main_load(); void pke_game_main_run(); void pke_game_main_teardown(); -- cgit v1.2.3