Improve physical geometry, fluid solvers, audio, and profiling
This commit is contained in:
24
include/FluidSim/Desktop/PlaybackControl.hpp
Normal file
24
include/FluidSim/Desktop/PlaybackControl.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include <SFML/Window/Event.hpp>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
namespace fluidsim::port::desktop {
|
||||
class PlaybackControl {
|
||||
public:
|
||||
bool realtime() const {return realtime_;}
|
||||
double target_speed() const {return realtime_?1.0:manual_speed_;}
|
||||
bool handle_event(const sf::Event& event,bool shift=false) {
|
||||
if(const auto* key=event.getIf<sf::Event::KeyPressed>()) {
|
||||
if(key->code==sf::Keyboard::Key::Space){realtime_=!realtime_;return true;}
|
||||
if(!realtime_&&key->code==sf::Keyboard::Key::PageUp){adjust(1);return true;}
|
||||
if(!realtime_&&key->code==sf::Keyboard::Key::PageDown){adjust(-1);return true;}
|
||||
}
|
||||
if(const auto* wheel=event.getIf<sf::Event::MouseWheelScrolled>();wheel&&!realtime_&&shift) {adjust(wheel->delta);return true;}
|
||||
return false;
|
||||
}
|
||||
private:
|
||||
bool realtime_{true};
|
||||
double manual_speed_{1};
|
||||
void adjust(double steps){manual_speed_=std::clamp(manual_speed_*std::exp(steps*.12),.0001,1.0);}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user