Skip to content

Commit fcab253

Browse files
committed
Use std::chrono::milliseconds for game speed
1 parent 557b444 commit fcab253

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

libs/s25main/gameData/GameConsts.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org)
1+
// Copyright (C) 2005 - 2026 Settlers Freaks (sf-team at siedler25.org)
22
//
33
// SPDX-License-Identifier: GPL-2.0-or-later
44

@@ -12,8 +12,8 @@
1212

1313
using namespace std::chrono_literals;
1414
/// Length of GameFrames for each speed level
15-
constexpr helpers::EnumArray<std::chrono::duration<unsigned, std::milli>, GameSpeed> SUPPRESS_UNUSED
16-
SPEED_GF_LENGTHS = {{80ms, 60ms, 50ms, 40ms, 30ms}};
15+
constexpr helpers::EnumArray<std::chrono::milliseconds, GameSpeed> SUPPRESS_UNUSED SPEED_GF_LENGTHS = {
16+
{80ms, 60ms, 50ms, 40ms, 30ms}};
1717
constexpr auto MAX_SPEED = 10ms;
1818
constexpr auto MIN_SPEED = SPEED_GF_LENGTHS[GameSpeed::VerySlow];
1919
/// Max/Max speed for debug mode (includes replays)
@@ -24,12 +24,15 @@ constexpr auto SPEED_STEP = 10ms;
2424

2525
/// Normal speed as reference speed for ingame time computations
2626
constexpr auto REFERENCE_SPEED = SPEED_GF_LENGTHS[GameSpeed::Normal];
27+
// When using unsigned as the type for number of GFs check that we can represent
28+
// game durations of at least a year in units of our chosen (reference) speed.
29+
static_assert(REFERENCE_SPEED * std::numeric_limits<unsigned>::max() >= 24h * 365);
2730

2831
/// Get normalized number of game frames for the given duration
2932
template<class Rep, class Period>
3033
constexpr auto duration_to_gfs(const std::chrono::duration<Rep, Period> d)
3134
{
32-
return d / REFERENCE_SPEED;
35+
return static_cast<unsigned>(d / REFERENCE_SPEED);
3336
}
3437

3538
/// Get normalized duration for the given number of game frames

0 commit comments

Comments
 (0)