time.hpp 759 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //
  2. // time.hpp
  3. // engine
  4. //
  5. // Created by Sam Jaffe on 9/3/16.
  6. //
  7. #pragma once
  8. #include <chrono>
  9. namespace env::clock {
  10. using clock_t = std::chrono::steady_clock;
  11. using timestamp = std::chrono::time_point<clock_t>;
  12. using duration = clock_t::duration;
  13. struct tick {
  14. tick(timestamp prev) : now(clock_t::now()), since(now - prev) {}
  15. timestamp now;
  16. duration since;
  17. };
  18. inline timestamp now() { return clock_t::now(); }
  19. template <typename T> T current_time() {
  20. return std::chrono::duration<T>(now().time_since_epoch()).count();
  21. }
  22. }
  23. namespace env {
  24. struct fps {
  25. static clock::duration const v24;
  26. static clock::duration const v30;
  27. static clock::duration const v60;
  28. static clock::duration const v120;
  29. static clock::duration const v144;
  30. };
  31. }