Improve physical geometry, fluid solvers, audio, and profiling

This commit is contained in:
max
2026-10-30 18:57:56 +01:00
parent bf8621ad39
commit eb2b6366c2
130 changed files with 14649 additions and 862 deletions

View File

@@ -1,10 +1,29 @@
#include "FluidSim/Desktop/DesktopUi.hpp"
#include "FluidSim/Scenario.hpp"
#include "FluidSim/ScenarioCatalog.hpp"
#include "FluidSim/DesktopScenario.hpp"
#include "FluidSim/Desktop/PlaybackControl.hpp"
#include "FluidSim/Desktop/PipePath.hpp"
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdexcept>
using namespace fluidsim::port::desktop;
void check(bool condition,const char* reason) {if(!condition)throw std::runtime_error(reason);}
int main() {
int main(int argc,char** argv) {
PlaybackControl playback;
sf::Event space=sf::Event::KeyPressed{.code=sf::Keyboard::Key::Space};
sf::Event wheel=sf::Event::MouseWheelScrolled{sf::Mouse::Wheel::Vertical,-1.f,{400,300}};
check(playback.realtime()&&!playback.handle_event(wheel,true),"realtime mode intercepted camera scrolling");
check(playback.handle_event(space)&&!playback.realtime(),"Space did not disable realtime");
check(!playback.handle_event(wheel)&&playback.target_speed()==1,"regular scroll changed manual speed");
check(playback.handle_event(wheel,true)&&playback.target_speed()<1,"Shift+scroll did not change manual speed");
const auto manual=playback.target_speed();playback.handle_event(space);check(playback.target_speed()==1,"Space did not restore realtime");
playback.handle_event(space);check(playback.target_speed()==manual,"manual speed was lost");
PipePath corner({{0,{0,0,0}},{1,{1,0,0}},{2,{1,1,0}}});
check(corner.position(.5f)==fluidsim::port::Vec3{.5f,0,0}&&corner.position(1.5f)==fluidsim::port::Vec3{1,.5f,0},"sharp pipe bend was rounded into a spline");
const auto miter=corner.miter_offset(1,{.70710678f,-.70710678f,0});
check(std::abs(miter.x-1)<1e-5f&&std::abs(miter.y+1)<1e-5f,"90 degree pipe joint pinches the cross-section");
for(auto size : {sf::Vector2u{933,1010},sf::Vector2u{1920,1080},sf::Vector2u{1040,800},sf::Vector2u{800,700}}) {
const auto l=WorkspaceLayout::calculate(size);
for(auto r : {l.sidebar,l.viewport,l.chart,l.inspector,l.pedal}) {
@@ -46,5 +65,31 @@ int main() {
check(std::abs(std::cos(y)*listener.right.x+std::sin(y)*listener.right.z-1)<1e-6f,
"audio ears must rotate with the camera right axis");
}
std::cout<<"Desktop layout, spring pedal, keyboard travel and orbit camera checks passed\n";
ui.configure_resolution(20);
const auto buttons=DesktopUi::resolution_buttons(size);
const auto plus=buttons[1].position+sf::Vector2f{10,8};
ui.handle_event(sf::Event::MouseButtonPressed{sf::Mouse::Button::Left,{int(plus.x),int(plus.y)}},size);
check(ui.take_resolution_request()==25,"resolution plus button failed");
ui.resolution_started();
ui.handle_event(sf::Event::MouseButtonPressed{sf::Mouse::Button::Left,{int(plus.x),int(plus.y)}},size);
check(!ui.take_resolution_request(),"resolution changed while rebuilding");
ui.resolution_finished(25,"Applied");
if(argc==3 && std::string(argv[1])=="--preview") {
const std::filesystem::path directory=argv[2];std::filesystem::create_directories(directory);
sf::ContextSettings context;context.depthBits=24;context.majorVersion=2;context.minorVersion=1;
sf::RenderWindow window(sf::VideoMode({1440,900}),"Geometry preview",sf::Style::Default,sf::State::Windowed,context);
window.setVisible(false);sf::Font font("C:/Windows/Fonts/consola.ttf");
const auto& catalog=fluidsim::port::scenario_examples();
sf::RenderTexture contact({1280,static_cast<unsigned>((catalog.size()+3)/4)*200});contact.clear(sf::Color::Black);
unsigned index=0;
for(const auto& example:catalog) {
fluidsim::port::DesktopScenario simulation(example);for(int i=0;i<512;++i)simulation.process();
const auto state=simulation.snapshot();DesktopUi preview;preview.configure_resolution(state.cells_per_meter);preview.draw(window,&font,state,{});
sf::Texture texture(window.getSize());texture.update(window);
check(texture.copyToImage().saveToFile(directory/(example.id+".png")),"could not save geometry preview");
sf::Sprite thumbnail(texture);thumbnail.setScale({320.f/window.getSize().x,200.f/window.getSize().y});thumbnail.setPosition({float(index%4)*320,float(index/4)*200});contact.draw(thumbnail);++index;
}
contact.display();check(contact.getTexture().copyToImage().saveToFile(directory/"catalog.png"),"could not save catalog preview");
}
std::cout<<"Desktop controls, resolution stepper, and camera checks passed\n";
}