From e118b1f5d8071460e3a9d4d731c6d69221f785dc Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 6 Mar 2021 19:44:58 +0000 Subject: Carve up the mess in game/vehicles --- game/vehicles/linkHistory.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 game/vehicles/linkHistory.cpp (limited to 'game/vehicles/linkHistory.cpp') diff --git a/game/vehicles/linkHistory.cpp b/game/vehicles/linkHistory.cpp new file mode 100644 index 0000000..4fac4ba --- /dev/null +++ b/game/vehicles/linkHistory.cpp @@ -0,0 +1,41 @@ +#include "linkHistory.h" +#include "game/network/link.h" +#include + +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}; +} -- cgit v1.2.3