aboutsummaryrefslogtreecommitdiff
path: root/src/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cc')
-rw-r--r--src/main.cc26
1 files changed, 19 insertions, 7 deletions
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;
}