mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-11 18:07:13 +01:00
fix(track): the cab keeps the shake a track doesn't replace, and the editor redraws all that an edit changes
The side sway from the lateral acceleration now goes off only on a track with a sideways value, and the random jolts on one with a vertical or a sideways value. Dips at the rail joints and cross level alone replace neither. On a switch it goes by the path set and what its joined tracks allow. An edit in the editor also rebuilds the other switches of a joined group with the tracks they meet, and the tracks of a rail run whose joints moved. Removing a track does the same. While dragging, the tracks further off wait until the drag ends. The clatter of a bogie's axles was right: the followers stand at the pivots and the offsets are the places of the wheel sets. The misleading name goes. Also what Sonar had left: a parameter as a span, a const method, a struct and its member apart, commented out code, and a function of the grading tool split, with the same output.
This commit is contained in:
@@ -59,7 +59,8 @@ class TSegment
|
||||
int path { 0 }; // which path of a switch
|
||||
// where the path meets the next one: the middle of their ends and their common vector across
|
||||
std::array<std::optional<std::pair<glm::dvec3, glm::dvec3>>, 2> joints;
|
||||
} m_setting;
|
||||
};
|
||||
setting m_setting;
|
||||
double fLength { -1.0 }; // długość policzona
|
||||
std::vector<double> fTsBuffer; // wartości parametru krzywej t dla równych odcinków s
|
||||
std::vector<double> fTsSlope; // nachylenie dt/du (= dt/ds * fStep) w tych samych punktach
|
||||
|
||||
@@ -1375,7 +1375,7 @@ glm::vec3 TTrack::get_nearest_point(const glm::dvec3 &point) const
|
||||
// wypełnianie tablic VBO
|
||||
void TTrack::rebuild_geometry( gfx::geometrybank_handle const &Bank ) {
|
||||
|
||||
++s_layoutstamp;
|
||||
m_drawnrun = {};
|
||||
|
||||
Geometry1.clear();
|
||||
Geometry2.clear();
|
||||
@@ -1392,6 +1392,9 @@ void TTrack::rebuild_geometry( gfx::geometrybank_handle const &Bank ) {
|
||||
void TTrack::create_geometry( gfx::geometrybank_handle const &Bank ) {
|
||||
gfx::userdata_array empty_userdata;
|
||||
share_joints();
|
||||
if( rail_phase( 0.0 ) >= 0.0 ) {
|
||||
m_drawnrun = m_railrun;
|
||||
}
|
||||
// bake per-instance sleeper transforms now that the owning cell has assigned m_origin.
|
||||
// safe to call here even if the track has no sleepermodel (early-outs internally).
|
||||
if( m_sleeper_enabled && m_sleeper_local_transforms.empty() ) {
|
||||
|
||||
@@ -348,6 +348,8 @@ public:
|
||||
// the unevenness the track declares, on a path of a switch
|
||||
track_uneven::amounts uneven_declared( int const Path = 0 ) const;
|
||||
bool is_uneven() const;
|
||||
// the unevenness along what the vehicles take now: the path set on a switch, with what the switches joined and the tracks by them allow
|
||||
track_uneven::amounts uneven_underway();
|
||||
// the unevenness at a distance along a path, meeting the tracks joined at its ends
|
||||
track_uneven::amounts uneven_at( double const Distance, int const Path = 0 );
|
||||
// how much of the displacement a point of the profile at the depth takes
|
||||
@@ -358,6 +360,10 @@ public:
|
||||
double joint_dip( double const Distance ); // m
|
||||
// distance from the rail joint behind; negative: the track has no joints that dip
|
||||
double rail_phase( double const Distance );
|
||||
// whether the rail joints are elsewhere than the geometry of the track has them
|
||||
bool rail_joints_moved();
|
||||
// the uneven tracks whose values go by the switches among the given: all the switches joined to those, and the tracks they meet
|
||||
static std::vector<TTrack *> switch_followers( std::vector<TTrack *> const &Tracks );
|
||||
void ConnectionsLog();
|
||||
bool DoubleSlip() const;
|
||||
static void fetch_default_profiles();
|
||||
@@ -397,6 +403,7 @@ private:
|
||||
};
|
||||
void settle_rail_run();
|
||||
rail_run m_railrun;
|
||||
rail_run m_drawnrun; // as the geometry has it; stamp -1: it has no joints that dip
|
||||
// the value along each path of a switch: the lowest of that path in the switches joined, 0 next to a track with none.
|
||||
// And at the ends of the paths, by what meets there: the other path at the common end, the path of a switch joined
|
||||
struct switch_stray {
|
||||
@@ -411,10 +418,10 @@ private:
|
||||
// the lowest value of the paths ending at the point
|
||||
track_uneven::amounts switch_paths_at( glm::dvec3 const &Point ) const;
|
||||
// what a plain track comes to at its end, where it meets the other one
|
||||
track_uneven::amounts uneven_met( TTrack *Other, glm::dvec3 const &Point );
|
||||
track_uneven::amounts uneven_met( TTrack *Other, glm::dvec3 const &Point ) const;
|
||||
// the value of a switch where a track joined to it meets it
|
||||
track_uneven::amounts switch_uneven_at( glm::dvec3 const &Point );
|
||||
static int s_layoutstamp; // bumped when tracks are joined or changed, invalidates the two above
|
||||
static int s_layoutstamp; // bumped when tracks are joined or changed, invalidates the two above. Once per change: a run is walked again after each
|
||||
void create_road_profile( gfx::vertex_array &Output, bool const Forcetransition = false );
|
||||
void create_road_side_profile( gfx::vertex_array &Right, gfx::vertex_array &Left, gfx::vertex_array const &Road, bool const Forcetransition = false );
|
||||
/// <summary>
|
||||
|
||||
@@ -10,6 +10,8 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "stdafx.h"
|
||||
#include "world/Track.h"
|
||||
|
||||
#include <span>
|
||||
|
||||
// The part of TTrack that goes with the unevenness of a track and with what it meets at its ends: joined tracks and switches.
|
||||
// The rules themselves are in TrackUneven.h, here they get applied to the tracks.
|
||||
|
||||
@@ -64,7 +66,7 @@ void keep_to_plain_track( std::array<track_uneven::amounts, 2> &Values, TTrack c
|
||||
}
|
||||
|
||||
// the value along each path: the lowest of that path in the group, 0 in a component that a plain track joined has none of
|
||||
std::array<track_uneven::amounts, 2> group_path_values( std::vector<TTrack *> const &Group ) {
|
||||
std::array<track_uneven::amounts, 2> group_path_values( std::span<TTrack * const> const Group ) {
|
||||
|
||||
std::array<track_uneven::amounts, 2> values { Group.front()->uneven_declared( 0 ), Group.front()->uneven_declared( 1 ) };
|
||||
for( auto const *track : Group ) {
|
||||
@@ -173,6 +175,11 @@ bool TTrack::is_uneven() const {
|
||||
return any( uneven_declared( 0 ) ) || any( uneven_declared( 1 ) ) || joint_depth() > 0.0;
|
||||
}
|
||||
|
||||
track_uneven::amounts TTrack::uneven_underway() {
|
||||
|
||||
return is_switch( this ) ? switch_uneven().paths[ SwitchExtension->CurrentIndex ] : uneven_declared();
|
||||
}
|
||||
|
||||
double TTrack::uneven_bed_share( double const Depth ) const {
|
||||
|
||||
return track_uneven::bed_share( Depth, std::abs( track_rail_profile( m_profile1.second ).front().position.y ), fTexHeight1 );
|
||||
@@ -187,7 +194,7 @@ track_uneven::amounts TTrack::uneven_at( double const Distance, int const Path )
|
||||
return track_uneven::along( uneven_declared(), uneven_met( trPrev, end_point( *Segment, 0 ) ), uneven_met( trNext, end_point( *Segment, 1 ) ), Distance, Length() );
|
||||
}
|
||||
|
||||
track_uneven::amounts TTrack::uneven_met( TTrack *Other, glm::dvec3 const &Point ) {
|
||||
track_uneven::amounts TTrack::uneven_met( TTrack *Other, glm::dvec3 const &Point ) const {
|
||||
|
||||
if( Other == nullptr ) {
|
||||
return {};
|
||||
@@ -278,6 +285,32 @@ double TTrack::rail_phase( double const Distance ) {
|
||||
return track_uneven::rail_phase( m_railrun.origin + m_railrun.way * Distance, fSoundDistance );
|
||||
}
|
||||
|
||||
bool TTrack::rail_joints_moved() {
|
||||
|
||||
return m_drawnrun.stamp != -1
|
||||
&& rail_phase( 0.0 ) >= 0.0
|
||||
&& ( m_railrun.origin != m_drawnrun.origin || m_railrun.way != m_drawnrun.way );
|
||||
}
|
||||
|
||||
std::vector<TTrack *> TTrack::switch_followers( std::vector<TTrack *> const &Tracks ) {
|
||||
|
||||
std::vector<TTrack *> followers;
|
||||
auto const follow = [ &followers ]( TTrack *Track ) {
|
||||
if( Track != nullptr && Track->is_uneven() && std::ranges::find( followers, Track ) == followers.end() ) {
|
||||
followers.push_back( Track );
|
||||
} };
|
||||
for( auto *track : Tracks ) {
|
||||
if( false == is_switch( track ) ) {
|
||||
continue;
|
||||
}
|
||||
for( auto *member : switch_group( *track ) ) {
|
||||
follow( member );
|
||||
std::ranges::for_each( joined_to_switch( *member ), follow );
|
||||
}
|
||||
}
|
||||
return followers;
|
||||
}
|
||||
|
||||
void TTrack::settle_rail_run() {
|
||||
|
||||
// the next track of the run past an end of a track, and which of its ends is joined there
|
||||
|
||||
@@ -43,6 +43,18 @@ inline amounts least( amounts const &Left, amounts const &Right ) {
|
||||
return { std::min( Left.up, Right.up ), std::min( Left.side, Right.side ), std::min( Left.cross, Right.cross ) };
|
||||
}
|
||||
|
||||
// which of the other sources of the cab shake the ride on a track stands in for
|
||||
struct shake_sources {
|
||||
bool sway { false }; // from the lateral acceleration
|
||||
bool jolts { false }; // drawn at random
|
||||
};
|
||||
|
||||
// sideways only with something going sideways. Cross level turns the body, and the dips at the joints come and go: neither makes up for any of them
|
||||
inline shake_sources replaced_shake( amounts const &Amount ) {
|
||||
|
||||
return { Amount.side > 0.0, Amount.up > 0.0 || Amount.side > 0.0 };
|
||||
}
|
||||
|
||||
struct wave {
|
||||
double x;
|
||||
double z;
|
||||
|
||||
Reference in New Issue
Block a user