diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-09-14 04:45:54 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-09-14 04:45:54 +0200 |
commit | af01062b0a207c106a6ebb599993fb72a43484c5 (patch) | |
tree | f081c78e9684af0bd3cef9d13a1aa9e5e2733770 /src/Vsync.cpp | |
parent | f0122e7386e0e4fe63dafa9c1835ae0b04557ee4 (diff) |
Use manual vsync since nouveau drivers are broken
Diffstat (limited to 'src/Vsync.cpp')
-rw-r--r-- | src/Vsync.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Vsync.cpp b/src/Vsync.cpp new file mode 100644 index 0000000..ab88205 --- /dev/null +++ b/src/Vsync.cpp @@ -0,0 +1,20 @@ +#include "../include/Vsync.hpp" +#include <time.h> +#include <unistd.h> + +namespace QuickMedia { + VSync::VSync(int framerate) : target_frame_delta_micro(1000.0 / (double)framerate * 1000.0), overflow(0) { + + } + + void VSync::display(sf::RenderWindow &window) { + sf::Int64 sleep_time_micro = target_frame_delta_micro - timer.getElapsedTime().asMicroseconds(); + window.display(); + if(sleep_time_micro > 0) { + if(usleep(sleep_time_micro) != 0) { + fprintf(stderr, "failed to sleep!\n"); + } + timer.restart(); + } + } +}
\ No newline at end of file |