summaryrefslogtreecommitdiff
path: root/game/vehicles/railloco.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-02-14 16:44:00 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-02-14 16:44:00 +0000
commit4562557d599fd70d32b15313ffebd976c3ddfa7d (patch)
tree54d0a6798be87fb1f38f2152c12e60b1dc033639 /game/vehicles/railloco.cpp
parentBroken down Brush47 (diff)
downloadilt-4562557d599fd70d32b15313ffebd976c3ddfa7d.tar.bz2
ilt-4562557d599fd70d32b15313ffebd976c3ddfa7d.tar.xz
ilt-4562557d599fd70d32b15313ffebd976c3ddfa7d.zip
Maintain a history of links traversed
Diffstat (limited to 'game/vehicles/railloco.cpp')
-rw-r--r--game/vehicles/railloco.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/game/vehicles/railloco.cpp b/game/vehicles/railloco.cpp
index d06474c..146d2e0 100644
--- a/game/vehicles/railloco.cpp
+++ b/game/vehicles/railloco.cpp
@@ -12,25 +12,23 @@ void
RailLoco::tick(TickDuration dur)
{
linkDist += dur.count() * speed;
- auto curLink {link.lock()};
- while (linkDist > curLink->length) {
- location = curLink->positionAt(curLink->length, linkDir);
- const auto & nexts {curLink->nexts[1 - linkDir]};
+ auto curLink {linkHist.getAt(0.F)};
+ while (linkDist > curLink.first->length) {
+ location = curLink.first->positionAt(curLink.first->length, curLink.second);
+ const auto & nexts {curLink.first->nexts[1 - curLink.second]};
const auto next = std::find_if(nexts.begin(), nexts.end(), [ang = location.GetRot().y](const Link::Next & n) {
return std::abs(normalize(n.first.lock()->ends[n.second].second - ang)) < 0.1F;
});
if (next != nexts.end()) {
- linkDist -= curLink->length;
- link = next->first;
- curLink = link.lock();
- linkDir = next->second;
+ linkDist -= curLink.first->length;
+ curLink = linkHist.add(next->first, next->second);
}
else {
- linkDist = curLink->length;
+ linkDist = curLink.first->length;
speed = 0;
}
}
- location = curLink->positionAt(linkDist, linkDir);
+ location = curLink.first->positionAt(linkDist, curLink.second);
}
Brush47::Brush47(const LinkPtr & l) : RailLoco(l, "brush47.obj", "brush47.png") { }