diff options
-rw-r--r-- | src/glfw/window.cc | 1 | ||||
-rw-r--r-- | src/main.cc | 26 | ||||
-rw-r--r-- | src/shader/code/collide.glsl | 2 | ||||
-rw-r--r-- | src/timer.cc | 7 | ||||
-rw-r--r-- | src/timer.h | 3 |
5 files changed, 31 insertions, 8 deletions
diff --git a/src/glfw/window.cc b/src/glfw/window.cc index c0074ad..77be947 100644 --- a/src/glfw/window.cc +++ b/src/glfw/window.cc @@ -14,6 +14,7 @@ Window::Window(const std::string& title): _handle(glfwCreateWindow(_width, _height, title.c_str(), NULL, NULL)) { if ( _handle != nullptr ) { glfwMakeContextCurrent(_handle); + glfwSwapInterval(0); if ( glewInit() == GLEW_OK ) { _good = true; } diff --git a/src/main.cc b/src/main.cc index 0b4df95..eeeb130 100644 --- a/src/main.cc +++ b/src/main.cc @@ -26,7 +26,7 @@ constexpr GLuint nX = 512; constexpr GLuint nY = 128; -constexpr int lups = 100; // max lattice updates per second +constexpr double maxLUPS = 500; float getWorldHeight(int window_width, int window_height, float world_width) { return world_width / window_width * window_height; @@ -120,15 +120,11 @@ int render(bool open_boundaries) { return -1; } - auto last_frame = timer::now(); - bool update_lattice = true; bool tick = true; auto pause_key = window.getKeyWatcher(GLFW_KEY_SPACE); - GLuint iT = 0; - int prevMouseState = 0; float prevLatticeMouseX; float prevLatticeMouseY; @@ -140,6 +136,12 @@ int render(bool open_boundaries) { auto tick_buffers = { lattice_a->getBuffer(), lattice_b->getBuffer(), fluid->getBuffer() }; auto tock_buffers = { lattice_b->getBuffer(), lattice_a->getBuffer(), fluid->getBuffer() }; + GLuint iT = 0; + int statLUPS = 0; + + auto last_lattice_update = timer::now(); + auto last_lups_update = timer::now(); + window.render([&](bool window_size_changed) { if ( pause_key.wasClicked() ) { update_lattice = !update_lattice; @@ -151,7 +153,15 @@ int render(bool open_boundaries) { } if ( update_lattice ) { - if ( timer::millisecondsSince(last_frame) >= 1000/lups ) { + 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); @@ -198,7 +208,7 @@ int render(bool open_boundaries) { collide_shader->dispatch(nX, nY); } - last_frame = timer::now(); + last_lattice_update = timer::now(); } } @@ -214,6 +224,8 @@ int render(bool open_boundaries) { } }); + std::cout << std::endl; + return 0; } diff --git a/src/shader/code/collide.glsl b/src/shader/code/collide.glsl index 230f02e..8755a3d 100644 --- a/src/shader/code/collide.glsl +++ b/src/shader/code/collide.glsl @@ -20,7 +20,7 @@ const float weight[q] = float[]( 1./36 , 1./9., 1./36. ); -const float tau = 0.6; +const float tau = 0.65; const float omega = 1/tau; /// Vector utilities diff --git a/src/timer.cc b/src/timer.cc index c46017c..162b3fe 100644 --- a/src/timer.cc +++ b/src/timer.cc @@ -13,4 +13,11 @@ double millisecondsSince( ).count(); } +double secondsSince( + std::chrono::time_point<std::chrono::high_resolution_clock>& pit) { + return std::chrono::duration_cast<std::chrono::seconds>( + now() - pit + ).count(); +} + } diff --git a/src/timer.h b/src/timer.h index aed1b61..0ce6d27 100644 --- a/src/timer.h +++ b/src/timer.h @@ -9,4 +9,7 @@ std::chrono::time_point<std::chrono::high_resolution_clock> now(); double millisecondsSince( std::chrono::time_point<std::chrono::high_resolution_clock>& pit); +double secondsSince( + std::chrono::time_point<std::chrono::high_resolution_clock>& pit); + } |