mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 08:09:19 +02:00
reformat: use auto on certain types
This commit is contained in:
@@ -70,7 +70,7 @@ bool TEventLauncher::Load(cParser *parser)
|
||||
{ "radio_call1", radio_message::call1 },
|
||||
{ "radio_call3", radio_message::call3 }
|
||||
};
|
||||
auto lookup = messages.find( token );
|
||||
const auto lookup = messages.find( token );
|
||||
iKey = lookup != messages.end() ? lookup->second :
|
||||
// a jak więcej, to jakby numer klawisza jest
|
||||
vk_to_glfw_key(stol_def(token, 0));
|
||||
@@ -160,11 +160,11 @@ bool TEventLauncher::check_activation_key() {
|
||||
if (iKey <= 0)
|
||||
return false;
|
||||
|
||||
char key = iKey & 0xff;
|
||||
const char key = iKey & 0xff;
|
||||
|
||||
bool result = Console::Pressed(key);
|
||||
|
||||
char modifier = iKey >> 8;
|
||||
const char modifier = iKey >> 8;
|
||||
if (modifier & GLFW_MOD_SHIFT)
|
||||
result &= Global.shiftState;
|
||||
if (modifier & GLFW_MOD_CONTROL)
|
||||
|
||||
@@ -126,7 +126,7 @@ basic_event::event_conditions::test() const {
|
||||
if( flags & ( flags::text | flags::value1 | flags::value2 ) ) {
|
||||
// porównanie wartości
|
||||
for( auto &cellwrapper : *memcompare_cells ) {
|
||||
auto *cell { static_cast<TMemCell *>( std::get<scene::basic_node *>( cellwrapper ) ) };
|
||||
const auto *cell { static_cast<TMemCell *>( std::get<scene::basic_node *>( cellwrapper ) ) };
|
||||
if( cell == nullptr ) {
|
||||
// ErrorLog( "Event " + asName + " trying conditional_memcompare with nonexistent memcell" );
|
||||
continue; // though this is technically error, we treat it as a success to maintain backward compatibility
|
||||
@@ -357,7 +357,7 @@ basic_event::export_as_text( std::ostream &Output ) const {
|
||||
else {
|
||||
auto targetidx { 0 };
|
||||
for( auto &target : m_targets ) {
|
||||
auto *targetnode { std::get<scene::basic_node *>( target ) };
|
||||
const auto *targetnode { std::get<scene::basic_node *>( target ) };
|
||||
Output
|
||||
<< ( targetnode != nullptr ? targetnode->name() : std::get<std::string>( target ) )
|
||||
<< ( ++targetidx < m_targets.size() ? '|' : ' ' );
|
||||
@@ -534,7 +534,7 @@ updatevalues_event::run_() {
|
||||
// targetcell->LogValues();
|
||||
if( targetcell->Track == nullptr ) { continue; }
|
||||
// McZapkie-100302 - updatevalues oprocz zmiany wartosci robi putcommand dla wszystkich 'dynamic' na danym torze
|
||||
for( auto vehicle : targetcell->Track->Dynamics ) {
|
||||
for (const auto vehicle : targetcell->Track->Dynamics ) {
|
||||
if( vehicle->Mechanik ) {
|
||||
WriteLog( " Vehicle: [" + vehicle->name() + "]" );
|
||||
targetcell->PutCommand(
|
||||
@@ -575,7 +575,7 @@ getvalues_event::init() {
|
||||
init_targets( simulation::Memory, "memory cell" );
|
||||
// custom target initialization code
|
||||
for( auto &target : m_targets ) {
|
||||
auto *targetcell { static_cast<TMemCell *>( std::get<scene::basic_node *>( target ) ) };
|
||||
const auto *targetcell { static_cast<TMemCell *>( std::get<scene::basic_node *>( target ) ) };
|
||||
if( targetcell == nullptr ) { continue; }
|
||||
if( targetcell->IsVelocity() ) {
|
||||
// jeśli odczyt komórki a komórka zawiera komendę SetVelocity albo ShuntVelocity
|
||||
@@ -1189,7 +1189,7 @@ logvalues_event::run_() {
|
||||
else {
|
||||
// jeśli była podana nazwa komórki
|
||||
for( auto &target : m_targets ) {
|
||||
auto *targetcell { static_cast<TMemCell *>( std::get<scene::basic_node *>( target ) ) };
|
||||
const auto *targetcell { static_cast<TMemCell *>( std::get<scene::basic_node *>( target ) ) };
|
||||
if( targetcell == nullptr ) { continue; }
|
||||
targetcell->LogValues();
|
||||
}
|
||||
@@ -1322,7 +1322,7 @@ multi_event::export_as_text_( std::ostream &Output ) const {
|
||||
|
||||
for( auto const &childevent : m_children ) {
|
||||
if( true == std::get<bool>( childevent ) ) {
|
||||
auto *childeventdata { std::get<basic_event *>( childevent ) };
|
||||
const auto *childeventdata { std::get<basic_event *>( childevent ) };
|
||||
Output
|
||||
<< ( childeventdata != nullptr ?
|
||||
childeventdata->m_name :
|
||||
@@ -1335,7 +1335,7 @@ multi_event::export_as_text_( std::ostream &Output ) const {
|
||||
Output << "else ";
|
||||
for( auto const &childevent : m_children ) {
|
||||
if( false == std::get<bool>( childevent ) ) {
|
||||
auto *childeventdata{ std::get<basic_event *>( childevent ) };
|
||||
const auto *childeventdata{ std::get<basic_event *>( childevent ) };
|
||||
Output
|
||||
<< ( childeventdata != nullptr ?
|
||||
childeventdata->m_name :
|
||||
@@ -1652,7 +1652,7 @@ animation_event::deserialize_( cParser &Input, scene::scratch_data &Scratchpad )
|
||||
{
|
||||
m_animationfilename = token;
|
||||
std::ifstream file( paths::models + m_animationfilename, std::ios::binary | std::ios::ate ); file.unsetf( std::ios::skipws );
|
||||
auto size = file.tellg(); // ios::ate already positioned us at the end of the file
|
||||
const auto size = file.tellg(); // ios::ate already positioned us at the end of the file
|
||||
file.seekg( 0, std::ios::beg ); // rewind the caret afterwards
|
||||
// animation size, previously held in param 7
|
||||
m_animationfilesize = size;
|
||||
@@ -1685,7 +1685,7 @@ animation_event::run_() {
|
||||
// animation modes target specific submodels
|
||||
m_animationcontainers.remove_if([this](std::weak_ptr<TAnimContainer> ptr)
|
||||
{
|
||||
auto targetcontainer = ptr.lock();
|
||||
const auto targetcontainer = ptr.lock();
|
||||
if (!targetcontainer)
|
||||
return true;
|
||||
|
||||
@@ -2235,7 +2235,7 @@ make_event( cParser &Input, scene::scratch_data &Scratchpad ) {
|
||||
|
||||
event_manager::~event_manager() {
|
||||
|
||||
for( auto *event : m_events ) {
|
||||
for (const auto *event : m_events ) {
|
||||
delete event;
|
||||
}
|
||||
}
|
||||
@@ -2292,7 +2292,7 @@ event_manager::update() {
|
||||
bool
|
||||
event_manager::insert( basic_event *Event ) {
|
||||
// najpierw sprawdzamy, czy nie ma, a potem dopisujemy
|
||||
auto lookup = m_eventmap.find( Event->m_name );
|
||||
const auto lookup = m_eventmap.find( Event->m_name );
|
||||
if( lookup != m_eventmap.end() ) {
|
||||
// duplicate of already existing event
|
||||
auto const size = Event->m_name.size();
|
||||
@@ -2499,7 +2499,7 @@ event_manager::InitEvents() {
|
||||
void
|
||||
event_manager::InitLaunchers() {
|
||||
|
||||
std::vector<basic_table<TEventLauncher> *> launchertables {
|
||||
const std::vector<basic_table<TEventLauncher> *> launchertables {
|
||||
&m_inputdrivenlaunchers,
|
||||
&m_radiodrivenlaunchers
|
||||
};
|
||||
|
||||
@@ -678,7 +678,7 @@ public:
|
||||
basic_event *
|
||||
FindEvent( std::string const &Name );
|
||||
inline TEventLauncher* FindEventlauncher(std::string const &Name) {
|
||||
auto ptr = m_inputdrivenlaunchers.find(Name);
|
||||
const auto ptr = m_inputdrivenlaunchers.find(Name);
|
||||
return ptr ? ptr : m_radiodrivenlaunchers.find(Name);
|
||||
}
|
||||
// legacy method, inserts specified event in the event query
|
||||
|
||||
@@ -157,7 +157,7 @@ bool TMemCell::Compare( std::string const &szTestText, double const fTestValue1,
|
||||
|
||||
if( TestFlag( CheckMask, basic_event::flags::text ) ) {
|
||||
// porównać teksty
|
||||
auto range = szTestText.find( '*' );
|
||||
const auto range = szTestText.find( '*' );
|
||||
auto const result { (
|
||||
range == std::string::npos ?
|
||||
compare( szText, szTestText, TextOperator ) :
|
||||
@@ -277,7 +277,7 @@ memory_table::InitCells() {
|
||||
void
|
||||
memory_table::log_all() {
|
||||
|
||||
for( auto *cell : m_items ) {
|
||||
for (const auto *cell : m_items ) {
|
||||
cell->LogValues();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,8 +193,8 @@ double TSegment::RombergIntegral(double const fA, double const fB) const
|
||||
double TSegment::GetTFromS(double const s) const
|
||||
{
|
||||
// initial guess for Newton's method
|
||||
double fTolerance = 0.001;
|
||||
double fRatio = s / RombergIntegral(0, 1);
|
||||
const double fTolerance = 0.001;
|
||||
const double fRatio = s / RombergIntegral(0, 1);
|
||||
double fTime = std::lerp( 0.0, 1.0, fRatio );
|
||||
|
||||
int iteration = 0;
|
||||
@@ -295,10 +295,10 @@ const double fDirectionOffset = 0.1; // długość wektora do wyliczenia kierunk
|
||||
|
||||
glm::dvec3 TSegment::GetDirection(double const fDistance) const
|
||||
{ // takie toporne liczenie pochodnej dla podanego dystansu od Point1
|
||||
double t1 = GetTFromS(fDistance - fDirectionOffset);
|
||||
const double t1 = GetTFromS(fDistance - fDirectionOffset);
|
||||
if (t1 <= 0.0)
|
||||
return CPointOut - Point1; // na zewnątrz jako prosta
|
||||
double t2 = GetTFromS(fDistance + fDirectionOffset);
|
||||
const double t2 = GetTFromS(fDistance + fDirectionOffset);
|
||||
if (t2 >= 1.0)
|
||||
return Point1 - CPointIn; // na zewnątrz jako prosta
|
||||
return FastGetPoint(t2) - FastGetPoint(t1);
|
||||
@@ -306,10 +306,10 @@ glm::dvec3 TSegment::GetDirection(double const fDistance) const
|
||||
|
||||
glm::dvec3 TSegment::FastGetDirection(double fDistance, double fOffset)
|
||||
{ // takie toporne liczenie pochodnej dla parametru 0.0÷1.0
|
||||
double t1 = fDistance - fOffset;
|
||||
const double t1 = fDistance - fOffset;
|
||||
if (t1 <= 0.0)
|
||||
return CPointOut - Point1; // wektor na początku jest stały
|
||||
double t2 = fDistance + fOffset;
|
||||
const double t2 = fDistance + fOffset;
|
||||
if (t2 >= 1.0)
|
||||
return Point2 - CPointIn; // wektor na końcu jest stały
|
||||
return FastGetPoint(t2) - FastGetPoint(t1);
|
||||
|
||||
@@ -1082,7 +1082,7 @@ const int numPts = 4;
|
||||
|
||||
bool TTrack::CheckDynamicObject(TDynamicObject *Dynamic)
|
||||
{ // sprawdzenie, czy pojazd jest przypisany do toru
|
||||
for( auto dynamic : Dynamics ) {
|
||||
for (const auto dynamic : Dynamics ) {
|
||||
if( dynamic == Dynamic ) {
|
||||
return true;
|
||||
}
|
||||
@@ -1142,7 +1142,7 @@ bool TTrack::InMovement()
|
||||
if (!SwitchExtension->CurrentIndex)
|
||||
return false; // 0=zablokowana się nie animuje
|
||||
// trzeba każdorazowo porównywać z kątem modelu
|
||||
auto ac = SwitchExtension->pModel ? SwitchExtension->pModel->GetContainer() : nullptr;
|
||||
const auto ac = SwitchExtension->pModel ? SwitchExtension->pModel->GetContainer() : nullptr;
|
||||
return ac ?
|
||||
ac->AngleGet() != SwitchExtension->fOffset ||
|
||||
!(ac->TransGet() == SwitchExtension->vTrans) :
|
||||
@@ -1208,7 +1208,7 @@ TTrack *TTrack::Next(TTrack *visitor) {
|
||||
else
|
||||
return trPrev;
|
||||
} else if (eType == tt_Switch) {
|
||||
int state = GetSwitchState();
|
||||
const int state = GetSwitchState();
|
||||
|
||||
if (SwitchExtension->pPrevs[0] == visitor
|
||||
|| SwitchExtension->pPrevs[1] == visitor)
|
||||
@@ -1754,7 +1754,7 @@ void TTrack::create_geometry( gfx::geometrybank_handle const &Bank ) {
|
||||
|
||||
void TTrack::RenderDynSounds()
|
||||
{ // odtwarzanie dźwięków pojazdów jest niezależne od ich wyświetlania
|
||||
for( auto dynamic : Dynamics ) {
|
||||
for (const auto dynamic : Dynamics ) {
|
||||
dynamic->RenderSounds();
|
||||
}
|
||||
};
|
||||
@@ -2095,7 +2095,7 @@ TTrack * TTrack::RaAnimate()
|
||||
//---------------------------------------------------------------------------
|
||||
void TTrack::RadioStop()
|
||||
{ // przekazanie pojazdom rozkazu zatrzymania
|
||||
for( auto dynamic : Dynamics ) {
|
||||
for (const auto dynamic : Dynamics ) {
|
||||
dynamic->RadioStop();
|
||||
}
|
||||
};
|
||||
@@ -2147,7 +2147,7 @@ int TTrack::TestPoint(const glm::dvec3 *Point)
|
||||
break;
|
||||
case tt_Switch: // zwrotnica
|
||||
{
|
||||
int state = GetSwitchState(); // po co?
|
||||
const int state = GetSwitchState(); // po co?
|
||||
// Ra: TODO: jak się zmieni na bezpośrednie odwołania do segmentow zwrotnicy,
|
||||
// to się wykoleja, ponieważ trNext zależy od przełożenia
|
||||
Switch(0);
|
||||
|
||||
@@ -474,7 +474,7 @@ double TTraction::VoltageGet(double u, double i)
|
||||
// 1. zasilacz psPower[0] z rezystancją fResistance[0] oraz jego wewnętrzną
|
||||
// 2. zasilacz psPower[1] z rezystancją fResistance[1] oraz jego wewnętrzną
|
||||
// 3. zasilacz psPowered z jego wewnętrzną rezystancją dla przęseł zasilanych bezpośrednio
|
||||
double res = i != 0.0 ? u / i : 10000.0;
|
||||
const double res = i != 0.0 ? u / i : 10000.0;
|
||||
if( psPowered != nullptr ) {
|
||||
// yB: dla zasilanego nie baw się w gwiazdy, tylko bierz bezpośrednio
|
||||
return res != 0.0 ? psPowered->CurrentGet(res) * res : 0.0;
|
||||
|
||||
@@ -125,7 +125,7 @@ double TTractionPowerSource::CurrentGet(double res)
|
||||
}
|
||||
if (res > 0 || (res < 0 && (Recuperation || true)))
|
||||
TotalAdmitance += 1.0 / res; // połączenie równoległe rezystancji jest równoważne sumie admitancji
|
||||
float NomVolt = TotalPreviousAdmitance < 0 ? NominalVoltage * 1.083 : NominalVoltage;
|
||||
const float NomVolt = TotalPreviousAdmitance < 0 ? NominalVoltage * 1.083 : NominalVoltage;
|
||||
TotalCurrent = TotalPreviousAdmitance != 0.0 ?
|
||||
NomVolt / (InternalRes + 1.0 / TotalPreviousAdmitance) :
|
||||
0.0; // napięcie dzielone przez sumę rezystancji wewnętrznej i obciążenia
|
||||
|
||||
@@ -51,7 +51,7 @@ TTrack * TTrackFollower::SetCurrentTrack(TTrack *pTrack, int end)
|
||||
{
|
||||
case tt_Switch: // jeśli zwrotnica, to przekładamy ją, aby uzyskać dobry segment
|
||||
{
|
||||
int i = end ? pCurrentTrack->iNextDirection : pCurrentTrack->iPrevDirection;
|
||||
const int i = end ? pCurrentTrack->iNextDirection : pCurrentTrack->iPrevDirection;
|
||||
if (i > 0) // jeżeli wjazd z ostrza
|
||||
pTrack->SwitchForced(i >> 1, Owner); // to przełożenie zwrotnicy - rozprucie!
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ basic_station::update_load( TDynamicObject *First, Mtable::TTrainParameters &Sch
|
||||
if( parameters.LoadType.name == "passengers" ) {
|
||||
// NOTE: for the time being we're doing simple, random load change calculation
|
||||
// TODO: exchange driven by station parameters and time of the day
|
||||
auto unloadcount = static_cast<int>(
|
||||
const auto unloadcount = static_cast<int>(
|
||||
TestFlag( parameters.DamageFlag, dtrain_out ) ? parameters.LoadAmount :
|
||||
laststop ? parameters.LoadAmount :
|
||||
firststop ? 0 :
|
||||
|
||||
Reference in New Issue
Block a user