mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-04 23:45:17 +01:00
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.
This commit is contained in:
+1
-1
@@ -46,7 +46,7 @@ bonebend: <submodel> <point> <point> ... [head <point> <point>] [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`
|
||||
|
||||
+7
-5
@@ -1152,15 +1152,17 @@ bool TDynamicObject::follows( shared_chain const &Shared ) const {
|
||||
return Shared.vehicle != nullptr && std::less<TDynamicObject const *> {}( 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<glm::dvec3> 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<glm::dvec3> 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 );
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user