From a1f777f632a1ef790d7f0be3f09946e3c192fa42 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Wed, 9 Mar 2022 22:37:37 -0500 Subject: [PATCH] Add MCPI_DEBUG & Improve Documentation --- CMakeLists.txt | 1 - docs/COMMAND_LINE.md | 33 ++++++++++++++++++++++++++----- launcher/src/bootstrap.c | 5 ++--- libreborn/include/libreborn/log.h | 1 + libreborn/src/patch.c | 10 ++-------- mods/src/feature/feature.c | 8 +++++--- 6 files changed, 38 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c9a5fee1b..64f7a4f59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,6 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release") add_compile_options(-O3) else() add_compile_options(-g) - add_definitions(-DDEBUG) endif() # Start Project diff --git a/docs/COMMAND_LINE.md b/docs/COMMAND_LINE.md index 9e078f9c5..8e8498e89 100644 --- a/docs/COMMAND_LINE.md +++ b/docs/COMMAND_LINE.md @@ -1,16 +1,39 @@ -# Command Line Arguments +# Command Line Usage -## ``--print-available-feature-flags`` (Client Mode Only) -If you run MCPI-Reborn with ``--print-available-feature-flags``, it will print the available feature flags and then immediately exit. The feature flags are printed in the following format: +## Command Line Arguments + +### ``--print-available-feature-flags`` (Client Mode Only) +If you run MCPI-Reborn with ``--print-available-feature-flags``, it will print the available feature flags and then immediately exit. + +The feature flags are printed in the following format: ``` TRUE This Flag Is On By Default FALSE This Flag Is Off By Default ``` -## ``--only-generate`` (Server Mode Only) +### ``--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. -## ``--benchmark`` (Client Mode Only) +### ``--benchmark`` (Client Mode Only) If you run MCPI-Reborn with ``--benchmark``, it will enter a simple benchmark mode. This means automatically loading a newly generated world, then rotating the camera for a period of time. When it has finished, it will then exit and print the average FPS while the world was loaded. In this mode, all user input is blocked. However you can still modify rendering settings by changing feature flags. 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. + +### 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. + +### ``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`` +This is the render distance. The possible values are: ``Far``, ``Normal``, ``Short``, and ``Tiny``. + +### ``MCPI_USERNAME`` +This is the username. diff --git a/launcher/src/bootstrap.c b/launcher/src/bootstrap.c index c815f6818..257eec0bc 100644 --- a/launcher/src/bootstrap.c +++ b/launcher/src/bootstrap.c @@ -38,10 +38,9 @@ void set_and_print_env(const char *name, char *value) { trim(&value); } -#ifdef DEBUG // Print New Value - INFO("Set %s = %s", name, value); -#endif + DEBUG("Set %s = %s", name, value); + // Set The Value setenv(name, value, 1); } diff --git a/libreborn/include/libreborn/log.h b/libreborn/include/libreborn/log.h index 9333b21f3..37161c2c1 100644 --- a/libreborn/include/libreborn/log.h +++ b/libreborn/include/libreborn/log.h @@ -6,5 +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 ERR(format, ...) { fprintf(stderr, "[ERR]: (%s:%i): " format "\n", __FILE__, __LINE__, __VA_ARGS__); exit(EXIT_FAILURE); } #define IMPOSSIBLE() ERR("%s", "This Should Never Be Called") diff --git a/libreborn/src/patch.c b/libreborn/src/patch.c index 80efe15fa..09fbc9c87 100644 --- a/libreborn/src/patch.c +++ b/libreborn/src/patch.c @@ -79,9 +79,7 @@ static void update_code_block(void *target) { if (code_block == MAP_FAILED) { ERR("Unable To Allocate Code Block: %s", strerror(errno)); } -#ifdef DEBUG - INFO("Code Block Allocated At: 0x%08x", (uint32_t) code_block); -#endif + DEBUG("Code Block Allocated At: 0x%08x", (uint32_t) code_block); } if (code_block_remaining < CODE_SIZE) { ERR("%s", "Maximum Amount Of overwrite_calls() Uses Reached"); @@ -138,11 +136,7 @@ void _overwrite(const char *file, int line, void *start, void *target) { } // Print Patch Debug Data -#ifdef DEBUG -#define PATCH_PRINTF(file, line, start, str) if (file != NULL) fprintf(stderr, "[PATCH]: (%s:%i) Patching (0x%08x) - "str": 0x%02x 0x%02x 0x%02x 0x%02x\n", file, line, (uint32_t) start, data[0], data[1], data[2], data[3]); -#else -#define PATCH_PRINTF(file, line, start, str) { (void) file; (void) line; (void) start; (void) str; } // Mark As Used -#endif +#define PATCH_PRINTF(file, line, start, str) if (file != NULL) DEBUG("(%s:%i): Patching (0x%08x) - " str ": 0x%02x 0x%02x 0x%02x 0x%02x", file, line, (uint32_t) start, data[0], data[1], data[2], data[3]); // Patch Instruction void _patch(const char *file, int line, void *start, unsigned char patch[4]) { diff --git a/mods/src/feature/feature.c b/mods/src/feature/feature.c index fda15dbea..782fa8240 100644 --- a/mods/src/feature/feature.c +++ b/mods/src/feature/feature.c @@ -29,8 +29,10 @@ int feature_has(const char *name, int server_default) { tok = strtok(NULL, "|"); } free(features); -#ifdef DEBUG - INFO("Feature: %s: %s", name, ret ? "Enabled" : "Disabled"); -#endif + + // Log + DEBUG("Feature: %s: %s", name, ret ? "Enabled" : "Disabled"); + + // Return return ret; }