From 521b5da83485a956811fc510cba9f139acad8b26 Mon Sep 17 00:00:00 2001 From: "Emil A. Overbeck" Date: Sun, 19 Jul 2026 04:19:48 +0200 Subject: New maps and map selector --- tools/sim_check.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 tools/sim_check.cpp (limited to 'tools/sim_check.cpp') diff --git a/tools/sim_check.cpp b/tools/sim_check.cpp new file mode 100644 index 0000000..449a7c3 --- /dev/null +++ b/tools/sim_check.cpp @@ -0,0 +1,80 @@ +// Headless map soak test. +// +// The GUI needs a display, but the solver does not: build_graph and the Lua +// loaders have no SDL dependency. This loads every map, settles it under the +// same fixed-step tick order the game uses, and reports whether the forts stand. +// Use it to catch "the fort collapses on load" without opening the game. +// +// ./builddir/sim_check [seconds] +// +// Exit status is non-zero if any map lost struts, so it can gate a commit. + +#include "engine/script.hpp" +#include "game/build_graph.hpp" +#include "game/data.hpp" + +#include +#include +#include +#include +#include + +int main(int argc, char** argv) { + const float FIXED_DT = 1.0f / 60.0f; + const float seconds = (argc > 1) ? std::atof(argv[1]) : 5.0f; + const int ticks = (int)(seconds / FIXED_DT); + + ScriptEngine script; // ctor brings the Lua state up + + BuildGraph graph; + graph.materials = load_materials(script, "data"); + if (graph.materials.empty()) { fprintf(stderr, "no materials\n"); return 2; } + std::vector maps = load_maps(script, "data"); + if (maps.empty()) { fprintf(stderr, "no maps\n"); return 2; } + + int failures = 0; + for (const auto& m : maps) { + build_map(m, graph); + // Beams the graph refused (duplicate node pair after snapping, or a + // degenerate endpoint) silently weaken a fort, so surface them. + if ((int)graph.edges.size() != (int)m.beams.size()) + printf(" %s: %zu beams declared but %zu welded (%zu rejected)\n", + m.name.c_str(), m.beams.size(), graph.edges.size(), + m.beams.size() - graph.edges.size()); + const int edges0 = (int)graph.edges.size(); + const int nodes0 = (int)graph.nodes.size(); + std::vector y0; + for (const auto& n : graph.nodes) y0.push_back(n.y); + + int snapped = 0, killed = 0, first_break = -1; + for (int t = 0; t < ticks; t++) { + graph.step(FIXED_DT); + int s = graph.check_strain(); + graph.update_timers(FIXED_DT); + graph.update_fire(FIXED_DT); + int k = graph.kill_grounded(); + if (s > 0 && first_break < 0) first_break = t; + snapped += s; + killed += k; + } + + // Worst downward drift of any surviving node (sag). + float sag = 0.0f; + for (size_t i = 0; i < graph.nodes.size() && i < y0.size(); i++) + sag = std::max(sag, y0[i] - graph.nodes[i].y); + + const bool ok = (snapped == 0 && killed == 0); + if (!ok) failures++; + printf("%-16s %s struts %d -> %d, nodes %d -> %d, snapped %d, killed %d", + m.name.c_str(), ok ? "STANDS " : "COLLAPSE", + edges0, (int)graph.edges.size(), + nodes0, (int)graph.nodes.size(), snapped, killed); + if (first_break >= 0) + printf(", first break at t=%.2fs", first_break * FIXED_DT); + printf(", max sag %.3f\n", sag); + } + + printf("\n%d/%zu maps stand after %.1fs\n", (int)maps.size() - failures, + maps.size(), seconds); + return failures == 0 ? 0 : 1; +} -- cgit v1.3