diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-02-14 14:52:04 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-02-14 14:52:04 +0000 |
commit | 08f6e874a8930899714e2c0d313a9ed9f4eec35c (patch) | |
tree | accb6a40100dceb2d5aa4d79b2a96a865b3a65d7 /game/vehicles/railloco.cpp | |
parent | Code tidy-up (diff) | |
download | ilt-08f6e874a8930899714e2c0d313a9ed9f4eec35c.tar.bz2 ilt-08f6e874a8930899714e2c0d313a9ed9f4eec35c.tar.xz ilt-08f6e874a8930899714e2c0d313a9ed9f4eec35c.zip |
Link weak_ptrs
Diffstat (limited to 'game/vehicles/railloco.cpp')
-rw-r--r-- | game/vehicles/railloco.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/game/vehicles/railloco.cpp b/game/vehicles/railloco.cpp index 54582c2..d06474c 100644 --- a/game/vehicles/railloco.cpp +++ b/game/vehicles/railloco.cpp @@ -12,23 +12,25 @@ void RailLoco::tick(TickDuration dur) { linkDist += dur.count() * speed; - while (linkDist > link->length) { - location = link->positionAt(link->length, linkDir); - const auto & nexts {link->nexts[1 - linkDir]}; + auto curLink {link.lock()}; + while (linkDist > curLink->length) { + location = curLink->positionAt(curLink->length, linkDir); + const auto & nexts {curLink->nexts[1 - linkDir]}; const auto next = std::find_if(nexts.begin(), nexts.end(), [ang = location.GetRot().y](const Link::Next & n) { - return std::abs(normalize(n.first->ends[n.second].second - ang)) < 0.1F; + return std::abs(normalize(n.first.lock()->ends[n.second].second - ang)) < 0.1F; }); if (next != nexts.end()) { - linkDist -= link->length; + linkDist -= curLink->length; link = next->first; + curLink = link.lock(); linkDir = next->second; } else { - linkDist = link->length; + linkDist = curLink->length; speed = 0; } } - location = link->positionAt(linkDist, linkDir); + location = curLink->positionAt(linkDist, linkDir); } Brush47::Brush47(const LinkPtr & l) : RailLoco(l, "brush47.obj", "brush47.png") { } |