add standalone generator for easier generator testing

This commit is contained in:
gymnast86
2026-08-02 00:58:52 -07:00
parent a53b363905
commit 631cb99208
4 changed files with 45 additions and 17 deletions
+26 -12
View File
@@ -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)
@@ -0,0 +1,8 @@
#include "randomizer.hpp"
int main() {
randomizer::Randomizer rando{RANDO_SAVE_PATH};
rando.Generate();
return 0;
}
+5 -2
View File
@@ -14,8 +14,10 @@
#include <iostream>
#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;
+6 -3
View File
@@ -6,8 +6,10 @@
#include <unordered_map>
#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