aboutsummaryrefslogtreecommitdiff
path: root/src/main.cc
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-04-17 21:18:11 +0200
committerAdrian Kummerlaender2019-04-17 21:18:11 +0200
commit9a48932e393b8bb714e5b7748f6498f4e2e2d233 (patch)
tree60fae3c9cdf74ea68a1808b2db3684698c2a7650 /src/main.cc
parent303025eda4e10a0d962231c7b3349f8b9cb8cfa1 (diff)
downloadcompustream-9a48932e393b8bb714e5b7748f6498f4e2e2d233.tar
compustream-9a48932e393b8bb714e5b7748f6498f4e2e2d233.tar.gz
compustream-9a48932e393b8bb714e5b7748f6498f4e2e2d233.tar.bz2
compustream-9a48932e393b8bb714e5b7748f6498f4e2e2d233.tar.lz
compustream-9a48932e393b8bb714e5b7748f6498f4e2e2d233.tar.xz
compustream-9a48932e393b8bb714e5b7748f6498f4e2e2d233.tar.zst
compustream-9a48932e393b8bb714e5b7748f6498f4e2e2d233.zip
Pause lattice updates independently of UI
This way walls may be drawn without disrupting the active fluid flow even more than necessary.
Diffstat (limited to 'src/main.cc')
-rw-r--r--src/main.cc82
1 files changed, 40 insertions, 42 deletions
diff --git a/src/main.cc b/src/main.cc
index 5c27306..92f6f2a 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -150,65 +150,63 @@ int render() {
MVP = getMVP(world_width, world_height);
}
- if ( update_lattice ) {
+ if ( update_lattice && timer::millisecondsSince(last_lattice_update) >= 1000/maxLUPS ) {
if ( timer::secondsSince(last_lups_update) >= 1.0 ) {
std::cout << "\rComputing about " << statLUPS << " lattice updates per second." << std::flush;
statLUPS = 0;
last_lups_update = timer::now();
}
- if ( timer::millisecondsSince(last_lattice_update) >= 1000/maxLUPS ) {
- statLUPS += 1;
-
- if ( tick ) {
- interact_shader->workOn(tick_buffers);
- collide_shader->workOn(tick_buffers);
- tick = false;
- } else {
- interact_shader->workOn(tock_buffers);
- collide_shader->workOn(tock_buffers);
- tick = true;
- }
+ statLUPS += 1;
+
+ if ( tick ) {
+ interact_shader->workOn(tick_buffers);
+ collide_shader->workOn(tick_buffers);
+ tick = false;
+ } else {
+ interact_shader->workOn(tock_buffers);
+ collide_shader->workOn(tock_buffers);
+ tick = true;
+ }
- /// Update mouse projection
- {
- const auto m = window.getMouse();
+ /// Perform collide & stream steps
+ {
+ auto guard = collide_shader->use();
- prevMouseState = currMouseState;
- prevLatticeMouseX = currLatticeMouseX;
- prevLatticeMouseY = currLatticeMouseY;
+ collide_shader->setUniform("fluidQuality", show_fluid_quality);
+ collide_shader->setUniform("iT", iT);
+ iT += 1;
- currMouseState = std::get<0>(m);
- currLatticeMouseX = float(std::get<1>(m)) / window.getWidth() * world_width + nX/2;
- currLatticeMouseY = float(std::get<2>(m)) / window.getHeight() * world_height + nY/2;
- }
+ collide_shader->dispatch(nX, nY);
+ }
- /// Handle mouse-based interaction
- if ( currMouseState != 0 || prevMouseState != 0 ) {
- auto guard = interact_shader->use();
+ last_lattice_update = timer::now();
+ }
- interact_shader->setUniform("influxRequested", currMouseState == 1);
- interact_shader->setUniform("wallRequested", currMouseState == 2);
+ /// Update mouse projection
+ {
+ const auto m = window.getMouse();
- interact_shader->setUniform("startOfLine", prevLatticeMouseX, prevLatticeMouseY);
- interact_shader->setUniform("endOfLine", currLatticeMouseX, currLatticeMouseY);
+ prevMouseState = currMouseState;
+ prevLatticeMouseX = currLatticeMouseX;
+ prevLatticeMouseY = currLatticeMouseY;
- interact_shader->dispatch(nX, nY);
- }
+ currMouseState = std::get<0>(m);
+ currLatticeMouseX = float(std::get<1>(m)) / window.getWidth() * world_width + nX/2;
+ currLatticeMouseY = float(std::get<2>(m)) / window.getHeight() * world_height + nY/2;
+ }
- /// Perform collide & stream steps
- {
- auto guard = collide_shader->use();
+ /// Handle mouse-based interaction
+ if ( currMouseState != 0 || prevMouseState != 0 ) {
+ auto guard = interact_shader->use();
- collide_shader->setUniform("fluidQuality", show_fluid_quality);
- collide_shader->setUniform("iT", iT);
- iT += 1;
+ interact_shader->setUniform("influxRequested", currMouseState == 1);
+ interact_shader->setUniform("wallRequested", currMouseState == 2);
- collide_shader->dispatch(nX, nY);
- }
+ interact_shader->setUniform("startOfLine", prevLatticeMouseX, prevLatticeMouseY);
+ interact_shader->setUniform("endOfLine", currLatticeMouseX, currLatticeMouseY);
- last_lattice_update = timer::now();
- }
+ interact_shader->dispatch(nX, nY);
}
{