neoGFX
Cross-platform C++ app/game engine
chrono.hpp
Go to the documentation of this file.
1 // chrono.hpp
2 /*
3  neogfx C++ GUI Library
4  Copyright (c) 2015 Leigh Johnston. All Rights Reserved.
5 
6  This program is free software: you can redistribute it and / or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #pragma once
20 
21 #include <neogfx/neogfx.hpp>
24 
25 namespace neogfx::game
26 {
27  namespace chrono
28  {
29  using namespace facebook::util;
30 
31  inline constexpr double to_milliseconds(const flicks ns)
32  {
33  return static_cast<double>(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::duration<double>(ns)).count());
34  }
35  }
36 
38  typedef std::optional<time_interval> optional_time_interval;
39  typedef int64_t step_time_interval;
40  typedef std::optional<step_time_interval> optional_step_time_interval;
41  typedef step_time_interval step_time;
42  typedef std::optional<step_time> optional_step_time;
43 
44  inline step_time_interval to_step_time(time_interval aTime, step_time_interval aStepInterval)
45  {
46  auto fs = chrono::to_flicks(aTime).count();
47  return fs - (fs % aStepInterval);
48  }
49 
50  inline step_time_interval to_step_time(optional_time_interval& aTime, step_time_interval aStepInterval)
51  {
52  if (aTime)
53  return to_step_time(*aTime, aStepInterval);
54  else
55  return 0;
56  }
57 
58  inline time_interval from_step_time(step_time_interval aStepTime)
59  {
60  return chrono::to_seconds(chrono::flicks{ aStepTime });
61  }
62 }
std::optional< time_interval > optional_time_interval
Definition: chrono.hpp:38
scalar time_interval
Definition: chrono.hpp:37
constexpr flicks to_flicks(const double s)
Definition: flicks.h:83
std::optional< step_time > optional_step_time
Definition: chrono.hpp:42
constexpr double to_seconds(const flicks ns)
Definition: flicks.h:77
time_interval from_step_time(step_time_interval aStepTime)
Definition: chrono.hpp:58
std::optional< step_time_interval > optional_step_time_interval
Definition: chrono.hpp:40
step_time_interval to_step_time(time_interval aTime, step_time_interval aStepInterval)
Definition: chrono.hpp:44
step_time_interval step_time
Definition: chrono.hpp:41
std::chrono::duration< std::chrono::nanoseconds::rep, std::ratio< 1, 705600000 > > flicks
Definition: flicks.h:60
double scalar
Definition: numerical.hpp:40
constexpr double to_milliseconds(const flicks ns)
Definition: chrono.hpp:31
int64_t step_time_interval
Definition: chrono.hpp:39