mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-29 01:24:37 +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.
516 lines
16 KiB
C++
516 lines
16 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 <vector>
|
|
|
|
#include "utilities/Classes.h"
|
|
#include "model/material.h"
|
|
#include "model/vertex.h"
|
|
#include "rendering/geometrybank.h"
|
|
#include "../utilities/uuid.hpp"
|
|
|
|
struct lighting_data {
|
|
|
|
glm::vec4 diffuse { 0.8f, 0.8f, 0.8f, 1.0f };
|
|
glm::vec4 ambient { 0.2f, 0.2f, 0.2f, 1.0f };
|
|
glm::vec4 specular { 0.0f, 0.0f, 0.0f, 1.0f };
|
|
|
|
// stores content of the struct in provided output stream
|
|
void
|
|
serialize( std::ostream &Output ) const;
|
|
// restores content of the struct from provided input stream
|
|
void
|
|
deserialize( std::istream &Input );
|
|
};
|
|
|
|
inline
|
|
bool
|
|
operator==( lighting_data const &Left, lighting_data const &Right ) {
|
|
return Left.diffuse == Right.diffuse && Left.ambient == Right.ambient && Left.specular == Right.specular;
|
|
}
|
|
|
|
inline
|
|
bool
|
|
operator!=( lighting_data const &Left, lighting_data const &Right ) {
|
|
return !( Left == Right );
|
|
}
|
|
|
|
namespace scene {
|
|
|
|
struct bounding_area {
|
|
glm::dvec3 center; // mid point of the rectangle
|
|
float radius { -1.0f }; // radius of the bounding sphere
|
|
|
|
bounding_area() = default;
|
|
bounding_area( glm::dvec3 Center, float Radius ) :
|
|
center( Center ),
|
|
radius( Radius )
|
|
{}
|
|
// stores content of the struct in provided output stream
|
|
void
|
|
serialize( std::ostream &Output ) const;
|
|
// restores content of the struct from provided input stream.
|
|
void
|
|
deserialize( std::istream &Input, bool const Preserveradius = true );
|
|
};
|
|
|
|
//using group_handle = std::size_t;
|
|
|
|
struct node_data {
|
|
|
|
double range_min { 0.0 };
|
|
double range_max { std::numeric_limits<double>::max() };
|
|
std::string name;
|
|
std::string type;
|
|
layer_handle layer { null_handle }; // scenery layer the node is defined in, if any
|
|
instance_handle instance { 0 }; // include of an *.inc template which defines the node, if it isn't defined directly by a scenery layer file
|
|
};
|
|
|
|
// holds unique piece of geometry, covered with single material
|
|
class shape_node
|
|
{
|
|
|
|
friend class basic_region; // region might want to modify node content when it's being inserted
|
|
friend class terrain_file; // binary terrain files hold complete content of the nodes
|
|
|
|
public:
|
|
// types
|
|
struct shapenode_data {
|
|
// members:
|
|
// placement and visibility
|
|
scene::bounding_area area; // bounding area, in world coordinates
|
|
double rangesquared_min { 0.0 }; // visibility range, min
|
|
double rangesquared_max { 0.0 }; // visibility range, max
|
|
bool visible { true }; // visibility flag
|
|
// material data
|
|
bool translucent { false }; // whether opaque or translucent
|
|
material_handle material { null_handle };
|
|
lighting_data lighting;
|
|
// geometry data
|
|
glm::dvec3 origin; // world position of the relative coordinate system origin
|
|
gfx::geometry_handle geometry { 0, 0 }; // relative origin-centered chunk of geometry held by gfx renderer
|
|
std::vector<world_vertex> vertices; // world space source data of the geometry
|
|
gfx::userdata_array userdata;
|
|
// terrain file the shape comes from, see scene::terrain_file::reference_of(); 0: none, or not known (only the editor asks)
|
|
std::uint16_t terrainfile { 0 };
|
|
// drawn pulled towards the camera in the depth buffer, over the surface it lies on: the photos of the editor laid on the
|
|
// terrain. not kept by serialize()
|
|
bool decal { false };
|
|
// methods:
|
|
// sends content of the struct to provided stream
|
|
void
|
|
serialize( std::ostream &Output ) const;
|
|
// restores content of the struct from provided input stream
|
|
void
|
|
deserialize( std::istream &Input );
|
|
};
|
|
|
|
// methods
|
|
// sends content of the class to provided stream
|
|
void
|
|
serialize( std::ostream &Output ) const;
|
|
// restores content of the node from provided input stream
|
|
shape_node &
|
|
deserialize( std::istream &Input );
|
|
// restores content of the node from provided input stream
|
|
shape_node &
|
|
import_from( cParser &Input, scene::node_data const &Nodedata );
|
|
// imports data from provided submodel
|
|
shape_node &
|
|
convert( TSubModel const *Submodel );
|
|
// builds an opaque, always-visible shape from a world-space GL_TRIANGLES vertex list, stored
|
|
// relative to Origin. used by the editor's terrain to own editable geometry it can re-upload.
|
|
shape_node &
|
|
make_terrain( material_handle const Material, std::vector<world_vertex> Vertices, glm::dvec3 const Origin );
|
|
// see shapenode_data::decal
|
|
void
|
|
decal( bool const Decal ) { m_data.decal = Decal; }
|
|
// adds content of provided node to already enclosed geometry. returns: true if merge could be performed
|
|
bool
|
|
merge( shape_node &Shape );
|
|
// generates renderable version of held non-instanced geometry in specified geometry bank
|
|
void
|
|
create_geometry( gfx::geometrybank_handle const &Bank );
|
|
// calculates shape's bounding radius
|
|
void
|
|
compute_radius();
|
|
// invalidates shape's bounding radius
|
|
void
|
|
invalidate_radius();
|
|
// set visibility
|
|
void
|
|
visible( bool State );
|
|
// set origin point
|
|
void
|
|
origin( glm::dvec3 Origin );
|
|
// replaces the renderable geometry handle (used by the editor when it re-uploads terrain geometry)
|
|
void
|
|
geometry( gfx::geometry_handle const &Handle );
|
|
// set lighting (used by generated geometry painted with plain colour)
|
|
void
|
|
lighting( lighting_data const &Lighting );
|
|
// sets whether the shape is drawn with the translucent geometry (used by generated geometry)
|
|
void
|
|
translucent( bool const Translucent );
|
|
// notes the terrain file the shape comes from
|
|
void
|
|
source_file( std::uint16_t const Reference ) { m_data.terrainfile = Reference; }
|
|
// data access
|
|
shapenode_data const &
|
|
data() const;
|
|
// get bounding radius
|
|
// NOTE: use this method instead of direct access to the data member, due to lazy radius evaluation
|
|
float radius();
|
|
|
|
private:
|
|
// members
|
|
std::string m_name;
|
|
shapenode_data m_data;
|
|
};
|
|
|
|
// set visibility
|
|
inline
|
|
void
|
|
shape_node::visible( bool State ) {
|
|
m_data.visible = State;
|
|
}
|
|
// set origin point
|
|
inline
|
|
void
|
|
shape_node::origin( glm::dvec3 Origin ) {
|
|
m_data.origin = Origin;
|
|
}
|
|
// replaces the renderable geometry handle
|
|
inline
|
|
void
|
|
shape_node::geometry( gfx::geometry_handle const &Handle ) {
|
|
m_data.geometry = Handle;
|
|
}
|
|
// set lighting
|
|
inline
|
|
void
|
|
shape_node::lighting( lighting_data const &Lighting ) {
|
|
m_data.lighting = Lighting;
|
|
}
|
|
inline
|
|
void
|
|
shape_node::translucent( bool const Translucent ) {
|
|
m_data.translucent = Translucent;
|
|
}
|
|
// data access
|
|
inline
|
|
shape_node::shapenode_data const &
|
|
shape_node::data() const {
|
|
return m_data;
|
|
}
|
|
|
|
|
|
|
|
// holds a group of untextured lines
|
|
class lines_node
|
|
{
|
|
friend class basic_region; // region might want to modify node content when it's being inserted
|
|
|
|
public:
|
|
// types
|
|
struct linesnode_data {
|
|
// members:
|
|
// placement and visibility
|
|
scene::bounding_area area; // bounding area, in world coordinates
|
|
double rangesquared_min { 0.0 }; // visibility range, min
|
|
double rangesquared_max { 0.0 }; // visibility range, max
|
|
bool visible { true }; // visibility flag
|
|
// material data
|
|
float line_width { 1.f }; // thickness of stored lines
|
|
lighting_data lighting;
|
|
// geometry data
|
|
glm::dvec3 origin; // world position of the relative coordinate system origin
|
|
gfx::geometry_handle geometry { 0, 0 }; // relative origin-centered chunk of geometry held by gfx renderer
|
|
std::vector<world_vertex> vertices; // world space source data of the geometry
|
|
gfx::userdata_array userdata;
|
|
// methods:
|
|
// sends content of the struct to provided stream
|
|
void
|
|
serialize( std::ostream &Output ) const;
|
|
// restores content of the struct from provided input stream
|
|
void
|
|
deserialize( std::istream &Input );
|
|
};
|
|
|
|
// methods
|
|
// sends content of the class to provided stream
|
|
void
|
|
serialize( std::ostream &Output ) const;
|
|
// restores content of the node from provided input stream
|
|
lines_node &
|
|
deserialize( std::istream &Input );
|
|
// restores content of the node from provided input stream
|
|
lines_node &
|
|
import_from( cParser &Input, scene::node_data const &Nodedata );
|
|
// adds content of provided node to already enclosed geometry. returns: true if merge could be performed
|
|
bool
|
|
merge( lines_node &Lines );
|
|
// generates renderable version of held non-instanced geometry in specified geometry bank
|
|
void
|
|
create_geometry( gfx::geometrybank_handle const &Bank );
|
|
// calculates shape's bounding radius
|
|
void
|
|
compute_radius();
|
|
// set visibility
|
|
void
|
|
visible( bool State );
|
|
// set origin point
|
|
void
|
|
origin( glm::dvec3 Origin );
|
|
// data access
|
|
linesnode_data const &
|
|
data() const;
|
|
|
|
private:
|
|
// members
|
|
std::string m_name;
|
|
linesnode_data m_data;
|
|
};
|
|
|
|
// set visibility
|
|
inline
|
|
void
|
|
lines_node::visible( bool State ) {
|
|
m_data.visible = State;
|
|
}
|
|
// set origin point
|
|
inline
|
|
void
|
|
lines_node::origin( glm::dvec3 Origin ) {
|
|
m_data.origin = Origin;
|
|
}
|
|
// data access
|
|
inline
|
|
lines_node::linesnode_data const &
|
|
lines_node::data() const {
|
|
return m_data;
|
|
}
|
|
|
|
|
|
/*
|
|
// holds geometry for specific piece of track/road/waterway
|
|
class path_node {
|
|
|
|
friend class basic_region; // region might want to modify node content when it's being inserted
|
|
|
|
public:
|
|
// types
|
|
// TODO: enable after track class refactoring
|
|
struct pathnode_data {
|
|
// placement and visibility
|
|
bounding_area area; // bounding area, in world coordinates
|
|
bool visible { true }; // visibility flag
|
|
// material data
|
|
material_handle material_1 { 0 };
|
|
material_handle material_2 { 0 };
|
|
lighting_data lighting;
|
|
TEnvironmentType environment { e_flat };
|
|
// geometry data
|
|
std::vector<world_vertex> vertices; // world space source data of the geometry
|
|
glm::dvec3 origin; // world position of the relative coordinate system origin
|
|
using geometryhandle_sequence = std::vector<geometry_handle>;
|
|
geometryhandle_sequence geometry_1; // geometry chunks textured with texture 1
|
|
geometryhandle_sequence geometry_2; // geometry chunks textured with texture 2
|
|
};
|
|
// methods
|
|
// restores content of the node from provded input stream
|
|
// TODO: implement
|
|
path_node &
|
|
deserialize( cParser &Input, node_data const &Nodedata );
|
|
// binds specified track to the node
|
|
// TODO: remove after track class refactoring
|
|
void
|
|
path( TTrack *Path ) {
|
|
m_path = Path; }
|
|
TTrack *
|
|
path() {
|
|
return m_path; }
|
|
|
|
private:
|
|
// members
|
|
|
|
// // TODO: enable after track class refactoring
|
|
// pathnode_data m_data;
|
|
|
|
TTrack * m_path;
|
|
};
|
|
*/
|
|
|
|
|
|
|
|
// changes whenever a node is shown or hidden, or a model instance stops being drawn along with other instances of its
|
|
// model. copies of these states (instance records of the renderer) are made anew once it changes
|
|
inline unsigned int node_state_version { 1 };
|
|
|
|
// base interface for nodes which can be actvated in scenario editor
|
|
class basic_node {
|
|
|
|
public:
|
|
// constructor
|
|
explicit basic_node( scene::node_data const &Nodedata );
|
|
// destructor
|
|
virtual ~basic_node() = default;
|
|
// methods
|
|
// sends content of the class to provided stream
|
|
void
|
|
serialize( std::ostream &Output ) const;
|
|
// restores content of the class from provided stream
|
|
void
|
|
deserialize( std::istream &Input );
|
|
// sends basic content of the class in legacy (text) format to provided stream
|
|
void
|
|
export_as_text( std::ostream &Output ) const;
|
|
void
|
|
export_as_text( std::string &Output ) const;
|
|
std::string const &
|
|
name() const;
|
|
virtual std::string tooltip() const;
|
|
void
|
|
location( glm::dvec3 const Location );
|
|
glm::dvec3 const &
|
|
location() const;
|
|
glm::dvec3 &
|
|
location();
|
|
float const &
|
|
radius();
|
|
// the radius as worked out already, or worked out anew and not kept
|
|
float
|
|
radius() const;
|
|
void
|
|
visible( bool const Visible );
|
|
bool
|
|
visible() const;
|
|
void
|
|
group( scene::group_handle Group );
|
|
scene::group_handle
|
|
group() const;
|
|
void
|
|
layer( scene::layer_handle Layer );
|
|
scene::layer_handle
|
|
layer() const;
|
|
// true if the node is defined by an *.inc template
|
|
bool
|
|
from_template() const { return m_instance != 0; }
|
|
void
|
|
mark_dirty() { m_dirty = true; }
|
|
bool
|
|
dirty() const { return m_dirty; }
|
|
|
|
std::string node_type;
|
|
|
|
public:
|
|
// members
|
|
scene::group_handle m_group { null_handle }; // group this node belongs to, if any
|
|
scene::bounding_area m_area;
|
|
double m_rangesquaredmin { 0.0 }; // visibility range, min
|
|
double m_rangesquaredmax { 0.0 }; // visibility range, max
|
|
bool m_visible { true }; // visibility flag
|
|
std::string m_name;
|
|
bool m_dirty { false };
|
|
bool m_layerhidden { false }; // the node was visible until the editor hid its scenery layer, or the include which defines it
|
|
bool m_preview { false }; // the node was made by the editor to show an include it placed or changed, and is replaced when the include changes
|
|
bool m_catenary { false }; // a part the catenary assembled (world/catenary_scene.cpp): it's changed by the catenary tool, not edited as a node
|
|
scene::layer_handle m_layer { null_handle }; // scenery layer this node belongs to, if any
|
|
// include of an *.inc template which defines the node; 0 if the node is defined directly by a scenery layer file.
|
|
// such nodes can't be rewritten one by one on scenery save. set only for scenery opened for editing
|
|
scene::instance_handle m_instance { 0 };
|
|
UID uuid;
|
|
|
|
private:
|
|
// methods
|
|
// radius() subclass details, calculates node's bounding radius
|
|
virtual float radius_() const;
|
|
// serialize() subclass details, sends content of the subclass to provided stream
|
|
virtual void serialize_( std::ostream &Output ) const = 0;
|
|
// deserialize() subclass details, restores content of the subclass from provided stream
|
|
virtual void deserialize_( std::istream &Input ) = 0;
|
|
// export() subclass details, sends basic content of the class in legacy (text) format to provided stream
|
|
virtual void export_as_text_( std::ostream &Output ) const = 0;
|
|
};
|
|
|
|
inline
|
|
std::string const &
|
|
basic_node::name() const {
|
|
return m_name;
|
|
}
|
|
|
|
// Returns the tooltip of this Node when hovered with the mouse cursor.
|
|
inline
|
|
std::string basic_node::tooltip() const
|
|
{
|
|
return m_name;
|
|
}
|
|
inline
|
|
void
|
|
basic_node::location( glm::dvec3 const Location ) {
|
|
m_area.center = Location;
|
|
}
|
|
|
|
inline
|
|
glm::dvec3 const &
|
|
basic_node::location() const {
|
|
return m_area.center;
|
|
}
|
|
|
|
inline
|
|
glm::dvec3 &
|
|
basic_node::location() {
|
|
return m_area.center;
|
|
}
|
|
|
|
inline
|
|
void
|
|
basic_node::visible( bool const Visible ) {
|
|
if( Visible != m_visible ) {
|
|
++node_state_version;
|
|
}
|
|
m_visible = Visible;
|
|
}
|
|
|
|
inline
|
|
bool
|
|
basic_node::visible() const {
|
|
return m_visible;
|
|
}
|
|
|
|
inline
|
|
void
|
|
basic_node::group( scene::group_handle Group ) {
|
|
m_group = Group;
|
|
}
|
|
|
|
inline
|
|
scene::group_handle
|
|
basic_node::group() const {
|
|
return m_group;
|
|
}
|
|
|
|
inline
|
|
void
|
|
basic_node::layer( scene::layer_handle Layer ) {
|
|
m_layer = Layer;
|
|
}
|
|
|
|
inline
|
|
scene::layer_handle
|
|
basic_node::layer() const {
|
|
return m_layer;
|
|
}
|
|
|
|
} // scene
|
|
|
|
//---------------------------------------------------------------------------
|