18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-21 09:44:59 +01:00

fix(models): a scenery light that is off no longer shows lit for a moment the first time it comes into view (#407)

* fix(models): a scenery light that is off no longer shows lit for a moment the first time it comes into view

Since d13c27a7 (the light blinking rework) the opacity of a light changes step
by step from its last value, and the opacities start at 1. RaAnimate runs only
for the instances that are drawn, so a model with "lights 0" (a W24 LED
indicator, for one) was drawn lit when it first came into range and faded out
over 0.45 s. Before d13c27a7 the opacity of a plain on/off light was worked out
anew from a timer starting at 0, so a light that is off was off from the first
frame.

Now the first time an instance is animated its lights take their current
state at once, whether it came from the definition or from an event since.
Every later change fades as before. The light threshold modes (ls_Dark,
ls_Home) are untouched. The only other difference from before d13c27a7: a
light that is on no longer fades in the first time it is drawn.

* fix(models): the light opacity step written without an implicit double to float conversion (Sonar S5276)

The sum is still worked out in double and rounded to float once, as the
compound assignment did, so the result is the same to the bit.

---------

Co-authored-by: maj00r <maj00r@host>
This commit is contained in:
maj00r
2026-11-20 03:39:52 +01:00
committed by GitHub
parent 79c88c1793
commit 8794c80c58
2 changed files with 8 additions and 2 deletions

View File

@@ -597,6 +597,10 @@ void TAnimModel::RaAnimate( unsigned int const Framestamp ) {
if( Framestamp == m_framestamp ) { return; }
auto const timedelta { Timer::GetDeltaTime() };
// the opacities change step by step from where they are, and they start at 1. the first time the instance is
// drawn its lights take their current state at once, whether it came from the definition or from an event since:
// a fade from 1 showed a light that is off as lit for a moment, the first time it came into view
bool const transition { m_transition && m_lightsanimated };
// interpretacja ułamka zależnie od typu
// case ls_Off: ustalenie czasu migotania, t<1s (f>1Hz), np. 0.1 => t=0.1 (f=10Hz)
@@ -637,12 +641,13 @@ void TAnimModel::RaAnimate( unsigned int const Framestamp ) {
const float transitionontime = std::min(0.25f, std::min(ontime, offtime) * 0.95f);
const float transitionofftime = std::min(0.45f, std::min(ontime, offtime) * 0.95f);
if (on)
opacity += m_transition ? timedelta / transitionontime : 1.f; // increase to max value
opacity = static_cast<float>( opacity + ( transition ? timedelta / transitionontime : 1.0 ) ); // increase to max value
else
opacity -= m_transition ? timedelta / transitionofftime : 1.f; // reduce to zero
opacity = static_cast<float>( opacity - ( transition ? timedelta / transitionofftime : 1.0 ) ); // reduce to zero
// Clamp the opacity
opacity = std::clamp(opacity, 0.f, 1.f);
}
m_lightsanimated = true;
// Ra 2F1I: to by można pomijać dla modeli bez animacji, których jest większość
for (const auto entry : m_animlist) {

View File

@@ -225,6 +225,7 @@ public:
float fOffTime { 1.f / 2 };// { 60.f / 45.f / 2 }; // były stałymi, teraz mogą być zmienne dla każdego egzemplarza
// float fTransitionTime { fOnTime * 0.9f }; // time
bool m_transition { true }; // smooth transition between light states
bool m_lightsanimated { false }; // the lights were brought to their state at least once
unsigned int m_framestamp { 0 }; // id of last rendered gfx frame
// true if this instance is eligible for the batched/instanced render path: