From 3c1bce876c71161c4be1cdcbcd9dce88a1cd8af3 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 8 Jul 2022 13:57:48 -0400 Subject: [PATCH] Run Benchmark During CI Test --- docs/COMMAND_LINE.md | 13 +++--- launcher/src/client/launcher.cpp | 60 ++++++++++++++++++++++---- libreborn/include/libreborn/log.h | 2 +- media-layer/core/dependencies/glfw/src | 2 +- scripts/test.sh | 11 +++++ 5 files changed, 72 insertions(+), 16 deletions(-) diff --git a/docs/COMMAND_LINE.md b/docs/COMMAND_LINE.md index cc39efd..b9eee1b 100644 --- a/docs/COMMAND_LINE.md +++ b/docs/COMMAND_LINE.md @@ -14,6 +14,9 @@ TRUE This Flag Is On By Default FALSE This Flag Is Off By Default ``` +### ``--default`` (Client Mode Only) +If you run MCPI-Reborn with ``--default``, it will skip the startup configuration dialogs and just use the default values. + ### ``--only-generate`` (Server Mode Only) If you run MCPI-Reborn with ``--only-generate``, it will immediately exit once world generation has completed. This is mainly used for automatically testing MCPI-Reborn. @@ -25,18 +28,18 @@ The world used will always be re-created on start and uses a hard-coded seed. ## Environmental Variables ### ``MCPI_DEBUG`` -This enables debug logging if you set it to any non-zero-length value. +This enables debug logging if it is set. ### Client Mode Only -If a value isn't set for any of the following variables, a GUI will open that allows you to select one. +If any of the following variables aren't set, one configuration dialog will open on startup for each unset variable. -### ``MCPI_FEATURE_FLAGS`` +#### ``MCPI_FEATURE_FLAGS`` This corresponds to ``--print-available-feature-flags``. This is just a list of all enabled feature flags separated by ``|``. For instance, the string ``Feature A|Feature B`` would enable both ``Feature A`` and ``Feature B`` and *disable every other available feature flag*. -### ``MCPI_RENDER_DISTANCE`` +#### ``MCPI_RENDER_DISTANCE`` This is the render distance. The possible values are: ``Far``, ``Normal``, ``Short``, and ``Tiny``. -### ``MCPI_USERNAME`` +#### ``MCPI_USERNAME`` This is the username. diff --git a/launcher/src/client/launcher.cpp b/launcher/src/client/launcher.cpp index 397aa49..f3c7036 100644 --- a/launcher/src/client/launcher.cpp +++ b/launcher/src/client/launcher.cpp @@ -126,6 +126,20 @@ static void run_zenity_and_set_env(const char *env_name, std::vector callback) { + if (getenv(env_name) == NULL) { + char *value = strdup(callback().c_str()); + ALLOC_CHECK(value); + set_and_print_env(env_name, value); + free(value); + } +} + +// Defaults +#define DEFAULT_USERNAME "StevePi" +#define DEFAULT_RENDER_DISTANCE "Short" + // Launch #define LIST_DIALOG_SIZE "400" int main(int argc, char *argv[]) { @@ -149,6 +163,37 @@ int main(int argc, char *argv[]) { } } + // --default + for (int i = 1; i < argc; i++) { + if (strcmp(argv[i], "--default") == 0) { + // Use Default Feature Flags + set_env_if_unset("MCPI_FEATURE_FLAGS", []() { + std::string feature_flags = ""; + load_available_feature_flags([&feature_flags](std::string flag) { + bool default_value; + // Strip Default Value + std::string stripped_flag = strip_feature_flag_default(flag, &default_value); + // Specify Default Value + if (default_value) { + // Enabled By Default + feature_flags += stripped_flag + '|'; + } + }); + if (feature_flags.length() > 0 && feature_flags[feature_flags.length() - 1] == '|') { + feature_flags.pop_back(); + } + return feature_flags; + }); + set_env_if_unset("MCPI_RENDER_DISTANCE", []() { + return DEFAULT_RENDER_DISTANCE; + }); + set_env_if_unset("MCPI_USERNAME", []() { + return DEFAULT_USERNAME; + }); + break; + } + } + // Create ~/.minecraft-pi If Needed // Minecraft Folder { @@ -215,14 +260,11 @@ int main(int argc, char *argv[]) { command.push_back("Selected"); command.push_back("--column"); command.push_back("Name"); - command.push_back("FALSE"); - command.push_back("Far"); - command.push_back("FALSE"); - command.push_back("Normal"); - command.push_back("TRUE"); - command.push_back("Short"); - command.push_back("FALSE"); - command.push_back("Tiny"); + std::string render_distances[] = {"Far", "Normal", "Short", "Tiny"}; + for (std::string &render_distance : render_distances) { + command.push_back(render_distance.compare(DEFAULT_RENDER_DISTANCE) == 0 ? "TRUE" : "FALSE"); + command.push_back(render_distance); + } // Run run_zenity_and_set_env("MCPI_RENDER_DISTANCE", command); } @@ -233,7 +275,7 @@ int main(int argc, char *argv[]) { command.push_back("--text"); command.push_back("Enter Minecraft Username:"); command.push_back("--entry-text"); - command.push_back("StevePi"); + command.push_back(DEFAULT_USERNAME); // Run run_zenity_and_set_env("MCPI_USERNAME", command); } diff --git a/libreborn/include/libreborn/log.h b/libreborn/include/libreborn/log.h index b850f3e..9a71525 100644 --- a/libreborn/include/libreborn/log.h +++ b/libreborn/include/libreborn/log.h @@ -6,6 +6,6 @@ // Logging #define INFO(format, ...) { fprintf(stderr, "[INFO]: " format "\n", ##__VA_ARGS__); } #define WARN(format, ...) { fprintf(stderr, "[WARN]: " format "\n", ##__VA_ARGS__); } -#define DEBUG(format, ...) { const char *debug = getenv("MCPI_DEBUG"); if (debug != NULL && strlen(debug) > 0) { fprintf(stderr, "[DEBUG]: " format "\n", ##__VA_ARGS__); } } +#define DEBUG(format, ...) { const char *debug = getenv("MCPI_DEBUG"); if (debug != NULL) { fprintf(stderr, "[DEBUG]: " format "\n", ##__VA_ARGS__); } } #define ERR(format, ...) { fprintf(stderr, "[ERR]: (%s:%i): " format "\n", __FILE__, __LINE__, ##__VA_ARGS__); exit(EXIT_FAILURE); } #define IMPOSSIBLE() ERR("This Should Never Be Called") diff --git a/media-layer/core/dependencies/glfw/src b/media-layer/core/dependencies/glfw/src index da6713c..84e165e 160000 --- a/media-layer/core/dependencies/glfw/src +++ b/media-layer/core/dependencies/glfw/src @@ -1 +1 @@ -Subproject commit da6713cd096a40a4512f468b34c189017e73f987 +Subproject commit 84e165ef64ce117c5f1fa99b607f5bd143973e65 diff --git a/scripts/test.sh b/scripts/test.sh index 904afaf..b269a55 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -17,3 +17,14 @@ mkdir -p build/test # Run Test cd build/test minecraft-pi-reborn-server --only-generate +cd ../../ + +# Build Benchmark +./scripts/setup.sh client "${ARCH}" -DMCPI_HEADLESS_MODE=ON +./scripts/build.sh client "${ARCH}" + +# Add minecraft-pi-reborn-server To PATH +export PATH="$(pwd)/out/client-$(dpkg-architecture -qDEB_BUILD_ARCH)/usr/bin:${PATH}" + +# Run Benchmark +minecraft-pi-reborn-client --default --benchmark