termaze

maze generation and pathfinding visualizer
git clone git://git.yotsev.xyz/termaze.git
Log | Files | Refs | README | LICENSE

timer.cpp (812B)


      1 #include "timer.hpp"
      2 #include "state.hpp"
      3 #include <chrono>
      4 #include <thread>
      5 
      6 timer::timer()
      7 {
      8     initTime = std::chrono::steady_clock::now();
      9 }
     10 
     11 timer::~timer()
     12 {
     13 }
     14 
     15 void timer::WaitInterval(const float& time_ms)
     16 {
     17     using namespace std::chrono;
     18     using namespace std::this_thread;
     19     if (s::ui_is_open) {
     20         s::ui_render_is_safe = true;
     21         while (s::ui_is_open) {
     22             sleep_for(milliseconds(3));
     23         }
     24         s::ui_render_is_safe = false;
     25         initTime = steady_clock::now();
     26         elapsedTime = milliseconds(0);
     27     } else {
     28         elapsedTime += duration<float>(time_ms / 1000);
     29         steady_clock::time_point now = steady_clock::now();
     30         if (initTime + elapsedTime - now > milliseconds(0)) {
     31             sleep_for(initTime + elapsedTime - now);
     32         }
     33     }
     34 }