From 9a48932e393b8bb714e5b7748f6498f4e2e2d233 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Wed, 17 Apr 2019 21:18:11 +0200 Subject: Pause lattice updates independently of UI This way walls may be drawn without disrupting the active fluid flow even more than necessary. --- src/main.cc | 82 ++++++++++++++++++++++++++++++------------------------------- 1 file 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); } { -- cgit v1.2.3