mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-11 18:07:13 +01:00
Merge pull request #257 from MaSzyna-EU07/fix/vehicle-removal-smoke
fix(gfx): a vehicle taken off the tracks stops smoking (#90)
This commit is contained in:
@@ -4852,7 +4852,7 @@ void TDynamicObject::RenderSounds() {
|
||||
#endif
|
||||
&& ( // compound test whether the vehicle belongs to user-driven consist (as these don't emit outer noise in cab view)
|
||||
FreeFlyModeFlag ? true : // in external view all vehicles emit outer noise
|
||||
// Global.pWorld->train() == nullptr ? true : // (can skip this check, with no player train the external view is a given)
|
||||
simulation::Train == nullptr ? true : // no player train, e.g. it went through a portal and the view isn't switched yet
|
||||
ctOwner == nullptr ? true : // standalone vehicle, can't be part of user-driven train
|
||||
ctOwner != simulation::Train->Dynamic()->ctOwner ? true : // confirmed isn't a part of the user-driven train
|
||||
Global.CabWindowOpen ? true : // sticking head out we get to hear outer noise
|
||||
|
||||
46
vehicle/smoke.cpp
Normal file
46
vehicle/smoke.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "vehicle/smoke.h"
|
||||
|
||||
#include "McZapkie/MOVER.h"
|
||||
|
||||
namespace smoke {
|
||||
|
||||
namespace {
|
||||
|
||||
// how hard the engine works, scaling the spawn rate of the source
|
||||
double engine_load(TMoverParameters const &Mover) {
|
||||
if (Mover.dizel_spinup) {
|
||||
// starting up, it puffs harder the faster it turns
|
||||
return ((Mover.enrot / 4) * 0.01);
|
||||
}
|
||||
auto const rpmrise{(Mover.DElist[Mover.MainCtrlPosNo].RPM - Mover.enrot) / 60};
|
||||
if (Mover.DirAbsolute == 0 || Mover.Im == 0) {
|
||||
// idling: speeding up to the revolutions of the master controller
|
||||
return ((rpmrise * 0.02) * (Mover.EnginePower * 0.005));
|
||||
}
|
||||
// under load: the more current the traction motors draw, the more smoke
|
||||
return ((rpmrise * (std::sqrt(Mover.Im) * 0.01) * 0.02) * (Mover.EnginePower * 0.005));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
float vehicle_spawn_count(TMoverParameters const &Mover, bool const Ontracks, spawn_rate const &Rate, double const Timedelta) {
|
||||
if (false == Ontracks) {
|
||||
return 0.f;
|
||||
}
|
||||
// the steady rate of the source, the way a source of the scenery spawns...
|
||||
auto const steady{std::min<float>(static_cast<float>(Rate.pending + (Rate.rate * Timedelta * Rate.fidelity)), Rate.limit)};
|
||||
// ...and on top of it the share of the engine
|
||||
return std::min<float>(static_cast<float>(steady + (Rate.rate * Timedelta * Rate.fidelity * engine_load(Mover))), Rate.limit);
|
||||
}
|
||||
|
||||
} // namespace smoke
|
||||
30
vehicle/smoke.h
Normal file
30
vehicle/smoke.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
class TMoverParameters;
|
||||
|
||||
// the smoke of a vehicle's engine, let out by the smoke sources of its model (rendering/particles.h)
|
||||
namespace smoke {
|
||||
|
||||
// what a smoke source spawns, before the engine of its vehicle is taken into account
|
||||
struct spawn_rate {
|
||||
float pending{0.f}; // particles left to spawn from the previous updates
|
||||
float rate{0.f}; // particles per second
|
||||
float fidelity{1.f}; // multiplier of the smoke settings
|
||||
float limit{0.f}; // most particles the source can have
|
||||
};
|
||||
|
||||
// number of particles the smoke source of a vehicle has to spawn after Timedelta seconds: the steady rate of the
|
||||
// source, plus a share which grows with the work of its engine. a vehicle taken off the tracks (Ontracks false: 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
|
||||
float vehicle_spawn_count(TMoverParameters const &Mover, bool Ontracks, spawn_rate const &Rate, double Timedelta);
|
||||
|
||||
} // namespace smoke
|
||||
Reference in New Issue
Block a user