summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editor/editor-main.cpp2
-rw-r--r--editor/editor.cpp24
-rw-r--r--runtime/runtime.cpp2
-rw-r--r--src/game-settings.hpp2
-rw-r--r--src/game.cpp31
-rw-r--r--src/game.hpp4
6 files changed, 48 insertions, 17 deletions
diff --git a/editor/editor-main.cpp b/editor/editor-main.cpp
index 541e11f..15f9245 100644
--- a/editor/editor-main.cpp
+++ b/editor/editor-main.cpp
@@ -33,7 +33,7 @@ int main(int argc, char *argv[]) {
}
// run
PkeArgs_Parse(argc, argv);
- Game_Main({}, argv[0]);
+ Game_Main({});
pk_mem_bucket_destroy(bkt_editor);
fprintf(stdout, "PKE_EDITOR EXITING\n");
return 0;
diff --git a/editor/editor.cpp b/editor/editor.cpp
index c1be34b..7400d5f 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -118,14 +118,22 @@ void PkeEditor_Tick(double delta) {
subProgramPid = fork();
if (subProgramPid == 0) {
int status = -1;
- const char *argv[] = {
- "pke-runtime",
- "--plugin", pkeSettings.args.pluginPath == nullptr ? "libpke-example.o" : pkeSettings.args.pluginPath,
- "--project", pkeSettings.args.projectPath == nullptr ? PKE_PROJ_DEFAULT_FILENAME : pkeSettings.args.projectPath,
- "--scene", (editor_mstr.active_scene != nullptr && editor_mstr.active_scene->file_path.length > 0) ? editor_mstr.active_scene->file_path.val : PKE_PROJ_DEFAULT_FILENAME ,
- NULL,
- };
- status = execvp("pke-runtime", const_cast<char **>(argv));
+ std::vector<const char*> args;
+ args.push_back(pkeSettings.executable_path);
+ if (pkeSettings.args.pluginPath != nullptr && strstr(pkeSettings.args.pluginPath, "libpke-editor") == nullptr) {
+ args.push_back("--plugin");
+ args.push_back(pkeSettings.args.pluginPath);
+ }
+ if (pkeSettings.args.projectPath != nullptr) {
+ args.push_back("--project");
+ args.push_back(pkeSettings.args.projectPath);
+ }
+ if (editor_mstr.active_scene != nullptr && editor_mstr.active_scene->file_path.length > 0) {
+ args.push_back("--scene");
+ args.push_back(editor_mstr.active_scene->file_path.val);
+ }
+ args.push_back(NULL);
+ status = execvp(pkeSettings.executable_path, const_cast<char **>(&args[0]));
fprintf(stderr, "pke-runtime (child) exited with a status of %i\n", status);
subProgramPid = -1;
} else if (subProgramPid == -1) {
diff --git a/runtime/runtime.cpp b/runtime/runtime.cpp
index 99836b4..85843bf 100644
--- a/runtime/runtime.cpp
+++ b/runtime/runtime.cpp
@@ -14,7 +14,7 @@ int main(int argc, char *argv[]) {
signal(SIGTERM, signal_handler);
fprintf(stdout, "PKE_RUNTIME ENTERING\n");
PkeArgs_Parse(argc, argv);
- Game_Main({}, argv[0]);
+ Game_Main({});
fprintf(stdout, "PKE_RUNTIME EXITING\n");
return 0;
}
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();