nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
history.h
Go to the documentation of this file.
1#ifndef NANOMMO_SERVER_HISTORY_H_
2#define NANOMMO_SERVER_HISTORY_H_
3
4#include <chrono>
5#include <cstdint>
6#include <deque>
7#include <map>
8#include <optional>
9
10#include "terrain/lands.h"
11
12namespace nanommo {
13
14/// Where each player has been, a place a tick, for the last second, which a
15/// World keeps. A client draws everyone else a moment in the past, so a blow
16/// it aimed at a player can be checked against where that player was then,
17/// not where they are now.
18class History {
19 public:
20 /// A second: more than any blow goes back.
21 static constexpr std::chrono::seconds kKept{1};
22
23 /// The player is at the place at the time, on the world's clock, which only
24 /// goes on. Their places from more than kKept before it go.
25 void Record(uint32_t id, std::chrono::nanoseconds time, Place place);
26
27 /// Where the player was at the time, between their places on either side of
28 /// it. Before their oldest, it's that, and after their newest, that. Or
29 /// nothing, for a player it has no places of.
30 std::optional<Place> At(uint32_t id, std::chrono::nanoseconds time) const;
31
32 /// Forgets a player who's left.
33 void Leave(uint32_t id);
34
35 private:
36 struct Moment {
37 std::chrono::nanoseconds time{0};
38 Place place;
39 };
40 std::map<uint32_t, std::deque<Moment>> moments_;
41};
42
43} // namespace nanommo
44
45#endif // NANOMMO_SERVER_HISTORY_H_
std::optional< Place > At(uint32_t id, std::chrono::nanoseconds time) const
Definition history.cc:20
static constexpr std::chrono::seconds kKept
A second: more than any blow goes back.
Definition history.h:21
void Record(uint32_t id, std::chrono::nanoseconds time, Place place)
Definition history.cc:12
void Leave(uint32_t id)
Forgets a player who's left.
Definition history.cc:42
Definition chat.cc:9
In metres from the middle of a land.
Definition lands.h:13