summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-12-04 11:07:10 -0500
committerJonathan Bradley <jcb@pikum.xyz>2025-12-04 11:07:10 -0500
commit78d07f005876cdfd3caf8144c455e8ae9ff77d76 (patch)
tree59d79689214e9de46eda68d26e7040c91c33c178 /src
parentc2d51783d5b9f17b4bbf624c33ba4ceb584aa4f5 (diff)
pke: actual exe path, child process launch tweaks
Diffstat (limited to 'src')
-rw-r--r--src/game-settings.hpp2
-rw-r--r--src/game.cpp31
-rw-r--r--src/game.hpp4
3 files changed, 30 insertions, 7 deletions
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 <cstdint>
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 <BulletCollision/NarrowPhaseCollision/btRaycastCallback.h>
#include <GLFW/glfw3.h>
#include <cstring>
+#include <filesystem>
#include <fstream>
#include <thread>
+void game_get_executable_path();
+
+#ifdef _WIN32
+#include <windows.h>
+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();