diff options
Diffstat (limited to 'game/vehicles/linkHistory.cpp')
| -rw-r--r-- | game/vehicles/linkHistory.cpp | 18 | 
1 files changed, 14 insertions, 4 deletions
diff --git a/game/vehicles/linkHistory.cpp b/game/vehicles/linkHistory.cpp index e6bab36..77840ed 100644 --- a/game/vehicles/linkHistory.cpp +++ b/game/vehicles/linkHistory.cpp @@ -1,17 +1,27 @@  #include "linkHistory.h"  #include "game/network/link.h"  #include <memory> +#include <optional>  LinkHistory::Entry  LinkHistory::add(const Link::WPtr & l, unsigned char d)  { +	constexpr auto HISTORY_KEEP_LENGTH = 500'000.F; +	while (const auto newLength = [this]() -> std::optional<decltype(totalLen)> { +		if (!links.empty()) { +			const auto newLength = totalLen - links.back().first.lock()->length; +			if (newLength >= HISTORY_KEEP_LENGTH) { +				return newLength; +			} +		} +		return std::nullopt; +	}()) { +		totalLen = newLength.value(); +		links.pop_back(); +	}  	links.insert(links.begin(), {l, d});  	const auto lp = l.lock();  	totalLen += lp->length; -	while (totalLen >= 1000000.F && !links.empty()) { -		totalLen -= links.back().first.lock()->length; -		links.pop_back(); -	}  	return {lp, d};  }  | 
