diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2023-12-18 20:35:37 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2023-12-23 11:41:03 -0500 |
| commit | c7c678651a30db30e449e965e6c82ad0dcb871e6 (patch) | |
| tree | 09f012460a7f77bb92d82d642ec0e9d85ef347e2 /src | |
| parent | 4c4304429a4c06167aa21de246aa21e7b3ceb725 (diff) | |
checkpoint - arg-handler
Diffstat (limited to 'src')
| -rw-r--r-- | src/arg-handler.cpp | 42 | ||||
| -rw-r--r-- | src/arg-handler.hpp | 6 | ||||
| -rw-r--r-- | src/game-settings.hpp | 1 | ||||
| -rw-r--r-- | src/game.cpp | 3 |
4 files changed, 52 insertions, 0 deletions
diff --git a/src/arg-handler.cpp b/src/arg-handler.cpp new file mode 100644 index 0000000..1b40039 --- /dev/null +++ b/src/arg-handler.cpp @@ -0,0 +1,42 @@ + +#include "arg-handler.hpp" +#include "game-settings.hpp" + +#include <cstdio> +#include <getopt.h> + +void PkeArgs_Parse(int argc, char *argv[]) { + while (1) { + + static struct option long_options[] = { + {"plugin", required_argument, 0, 'p'}, + {0, 0, 0, 0}, + }; + + int optionIndex = 0; + int c = getopt_long(argc, argv, "p:", long_options, &optionIndex); + if (c == -1) { + break; + } + + switch (c) { + case 0: + break; + case 'p': + pkeSettings.pluginPath = optarg; + break; + default: + fprintf(stderr, "Unused parameter: %c\n", c); + } + } + +#ifndef NDEBUG + if (optind < argc) { + fprintf(stdout, "non-option args:\n"); + while (optind < argc) { + fprintf(stdout, "%s ", argv[optind++]); + } + fprintf(stdout, "\n"); + } +#endif +} diff --git a/src/arg-handler.hpp b/src/arg-handler.hpp new file mode 100644 index 0000000..5471f01 --- /dev/null +++ b/src/arg-handler.hpp @@ -0,0 +1,6 @@ +#ifndef PKE_ARG_HANDLER_HPP +#define PKE_ARG_HANDLER_HPP + +void PkeArgs_Parse(int argc, char *argv[]); + +#endif /* PKE_ARG_HANDLER_HPP */ diff --git a/src/game-settings.hpp b/src/game-settings.hpp index 7e1d31d..7bc6765 100644 --- a/src/game-settings.hpp +++ b/src/game-settings.hpp @@ -8,6 +8,7 @@ struct GameSettings { const char *executablePath; + const char *pluginPath = nullptr; bool isGameRunning = true; bool isGamePaused = false; bool isShowingEditor = true; diff --git a/src/game.cpp b/src/game.cpp index 4dde008..7dfca42 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -481,6 +481,9 @@ void Game_Main(PKEWindowProperties windowProps, const char *executablePath) { CreateWindow(windowProps); PkeInput_Init(); EntityType_Init(); + if (pkeSettings.pluginPath) { + Pke_LoadPlugin(pkeSettings.pluginPath); + } if (pkePlugin.OnInit) { pkePlugin.OnInit(); } |
