From ba44b0c0d5a1d4476680960d95bbe070c3eca38b Mon Sep 17 00:00:00 2001
From: pwarszawski
Date: Sat, 14 Nov 2026 14:30:51 +0100
Subject: [PATCH 001/174] Draw the glare of a FreeSpotLight after its point
The glare of a light point is drawn without the depth test, conditioned
on the occlusion query of the point. That query was issued only after
the glare and is kept on the TSubModel, which every instance of a model
shares, so the glare of one lamp used what the query saw for whichever
instance drew that submodel last (earlier in the frame or in the last
frame): glares showed through walls and blinked while the camera moved.
The point (with its query) is now drawn first and the glare after it,
so the conditional render of the opengl renderer uses the query of this
very point of this instance in this frame. The glare is drawn only when
the point was, which already held, as both need the viewer inside the
visibility cone. The vulkan renderer keeps using the results of the
last frame.
---
rendering/common/scenewalk.cpp | 83 +++++++++++++++++-----------------
rendering/common/scenewalk.h | 3 +-
2 files changed, 43 insertions(+), 43 deletions(-)
diff --git a/rendering/common/scenewalk.cpp b/rendering/common/scenewalk.cpp
index 63aa3ce47..ced5318af 100644
--- a/rendering/common/scenewalk.cpp
+++ b/rendering/common/scenewalk.cpp
@@ -3218,48 +3218,8 @@ void scene_walk::Render_Alpha(TSubModel *Submodel)
// a point light (FalloffAngle 360) is seen all around
auto const pointlight{Submodel->fCosFalloffAngle <= -1.f};
- if (Global.fLuminance < Submodel->fLight || Global.Overcast > 1.0f)
- {
- if (pointlight || (Submodel->fCosViewAngle > Submodel->fCosFalloffAngle))
- {
- // only bother if the viewer is inside the visibility cone
- // luminosity at night is at level of ~0.1, so the overall resulting transparency in clear conditions is ~0.5 at full 'brightness'
- auto glarelevel{std::clamp(std::max(0.6f - Global.fLuminance, // reduce the glare in bright daylight
- Global.Overcast - 1.f), // ensure some glare in rainy/foggy conditions
- 0.f, 1.f)};
- // view angle attenuation
- float const anglefactor{pointlight ? 1.f : std::clamp((Submodel->fCosViewAngle - Submodel->fCosFalloffAngle) / (Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle), 0.f, 1.f)};
-
- glarelevel *= anglefactor;
-
- if (glarelevel > 0.0f)
- {
- walk_glare(true);
-
- ::glPushMatrix();
- ::glLoadIdentity(); // macierz jedynkowa
- ::glTranslatef(lightcenter.x, lightcenter.y, lightcenter.z); // początek układu zostaje bez zmian
- ::glRotated(std::atan2(lightcenter.x, lightcenter.z) * 180.0 / M_PI, 0.0, 1.0, 0.0); // jedynie obracamy w pionie o kąt
-
- auto const lightcolor = glm::vec3(Submodel->DiffuseOverride.r < 0.f ? // -1 indicates no override
- Submodel->f4Diffuse :
- Submodel->DiffuseOverride);
-
- walk_program( walk_shader::billboard );
- walk_texture(0, m_glaretexture);
- model_ubs.param[0] = glm::vec4(glm::vec3(lightcolor), Submodel->fVisible * glarelevel);
-
- // main draw call
- // drawn where the light itself was seen in the last frame (an occlusion query of the opengl renderer)
- walk_glare_draw(Submodel, m_billboardgeometry);
-
- walk_glare(false);
-
- ::glPopMatrix();
- }
- }
- }
-
+ // the glare is drawn after the point, where the occlusion query of this very point (of this instance, in this frame) saw it
+ auto pointdrawn{false};
if (pointlight || (Submodel->fCosViewAngle > Submodel->fCosFalloffAngle))
{
// kąt większy niż maksymalny stożek swiatła
@@ -3316,11 +3276,50 @@ void scene_walk::Render_Alpha(TSubModel *Submodel)
walk_draw(Submodel->m_geometry.handle);
walk_light_query(Submodel, false);
+ pointdrawn = true;
// post-draw reset
model_ubs.emission = 0.0f;
model_ubs.fog_density = 1.0f / m_fogrange;
+ ::glPopMatrix();
+ }
+ }
+ // the point is drawn only inside its visibility cone, so the glare is too
+ if (pointdrawn && (Global.fLuminance < Submodel->fLight || Global.Overcast > 1.0f))
+ {
+ // luminosity at night is at level of ~0.1, so the overall resulting transparency in clear conditions is ~0.5 at full 'brightness'
+ auto glarelevel{std::clamp(std::max(0.6f - Global.fLuminance, // reduce the glare in bright daylight
+ Global.Overcast - 1.f), // ensure some glare in rainy/foggy conditions
+ 0.f, 1.f)};
+ // view angle attenuation
+ float const anglefactor{pointlight ? 1.f : std::clamp((Submodel->fCosViewAngle - Submodel->fCosFalloffAngle) / (Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle), 0.f, 1.f)};
+
+ glarelevel *= anglefactor;
+
+ if (glarelevel > 0.0f)
+ {
+ walk_glare(true);
+
+ ::glPushMatrix();
+ ::glLoadIdentity(); // macierz jedynkowa
+ ::glTranslatef(lightcenter.x, lightcenter.y, lightcenter.z); // początek układu zostaje bez zmian
+ ::glRotated(std::atan2(lightcenter.x, lightcenter.z) * 180.0 / M_PI, 0.0, 1.0, 0.0); // jedynie obracamy w pionie o kąt
+
+ auto const lightcolor = glm::vec3(Submodel->DiffuseOverride.r < 0.f ? // -1 indicates no override
+ Submodel->f4Diffuse :
+ Submodel->DiffuseOverride);
+
+ walk_program( walk_shader::billboard );
+ walk_texture(0, m_glaretexture);
+ model_ubs.param[0] = glm::vec4(glm::vec3(lightcolor), Submodel->fVisible * glarelevel);
+
+ // main draw call
+ // drawn where the point of the light was seen just above (an occlusion query of the opengl renderer)
+ walk_glare_draw(Submodel, m_billboardgeometry);
+
+ walk_glare(false);
+
::glPopMatrix();
}
}
diff --git a/rendering/common/scenewalk.h b/rendering/common/scenewalk.h
index 91a708c8d..ac22f7d99 100644
--- a/rendering/common/scenewalk.h
+++ b/rendering/common/scenewalk.h
@@ -266,7 +266,8 @@ class scene_walk
virtual void walk_timbers_expand(std::vector const &Origins, std::vector const &Ranges) {}
virtual void walk_cull_face(bool const Enabled) = 0;
// the glare of a lamp: drawn without the depth test, added to what is there; drawn only where the point of the light was
- // seen (walk_light_query() of the last frame, when the backend has it)
+ // seen (walk_light_query() of this point drawn just before it, when the backend has it: the opengl renderer uses
+ // the query at once, the vulkan renderer the result of the last frame)
virtual void walk_glare(bool const Enabled) = 0;
virtual void walk_glare_draw(TSubModel *Submodel, gfx::geometry_handle const &Geometry) = 0;
virtual void walk_light_query(TSubModel *Submodel, bool const Begin) = 0;
From 2dd53bc97beae51ec8abf8475492a8d7f7f925c4 Mon Sep 17 00:00:00 2001
From: pwarszawski
Date: Sat, 14 Nov 2026 17:46:40 +0100
Subject: [PATCH 002/174] Make the glare of a FreeSpotLight as bright as the
part of its point seen
The glare was drawn whole or not at all, depending on whether any sample
of the light point passed the depth test. The point is a few pixels
wide, so where it sits at the edge of something in front of it (the
hood of the lamp, a mast, a wire) the large glare switched on and off
as the camera moved and the signal seemed to flash.
The opengl renderer now counts the samples of the point which are seen
and, drawing the point once more without the depth test and without
colour, all of its samples. The gpu writes both counts into a small
storage buffer (GLARE_SSBO_BINDING) and billboard.frag scales the glare
by their ratio, so a partly hidden lamp gets a fainter glare instead
of a flashing one. The conditional render still leaves out the glare
of a point not seen at all. The vulkan renderer is unchanged.
---
gl/glsl_common.cpp | 1 +
gl/ubo.h | 4 +++
rendering/common/scenewalk.cpp | 1 +
rendering/common/scenewalk.h | 6 ++++-
rendering/opengl46/opengl46renderer.cpp | 35 ++++++++++++++++++++++++-
rendering/opengl46/opengl46renderer.h | 8 ++++++
shaders/ogl46/billboard.frag | 12 +++++++++
shaders/ogl46/common.glsl | 1 +
8 files changed, 66 insertions(+), 2 deletions(-)
diff --git a/gl/glsl_common.cpp b/gl/glsl_common.cpp
index f6f3df06d..9a5c9a895 100644
--- a/gl/glsl_common.cpp
+++ b/gl/glsl_common.cpp
@@ -110,6 +110,7 @@ void gl::glsl_common_setup()
"#define SKY_OCCLUSION_HEIGHT_TEX " + std::to_string(SKY_OCCLUSION_HEIGHT_TEX) + "\n" +
"#define SKY_OCCLUSION_TEX " + std::to_string(SKY_OCCLUSION_TEX) + "\n" +
"#define CAB_PROBE_SSBO_BINDING " + std::to_string(CAB_PROBE_SSBO_BINDING) + "\n" +
+ "#define GLARE_SSBO_BINDING " + std::to_string(GLARE_SSBO_BINDING) + "\n" +
"#define CAB_PROBE_SH_SIZE " + std::to_string(CAB_PROBE_SH_SIZE) + "\n" +
"#define CAB_PROBE_SH_GROUP_SIZE " + std::to_string(CAB_PROBE_SH_GROUP_SIZE) + "\n" +
"#define WEATHER_UBO_BINDING " + std::to_string(WEATHER_UBO_BINDING) + "\n" +
diff --git a/gl/ubo.h b/gl/ubo.h
index c933cf523..83a6ac71d 100644
--- a/gl/ubo.h
+++ b/gl/ubo.h
@@ -446,6 +446,10 @@ namespace gl
};
// binding point of the opengl renderer, bound with the colour passes
const GLuint CAB_PROBE_SSBO_BINDING = 17;
+ // layout std430: the samples of the point of a lamp its occlusion queries counted, written there by the gpu (GLSL: glare_ssbo,
+ // read by billboard.frag): seen, which passed the depth test, and all, drawn without it. binding point of the opengl renderer,
+ // bound with the glare of a lamp
+ const GLuint GLARE_SSBO_BINDING = 18;
// the face of the level of the probe the spherical harmonics are taken from, at most, and the work group of cabprobe_sh.comp
const size_t CAB_PROBE_SH_SIZE = 16;
// the face of the level of the probe CAB_PROBE_MASK_TEX is a copy of, at most
diff --git a/rendering/common/scenewalk.cpp b/rendering/common/scenewalk.cpp
index ced5318af..d75bb40ca 100644
--- a/rendering/common/scenewalk.cpp
+++ b/rendering/common/scenewalk.cpp
@@ -3276,6 +3276,7 @@ void scene_walk::Render_Alpha(TSubModel *Submodel)
walk_draw(Submodel->m_geometry.handle);
walk_light_query(Submodel, false);
+ walk_light_reference(Submodel->m_geometry.handle);
pointdrawn = true;
// post-draw reset
diff --git a/rendering/common/scenewalk.h b/rendering/common/scenewalk.h
index ac22f7d99..697e1ae68 100644
--- a/rendering/common/scenewalk.h
+++ b/rendering/common/scenewalk.h
@@ -267,10 +267,14 @@ class scene_walk
virtual void walk_cull_face(bool const Enabled) = 0;
// the glare of a lamp: drawn without the depth test, added to what is there; drawn only where the point of the light was
// seen (walk_light_query() of this point drawn just before it, when the backend has it: the opengl renderer uses
- // the query at once, the vulkan renderer the result of the last frame)
+ // the query at once and makes the glare as bright as the part of the point seen, the vulkan renderer uses the result of the
+ // last frame)
virtual void walk_glare(bool const Enabled) = 0;
virtual void walk_glare_draw(TSubModel *Submodel, gfx::geometry_handle const &Geometry) = 0;
virtual void walk_light_query(TSubModel *Submodel, bool const Begin) = 0;
+ // the point of the light drawn once more right after walk_light_query(), unseen and whole, for the backend which makes the
+ // glare as bright as the part of the point seen (the opengl renderer); by default nothing
+ virtual void walk_light_reference(gfx::geometry_handle const &Geometry) {}
// what the backend may draw itself (the gpu culling of the opengl renderer); by default the walk draws everything
// the start of the walk of a region
virtual void walk_region_begin() {}
diff --git a/rendering/opengl46/opengl46renderer.cpp b/rendering/opengl46/opengl46renderer.cpp
index 4e45137a5..e6a2854c6 100644
--- a/rendering/opengl46/opengl46renderer.cpp
+++ b/rendering/opengl46/opengl46renderer.cpp
@@ -5058,6 +5058,11 @@ void opengl46_renderer::walk_glare(bool const Enabled)
void opengl46_renderer::walk_glare_draw(TSubModel *Submodel, gfx::geometry_handle const &Geometry)
{
+ // billboard.frag scales the glare by the part of the point seen, when the samples were counted for it
+ auto const parameter{model_ubs.param[1].w};
+ model_ubs.param[1].w = (m_glaresamples ? 1.f : 0.f);
+ if (m_glaresamples)
+ m_glaressbo->bind_base();
if (Submodel->occlusion_query) {
glBeginConditionalRender(*Submodel->occlusion_query, GL_QUERY_WAIT);
draw(Geometry);
@@ -5065,6 +5070,8 @@ void opengl46_renderer::walk_glare_draw(TSubModel *Submodel, gfx::geometry_handl
}
else
draw(Geometry);
+ model_ubs.param[1].w = parameter;
+ m_glaresamples = false;
}
void opengl46_renderer::walk_light_query(TSubModel *Submodel, bool const Begin)
@@ -5072,14 +5079,40 @@ void opengl46_renderer::walk_light_query(TSubModel *Submodel, bool const Begin)
if (false == gl::vao::use_vao)
return;
if (Begin) {
+ m_glaresamples = false;
if (!Submodel->occlusion_query)
- Submodel->occlusion_query.emplace(gl::query::ANY_SAMPLES_PASSED);
+ Submodel->occlusion_query.emplace(gl::query::SAMPLES_PASSED);
Submodel->occlusion_query->begin();
+ m_glarequerysubmodel = Submodel;
}
else
Submodel->occlusion_query->end();
}
+void opengl46_renderer::walk_light_reference(gfx::geometry_handle const &Geometry)
+{
+ if ((false == gl::vao::use_vao) || (m_glarequerysubmodel == nullptr) || (false == m_glarequerysubmodel->occlusion_query.has_value()))
+ return;
+ auto const &seen{*m_glarequerysubmodel->occlusion_query};
+ m_glarequerysubmodel = nullptr;
+ if (!m_glarequery)
+ m_glarequery.emplace(gl::query::SAMPLES_PASSED);
+ if (!m_glaressbo)
+ m_glaressbo = std::make_unique(static_cast(2 * sizeof(GLuint)), gl::GLARE_SSBO_BINDING);
+ // the whole point, unseen: what the samples seen are compared with
+ glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+ glDisable(GL_DEPTH_TEST);
+ m_glarequery->begin();
+ draw(Geometry);
+ m_glarequery->end();
+ glEnable(GL_DEPTH_TEST);
+ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ // the gpu writes the counts when they're done, no wait here
+ glGetQueryBufferObjectuiv(seen, *m_glaressbo, GL_QUERY_RESULT, 0);
+ glGetQueryBufferObjectuiv(*m_glarequery, *m_glaressbo, GL_QUERY_RESULT, static_cast(sizeof(GLuint)));
+ m_glaresamples = true;
+}
+
void opengl46_renderer::walk_region_begin()
{
// the gpu culling runs along the first color pass of the main viewport of a frame, and the passes of the cascades of the
diff --git a/rendering/opengl46/opengl46renderer.h b/rendering/opengl46/opengl46renderer.h
index a49c8dd5a..fa46ef3c0 100644
--- a/rendering/opengl46/opengl46renderer.h
+++ b/rendering/opengl46/opengl46renderer.h
@@ -228,6 +228,7 @@ class opengl46_renderer : public gfx_renderer, public gfx::scene_walk {
void walk_glare(bool const Enabled) override;
void walk_glare_draw(TSubModel *Submodel, gfx::geometry_handle const &Geometry) override;
void walk_light_query(TSubModel *Submodel, bool const Begin) override;
+ void walk_light_reference(gfx::geometry_handle const &Geometry) override;
// the gpu culling of the instances, models and sleepers, the depth pass of the whole scene
void walk_region_begin() override;
void walk_editor_cursor() override;
@@ -848,6 +849,13 @@ class opengl46_renderer : public gfx_renderer, public gfx::scene_walk {
unsigned int m_editor_overlay_revision{0};
std::unique_ptr m_freespot_shader;
std::unique_ptr m_billboard_shader;
+ // the glare of a lamp as bright as the part of its point seen: the submodel of the point whose query is under way
+ // (walk_light_query()), the samples of the point drawn without the depth test (walk_light_reference()), the samples counted
+ // for the point (seen and all) written there by the gpu, and whether they were for the glare which follows
+ TSubModel *m_glarequerysubmodel { nullptr };
+ std::optional m_glarequery;
+ std::unique_ptr m_glaressbo;
+ bool m_glaresamples { false };
std::unique_ptr m_celestial_shader;
std::unique_ptr m_hiddenarea_shader;
std::unique_ptr m_copy_shader;
diff --git a/shaders/ogl46/billboard.frag b/shaders/ogl46/billboard.frag
index 42f3e64d3..1182d06dd 100644
--- a/shaders/ogl46/billboard.frag
+++ b/shaders/ogl46/billboard.frag
@@ -11,9 +11,21 @@ layout(binding = 0) uniform sampler2D tex1;
layout(location = 0) out vec4 out_color;
layout(location = 1) out vec4 out_motion;
+// the samples of the point of the lamp its occlusion queries counted (the opengl renderer, with param[1].w 1): the glare is as
+// bright as the part of the point which is seen
+layout(std430, binding = GLARE_SSBO_BINDING) readonly buffer glare_ssbo
+{
+ uint glare_seen;
+ uint glare_all;
+};
+
void main()
{
vec4 tex_color = texture(tex1, f_coord);
+ if (param[1].w > 0.5f)
+ {
+ tex_color.a *= (glare_all > 0u ? clamp(float(glare_seen) / float(glare_all), 0.0f, 1.0f) : 0.0f);
+ }
if (POSTFX_ENABLED)
{
out_color = tex_color * param[0];
diff --git a/shaders/ogl46/common.glsl b/shaders/ogl46/common.glsl
index 9c0a2ada4..7fbaca131 100644
--- a/shaders/ogl46/common.glsl
+++ b/shaders/ogl46/common.glsl
@@ -119,6 +119,7 @@
#define SKY_OCCLUSION_TEX 30
#define CAB_PROBE_MASK_TEX 31
#define CAB_PROBE_SSBO_BINDING 17
+#define GLARE_SSBO_BINDING 18
#define CAB_PROBE_SH_SIZE 16
#define CAB_PROBE_SH_GROUP_SIZE 64
#define WEATHER_UBO_BINDING 5
From 23623696718d2b7ebc2223854dcd4c65882eb7d5 Mon Sep 17 00:00:00 2001
From: pwarszawski
Date: Sat, 14 Nov 2026 21:11:41 +0100
Subject: [PATCH 003/174] Cluster culling: the radius of a lamp isn't a part of
its brightness
light_peak() scaled point and spot lights by 1 + ambient, but for them ambient holds the radius of the sphere the light
shines from, negative with the soft falloff. A soft lamp with a radius of 1 m or more got no range and lit nothing; other
lamps got ranges too short (soft) or too long. The shading ends the light at 1 / sqrt(quadratic) whatever its radius.
---
shaders/ogl46/cluster_cull.comp | 3 ++-
shaders/vk14/cluster_cull.comp | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/shaders/ogl46/cluster_cull.comp b/shaders/ogl46/cluster_cull.comp
index 0545540f9..59d9a6bea 100644
--- a/shaders/ogl46/cluster_cull.comp
+++ b/shaders/ogl46/cluster_cull.comp
@@ -25,7 +25,8 @@ float light_peak(light_s light)
if (light.type == LIGHT_HEADLIGHTS)
// weights are the state of the individual lamps and the beam texture, which is not brighter than 1, picks from them
return peak * max(light.headlight_weights.r, max(light.headlight_weights.g, light.headlight_weights.b));
- return peak * (1.0 + light.ambient);
+ // point and spot lights: ambient holds the signed radius of the sphere the light shines from, which brings no brightness
+ return peak;
}
// distance from the light at which its contribution falls under MIN_CONTRIBUTION, 0 for a light which has none
diff --git a/shaders/vk14/cluster_cull.comp b/shaders/vk14/cluster_cull.comp
index 141f9eaf5..3f5792280 100644
--- a/shaders/vk14/cluster_cull.comp
+++ b/shaders/vk14/cluster_cull.comp
@@ -25,7 +25,8 @@ float light_peak(light_s light)
if (light.type == LIGHT_HEADLIGHTS)
// weights are the state of the individual lamps and the beam texture, which is not brighter than 1, picks from them
return peak * max(light.headlight_weights.r, max(light.headlight_weights.g, light.headlight_weights.b));
- return peak * (1.0 + light.ambient);
+ // point and spot lights: ambient holds the signed radius of the sphere the light shines from, which brings no brightness
+ return peak;
}
// distance from the light at which its contribution falls under MIN_CONTRIBUTION, 0 for a light which has none
From e3584e706bc1c2ed97b9ac2ea0f34f39813e27d1 Mon Sep 17 00:00:00 2001
From: pwarszawski
Date: Sun, 15 Nov 2026 17:05:11 +0100
Subject: [PATCH 004/174] Glare of light points: the glare in a function of its
own, the define of its buffer with std::format
Render_Glare draws the glare around a light point, so Render_Alpha keeps its nesting. The define of GLARE_SSBO_BINDING is
appended with std::format after the chain of the common defines, the luminance is cast to float explicitly (the same value) and
the empty default of walk_light_reference says why it's empty.
---
gl/glsl_common.cpp | 5 ++-
rendering/common/scenewalk.cpp | 73 ++++++++++++++++++----------------
rendering/common/scenewalk.h | 7 +++-
3 files changed, 49 insertions(+), 36 deletions(-)
diff --git a/gl/glsl_common.cpp b/gl/glsl_common.cpp
index 9a5c9a895..ad82b36f1 100644
--- a/gl/glsl_common.cpp
+++ b/gl/glsl_common.cpp
@@ -2,6 +2,8 @@
#include "glsl_common.h"
#include "rendering/common/shadersource.h"
+#include
+
std::string gl::glsl_common;
void gl::glsl_common_setup()
@@ -110,7 +112,6 @@ void gl::glsl_common_setup()
"#define SKY_OCCLUSION_HEIGHT_TEX " + std::to_string(SKY_OCCLUSION_HEIGHT_TEX) + "\n" +
"#define SKY_OCCLUSION_TEX " + std::to_string(SKY_OCCLUSION_TEX) + "\n" +
"#define CAB_PROBE_SSBO_BINDING " + std::to_string(CAB_PROBE_SSBO_BINDING) + "\n" +
- "#define GLARE_SSBO_BINDING " + std::to_string(GLARE_SSBO_BINDING) + "\n" +
"#define CAB_PROBE_SH_SIZE " + std::to_string(CAB_PROBE_SH_SIZE) + "\n" +
"#define CAB_PROBE_SH_GROUP_SIZE " + std::to_string(CAB_PROBE_SH_GROUP_SIZE) + "\n" +
"#define WEATHER_UBO_BINDING " + std::to_string(WEATHER_UBO_BINDING) + "\n" +
@@ -119,6 +120,8 @@ void gl::glsl_common_setup()
"#define FOG_HORIZON_SAMPLES " + std::to_string(FOG_HORIZON_SAMPLES) + "\n" +
"#define WEATHER_GROUP_SIZE " + std::to_string(WEATHER_GROUP_SIZE) + "\n" +
"#define FOG_VOLUME_BIAS " + std::to_string(FOG_VOLUME_BIAS) + "\n";
+ // the counts of the samples of the light points seen, which their glares are made as bright as
+ glsl_common += std::format("#define GLARE_SSBO_BINDING {}\n", GLARE_SSBO_BINDING);
}
std::string gl::glsl_settings_defines()
diff --git a/rendering/common/scenewalk.cpp b/rendering/common/scenewalk.cpp
index d75bb40ca..a7f7322fb 100644
--- a/rendering/common/scenewalk.cpp
+++ b/rendering/common/scenewalk.cpp
@@ -3110,6 +3110,44 @@ void scene_walk::Render_Alpha_text(TSubModel *Submodel)
}
}
+void scene_walk::Render_Glare(TSubModel *Submodel, glm::vec4 const &Lightcenter, bool const Pointlight)
+{
+ // luminosity at night is at level of ~0.1, so the overall resulting transparency in clear conditions is ~0.5 at full 'brightness'
+ auto glarelevel{std::clamp(std::max(static_cast(0.6f - Global.fLuminance), // reduce the glare in bright daylight
+ Global.Overcast - 1.f), // ensure some glare in rainy/foggy conditions
+ 0.f, 1.f)};
+ // view angle attenuation
+ float const anglefactor{Pointlight ? 1.f : std::clamp((Submodel->fCosViewAngle - Submodel->fCosFalloffAngle) / (Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle), 0.f, 1.f)};
+
+ glarelevel *= anglefactor;
+
+ if (glarelevel > 0.0f)
+ {
+ walk_glare(true);
+
+ ::glPushMatrix();
+ ::glLoadIdentity(); // macierz jedynkowa
+ ::glTranslatef(Lightcenter.x, Lightcenter.y, Lightcenter.z); // początek układu zostaje bez zmian
+ ::glRotated(std::atan2(Lightcenter.x, Lightcenter.z) * 180.0 / M_PI, 0.0, 1.0, 0.0); // jedynie obracamy w pionie o kąt
+
+ auto const lightcolor = glm::vec3(Submodel->DiffuseOverride.r < 0.f ? // -1 indicates no override
+ Submodel->f4Diffuse :
+ Submodel->DiffuseOverride);
+
+ walk_program( walk_shader::billboard );
+ walk_texture(0, m_glaretexture);
+ model_ubs.param[0] = glm::vec4(glm::vec3(lightcolor), Submodel->fVisible * glarelevel);
+
+ // main draw call
+ // drawn where the point of the light was seen just above (an occlusion query of the opengl renderer)
+ walk_glare_draw(Submodel, m_billboardgeometry);
+
+ walk_glare(false);
+
+ ::glPopMatrix();
+ }
+}
+
void scene_walk::Render_Alpha(TSubModel *Submodel)
{
// renderowanie przezroczystych przez DL
@@ -3289,40 +3327,7 @@ void scene_walk::Render_Alpha(TSubModel *Submodel)
// the point is drawn only inside its visibility cone, so the glare is too
if (pointdrawn && (Global.fLuminance < Submodel->fLight || Global.Overcast > 1.0f))
{
- // luminosity at night is at level of ~0.1, so the overall resulting transparency in clear conditions is ~0.5 at full 'brightness'
- auto glarelevel{std::clamp(std::max(0.6f - Global.fLuminance, // reduce the glare in bright daylight
- Global.Overcast - 1.f), // ensure some glare in rainy/foggy conditions
- 0.f, 1.f)};
- // view angle attenuation
- float const anglefactor{pointlight ? 1.f : std::clamp((Submodel->fCosViewAngle - Submodel->fCosFalloffAngle) / (Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle), 0.f, 1.f)};
-
- glarelevel *= anglefactor;
-
- if (glarelevel > 0.0f)
- {
- walk_glare(true);
-
- ::glPushMatrix();
- ::glLoadIdentity(); // macierz jedynkowa
- ::glTranslatef(lightcenter.x, lightcenter.y, lightcenter.z); // początek układu zostaje bez zmian
- ::glRotated(std::atan2(lightcenter.x, lightcenter.z) * 180.0 / M_PI, 0.0, 1.0, 0.0); // jedynie obracamy w pionie o kąt
-
- auto const lightcolor = glm::vec3(Submodel->DiffuseOverride.r < 0.f ? // -1 indicates no override
- Submodel->f4Diffuse :
- Submodel->DiffuseOverride);
-
- walk_program( walk_shader::billboard );
- walk_texture(0, m_glaretexture);
- model_ubs.param[0] = glm::vec4(glm::vec3(lightcolor), Submodel->fVisible * glarelevel);
-
- // main draw call
- // drawn where the point of the light was seen just above (an occlusion query of the opengl renderer)
- walk_glare_draw(Submodel, m_billboardgeometry);
-
- walk_glare(false);
-
- ::glPopMatrix();
- }
+ Render_Glare(Submodel, lightcenter, pointlight);
}
}
diff --git a/rendering/common/scenewalk.h b/rendering/common/scenewalk.h
index 697e1ae68..b71eafa12 100644
--- a/rendering/common/scenewalk.h
+++ b/rendering/common/scenewalk.h
@@ -274,7 +274,10 @@ class scene_walk
virtual void walk_light_query(TSubModel *Submodel, bool const Begin) = 0;
// the point of the light drawn once more right after walk_light_query(), unseen and whole, for the backend which makes the
// glare as bright as the part of the point seen (the opengl renderer); by default nothing
- virtual void walk_light_reference(gfx::geometry_handle const &Geometry) {}
+ virtual void walk_light_reference(gfx::geometry_handle const &Geometry)
+ {
+ // a backend which doesn't scale the glare by the part of the point seen has nothing to draw here
+ }
// what the backend may draw itself (the gpu culling of the opengl renderer); by default the walk draws everything
// the start of the walk of a region
virtual void walk_region_begin() {}
@@ -637,6 +640,8 @@ class scene_walk
private:
static float editor_ortho_reach();
+ // the glare around a light point drawn just before, Lightcenter in view space
+ void Render_Glare(TSubModel *Submodel, glm::vec4 const &Lightcenter, bool Pointlight);
};
} // namespace gfx
From 4342f5f5637af3df479edc64cd5b198561657c5c Mon Sep 17 00:00:00 2001
From: pwarszawski
Date: Sun, 15 Nov 2026 18:29:00 +0100
Subject: [PATCH 005/174] gl46: draw opaque characters of text displays
The walk laid out the characters of a text display in the translucent pass
only; the opaque pass drew the whole character set of the display as plain
children. Station name boards made of opaque character sub-models lost their
text. Port of the opengl33 change (#201): the opaque pass lays the characters
of the displayed text out in a row, the same way as the translucent one.
---
rendering/common/scenewalk.cpp | 33 ++++++++++++++++++++++++++++++++-
rendering/common/scenewalk.h | 2 ++
2 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/rendering/common/scenewalk.cpp b/rendering/common/scenewalk.cpp
index 63aa3ce47..235e8b9ee 100644
--- a/rendering/common/scenewalk.cpp
+++ b/rendering/common/scenewalk.cpp
@@ -2067,6 +2067,37 @@ bool scene_walk::Render(TModel3d *Model, material_data const *Material, float co
return result;
}
+// opaque characters of a text display, laid out in a row the same way as the translucent ones
+void scene_walk::Render_text(TSubModel *Submodel)
+{
+ if (TSubModel::pasText == nullptr)
+ {
+ return;
+ }
+ ::glPushMatrix();
+ for (auto *p : Submodel->text_letters(*TSubModel::pasText))
+ {
+ Render(p);
+ if (p->fMatrix)
+ ::glMultMatrixf(p->fMatrix->readArray()); // move on to the place of the next character
+ }
+ ::glPopMatrix();
+}
+
+// opaque sub-models under the given one. the children of a text display are its character set, only the characters
+// of the displayed text are drawn
+void scene_walk::Render_children(TSubModel *Submodel)
+{
+ if (Submodel->eType == TP_TEXT)
+ {
+ Render_text(Submodel);
+ }
+ else
+ {
+ Render(Submodel->Child);
+ }
+}
+
void scene_walk::Render(TSubModel *Submodel)
{
glDebug("Render TSubModel");
@@ -2227,7 +2258,7 @@ void scene_walk::Render(TSubModel *Submodel)
}
if (Submodel->Child != nullptr)
if (Submodel->iAlpha & Submodel->iFlags & 0x001F0000)
- Render(Submodel->Child);
+ Render_children(Submodel);
if (Submodel->iFlags & 0xC000)
{
diff --git a/rendering/common/scenewalk.h b/rendering/common/scenewalk.h
index 91a708c8d..3969bc795 100644
--- a/rendering/common/scenewalk.h
+++ b/rendering/common/scenewalk.h
@@ -163,6 +163,8 @@ class scene_walk
bool Render(TModel3d *Model, material_data const *Material, float const Squaredistance, glm::dvec3 const &Position, glm::vec3 const &Angle);
bool Render(TModel3d *Model, material_data const *Material, float const Squaredistance);
void Render(TSubModel *Submodel);
+ void Render_children(TSubModel *Submodel); // opaque sub-models under the given one
+ void Render_text(TSubModel *Submodel); // opaque characters of a text display
void Render(TTrack *Track);
void Render(scene::basic_cell::path_sequence::const_iterator First, scene::basic_cell::path_sequence::const_iterator Last);
// renders the per-track sleeper instances (TTrack::m_sleeper_local_transforms) via GPU instancing.
From 0367a04f2242970d6ea858aa176ee9611a9a67bf Mon Sep 17 00:00:00 2001
From: pwarszawski
Date: Mon, 16 Nov 2026 16:44:44 +0100
Subject: [PATCH 006/174] Glare of light points: occlusion queries of each
light point of each model, read without waiting
The glare waited for the occlusion query of its point in the same frame (a conditional render with GL_QUERY_WAIT and the counts
written to a buffer for the shader), which drains the gpu at every lamp. Each light point of each model (the submodel and the
instance drawn) now has a pair of queries of its own in the main view: the samples of the point which passed the depth test, and
all of them drawn once more without it. Their results are read once the gpu has them, without waiting, and the glare is as
bright as the part of the point seen by them, a frame or two late. A point not drawn for more than two frames starts over unseen,
so a glare doesn't show through what came in front of it meanwhile. The walk, the shaders and the vulkan renderer are as they
were.
---
gl/glsl_common.cpp | 4 -
gl/ubo.h | 4 -
rendering/common/scenewalk.cpp | 89 ++++++++--------
rendering/common/scenewalk.h | 12 +--
rendering/opengl46/opengl46renderer.cpp | 136 ++++++++++++++++--------
rendering/opengl46/opengl46renderer.h | 43 ++++++--
shaders/ogl46/billboard.frag | 12 ---
shaders/ogl46/common.glsl | 1 -
8 files changed, 170 insertions(+), 131 deletions(-)
diff --git a/gl/glsl_common.cpp b/gl/glsl_common.cpp
index ad82b36f1..f6f3df06d 100644
--- a/gl/glsl_common.cpp
+++ b/gl/glsl_common.cpp
@@ -2,8 +2,6 @@
#include "glsl_common.h"
#include "rendering/common/shadersource.h"
-#include
-
std::string gl::glsl_common;
void gl::glsl_common_setup()
@@ -120,8 +118,6 @@ void gl::glsl_common_setup()
"#define FOG_HORIZON_SAMPLES " + std::to_string(FOG_HORIZON_SAMPLES) + "\n" +
"#define WEATHER_GROUP_SIZE " + std::to_string(WEATHER_GROUP_SIZE) + "\n" +
"#define FOG_VOLUME_BIAS " + std::to_string(FOG_VOLUME_BIAS) + "\n";
- // the counts of the samples of the light points seen, which their glares are made as bright as
- glsl_common += std::format("#define GLARE_SSBO_BINDING {}\n", GLARE_SSBO_BINDING);
}
std::string gl::glsl_settings_defines()
diff --git a/gl/ubo.h b/gl/ubo.h
index 83a6ac71d..c933cf523 100644
--- a/gl/ubo.h
+++ b/gl/ubo.h
@@ -446,10 +446,6 @@ namespace gl
};
// binding point of the opengl renderer, bound with the colour passes
const GLuint CAB_PROBE_SSBO_BINDING = 17;
- // layout std430: the samples of the point of a lamp its occlusion queries counted, written there by the gpu (GLSL: glare_ssbo,
- // read by billboard.frag): seen, which passed the depth test, and all, drawn without it. binding point of the opengl renderer,
- // bound with the glare of a lamp
- const GLuint GLARE_SSBO_BINDING = 18;
// the face of the level of the probe the spherical harmonics are taken from, at most, and the work group of cabprobe_sh.comp
const size_t CAB_PROBE_SH_SIZE = 16;
// the face of the level of the probe CAB_PROBE_MASK_TEX is a copy of, at most
diff --git a/rendering/common/scenewalk.cpp b/rendering/common/scenewalk.cpp
index a7f7322fb..63aa3ce47 100644
--- a/rendering/common/scenewalk.cpp
+++ b/rendering/common/scenewalk.cpp
@@ -3110,44 +3110,6 @@ void scene_walk::Render_Alpha_text(TSubModel *Submodel)
}
}
-void scene_walk::Render_Glare(TSubModel *Submodel, glm::vec4 const &Lightcenter, bool const Pointlight)
-{
- // luminosity at night is at level of ~0.1, so the overall resulting transparency in clear conditions is ~0.5 at full 'brightness'
- auto glarelevel{std::clamp(std::max(static_cast(0.6f - Global.fLuminance), // reduce the glare in bright daylight
- Global.Overcast - 1.f), // ensure some glare in rainy/foggy conditions
- 0.f, 1.f)};
- // view angle attenuation
- float const anglefactor{Pointlight ? 1.f : std::clamp((Submodel->fCosViewAngle - Submodel->fCosFalloffAngle) / (Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle), 0.f, 1.f)};
-
- glarelevel *= anglefactor;
-
- if (glarelevel > 0.0f)
- {
- walk_glare(true);
-
- ::glPushMatrix();
- ::glLoadIdentity(); // macierz jedynkowa
- ::glTranslatef(Lightcenter.x, Lightcenter.y, Lightcenter.z); // początek układu zostaje bez zmian
- ::glRotated(std::atan2(Lightcenter.x, Lightcenter.z) * 180.0 / M_PI, 0.0, 1.0, 0.0); // jedynie obracamy w pionie o kąt
-
- auto const lightcolor = glm::vec3(Submodel->DiffuseOverride.r < 0.f ? // -1 indicates no override
- Submodel->f4Diffuse :
- Submodel->DiffuseOverride);
-
- walk_program( walk_shader::billboard );
- walk_texture(0, m_glaretexture);
- model_ubs.param[0] = glm::vec4(glm::vec3(lightcolor), Submodel->fVisible * glarelevel);
-
- // main draw call
- // drawn where the point of the light was seen just above (an occlusion query of the opengl renderer)
- walk_glare_draw(Submodel, m_billboardgeometry);
-
- walk_glare(false);
-
- ::glPopMatrix();
- }
-}
-
void scene_walk::Render_Alpha(TSubModel *Submodel)
{
// renderowanie przezroczystych przez DL
@@ -3256,8 +3218,48 @@ void scene_walk::Render_Alpha(TSubModel *Submodel)
// a point light (FalloffAngle 360) is seen all around
auto const pointlight{Submodel->fCosFalloffAngle <= -1.f};
- // the glare is drawn after the point, where the occlusion query of this very point (of this instance, in this frame) saw it
- auto pointdrawn{false};
+ if (Global.fLuminance < Submodel->fLight || Global.Overcast > 1.0f)
+ {
+ if (pointlight || (Submodel->fCosViewAngle > Submodel->fCosFalloffAngle))
+ {
+ // only bother if the viewer is inside the visibility cone
+ // luminosity at night is at level of ~0.1, so the overall resulting transparency in clear conditions is ~0.5 at full 'brightness'
+ auto glarelevel{std::clamp(std::max(0.6f - Global.fLuminance, // reduce the glare in bright daylight
+ Global.Overcast - 1.f), // ensure some glare in rainy/foggy conditions
+ 0.f, 1.f)};
+ // view angle attenuation
+ float const anglefactor{pointlight ? 1.f : std::clamp((Submodel->fCosViewAngle - Submodel->fCosFalloffAngle) / (Submodel->fCosHotspotAngle - Submodel->fCosFalloffAngle), 0.f, 1.f)};
+
+ glarelevel *= anglefactor;
+
+ if (glarelevel > 0.0f)
+ {
+ walk_glare(true);
+
+ ::glPushMatrix();
+ ::glLoadIdentity(); // macierz jedynkowa
+ ::glTranslatef(lightcenter.x, lightcenter.y, lightcenter.z); // początek układu zostaje bez zmian
+ ::glRotated(std::atan2(lightcenter.x, lightcenter.z) * 180.0 / M_PI, 0.0, 1.0, 0.0); // jedynie obracamy w pionie o kąt
+
+ auto const lightcolor = glm::vec3(Submodel->DiffuseOverride.r < 0.f ? // -1 indicates no override
+ Submodel->f4Diffuse :
+ Submodel->DiffuseOverride);
+
+ walk_program( walk_shader::billboard );
+ walk_texture(0, m_glaretexture);
+ model_ubs.param[0] = glm::vec4(glm::vec3(lightcolor), Submodel->fVisible * glarelevel);
+
+ // main draw call
+ // drawn where the light itself was seen in the last frame (an occlusion query of the opengl renderer)
+ walk_glare_draw(Submodel, m_billboardgeometry);
+
+ walk_glare(false);
+
+ ::glPopMatrix();
+ }
+ }
+ }
+
if (pointlight || (Submodel->fCosViewAngle > Submodel->fCosFalloffAngle))
{
// kąt większy niż maksymalny stożek swiatła
@@ -3314,8 +3316,6 @@ void scene_walk::Render_Alpha(TSubModel *Submodel)
walk_draw(Submodel->m_geometry.handle);
walk_light_query(Submodel, false);
- walk_light_reference(Submodel->m_geometry.handle);
- pointdrawn = true;
// post-draw reset
model_ubs.emission = 0.0f;
@@ -3324,11 +3324,6 @@ void scene_walk::Render_Alpha(TSubModel *Submodel)
::glPopMatrix();
}
}
- // the point is drawn only inside its visibility cone, so the glare is too
- if (pointdrawn && (Global.fLuminance < Submodel->fLight || Global.Overcast > 1.0f))
- {
- Render_Glare(Submodel, lightcenter, pointlight);
- }
}
if (Submodel->Child != nullptr)
diff --git a/rendering/common/scenewalk.h b/rendering/common/scenewalk.h
index b71eafa12..91a708c8d 100644
--- a/rendering/common/scenewalk.h
+++ b/rendering/common/scenewalk.h
@@ -266,18 +266,10 @@ class scene_walk
virtual void walk_timbers_expand(std::vector const &Origins, std::vector const &Ranges) {}
virtual void walk_cull_face(bool const Enabled) = 0;
// the glare of a lamp: drawn without the depth test, added to what is there; drawn only where the point of the light was
- // seen (walk_light_query() of this point drawn just before it, when the backend has it: the opengl renderer uses
- // the query at once and makes the glare as bright as the part of the point seen, the vulkan renderer uses the result of the
- // last frame)
+ // seen (walk_light_query() of the last frame, when the backend has it)
virtual void walk_glare(bool const Enabled) = 0;
virtual void walk_glare_draw(TSubModel *Submodel, gfx::geometry_handle const &Geometry) = 0;
virtual void walk_light_query(TSubModel *Submodel, bool const Begin) = 0;
- // the point of the light drawn once more right after walk_light_query(), unseen and whole, for the backend which makes the
- // glare as bright as the part of the point seen (the opengl renderer); by default nothing
- virtual void walk_light_reference(gfx::geometry_handle const &Geometry)
- {
- // a backend which doesn't scale the glare by the part of the point seen has nothing to draw here
- }
// what the backend may draw itself (the gpu culling of the opengl renderer); by default the walk draws everything
// the start of the walk of a region
virtual void walk_region_begin() {}
@@ -640,8 +632,6 @@ class scene_walk
private:
static float editor_ortho_reach();
- // the glare around a light point drawn just before, Lightcenter in view space
- void Render_Glare(TSubModel *Submodel, glm::vec4 const &Lightcenter, bool Pointlight);
};
} // namespace gfx
diff --git a/rendering/opengl46/opengl46renderer.cpp b/rendering/opengl46/opengl46renderer.cpp
index e6a2854c6..6c36ec921 100644
--- a/rendering/opengl46/opengl46renderer.cpp
+++ b/rendering/opengl46/opengl46renderer.cpp
@@ -5056,61 +5056,109 @@ void opengl46_renderer::walk_glare(bool const Enabled)
}
}
+// the frames a result of the glare queries is good for: a point not drawn for longer may have something else in front of it now
+constexpr unsigned int GLARE_RESULT_FRAMES{2};
+// the frames after which the entries of points no longer drawn are dropped
+constexpr unsigned int GLARE_KEEP_FRAMES{600};
+
+opengl46_renderer::glare_visibility *opengl46_renderer::glare_entry(TSubModel const *Submodel, bool const Create)
+{
+ glare_key const key{Submodel, TSubModel::iInstance};
+ if (false == Create)
+ {
+ auto const lookup{m_glares.find(key)};
+ return (lookup != m_glares.end() ? &lookup->second : nullptr);
+ }
+ if (m_framestamp - m_glarepruned > GLARE_KEEP_FRAMES)
+ {
+ m_glarepruned = m_framestamp;
+ auto const framestamp{m_framestamp};
+ // a query whose result nobody reads any more is deleted along
+ std::erase_if(m_glares, [framestamp](auto const &Entry) { return framestamp - Entry.second.frame > GLARE_KEEP_FRAMES; });
+ }
+ return &m_glares.try_emplace(key).first->second;
+}
+
+void opengl46_renderer::glare_read(glare_visibility &Entry)
+{
+ // the results once the gpu has both of them, nothing waits for them
+ auto const seen{Entry.seen.result()};
+ if (false == seen.has_value())
+ {
+ return;
+ }
+ auto const all{Entry.all.result()};
+ if (false == all.has_value())
+ {
+ return;
+ }
+ Entry.pending = false;
+ Entry.share = (*all > 0 ? std::clamp(static_cast(*seen) / static_cast(*all), 0.f, 1.f) : 0.f);
+}
+
void opengl46_renderer::walk_glare_draw(TSubModel *Submodel, gfx::geometry_handle const &Geometry)
{
- // billboard.frag scales the glare by the part of the point seen, when the samples were counted for it
- auto const parameter{model_ubs.param[1].w};
- model_ubs.param[1].w = (m_glaresamples ? 1.f : 0.f);
- if (m_glaresamples)
- m_glaressbo->bind_base();
- if (Submodel->occlusion_query) {
- glBeginConditionalRender(*Submodel->occlusion_query, GL_QUERY_WAIT);
+ if (false == gl::vao::use_vao)
+ {
draw(Geometry);
- glEndConditionalRender();
+ return;
}
- else
- draw(Geometry);
- model_ubs.param[1].w = parameter;
- m_glaresamples = false;
+ // as bright as the part of the point seen in the main view, by the results of an earlier frame; none for a point not seen
+ // lately
+ auto const *entry{glare_entry(Submodel, false)};
+ if ((entry == nullptr) || (m_framestamp - entry->frame > GLARE_RESULT_FRAMES) || (entry->share <= 0.f))
+ {
+ return;
+ }
+ auto const opacity{model_ubs.param[0].w};
+ model_ubs.param[0].w = opacity * entry->share;
+ draw(Geometry);
+ model_ubs.param[0].w = opacity;
}
void opengl46_renderer::walk_light_query(TSubModel *Submodel, bool const Begin)
{
- if (false == gl::vao::use_vao)
+ if ((false == gl::vao::use_vao) || (m_renderpass.draw_mode != rendermode::color) || (m_current_viewport == nullptr) || (false == m_current_viewport->main))
+ {
return;
- if (Begin) {
- m_glaresamples = false;
- if (!Submodel->occlusion_query)
- Submodel->occlusion_query.emplace(gl::query::SAMPLES_PASSED);
- Submodel->occlusion_query->begin();
- m_glarequerysubmodel = Submodel;
}
- else
- Submodel->occlusion_query->end();
-}
-
-void opengl46_renderer::walk_light_reference(gfx::geometry_handle const &Geometry)
-{
- if ((false == gl::vao::use_vao) || (m_glarequerysubmodel == nullptr) || (false == m_glarequerysubmodel->occlusion_query.has_value()))
+ if (false == Begin)
+ {
+ if (m_glarequery == nullptr)
+ {
+ return;
+ }
+ m_glarequery->seen.end();
+ // the whole point, unseen: what the samples seen are compared with
+ glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+ glDisable(GL_DEPTH_TEST);
+ m_glarequery->all.begin();
+ draw(Submodel->m_geometry.handle);
+ m_glarequery->all.end();
+ glEnable(GL_DEPTH_TEST);
+ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ m_glarequery->pending = true;
+ m_glarequery = nullptr;
return;
- auto const &seen{*m_glarequerysubmodel->occlusion_query};
- m_glarequerysubmodel = nullptr;
- if (!m_glarequery)
- m_glarequery.emplace(gl::query::SAMPLES_PASSED);
- if (!m_glaressbo)
- m_glaressbo = std::make_unique(static_cast(2 * sizeof(GLuint)), gl::GLARE_SSBO_BINDING);
- // the whole point, unseen: what the samples seen are compared with
- glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
- glDisable(GL_DEPTH_TEST);
- m_glarequery->begin();
- draw(Geometry);
- m_glarequery->end();
- glEnable(GL_DEPTH_TEST);
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- // the gpu writes the counts when they're done, no wait here
- glGetQueryBufferObjectuiv(seen, *m_glaressbo, GL_QUERY_RESULT, 0);
- glGetQueryBufferObjectuiv(*m_glarequery, *m_glaressbo, GL_QUERY_RESULT, static_cast(sizeof(GLuint)));
- m_glaresamples = true;
+ }
+ auto &entry{*glare_entry(Submodel, true)};
+ if (m_framestamp - entry.frame > GLARE_RESULT_FRAMES)
+ {
+ // not drawn lately: what it saw then is no good, it starts over unseen
+ entry.share = 0.f;
+ entry.pending = false;
+ }
+ entry.frame = m_framestamp;
+ if (entry.pending)
+ {
+ glare_read(entry);
+ }
+ if (false == entry.pending)
+ {
+ // new queries once the results of the last ones are read
+ entry.seen.begin();
+ m_glarequery = &entry;
+ }
}
void opengl46_renderer::walk_region_begin()
diff --git a/rendering/opengl46/opengl46renderer.h b/rendering/opengl46/opengl46renderer.h
index fa46ef3c0..588761868 100644
--- a/rendering/opengl46/opengl46renderer.h
+++ b/rendering/opengl46/opengl46renderer.h
@@ -53,6 +53,10 @@ http://mozilla.org/MPL/2.0/.
#include "rendering/common/temporalaa.h"
#include "rendering/common/screenreflections.h"
+#include
+#include
+#include
+
// bare-bones render controller, in lack of anything better yet
class opengl46_renderer : public gfx_renderer, public gfx::scene_walk {
public:
@@ -228,7 +232,6 @@ class opengl46_renderer : public gfx_renderer, public gfx::scene_walk {
void walk_glare(bool const Enabled) override;
void walk_glare_draw(TSubModel *Submodel, gfx::geometry_handle const &Geometry) override;
void walk_light_query(TSubModel *Submodel, bool const Begin) override;
- void walk_light_reference(gfx::geometry_handle const &Geometry) override;
// the gpu culling of the instances, models and sleepers, the depth pass of the whole scene
void walk_region_begin() override;
void walk_editor_cursor() override;
@@ -849,13 +852,37 @@ class opengl46_renderer : public gfx_renderer, public gfx::scene_walk {
unsigned int m_editor_overlay_revision{0};
std::unique_ptr m_freespot_shader;
std::unique_ptr m_billboard_shader;
- // the glare of a lamp as bright as the part of its point seen: the submodel of the point whose query is under way
- // (walk_light_query()), the samples of the point drawn without the depth test (walk_light_reference()), the samples counted
- // for the point (seen and all) written there by the gpu, and whether they were for the glare which follows
- TSubModel *m_glarequerysubmodel { nullptr };
- std::optional m_glarequery;
- std::unique_ptr m_glaressbo;
- bool m_glaresamples { false };
+ // the glare of a light point is as bright as the part of its point seen in the main view, counted by a pair of occlusion
+ // queries of its own for each light point of each model (the submodel and the instance drawn, TSubModel::iInstance): the
+ // samples which passed the depth test and all of them. the results are read once the gpu has them, without waiting, so the
+ // glare follows its point a frame or two late
+ struct glare_key
+ {
+ TSubModel const *submodel{nullptr};
+ std::uintptr_t instance{0};
+ bool operator==(glare_key const &) const = default;
+ };
+ struct glare_key_hash
+ {
+ std::size_t operator()(glare_key const &Key) const
+ {
+ return std::hash{}(Key.submodel) ^ (std::hash{}(Key.instance) * 31u);
+ }
+ };
+ struct glare_visibility
+ {
+ gl::query seen{gl::query::SAMPLES_PASSED};
+ gl::query all{gl::query::SAMPLES_PASSED};
+ bool pending{false}; // the queries were issued and their results aren't read yet
+ float share{0.f}; // the part of the point seen, by the last results read
+ unsigned int frame{0}; // the frame the point was last drawn in the main view
+ };
+ // the visibility of the point the walk draws, for the queries around it (walk_light_query())
+ glare_visibility *glare_entry(TSubModel const *Submodel, bool Create);
+ static void glare_read(glare_visibility &Entry);
+ std::unordered_map m_glares;
+ glare_visibility *m_glarequery{nullptr}; // the entry whose queries are under way
+ unsigned int m_glarepruned{0}; // the frame the entries of points no longer drawn were last dropped
std::unique_ptr m_celestial_shader;
std::unique_ptr m_hiddenarea_shader;
std::unique_ptr m_copy_shader;
diff --git a/shaders/ogl46/billboard.frag b/shaders/ogl46/billboard.frag
index 1182d06dd..42f3e64d3 100644
--- a/shaders/ogl46/billboard.frag
+++ b/shaders/ogl46/billboard.frag
@@ -11,21 +11,9 @@ layout(binding = 0) uniform sampler2D tex1;
layout(location = 0) out vec4 out_color;
layout(location = 1) out vec4 out_motion;
-// the samples of the point of the lamp its occlusion queries counted (the opengl renderer, with param[1].w 1): the glare is as
-// bright as the part of the point which is seen
-layout(std430, binding = GLARE_SSBO_BINDING) readonly buffer glare_ssbo
-{
- uint glare_seen;
- uint glare_all;
-};
-
void main()
{
vec4 tex_color = texture(tex1, f_coord);
- if (param[1].w > 0.5f)
- {
- tex_color.a *= (glare_all > 0u ? clamp(float(glare_seen) / float(glare_all), 0.0f, 1.0f) : 0.0f);
- }
if (POSTFX_ENABLED)
{
out_color = tex_color * param[0];
diff --git a/shaders/ogl46/common.glsl b/shaders/ogl46/common.glsl
index 7fbaca131..9c0a2ada4 100644
--- a/shaders/ogl46/common.glsl
+++ b/shaders/ogl46/common.glsl
@@ -119,7 +119,6 @@
#define SKY_OCCLUSION_TEX 30
#define CAB_PROBE_MASK_TEX 31
#define CAB_PROBE_SSBO_BINDING 17
-#define GLARE_SSBO_BINDING 18
#define CAB_PROBE_SH_SIZE 16
#define CAB_PROBE_SH_GROUP_SIZE 64
#define WEATHER_UBO_BINDING 5
From c7c17e9b9fe53c43db04a59fb08fcea26606c464 Mon Sep 17 00:00:00 2001
From: pwarszawski
Date: Mon, 16 Nov 2026 17:48:44 +0100
Subject: [PATCH 007/174] gl46: leave the character set of text displays out of
the sky occlusion
The sky occlusion gathered the children of a text display like any other
geometry, so the whole character set of a station name board was baked in,
every character at the place of the first one. The children of a text
sub-model are skipped now.
---
rendering/common/skyocclusion.cpp | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/rendering/common/skyocclusion.cpp b/rendering/common/skyocclusion.cpp
index 4aef4cce1..8b6238507 100644
--- a/rendering/common/skyocclusion.cpp
+++ b/rendering/common/skyocclusion.cpp
@@ -165,6 +165,13 @@ double shape_reach(scene::shape_node &Shape)
return (radius > 0.0 ? radius : std::numeric_limits::max());
}
+// the sub-models under the given one which are geometry of the model. the children of a text display are its whole
+// character set, not the characters it shows, and are left out
+TSubModel *geometry_children(TSubModel const *Submodel)
+{
+ return (Submodel->eType == TP_TEXT ? nullptr : Submodel->Child);
+}
+
} // namespace
sky_occlusion::layout sky_occlusion::layout_of(int const Level)
@@ -848,7 +855,7 @@ void sky_occlusion::gather_submodel(TSubModel *Submodel, std::uint32_t const Alp
}
}
if (part->Child != nullptr)
- gather_submodel(part->Child, Alpha, transform, Corner, Far, Triangles);
+ gather_submodel(geometry_children(part), Alpha, transform, Corner, Far, Triangles);
}
}
From 139f15ac88cc4cb3df55fccb5e99e07f81c02cd4 Mon Sep 17 00:00:00 2001
From: jerrrrycho
Date: Fri, 20 Nov 2026 18:29:46 +0100
Subject: [PATCH 008/174] ci: cache the Linux compiler output with ccache
---
.github/workflows/build_bin.yml | 37 +++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/.github/workflows/build_bin.yml b/.github/workflows/build_bin.yml
index fed45a44b..a4e8097ff 100644
--- a/.github/workflows/build_bin.yml
+++ b/.github/workflows/build_bin.yml
@@ -252,6 +252,7 @@ jobs:
# Without them it builds with OSS only, which modern distributions and the Steam Linux Runtime don't have: no sound.
sudo apt-get install -y \
build-essential \
+ ccache \
libasound2-dev \
libpulse-dev \
libpipewire-0.3-dev \
@@ -309,11 +310,34 @@ jobs:
cmake --version
python --version
+ # The compiler cache (ccache), one per variant. Only the runs on staging and master save it (the step after the
+ # build); a pull request takes the newest one of its variant, and so recompiles just what it changed. A pull
+ # request can read the caches of its base branch and of the default branch, not those of other pull requests.
+ # The compiler version is in the key, so a new GCC of the runner image starts a cache of its own.
+ - name: Compiler cache key
+ id: ccache-key
+ run: echo "gcc=$(g++ -dumpfullversion)" >> "$GITHUB_OUTPUT"
+
+ - name: Restore the compiler cache
+ uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
+ with:
+ path: ${{ runner.temp }}/ccache
+ key: ccache-linux-${{ matrix.variant.suffix }}-gcc${{ steps.ccache-key.outputs.gcc }}-${{ github.sha }}
+ restore-keys: |
+ ccache-linux-${{ matrix.variant.suffix }}-gcc${{ steps.ccache-key.outputs.gcc }}-
+ ccache-linux-${{ matrix.variant.suffix }}-
+
- name: Configure
+ env:
+ CCACHE_DIR: ${{ runner.temp }}/ccache
+ CCACHE_MAXSIZE: 500M
run: |
+ ccache --zero-stats
cmake \
-S . \
-B build \
+ -DCMAKE_C_COMPILER_LAUNCHER=ccache \
+ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_BUILD_TYPE="${CONFIG_LINUX}" \
-DWITH_BETTER_RENDERER=OFF \
-DWITH_ZMQ=OFF \
@@ -323,11 +347,24 @@ jobs:
-DPython3_EXECUTABLE="${{ steps.python.outputs.python-path }}" \
-DCMAKE_CXX_FLAGS="-Wno-attributes -fno-inline-functions-called-once"
+ # CCACHE_BASEDIR makes the paths relative, so a cache made on another checkout path still hits
- name: Build
+ env:
+ CCACHE_DIR: ${{ runner.temp }}/ccache
+ CCACHE_MAXSIZE: 500M
+ CCACHE_BASEDIR: ${{ github.workspace }}
run: |
cmake \
--build build \
--parallel "$(nproc)"
+ ccache --show-stats
+
+ - name: Save the compiler cache
+ if: ${{ !cancelled() && github.event_name == 'push' && (github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/master') }}
+ uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
+ with:
+ path: ${{ runner.temp }}/ccache
+ key: ccache-linux-${{ matrix.variant.suffix }}-gcc${{ steps.ccache-key.outputs.gcc }}-${{ github.sha }}
# the build copies the shared libraries next to the game (CMake_modules/bundle_runtime_libs.cmake) and the
# game looks for them there first ($ORIGIN): each one it loads from outside build/bin has to be one of the system
From b64d4dab1a0f54a16e5886d4924b27ade78a078b Mon Sep 17 00:00:00 2001
From: jerrrrycho
Date: Fri, 20 Nov 2026 18:30:21 +0100
Subject: [PATCH 009/174] ci: build only the AVX2 variants on pull requests
---
.github/workflows/build_bin.yml | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
diff --git a/.github/workflows/build_bin.yml b/.github/workflows/build_bin.yml
index a4e8097ff..a3cd2e5d1 100644
--- a/.github/workflows/build_bin.yml
+++ b/.github/workflows/build_bin.yml
@@ -45,13 +45,9 @@ jobs:
strategy:
fail-fast: false
matrix:
- variant:
- - name: "AVX2"
- suffix: "avx2"
- cmake_flags: "-DENABLE_AVX2=ON"
- - name: "No AVX2"
- suffix: "noavx2"
- cmake_flags: "-DENABLE_AVX2=OFF"
+ # a pull request builds the AVX2 variant only; the variant without AVX2 (the same sources, one compiler
+ # switch) is built by the pushes to the branches and by a manual run
+ variant: ${{ fromJSON(github.event_name == 'pull_request' && '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"}]' || '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"},{"name":"No AVX2","suffix":"noavx2","cmake_flags":"-DENABLE_AVX2=OFF"}]') }}
steps:
- name: Checkout repository
@@ -215,13 +211,9 @@ jobs:
strategy:
fail-fast: false
matrix:
- variant:
- - name: "AVX2"
- suffix: "avx2"
- cmake_flags: "-DENABLE_AVX2=ON"
- - name: "No AVX2"
- suffix: "noavx2"
- cmake_flags: "-DENABLE_AVX2=OFF"
+ # a pull request builds the AVX2 variant only; the variant without AVX2 (the same sources, one compiler
+ # switch) is built by the pushes to the branches and by a manual run
+ variant: ${{ fromJSON(github.event_name == 'pull_request' && '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"}]' || '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"},{"name":"No AVX2","suffix":"noavx2","cmake_flags":"-DENABLE_AVX2=OFF"}]') }}
steps:
- name: Checkout repository
From dc4fbb56f4493427d9e21145f4e08b0fe111cd45 Mon Sep 17 00:00:00 2001
From: jerrrrycho
Date: Fri, 20 Nov 2026 18:33:03 +0100
Subject: [PATCH 010/174] ci: skip the coverage build for documentation-only
pull requests
---
.github/workflows/coverage.yml | 40 ++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
index d2f00bccd..3a05010f2 100644
--- a/.github/workflows/coverage.yml
+++ b/.github/workflows/coverage.yml
@@ -28,8 +28,48 @@ concurrency:
cancel-in-progress: true
jobs:
+ # A pull request that changes only documentation doesn't need the coverage build. The check is a job-level
+ # condition, not `paths-ignore` on the trigger: a workflow that doesn't start leaves a required check "pending"
+ # for ever, while a skipped job (its name is fixed) counts as passed. A push, and anything this step can't
+ # decide, runs the build.
+ changes:
+ name: Which files changed
+ runs-on: ubuntu-24.04
+ timeout-minutes: 5
+ permissions:
+ pull-requests: read
+ outputs:
+ code: ${{ steps.files.outputs.code }}
+ steps:
+ - name: List the changed files
+ id: files
+ env:
+ GH_TOKEN: ${{ github.token }}
+ EVENT_NAME: ${{ github.event_name }}
+ REPO: ${{ github.repository }}
+ PR_NUMBER: ${{ github.event.pull_request.number }}
+ run: |
+ if [ "$EVENT_NAME" != pull_request ]; then
+ echo "code=true" >> "$GITHUB_OUTPUT"
+ exit 0
+ fi
+ if ! files="$(gh api --paginate "repos/$REPO/pulls/$PR_NUMBER/files" --jq '.[].filename')" || [ -z "$files" ]; then
+ echo "The list of changed files is not available, building."
+ echo "code=true" >> "$GITHUB_OUTPUT"
+ exit 0
+ fi
+ # what is not documentation: *.md, docs/ and LICENSE (not *.txt: CMakeLists.txt is code)
+ if printf '%s\n' "$files" | grep -Evq '(\.md$|^docs/|^LICENSE)'; then
+ echo "code=true" >> "$GITHUB_OUTPUT"
+ else
+ echo "Only documentation changed, the coverage build is skipped."
+ echo "code=false" >> "$GITHUB_OUTPUT"
+ fi
+
coverage:
name: Unit test coverage (GCC)
+ needs: changes
+ if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 60
permissions:
From 8f64a27ba65ca5d558c812ef911a00a79d919259 Mon Sep 17 00:00:00 2001
From: pwarszawski
Date: Sat, 14 Nov 2026 14:42:29 +0100
Subject: [PATCH 011/174] Derive flat normals for scenery shapes with zero
normals
Legacy scenery triangles (e.g. pkp/szafa-przek1.inc) are often authored
with 0 0 0 normals. normalize() of a zero vector yields NaN in the
shaders, and since gl46 ambient/envmap/sky-occlusion terms all depend on
the normal, such surfaces render completely black. Fill missing normals
with the triangle face normal on text import and when loading binary
terrain caches.
---
scene/scenenode.cpp | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/scene/scenenode.cpp b/scene/scenenode.cpp
index 426f0e077..0caa62930 100644
--- a/scene/scenenode.cpp
+++ b/scene/scenenode.cpp
@@ -87,6 +87,39 @@ shape_node::shapenode_data::serialize( std::ostream &Output ) const {
}
}
+namespace {
+
+// legacy scenery shapes frequently come with all-zero normals (e.g. pkp/szafa-przek1.inc).
+// the shaders normalize the interpolated normal, which turns a zero vector into NaN; with the gl46
+// lighting (ambient sh, envmap, sky occlusion all depend on the normal) that blackens the whole surface.
+// replace missing normals with the flat normal of the triangle, using the same winding as authored data
+void
+fill_missing_normals( std::vector &Vertices ) {
+
+ for( std::size_t idx = 0; idx + 2 < Vertices.size(); idx += 3 ) {
+ auto *triangle { &Vertices[ idx ] };
+ if( ( glm::length2( triangle[ 0 ].normal ) > 1e-12f )
+ && ( glm::length2( triangle[ 1 ].normal ) > 1e-12f )
+ && ( glm::length2( triangle[ 2 ].normal ) > 1e-12f ) ) {
+ continue;
+ }
+ auto const facenormal { glm::cross(
+ triangle[ 1 ].position - triangle[ 0 ].position,
+ triangle[ 2 ].position - triangle[ 0 ].position ) };
+ auto const normal { (
+ glm::length2( facenormal ) > 0.0 ?
+ glm::vec3{ glm::normalize( facenormal ) } :
+ glm::vec3{ 0.f, 1.f, 0.f } ) };
+ for( int vertexidx = 0; vertexidx < 3; ++vertexidx ) {
+ if( glm::length2( triangle[ vertexidx ].normal ) <= 1e-12f ) {
+ triangle[ vertexidx ].normal = normal;
+ }
+ }
+ }
+}
+
+} // namespace
+
// restores content of the struct from provided input stream
void
shape_node::shapenode_data::deserialize( std::istream &Input ) {
@@ -118,6 +151,8 @@ shape_node::shapenode_data::deserialize( std::istream &Input ) {
if(has_userdata)
userdata[i].deserialize( Input );
}
+ // binary caches created by older builds may still hold the zero normals
+ fill_missing_normals( vertices );
}
@@ -312,6 +347,8 @@ shape_node::import( cParser &Input, scene::node_data const &Nodedata ) {
} while( token != "endtri"
&& false == token.empty() ); // data which ends without closing the node would otherwise keep the loop going forever
+ fill_missing_normals( m_data.vertices );
+
return *this;
}
From 22c41c023ba0d308b8a188c2d9b6a76e38dfde12 Mon Sep 17 00:00:00 2001
From: pwarszawski
Date: Sun, 22 Nov 2026 11:46:37 +0100
Subject: [PATCH 012/174] Fill zero normals of terrain loaded from .btf files
A .btf file written by an older build keeps the zero normals of its
text, and it isn't rebuilt while it is newer than the text. Its reader
builds the shapes on its own, so it fills them the same way as the
text and the .sbt readers.
---
scene/scenenode.cpp | 4 ----
scene/scenenode.h | 3 +++
scene/sceneterrain.cpp | 2 ++
3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/scene/scenenode.cpp b/scene/scenenode.cpp
index 0caa62930..d98c83092 100644
--- a/scene/scenenode.cpp
+++ b/scene/scenenode.cpp
@@ -87,8 +87,6 @@ shape_node::shapenode_data::serialize( std::ostream &Output ) const {
}
}
-namespace {
-
// legacy scenery shapes frequently come with all-zero normals (e.g. pkp/szafa-przek1.inc).
// the shaders normalize the interpolated normal, which turns a zero vector into NaN; with the gl46
// lighting (ambient sh, envmap, sky occlusion all depend on the normal) that blackens the whole surface.
@@ -118,8 +116,6 @@ fill_missing_normals( std::vector &Vertices ) {
}
}
-} // namespace
-
// restores content of the struct from provided input stream
void
shape_node::shapenode_data::deserialize( std::istream &Input ) {
diff --git a/scene/scenenode.h b/scene/scenenode.h
index f10ac0d16..f1c9c43ae 100644
--- a/scene/scenenode.h
+++ b/scene/scenenode.h
@@ -74,6 +74,9 @@ struct node_data {
instance_handle instance { 0 }; // include of an *.inc template which defines the node, if it isn't defined directly by a scenery layer file
};
+// gives the vertices of each triangle with a zero normal the flat normal of the triangle, by its authored winding
+void fill_missing_normals( std::vector &Vertices );
+
// holds unique piece of geometry, covered with single material
class shape_node
{
diff --git a/scene/sceneterrain.cpp b/scene/sceneterrain.cpp
index d0453f2b3..044300812 100644
--- a/scene/sceneterrain.cpp
+++ b/scene/sceneterrain.cpp
@@ -1130,6 +1130,8 @@ void terrain_file::load(basic_section &Section, terrain_block const &Block)
vertex.texture.t = std::clamp(vertex.texture.t, 0.001f, 0.999f);
}
}
+ // a file written by an older build can hold the zero normals of its text
+ fill_missing_normals(shapedata.vertices);
if (true == shapedata.translucent || shapedata.rangesquared_max <= 90000.0 || shapedata.rangesquared_min > 0.0)
{
From b9e5ec51a83f5fd5118db654544c245b7f498150 Mon Sep 17 00:00:00 2001
From: jerrrrycho
Date: Sun, 22 Nov 2026 19:17:59 +0100
Subject: [PATCH 013/174] ci: ccache through the precompiled header, both
variants for forks, renamed files counted
- ccache caches the files built with the precompiled header (stdafx.h) only with
CCACHE_SLOPPINESS pch_defines,time_macros (plus the include file times); without
it every such file was compiled in full while the cache was still restored and saved
- a pull request from a fork has no push run here, so it builds the variant without
AVX2 too; a branch of this repository still builds only the AVX2 one
- the docs-only check also counts the old name of a renamed file, so moving code
out to docs/ or a .md name doesn't skip the coverage build
- no fallback to the cache of another GCC, which ccache can't use
Review of maj00r on #434.
---
.github/workflows/build_bin.yml | 24 ++++++++++++++++--------
.github/workflows/coverage.yml | 2 +-
2 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/.github/workflows/build_bin.yml b/.github/workflows/build_bin.yml
index a3cd2e5d1..f0aad4891 100644
--- a/.github/workflows/build_bin.yml
+++ b/.github/workflows/build_bin.yml
@@ -45,9 +45,10 @@ jobs:
strategy:
fail-fast: false
matrix:
- # a pull request builds the AVX2 variant only; the variant without AVX2 (the same sources, one compiler
- # switch) is built by the pushes to the branches and by a manual run
- variant: ${{ fromJSON(github.event_name == 'pull_request' && '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"}]' || '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"},{"name":"No AVX2","suffix":"noavx2","cmake_flags":"-DENABLE_AVX2=OFF"}]') }}
+ # a pull request from a branch of this repository builds the AVX2 variant only; the variant without AVX2
+ # (the same sources, one compiler switch) is built by the push of that branch, by the pushes to staging
+ # and master and by a manual run. a pull request from a fork has no push run here, so it builds both
+ variant: ${{ fromJSON(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"}]' || '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"},{"name":"No AVX2","suffix":"noavx2","cmake_flags":"-DENABLE_AVX2=OFF"}]') }}
steps:
- name: Checkout repository
@@ -211,9 +212,10 @@ jobs:
strategy:
fail-fast: false
matrix:
- # a pull request builds the AVX2 variant only; the variant without AVX2 (the same sources, one compiler
- # switch) is built by the pushes to the branches and by a manual run
- variant: ${{ fromJSON(github.event_name == 'pull_request' && '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"}]' || '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"},{"name":"No AVX2","suffix":"noavx2","cmake_flags":"-DENABLE_AVX2=OFF"}]') }}
+ # a pull request from a branch of this repository builds the AVX2 variant only; the variant without AVX2
+ # (the same sources, one compiler switch) is built by the push of that branch, by the pushes to staging
+ # and master and by a manual run. a pull request from a fork has no push run here, so it builds both
+ variant: ${{ fromJSON(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"}]' || '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"},{"name":"No AVX2","suffix":"noavx2","cmake_flags":"-DENABLE_AVX2=OFF"}]') }}
steps:
- name: Checkout repository
@@ -305,7 +307,8 @@ jobs:
# The compiler cache (ccache), one per variant. Only the runs on staging and master save it (the step after the
# build); a pull request takes the newest one of its variant, and so recompiles just what it changed. A pull
# request can read the caches of its base branch and of the default branch, not those of other pull requests.
- # The compiler version is in the key, so a new GCC of the runner image starts a cache of its own.
+ # The compiler version is in the key, so a new GCC of the runner image starts a cache of its own, with no
+ # fallback to the cache of the old one, which ccache couldn't use (the compiler is part of its hash).
- name: Compiler cache key
id: ccache-key
run: echo "gcc=$(g++ -dumpfullversion)" >> "$GITHUB_OUTPUT"
@@ -317,12 +320,14 @@ jobs:
key: ccache-linux-${{ matrix.variant.suffix }}-gcc${{ steps.ccache-key.outputs.gcc }}-${{ github.sha }}
restore-keys: |
ccache-linux-${{ matrix.variant.suffix }}-gcc${{ steps.ccache-key.outputs.gcc }}-
- ccache-linux-${{ matrix.variant.suffix }}-
- name: Configure
env:
CCACHE_DIR: ${{ runner.temp }}/ccache
CCACHE_MAXSIZE: 500M
+ # the game and eu07_core use a precompiled header (stdafx.h): ccache caches such compilations only with
+ # this sloppiness, else it compiles every file in full
+ CCACHE_SLOPPINESS: pch_defines,time_macros,include_file_mtime,include_file_ctime
run: |
ccache --zero-stats
cmake \
@@ -345,6 +350,9 @@ jobs:
CCACHE_DIR: ${{ runner.temp }}/ccache
CCACHE_MAXSIZE: 500M
CCACHE_BASEDIR: ${{ github.workspace }}
+ # the game and eu07_core use a precompiled header (stdafx.h): ccache caches such compilations only with
+ # this sloppiness, else it compiles every file in full
+ CCACHE_SLOPPINESS: pch_defines,time_macros,include_file_mtime,include_file_ctime
run: |
cmake \
--build build \
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
index 3a05010f2..dbd79eee8 100644
--- a/.github/workflows/coverage.yml
+++ b/.github/workflows/coverage.yml
@@ -53,7 +53,7 @@ jobs:
echo "code=true" >> "$GITHUB_OUTPUT"
exit 0
fi
- if ! files="$(gh api --paginate "repos/$REPO/pulls/$PR_NUMBER/files" --jq '.[].filename')" || [ -z "$files" ]; then
+ if ! files="$(gh api --paginate "repos/$REPO/pulls/$PR_NUMBER/files" --jq '.[] | .filename, (.previous_filename // empty)')" || [ -z "$files" ]; then
echo "The list of changed files is not available, building."
echo "code=true" >> "$GITHUB_OUTPUT"
exit 0
From e6611341de196056aacd404bd75df9cda7ac7ae7 Mon Sep 17 00:00:00 2001
From: jerrrrycho
Date: Wed, 25 Nov 2026 02:21:38 +0100
Subject: [PATCH 014/174] ci: a saved compiler cache replaces the older ones of
its branch
Every push to staging or master saved a new cache key of up to 0.5 GB
and nothing deleted the old ones, so master alone would pass the 10 GB
of the repository in a week and push out the small caches. The Linux
job now deletes the older ccache entries of its branch and variant right
after a save (actions: write on that job). The comments say a feature
branch push hits only master's cache, and that the No AVX2 jobs of a
pull request never run, so they can't be a required check.
---
.github/workflows/build_bin.yml | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/.github/workflows/build_bin.yml b/.github/workflows/build_bin.yml
index f0aad4891..b44a71590 100644
--- a/.github/workflows/build_bin.yml
+++ b/.github/workflows/build_bin.yml
@@ -47,7 +47,8 @@ jobs:
matrix:
# a pull request from a branch of this repository builds the AVX2 variant only; the variant without AVX2
# (the same sources, one compiler switch) is built by the push of that branch, by the pushes to staging
- # and master and by a manual run. a pull request from a fork has no push run here, so it builds both
+ # and master and by a manual run. a pull request from a fork has no push run here, so it builds both.
+ # so the "No AVX2" jobs of a pull request of this repository never run: don't make them a required check
variant: ${{ fromJSON(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"}]' || '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"},{"name":"No AVX2","suffix":"noavx2","cmake_flags":"-DENABLE_AVX2=OFF"}]') }}
steps:
@@ -204,6 +205,10 @@ jobs:
linux:
name: Linux x64 / GCC / ${{ matrix.variant.name }}
runs-on: ubuntu-24.04
+ # actions: write only to delete the older compiler caches after a save (the step after "Save the compiler cache")
+ permissions:
+ contents: read
+ actions: write
# see the notes above the windows job: two variants, each with a concurrency group of its own
concurrency:
group: ${{ github.workflow }}-linux-${{ matrix.variant.suffix }}-${{ github.event_name }}-${{ github.ref == 'refs/heads/master' && github.sha || github.ref }}
@@ -305,8 +310,10 @@ jobs:
python --version
# The compiler cache (ccache), one per variant. Only the runs on staging and master save it (the step after the
- # build); a pull request takes the newest one of its variant, and so recompiles just what it changed. A pull
- # request can read the caches of its base branch and of the default branch, not those of other pull requests.
+ # build) and delete their older ones; a pull request takes the newest one of its variant, and so recompiles just
+ # what it changed. A pull request can read the caches of its base branch and of the default branch, not those of
+ # other pull requests. A push of another branch can read only master's, so it hits only as far as the branch
+ # still matches master.
# The compiler version is in the key, so a new GCC of the runner image starts a cache of its own, with no
# fallback to the cache of the old one, which ccache couldn't use (the compiler is part of its hash).
- name: Compiler cache key
@@ -360,12 +367,29 @@ jobs:
ccache --show-stats
- name: Save the compiler cache
+ id: ccache-save
if: ${{ !cancelled() && github.event_name == 'push' && (github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/master') }}
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ runner.temp }}/ccache
key: ccache-linux-${{ matrix.variant.suffix }}-gcc${{ steps.ccache-key.outputs.gcc }}-${{ github.sha }}
+ # a cache can't be written over, so every save above is a new key of up to 0.5 GB. the older ones of this branch
+ # and variant (of any GCC) go right after it, or they'd fill the 10 GB of the repository and push out the small
+ # caches (audio-dlls-*, apt-*). a failed delete only leaves the old cache to the eviction
+ - name: Delete the older compiler caches
+ if: ${{ !cancelled() && steps.ccache-save.outcome == 'success' }}
+ env:
+ GH_TOKEN: ${{ github.token }}
+ PREFIX: ccache-linux-${{ matrix.variant.suffix }}-
+ KEEP: ccache-linux-${{ matrix.variant.suffix }}-gcc${{ steps.ccache-key.outputs.gcc }}-${{ github.sha }}
+ run: |
+ gh cache list --repo "$GITHUB_REPOSITORY" --ref "$GITHUB_REF" --key "$PREFIX" --limit 100 --json id,key \
+ --jq ".[] | select(.key != env.KEEP) | .id" |
+ while read -r id; do
+ gh cache delete "$id" --repo "$GITHUB_REPOSITORY" || echo "::warning::cache $id not deleted"
+ done
+
# the build copies the shared libraries next to the game (CMake_modules/bundle_runtime_libs.cmake) and the
# game looks for them there first ($ORIGIN): each one it loads from outside build/bin has to be one of the system
- name: Check the bundled libraries
From b47de97e550c2b3a0cf7546c3b488cef3cc4a0f4 Mon Sep 17 00:00:00 2001
From: jerrrrycho
Date: Thu, 26 Nov 2026 05:25:32 +0100
Subject: [PATCH 015/174] ci: keep the newest cache when two runs finish
together; write permission only in the cleanup job
---
.github/workflows/build_bin.yml | 66 ++++++++++++++++++++++++---------
1 file changed, 48 insertions(+), 18 deletions(-)
diff --git a/.github/workflows/build_bin.yml b/.github/workflows/build_bin.yml
index b44a71590..dc612e0fd 100644
--- a/.github/workflows/build_bin.yml
+++ b/.github/workflows/build_bin.yml
@@ -205,10 +205,11 @@ jobs:
linux:
name: Linux x64 / GCC / ${{ matrix.variant.name }}
runs-on: ubuntu-24.04
- # actions: write only to delete the older compiler caches after a save (the step after "Save the compiler cache")
- permissions:
- contents: read
- actions: write
+ # the key of a compiler cache saved here, one output per variant (a matrix job's outputs are shared by its legs):
+ # the job linux-ccache-cleanup deletes the older ones, so this job needs no write access
+ outputs:
+ ccache-key-avx2: ${{ steps.ccache-saved.outputs.avx2 }}
+ ccache-key-noavx2: ${{ steps.ccache-saved.outputs.noavx2 }}
# see the notes above the windows job: two variants, each with a concurrency group of its own
concurrency:
group: ${{ github.workflow }}-linux-${{ matrix.variant.suffix }}-${{ github.event_name }}-${{ github.ref == 'refs/heads/master' && github.sha || github.ref }}
@@ -219,7 +220,8 @@ jobs:
matrix:
# a pull request from a branch of this repository builds the AVX2 variant only; the variant without AVX2
# (the same sources, one compiler switch) is built by the push of that branch, by the pushes to staging
- # and master and by a manual run. a pull request from a fork has no push run here, so it builds both
+ # and master and by a manual run. a pull request from a fork has no push run here, so it builds both.
+ # so the "No AVX2" jobs of a pull request of this repository never run: don't make them a required check
variant: ${{ fromJSON(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"}]' || '[{"name":"AVX2","suffix":"avx2","cmake_flags":"-DENABLE_AVX2=ON"},{"name":"No AVX2","suffix":"noavx2","cmake_flags":"-DENABLE_AVX2=OFF"}]') }}
steps:
@@ -374,21 +376,13 @@ jobs:
path: ${{ runner.temp }}/ccache
key: ccache-linux-${{ matrix.variant.suffix }}-gcc${{ steps.ccache-key.outputs.gcc }}-${{ github.sha }}
- # a cache can't be written over, so every save above is a new key of up to 0.5 GB. the older ones of this branch
- # and variant (of any GCC) go right after it, or they'd fill the 10 GB of the repository and push out the small
- # caches (audio-dlls-*, apt-*). a failed delete only leaves the old cache to the eviction
- - name: Delete the older compiler caches
+ # for the job linux-ccache-cleanup, which deletes the older caches of this branch and variant
+ - name: Pass on the saved compiler cache key
+ id: ccache-saved
if: ${{ !cancelled() && steps.ccache-save.outcome == 'success' }}
env:
- GH_TOKEN: ${{ github.token }}
- PREFIX: ccache-linux-${{ matrix.variant.suffix }}-
- KEEP: ccache-linux-${{ matrix.variant.suffix }}-gcc${{ steps.ccache-key.outputs.gcc }}-${{ github.sha }}
- run: |
- gh cache list --repo "$GITHUB_REPOSITORY" --ref "$GITHUB_REF" --key "$PREFIX" --limit 100 --json id,key \
- --jq ".[] | select(.key != env.KEEP) | .id" |
- while read -r id; do
- gh cache delete "$id" --repo "$GITHUB_REPOSITORY" || echo "::warning::cache $id not deleted"
- done
+ KEY: ccache-linux-${{ matrix.variant.suffix }}-gcc${{ steps.ccache-key.outputs.gcc }}-${{ github.sha }}
+ run: echo "${{ matrix.variant.suffix }}=$KEY" >> "$GITHUB_OUTPUT"
# the build copies the shared libraries next to the game (CMake_modules/bundle_runtime_libs.cmake) and the
# game looks for them there first ($ORIGIN): each one it loads from outside build/bin has to be one of the system
@@ -453,6 +447,42 @@ jobs:
retention-days: 14
+ # a cache can't be written over, so every save of the linux job is a new key of up to 0.5 GB. the older ones of the
+ # branch and variant (of any GCC) go right after it, or they'd fill the 10 GB of the repository and push out the
+ # small caches (audio-dlls-*, apt-*). only the caches created before the one saved go: when two runs of a branch end
+ # together, the one which saved later keeps its cache. a failed delete only leaves the old cache to the eviction
+ linux-ccache-cleanup:
+ name: Linux / delete the older compiler caches
+ needs: linux
+ if: ${{ !cancelled() && (needs.linux.outputs.ccache-key-avx2 != '' || needs.linux.outputs.ccache-key-noavx2 != '') }}
+ runs-on: ubuntu-24.04
+ permissions:
+ actions: write
+
+ steps:
+ - name: Delete the older compiler caches
+ env:
+ GH_TOKEN: ${{ github.token }}
+ SAVED: ${{ needs.linux.outputs.ccache-key-avx2 }} ${{ needs.linux.outputs.ccache-key-noavx2 }}
+ run: |
+ # the ids of the caches created before the one saved (env.KEEP); none when it isn't listed. the times are
+ # compared as numbers, as their fractions of a second can have any number of digits
+ older='
+ def t: capture("^(?[^.Z]+)(?[.][0-9]+)?Z$") | ((.s + "Z") | fromdateiso8601) + (("0" + (.f // "")) | tonumber);
+ (map(select(.key == env.KEEP)) | first | .createdAt) as $saved
+ | if $saved == null then empty else ($saved | t) as $at | .[] | select((.createdAt | t) < $at) | .id end'
+ for KEEP in $SAVED; do
+ export KEEP
+ # the key without its GCC version and commit: ccache-linux--
+ prefix="${KEEP%%-gcc*}-"
+ gh cache list --repo "$GITHUB_REPOSITORY" --ref "$GITHUB_REF" --key "$prefix" --limit 100 \
+ --json id,key,createdAt --jq "$older" |
+ while read -r id; do
+ gh cache delete "$id" --repo "$GITHUB_REPOSITORY" || echo "::warning::cache $id not deleted"
+ done
+ done
+
+
# ============================================================
# Public download: release assets need no GitHub account
# ============================================================
From d17e94c84e5801d1e7d1e46f59a0bd72cb4ab374 Mon Sep 17 00:00:00 2001
From: Hirek193
Date: Fri, 27 Nov 2026 16:21:42 +0100
Subject: [PATCH 016/174] refactor(mover): the vehicle type is an enum class
train_type, not dt_* bit constants
---
McZapkie/MOVER.h | 59 +++++++------
McZapkie/Mover.cpp | 147 +++++++++++++++++----------------
application/driveruipanels.cpp | 2 +-
tests/unit/drive.cpp | 2 +-
tests/unit/golden.cpp | 25 +++++-
tests/unit/test_cntrl.cpp | 6 +-
vehicle/Driver.cpp | 16 ++--
vehicle/Driver.h | 4 +-
vehicle/DynObj.cpp | 14 ++--
vehicle/Train.cpp | 42 +++++-----
widgets/vehicleparams.cpp | 2 +-
11 files changed, 175 insertions(+), 144 deletions(-)
diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h
index d5847cbc1..3c4f14b41 100644
--- a/McZapkie/MOVER.h
+++ b/McZapkie/MOVER.h
@@ -489,31 +489,33 @@ enum activation
neutraldirection = 1 << 7,
};
-// szczególne typy pojazdów (inna obsługa) dla zmiennej TrainType
-// zamienione na flagi bitowe, aby szybko wybierać grupę (np. EZT+SZT)
-// TODO: convert to enums, they're used as specific checks anyway
-/// Vehicle type flag: default (no special handling).
-static int const dt_Default = 0;
-/// Vehicle type flag: EZT (electric multiple unit).
-static int const dt_EZT = 1;
-/// Vehicle type flag: ET41 locomotive.
-static int const dt_ET41 = 2;
-/// Vehicle type flag: ET42 locomotive.
-static int const dt_ET42 = 4;
-/// Vehicle type flag: pseudo-diesel (electric drivetrain with diesel input model).
-static int const dt_PseudoDiesel = 8;
-/// Vehicle type flag: ET22 locomotive (added in Megapack).
-static int const dt_ET22 = 0x10; // używane od Megapacka
-/// Vehicle type flag: SN61 (set from CHK only, not used in conditions).
-static int const dt_SN61 = 0x20; // nie używane w warunkach, ale ustawiane z CHK
-/// Vehicle type flag: EP05 locomotive.
-static int const dt_EP05 = 0x40;
-/// Vehicle type flag: ET40 locomotive.
-static int const dt_ET40 = 0x80;
-/// Vehicle type flag: ŠKODA 181 locomotive.
-static int const dt_181 = 0x100;
-/// Vehicle type flag: DMU (diesel multiple unit).
-static int const dt_DMU = 0x200;
+/// The vehicles the code handles in a way of their own, by the Type of the Param section of the .fiz
+/// (TrainType). A vehicle is of one of them; a .fiz type not listed is generic.
+enum class train_type
+{
+ /// No handling of its own.
+ generic,
+ /// Electric multiple unit (Type=EZT).
+ emu,
+ /// Diesel multiple unit (Type=DMU).
+ dmu,
+ /// ET22 locomotive (Type=ET22, since the Megapack).
+ et22,
+ /// ET40 locomotive.
+ et40,
+ /// ET41 locomotive.
+ et41,
+ /// ET42 locomotive.
+ et42,
+ /// EP05 locomotive.
+ ep05,
+ /// SN61 railcar: the type is read, but nothing handles it on its own.
+ sn61,
+ /// Pseudo-diesel (an electric drivetrain with the input model of a diesel).
+ pseudodiesel,
+ /// Škoda 181 and 182 locomotives (Type=181 or 182).
+ skoda181,
+};
// stałe dla asynchronów
/// EIM config index: dfic — frequency rise rate at start.
@@ -1706,7 +1708,12 @@ class TMoverParameters
int CategoryFlag = 1; /*1 - pociag, 2 - samochod, 4 - statek, 8 - samolot*/
/*--sekcja stalych typowych parametrow*/
std::string TypeName; /*nazwa serii/typu*/
- int TrainType = 0; /*typ: EZT/elektrowoz - Winger 040304 Ra: powinno być szybciej niż string*/
+ train_type TrainType{train_type::generic}; // the vehicles of a handling of their own, from the Type of the .fiz
+ // an electric or a diesel multiple unit
+ bool is_multiple_unit() const
+ {
+ return TrainType == train_type::emu || TrainType == train_type::dmu;
+ }
TEngineType EngineType = TEngineType::None; /*typ napedu*/
TPowerParameters EnginePowerSource; /*zrodlo mocy dla silnikow*/
TPowerParameters SystemPowerSource; /*zrodlo mocy dla systemow sterowania/przetwornic/sprezarek*/
diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp
index 7ee85203a..466523d89 100644
--- a/McZapkie/Mover.cpp
+++ b/McZapkie/Mover.cpp
@@ -357,14 +357,14 @@ double TMoverParameters::Current(double n, double U)
ResistorsFlag = RList[MainCtrlActualPos].R > 0.01; // and (!DelayCtrlFlag)
ResistorsFlag = ResistorsFlag || (DynamicBrakeFlag == true && DynamicBrakeType == dbrake_automatic);
- if (TrainType == dt_ET22 && DelayCtrlFlag && MainCtrlActualPos > 1)
+ if (TrainType == train_type::et22 && DelayCtrlFlag && MainCtrlActualPos > 1)
Bn = 1.0 - 1.0 / RList[MainCtrlActualPos].Bn;
else
Bn = 1; // to jest wykonywane dla EU07
R = RList[MainCtrlActualPos].R * Bn + CircuitRes;
- if (TrainType != dt_EZT || Imin != IminLo || false == ScndS)
+ if (TrainType != train_type::emu || Imin != IminLo || false == ScndS)
{
// yBARC - boczniki na szeregu poprawnie
Mn = RList[MainCtrlActualPos].Mn; // to jest wykonywane dla EU07
@@ -414,7 +414,7 @@ double TMoverParameters::Current(double n, double U)
void TMoverParameters::UpdateSeriesMotorDynamicBrakeFlag()
{
// i dzialanie hamulca ED w EP09
- if (DynamicBrakeType == dbrake_automatic && TrainType != dt_EZT)
+ if (DynamicBrakeType == dbrake_automatic && TrainType != train_type::emu)
{
if ((Hamulec->GetEDBCP() < 0.25 && Vadd < 1) || BrakePress > 2.1)
DynamicBrakeFlag = false;
@@ -422,7 +422,7 @@ void TMoverParameters::UpdateSeriesMotorDynamicBrakeFlag()
DynamicBrakeFlag = true;
DynamicBrakeFlag = DynamicBrakeFlag && Power110vIsAvailable;
}
- if (DynamicBrakeType == dbrake_automatic && TrainType == dt_EZT)
+ if (DynamicBrakeType == dbrake_automatic && TrainType == train_type::emu)
{
DynamicBrakeFlag = Power110vIsAvailable && (TUHEX_Active || Vadd > TUHEX_MinIw) && DynamicBrakeEMUStatus;
}
@@ -472,7 +472,7 @@ double TMoverParameters::SeriesMotorCurrent(double const n, double const U, doub
MotorCurrent:=(U-Isf*Rz-Mn*fi*n+SQRT(Delta))/(2*Rz)
end*/
// only the ET42's switched brake brakes on the starting resistors, otherwise the current is cut off (0)
- if (DynamicBrakeType == dbrake_switch && TrainType == dt_ET42)
+ if (DynamicBrakeType == dbrake_switch && TrainType == train_type::et42)
{ // z Megapacka
Rz = WindingRes + R;
MotorCurrent = -motor_param(SP).fi * n / Rz; //{hamowanie silnikiem na oporach rozruchowych}
@@ -812,7 +812,7 @@ bool TMoverParameters::DirectionForward()
SendCtrlToNext("Direction", DirActive, CabActive);
return true;
}
- else if (DirActive == 1 && IsMainCtrlNoPowerPos() && TrainType == dt_EZT && EngineType != TEngineType::ElectricInductionMotor)
+ else if (DirActive == 1 && IsMainCtrlNoPowerPos() && TrainType == train_type::emu && EngineType != TEngineType::ElectricInductionMotor)
return MinCurrentSwitch(true); //"wysoki rozruch" EN57
return false;
};
@@ -916,7 +916,7 @@ bool TMoverParameters::CurrentSwitch(bool const State)
if (MaxCurrentSwitch(State))
{
- if (TrainType != dt_EZT)
+ if (TrainType != train_type::emu)
{
MinCurrentSwitch(State);
}
@@ -966,7 +966,7 @@ void TMoverParameters::UpdatePantVolume(double dt)
// włączona mała sprężarka
PantVolume += dt
// Ra 2013-12: Niebugocław mówi, że w EZT nabija 1.5 raz wolniej niż jak było 0.005
- * (TrainType == dt_EZT ? 0.003 : 0.005) / std::max(1.0, PantPress) * (0.45 - (0.1 / PantVolume / 10 - 0.1)) / 0.45;
+ * (TrainType == train_type::emu ? 0.003 : 0.005) / std::max(1.0, PantPress) * (0.45 - (0.1 / PantVolume / 10 - 0.1)) / 0.45;
}
PantPress = safe_clamp(10.0 * PantVolume - 1.0, 0.0, EnginePowerSource.CollectorParameters.MaxPress); // tu by się przydała objętość zbiornika
}
@@ -1019,14 +1019,14 @@ void TMoverParameters::PantPressureSwitchCheck()
void TMoverParameters::PantPressureSwitchTrip()
{
// opuszczenie pantografów przy niskim ciśnieniu
- if (TrainType != dt_EZT)
+ if (TrainType != train_type::emu)
{
// pressure switch safety measure -- open the line breaker, unless there's alternate source of traction voltage
// (the genset of a dual-mode vehicle, when the selector is on it, doesn't need the pantographs)
if (GetTrainsetHighVoltage() < EnginePowerSource.CollectorParameters.MinV && false == GensetSelected())
{
// TODO: check whether line breaker should be open EMU-wide
- MainSwitch(false, TrainType == dt_EZT ? range_t::unit : range_t::local);
+ MainSwitch(false, TrainType == train_type::emu ? range_t::unit : range_t::local);
}
}
else
@@ -1597,7 +1597,7 @@ void TMoverParameters::damage_coupler(int const End)
collision::vehicle_kind TMoverParameters::collision_kind() const
{
auto const powered{EngineType != TEngineType::None && EngineType != TEngineType::Dumb};
- auto const unit{(TrainType & (dt_EZT | dt_DMU)) != 0};
+ auto const unit{is_multiple_unit()};
auto const passengers{std::any_of(LoadAttributes.begin(), LoadAttributes.end(), [](auto const &Load) { return ToLower(Load.name).starts_with("passenger"); })};
// a coach heats its compartments; the crash zone is a matter of each end (crush_of())
return collision::kind_of(powered, unit || passengers || (false == powered && HeatingPower > 0.0), false);
@@ -2487,14 +2487,14 @@ void TMoverParameters::compute_movement_(double const Deltatime)
{
if (MotorOverloadRelayHighThreshold)
{ // set high threshold
- if (TrainType != dt_ET42 ? RList[MainCtrlPos].Bn < 2 : MainCtrlPos == 0)
+ if (TrainType != train_type::et42 ? RList[MainCtrlPos].Bn < 2 : MainCtrlPos == 0)
{
Imax = ImaxHi;
}
}
else
{ // set low threshold
- if (TrainType != dt_ET42 || MainCtrlPos == 0)
+ if (TrainType != train_type::et42 || MainCtrlPos == 0)
{
Imax = ImaxLo;
}
@@ -2660,7 +2660,7 @@ void TMoverParameters::MainsCheck(double const Deltatime)
// an emergency brake application made under power opens the line breaker, where the vehicle has such an interlock
if (Mains && EmergencyBrakeHoldsMainOff())
{
- MainSwitch(false, TrainType == dt_EZT ? range_t::unit : range_t::local);
+ MainSwitch(false, TrainType == train_type::emu ? range_t::unit : range_t::local);
}
}
@@ -3374,12 +3374,12 @@ bool TMoverParameters::IncMainCtrl(int CtrlSpeed)
// nie ma sterowania
return false;
}
- if (TrainType == dt_ET22 && ScndCtrlPos != 0)
+ if (TrainType == train_type::et22 && ScndCtrlPos != 0)
{
// w ET22 nie da się kręcić nastawnikiem przy włączonym boczniku
return false;
}
- if (TrainType == dt_EZT && DirActive == 0)
+ if (TrainType == train_type::emu && DirActive == 0)
{
// w EZT nie da się załączyć pozycji bez ustawienia kierunku
return false;
@@ -3506,7 +3506,7 @@ bool TMoverParameters::IncMainCtrlSeriesMotor(int const CtrlSpeed)
if (CtrlSpeed > 1)
{
// szybkie przejœcie na bezoporow¹
- if (TrainType == dt_ET40)
+ if (TrainType == train_type::et40)
{
return false; // this means ET40 won't react at all to fast acceleration command. should it issue just IncMainCtrl(1) instead?
}
@@ -3515,7 +3515,7 @@ bool TMoverParameters::IncMainCtrlSeriesMotor(int const CtrlSpeed)
// all work is done in the loop header
}
OK = false; // shouldn't this be part of the loop above?
- // if (TrainType=dt_ET40) then
+ // if (TrainType=train_type::et40) then
// while Abs (Im)>IminHi do
// dec(MainCtrlPos);
// OK:=false ;
@@ -3532,7 +3532,7 @@ bool TMoverParameters::IncMainCtrlSeriesMotor(int const CtrlSpeed)
SetFlag( SoundFlag, sound::relay );
}
*/
- if (TrainType == dt_ET42)
+ if (TrainType == train_type::et42)
{
--MainCtrlPos;
OK = false;
@@ -3548,7 +3548,7 @@ bool TMoverParameters::IncMainCtrlSeriesMotor(int const CtrlSpeed)
//}
}
- if (TrainType == dt_ET42 && true == DynamicBrakeFlag && MainCtrlPos > 20)
+ if (TrainType == train_type::et42 && true == DynamicBrakeFlag && MainCtrlPos > 20)
{
MainCtrlPos = 20;
OK = false;
@@ -3578,7 +3578,7 @@ bool TMoverParameters::DecMainCtrl(int CtrlSpeed)
// TBD, TODO: replace with mainctrlpowerpos() check?
if (MainCtrlPos > 0)
{
- if (TrainType != dt_ET22 || ScndCtrlPos == 0) // Ra: ET22 blokuje nastawnik przy boczniku
+ if (TrainType != train_type::et22 || ScndCtrlPos == 0) // Ra: ET22 blokuje nastawnik przy boczniku
{
if (CoupledCtrl && ScndCtrlPos > 0)
{
@@ -3677,10 +3677,10 @@ bool TMoverParameters::DecMainCtrlSeriesMotor(int const CtrlSpeed)
{
MainCtrlPos--;
// if (MainCtrlPos=0) and (ScndCtrlPos=0) and
- // (TrainType<>dt_ET40)and(TrainType<>dt_EP05) then
+ // (TrainType<>train_type::et40)and(TrainType<>train_type::ep05) then
// StLinFlag:=false;
- // if (MainCtrlPos=0) and (TrainType<>dt_ET40) and
- // (TrainType<>dt_EP05) then
+ // if (MainCtrlPos=0) and (TrainType<>train_type::et40) and
+ // (TrainType<>train_type::ep05) then
// MainCtrlActualPos:=0; //yBARC: co to tutaj robi? ;)
OK = true;
}
@@ -3778,11 +3778,11 @@ bool TMoverParameters::IncScndCtrl(int CtrlSpeed)
{
bool OK = false;
- if (DynamicBrakeFlag && TrainType == dt_ET42 && CabActive != 0 && IsMainCtrlNoPowerPos() && ScndCtrlPos == 0)
+ if (DynamicBrakeFlag && TrainType == train_type::et42 && CabActive != 0 && IsMainCtrlNoPowerPos() && ScndCtrlPos == 0)
{
OK = DynamicBrakeSwitch(false);
}
- else if (ScndCtrlPosNo > 0 && CabActive != 0 && !(TrainType == dt_ET42 && (Imax == ImaxHi || (DynamicBrakeFlag && MainCtrlPowerPos() > 0))))
+ else if (ScndCtrlPosNo > 0 && CabActive != 0 && !(TrainType == train_type::et42 && (Imax == ImaxHi || (DynamicBrakeFlag && MainCtrlPowerPos() > 0))))
{
// if (RList[MainCtrlPos].R=0) and (MainCtrlPos>0) and (ScndCtrlPos0
OK = DynamicBrakeSwitch(true);
@@ -3926,7 +3926,7 @@ void TMoverParameters::ScndCtrlResistiveLockCheck()
int TMoverParameters::GetVirtualScndPos() const
{
- if (TrainType == dt_ET42 && DynamicBrakeFlag && !ScndCtrlPos)
+ if (TrainType == train_type::et42 && DynamicBrakeFlag && !ScndCtrlPos)
return -1;
return ScndCtrlPos;
}
@@ -4348,7 +4348,7 @@ bool TMoverParameters::DirectionBackward(void)
return false;
}
- if (DirActive == 1 && MainCtrlPos == 0 && TrainType == dt_EZT && EngineType != TEngineType::ElectricInductionMotor && MinCurrentSwitch(false))
+ if (DirActive == 1 && MainCtrlPos == 0 && TrainType == train_type::emu && EngineType != TEngineType::ElectricInductionMotor && MinCurrentSwitch(false))
{
return true;
}
@@ -5222,7 +5222,7 @@ bool TMoverParameters::DynamicBrakeSwitch(bool Switch)
if (TestFlag(thiscoupler.CouplingFlag, coupling::control))
thiscoupler.Connected->DynamicBrakeFlag = Switch;
// end;
- // if (DynamicBrakeType=dbrake_passive) and (TrainType=dt_ET42) then
+ // if (DynamicBrakeType=dbrake_passive) and (TrainType=train_type::et42) then
// begin
// DynamicBrakeFlag:=false;
// DynamicBrakeSwitch:=false;
@@ -5391,7 +5391,7 @@ bool TMoverParameters::IncBrakePress(double &brake, double PressLimit, double dp
bool IBP;
// if (DynamicBrakeType<>dbrake_switch) and (DynamicBrakeType<>dbrake_none) and
// ((BrakePress>2.0) or (PipePress<3.7{(LowPipePress+0.5)})) then
- if (DynamicBrakeType != dbrake_switch && DynamicBrakeType != dbrake_none && BrakePress > 2.0 && TrainType != dt_EZT) // yB radzi nie sprawdzać ciśnienia w przewodzie
+ if (DynamicBrakeType != dbrake_switch && DynamicBrakeType != dbrake_none && BrakePress > 2.0 && TrainType != train_type::emu) // yB radzi nie sprawdzać ciśnienia w przewodzie
// hunter-301211: dla EN57 silnikow nie odlaczamy
{
DynamicBrakeFlag = true; // uruchamianie hamulca ED albo odlaczanie silnikow
@@ -5852,7 +5852,7 @@ double TMoverParameters::MainValveSupply()
LockPipe = PipePress < (LockPipe ? LockPipeOff : LockPipeOn);
bool lock_new = (LockPipe && !UnlockPipe && BrakeCtrlPosR > HandleUnlock) || (EmergencyCutsOffHandle && EmergencyValveFlow > 0); // new simple codition based on .fiz
bool lock_old = BrakeHandle == TBrakeHandle::FV4a // old complex condition based on assumptions
- && PipePress < 2.75 && (Hamulec->GetStatus() & b_rls) == 0 && BrakeSubsystem == TBrakeSubSystem::ss_LSt && TrainType != dt_EZT && !UnlockPipe;
+ && PipePress < 2.75 && (Hamulec->GetStatus() & b_rls) == 0 && BrakeSubsystem == TBrakeSubSystem::ss_LSt && TrainType != train_type::emu && !UnlockPipe;
if (lock_old || lock_new)
{
@@ -5928,10 +5928,11 @@ void TMoverParameters::UpdateDistributorSettings()
{
LocBrakePress = LocHandle->GetCP();
+ auto const et41or42 = [](train_type const Type) { return Type == train_type::et41 || Type == train_type::et42; };
for (auto const &couplerentry : Couplers)
// nie podoba mi się to rozwiązanie, chyba trzeba
// dodać jakiś wpis do fizyki na to
- if ((TrainType & (dt_ET41 | dt_ET42)) != 0 && couplerentry.Connected != nullptr && (couplerentry.Connected->TrainType & (dt_ET41 | dt_ET42)) != 0 && (couplerentry.CouplingFlag & 36) == 36)
+ if (et41or42(TrainType) && couplerentry.Connected != nullptr && et41or42(couplerentry.Connected->TrainType) && (couplerentry.CouplingFlag & 36) == 36)
LocBrakePress = std::max(couplerentry.Connected->LocHandle->GetCP(), LocBrakePress);
// if ((DynamicBrakeFlag) && (EngineType == ElectricInductionMotor))
@@ -6048,7 +6049,7 @@ void TMoverParameters::UpdateScndPipePressure(double dt)
Pipe2->Flow(Hamulec->GetHPFlow(ScndPipePress, dt));
// NOTE: condition disabled to allow the air flow from the main hose to the main tank as well
- if (/* ( ( Compressor > ScndPipePress ) && ( */ VeselVolume > 0.0 /* ) ) || ( TrainType == dt_EZT ) || ( TrainType == dt_DMU ) */)
+ if (/* ( ( Compressor > ScndPipePress ) && ( */ VeselVolume > 0.0 /* ) ) || ( TrainType == train_type::emu ) || ( TrainType == train_type::dmu ) */)
{
double const dV = PF(Compressor, ScndPipePress, Spz) * dt;
CompressedVolume += dV / 1000.0;
@@ -6507,7 +6508,7 @@ void TMoverParameters::ComputeTotalForce(double dt)
if (brakes_changed_asleep())
switch_physics(true, wake_cause::other);
- auto const vehicleisactive{CabActive != 0 || Vel > 0.0001 || accelerating() || LastSwitchingTime < 5 || TrainType == dt_EZT || TrainType == dt_DMU};
+ auto const vehicleisactive{CabActive != 0 || Vel > 0.0001 || accelerating() || LastSwitchingTime < 5 || is_multiple_unit()};
auto const movingvehicleahead{Neighbours[end::front].vehicle != nullptr &&
(Neighbours[end::front].vehicle->MoverParameters->Vel > 0.0001 || Neighbours[end::front].vehicle->MoverParameters->accelerating())};
@@ -6699,7 +6700,7 @@ double TMoverParameters::BrakeForceR(double ratio, double velocity) const
ratio = ratio + (1.5 - ratio) * std::min(1.0, Vel * 0.02);
if (BrakeDelayFlag & bdelay_R && BrakeMethod % 128 != bp_Cosid && BrakeMethod % 128 != bp_D1 && BrakeMethod % 128 != bp_D2 && Power < 1)
ratio *= Hamulec->GetRapidRatio(velocity);
- if (TrainType == dt_DMU && velocity < 30.0)
+ if (TrainType == train_type::dmu && velocity < 30.0)
{
ratio -= 0.3;
}
@@ -7508,7 +7509,7 @@ void TMoverParameters::VoltageRelaysCheck()
// wywalanie szybkiego z powodu niewłaściwego napięcia
// (a line breaker closed ahead of the pantographs holds without voltage)
EventFlag |= true == Mains && ((false == NoVoltRelay && false == PantographsRequireMains) || false == OvervoltageRelay) &&
- MainSwitch(false, TrainType == dt_EZT ? range_t::unit : range_t::local); // TODO: check whether we need to send this EMU-wide
+ MainSwitch(false, TrainType == train_type::emu ? range_t::unit : range_t::local); // TODO: check whether we need to send this EMU-wide
break;
}
@@ -7521,7 +7522,7 @@ void TMoverParameters::VoltageRelaysCheck()
if (Mains && ((TractionSupplyVoltage() < TractionSupplyMinVoltage() && false == PantographsRequireMains) ||
TractionSupplyVoltage() > EnginePowerSource.CollectorParameters.MaxV + 200))
{
- MainSwitch(false, TrainType == dt_EZT ? range_t::unit : range_t::local); // TODO: check whether we need to send this EMU-wide
+ MainSwitch(false, TrainType == train_type::emu ? range_t::unit : range_t::local); // TODO: check whether we need to send this EMU-wide
}
break;
}
@@ -7581,11 +7582,11 @@ void TMoverParameters::SeriesMotorTractionForce(double dt)
{
// enrot:=Transmision.Ratio*nrot;
// yB: szereg dwoch sekcji w ET42
- if (TrainType == dt_ET42 && Imax == ImaxHi)
+ if (TrainType == train_type::et42 && Imax == ImaxHi)
EngineVoltage = EngineVoltage / 2.0;
Mm = Momentum(Current(enrot, EngineVoltage)); // oblicza tez prad p/slinik
- if (TrainType == dt_ET42)
+ if (TrainType == train_type::et42)
{
if (Imax == ImaxHi)
EngineVoltage = EngineVoltage * 2;
@@ -7597,7 +7598,7 @@ void TMoverParameters::SeriesMotorTractionForce(double dt)
SeriesMotorDynamicBrake(dt);
}
- if (TrainType == dt_ET22 && DelayCtrlFlag) // szarpanie przy zmianie układu w byku
+ if (TrainType == train_type::et22 && DelayCtrlFlag) // szarpanie przy zmianie układu w byku
Mm = Mm * RList[MainCtrlActualPos].Bn / (RList[MainCtrlActualPos].Bn + 1); // zrobione w momencie, żeby nie dawac elektryki w przeliczaniu sił
if (abs(Im) > Imax)
@@ -7609,7 +7610,7 @@ void TMoverParameters::SeriesMotorTractionForce(double dt)
if ((DynamicBrakeType == dbrake_automatic || DynamicBrakeType == dbrake_switch) && DynamicBrakeFlag)
Itot = Im * 2; // 2x2 silniki w EP09
- else if (TrainType == dt_EZT && Imin == IminLo && ScndS) // yBARC - boczniki na szeregu poprawnie
+ else if (TrainType == train_type::emu && Imin == IminLo && ScndS) // yBARC - boczniki na szeregu poprawnie
Itot = Im;
else
Itot = Im * RList[MainCtrlActualPos].Bn; // prad silnika * ilosc galezi
@@ -8787,7 +8788,7 @@ bool TMoverParameters::MaxCurrentSwitch(bool State, range_t const Notify)
bool TMoverParameters::MinCurrentSwitch(bool State)
{
bool MCS = false;
- if ((EngineType == TEngineType::ElectricSeriesMotor && IminHi > IminLo) || (TrainType == dt_EZT && EngineType != TEngineType::ElectricInductionMotor))
+ if ((EngineType == TEngineType::ElectricSeriesMotor && IminHi > IminLo) || (TrainType == train_type::emu && EngineType != TEngineType::ElectricInductionMotor))
{
if (State && Imin == IminLo)
@@ -8919,7 +8920,7 @@ bool TMoverParameters::AutoRelayShuntStep(bool const ARFASI2)
}
else if (ScndCtrlActualPos > ScndCtrlPos)
{
- if (LastRelayTime > CtrlDownDelay && TrainType != dt_EZT)
+ if (LastRelayTime > CtrlDownDelay && TrainType != train_type::emu)
{
--ScndCtrlActualPos;
SetFlag(SoundFlag, sound::shuntfield);
@@ -8938,11 +8939,11 @@ bool TMoverParameters::AutoRelayMainStep(bool const ARFASI)
// running backwards, the motors don't get joined in more branches than allowed (the series connection
// alone, usually); the camshaft still goes back down from there (eu07/maszyna#393: it stayed where it
// was, the line contactors closed, whatever the driver did with the master controller)
- auto const backwardslimit{DirActive < 0 && TrainType != dt_PseudoDiesel && RList[MainCtrlActualPos + 1].Bn > BackwardsBranchesAllowed};
+ auto const backwardslimit{DirActive < 0 && TrainType != train_type::pseudodiesel && RList[MainCtrlActualPos + 1].Bn > BackwardsBranchesAllowed};
// main bez samoczynnego rozruchu
if (false == backwardslimit && MainCtrlActualPos < std::size(RList) - 1 // crude guard against running out of current fixed table
&& (RList[MainCtrlActualPos].Relay < MainCtrlPos || (RList[MainCtrlActualPos + 1].Relay == MainCtrlPos && MainCtrlActualPos < RlistSize) ||
- (TrainType == dt_ET22 && DelayCtrlFlag)))
+ (TrainType == train_type::et22 && DelayCtrlFlag)))
{
OK = AutoRelayMainUp(ARFASI);
}
@@ -9007,7 +9008,7 @@ bool TMoverParameters::AutoRelayMainNotchUp()
bool OK = false;
// WriteLog("LRT = " + FloatToStr(LastRelayTime) + ", " +
// FloatToStr(CtrlDelay));
- if (TrainType == dt_ET22 && MainCtrlPos > 1 && (RList[MainCtrlActualPos].Bn < RList[MainCtrlActualPos + 1].Bn || DelayCtrlFlag))
+ if (TrainType == train_type::et22 && MainCtrlPos > 1 && (RList[MainCtrlActualPos].Bn < RList[MainCtrlActualPos + 1].Bn || DelayCtrlFlag))
{
// et22 z walem grupowym
if (!DelayCtrlFlag) // najpierw przejscie
@@ -9067,7 +9068,7 @@ bool TMoverParameters::AutoRelayMainDown()
}
else if (LastRelayTime > CtrlDownDelay)
{
- if (TrainType != dt_EZT) // tutaj powinien być tryb sterowania wałem
+ if (TrainType != train_type::emu) // tutaj powinien być tryb sterowania wałem
{
--MainCtrlActualPos;
OK = true;
@@ -9087,7 +9088,7 @@ bool TMoverParameters::AutoRelayLineContactorsStep(bool const motorconnectorsoff
{
bool OK = false;
// ybARC - zalaczenie stycznikow liniowych
- if (false == motorconnectorsoff && MainCtrlActualPos == 0 && (TrainType == dt_EZT || HasCamshaft ? MainCtrlPowerPos() > 0 : MainCtrlPowerPos() == 1))
+ if (false == motorconnectorsoff && MainCtrlActualPos == 0 && (TrainType == train_type::emu || HasCamshaft ? MainCtrlPowerPos() > 0 : MainCtrlPowerPos() == 1))
{
DelayCtrlFlag = true;
@@ -9121,7 +9122,7 @@ bool TMoverParameters::CamshaftRunDown()
if (CoupledCtrl)
{
- if (TrainType == dt_EZT)
+ if (TrainType == train_type::emu)
{
OK = CamshaftRunDownEMU();
}
@@ -11256,7 +11257,7 @@ void TMoverParameters::move_door(basic_door &door, double const Deltatime)
if (door.step_folding)
{
// fold left doorstep
- if (TrainType == dt_EZT || TrainType == dt_DMU)
+ if (is_multiple_unit())
{
// multi-unit vehicles typically fold the doorstep only after closing the door
if (door.position <= 0.f)
@@ -12883,26 +12884,26 @@ void TMoverParameters::LoadFIZ_Param(std::string const &line)
}
{
- std::map> types{
- {"pseudodiesel", dt_PseudoDiesel},
- {"ezt", dt_EZT},
- {"dmu", dt_DMU},
- {"sn61", dt_SN61},
- {"et22", dt_ET22},
- {"et40", dt_ET40},
- {"et41", dt_ET41},
- {"et42", dt_ET42},
- {"ep05", dt_EP05},
- {"181", dt_181},
- {"182", dt_181} // na razie tak
+ std::map> types{
+ {"pseudodiesel", train_type::pseudodiesel},
+ {"ezt", train_type::emu},
+ {"dmu", train_type::dmu},
+ {"sn61", train_type::sn61},
+ {"et22", train_type::et22},
+ {"et40", train_type::et40},
+ {"et41", train_type::et41},
+ {"et42", train_type::et42},
+ {"ep05", train_type::ep05},
+ {"181", train_type::skoda181},
+ {"182", train_type::skoda181} // na razie tak
};
std::string type;
extract_value(type, "Type", line, "none");
auto lookup = types.find(ToLower(type));
- TrainType = lookup != types.end() ? lookup->second : dt_Default;
+ TrainType = lookup != types.end() ? lookup->second : train_type::generic;
}
- if (TrainType == dt_EZT)
+ if (TrainType == train_type::emu)
{
IminLo = 1;
@@ -13727,7 +13728,7 @@ void TMoverParameters::LoadFIZ_CntrlStarts(std::string const &line)
ConverterStart = lookup != starts.end() ? lookup->second : manual;
}
extract_value(ConverterStartDelay, "ConverterStartDelay", line, "");
- extract_value(ConverterOverloadRelayOffWhenMainIsOff, "ConverterOverloadWhenMainIsOff", line, TrainType == dt_EZT ? "yes" : "no");
+ extract_value(ConverterOverloadRelayOffWhenMainIsOff, "ConverterOverloadWhenMainIsOff", line, TrainType == train_type::emu ? "yes" : "no");
// compressor
{
auto lookup = starts.find(extract_value("CompressorStart", line));
@@ -13739,7 +13740,7 @@ void TMoverParameters::LoadFIZ_CntrlStarts(std::string const &line)
PantographCompressorStart = lookup != starts.end() ? lookup->second : manual;
}
// pantograph compressor valve
- PantAutoValve = TrainType == dt_EZT; // legacy code behaviour, automatic valve was initially installed in all EMUs
+ PantAutoValve = TrainType == train_type::emu; // legacy code behaviour, automatic valve was initially installed in all EMUs
extract_value(PantAutoValve, "PantAutoValve", line, "");
// pantographs valve
{
@@ -13804,14 +13805,14 @@ void TMoverParameters::LoadFIZ_CntrlStarts(std::string const &line)
// ground relay
{
auto lookup = starts.find(extract_value("GroundRelayStart", line));
- auto const defaultstart{TrainType == dt_EZT ? automatic : manual};
+ auto const defaultstart{TrainType == train_type::emu ? automatic : manual};
GroundRelayStart = lookup != starts.end() ? lookup->second : defaultstart;
}
// converter overload relay
{
auto lookup = starts.find(extract_value("ConverterOverloadRelayStart", line));
// the relay of a multiple unit activates when the converter is switched off
- auto const defaultstart{TrainType == dt_EZT ? converter : manual};
+ auto const defaultstart{TrainType == train_type::emu ? converter : manual};
ConverterOverloadRelayStart = lookup != starts.end() ? lookup->second : defaultstart;
}
}
@@ -14060,7 +14061,7 @@ void TMoverParameters::LoadFIZ_Engine(std::string const &Input)
extract_value(MotorBlowers[end::front].min_start_velocity, "MotorBlowersStartVelocity", Input, "");
MotorBlowers[end::rear] = MotorBlowers[end::front];
// pressure switch
- extract_value(HasControlPressureSwitch, "PressureSwitch", Input, TrainType != dt_EZT ? "yes" : "no");
+ extract_value(HasControlPressureSwitch, "PressureSwitch", Input, TrainType != train_type::emu ? "yes" : "no");
// its brake cylinder half; the brake pipe one stays
extract_value(PressureSwitchBrakeCylinder, "PressureSwitchBrakeCylinder", Input, "");
}
@@ -14966,7 +14967,7 @@ void TMoverParameters::CreateBrakeHandles()
{
LocHandle = std::make_shared();
LocHandle->Init(MaxBrakePress[0]);
- if (TrainType == dt_EZT)
+ if (TrainType == train_type::emu)
{
dynamic_cast(LocHandle.get())->SetSpeed(3.5);
@@ -15645,7 +15646,7 @@ bool TMoverParameters::RunPowerCommand(std::string const &Command, double CValue
auto const inputend{(static_cast(CValue1) & 0x80) != 0 ? 1 : 0};
auto const inputcab{(static_cast(CValue1) & 0x40) != 0 ? 1 : 0};
auto const inputoperation{static_cast(CValue1) & ~(0x80 | 0x40)};
- auto const noswap{TrainType == dt_EZT || TrainType == dt_ET41};
+ auto const noswap{TrainType == train_type::emu || TrainType == train_type::et41};
auto swap{false == noswap && TestFlag(Couplers[CValue2 == -1 ? end::rear : end::front].CouplingFlag, coupling::control)};
if (auto const reversed{inputcab != (CabActive != -1 ? 1 : 0)}; reversed)
{
@@ -15857,7 +15858,7 @@ double TMoverParameters::ShowCurrentP(int AmpN) const
bool Grupowy;
// ClearPendingExceptions;
- Grupowy = DelayCtrlFlag && TrainType == dt_ET22; // przerzucanie walu grupowego w ET22;
+ Grupowy = DelayCtrlFlag && TrainType == train_type::et22; // przerzucanie walu grupowego w ET22;
Bn = RList[MainCtrlActualPos].Bn; // ile równoległych gałęzi silników
if (DynamicBrakeType == dbrake_automatic && DynamicBrakeFlag)
diff --git a/application/driveruipanels.cpp b/application/driveruipanels.cpp
index d7d9d6bca..f577573c9 100644
--- a/application/driveruipanels.cpp
+++ b/application/driveruipanels.cpp
@@ -892,7 +892,7 @@ debug_panel::update_section_vehicle( std::vector &Output ) {
std::string( isdieselinshuntmode ? to_string( mover.AnPos, 2 ) + STR(" (shunt mode)") : std::to_string( mover.ScndCtrlPos ) + "(" + std::to_string( mover.ScndCtrlActualPos ) + ")" ).c_str(),
// engine
mover.EnginePower,
- std::abs( mover.TrainType == dt_EZT ? mover.ShowCurrent( 0 ) : mover.Im ),
+ std::abs( mover.TrainType == train_type::emu ? mover.ShowCurrent( 0 ) : mover.Im ),
// revolutions
std::abs( mover.enrot ) * 60,
std::abs( mover.nrot ) * mover.Transmision.Ratio * 60,
diff --git a/tests/unit/drive.cpp b/tests/unit/drive.cpp
index 02fc74c03..939a9a626 100644
--- a/tests/unit/drive.cpp
+++ b/tests/unit/drive.cpp
@@ -108,7 +108,7 @@ void prepare_diesel(driven const &Driven) {
// the pantographs' own air topped up by their compressor, and the pantographs raised
void raise_pantographs(driven const &Driven) {
auto &pantographs{Driven.pantographs};
- if (auto const enough{(pantographs.TrainType == dt_EZT ? 2.5 : 3.5) + 0.1}; pantographs.PantPress < enough) {
+ if (auto const enough{(pantographs.TrainType == train_type::emu ? 2.5 : 3.5) + 0.1}; pantographs.PantPress < enough) {
if (false == pantographs.PantAutoValve) {
pantographs.bPantKurek3 = false; // the pantographs on their own air
}
diff --git a/tests/unit/golden.cpp b/tests/unit/golden.cpp
index 45bd1c532..fcbf01e14 100644
--- a/tests/unit/golden.cpp
+++ b/tests/unit/golden.cpp
@@ -15,6 +15,29 @@
namespace test {
+namespace {
+
+// the number the traces record for the type of a vehicle: the bit it was before the type became an enum, so the traces
+// recorded before it still compare
+int legacy_code(train_type const Type) {
+ switch (Type) {
+ case train_type::emu: return 0x1;
+ case train_type::et41: return 0x2;
+ case train_type::et42: return 0x4;
+ case train_type::pseudodiesel: return 0x8;
+ case train_type::et22: return 0x10;
+ case train_type::sn61: return 0x20;
+ case train_type::ep05: return 0x40;
+ case train_type::et40: return 0x80;
+ case train_type::skoda181: return 0x100;
+ case train_type::dmu: return 0x200;
+ case train_type::generic: return 0;
+ }
+ return 0;
+}
+
+} // namespace
+
namespace channels {
std::vector motion() {
@@ -103,7 +126,7 @@ std::vector doors() {
std::vector parameters() {
std::vector result{
{"CategoryFlag", [](auto const &M) { return M.CategoryFlag; }},
- {"TrainType", [](auto const &M) { return M.TrainType; }},
+ {"TrainType", [](auto const &M) { return legacy_code(M.TrainType); }},
{"EngineType", [](auto const &M) { return static_cast(M.EngineType); }},
{"Vmax", [](auto const &M) { return M.Vmax; }},
{"Mass", [](auto const &M) { return M.Mass; }},
diff --git a/tests/unit/test_cntrl.cpp b/tests/unit/test_cntrl.cpp
index c73c45d85..bff7759ea 100644
--- a/tests/unit/test_cntrl.cpp
+++ b/tests/unit/test_cntrl.cpp
@@ -22,7 +22,7 @@ TEST_CASE("cntrl: the brake delays of the settings come from BDelay1 to BDelay4"
TEST_CASE("cntrl: the relays of a multiple unit start on their own, of other vehicles by hand") {
SUBCASE("multiple unit") {
vehicle unit{definition::load("wagon").set("Param", "Type", "ezt")};
- REQUIRE(unit->TrainType == dt_EZT);
+ REQUIRE(unit->TrainType == train_type::emu);
CHECK(unit->GroundRelayStart == start_t::automatic);
CHECK(unit->ConverterOverloadRelayStart == start_t::converter); // activates when the converter is switched off
}
@@ -117,7 +117,7 @@ TEST_CASE("cntrl: ScndCtrlResistiveLock keeps the field shunting off at zero and
SUBCASE("the master controller taken back from a shunt step drops the shunt") {
controllers_at(locked, resistancefree);
REQUIRE(locked->IncScndCtrl(1));
- if (locked->TrainType == dt_ET22) {
+ if (locked->TrainType == train_type::et22) {
// the ET22's master controller doesn't turn with the shunt on: the shunt goes off first, as before
CHECK_FALSE(locked->DecMainCtrl(1));
CHECK(locked->MainCtrlPos == resistancefree);
@@ -152,7 +152,7 @@ TEST_CASE("cntrl: ScndCtrlResistiveLock keeps the field shunting off at zero and
controllers_at(locked, lastseries);
locked->DirActive = 1;
REQUIRE(locked->IncScndCtrl(1));
- if (locked->TrainType == dt_ET22) {
+ if (locked->TrainType == train_type::et22) {
CHECK_FALSE(locked->IncMainCtrl(1)); // the ET22's interlock, as before
CHECK(locked->ScndCtrlPos == 1);
}
diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp
index 4b8a68ed4..eb89088ac 100644
--- a/vehicle/Driver.cpp
+++ b/vehicle/Driver.cpp
@@ -2352,7 +2352,7 @@ TController::TController(bool AI, TDynamicObject *NewControll, bool InitPsyche,
fAccThreshold = is_emu() ? -0.55 : is_dmu() ? -0.45 : -0.2;
/*
// HACK: emu with induction motors need to start their braking a bit sooner than the ones with series motors
- if( ( mvOccupied->TrainType == dt_EZT )
+ if( ( mvOccupied->TrainType == train_type::emu )
&& ( mvControlling->EngineType == TEngineType::ElectricInductionMotor ) ) {
fAccThreshold += 0.10;
}
@@ -3186,7 +3186,7 @@ double TController::BrakeAccFactor() const
Factor += fBrakeReaction * (/*mvOccupied->BrakeCtrlPosR*/ BrakeCtrlPosition < 0.5 ? 1.5 : 1) * mvOccupied->Vel / ( std::max( 0.0, ActualProximityDist ) + 1 ) * ( ( AccDesired - AbsAccS ) / fAccThreshold );
}
/*
- if (mvOccupied->TrainType == dt_DMU && mvOccupied->Vel > 40 && VelNext<40)
+ if (mvOccupied->TrainType == train_type::dmu && mvOccupied->Vel > 40 && VelNext<40)
Factor *= 1 + 0.25 * ( (1600 - VelNext * VelNext) / (mvOccupied->Vel * mvOccupied->Vel) );
*/
return Factor;
@@ -3623,8 +3623,8 @@ bool TController::IncBrake()
}
// NOTE: can't perform just test whether connected vehicle == nullptr, due to virtual couplers formed with nearby vehicles
auto standalone { true };
- if( mvOccupied->TrainType == dt_ET41
- || mvOccupied->TrainType == dt_ET42 ) {
+ if( mvOccupied->TrainType == train_type::et41
+ || mvOccupied->TrainType == train_type::et42 ) {
// NOTE: we're doing simplified checks full of presuptions here.
// they'll break if someone does strange thing like turning around the second unit
if( mvOccupied->Couplers[end::rear].CouplingFlag & coupling::permanent
@@ -3991,7 +3991,7 @@ bool TController::IncSpeed()
if (!IsAnyMotorOverloadRelayOpen && !mvControlling->ControlPressureSwitch && (mvControlling->IsMainCtrlNoPowerPos() || mvControlling->StLinFlag) && (Ready || iDrivigFlags & movePress)) {
// youBy polecił dodać 2012-09-08 v367
// na pozycji 0 przejdzie, a na pozostałych będzie czekać, aż się załączą liniowe (zgaśnie DelayCtrlFlag)
- auto const usehighoverloadrelaythreshold{mvControlling->TrainType != dt_ET42 // ET42 uses these variables for different purpose. TODO: fix this
+ auto const usehighoverloadrelaythreshold{mvControlling->TrainType != train_type::et42 // ET42 uses these variables for different purpose. TODO: fix this
&& mvControlling->ImaxHi > mvControlling->ImaxLo && mvOccupied->Vel < (mvControlling->IsMotorOverloadRelayHighThresholdOn() ? 30.0 : 20.0) &&
iVehicles - ControlledEnginesCount > 0
// && ( std::fabs( mvControlling->Im ) > 0.85 * mvControlling->Imax )
@@ -4023,7 +4023,7 @@ bool TController::IncSpeed()
mvControlling->MainCtrlPos == mvControlling->MainCtrlPosNo);
// if needed enable high threshold for overload relay...
- if (mvControlling->TrainType != dt_ET42)
+ if (mvControlling->TrainType != train_type::et42)
{ // ET42 uses these variables for different purpose. TODO: fix this
if (usehighoverloadrelaythreshold)
{
@@ -6368,7 +6368,7 @@ void TController::DirectionForward(bool forward)
iTableDirection = 0;
}
}
- if( mvOccupied->TrainType == dt_SN61 ) {
+ if( mvOccupied->TrainType == train_type::sn61 ) {
// specjalnie dla SN61 żeby nie zgasł
while( mvControlling->RList[mvControlling->MainCtrlPos].Mn == 0
&& mvControlling->IncMainCtrl(1) ) {
@@ -6970,7 +6970,7 @@ TController::control_pantographs() {
auto const useregularpantographlayout {
pVehicle->Next(coupling::control) == nullptr // standalone
|| is_emu() // special case
- || mvControlling->TrainType == dt_ET41 }; // special case
+ || mvControlling->TrainType == train_type::et41 }; // special case
if( mvOccupied->Vel > EU07_AI_NOMOVEMENT ) {
diff --git a/vehicle/Driver.h b/vehicle/Driver.h
index 0eae2caf1..a6985bcd6 100644
--- a/vehicle/Driver.h
+++ b/vehicle/Driver.h
@@ -274,10 +274,10 @@ public:
return TestFlag( mvOccupied->CategoryFlag, 2 ); }
inline
bool is_emu() const {
- return mvControlling->TrainType == dt_EZT; }
+ return mvControlling->TrainType == train_type::emu; }
inline
bool is_dmu() const {
- return mvControlling->TrainType == dt_DMU; }
+ return mvControlling->TrainType == train_type::dmu; }
inline
bool has_diesel_engine() const {
return mvControlling->EngineType == TEngineType::DieselElectric || mvControlling->EngineType == TEngineType::DieselEngine;
diff --git a/vehicle/DynObj.cpp b/vehicle/DynObj.cpp
index 7eb6f19a9..cfe479a94 100644
--- a/vehicle/DynObj.cpp
+++ b/vehicle/DynObj.cpp
@@ -4285,7 +4285,7 @@ bool TDynamicObject::Update(double dt, double dt1)
*/
&& MoverParameters->EngineType != TEngineType::DieselEngine
&& MoverParameters->EngineType != TEngineType::WheelsDriven ) { // jeśli bateria wyłączona, a nie diesel ani drezyna reczna
- if( MoverParameters->MainSwitch( false, MoverParameters->TrainType == dt_EZT ? range_t::unit : range_t::local ) ) {
+ if( MoverParameters->MainSwitch( false, MoverParameters->TrainType == train_type::emu ? range_t::unit : range_t::local ) ) {
// wyłączyć zasilanie
// NOTE: we turn off entire EMU, but only the affected unit for other multi-unit consists
MoverParameters->EventFlag = true;
@@ -4294,8 +4294,8 @@ bool TDynamicObject::Update(double dt, double dt1)
// TODO: have this dependant on .fiz-driven flag
// NOTE: moved to pantspeed calculation part a little later in the function. all remarks and todo still apply
/*
- MoverParameters->PantFront( false, ( MoverParameters->TrainType == dt_EZT ? range::unit : range::local ) );
- MoverParameters->PantRear( false, ( MoverParameters->TrainType == dt_EZT ? range::unit : range::local ) );
+ MoverParameters->PantFront( false, ( MoverParameters->TrainType == train_type::emu ? range::unit : range::local ) );
+ MoverParameters->PantRear( false, ( MoverParameters->TrainType == train_type::emu ? range::unit : range::local ) );
*/
}
}
@@ -4421,7 +4421,7 @@ bool TDynamicObject::Update(double dt, double dt1)
// McZapkie-260202 end
// fragment z EXE Kursa
- /* if (MoverParameters->TrainType==dt_ET42)
+ /* if (MoverParameters->TrainType==train_type::et42)
{
if ((MoverParameters->DynamicBrakeType=dbrake_switch) &&
((MoverParameters->BrakePress >
@@ -4606,7 +4606,7 @@ bool TDynamicObject::Update(double dt, double dt1)
break;
} // pozostałe na razie nie obsługiwane
if( MoverParameters->PantPress > (
- MoverParameters->TrainType == dt_EZT ?
+ MoverParameters->TrainType == train_type::emu ?
2.45 : // Ra 2013-12: Niebugocław mówi, że w EZT podnoszą się przy 2.5
3.45 ) ) {
// z EXE Kursa
@@ -8546,7 +8546,7 @@ TDynamicObject * TDynamicObject::FindPowered()
// problematyczna może być kwestia wybranej kabiny (w silnikowym...)
// jeśli silnikowy będzie zapięty odwrotnie (tzn. -1), to i tak powinno jeździć dobrze
// również hamowanie wykonuje się zaworem w członie, a nie w silnikowym...
- auto const coupling { MoverParameters->TrainType == dt_EZT || MoverParameters->TrainType == dt_DMU ?
+ auto const coupling { MoverParameters->is_multiple_unit() ?
coupling::permanent :
coupling::control };
@@ -9754,7 +9754,7 @@ vehicle_table::update( double Deltatime, int Iterationcount ) {
if( mover->Vel > 0.0001 ) { ++awake.speed; }
if( mover->accelerating() ) { ++awake.acceleration; }
if( mover->LastSwitchingTime < 5 ) { ++awake.switching; }
- if( ( mover->TrainType == dt_EZT ) || ( mover->TrainType == dt_DMU ) ) { ++awake.multipleunit; }
+ if( mover->is_multiple_unit() ) { ++awake.multipleunit; }
if( moving( mover->Neighbours[ end::front ] ) || moving( mover->Neighbours[ end::rear ] ) ) { ++awake.neighbour; }
}
}
diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp
index 3c4e5f6fe..27f23b601 100644
--- a/vehicle/Train.cpp
+++ b/vehicle/Train.cpp
@@ -1013,7 +1013,7 @@ TTrain::state_t TTrain::get_state() const
static_cast(mvOccupied->BrakePress),
static_cast(mvPantographUnit->PantPress),
fHVoltage,
- {fHCurrent[mvControlled->TrainType & dt_EZT ? 0 : 1], fHCurrent[2], fHCurrent[3]},
+ {fHCurrent[mvControlled->TrainType == train_type::emu ? 0 : 1], fHCurrent[2], fHCurrent[3]},
ggLVoltage.GetValue(),
mvOccupied->DistCounter,
static_cast(RadioChannel()),
@@ -1036,7 +1036,7 @@ TTrain::state_t TTrain::get_state() const
bool TTrain::is_eztoer() const
{
- return mvControlled->TrainType == dt_EZT && mvOccupied->BrakeSubsystem == TBrakeSubSystem::ss_ESt && mvControlled->Power24vIsAvailable == true && mvControlled->EpFuse == true &&
+ return mvControlled->TrainType == train_type::emu && mvOccupied->BrakeSubsystem == TBrakeSubSystem::ss_ESt && mvControlled->Power24vIsAvailable == true && mvControlled->EpFuse == true &&
mvControlled->DirActive != 0; // od yB
}
@@ -1112,7 +1112,7 @@ void TTrain::set_train_brake_speed(TDynamicObject *Vehicle, int const Speed)
void TTrain::set_paired_open_motor_connectors_button(bool const State)
{
- if (mvControlled->TrainType == dt_ET41 || mvControlled->TrainType == dt_ET42)
+ if (mvControlled->TrainType == train_type::et41 || mvControlled->TrainType == train_type::et42)
{
// crude implementation of the button affecting entire unit for multi-unit engines
// TODO: rework it into part of standard command propagation system
@@ -1901,7 +1901,7 @@ void TTrain::OnCommand_independentbrakebailoff(TTrain *Train, command_data const
{
// TODO: check if this set of conditions can be simplified.
// it'd be more flexible to have an attribute indicating whether bail off position is supported
- if (Train->mvControlled->TrainType != dt_EZT &&
+ if (Train->mvControlled->TrainType != train_type::emu &&
(Train->mvControlled->EngineType == TEngineType::ElectricSeriesMotor || Train->mvControlled->EngineType == TEngineType::DieselElectric ||
Train->mvControlled->EngineType == TEngineType::ElectricInductionMotor) &&
Train->mvOccupied->BrakeCtrlPosNo > 0)
@@ -2631,7 +2631,7 @@ void TTrain::OnCommand_mubrakingindicatortoggle(TTrain *Train, command_data cons
}
return;
}
- if (Train->mvControlled->TrainType != dt_EZT)
+ if (Train->mvControlled->TrainType != train_type::emu)
{
//
return;
@@ -2875,7 +2875,7 @@ void TTrain::OnCommand_alerteracknowledge(TTrain *Train, command_data const &Com
// visual feedback
Train->ggSecurityResetButton.UpdateValue(1.0, Train->dsbSwitch);
- if (Train->mvOccupied->TrainType == dt_EZT || Train->mvOccupied->DirActive != 0)
+ if (Train->mvOccupied->TrainType == train_type::emu || Train->mvOccupied->DirActive != 0)
Train->mvOccupied->SecuritySystem.acknowledge_press();
}
else if (Command.action == GLFW_RELEASE)
@@ -2883,7 +2883,7 @@ void TTrain::OnCommand_alerteracknowledge(TTrain *Train, command_data const &Com
// visual feedback
Train->ggSecurityResetButton.UpdateValue(0.0);
- if (Train->mvOccupied->TrainType == dt_EZT || Train->mvOccupied->DirActive != 0)
+ if (Train->mvOccupied->TrainType == train_type::emu || Train->mvOccupied->DirActive != 0)
Train->mvOccupied->SecuritySystem.acknowledge_release();
}
}
@@ -5402,7 +5402,7 @@ void TTrain::OnCommand_motorconnectorsclose(TTrain *Train, command_data const &C
void TTrain::OnCommand_motordisconnect(TTrain *Train, command_data const &Command)
{
- if (Train->mvControlled->TrainType == dt_EZT ? Train->mvControlled != Train->mvOccupied : Train->iCabn != 0)
+ if (Train->mvControlled->TrainType == train_type::emu ? Train->mvControlled != Train->mvOccupied : Train->iCabn != 0)
{
// tylko w maszynowym
return;
@@ -9053,7 +9053,7 @@ bool TTrain::Update(double const Deltatime)
UpdateCab();
// nie blokujemy AI
- if (DynamicObject->Mechanik != nullptr && false == DynamicObject->Mechanik->AIControllFlag && (mvOccupied->TrainType == dt_ET40 || mvOccupied->TrainType == dt_EP05 || mvOccupied->HasCamshaft))
+ if (DynamicObject->Mechanik != nullptr && false == DynamicObject->Mechanik->AIControllFlag && (mvOccupied->TrainType == train_type::et40 || mvOccupied->TrainType == train_type::ep05 || mvOccupied->HasCamshaft))
{
// dla ET40 i EU05 automatyczne cofanie nastawnika - i tak nie będzie to działać dobrze...
// TODO: use deltatime to stabilize speed
@@ -9326,7 +9326,7 @@ bool TTrain::Update(double const Deltatime)
// Ra: sterowanie miernikiem: drugi amperomierz
Console::ValueSet(4, fHCurrent[2]);
// pierwszy amperomierz; dla EZT prąd całkowity
- Console::ValueSet(5, fHCurrent[mvControlled->TrainType & dt_EZT ? 0 : 1]);
+ Console::ValueSet(5, fHCurrent[mvControlled->TrainType == train_type::emu ? 0 : 1]);
// Ra: prędkość na pin 43 - wyjście analogowe (to nie jest PWM); skakanie zapewnia mechanika napędu
Console::ValueSet(6, fTachoVelocity);
}
@@ -9337,15 +9337,15 @@ bool TTrain::Update(double const Deltatime)
if (mvControlled->ConverterFlag == true)
{
fConverterTimer += static_cast(Deltatime);
- if (mvControlled->CompressorFlag == true && mvControlled->CompressorPower == 1 && (mvControlled->EngineType == TEngineType::ElectricSeriesMotor || mvControlled->TrainType == dt_EZT) &&
+ if (mvControlled->CompressorFlag == true && mvControlled->CompressorPower == 1 && (mvControlled->EngineType == TEngineType::ElectricSeriesMotor || mvControlled->TrainType == train_type::emu) &&
DynamicObject->Controller == Humandriver // hunter-110212: poprawka dla EZT
&& false == DynamicObject->Mechanik->AIControllFlag)
{ // hunter-091012: poprawka (zmiana warunku z CompressorPower /rozne od 0/ na /rowne 1/)
if (fConverterTimer < fConverterPrzekaznik)
{
mvControlled->ConvOvldFlag = true;
- if (mvControlled->TrainType != dt_EZT)
- mvControlled->MainSwitch(false, mvControlled->TrainType == dt_EZT ? range_t::unit : range_t::local);
+ if (mvControlled->TrainType != train_type::emu)
+ mvControlled->MainSwitch(false, mvControlled->TrainType == train_type::emu ? range_t::unit : range_t::local);
}
else if (fConverterTimer >= fConverterPrzekaznik)
{
@@ -9432,7 +9432,7 @@ bool TTrain::Update(double const Deltatime)
else
{
int x;
- if (mvControlled->TrainType == dt_ET42 && mvControlled->Imax == mvControlled->ImaxHi)
+ if (mvControlled->TrainType == train_type::et42 && mvControlled->Imax == mvControlled->ImaxHi)
x = 1;
else
x = 2;
@@ -9611,12 +9611,12 @@ bool TTrain::Update(double const Deltatime)
switch (mvControlled->TrainType)
{
// zależnie od typu lokomotywy
- case dt_EZT:
+ case train_type::emu:
{
btLampkaHamienie.Turn(mvControlled->BrakePress >= 0.2 && mvControlled->Signalling);
break;
}
- case dt_ET41:
+ case train_type::et41:
{
// odhamowanie drugiego członu
if (mvSecond)
@@ -9941,7 +9941,7 @@ bool TTrain::Update(double const Deltatime)
// Ra: od byte odejmowane boolean i konwertowane potem na double?
if (false == ggScndCtrl.is_push())
{
- ggScndCtrl.UpdateValue(static_cast(double(mvControlled->ScndCtrlPos - (mvControlled->TrainType == dt_ET42 && mvControlled->DynamicBrakeFlag))), dsbNastawnikBocz);
+ ggScndCtrl.UpdateValue(static_cast(double(mvControlled->ScndCtrlPos - (mvControlled->TrainType == train_type::et42 && mvControlled->DynamicBrakeFlag))), dsbNastawnikBocz);
}
ggScndCtrl.Update();
}
@@ -9963,7 +9963,7 @@ bool TTrain::Update(double const Deltatime)
}
if (ggDirKey.SubModel != nullptr)
{
- if (mvControlled->TrainType != dt_EZT)
+ if (mvControlled->TrainType != train_type::emu)
{
ggDirKey.UpdateValue(static_cast(double(mvControlled->DirActive)), dsbReverserKey);
}
@@ -11766,11 +11766,11 @@ void TTrain::clear_cab_controls()
btLampkaNadmSil.Clear(4);
btLampkaStyczn.Clear(5);
btLampkaPoslizg.Clear(6);
- btLampkaNadmPrzetw.Clear((mvControlled->TrainType & dt_EZT) != 0 ? -1 : 7); // EN57 nie ma tej lampki
- btLampkaPrzetwOff.Clear((mvControlled->TrainType & dt_EZT) != 0 ? 7 : -1); // za to ma tę
+ btLampkaNadmPrzetw.Clear(mvControlled->TrainType == train_type::emu ? -1 : 7); // EN57 nie ma tej lampki
+ btLampkaPrzetwOff.Clear(mvControlled->TrainType == train_type::emu ? 7 : -1); // za to ma tę
btLampkaNadmSpr.Clear(8);
btLampkaNadmWent.Clear(9);
- btLampkaWysRozr.Clear((mvControlled->TrainType & dt_ET22) != 0 ? -1 : 10); // ET22 nie ma tej lampki
+ btLampkaWysRozr.Clear(mvControlled->TrainType == train_type::et22 ? -1 : 10); // ET22 nie ma tej lampki
btLampkaOgrzewanieSkladu.Clear(11);
// overheat indicator lamps
btLampkaOilOverheat.Clear(-1);
diff --git a/widgets/vehicleparams.cpp b/widgets/vehicleparams.cpp
index 14ca9923c..c2b140d8a 100644
--- a/widgets/vehicleparams.cpp
+++ b/widgets/vehicleparams.cpp
@@ -169,7 +169,7 @@ void ui::vehicleparams_panel::render_contents()
mover.MainCtrlPos, mover.MainCtrlActualPos,
std::string(isdieselinshuntmode ? to_string(mover.AnPos, 2) + STR(" (shunt mode)") : std::to_string(mover.ScndCtrlPos) + "(" + std::to_string(mover.ScndCtrlActualPos) + ")").c_str(),
// engine
- mover.EnginePower, std::abs(mover.TrainType == dt_EZT ? mover.ShowCurrent(0) : mover.Im),
+ mover.EnginePower, std::abs(mover.TrainType == train_type::emu ? mover.ShowCurrent(0) : mover.Im),
// revolutions
std::abs(mover.enrot) * 60, std::abs(mover.nrot) * mover.Transmision.Ratio * 60, mover.RventRot * 60, std::abs(mover.MotorBlowers[end::front].revolutions),
std::abs(mover.MotorBlowers[end::rear].revolutions), mover.dizel_heat.rpmw, mover.dizel_heat.rpmw2);
From 5a537e69f2dbf4727abae9d46ad68fdb10f72487 Mon Sep 17 00:00:00 2001
From: Hirek193
Date: Fri, 27 Nov 2026 17:11:46 +0100
Subject: [PATCH 017/174] refactor(physics): McZapkie/ becomes physics/, its
files get English names
The folder of the vehicle physics was named after the author of its first
version (2001). Its name now says what it holds, and so do its files:
McZapkie/MOVER.h, Mover.cpp -> physics/mover.h, mover.cpp
McZapkie/hamulce.h, hamulce.cpp -> physics/brakes.h, brakes.cpp
McZapkie/Oerlikon_ESt.h, .cpp -> physics/oerlikonest.h, .cpp
friction, collision, couplerphysics, derailment: same names in physics/
Every include names the folder ("physics/mover.h"); the McZapkie include
directory is gone from CMakeLists.txt. The comments and documents that
named the old paths name the new ones. The credits to McZapkie stay.
Renames only: git sees every file as renamed (98-100%). 1142/1142 tests,
golden traces exact against staging 62f7a29b.
---
CMakeLists.txt | 17 ++++++++---------
directoryDescription.md | 2 +-
McZapkie/hamulce.cpp => physics/brakes.cpp | 4 ++--
McZapkie/hamulce.h => physics/brakes.h | 2 +-
{McZapkie => physics}/collision.cpp | 4 ++--
{McZapkie => physics}/collision.h | 4 ++--
{McZapkie => physics}/couplerphysics.cpp | 2 +-
{McZapkie => physics}/couplerphysics.h | 0
{McZapkie => physics}/derailment.cpp | 2 +-
{McZapkie => physics}/derailment.h | 2 +-
{McZapkie => physics}/friction.cpp | 2 +-
{McZapkie => physics}/friction.h | 0
McZapkie/Mover.cpp => physics/mover.cpp | 4 ++--
McZapkie/MOVER.h => physics/mover.h | 8 ++++----
.../oerlikonest.cpp | 2 +-
.../Oerlikon_ESt.h => physics/oerlikonest.h | 4 ++--
tests/unit/COVERAGE.md | 18 +++++++++---------
tests/unit/drive.cpp | 2 +-
tests/unit/figures.h | 2 +-
tests/unit/golden.cpp | 2 +-
tests/unit/golden.h | 2 +-
tests/unit/invariants.h | 2 +-
tests/unit/scenario.cpp | 2 +-
tests/unit/test_brake_cycle.cpp | 2 +-
tests/unit/test_brake_handles.cpp | 2 +-
tests/unit/test_brake_pipe.cpp | 4 ++--
tests/unit/test_brake_setting.cpp | 4 ++--
tests/unit/test_cab.cpp | 2 +-
tests/unit/test_collisions.cpp | 6 +++---
tests/unit/test_commands.cpp | 2 +-
tests/unit/test_consist.cpp | 2 +-
tests/unit/test_controls.cpp | 2 +-
tests/unit/test_coupler_physics.cpp | 4 ++--
tests/unit/test_crew.cpp | 2 +-
tests/unit/test_derail_motion.cpp | 4 ++--
tests/unit/test_derailment.cpp | 4 ++--
tests/unit/test_derailment_vehicle.cpp | 6 +++---
tests/unit/test_diesel.cpp | 2 +-
tests/unit/test_drivingaid.cpp | 2 +-
tests/unit/test_dynamic_brake_diesel.cpp | 2 +-
tests/unit/test_elf_controller.cpp | 2 +-
tests/unit/test_est3al2_relay.cpp | 2 +-
tests/unit/test_feed_pipe.cpp | 4 ++--
tests/unit/test_genset.cpp | 2 +-
tests/unit/test_line_contactors_interlock.cpp | 2 +-
tests/unit/test_pressure_switch.cpp | 2 +-
tests/unit/test_timetable.cpp | 2 +-
tests/unit/test_track_buckle_derailment.cpp | 2 +-
tests/unit/test_traction.cpp | 2 +-
tests/unit/vehicle.h | 2 +-
utilities/Globals.cpp | 4 ++--
utilities/Globals.h | 6 +++---
utilities/translation.cpp | 2 +-
vehicle/Camera.cpp | 2 +-
vehicle/Driver.h | 2 +-
vehicle/DynObj.cpp | 2 +-
vehicle/DynObj.h | 4 ++--
vehicle/brakesetting.cpp | 4 ++--
vehicle/crew.cpp | 2 +-
vehicle/derailmotion.cpp | 2 +-
vehicle/derailmotion.h | 8 ++++----
vehicle/drivingaid.cpp | 4 ++--
vehicle/enginestart.cpp | 2 +-
vehicle/handover.cpp | 2 +-
vehicle/lightsprogrammer.h | 2 +-
vehicle/mainctrlact.h | 2 +-
vehicle/smoke.cpp | 2 +-
vehicle/timetableservice.cpp | 2 +-
world/TrackCheck.h | 4 ++--
69 files changed, 110 insertions(+), 111 deletions(-)
rename McZapkie/hamulce.cpp => physics/brakes.cpp (99%)
rename McZapkie/hamulce.h => physics/brakes.h (99%)
rename {McZapkie => physics}/collision.cpp (99%)
rename {McZapkie => physics}/collision.h (99%)
rename {McZapkie => physics}/couplerphysics.cpp (99%)
rename {McZapkie => physics}/couplerphysics.h (100%)
rename {McZapkie => physics}/derailment.cpp (99%)
rename {McZapkie => physics}/derailment.h (99%)
rename {McZapkie => physics}/friction.cpp (99%)
rename {McZapkie => physics}/friction.h (100%)
rename McZapkie/Mover.cpp => physics/mover.cpp (99%)
rename McZapkie/MOVER.h => physics/mover.h (99%)
rename McZapkie/Oerlikon_ESt.cpp => physics/oerlikonest.cpp (99%)
rename McZapkie/Oerlikon_ESt.h => physics/oerlikonest.h (98%)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f5f18344f..b6f35af69 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -56,7 +56,7 @@ set(CMAKE_CXX_STANDARD 20)
file(GLOB HEADERS "*.h"
"Console/*.h"
-"McZapkie/*.h"
+"physics/*.h"
"gl/*.h"
"network/*.h"
"vr/*.h"
@@ -740,16 +740,16 @@ add_library(eu07_settings INTERFACE)
# definition parser, the helpers they use and the rules of the test mode. built once, and tested as the game uses them
set(CORE_SOURCES
"audio/startsample.cpp"
-"McZapkie/friction.cpp"
-"McZapkie/hamulce.cpp"
-"McZapkie/Mover.cpp"
-"McZapkie/couplerphysics.cpp"
-"McZapkie/derailment.cpp"
-"McZapkie/collision.cpp"
+"physics/friction.cpp"
+"physics/brakes.cpp"
+"physics/mover.cpp"
+"physics/couplerphysics.cpp"
+"physics/derailment.cpp"
+"physics/collision.cpp"
"vehicle/derailmotion.cpp"
"world/TrackCheck.cpp"
"world/SleeperPack.cpp"
-"McZapkie/Oerlikon_ESt.cpp"
+"physics/oerlikonest.cpp"
"utilities/logfiles.cpp"
"utilities/parser.cpp"
"utilities/utilities.cpp"
@@ -825,7 +825,6 @@ target_compile_definitions(eu07_settings INTERFACE ${DEFINITIONS})
target_include_directories(eu07_settings INTERFACE
"."
"Console"
- "McZapkie"
"gl"
"${DEPS_DIR}/glad/include"
"${DEPS_DIR}/dds-ktx/include"
diff --git a/directoryDescription.md b/directoryDescription.md
index 77d571771..51ba37f32 100644
--- a/directoryDescription.md
+++ b/directoryDescription.md
@@ -2,7 +2,7 @@
# File structure
| Directory| Description|
|--|--|
-| McZapkie/ | Train Physics Engine |
+| physics/ | Vehicle physics: the mover, brakes, couplers, collisions, derailment |
| gl/ | OpenGL Abstraction Layer|
| network/ | Multiplayer Support
| launcher/ | Scenario/Vehicle Selection (built in starter)|
diff --git a/McZapkie/hamulce.cpp b/physics/brakes.cpp
similarity index 99%
rename from McZapkie/hamulce.cpp
rename to physics/brakes.cpp
index 4a2029af5..65d38663f 100644
--- a/McZapkie/hamulce.cpp
+++ b/physics/brakes.cpp
@@ -13,9 +13,9 @@ Copyright (C) 2007-2014 Maciej Cierniak
*/
#include "stdafx.h"
-#include "hamulce.h"
+#include "physics/brakes.h"
#include
-#include "MOVER.h"
+#include "physics/mover.h"
#include "utilities/utilities.h"
//---FUNKCJE OGOLNE---
diff --git a/McZapkie/hamulce.h b/physics/brakes.h
similarity index 99%
rename from McZapkie/hamulce.h
rename to physics/brakes.h
index 2b08e1f63..dd07f0630 100644
--- a/McZapkie/hamulce.h
+++ b/physics/brakes.h
@@ -33,7 +33,7 @@ Knorr/West EP - żeby był
#pragma once
-#include "friction.h" // Pascal unit
+#include "physics/friction.h" // Pascal unit
/// Number of positions of the local (auxiliary/manual) brake handle.
static int const LocalBrakePosNo = 10; /*ilosc nastaw hamulca recznego lub pomocniczego*/
diff --git a/McZapkie/collision.cpp b/physics/collision.cpp
similarity index 99%
rename from McZapkie/collision.cpp
rename to physics/collision.cpp
index 2fb085e69..2dd3af62c 100644
--- a/McZapkie/collision.cpp
+++ b/physics/collision.cpp
@@ -8,13 +8,13 @@ http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
-#include "collision.h"
+#include "physics/collision.h"
#include
#include
#include
-#include "derailment.h"
+#include "physics/derailment.h"
namespace collision {
diff --git a/McZapkie/collision.h b/physics/collision.h
similarity index 99%
rename from McZapkie/collision.h
rename to physics/collision.h
index 01239a3cd..62d16669e 100644
--- a/McZapkie/collision.h
+++ b/physics/collision.h
@@ -12,8 +12,8 @@ http://mozilla.org/MPL/2.0/.
#include
#include
-#include "couplerphysics.h"
-#include "derailment.h"
+#include "physics/couplerphysics.h"
+#include "physics/derailment.h"
// what a collision of two vehicles does to them past their buffers (physics.collisions new in eu07.ini, see
// TMoverParameters::CollisionDetect()), as plain functions of the vehicles and the hit:
diff --git a/McZapkie/couplerphysics.cpp b/physics/couplerphysics.cpp
similarity index 99%
rename from McZapkie/couplerphysics.cpp
rename to physics/couplerphysics.cpp
index 31afd26fe..ca293f69c 100644
--- a/McZapkie/couplerphysics.cpp
+++ b/physics/couplerphysics.cpp
@@ -8,7 +8,7 @@ http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
-#include "couplerphysics.h"
+#include "physics/couplerphysics.h"
#include
#include
diff --git a/McZapkie/couplerphysics.h b/physics/couplerphysics.h
similarity index 100%
rename from McZapkie/couplerphysics.h
rename to physics/couplerphysics.h
diff --git a/McZapkie/derailment.cpp b/physics/derailment.cpp
similarity index 99%
rename from McZapkie/derailment.cpp
rename to physics/derailment.cpp
index e9cfa452e..46945600f 100644
--- a/McZapkie/derailment.cpp
+++ b/physics/derailment.cpp
@@ -8,7 +8,7 @@ http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
-#include "derailment.h"
+#include "physics/derailment.h"
#include
#include
diff --git a/McZapkie/derailment.h b/physics/derailment.h
similarity index 99%
rename from McZapkie/derailment.h
rename to physics/derailment.h
index 50a3d84cb..e25e027cc 100644
--- a/McZapkie/derailment.h
+++ b/physics/derailment.h
@@ -112,7 +112,7 @@ struct vehicle_state {
std::array ends{};
};
-// the dtrack_* flags of the track (MOVER.h) the criteria look at
+// the dtrack_* flags of the track (mover.h) the criteria look at
namespace track_damage {
inline constexpr int railwear{2};
inline constexpr int freerail{4};
diff --git a/McZapkie/friction.cpp b/physics/friction.cpp
similarity index 99%
rename from McZapkie/friction.cpp
rename to physics/friction.cpp
index 6ecf5a064..bb4d872d8 100644
--- a/McZapkie/friction.cpp
+++ b/physics/friction.cpp
@@ -13,7 +13,7 @@ Copyright (C) 2007-2013 Maciej Cierniak
*/
#include "stdafx.h"
-#include "friction.h"
+#include "physics/friction.h"
double TFricMat::GetFC(double N, double Vel)
{
diff --git a/McZapkie/friction.h b/physics/friction.h
similarity index 100%
rename from McZapkie/friction.h
rename to physics/friction.h
diff --git a/McZapkie/Mover.cpp b/physics/mover.cpp
similarity index 99%
rename from McZapkie/Mover.cpp
rename to physics/mover.cpp
index 466523d89..384f1a684 100644
--- a/McZapkie/Mover.cpp
+++ b/physics/mover.cpp
@@ -8,10 +8,10 @@ http://mozilla.org/MPL/2.0/.
*/
#include "stdafx.h"
-#include "MOVER.h"
+#include "physics/mover.h"
#include "vehicle/DynObj.h"
-#include "Oerlikon_ESt.h"
+#include "physics/oerlikonest.h"
#include "utilities/Globals.h"
#include "utilities/Logs.h"
#include "utilities/Timer.h"
diff --git a/McZapkie/MOVER.h b/physics/mover.h
similarity index 99%
rename from McZapkie/MOVER.h
rename to physics/mover.h
index 3c4f14b41..0e2211afe 100644
--- a/McZapkie/MOVER.h
+++ b/physics/mover.h
@@ -14,10 +14,10 @@ http://mozilla.org/MPL/2.0/.
#include