From 631cb99208617813d978f6416c7e0a0b475158e1 Mon Sep 17 00:00:00 2001 From: gymnast86 Date: Sun, 2 Aug 2026 00:58:52 -0700 Subject: [PATCH] add standalone generator for easier generator testing --- mods/randomizer/CMakeLists.txt | 38 +++++++++++++------- mods/randomizer/generator/generator_only.cpp | 8 +++++ mods/randomizer/generator/randomizer.cpp | 7 ++-- mods/randomizer/generator/utility/text.cpp | 9 +++-- 4 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 mods/randomizer/generator/generator_only.cpp diff --git a/mods/randomizer/CMakeLists.txt b/mods/randomizer/CMakeLists.txt index ffaf9a1bb2..aeb5bb5c96 100644 --- a/mods/randomizer/CMakeLists.txt +++ b/mods/randomizer/CMakeLists.txt @@ -87,6 +87,23 @@ set(RANDOMIZER_SOURCES src/session.cpp ) +# Embed the generator's YAML data into the mod library. Paths are relative to this +# directory and must match the RANDO_DATA_PATH-based b::embed<> identifiers in code. +file(GLOB_RECURSE RANDOMIZER_DATA RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}/generator/data/*") + +# Create an OBJECT library to hold all battery-embed generated files so we can add it +# to both the mod and the standalone generator +add_library(randomizer_embeds OBJECT) + +b_embed(randomizer_embeds "res/shadow_crystal.bti") +foreach (RANDOMIZER_FILE IN LISTS RANDOMIZER_DATA) + if (RANDOMIZER_FILE MATCHES "^generator/data/tests") + continue() + endif () + b_embed(randomizer_embeds "${RANDOMIZER_FILE}") +endforeach () + add_mod(randomizer FEATURES game SOURCES src/mod.cpp ${RANDOMIZER_GENERATOR_SOURCES} ${RANDOMIZER_SOURCES} @@ -94,7 +111,7 @@ add_mod(randomizer RES_DIR res ) -target_link_libraries(randomizer PRIVATE yaml-cpp::yaml-cpp base64pp fmt::fmt) +target_link_libraries(randomizer PRIVATE yaml-cpp::yaml-cpp base64pp fmt::fmt randomizer_embeds) string(LENGTH "${CMAKE_CURRENT_SOURCE_DIR}/" RANDOMIZER_SOURCE_PATH_SIZE) target_compile_definitions(randomizer PRIVATE @@ -102,14 +119,11 @@ target_compile_definitions(randomizer PRIVATE SOURCE_PATH_SIZE=${RANDOMIZER_SOURCE_PATH_SIZE} ) -# Embed the generator's YAML data into the mod library. Paths are relative to this -# directory and must match the RANDO_DATA_PATH-based b::embed<> identifiers in code. -file(GLOB_RECURSE RANDOMIZER_DATA RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" - "${CMAKE_CURRENT_SOURCE_DIR}/generator/data/*") -b_embed(randomizer "res/shadow_crystal.bti") -foreach (RANDOMIZER_FILE IN LISTS RANDOMIZER_DATA) - if (RANDOMIZER_FILE MATCHES "^generator/data/tests") - continue() - endif () - b_embed(randomizer "${RANDOMIZER_FILE}") -endforeach () +# standalone randomizer generator for testing +add_executable(randomizer_generator ${CMAKE_CURRENT_SOURCE_DIR}/generator/generator_only.cpp ${RANDOMIZER_GENERATOR_SOURCES}) +target_link_libraries(randomizer_generator PRIVATE yaml-cpp::yaml-cpp base64pp fmt::fmt randomizer_embeds) +target_compile_definitions(randomizer_generator PRIVATE + RANDO_DATA_PATH="generator/data/" + SOURCE_PATH_SIZE=${RANDOMIZER_SOURCE_PATH_SIZE} + RANDO_SAVE_PATH="${CMAKE_BINARY_DIR}/randomizer/" + RANDOMIZER_ONLY) diff --git a/mods/randomizer/generator/generator_only.cpp b/mods/randomizer/generator/generator_only.cpp new file mode 100644 index 0000000000..12f5ae52bb --- /dev/null +++ b/mods/randomizer/generator/generator_only.cpp @@ -0,0 +1,8 @@ +#include "randomizer.hpp" + +int main() { + randomizer::Randomizer rando{RANDO_SAVE_PATH}; + rando.Generate(); + + return 0; +} \ No newline at end of file diff --git a/mods/randomizer/generator/randomizer.cpp b/mods/randomizer/generator/randomizer.cpp index 7f8cec0adf..9935213b46 100644 --- a/mods/randomizer/generator/randomizer.cpp +++ b/mods/randomizer/generator/randomizer.cpp @@ -14,8 +14,10 @@ #include +#ifndef RANDOMIZER_ONLY #include "../src/paths.hpp" #include "../src/randomizer_context.hpp" +#endif namespace randomizer { @@ -37,13 +39,14 @@ namespace randomizer catch(const std::exception& e) { std::cout << "============================================================" << std::endl; - std::cout << "The following exception occured: " << e.what() << std::endl; + std::cout << "The following exception occurred: " << e.what() << std::endl; return e.what(); } return std::nullopt; } +#ifndef RANDOMIZER_ONLY void Randomizer::GenerateTrackerWorld() { auto contextHash = randomizer_GetContext().mHash; @@ -78,7 +81,7 @@ namespace randomizer FlattenSearch search = FlattenSearch(trackerWorld); search.doSearch(); } - +#endif void Randomizer::GenerateWorlds() { utility::time::ScopedTimer<"Seed generation took ", std::chrono::milliseconds> timer; diff --git a/mods/randomizer/generator/utility/text.cpp b/mods/randomizer/generator/utility/text.cpp index 70f830697a..afe3ea32a7 100644 --- a/mods/randomizer/generator/utility/text.cpp +++ b/mods/randomizer/generator/utility/text.cpp @@ -6,8 +6,10 @@ #include +#ifndef RANDOMIZER_ONLY #include "JSystem/JUtility/JUTFont.h" #include "m_Do/m_Do_ext.h" +#endif namespace randomizer { @@ -399,14 +401,15 @@ namespace randomizer { continue; } - JUTFont::TWidth width{}; + #ifndef RANDOMIZER_ONLY + JUTFont::TWidth width{}; gameFont->getWidthEntry(str[i], &width); + curLineWidth += /*width.field_0x0 + */width.field_0x1; #else // Assume worst case with no iso access - width.field_0x1 = 21; + curLineWidth += 21; #endif - curLineWidth += /*width.field_0x0 + */width.field_0x1; // If we exceed the maximum line width, replace the // previous space with a newline and start counting // from the newline again