blob: b9d10bc2de3fd2afd9bd7bcd4cbe6cdb43af6213 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#include "vehicle.h"
#include "game/network/link.h"
#include <array>
#include <memory>
#include <utility>
Vehicle::Vehicle(const LinkPtr & l, float ld) : linkDist {ld}
{
linkHist.add(l, 0);
}
LinkHistory::Entry
LinkHistory::add(const LinkWPtr & l, unsigned char d)
{
links.insert(links.begin(), {l, d});
const auto lp = l.lock();
totalLen += lp->length;
while (totalLen >= 1000.F && !links.empty()) {
totalLen -= links.back().first.lock()->length;
links.pop_back();
}
return {lp, d};
}
LinkHistory::Entry
LinkHistory::getCurrent() const
{
return {links.front().first.lock(), links.front().second};
}
LinkHistory::Entry
LinkHistory::getAt(float len, float * rem) const
{
auto litr = links.begin();
while (len > 0.F && litr != links.end()) {
litr++;
if (litr != links.end()) {
len -= litr->first.lock()->length;
}
}
if (litr == links.end()) {
litr--;
}
if (rem) {
*rem = -len;
}
return {litr->first.lock(), litr->second};
}
|