18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-29 17:06:36 +01:00
Files
maszyna/world/RoadPoint.h
jerrrrycho 3eb2fdf462 Merge staging into feat/gl46-migration
origin/staging 7ac2472c3 into feat/gl46-migration db26a33ed, so that #468
merges into staging. Merge base 037158104. Staging carries master up to
571487612 (squashed in #514); this branch had merged master up to 7c12b83ba.

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's f4f8c75e4 (road orders measured along the lane) and 8fbf05674 (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.
2026-11-27 05:26:13 +01:00

238 lines
9.6 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 <map>
#include <memory>
#include <string>
#include <vector>
#include <glm/glm.hpp>
#include "utilities/Classes.h"
#include "utilities/Names.h"
#include "scene/scenenode.h"
#include "world/Road.h"
class TDynamicObject;
class basic_event;
// a place on a road where something happens to the traffic, or is painted for it:
// - a level crossing: vehicles are stopped ahead of the rails for as long as a train is near, or the scenery says so,
// - a point where vehicles appear, drawn from a set made ready while the scenery is loaded,
// - a point where vehicles are taken away. the ones which came from a point of the previous kind go back to its set,
// - a pedestrian crossing: stripes painted across the road.
// scenery entries:
// node <max> <min> <name> crossing <position> [clearance <m>] [warning <m>] [stoplines <yes|no>] [memcell <name>] endcrossing
// node <max> <min> <name> spawn <position> [interval <s>] [variation <0..1>] [velocity <km/h>] [count <n>]
// [node <max> <min> <name> dynamic <folder> <skin> <type> <path> <offset> <driver> <velocity> <load> [<load type>] enddynamic]... endspawn
// node <max> <min> <name> despawn <position> [radius <m>] enddespawn
// node <max> <min> <name> crosswalk <position> [length <m>] endcrosswalk
// the vehicles of a spawn point are given the way vehicles are put in a scenery; where they're put and how they're driven
// is up to the point, so the path, the offset, the driver and the velocity of these entries don't matter. the listed vehicles
// are what the point draws from to have <count> vehicles of its own on the roads; one which gets stuck is taken off the road.
// a level crossing is told by the scenery through a memory cell: the one named in its entry, or "<name of the crossing>:block",
// made if the scenery doesn't have it. its first value above zero closes the entry onto the crossing, below zero keeps it open
// whatever comes by the rails, and zero leaves it to the trains. the vehicles past the stops, on the crossing or leaving it, drive on.
// the second value is set by the crossing: 1 while its entry is closed, 0 while it's open
class roadpoint_node : public scene::basic_node
{
public:
// types
enum class kind_type
{
crossing,
spawn,
despawn,
crosswalk
};
struct vehicle_data
{
std::string folder; // where the vehicle is defined, in the folder of the vehicles
std::string skin;
std::string type; // name of its definition files
int load{0};
std::string loadtype;
bool operator==(vehicle_data const &Other) const
{
return folder == Other.folder && skin == Other.skin && type == Other.type && load == Other.load && loadtype == Other.loadtype;
}
};
struct state
{
kind_type kind{kind_type::crossing};
glm::dvec3 position{0.0};
// level crossing
float clearance{6.f}; // distance along the road from the point to the places the vehicles stop at
float warning{800.f}; // how far along the rails a train coming closes the crossing
bool stoplines{true}; // lines are painted where the vehicles stop
std::string memcell; // name of the memory cell the scenery tells the crossing by; empty: the one named after the crossing
// point where vehicles appear
float interval{20.f}; // seconds from a vehicle to the next
float variation{0.5f}; // part of the interval which is drawn at random
float velocity{50.f}; // speed the vehicles appear with, and are told to keep, km/h
int count{6}; // how many vehicles of the point can be on the roads at a time. that many are made ready, drawn from the listed ones
std::vector<vehicle_data> vehicles;
// point where vehicles are taken away
float radius{2.f}; // vehicles on lanes this close to the point are taken
// pedestrian crossing
float length{4.f}; // how much of the road the stripes take along it
// brings the content to a usable form
void normalize();
};
// place the vehicles of a lane stop at while a crossing is closed
struct stop_data
{
TTrack *track{nullptr}; // the lane it's on
glm::dvec3 position{0.0};
glm::dvec3 direction{0.0, 0.0, 1.0}; // the way the lane goes there
float width{3.5f}; // of the lane
};
// constructors
explicit roadpoint_node(scene::node_data const &Nodedata);
// methods
// restores content of the node from provided input stream; reads up to and including the closing statement
void import_from(cParser &Input, glm::dvec3 const &Offset);
state const &definition() const
{
return m_state;
}
// replaces what the node knows about itself. what it's tied to stays, it's up to the caller to bind it again.
// a spawn point given another set of vehicles makes them anew; the ones it had stay on the road until they're taken away
void define(state const &State);
// scenery keyword for specified kind of point, and the statement closing its entry
static std::string keyword(kind_type const Kind);
static bool is_keyword(std::string const &Type);
// reads vehicles out of a text. each is given the way vehicles are put in a scenery, or, if there's no such entry
// in the text, as "<folder> <skin> <type> [<load> <load type>]" on a line of its own
static std::vector<vehicle_data> parse_vehicles(std::string const &Text);
// ties the point to the lanes and the rails as they are at the moment, or lets go of them
void bind();
void unbind();
// makes the vehicles of a spawn point, once. it loads their models, which takes a while
void prepare();
// to be called with each step of the simulation
void update(double const Deltatime);
// state for display
bool closed() const
{
return m_closed;
}
std::vector<stop_data> const &stops() const
{
return m_stops;
}
std::vector<TTrack *> const &lanes() const
{
return m_lanes;
}
std::size_t rails() const
{
return m_rails.size();
}
// memory cell the level crossing is told by, nullptr if there's none
TMemCell *memcell() const
{
return m_memcell;
}
// name of that cell: the one the entry gives, or the one made of the name of the crossing; empty if neither is there
std::string memcell_name() const;
// vehicles made for a spawn point, and how many of them wait for their turn
std::size_t vehicles() const
{
return m_pool.size();
}
std::size_t waiting() const;
// true if specified vehicle stands in the line of vehicles held by the crossing, which is closed
bool holds(TDynamicObject const &Vehicle) const;
// generates geometry of the stop lines
std::vector<scene::shape_node> create_shapes() const;
// puts geometry of the point in the scene, or takes it back
void show();
void hide();
bool shown() const
{
return m_shapes.shown();
}
// members
bool m_editorremoved{false}; // removed in the editor; kept around so the removal can be undone
private:
// types
struct pooled_vehicle
{
TDynamicObject *vehicle{nullptr};
double velocity{0.0}; // what its speed was when it was made, to be given back each time it's put on the road
double standing{0.0}; // how long it's been standing still on the road
};
// methods
float radius_() const override;
void serialize_(std::ostream &Output) const override;
void deserialize_(std::istream &Input) override;
void export_as_text_(std::ostream &Output) const override;
void bind_crossing();
void bind_memcell();
void update_crossing(double const Deltatime);
void update_spawn(double const Deltatime);
void update_despawn();
void close(bool const Closed);
// members
state m_state;
bool m_bound{false};
// level crossing
std::vector<stop_data> m_stops;
std::vector<basic_event *> m_events; // orders for the drivers, one for each stop. these are never freed, as a driver can hold on to one
std::vector<TTrack *> m_rails; // rails a train closes the crossing from
std::vector<TTrack *> m_queue; // lanes the vehicles held by the crossing wait on
std::map<TDynamicObject const *, double> m_seen; // rail vehicles near, with how far each was the last time
bool m_closed{false};
double m_hold{0.0}; // time left for the crossing to stay closed after the last train was seen
TMemCell *m_memcell{nullptr}; // what the scenery tells the crossing by
double m_scan{0.0}; // time left to the next look at the rails
// spawn and despawn
std::vector<TTrack *> m_lanes; // spawn: the lane the vehicles are put on. despawn: lanes the vehicles are taken from
double m_offset{0.0}; // spawn: distance of the point from the start of that lane
std::vector<pooled_vehicle> m_pool;
bool m_prepared{false};
int m_made{0}; // number of vehicles made so far, for their names
double m_timer{0.0}; // time left to the next vehicle
// pedestrian crossing: the road at the point
bool m_onroad{false};
glm::dvec3 m_along{0.0, 0.0, 1.0}; // the way the road goes
double m_halfwidth{0.0}; // of the road
owned_shapes m_shapes;
};
// collection of the road points present in the scene
class roadpoint_table : public basic_table<roadpoint_node>
{
public:
// legacy style initialization, to be performed when the lanes of the roads are tied together
void InitRoadpoints();
// lets go of the lanes and the rails, ahead of a change of the roads, and ties all points anew when it's done
void unbind();
void bind();
// puts geometry of the points in the scene
void create_geometry();
// to be called with each step of the simulation
void update(double const Deltatime);
// true if specified vehicle stands in the line of vehicles held by a closed level crossing
bool holds(TDynamicObject const &Vehicle) const;
private:
bool m_geometry{false}; // the scene is ready to take geometry of the points
};
//---------------------------------------------------------------------------