nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
tick.h
Go to the documentation of this file.
1#ifndef NANOMMO_SERVER_TICK_H_
2#define NANOMMO_SERVER_TICK_H_
3
4#include <chrono>
5
6#include "absl/status/statusor.h"
7
8namespace nanommo {
9
10/// Returns the time between two simulation ticks, accurate to the nanosecond,
11/// when the world is updated `ticks_per_second` times a second. Returns an
12/// InvalidArgument error if `ticks_per_second` isn't positive.
13absl::StatusOr<std::chrono::nanoseconds> TickInterval(int ticks_per_second);
14
15/// The most a world catches up on, by running the ticks it's behind back to
16/// back.
17inline constexpr std::chrono::seconds kMostBehind{1};
18
19/// When the tick after the one that was due at `due` is due, once that one's
20/// over, at `now`: an interval after it, so that the ticks don't drift, and a
21/// tick that ran late is caught up on. A world that's more than kMostBehind
22/// behind, as when it waited for Redis, doesn't run the ticks it missed back
23/// to back, which would play the stall over at many times the speed: those
24/// are gone, and the next is an interval from now.
25std::chrono::steady_clock::time_point NextTick(
26 std::chrono::steady_clock::time_point due,
27 std::chrono::steady_clock::time_point now,
28 std::chrono::nanoseconds interval);
29
30} // namespace nanommo
31
32#endif // NANOMMO_SERVER_TICK_H_
Definition chat.cc:9
absl::StatusOr< std::chrono::nanoseconds > TickInterval(int ticks_per_second)
Definition tick.cc:9
std::chrono::steady_clock::time_point NextTick(std::chrono::steady_clock::time_point due, std::chrono::steady_clock::time_point now, std::chrono::nanoseconds interval)
Definition tick.cc:16
constexpr std::chrono::seconds kMostBehind
Definition tick.h:17