summaryrefslogtreecommitdiff
path: root/game/vehicles
diff options
context:
space:
mode:
Diffstat (limited to 'game/vehicles')
-rw-r--r--game/vehicles/linkHistory.cpp18
-rw-r--r--game/vehicles/railVehicleClass.h5
-rw-r--r--game/vehicles/train.cpp10
-rw-r--r--game/vehicles/train.h2
-rw-r--r--game/vehicles/vehicle.cpp2
-rw-r--r--game/vehicles/vehicle.h2
6 files changed, 25 insertions, 14 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};
}
diff --git a/game/vehicles/railVehicleClass.h b/game/vehicles/railVehicleClass.h
index 9d9d4c2..88f08c5 100644
--- a/game/vehicles/railVehicleClass.h
+++ b/game/vehicles/railVehicleClass.h
@@ -3,14 +3,13 @@
#include "assetFactory/asset.h"
#include "gfx/gl/instanceVertices.h"
#include "gfx/models/mesh.h"
+#include "gfx/models/texture.h"
#include "gfx/renderable.h"
#include <array>
#include <memory>
-#include <string>
class SceneShader;
class ShadowMapper;
-class Texture;
class Location;
class RailVehicleClass : public Renderable, public Asset {
@@ -25,7 +24,7 @@ public:
std::array<Mesh::Ptr, 2> bogies;
Mesh::Ptr bodyMesh;
- std::shared_ptr<Texture> texture;
+ Texture::Ptr texture;
float wheelBase;
float length;
float maxSpeed;
diff --git a/game/vehicles/train.cpp b/game/vehicles/train.cpp
index 5bddd61..2461d9c 100644
--- a/game/vehicles/train.cpp
+++ b/game/vehicles/train.cpp
@@ -2,7 +2,6 @@
#include "game/vehicles/linkHistory.h"
#include "game/vehicles/railVehicle.h"
#include "game/vehicles/railVehicleClass.h"
-#include "gfx/renderable.h"
#include "location.h"
#include <algorithm>
#include <functional>
@@ -11,6 +10,9 @@
template<typename> class Ray;
+constexpr auto DECELERATION_RATE = 60000.F;
+constexpr auto ACCELERATIONS_RATE = 30000.F;
+
Location
Train::getBogiePosition(float linkDist, float dist) const
{
@@ -41,8 +43,8 @@ Train::doActivity(Go * go, TickDuration dur)
const auto maxSpeed = objects.front()->rvClass->maxSpeed;
if (go->dist) {
*go->dist -= speed * dur.count();
- if (*go->dist < (speed * speed) / 60.F) {
- speed -= std::min(speed, 30.F * dur.count());
+ if (*go->dist < (speed * speed) / DECELERATION_RATE) {
+ speed -= std::min(speed, ACCELERATIONS_RATE * dur.count());
}
else {
if (speed != maxSpeed) {
@@ -61,6 +63,6 @@ void
Train::doActivity(Idle *, TickDuration dur)
{
if (speed != 0.F) {
- speed -= std::min(speed, 30.F * dur.count());
+ speed -= std::min(speed, DECELERATION_RATE * dur.count());
}
}
diff --git a/game/vehicles/train.h b/game/vehicles/train.h
index 4320103..4933347 100644
--- a/game/vehicles/train.h
+++ b/game/vehicles/train.h
@@ -17,7 +17,7 @@ template<typename> class Ray;
class Train : public Vehicle, public Collection<RailVehicle, false>, public Can<Go>, public Can<Idle> {
public:
- explicit Train(const Link::Ptr & link, float linkDist = 0) : Vehicle {link, linkDist} { }
+ explicit Train(const Link::CPtr & link, float linkDist = 0) : Vehicle {link, linkDist} { }
[[nodiscard]] const Location &
getLocation() const override
diff --git a/game/vehicles/vehicle.cpp b/game/vehicles/vehicle.cpp
index 0d46017..dd652bc 100644
--- a/game/vehicles/vehicle.cpp
+++ b/game/vehicles/vehicle.cpp
@@ -15,7 +15,7 @@
#include <utility>
#include <vector>
-Vehicle::Vehicle(const Link::Ptr & l, float ld) : linkDist {ld}
+Vehicle::Vehicle(const Link::CPtr & l, float ld) : linkDist {ld}
{
linkHist.add(l, 0);
currentActivity = std::make_unique<Idle>();
diff --git a/game/vehicles/vehicle.h b/game/vehicles/vehicle.h
index 354f904..c3b35b7 100644
--- a/game/vehicles/vehicle.h
+++ b/game/vehicles/vehicle.h
@@ -14,7 +14,7 @@ class Location;
class Vehicle : public WorldObject, public Selectable {
public:
- explicit Vehicle(const Link::Ptr & link, float linkDist = 0);
+ explicit Vehicle(const Link::CPtr & link, float linkDist = 0);
float linkDist; // distance along current link
float speed {}; // speed in m/s (~75 km/h)