18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 22:07:55 +01:00

Keep the wiper timers of the windscreen when the camera leaves the cab

The moments the blades were at the ends of their sweep (wiper_timer_out /
wiper_timer_return, the drops on the glass come back from then) were set to
-1000 whenever the camera wasn't in an active cab, so the glass came back
fully wet on the return to the cab, and stayed so until the blades reached
the end of their sweep again.

They now follow the train driven while the camera is outside it (or the
vehicle of the camera, as before, when it's in an active cab) and are kept;
they're forgotten only when another vehicle is followed. Both renderers
(OpenGL 4.6 and Vulkan).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqfRrTiBDaAyQ2gT6ZrnZD
This commit is contained in:
Claude
2026-11-01 19:12:41 +01:00
parent 51c76da927
commit 443b6ca6d3
4 changed files with 34 additions and 8 deletions
+15 -4
View File
@@ -1625,13 +1625,26 @@ void opengl46_renderer::Render_pass(viewport_config &vp, rendermode const Mode)
air -= owner->VectorFront() * owner->MoverParameters->V;
scene_ubs.rain_wind = glm::vec4{glm::vec3{air}, 0.f};
}
if (TDynamicObject const *owner = Global.pCamera.m_owner; owner && !!owner->MoverParameters->CabActive)
// the wipers of the vehicle the camera is in, or of the train driven when the camera is outside it: the moments the blades
// were at the ends of their sweep (the drops on the glass come back from then) are kept while the camera is away, so the glass
// looks as the blades left it when it's back in the cab. they're forgotten only for another vehicle
TDynamicObject const *owner = Global.pCamera.m_owner;
if ((owner == nullptr) || (owner->MoverParameters->CabActive == 0))
owner = (simulation::Train != nullptr) ? simulation::Train->Dynamic() : nullptr;
if (owner != m_wipervehicle)
{
m_wipervehicle = owner;
scene_ubs.wiper_timer_out = glm::vec4{-1000.};
scene_ubs.wiper_timer_return = glm::vec4{-1000.};
}
if (owner != nullptr)
{
auto const cabactive{owner->MoverParameters->CabActive != 0 ? owner->MoverParameters->CabActive : 1};
for (int i = 0; i < 4; ++i)
{
if (i < owner->dWiperPos.size())
{
int index = owner->MoverParameters->CabActive > 0 ? i : static_cast<int>(owner->dWiperPos.size() - 1) - i;
int index = cabactive > 0 ? i : static_cast<int>(owner->dWiperPos.size() - 1) - i;
scene_ubs.wiper_pos[i] = owner->dWiperPos[index];
if (owner->dWiperPos[index] > 0. && owner->wiperDirection[index])
{
@@ -1657,8 +1670,6 @@ void opengl46_renderer::Render_pass(viewport_config &vp, rendermode const Mode)
else
{
scene_ubs.wiper_pos = glm::vec4{0.};
scene_ubs.wiper_timer_out = glm::vec4{-1000.};
scene_ubs.wiper_timer_return = glm::vec4{-1000.};
}
}
// the reflections: the ground below the horizon of the environment map, and the screen space ones set up for the colour
+2
View File
@@ -844,6 +844,8 @@ class opengl46_renderer : public gfx_renderer, public gfx::scene_walk {
// persistently mapped with Global.gfx_bufferstreaming
std::unique_ptr<gl::frame_stream> m_instancestream;
gl::scene_ubs scene_ubs;
// the vehicle whose wipers the timers of the blades in scene_ubs (wiper_timer_out / wiper_timer_return) follow
TDynamicObject const *m_wipervehicle{nullptr};
gl::light_data light_data;
std::unordered_map<std::string, std::shared_ptr<gl::program>> m_shaders;
+15 -4
View File
@@ -1489,13 +1489,26 @@ void vulkan14_renderer::render_viewport(std::size_t const Index)
air -= owner->VectorFront() * owner->MoverParameters->V;
scene_ubs.rain_wind = glm::vec4{glm::vec3{air}, 0.f};
}
if (TDynamicObject const *owner = Global.pCamera.m_owner; owner && !!owner->MoverParameters->CabActive)
// the wipers of the vehicle the camera is in, or of the train driven when the camera is outside it: the moments the blades
// were at the ends of their sweep (the drops on the glass come back from then) are kept while the camera is away, so the glass
// looks as the blades left it when it's back in the cab. they're forgotten only for another vehicle
TDynamicObject const *owner = Global.pCamera.m_owner;
if ((owner == nullptr) || (owner->MoverParameters->CabActive == 0))
owner = (simulation::Train != nullptr) ? simulation::Train->Dynamic() : nullptr;
if (owner != m_wipervehicle)
{
m_wipervehicle = owner;
scene_ubs.wiper_timer_out = glm::vec4{-1000.};
scene_ubs.wiper_timer_return = glm::vec4{-1000.};
}
if (owner != nullptr)
{
auto const cabactive{owner->MoverParameters->CabActive != 0 ? owner->MoverParameters->CabActive : 1};
for (int i = 0; i < 4; ++i)
{
if (i < owner->dWiperPos.size())
{
int index = owner->MoverParameters->CabActive > 0 ? i : static_cast<int>(owner->dWiperPos.size() - 1) - i;
int index = cabactive > 0 ? i : static_cast<int>(owner->dWiperPos.size() - 1) - i;
scene_ubs.wiper_pos[i] = owner->dWiperPos[index];
if (owner->dWiperPos[index] > 0. && owner->wiperDirection[index])
{
@@ -1521,8 +1534,6 @@ void vulkan14_renderer::render_viewport(std::size_t const Index)
else
{
scene_ubs.wiper_pos = glm::vec4{0.};
scene_ubs.wiper_timer_out = glm::vec4{-1000.};
scene_ubs.wiper_timer_return = glm::vec4{-1000.};
}
}
// the stages after D: no contact shadows, no cascades fitted to the depth, no shadow maps of headlights
+2
View File
@@ -550,6 +550,8 @@ class vulkan14_renderer : public gfx_renderer, public gfx::scene_walk
glm::vec3 m_fogcolor{0.f};
glm::vec4 m_shadowcolor{colors::shadow};
gl::scene_ubs scene_ubs{};
// the vehicle whose wipers the timers of the blades in scene_ubs (wiper_timer_out / wiper_timer_return) follow
TDynamicObject const *m_wipervehicle{nullptr};
gl::light_data light_data{};
std::uint32_t m_lightcount{1}; // lights written to light_data
// the copies of the light buffer in the ring of the frame since the lights were last written, by the header and the sun