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.
This commit is contained in:
@@ -1,24 +1,28 @@
|
||||
#pragma once
|
||||
#include "FluidSim/Scenario.hpp"
|
||||
#include "FluidSim/ScenarioCatalog.hpp"
|
||||
#include "FluidSim/TwoStrokeScenario.hpp"
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace fluidsim::port {
|
||||
// Shared desktop controls/snapshot contract. Two-stroke access is serialized;
|
||||
// the twin already protects its own simulation state.
|
||||
// Shared desktop controls and snapshots. Each simulation owns its state lock.
|
||||
class DesktopScenario {
|
||||
public:
|
||||
explicit DesktopScenario(ScenarioKind kind, TwoStrokeConfig config = {}, ExhaustConfig exhaust = {}, V8ExhaustConfig v8 = {}, EngineConfig engine = {}, std::string name = {}) : name_(std::move(name)) {
|
||||
explicit DesktopScenario(const ScenarioExample& e)
|
||||
: DesktopScenario(e.kind,e.two,e.exhaust,e.junctions,e.engine,e.title) {}
|
||||
explicit DesktopScenario(ScenarioKind kind, TwoStrokeConfig config = {}, ExhaustConfig exhaust = {}, JunctionConfig junctions = {}, EngineConfig engine = {}, std::string name = {}) : name_(std::move(name)) {
|
||||
if (kind == ScenarioKind::TwoStroke)
|
||||
two_ = std::make_unique<TwoStrokeScenario>(44100, config);
|
||||
else
|
||||
twin_ = std::make_unique<FourStrokeScenario>(44100, kind == ScenarioKind::SaabB205 ?
|
||||
FourStrokePreset::SaabB205 : kind == ScenarioKind::AmericanV8 ? FourStrokePreset::AmericanV8 : FourStrokePreset::Twin, exhaust, v8,engine);
|
||||
else {
|
||||
if(!engine.cylinders)engine=preset_engine_definition(kind==ScenarioKind::SaabB205?
|
||||
FourStrokePreset::SaabB205:kind==ScenarioKind::AmericanV8?FourStrokePreset::AmericanV8:FourStrokePreset::Twin).engine;
|
||||
four_ = std::make_unique<FourStrokeScenario>(44100,std::move(engine),exhaust,junctions);
|
||||
}
|
||||
}
|
||||
AudioFrame process() {
|
||||
if (twin_)
|
||||
return twin_->process();
|
||||
if (four_)
|
||||
return four_->process();
|
||||
const std::lock_guard lock(mutex_);
|
||||
return two_->process();
|
||||
}
|
||||
@@ -33,8 +37,11 @@ public:
|
||||
void set_audio_scene(OutdoorScene scene) {
|
||||
visit([&](auto& scenario) { scenario.set_audio_scene(scene); });
|
||||
}
|
||||
void set_listener(AudioListener listener) {
|
||||
visit([&](auto& scenario) { scenario.set_listener(listener); });
|
||||
}
|
||||
ScenarioSnapshot snapshot() const {
|
||||
if (twin_) { auto s=twin_->snapshot();s.example_name=name_;return s; }
|
||||
if (four_) { auto s=four_->snapshot();s.example_name=name_;return s; }
|
||||
const std::lock_guard lock(mutex_);
|
||||
const auto source = two_->snapshot();
|
||||
ScenarioSnapshot s;
|
||||
@@ -65,6 +72,7 @@ public:
|
||||
s.valve1_exhaust_area = source.exhaust_area;
|
||||
s.reed_open = source.reed_open;
|
||||
s.fuel_cut = source.fuel_cut;
|
||||
s.ignition_cut = source.ignition_cut;
|
||||
s.idle_control = two_->ecu.idle_active();
|
||||
s.rev_limit1 = two_->ecu.rev_limited();
|
||||
s.audio_scene = source.audio_scene;
|
||||
@@ -77,11 +85,11 @@ public:
|
||||
private:
|
||||
template<class Function> void visit(Function&& function) {
|
||||
const std::lock_guard lock(mutex_);
|
||||
if (twin_) function(*twin_);
|
||||
if (four_) function(*four_);
|
||||
else function(*two_);
|
||||
}
|
||||
std::string name_;
|
||||
std::unique_ptr<FourStrokeTwinScenario> twin_;
|
||||
std::unique_ptr<FourStrokeScenario> four_;
|
||||
std::unique_ptr<TwoStrokeScenario> two_;
|
||||
mutable std::mutex mutex_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user