nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
interpolation.h
Go to the documentation of this file.
1#ifndef NANOMMO_CLIENT_INTERPOLATION_H_
2#define NANOMMO_CLIENT_INTERPOLATION_H_
3
4#include <cstdint>
5#include <deque>
6#include <map>
7
8#include "protocol/nanommo.pb.h"
9
10namespace nanommo {
11
12/// Everyone but you, drawn a little in the past, between the two worlds from
13/// the server on either side of that moment, so that they move smoothly
14/// whenever the worlds come, as long as each next one has come by then.
16 public:
17 /// How far behind the server's clock we draw them: two of its ticks, so a
18 /// world can come up to one tick late and still be there in time.
19 static constexpr double kDelay = 0.1;
20
21 /// How far past the newest world we carry them on, along the way they were
22 /// going, when the next one's late or lost, before they wait for it.
23 static constexpr double kMostAhead = 0.1;
24
25 /// A world as it came, at the time on our clock, in seconds. More of a world
26 /// we have, as its other parts come, fills it in, and keeps the time its
27 /// first part came.
28 void Add(const protocol::World& world, double now);
29
30 /// The newest world, with the players other than you, and the monsters,
31 /// where they were kDelay ago on the server's clock.
32 protocol::World Shown(const protocol::World& newest, double now) const;
33
34 /// The time on the server's clock that we draw everyone else at, now, in
35 /// microseconds, which each input says, so that a blow on a duel opponent
36 /// is checked against where we drew them. Or 0 before any world has come.
37 int64_t Drawn(double now) const;
38
39 private:
40 struct Place {
41 float x = 0.0f;
42 float z = 0.0f;
43 };
44 struct Snapshot {
45 /// On the server's clock, in seconds.
46 double sent = 0.0;
47 /// How far our clock was ahead of the server's when it came.
48 double ahead = 0.0;
49 std::map<uint32_t, Place> players;
50 std::map<uint32_t, Place> monsters;
51 };
52 /// The time on the server's clock to draw at, now.
53 double Then(double now) const;
54
55 std::deque<Snapshot> snapshots_;
56};
57
58} // namespace nanommo
59
60#endif // NANOMMO_CLIENT_INTERPOLATION_H_
void Add(const protocol::World &world, double now)
int64_t Drawn(double now) const
static constexpr double kDelay
protocol::World Shown(const protocol::World &newest, double now) const
static constexpr double kMostAhead
Definition chat.cc:9