17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-08 09:27:54 +01:00

test(gfx): unit tests of the smoke of a vehicle taken off the tracks (#90)

The spawn count of the smoke source of a vehicle moves out of
smoke_source::update() into smoke::vehicle_spawn_count() (vehicle/smoke.h),
a free function on the mover state, which joins the core library so the
unit tests can call it the way the source does. The rates are the same as
before, the steady rate of the source still counted in before the share of
the engine.

Tests: tests/unit/test_smoke.cpp. A vehicle taken off the tracks spawns no
smoke and drops the pending particles, with the engine starting, idling or
under load; a road vehicle back from the pool puffs again; the engine adds
to the steady rate; the pending count stays within the room of the source.
Two of the four fail without the fix.

Checked again on td.scn with the SM42 driven into a portal: the smoke
source keeps puffing on the run and drops to 0 particles once the vehicle
is taken off the tracks.
This commit is contained in:
jerrrrycho
2026-11-07 11:38:49 +01:00
parent f94b308062
commit 4489dd7469
5 changed files with 186 additions and 51 deletions

View File

@@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/.
#include "model/AnimModel.h"
#include "simulation/simulationenvironment.h"
#include "utilities/Logs.h"
#include "vehicle/smoke.h"
void
@@ -162,60 +163,32 @@ smoke_source::update( double const Timedelta, bool const Onlydespawn ) {
glm::dvec3{ std::numeric_limits<double>::max() },
glm::dvec3{ std::numeric_limits<double>::lowest() } };
// a vehicle taken off the tracks (gone through a portal, or waiting in the pool of the road traffic) puffs no more,
// the particles it already let out fade away as usual
auto const nospawn {
false == Global.Smoke
|| true == Onlydespawn
|| ( m_ownertype == owner_type::vehicle && false == m_owner.vehicle->bEnabled ) };
auto const spawning { ( true == Global.Smoke ) && ( false == Onlydespawn ) };
m_spawncount = (
( true == nospawn ) ?
0.f :
std::min<float>(
static_cast<float>(m_spawncount + ( m_spawnrate * Timedelta * Global.SmokeFidelity )),
static_cast<float>(m_max_particles) ) );
// consider special spawn rate cases
if( m_ownertype == owner_type::vehicle ) {
if (Global.AirTemperature <= 5.f || m_owner.vehicle->MoverParameters->dizel_heat.Ts < 45.f)
{
m_emitter.color = glm::vec3{128, 128, 128};
}
if (m_owner.vehicle->MoverParameters->dizel_spinup == true)
{
m_spawncount =
(true == nospawn) ?
0.f :
std::min<float>(
// m_spawncount + ( m_spawnrate * Timedelta * Global.SmokeFidelity ),
static_cast<float>(m_spawncount +(m_spawnrate * Timedelta * Global.SmokeFidelity * (((m_owner.vehicle->MoverParameters->enrot) / 4 ) * 0.01))), static_cast<float>(m_max_particles));
}
else
{
if (m_owner.vehicle->MoverParameters->DirAbsolute == 0 ||
m_owner.vehicle->MoverParameters->Im == 0)
{
m_spawncount =
(true == nospawn) ?
0.f :
std::min<float>(
// m_spawncount + ( m_spawnrate * Timedelta * Global.SmokeFidelity ),
static_cast<float>(m_spawncount + (m_spawnrate * Timedelta * Global.SmokeFidelity * ((((m_owner.vehicle->MoverParameters->DElist[m_owner.vehicle->MoverParameters->MainCtrlPosNo].RPM -m_owner.vehicle->MoverParameters->enrot) /60) *0.02) *(m_owner.vehicle->MoverParameters->EnginePower * 0.005)))), static_cast<float>(m_max_particles));
}
else
{
m_spawncount =
(true == nospawn) ?
0.f :
std::min<float>(
// m_spawncount + ( m_spawnrate * Timedelta * Global.SmokeFidelity ),
static_cast<float>(m_spawncount + (m_spawnrate * Timedelta * Global.SmokeFidelity * ((((m_owner.vehicle->MoverParameters->DElist[m_owner.vehicle->MoverParameters->MainCtrlPosNo].RPM -m_owner.vehicle->MoverParameters->enrot) /60) * (sqrt(m_owner.vehicle->MoverParameters->Im) * 0.01) * 0.02) *(m_owner.vehicle->MoverParameters->EnginePower * 0.005)))), static_cast<float>(m_max_particles));
}
}
}
auto const &mover { *m_owner.vehicle->MoverParameters };
if( Global.AirTemperature <= 5.f || mover.dizel_heat.Ts < 45.f ) {
m_emitter.color = glm::vec3{ 128, 128, 128 };
}
// a vehicle taken off the tracks (gone through a portal, or waiting in the pool of the road traffic) puffs no more,
// the particles it already let out fade away as usual
m_spawncount = (
( true == spawning ) ?
smoke::vehicle_spawn_count(
mover, m_owner.vehicle->bEnabled,
{ m_spawncount, m_spawnrate, Global.SmokeFidelity, static_cast<float>( m_max_particles ) },
Timedelta ) :
0.f );
}
else {
m_spawncount = (
( true == spawning ) ?
std::min<float>(
static_cast<float>(m_spawncount + ( m_spawnrate * Timedelta * Global.SmokeFidelity )),
static_cast<float>(m_max_particles) ) :
0.f );
}
// update spawned particles
for( auto particleiterator { std::begin( m_particles ) }; particleiterator != std::end( m_particles ); ++particleiterator ) {