project-kyoku/include/core/time.h

44 lines
954 B
C
Raw Permalink Normal View History

2021-12-29 15:59:18 +01:00
#pragma once
namespace kku
{
2022-12-14 11:37:49 +01:00
/// microsec
///
/// Primitive alias representing microseconds, which
/// is the main time measure in-game.
/// 1 second is 1000000 microseconds.
2021-12-29 15:59:18 +01:00
using microsec = long long;
2022-12-14 11:37:49 +01:00
/// TimeRange
///
/// Object representing a section of time.
/// To ensure order safety use
/// static produceValidated function.
2021-12-29 15:59:18 +01:00
struct TimeRange
{
const microsec begin = 0;
const microsec end = 0;
2022-12-14 11:37:49 +01:00
constexpr inline explicit TimeRange() noexcept : begin(0), end(0)
{
}
2021-12-29 15:59:18 +01:00
constexpr inline explicit TimeRange(microsec x, microsec y) noexcept
: begin(x), end(y)
{
}
2022-12-14 11:37:49 +01:00
/// produceValidated
///
/// Creates an object of TimeRange, but
/// also makes sure to place begin and end
/// in the right order to avoid confusion.
static inline TimeRange produceValidated(microsec x, microsec y) noexcept
{
return (x < y) ? TimeRange(x, y) : TimeRange(y, x);
}
2021-12-29 15:59:18 +01:00
};
} // namespace kku