From eaaf26ff8153360e49c606ebaa08e19399aa3d9d Mon Sep 17 00:00:00 2001 From: maj00r <73280030+maj00r@users.noreply.github.com> Date: Wed, 25 Nov 2026 19:21:21 +0100 Subject: [PATCH] fix(vehicle): hoses swing in simulation time, not wild with the time sped up The chains moved by the render time of each frame, while the vehicle moved by the simulation time. With the time sped up (Shift+F6), the ends of a hose leapt that many times farther than its nodes could swing, and the hoses flailed like shoelaces. They now move by the simulation time too. They are held with the pause. When a sped-up frame is longer than half a second, they start again as made, going along with the vehicle, as after any long gap. Assets: none. --- bones_doc.md | 2 +- vehicle/DynObj.cpp | 12 +++++++----- vehicle/DynObj.h | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/bones_doc.md b/bones_doc.md index 0edb0d572..482422de2 100644 --- a/bones_doc.md +++ b/bones_doc.md @@ -46,7 +46,7 @@ bonebend: ... [head ] [rooted] end made rather than swinging far to the side about the line between its ends. A chain from a cock (a `fixed` point) to a `coupler` point is one hose with the chain of the coupled vehicle that runs the other way, from the point ours ends at back to the point ours starts at, with as many nodes: one of the two vehicles moves it, and both draw it, - so the coupled heads never part. The chains move by the time of each frame, the frames long or short; after a gap + so the coupled heads never part. The chains move by the simulation time of each frame, the frames long or short, sped up with the time acceleration and held by the pause, as the vehicle is; after a gap of more than half a second (the vehicle left alone while far) they start again as made, going along with the vehicle. - `bone`: the submodel moves with its anchor point and turns about it to keep facing the other point. With `none` diff --git a/vehicle/DynObj.cpp b/vehicle/DynObj.cpp index 5acdc2491..c2f0433a1 100644 --- a/vehicle/DynObj.cpp +++ b/vehicle/DynObj.cpp @@ -1152,15 +1152,17 @@ bool TDynamicObject::follows( shared_chain const &Shared ) const { return Shared.vehicle != nullptr && std::less {}( Shared.vehicle, this ); } -// moves the chains by the render time since they moved last, once a frame, all but those the next vehicle moves +// moves the chains by the simulation time since they moved last, once a frame, all but those the next vehicle moves: the +// time the vehicle itself moves by, sped up (the time acceleration) or held (the pause) with it, so the ends of a hose don't +// leap a time faster than its nodes swing void TDynamicObject::advance_chains( std::vector const &Now, bool const Needed ) { - auto const clock { Timer::GetRenderTime() }; + auto const clock { Timer::GetTime() }; if( clock == m_chainclock || ( false == m_chainsnear && false == Needed ) ) { return; } auto const elapsed { m_chainclock < 0.0 ? 0.0 : std::max( clock - m_chainclock, 0.0 ) }; // the time as it went, so the nodes keep up with their ends: a step cut short while the ends moved all the way would - // be a jolt. after a long gap (the vehicle left alone while far, or the game held up) the chains start again where - // made instead, going along with the vehicle + // be a jolt. after a long gap (the vehicle left alone while far, the game held up, or a frame of the time sped up + // far) the chains start again where made instead, going along with the vehicle auto const restart { elapsed > max_chain_gap }; auto const deltatime { restart ? 0.0 : elapsed }; m_chainclock = clock; @@ -1209,7 +1211,7 @@ std::optional TDynamicObject::chain_clamp( bones::chain const &Chain // the same, for the next vehicle whose chain this one shares: with this vehicle's pose of the moment void TDynamicObject::advance_chains() { - if( m_rig.empty() || Timer::GetRenderTime() == m_chainclock ) { return; } + if( m_rig.empty() || Timer::GetTime() == m_chainclock ) { return; } // the next vehicle needs the chain it shares with this one: moved however far this one is, or out of sight advance_chains( bones::pose( m_rig, bone_drive( false ) ), true ); } diff --git a/vehicle/DynObj.h b/vehicle/DynObj.h index 362924143..4363ce0c3 100644 --- a/vehicle/DynObj.h +++ b/vehicle/DynObj.h @@ -355,8 +355,8 @@ private: TDynamicObject *vehicle { nullptr }; std::size_t chain { 0 }; }; - double m_chainclock { -1.0 }; // the render time the chains were moved to - double m_chainposed { -1.0 }; // the render time the nodes were last taken into the pose + double m_chainclock { -1.0 }; // the simulation time the chains were moved to + double m_chainposed { -1.0 }; // the simulation time the nodes were last taken into the pose bool m_flexesnear { false }; // whether the vehicle is near enough for its bent submodels to be bent and drawn static constexpr double flex_reach { 50.0 }; // m, how near that is bool m_chainsnear { false }; // whether it's near enough for its chains to move