This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //------------------------------------------------------------------------------ | |
| namespace sim | |
| { | |
| template<class tag, typename T, T invalid> | |
| class id | |
| { | |
| public: | |
| id() : m_Value(invalid) { } | |
| explicit id(T val) : m_Value(val) { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template<class clock, typename duration, typename real> | |
| class stopwatch_base | |
| { | |
| public: | |
| stopwatch_base(const clock& c) | |
| : m_Clock(c) | |
| , m_Start(c.now()) | |
| {} | |
| delta_clock::duration_type elapsed() const |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template<class clock, typename duration, typename real> | |
| class timer_base | |
| { | |
| public: | |
| timer_base(const clock& c, duration finish_in) | |
| : m_Clock(c) | |
| , m_End(c.now() + finish_in) | |
| {} | |
| bool finished() const { return m_Clock.now() >= m_End; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include <chrono> | |
| namespace sim | |
| { | |
| namespace time | |
| { | |
| //----------------------------------------------------------------------------- | |
| typedef std::chrono::seconds se; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template<class F> | |
| static void try_catch(const F& f) | |
| { | |
| try | |
| { | |
| f(); | |
| } | |
| catch (const std::exception& e) | |
| { | |
| std::cout << e.what() << std::endl; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template<typename chrono_clock, typename duration> | |
| class delta_clock_base | |
| { | |
| public: | |
| typedef typename chrono_clock::time_point time_point; | |
| typedef typename duration duration_type; | |
| delta_clock_base() | |
| { | |
| tick(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <chrono> | |
| template<class Clock, typename Interval> | |
| class SimpleTimer | |
| { | |
| public: | |
| SimpleTimer(int duration) : m_Duration(Interval(duration)), m_Start(Clock::now()) {} | |
| bool Done() | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <chrono> | |
| template<typename Clock, typename Interval> | |
| class SimpleStopwatch | |
| { | |
| public: | |
| SimpleStopwatch() : m_Start(Clock::now()) {} | |
| Interval Elapsed() | |
| { |