From c7c678651a30db30e449e965e6c82ad0dcb871e6 Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Mon, 18 Dec 2023 20:35:37 -0500 Subject: checkpoint - arg-handler --- src/arg-handler.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ src/arg-handler.hpp | 6 ++++++ src/game-settings.hpp | 1 + src/game.cpp | 3 +++ 4 files changed, 52 insertions(+) create mode 100644 src/arg-handler.cpp create mode 100644 src/arg-handler.hpp (limited to 'src') 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 +#include + +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(); } -- cgit v1.2.3