Files
FluidSimCpp/tests/scenario_examples.cpp
max bf8621ad39 Load engines from TOML and improve scenario audio and carb tuning
Migrate 32 engine definitions into validated startup-loaded TOML files and separate configuration and snapshots from scenario assembly. Add camera-based stereo propagation from shared pipe geometry, preserve exhaust character, tune carburetor mixtures and idle, use ignition cuts for carb engines, and support returning to the scenario menu.

Validation: full Windows build and all 14 CTest checks passed.
2026-10-24 03:24:35 +02:00

42 lines
2.8 KiB
C++

#include "FluidSim/ScenarioCatalog.hpp"
#include "FluidSim/DesktopScenario.hpp"
#include <cmath>
#include <chrono>
#include <iostream>
#include <set>
#include <stdexcept>
using namespace fluidsim::port;
int main() {
std::set<std::string> ids;
for(const auto& example:scenario_examples()) {
if(!ids.insert(example.id).second)throw std::runtime_error("duplicate example id");
DesktopScenario scenario(example.kind,example.two,example.exhaust,example.junctions,example.engine,example.title);
scenario.set_audio_scene(OutdoorScene::Dry);
const auto started=std::chrono::steady_clock::now();
float peak_power=0;
for(int i=0;i<88200;++i) {
scenario.set_controls(i<44100?.45f:0.f,0,1);
const auto audio=scenario.process();
if(i%4410==0) peak_power=std::max(peak_power,scenario.snapshot().average_power);
if(!std::isfinite(audio.left)||!std::isfinite(audio.right))throw std::runtime_error(example.id+" nonfinite audio");
}
const auto snapshot=scenario.snapshot();
if(snapshot.pipe_positivity_repairs)throw std::runtime_error(example.id+" required positivity repairs");
if(example.id=="big-carb" && peak_power<10000)throw std::runtime_error("big carb V8 failed to produce power");
if(!std::isfinite(snapshot.rpm)||snapshot.rpm<=0)throw std::runtime_error(example.id+" invalid engine speed");
if(example.engine.cylinders && (snapshot.cylinder_count!=example.engine.cylinders || snapshot.layout!=example.engine.layout))throw std::runtime_error("custom cylinder layout lost");
const bool custom_v8=example.engine.american_headers();
if(custom_v8 && (!snapshot.v8_headers || snapshot.h_pipe!=example.junctions.h_pipe || snapshot.pipe_states[25].empty()))
throw std::runtime_error("custom V8 lost American junction headers/crossover");
if(example.engine.staged_headers() && example.engine.layout==EngineLayout::Inline) {
if(!snapshot.staged_headers || snapshot.dual_exhaust)
throw std::runtime_error("inline engine lost staged junction collectors");
}
if(example.engine.staged_headers() && example.engine.layout==EngineLayout::V && (!snapshot.dual_exhaust || !snapshot.staged_headers))
throw std::runtime_error("large V engine lost separate bank outlets");
if(snapshot.example_name!=example.title)throw std::runtime_error("example name lost");
if(example.engine.has_silenced_exhaust() && snapshot.silencers!=example.exhaust.enabled)throw std::runtime_error("example silencer selection lost");
std::cout<<example.id<<" passed, rpm="<<snapshot.rpm<<", wall/sim="<<std::chrono::duration<double>(std::chrono::steady_clock::now()-started).count()/2<<std::endl;
}
}