mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-28 17:24:06 +01:00
origin/staging7ac2472c3into feat/gl46-migrationdb26a33ed, so that #468 merges into staging. Merge base037158104. Staging carries master up to571487612(squashed in #514); this branch had merged master up to7c12b83ba. Conflicts, file by file: - README.md: WITH_BETTER_RENDERER row dropped (gl46), USE_SYSTEM_JSON row kept (staging) - CMakeLists.txt: gl46 lists, plus staging's new core sources (hardwareinfo, sn_utils, regionfile, inionlysettings, fieldshunting, gaugewrap, drivingaid, signalpassing, brakereleaser, crew, brakecharge); none listed twice - tests/unit/CMakeLists.txt: both (texturealpha, freecameramotion; editorSwitchDrives, Camera) - vehicle/brakingcurve.{h,cpp}, tests/unit/test_braking_curve.cpp (add/add): staging (#479 brake_acting on the same #409 code) - editor/editorHttp.cpp: staging (it has gl46's #432 and certificate fixes, plus #439 libcurl loaded at run time) - tests/unit/test_editor_http.cpp (add/add): staging (adds the available() case of #439) - utilities/Globals.h: gl46 crashdump_full (staging's CrashDumpFull is #425, replaced here by utilities/crashdump.cpp); fmradio and staging's OpenAL options both; gfx_headlights_beamwidth (#481) not taken - utilities/Globals.cpp: both (odometer.expiry, OpenAL keys, fmradio, gl46 gfx keys); gfx.headlights.beamwidth (#481) not taken - utilities/Logs.cpp: staging's log_file_name() for both files, with gl46's crashdump_set_log_file() for both - utilities/utilities.h: gl46 set_thread_random_engine(); Random(int, int) gone on both sides - tests/unit/test_utilities.cpp: staging's includes - simulation/simulationtest.cpp: gl46 (no NvRenderer, LegacyRenderer, BasicRenderer here) - ci_shadervalidator/* (incl. add/add utilities/Logs.h): gl46's validator of shaders/ogl46 and shaders/vk14; staging's #437 fixed the GL 3.3 one - gl/shader.cpp, gl/glsl_common.cpp: gl46 (shaders come from rendering/common/shadersource.cpp); HEADLIGHT_BEAM_WIDTH (#481) not taken - shaders/mat_wire.frag: gl46. Rename detection paired staging's mat_colored.frag (#481) with it - lang/editor_pl.po: union; the 12 camera speed / orthophoto entries staging adds are here already (master #312) - audio/audiorenderer.{h,cpp}: both (fmradio; startsample and the low-pass filter); the destructor releases the radio, then the filter - application/editormode.h, application/editormodeswitchdrive.cpp: staging (#509 on #330, which is all this side had) - application/application.cpp: gl46's start sequence (no init_ogl, ANGLE or NvRenderer; crash window after init_ui) with staging's hardware::log_system() (#389) - EU07.cpp: gl46 (crash reports of utilities/crashdump.cpp); staging's side was #425's handler, replaced here - model/Texture.{h,cpp}: gl46 (texture_source); staging's side is master #399/#411/#362/#386, merged here before - world/Track.h, world/TrackSleepers.h: both (TrackBlend, lay(Fastened)/fasten; TrackBuckle, pack_models) - world/Segment.cpp: staging's track buckling on the split stray factors both sides have - vehicle/Driver.h: staging's additions (#444, #494, #473, #346, timetable flags) - vehicle/Driver.cpp: staging's file, with this branch'sf4f8c75e4(road orders measured along the lane) and8fbf05674(a holding road order blocks the ones past it) applied again; #409's SeenAheadTolerance gives way to #473 - vehicle/DynObj.h: friend opengl46_renderer and friend class vehicle_table - vehicle/DynObj.cpp: gl46's vehicle_table::update() with staging's update_off_track_contacts() and update_brake_pipes() - McZapkie/Mover.cpp: staging's function splits (#239) and hose exchange (#388); every line this branch added to Mover.cpp/MOVER.h is kept - .github/workflows/build_bin.yml: staging's apt-install step (#497) and pinned download-artifact (#331) Modify/delete, kept deleted: - rendering/opengl33renderer.{cpp,h}, rendering/openglparticles.cpp, rendering/openglrenderer.{cpp,h}: staging's versions are master's, and every master change to them is in this branch's history already - shaders/light_common.glsl, shaders/mat_sunlessnormalmap_specgloss.frag: see below Carried into this branch's code: - the hose exchange after each sub-step (#387/#388) also in update_steps_parallel(), per group of vehicles, as update() does it single-threaded - physics.pipewake (pipe_wakes(), wake_cause::scndpipe) in staging's GetScndDVc(), where the main reservoir hose exchange went - hardware::log_gl_context() (#389) in after_window() of the GL 4.6 backend, init_ogl() being gone Taken back out of the auto-merge (renderers this branch removed): - shaders/vk14/tonemapping.glsl: #481's switch to ACES, applied there by rename detection - environment/skydome.cpp, simulation/simulationenvironment.cpp: #415, the sky of the legacy renderer - application/application.cpp: #384's fallback of an unknown gfxrenderer, which this branch had dropped Not carried from staging (renderer files removed here): - master #481 (571487612): old assets drawn as in 26.05 (metal diffuse, sun highlight tint, ACES, SUN_DIFFUSE_SCALE 2.5, untinted Diffuse, mat_colored base) and gfx.headlights.beamwidth. Made for the GL 3.3 shaders; the PBR shaders of shaders/ogl46 and vk14 (and their SPIR-V binaries) are the author's call - #437: the unique temporary file of the shader validator (Sonar S5443); gl46's validator still writes /tmp/shader* Unit tests: 1133 of 1137 cases pass. Four staging tests fail (derailment: a repaired vehicle is back on the rails; three pullee cases): the vehicle stands, and with physics.sleepheld (on by default here) its physics sleeps with the Fb / FStand of before. With physics.sleepheld off they pass. Left to the author.
288 lines
12 KiB
C++
288 lines
12 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <array>
|
|
#include <optional>
|
|
#include <utility>
|
|
|
|
#include "utilities/Classes.h"
|
|
#include "rendering/geometrybank.h"
|
|
#include "world/TrackUneven.h"
|
|
#include <glm/glm.hpp>
|
|
#include <memory>
|
|
#include <vector>
|
|
#include "world/Knots.h"
|
|
|
|
struct map_colored_paths {
|
|
std::vector<gfx::geometrybank_handle> switches;
|
|
std::vector<gfx::geometrybank_handle> occupied;
|
|
std::vector<gfx::geometrybank_handle> future;
|
|
std::vector<gfx::geometrybank_handle> highlighted;
|
|
};
|
|
|
|
struct loft_end {
|
|
double bend { 0.0 };
|
|
};
|
|
|
|
// a rail profile made over below its head into a lower section, as the wing rails of a frog of the section of the blades: its web, its
|
|
// foot inwards and outwards as many times as thick and wide, the top of the edges of its foot and the root of its web as many times as high
|
|
struct loft_low {
|
|
double web { 1.0 };
|
|
double inward { 1.0 };
|
|
double outward { 1.0 };
|
|
double edge { 1.0 };
|
|
double root { 1.0 };
|
|
};
|
|
|
|
struct loft_span {
|
|
int side { 1 };
|
|
float halfwidth { 0.f };
|
|
double texturelength { 1.0 };
|
|
double from { 0.0 };
|
|
double to { 0.0 };
|
|
knots::line offsets;
|
|
knots::line extents;
|
|
knots::line inner;
|
|
float lift { 0.f };
|
|
gfx::userdata_array *userdata { nullptr };
|
|
knots::line ramp;
|
|
double rampwidth { 0.0 };
|
|
bool walls { false };
|
|
float wallu { -1.f };
|
|
loft_end fromend;
|
|
loft_end toend;
|
|
knots::line drops;
|
|
glm::dvec2 head { 0.0 };
|
|
double rise { 0.0 }; // how far the foot of the profile is raised, the web below the head (head.x) shortened by as much
|
|
knots::line rises; // along the span, in place of rise where given
|
|
knots::line lows; // along the span, how much of the low section the profile is made over into below its head, 0 to 1
|
|
loft_low low; // what the profile is made over into along lows
|
|
};
|
|
|
|
struct segment_data {
|
|
// types
|
|
enum point {
|
|
start = 0,
|
|
control1,
|
|
control2,
|
|
end
|
|
};
|
|
// members
|
|
std::array<glm::dvec3, 4> points {};
|
|
std::array<float, 2> rolls {};
|
|
float radius {};
|
|
std::vector<segment_data> pieces; // consecutive parts of the path, which then is their approximation for older versions
|
|
// constructors
|
|
segment_data() = default;
|
|
// methods
|
|
void deserialize( cParser &Input, glm::dvec3 const &Offset );
|
|
void translate( glm::dvec3 const &Offset );
|
|
// maps the ends of the path and of its pieces with Point and their control vectors with Vector
|
|
template <typename Pointmap, typename Vectormap>
|
|
void transform( Pointmap const &Point, Vectormap const &Vector ) {
|
|
for( auto const index : { point::start, point::end } ) {
|
|
points[ index ] = Point( points[ index ] ); }
|
|
for( auto const index : { point::control1, point::control2 } ) {
|
|
points[ index ] = Vector( points[ index ] ); }
|
|
for( auto &piece : pieces ) {
|
|
piece.transform( Point, Vector ); } }
|
|
};
|
|
|
|
class TSegment
|
|
{ // aproksymacja toru (zwrotnica ma dwa takie, jeden z nich jest aktywny)
|
|
private:
|
|
glm::dvec3 Point1;
|
|
glm::dvec3 CPointOut;
|
|
glm::dvec3 CPointIn;
|
|
glm::dvec3 Point2;
|
|
float fRoll1 { 0.f };
|
|
float fRoll2 { 0.f }; // przechyłka na końcach
|
|
// how the path sits among the others
|
|
struct setting {
|
|
std::array<float, 2> designrolls { 0.f, 0.f }; // as entered; fRoll1 and fRoll2 can differ at a joint
|
|
bool uneven { false }; // see TrackUneven.h
|
|
bool buckled { false }; // see TrackBuckle.h
|
|
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;
|
|
};
|
|
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
|
|
double fStep = 0.0;
|
|
int iSegCount = 0; // ilość odcinków do rysowania krzywej
|
|
double fDirection = 0.0; // Ra: kąt prostego w planie; dla łuku kąt od Point1
|
|
double fStoop = 0.0; // Ra: kąt wzniesienia; dla łuku od Point1
|
|
glm::dvec3 vA;
|
|
glm::dvec3 vB;
|
|
glm::dvec3 vC; // współczynniki wielomianów trzeciego stopnia vD==Point1
|
|
TTrack *pOwner = nullptr; // wskaźnik na właściciela
|
|
std::vector<std::shared_ptr<TSegment>> m_pieces; // parts of a path made of several curves, parametrized by distance
|
|
std::vector<double> m_starts; // distance from Point1 to the start of each part
|
|
double m_dense { 0.0 };
|
|
// a switch makes the profiles of its rails and its bed at the mean of the rolls of its paths: lofted along a path, they're turned
|
|
// from it to the roll of the path there, so a switch on a cant ramp follows it; none for the other paths
|
|
std::optional<float> m_baked_roll;
|
|
|
|
glm::dvec3 GetFirstDerivative(double const fTime) const;
|
|
double RombergIntegral(double const fA, double const fB) const;
|
|
void InitTFromSInterpolateData();
|
|
double GetTFromS(double const s) const;
|
|
double FastGetTFromS(double const s) const;
|
|
glm::dvec3 RaInterpolate(double const t) const;
|
|
glm::dvec3 RaInterpolate0(double const t) const;
|
|
std::size_t piece_at(double const s) const;
|
|
// the vertex of a profile lofted at the point and across the path there, turned from the baked roll to the one of the path at the distance
|
|
void roll_vertex( gfx::basic_vertex &Vertex, glm::vec3 const &Position, glm::vec3 const &Parallel, double const Distance ) const;
|
|
|
|
// moves a lofted vertex with the unevenness of the track
|
|
void settle_vertex( gfx::basic_vertex &Vertex, glm::dvec3 const &Origin, glm::vec3 const &Position, glm::vec3 const &Parallel, double const Distance ) const;
|
|
// displacement of a point by the unevenness, at a distance along the path, and by the buckle of the track across it, along Across
|
|
// (none along a zero vector)
|
|
glm::dvec3 stray( glm::dvec3 const &Point, track_uneven::amounts const &Amount, double const Distance, glm::dvec3 const &Across ) const;
|
|
|
|
public:
|
|
bool bCurve = false;
|
|
|
|
explicit TSegment(TTrack *owner);
|
|
bool Init(glm::dvec3 NewPoint1, glm::dvec3 NewPoint2, double fNewStep, double fNewRoll1 = 0, double fNewRoll2 = 0);
|
|
bool Init(glm::dvec3 &NewPoint1, glm::dvec3 NewCPointOut, glm::dvec3 NewCPointIn, glm::dvec3 &NewPoint2, double fNewStep, double fNewRoll1 = 0, double fNewRoll2 = 0, bool bIsCurve = true);
|
|
bool InitChain(std::vector<std::shared_ptr<TSegment>> Pieces);
|
|
inline
|
|
std::size_t
|
|
PieceCount() const {
|
|
return m_pieces.size(); };
|
|
inline
|
|
double
|
|
PieceStart( std::size_t const Piece ) const {
|
|
return m_starts[ Piece ]; };
|
|
double
|
|
ComputeLength() const; // McZapkie-150503
|
|
// finds point on segment closest to specified point in 3d space. returns: point on segment as value in range 0-1
|
|
double
|
|
find_nearest_point( glm::dvec3 const &Point ) const;
|
|
inline
|
|
glm::dvec3
|
|
GetDirection1() const {
|
|
return bCurve ? CPointOut - Point1 : CPointOut; };
|
|
inline
|
|
glm::dvec3
|
|
GetDirection2() const {
|
|
return bCurve ? CPointIn - Point2 : CPointIn; };
|
|
glm::dvec3
|
|
GetDirection(double const fDistance) const;
|
|
inline
|
|
glm::dvec3
|
|
GetDirection() const {
|
|
return CPointOut; };
|
|
glm::dvec3
|
|
FastGetDirection(double const fDistance, double const fOffset) const;
|
|
/*
|
|
Math3D::vector3
|
|
GetPoint(double const fDistance) const;
|
|
*/
|
|
|
|
/// <summary>
|
|
/// ustalenie pozycji osi na torze, przechyłki, pochylenia i kierunku jazdy
|
|
/// </summary>
|
|
/// <param name="fDistance">Distance from p1</param>
|
|
/// <param name="position">Calculated position</param>
|
|
/// <param name="rotation">Calculated rotation</param>
|
|
void RaPositionGet(double const fDistance, glm::dvec3 &position, glm::vec3 &rotation) const;
|
|
// call before Init, it sets the density of the geometry
|
|
void
|
|
set_uneven( bool const Uneven, int const Path = 0 ) {
|
|
m_setting.uneven = Uneven;
|
|
m_setting.path = Path; }
|
|
// call before Init too
|
|
void
|
|
set_buckled( bool const Buckled ) {
|
|
m_setting.buckled = Buckled; }
|
|
// a point of the path and the unit vector across it in the plan, towards the right rail profile; zero for a path never made
|
|
void
|
|
plan_frame( double const Distance, glm::dvec3 &Point, glm::dvec3 &Across ) const;
|
|
float
|
|
design_roll( int const End ) const {
|
|
return m_setting.designrolls[ End ]; }
|
|
void
|
|
set_joint( int const End, std::optional<std::pair<glm::dvec3, glm::dvec3>> const &Joint, float const Roll ) {
|
|
m_setting.joints[ End ] = Joint;
|
|
( End == 0 ? fRoll1 : fRoll2 ) = Roll; }
|
|
// second derivative of the displacement along the path; times speed squared: acceleration of an axle
|
|
glm::dvec3
|
|
uneven_bend( double const Distance ) const;
|
|
// the curvature the buckle of the track adds to the path at the distance, 1/m, positive bending towards its right; averaged over Base
|
|
// around it, as a bogie or a body takes it
|
|
double
|
|
buckle_bend( double const Distance, double const Base = 0.0 ) const;
|
|
// the unit vector across the path at the distance, towards its right
|
|
glm::dvec3
|
|
across_at( double const Distance ) const;
|
|
glm::dvec3 FastGetPoint(double const t) const;
|
|
inline
|
|
glm::dvec3
|
|
FastGetPoint_0() const {
|
|
return Point1; };
|
|
inline
|
|
glm::dvec3
|
|
FastGetPoint_1() const {
|
|
return Point2; };
|
|
inline
|
|
float
|
|
GetRoll(double const Distance) const {
|
|
if( false == m_pieces.empty() ) {
|
|
auto const piece { piece_at( Distance ) };
|
|
return m_pieces[ piece ]->GetRoll( Distance - m_starts[ piece ] ); }
|
|
return std::lerp( fRoll1, fRoll2, static_cast<float>(Distance / fLength) ); }
|
|
inline
|
|
void
|
|
GetRolls(float &r1, float &r2) const {
|
|
// pobranie przechyłek (do generowania trójkątów)
|
|
r1 = fRoll1;
|
|
r2 = fRoll2; }
|
|
|
|
bool
|
|
RenderLoft( gfx::vertex_array &Output, glm::dvec3 const &Origin, gfx::vertex_array const &ShapePoints, bool const Transition, double fTextureLength, double Texturescale = 1.0, int iSkip = 0, int iEnd = 0, std::pair<float, float> fOffsetX = {0.f, 0.f}, glm::vec3 **p = nullptr, bool bRender = true );
|
|
// a transition profile lofted in Steps pieces of equal length, so two paths of different make-up line up piece by piece
|
|
bool
|
|
RenderLoftSteps( gfx::vertex_array &Output, glm::dvec3 const &Origin, gfx::vertex_array const &ShapePoints, double fTextureLength, int const Steps ) const;
|
|
// the profile lofted from distance From to To, moved outwards by Offsets and cut on its outer side to Extents beyond the gauge line, both as (distance, value) knots
|
|
bool
|
|
RenderLoftSpan( gfx::vertex_array &Output, glm::dvec3 const &Origin, gfx::vertex_array const &ShapePoints, loft_span const &Span ) const;
|
|
void
|
|
set_dense( double const Distance ) {
|
|
m_dense = Distance; }
|
|
void
|
|
set_baked_roll( std::optional<float> const Roll ) {
|
|
m_baked_roll = Roll; }
|
|
/*
|
|
void
|
|
Render();
|
|
*/
|
|
inline
|
|
double
|
|
GetLength() const {
|
|
return fLength; };
|
|
inline
|
|
int
|
|
RaSegCount() const {
|
|
return fTsBuffer.empty() ? 1 : iSegCount; };
|
|
|
|
void
|
|
render_lines(std::vector<gfx::basic_vertex> &out, float quality = 1.0f) const;
|
|
|
|
glm::vec3
|
|
get_nearest_point(const glm::dvec3 &point, float quality = 1.0f) const;
|
|
};
|
|
|
|
//---------------------------------------------------------------------------
|