From a700d36ea7d8a747aab2ee1a05e11c4a1a76baef Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Wed, 1 Nov 2017 02:54:31 +0100 Subject: [PATCH 1/3] maintenance: minor code touch ups --- AnimModel.h | 2 +- Button.h | 1 + EvLaunch.cpp | 4 ++-- EvLaunch.h | 2 +- McZapkie/mctools.cpp | 2 +- McZapkie/mctools.h | 2 +- MemCell.cpp | 2 +- MemCell.h | 4 ++-- Model3d.cpp | 2 +- Model3d.h | 14 ++++++-------- ResourceManager.h | 10 +++++----- Texture.cpp | 2 +- Texture.h | 2 +- Track.h | 23 ++++++++++++++--------- Traction.h | 2 +- openglgeometrybank.h | 4 +++- scene.cpp | 8 ++++---- scene.h | 9 +++++---- scenenode.h | 2 +- simulation.h | 2 +- 20 files changed, 53 insertions(+), 46 deletions(-) diff --git a/AnimModel.h b/AnimModel.h index adcd8d9d..fdcec615 100644 --- a/AnimModel.h +++ b/AnimModel.h @@ -125,7 +125,7 @@ class TAnimModel : public editor::basic_node { public: // constructors - TAnimModel( scene::node_data const &Nodedata ); + explicit TAnimModel( scene::node_data const &Nodedata ); // destructor ~TAnimModel(); // methods diff --git a/Button.h b/Button.h index 67061a47..addc43c0 100644 --- a/Button.h +++ b/Button.h @@ -32,6 +32,7 @@ class TButton void play(); // plays specified sound + static void play( PSound Sound ); diff --git a/EvLaunch.cpp b/EvLaunch.cpp index 6abe7350..38c23da1 100644 --- a/EvLaunch.cpp +++ b/EvLaunch.cpp @@ -134,8 +134,8 @@ bool TEventLauncher::check_conditions() // key and modifier auto const modifier = ( iKey & 0xff00 ) >> 8; bCond = ( Console::Pressed( iKey & 0xff ) ) - && ( modifier & 1 ? Global::shiftState : true ) - && ( modifier & 2 ? Global::ctrlState : true ); + && ( ( modifier & 1 ) ? Global::shiftState : true ) + && ( ( modifier & 2 ) ? Global::ctrlState : true ); } else { // just key diff --git a/EvLaunch.h b/EvLaunch.h index d6fe9324..b10bed2d 100644 --- a/EvLaunch.h +++ b/EvLaunch.h @@ -18,7 +18,7 @@ class TEventLauncher : public editor::basic_node { public: // constructor - TEventLauncher( scene::node_data const &Nodedata ) : basic_node( Nodedata ) {} + explicit TEventLauncher( scene::node_data const &Nodedata ) : basic_node( Nodedata ) {} // legacy constructor TEventLauncher() = default; diff --git a/McZapkie/mctools.cpp b/McZapkie/mctools.cpp index 7cb32c88..4fff8667 100644 --- a/McZapkie/mctools.cpp +++ b/McZapkie/mctools.cpp @@ -294,7 +294,7 @@ FileExists( std::string const &Filename ) { } // returns time of last modification for specified file -__time64_t +std::time_t last_modified( std::string const &Filename ) { struct stat filestat; diff --git a/McZapkie/mctools.h b/McZapkie/mctools.h index 518cd77d..c86f0731 100644 --- a/McZapkie/mctools.h +++ b/McZapkie/mctools.h @@ -160,4 +160,4 @@ extract_value( bool &Variable, std::string const &Key, std::string const &Input, bool FileExists( std::string const &Filename ); // returns time of last modification for specified file -__time64_t last_modified( std::string const &Filename ); \ No newline at end of file +std::time_t last_modified( std::string const &Filename ); \ No newline at end of file diff --git a/MemCell.cpp b/MemCell.cpp index 51bc2194..7e8b379f 100644 --- a/MemCell.cpp +++ b/MemCell.cpp @@ -139,7 +139,7 @@ bool TMemCell::Compare( std::string const &szTestText, double const fTestValue1, && ( !TestFlag( CheckMask, conditional_memval2 ) || ( fValue2 == fTestValue2 ) ) ); }; -bool TMemCell::IsVelocity() +bool TMemCell::IsVelocity() const { // sprawdzenie, czy event odczytu tej komórki ma być do skanowania, czy do kolejkowania if (eCommand == cm_SetVelocity) return true; diff --git a/MemCell.h b/MemCell.h index 97e1eb01..061b75d9 100644 --- a/MemCell.h +++ b/MemCell.h @@ -19,7 +19,7 @@ class TMemCell : public editor::basic_node { public: std::string asTrackName; // McZapkie-100302 - zeby nazwe toru na ktory jest Putcommand wysylane pamietac - TMemCell( scene::node_data const &Nodedata ); + explicit TMemCell( scene::node_data const &Nodedata ); void UpdateValues( std::string const &szNewText, double const fNewValue1, double const fNewValue2, int const CheckMask ); @@ -46,7 +46,7 @@ public: return bCommand; }; void StopCommandSent(); TCommandType CommandCheck(); - bool IsVelocity(); + bool IsVelocity() const; void AssignEvents(TEvent *e); private: diff --git a/Model3d.cpp b/Model3d.cpp index 9e9200b5..799c136a 100644 --- a/Model3d.cpp +++ b/Model3d.cpp @@ -1752,7 +1752,7 @@ void TModel3d::Init() // 2012-02 funkcje do tworzenia terenu z E3D //----------------------------------------------------------------------------- -int TModel3d::TerrainCount() +int TModel3d::TerrainCount() const { // zliczanie kwadratów kilometrowych (główna // linia po Next) do tworznia tablicy int i = 0; diff --git a/Model3d.h b/Model3d.h index 8a0cb8b5..70c7c895 100644 --- a/Model3d.h +++ b/Model3d.h @@ -183,15 +183,13 @@ public: }; void InitialRotate(bool doit); void BinInit(TSubModel *s, float4x4 *m, std::vector *t, std::vector *n, bool dynamic); - void ReplacableSet(material_handle const *r, int a) - { + static void ReplacableSet(material_handle const *r, int a) { ReplacableSkinId = r; - iAlpha = a; - }; + iAlpha = a; }; void Name_Material( std::string const &Name ); void Name( std::string const &Name ); // Ra: funkcje do budowania terenu z E3D - int Flags() { return iFlags; }; + int Flags() const { return iFlags; }; void UnFlagNext() { iFlags &= 0x00FFFFFF; }; void ColorsSet( glm::vec3 const &Ambient, glm::vec3 const &Diffuse, glm::vec3 const &Specular ); // sets light level (alpha component of illumination color) to specified value @@ -200,7 +198,7 @@ public: return fMatrix ? *(fMatrix->TranslationGet()) + v_TransVector : v_TransVector; } inline float3 Translation2Get() { return *(fMatrix->TranslationGet()) + Child->Translation1Get(); } - material_handle GetMaterial() { + material_handle GetMaterial() const { return m_material; } void ParentMatrix(float4x4 *m); float MaxY( float4x4 const &m ); @@ -249,8 +247,8 @@ public: void SaveToBinFile(std::string const &FileName); int Flags() const { return iFlags; }; void Init(); - std::string NameGet() { return m_filename; }; - int TerrainCount(); + std::string NameGet() const { return m_filename; }; + int TerrainCount() const; TSubModel * TerrainSquare(int n); void deserialize(std::istream &s, size_t size, bool dynamic); }; diff --git a/ResourceManager.h b/ResourceManager.h index ae890b57..0d28f747 100644 --- a/ResourceManager.h +++ b/ResourceManager.h @@ -61,11 +61,11 @@ class garbage_collector { public: // constructor: - garbage_collector( Container_ &Container, int const Secondstolive, int const Sweepsize, std::string const Resourcename = "resource" ) : - m_container( Container ), - m_unusedresourcetimetolive { std::chrono::seconds( Secondstolive ) }, - m_unusedresourcesweepsize( Sweepsize ), - m_resourcename( Resourcename ) + garbage_collector( Container_ &Container, unsigned int const Secondstolive, std::size_t const Sweepsize, std::string const Resourcename = "resource" ) : + m_unusedresourcetimetolive{ std::chrono::seconds{ Secondstolive } }, + m_unusedresourcesweepsize{ Sweepsize }, + m_resourcename{ Resourcename }, + m_container{ Container } {} // methods: diff --git a/Texture.cpp b/Texture.cpp index b4c2716c..6c6d5448 100644 --- a/Texture.cpp +++ b/Texture.cpp @@ -625,7 +625,7 @@ opengl_texture::release( bool const Backup ) { } void -opengl_texture::set_filtering() { +opengl_texture::set_filtering() const { // default texture mode ::glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); diff --git a/Texture.h b/Texture.h index 62235f4a..64c0e11b 100644 --- a/Texture.h +++ b/Texture.h @@ -60,7 +60,7 @@ private: void load_DDS(); void load_TEX(); void load_TGA(); - void set_filtering(); + void set_filtering() const; void downsize( GLuint const Format ); // members diff --git a/Track.h b/Track.h index 250ebd96..2979525d 100644 --- a/Track.h +++ b/Track.h @@ -96,16 +96,11 @@ class TSwitchExtension class TIsolated { // obiekt zbierający zajętości z kilku odcinków - int iAxles = 0; // ilość osi na odcinkach obsługiwanych przez obiekt - TIsolated *pNext = nullptr; // odcinki izolowane są trzymane w postaci listy jednikierunkowej - static TIsolated *pRoot; // początek listy - public: - std::string asName; // nazwa obiektu, baza do nazw eventów - TEvent *evBusy = nullptr; // zdarzenie wyzwalane po zajęciu grupy - TEvent *evFree = nullptr; // zdarzenie wyzwalane po całkowitym zwolnieniu zajętości grupy - TMemCell *pMemCell = nullptr; // automatyczna komórka pamięci, która współpracuje z odcinkiem izolowanym +public: + // constructors TIsolated(); TIsolated(const std::string &n, TIsolated *i); + // methods static void DeleteAll(); static TIsolated * Find(const std::string &n); // znalezienie obiektu albo utworzenie nowego void Modify(int i, TDynamicObject *o); // dodanie lub odjęcie osi @@ -115,6 +110,16 @@ class TIsolated return (pRoot); }; TIsolated * Next() { return (pNext); }; + // members + std::string asName; // nazwa obiektu, baza do nazw eventów + TEvent *evBusy { nullptr }; // zdarzenie wyzwalane po zajęciu grupy + TEvent *evFree { nullptr }; // zdarzenie wyzwalane po całkowitym zwolnieniu zajętości grupy + TMemCell *pMemCell { nullptr }; // automatyczna komórka pamięci, która współpracuje z odcinkiem izolowanym +private: + // members + int iAxles { 0 }; // ilość osi na odcinkach obsługiwanych przez obiekt + TIsolated *pNext { nullptr }; // odcinki izolowane są trzymane w postaci listy jednikierunkowej + static TIsolated *pRoot; // początek listy }; // trajektoria ruchu - opakowanie @@ -184,7 +189,7 @@ public: bool ScannedFlag = false; // McZapkie: do zaznaczania kolorem torów skanowanych przez AI TGroundNode *nFouling[ 2 ] = { nullptr, nullptr }; // współrzędne ukresu albo oporu kozła - TTrack( scene::node_data const &Nodedata ); + explicit TTrack( scene::node_data const &Nodedata ); virtual ~TTrack(); void Init(); diff --git a/Traction.h b/Traction.h index 20ac20d2..3f75d60e 100644 --- a/Traction.h +++ b/Traction.h @@ -52,7 +52,7 @@ class TTraction : public editor::basic_node { glm::dvec3 m_origin; geometry_handle m_geometry; - TTraction( scene::node_data const &Nodedata ); + explicit TTraction( scene::node_data const &Nodedata ); void Load( cParser *parser, glm::dvec3 const &pOrigin ); // set origin point diff --git a/openglgeometrybank.h b/openglgeometrybank.h index 05a813c1..a13f803e 100644 --- a/openglgeometrybank.h +++ b/openglgeometrybank.h @@ -199,8 +199,10 @@ private: bind_buffer(); void delete_buffer(); + static void bind_streams( stream_units const &Units, unsigned int const Streams ); + static void release_streams(); @@ -310,7 +312,7 @@ private: // methods inline bool - valid( geometry_handle const &Geometry ) { + valid( geometry_handle const &Geometry ) const { return ( ( Geometry.bank != 0 ) && ( Geometry.bank <= m_geometrybanks.size() ) ); } inline diff --git a/scene.cpp b/scene.cpp index cdf7e511..16373e93 100644 --- a/scene.cpp +++ b/scene.cpp @@ -394,7 +394,7 @@ basic_cell::register_end( TTraction *Traction ) { // find a vehicle located nearest to specified point, within specified radius, optionally ignoring vehicles without drivers. reurns: located vehicle and distance std::tuple -basic_cell::find( glm::dvec3 const &Point, float const Radius, bool const Onlycontrolled, bool const Findbycoupler ) { +basic_cell::find( glm::dvec3 const &Point, float const Radius, bool const Onlycontrolled, bool const Findbycoupler ) const { TDynamicObject *vehiclenearest { nullptr }; float leastdistance { std::numeric_limits::max() }; @@ -429,7 +429,7 @@ basic_cell::find( glm::dvec3 const &Point, float const Radius, bool const Onlyco // finds a path with one of its ends located in specified point. returns: located path and id of the matching endpoint std::tuple -basic_cell::find( glm::dvec3 const &Point, TTrack const *Exclude ) { +basic_cell::find( glm::dvec3 const &Point, TTrack const *Exclude ) const { Math3D::vector3 point { Point.x, Point.y, Point.z }; // sad workaround until math classes unification int endpointid; @@ -449,7 +449,7 @@ basic_cell::find( glm::dvec3 const &Point, TTrack const *Exclude ) { // finds a traction piece with one of its ends located in specified point. returns: located traction piece and id of the matching endpoint std::tuple -basic_cell::find( glm::dvec3 const &Point, TTraction const *Exclude ) { +basic_cell::find( glm::dvec3 const &Point, TTraction const *Exclude ) const { int endpointid; @@ -468,7 +468,7 @@ basic_cell::find( glm::dvec3 const &Point, TTraction const *Exclude ) { // finds a traction piece located nearest to specified point, sharing section with specified other piece and powered in specified direction. returns: located traction piece std::tuple -basic_cell::find( glm::dvec3 const &Point, TTraction const *Other, int const Currentdirection ) { +basic_cell::find( glm::dvec3 const &Point, TTraction const *Other, int const Currentdirection ) const { TTraction *tractionnearest { nullptr }; diff --git a/scene.h b/scene.h index 06bcd6d6..d4b1853d 100644 --- a/scene.h +++ b/scene.h @@ -116,16 +116,16 @@ public: register_end( TTraction *Traction ); // find a vehicle located nearest to specified point, within specified radius. reurns: located vehicle and distance std::tuple - find( glm::dvec3 const &Point, float const Radius, bool const Onlycontrolled, bool const Findbycoupler ); + find( glm::dvec3 const &Point, float const Radius, bool const Onlycontrolled, bool const Findbycoupler ) const; // finds a path with one of its ends located in specified point. returns: located path and id of the matching endpoint std::tuple - find( glm::dvec3 const &Point, TTrack const *Exclude ); + find( glm::dvec3 const &Point, TTrack const *Exclude ) const; // finds a traction piece with one of its ends located in specified point. returns: located traction piece and id of the matching endpoint std::tuple - find( glm::dvec3 const &Point, TTraction const *Exclude ); + find( glm::dvec3 const &Point, TTraction const *Exclude ) const; // finds a traction piece located nearest to specified point, sharing section with specified other piece and powered in specified direction. returns: located traction piece std::tuple - find( glm::dvec3 const &Point, TTraction const *Other, int const Currentdirection ); + find( glm::dvec3 const &Point, TTraction const *Other, int const Currentdirection ) const; // sets center point of the cell void center( glm::dvec3 Center ); @@ -351,6 +351,7 @@ private: bool point_inside( glm::dvec3 const &Location ); // legacy method, trims provided shape to fit into a section. adds trimmed part at the end of provided list, returns true if changes were made + static bool RaTriangleDivider( shape_node &Shape, std::deque &Shapes ); // provides access to section enclosing specified point diff --git a/scenenode.h b/scenenode.h index 449575b3..7c2c7988 100644 --- a/scenenode.h +++ b/scenenode.h @@ -307,7 +307,7 @@ struct basic_node { public: // constructor - basic_node( scene::node_data const &Nodedata ); + explicit basic_node( scene::node_data const &Nodedata ); // destructor virtual ~basic_node() = default; // methods diff --git a/simulation.h b/simulation.h index 4addbe49..862f8445 100644 --- a/simulation.h +++ b/simulation.h @@ -33,7 +33,7 @@ public: // methods // legacy method, calculates changes in simulation state over specified time void - update( double dt, int iter ); + update( double Deltatime, int Iterationcount ); bool deserialize( std::string const &Scenariofile ); From 3456fbd651b13ef741b877e6447e5fe8e5731995 Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Wed, 1 Nov 2017 03:25:54 +0100 Subject: [PATCH 2/3] improved recognition and handling of light emitting vehicles --- Driver.cpp | 4 +- DynObj.cpp | 75 +++++++++++++----------- DynObj.h | 3 +- McZapkie/MOVER.h | 28 ++++----- Train.cpp | 144 +++++++++++++++++++++++------------------------ World.cpp | 14 ++--- lightarray.cpp | 33 ++++------- simulation.cpp | 9 +-- 8 files changed, 155 insertions(+), 155 deletions(-) diff --git a/Driver.cpp b/Driver.cpp index 01478ac6..adce34d5 100644 --- a/Driver.cpp +++ b/Driver.cpp @@ -1793,7 +1793,7 @@ void TController::AutoRewident() } if (mvOccupied->TrainType == dt_EZT) { - fAccThreshold = std::max(-fBrake_a0[BrakeAccTableSize] - 8 * fBrake_a1[BrakeAccTableSize], -0.75); + fAccThreshold = std::max(-fBrake_a0[BrakeAccTableSize] - 8 * fBrake_a1[BrakeAccTableSize], -0.6); fBrakeReaction = 0.25; } else if (ustaw > 16) @@ -5662,7 +5662,7 @@ bool TController::IsStop() double TController::TrackBlock() const { - return pVehicles[ TMoverParameters::side::front ]->fTrackBlock; + return pVehicles[ side::front ]->fTrackBlock; } void TController::MoveTo(TDynamicObject *to) diff --git a/DynObj.cpp b/DynObj.cpp index 4156d8be..b30cbabb 100644 --- a/DynObj.cpp +++ b/DynObj.cpp @@ -1274,21 +1274,21 @@ void TDynamicObject::CouplersDettach(double MinDist, int MyScanDir) { if (MyScanDir > 0) { // pojazd od strony sprzęgu 0 if( ( PrevConnected != nullptr ) - && ( MoverParameters->Couplers[ TMoverParameters::side::front ].CoupleDist > MinDist ) ) { + && ( MoverParameters->Couplers[ side::front ].CoupleDist > MinDist ) ) { // sprzęgi wirtualne zawsze przekraczają - if( ( PrevConnectedNo == TMoverParameters::side::front ? + if( ( PrevConnectedNo == side::front ? PrevConnected->PrevConnected : PrevConnected->NextConnected ) == this ) { // Ra: nie rozłączamy znalezionego, jeżeli nie do nas podłączony // (może jechać w innym kierunku) PrevConnected->MoverParameters->Couplers[PrevConnectedNo].Connected = nullptr; - if( PrevConnectedNo == TMoverParameters::side::front ) { + if( PrevConnectedNo == side::front ) { // sprzęg 0 nie podłączony PrevConnected->PrevConnectedNo = 2; PrevConnected->PrevConnected = nullptr; } - else if( PrevConnectedNo == TMoverParameters::side::rear ) { + else if( PrevConnectedNo == side::rear ) { // sprzęg 1 nie podłączony PrevConnected->NextConnectedNo = 2; PrevConnected->NextConnected = nullptr; @@ -1297,27 +1297,27 @@ void TDynamicObject::CouplersDettach(double MinDist, int MyScanDir) { // za to zawsze odłączamy siebie PrevConnected = nullptr; PrevConnectedNo = 2; // sprzęg 0 nie podłączony - MoverParameters->Couplers[ TMoverParameters::side::front ].Connected = nullptr; + MoverParameters->Couplers[ side::front ].Connected = nullptr; } } else { // pojazd od strony sprzęgu 1 if( ( NextConnected != nullptr ) - && ( MoverParameters->Couplers[ TMoverParameters::side::rear ].CoupleDist > MinDist ) ) { + && ( MoverParameters->Couplers[ side::rear ].CoupleDist > MinDist ) ) { // sprzęgi wirtualne zawsze przekraczają - if( ( NextConnectedNo == TMoverParameters::side::front ? + if( ( NextConnectedNo == side::front ? NextConnected->PrevConnected : NextConnected->NextConnected ) == this) { // Ra: nie rozłączamy znalezionego, jeżeli nie do nas podłączony // (może jechać w innym kierunku) NextConnected->MoverParameters->Couplers[ NextConnectedNo ].Connected = nullptr; - if( NextConnectedNo == TMoverParameters::side::front ) { + if( NextConnectedNo == side::front ) { // sprzęg 0 nie podłączony NextConnected->PrevConnectedNo = 2; NextConnected->PrevConnected = nullptr; } - else if( NextConnectedNo == TMoverParameters::side::rear ) { + else if( NextConnectedNo == side::rear ) { // sprzęg 1 nie podłączony NextConnected->NextConnectedNo = 2; NextConnected->NextConnected = nullptr; @@ -1409,7 +1409,7 @@ void TDynamicObject::ABuScanObjects( int Direction, double Distance ) // siebie można bezpiecznie podłączyć jednostronnie do znalezionego MoverParameters->Attach( mycoupler, foundcoupler, foundobject->MoverParameters, coupling::faux ); // MoverParameters->Couplers[MyCouplFound].Render=false; //wirtualnego nie renderujemy - if( mycoupler == TMoverParameters::side::front ) { + if( mycoupler == side::front ) { PrevConnected = foundobject; // pojazd od strony sprzęgu 0 PrevConnectedNo = foundcoupler; } @@ -1420,7 +1420,7 @@ void TDynamicObject::ABuScanObjects( int Direction, double Distance ) if( foundobject->MoverParameters->Couplers[ foundcoupler ].CouplingFlag == coupling::faux ) { // Ra: wpinamy się wirtualnym tylko jeśli znaleziony ma wirtualny sprzęg - if( ( foundcoupler == TMoverParameters::side::front ? + if( ( foundcoupler == side::front ? foundobject->PrevConnected : foundobject->NextConnected ) != this ) { @@ -1428,13 +1428,13 @@ void TDynamicObject::ABuScanObjects( int Direction, double Distance ) // otherwise we risk leaving the target's connected vehicle with active one-side connection foundobject->CouplersDettach( 1.0, - ( foundcoupler == TMoverParameters::side::front ? + ( foundcoupler == side::front ? 1 : -1 ) ); } foundobject->MoverParameters->Attach( foundcoupler, mycoupler, this->MoverParameters, coupling::faux ); - if( foundcoupler == TMoverParameters::side::front ) { + if( foundcoupler == side::front ) { // jeśli widoczny sprzęg 0 znalezionego if( ( DebugModeFlag ) && ( foundobject->PrevConnected ) @@ -1551,8 +1551,6 @@ TDynamicObject::TDynamicObject() iAxleFirst = 0; // numer pierwszej osi w kierunku ruchu (przełączenie // następuje, gdy osie sa na // tym samym torze) - iInventory = 0; // flagi bitowe posiadanych submodeli (zaktualizuje się po - // wczytaniu MMD) RaLightsSet(0, 0); // początkowe zerowanie stanu świateł // Ra: domyślne ilości animacji dla zgodności wstecz (gdy brak ilości podanych // w MMD) @@ -1929,19 +1927,19 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424" btEndSignals21.Init("endsignal23", mdModel, false); btEndSignals13.Init("endsignal12", mdModel, false); btEndSignals23.Init("endsignal22", mdModel, false); - iInventory |= btEndSignals11.Active() ? 0x01 : 0; // informacja, czy ma poszczególne światła - iInventory |= btEndSignals21.Active() ? 0x02 : 0; - iInventory |= btEndSignals13.Active() ? 0x04 : 0; - iInventory |= btEndSignals23.Active() ? 0x08 : 0; + iInventory[ side::front ] |= btEndSignals11.Active() ? light::redmarker_left : 0; // informacja, czy ma poszczególne światła + iInventory[ side::front ] |= btEndSignals13.Active() ? light::redmarker_right : 0; + iInventory[ side::rear ] |= btEndSignals21.Active() ? light::redmarker_left : 0; + iInventory[ side::rear ] |= btEndSignals23.Active() ? light::redmarker_right : 0; // ABu: to niestety zostawione dla kompatybilnosci modeli: btEndSignals1.Init("endsignals1", mdModel, false); btEndSignals2.Init("endsignals2", mdModel, false); btEndSignalsTab1.Init("endtab1", mdModel, false); btEndSignalsTab2.Init("endtab2", mdModel, false); - iInventory |= btEndSignals1.Active() ? 0x10 : 0; - iInventory |= btEndSignals2.Active() ? 0x20 : 0; - iInventory |= btEndSignalsTab1.Active() ? 0x40 : 0; // tabliczki blaszane - iInventory |= btEndSignalsTab2.Active() ? 0x80 : 0; + iInventory[ side::front ] |= btEndSignals1.Active() ? ( light::redmarker_left | light::redmarker_right ) : 0; + iInventory[ side::front ] |= btEndSignalsTab1.Active() ? light::rearendsignals : 0; // tabliczki blaszane + iInventory[ side::rear ] |= btEndSignals2.Active() ? ( light::redmarker_left | light::redmarker_right ) : 0; + iInventory[ side::rear ] |= btEndSignalsTab2.Active() ? light::rearendsignals : 0; // ABu Uwaga! tu zmienic w modelu! btHeadSignals11.Init("headlamp13", mdModel, false); // lewe btHeadSignals12.Init("headlamp11", mdModel, false); // górne @@ -1949,7 +1947,13 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424" btHeadSignals21.Init("headlamp23", mdModel, false); btHeadSignals22.Init("headlamp21", mdModel, false); btHeadSignals23.Init("headlamp22", mdModel, false); - btMechanik1.Init("mechanik1", mdLowPolyInt, false); + iInventory[ side::front ] |= btHeadSignals11.Active() ? light::headlight_left : 0; + iInventory[ side::front ] |= btHeadSignals12.Active() ? light::headlight_upper : 0; + iInventory[ side::front ] |= btHeadSignals13.Active() ? light::headlight_right : 0; + iInventory[ side::rear ] |= btHeadSignals21.Active() ? light::headlight_left : 0; + iInventory[ side::rear ] |= btHeadSignals22.Active() ? light::headlight_upper : 0; + iInventory[ side::rear ] |= btHeadSignals23.Active() ? light::headlight_right : 0; + btMechanik1.Init("mechanik1", mdLowPolyInt, false); btMechanik2.Init("mechanik2", mdLowPolyInt, false); TurnOff(); // resetowanie zmiennych submodeli @@ -4984,7 +4988,7 @@ void TDynamicObject::RaLightsSet(int head, int rear) // pojazdu if (!MoverParameters) return; // może tego nie być na początku - if (rear == 2 + 32 + 64) + if (rear == ( light::redmarker_left | light::redmarker_right | light::rearendsignals ) ) { // jeśli koniec pociągu, to trzeba ustalić, czy // jest tam czynna lokomotywa // EN57 może nie mieć końcówek od środka członu @@ -4993,15 +4997,20 @@ void TDynamicObject::RaLightsSet(int head, int rear) { // jeśli ma zarówno światła jak i końcówki, ustalić, czy jest w stanie // aktywnym // np. lokomotywa na zimno będzie mieć końcówki a nie światła - rear = 64; // tablice blaszane + rear = light::rearendsignals; // tablice blaszane // trzeba to uzależnić od "załączenia baterii" w pojeździe } - if (rear == 2 + 32 + 64) // jeśli nadal obydwie możliwości - if (iInventory & - (iDirection ? 0x2A : 0x15)) // czy ma jakieś światła czerowone od danej strony - rear = 2 + 32; // dwa światła czerwone - else - rear = 64; // tablice blaszane + if( rear == ( light::redmarker_left | light::redmarker_right | light::rearendsignals ) ) // jeśli nadal obydwie możliwości + if( iInventory[ + ( iDirection ? + side::rear : + side::front ) ] & ( light::redmarker_left | light::redmarker_right ) ) { + // czy ma jakieś światła czerowone od danej strony + rear = ( light::redmarker_left | light::redmarker_right ); // dwa światła czerwone + } + else { + rear = light::rearendsignals; // tablice blaszane + } } if (iDirection) // w zależności od kierunku pojazdu w składzie { // jesli pojazd stoi sprzęgiem 0 w stronę czoła @@ -5423,7 +5432,7 @@ vehicle_table::update_traction( TDynamicObject *Vehicle ) { // pętla po pantografach auto pantograph { Vehicle->pants[ pantographindex ].fParamPants }; if( true == ( - pantographindex == TMoverParameters::side::front ? + pantographindex == side::front ? Vehicle->MoverParameters->PantFrontUp : Vehicle->MoverParameters->PantRearUp ) ) { // jeśli pantograf podniesiony diff --git a/DynObj.h b/DynObj.h index fbdbd0da..7f8aeb2f 100644 --- a/DynObj.h +++ b/DynObj.h @@ -340,7 +340,7 @@ private: bool bBrakeAcc; TRealSound rsUnbrake; // yB - odglos luzowania float ModCamRot; - int iInventory; // flagi bitowe posiadanych submodeli (np. świateł) + int iInventory[ 2 ] { 0, 0 }; // flagi bitowe posiadanych submodeli (np. świateł) void TurnOff(); public: @@ -466,6 +466,7 @@ private: void RadioStop(); void Damage(char flag); void RaLightsSet(int head, int rear); + int LightList( side const Side ) const { return iInventory[ Side ]; } TDynamicObject * FirstFind(int &coupler_nr, int cf = 1); float GetEPP(); // wyliczanie sredniego cisnienia w PG int DirectionSet(int d); // ustawienie kierunku w składzie diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index 2d84007d..ce949609 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -140,6 +140,11 @@ static int const ctrain_passenger = 16; //mostek przejściowy static int const ctrain_scndpneumatic = 32; //przewody 8 atm (żółte; zasilanie powietrzem) static int const ctrain_heating = 64; //przewody ogrzewania WN static int const ctrain_depot = 128; //nie rozłączalny podczas zwykłych manewrów (międzyczłonowy), we wpisie wartość ujemna +// vehicle sides; exclusive +enum side { + front = 0, + rear +}; // possible coupling types; can be combined enum coupling { faux = 0x0, @@ -162,6 +167,16 @@ enum range { enum start { manual, automatic +}; +// recognized vehicle light locations and types; can be combined +enum light { + + headlight_left = 0x01, + redmarker_left = 0x02, + headlight_upper = 0x04, + headlight_right = 0x10, + redmarker_right = 0x20, + rearendsignals = 0x40 }; /*typ hamulca elektrodynamicznego*/ static int const dbrake_none = 0; @@ -699,15 +714,6 @@ public: int LightsDefPos = 1; bool LightsWrap = false; int Lights[2][17]; // pozycje świateł, przód - tył, 1 .. 16 - enum light { - - headlight_left = 0x01, - redmarker_left = 0x02, - headlight_upper = 0x04, - headlight_right = 0x10, - redmarker_right = 0x20, - rearendsignals = 0x40 - }; int ScndInMain{ 0 }; /*zaleznosc bocznika od nastawnika*/ bool MBrake = false; /*Czy jest hamulec reczny*/ double StopBrakeDecc = 0.0; @@ -802,10 +808,6 @@ public: TRotation Rot; std::string Name; /*nazwa wlasna*/ TCoupling Couplers[2]; //urzadzenia zderzno-sprzegowe, polaczenia miedzy wagonami - enum side { - front = 0, - rear - }; #ifdef EU07_USE_OLD_HVCOUPLERS double HVCouplers[ 2 ][ 2 ]; //przewod WN enum hvcoupler { diff --git a/Train.cpp b/Train.cpp index c76f97ec..9ab64c0f 100644 --- a/Train.cpp +++ b/Train.cpp @@ -2074,26 +2074,26 @@ void TTrain::OnCommand_headlighttoggleleft( TTrain *Train, command_data const &C return; } - int const lightsindex = + int const vehicleside = ( Train->mvOccupied->ActiveCab == 1 ? - 0 : - 1 ); + side::front : + side::rear ); if( Command.action == GLFW_PRESS ) { // only reacting to press, so the switch doesn't flip back and forth if key is held down - if( ( Train->DynamicObject->iLights[ lightsindex ] & TMoverParameters::light::headlight_left ) == 0 ) { + if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_left ) == 0 ) { // turn on - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::headlight_left; + Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_left; // visual feedback Train->ggLeftLightButton.UpdateValue( 1.0, Train->dsbSwitch ); // if the light is controlled by 3-way switch, disable marker light if( Train->ggLeftEndLightButton.SubModel == nullptr ) { - Train->DynamicObject->iLights[ lightsindex ] &= ~TMoverParameters::light::redmarker_left; + Train->DynamicObject->iLights[ vehicleside ] &= ~light::redmarker_left; } } else { //turn off - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::headlight_left; + Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_left; // visual feedback Train->ggLeftLightButton.UpdateValue( 0.0, Train->dsbSwitch ); } @@ -2107,26 +2107,26 @@ void TTrain::OnCommand_headlighttoggleright( TTrain *Train, command_data const & return; } - int const lightsindex = + int const vehicleside = ( Train->mvOccupied->ActiveCab == 1 ? - 0 : - 1 ); + side::front : + side::rear ); if( Command.action == GLFW_PRESS ) { // only reacting to press, so the switch doesn't flip back and forth if key is held down - if( ( Train->DynamicObject->iLights[ lightsindex ] & TMoverParameters::light::headlight_right ) == 0 ) { + if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_right ) == 0 ) { // turn on - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::headlight_right; + Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_right; // visual feedback Train->ggRightLightButton.UpdateValue( 1.0, Train->dsbSwitch ); // if the light is controlled by 3-way switch, disable marker light if( Train->ggRightEndLightButton.SubModel == nullptr ) { - Train->DynamicObject->iLights[ lightsindex ] &= ~TMoverParameters::light::redmarker_right; + Train->DynamicObject->iLights[ vehicleside ] &= ~light::redmarker_right; } } else { //turn off - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::headlight_right; + Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_right; // visual feedback Train->ggRightLightButton.UpdateValue( 0.0, Train->dsbSwitch ); } @@ -2140,22 +2140,22 @@ void TTrain::OnCommand_headlighttoggleupper( TTrain *Train, command_data const & return; } - int const lightsindex = + int const vehicleside = ( Train->mvOccupied->ActiveCab == 1 ? - 0 : - 1 ); + side::front : + side::rear ); if( Command.action == GLFW_PRESS ) { // only reacting to press, so the switch doesn't flip back and forth if key is held down - if( ( Train->DynamicObject->iLights[ lightsindex ] & TMoverParameters::light::headlight_upper ) == 0 ) { + if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_upper ) == 0 ) { // turn on - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::headlight_upper; + Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_upper; // visual feedback Train->ggUpperLightButton.UpdateValue( 1.0, Train->dsbSwitch ); } else { //turn off - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::headlight_upper; + Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_upper; // visual feedback Train->ggUpperLightButton.UpdateValue( 0.0, Train->dsbSwitch ); } @@ -2169,16 +2169,16 @@ void TTrain::OnCommand_redmarkertoggleleft( TTrain *Train, command_data const &C return; } - int const lightsindex = + int const vehicleside = ( Train->mvOccupied->ActiveCab == 1 ? - 0 : - 1 ); + side::front : + side::rear ); if( Command.action == GLFW_PRESS ) { // only reacting to press, so the switch doesn't flip back and forth if key is held down - if( ( Train->DynamicObject->iLights[ lightsindex ] & TMoverParameters::light::redmarker_left ) == 0 ) { + if( ( Train->DynamicObject->iLights[ vehicleside ] & light::redmarker_left ) == 0 ) { // turn on - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::redmarker_left; + Train->DynamicObject->iLights[ vehicleside ] ^= light::redmarker_left; // visual feedback if( Train->ggLeftEndLightButton.SubModel != nullptr ) { Train->ggLeftEndLightButton.UpdateValue( 1.0, Train->dsbSwitch ); @@ -2188,12 +2188,12 @@ void TTrain::OnCommand_redmarkertoggleleft( TTrain *Train, command_data const &C // this is crude, but for now will do Train->ggLeftLightButton.UpdateValue( -1.0, Train->dsbSwitch ); // if the light is controlled by 3-way switch, disable the headlight - Train->DynamicObject->iLights[ lightsindex ] &= ~TMoverParameters::light::headlight_left; + Train->DynamicObject->iLights[ vehicleside ] &= ~light::headlight_left; } } else { //turn off - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::redmarker_left; + Train->DynamicObject->iLights[ vehicleside ] ^= light::redmarker_left; // visual feedback if( Train->ggLeftEndLightButton.SubModel != nullptr ) { Train->ggLeftEndLightButton.UpdateValue( 0.0, Train->dsbSwitch ); @@ -2214,16 +2214,16 @@ void TTrain::OnCommand_redmarkertoggleright( TTrain *Train, command_data const & return; } - int const lightsindex = + int const vehicleside = ( Train->mvOccupied->ActiveCab == 1 ? - 0 : - 1 ); + side::front : + side::rear ); if( Command.action == GLFW_PRESS ) { // only reacting to press, so the switch doesn't flip back and forth if key is held down - if( ( Train->DynamicObject->iLights[ lightsindex ] & TMoverParameters::light::redmarker_right ) == 0 ) { + if( ( Train->DynamicObject->iLights[ vehicleside ] & light::redmarker_right ) == 0 ) { // turn on - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::redmarker_right; + Train->DynamicObject->iLights[ vehicleside ] ^= light::redmarker_right; // visual feedback if( Train->ggRightEndLightButton.SubModel != nullptr ) { Train->ggRightEndLightButton.UpdateValue( 1.0, Train->dsbSwitch ); @@ -2233,12 +2233,12 @@ void TTrain::OnCommand_redmarkertoggleright( TTrain *Train, command_data const & // this is crude, but for now will do Train->ggRightLightButton.UpdateValue( -1.0, Train->dsbSwitch ); // if the light is controlled by 3-way switch, disable the headlight - Train->DynamicObject->iLights[ lightsindex ] &= ~TMoverParameters::light::headlight_right; + Train->DynamicObject->iLights[ vehicleside ] &= ~light::headlight_right; } } else { //turn off - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::redmarker_right; + Train->DynamicObject->iLights[ vehicleside ] ^= light::redmarker_right; // visual feedback if( Train->ggRightEndLightButton.SubModel != nullptr ) { Train->ggRightEndLightButton.UpdateValue( 0.0, Train->dsbSwitch ); @@ -2259,23 +2259,23 @@ void TTrain::OnCommand_headlighttogglerearleft( TTrain *Train, command_data cons return; } - int const lightsindex = + int const vehicleside = ( Train->mvOccupied->ActiveCab == 1 ? - 1 : - 0 ); + side::rear : + side::front ); if( Command.action == GLFW_PRESS ) { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc // only reacting to press, so the switch doesn't flip back and forth if key is held down - if( ( Train->DynamicObject->iLights[ lightsindex ] & TMoverParameters::light::headlight_right ) == 0 ) { + if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_right ) == 0 ) { // turn on - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::headlight_right; + Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_right; // visual feedback Train->ggRearLeftLightButton.UpdateValue( 1.0, Train->dsbSwitch ); } else { //turn off - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::headlight_right; + Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_right; // visual feedback Train->ggRearLeftLightButton.UpdateValue( 0.0, Train->dsbSwitch ); } @@ -2289,23 +2289,23 @@ void TTrain::OnCommand_headlighttogglerearright( TTrain *Train, command_data con return; } - int const lightsindex = + int const vehicleside = ( Train->mvOccupied->ActiveCab == 1 ? - 1 : - 0 ); + side::rear : + side::front ); if( Command.action == GLFW_PRESS ) { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc // only reacting to press, so the switch doesn't flip back and forth if key is held down - if( ( Train->DynamicObject->iLights[ lightsindex ] & TMoverParameters::light::headlight_left ) == 0 ) { + if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_left ) == 0 ) { // turn on - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::headlight_left; + Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_left; // visual feedback Train->ggRearRightLightButton.UpdateValue( 1.0, Train->dsbSwitch ); } else { //turn off - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::headlight_left; + Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_left; // visual feedback Train->ggRearRightLightButton.UpdateValue( 0.0, Train->dsbSwitch ); } @@ -2319,22 +2319,22 @@ void TTrain::OnCommand_headlighttogglerearupper( TTrain *Train, command_data con return; } - int const lightsindex = + int const vehicleside = ( Train->mvOccupied->ActiveCab == 1 ? - 1 : - 0 ); + side::rear : + side::front ); if( Command.action == GLFW_PRESS ) { // only reacting to press, so the switch doesn't flip back and forth if key is held down - if( ( Train->DynamicObject->iLights[ lightsindex ] & TMoverParameters::light::headlight_upper ) == 0 ) { + if( ( Train->DynamicObject->iLights[ vehicleside ] & light::headlight_upper ) == 0 ) { // turn on - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::headlight_upper; + Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_upper; // visual feedback Train->ggRearUpperLightButton.UpdateValue( 1.0, Train->dsbSwitch ); } else { //turn off - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::headlight_upper; + Train->DynamicObject->iLights[ vehicleside ] ^= light::headlight_upper; // visual feedback Train->ggRearUpperLightButton.UpdateValue( 0.0, Train->dsbSwitch ); } @@ -2348,23 +2348,23 @@ void TTrain::OnCommand_redmarkertogglerearleft( TTrain *Train, command_data cons return; } - int const lightsindex = + int const vehicleside = ( Train->mvOccupied->ActiveCab == 1 ? - 1 : - 0 ); + side::rear : + side::front ); if( Command.action == GLFW_PRESS ) { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc // only reacting to press, so the switch doesn't flip back and forth if key is held down - if( ( Train->DynamicObject->iLights[ lightsindex ] & TMoverParameters::light::redmarker_right ) == 0 ) { + if( ( Train->DynamicObject->iLights[ vehicleside ] & light::redmarker_right ) == 0 ) { // turn on - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::redmarker_right; + Train->DynamicObject->iLights[ vehicleside ] ^= light::redmarker_right; // visual feedback Train->ggRearLeftEndLightButton.UpdateValue( 1.0, Train->dsbSwitch ); } else { //turn off - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::redmarker_right; + Train->DynamicObject->iLights[ vehicleside ] ^= light::redmarker_right; // visual feedback Train->ggRearLeftEndLightButton.UpdateValue( 0.0, Train->dsbSwitch ); } @@ -2378,23 +2378,23 @@ void TTrain::OnCommand_redmarkertogglerearright( TTrain *Train, command_data con return; } - int const lightsindex = + int const vehicleside = ( Train->mvOccupied->ActiveCab == 1 ? - 1 : - 0 ); + side::rear : + side::front ); if( Command.action == GLFW_PRESS ) { // NOTE: we toggle the light on opposite side, as 'rear right' is 'front left' on the rear end etc // only reacting to press, so the switch doesn't flip back and forth if key is held down - if( ( Train->DynamicObject->iLights[ lightsindex ] & TMoverParameters::light::redmarker_left ) == 0 ) { + if( ( Train->DynamicObject->iLights[ vehicleside ] & light::redmarker_left ) == 0 ) { // turn on - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::redmarker_left; + Train->DynamicObject->iLights[ vehicleside ] ^= light::redmarker_left; // visual feedback Train->ggRearRightEndLightButton.UpdateValue( 1.0, Train->dsbSwitch ); } else { //turn off - Train->DynamicObject->iLights[ lightsindex ] ^= TMoverParameters::light::redmarker_left; + Train->DynamicObject->iLights[ vehicleside ] ^= light::redmarker_left; // visual feedback Train->ggRearRightEndLightButton.UpdateValue( 0.0, Train->dsbSwitch ); } @@ -6706,21 +6706,21 @@ void TTrain::set_cab_controls() { ggMaxCurrentCtrl.PutValue( 1.0 ); } // lights - int const lightsindex = + int const vehicleside = ( mvOccupied->ActiveCab == 1 ? - 0 : - 1 ); + side::front : + side::rear ); - if( ( DynamicObject->iLights[ lightsindex ] & TMoverParameters::light::headlight_left ) != 0 ) { + if( ( DynamicObject->iLights[ vehicleside ] & light::headlight_left ) != 0 ) { ggLeftLightButton.PutValue( 1.0 ); } - if( ( DynamicObject->iLights[ lightsindex ] & TMoverParameters::light::headlight_right ) != 0 ) { + if( ( DynamicObject->iLights[ vehicleside ] & light::headlight_right ) != 0 ) { ggRightLightButton.PutValue( 1.0 ); } - if( ( DynamicObject->iLights[ lightsindex ] & TMoverParameters::light::headlight_upper ) != 0 ) { + if( ( DynamicObject->iLights[ vehicleside ] & light::headlight_upper ) != 0 ) { ggUpperLightButton.PutValue( 1.0 ); } - if( ( DynamicObject->iLights[ lightsindex ] & TMoverParameters::light::redmarker_left ) != 0 ) { + if( ( DynamicObject->iLights[ vehicleside ] & light::redmarker_left ) != 0 ) { if( ggLeftEndLightButton.SubModel != nullptr ) { ggLeftEndLightButton.PutValue( 1.0 ); } @@ -6728,7 +6728,7 @@ void TTrain::set_cab_controls() { ggLeftLightButton.PutValue( -1.0 ); } } - if( ( DynamicObject->iLights[ lightsindex ] & TMoverParameters::light::redmarker_right ) != 0 ) { + if( ( DynamicObject->iLights[ vehicleside ] & light::redmarker_right ) != 0 ) { if( ggRightEndLightButton.SubModel != nullptr ) { ggRightEndLightButton.PutValue( 1.0 ); } diff --git a/World.cpp b/World.cpp index 7949b346..65b364f5 100644 --- a/World.cpp +++ b/World.cpp @@ -707,9 +707,9 @@ void TWorld::OnKeyDown(int cKey) CouplNr = 0; // z [-1,1] zrobić [0,1] int mask, set = 0; // Ra: [Shift]+[Ctrl]+[T] odpala mi jakąś idiotyczną zmianę tapety pulpitu :/ if (Global::shiftState) // z [Shift] zapalanie - set = mask = TMoverParameters::light::rearendsignals; // bez [Ctrl] założyć tabliczki + set = mask = light::rearendsignals; // bez [Ctrl] założyć tabliczki else if (Global::ctrlState) - set = mask = ( TMoverParameters::light::redmarker_left | TMoverParameters::light::redmarker_right ); // z [Ctrl] zapalić światła czerwone + set = mask = ( light::redmarker_left | light::redmarker_right ); // z [Ctrl] zapalić światła czerwone else mask = 2 + 32 + 64; // wyłączanie ściąga wszystko if (((vehicle->iLights[CouplNr]) & mask) != set) @@ -1435,15 +1435,15 @@ TWorld::Update_UI() { "; TC:" + to_string( vehicle->MoverParameters->TotalCurrent, 0 ); auto const frontcouplerhighvoltage = - to_string( vehicle->MoverParameters->Couplers[ TMoverParameters::side::front ].power_high.voltage, 0 ) + to_string( vehicle->MoverParameters->Couplers[ side::front ].power_high.voltage, 0 ) + "@" - + to_string( vehicle->MoverParameters->Couplers[ TMoverParameters::side::front ].power_high.current, 0 ); + + to_string( vehicle->MoverParameters->Couplers[ side::front ].power_high.current, 0 ); auto const rearcouplerhighvoltage = - to_string( vehicle->MoverParameters->Couplers[ TMoverParameters::side::rear ].power_high.voltage, 0 ) + to_string( vehicle->MoverParameters->Couplers[ side::rear ].power_high.voltage, 0 ) + "@" - + to_string( vehicle->MoverParameters->Couplers[ TMoverParameters::side::rear ].power_high.current, 0 ); + + to_string( vehicle->MoverParameters->Couplers[ side::rear ].power_high.current, 0 ); uitextline2 += ", HV: "; - if( vehicle->MoverParameters->Couplers[ TMoverParameters::side::front ].power_high.local == false ) { + if( vehicle->MoverParameters->Couplers[ side::front ].power_high.local == false ) { uitextline2 += "(" + frontcouplerhighvoltage + ")-" + ":F" + ( vehicle->DirectionGet() ? "<<" : ">>" ) + "R:" diff --git a/lightarray.cpp b/lightarray.cpp index f0486b7f..9655da56 100644 --- a/lightarray.cpp +++ b/lightarray.cpp @@ -23,8 +23,8 @@ light_array::insert( TDynamicObject const *Owner ) { // we're only storing lights for locos, which have two sets of lights, front and rear // for a more generic role this function would have to be tweaked to add vehicle type-specific light combinations - data.emplace_back( Owner, 0 ); - data.emplace_back( Owner, 1 ); + data.emplace_back( Owner, side::front ); + data.emplace_back( Owner, side::rear ); } void @@ -44,7 +44,7 @@ light_array::update() { for( auto &light : data ) { // update light parameters to match current data of the owner - if( light.index == 0 ) { + if( light.index == side::front ) { // front light set light.position = light.owner->GetPosition() + ( light.owner->VectorFront() * light.owner->GetLength() * 0.4 ); light.direction = glm::make_vec3( light.owner->VectorFront().getArray() ); @@ -57,34 +57,25 @@ light_array::update() { light.direction.z = -light.direction.z; } // determine intensity of this light set - if( ( true == light.owner->MoverParameters->Battery ) || ( true == light.owner->MoverParameters->ConverterFlag ) ) { + if( ( true == light.owner->MoverParameters->Battery ) + || ( true == light.owner->MoverParameters->ConverterFlag ) ) { // with power on, the intensity depends on the state of activated switches - auto const &lightbits = light.owner->iLights[ light.index ]; + // first we cross-check the list of enabled lights with the lights installed in the vehicle... + auto const lights { light.owner->iLights[ light.index ] & light.owner->LightList( static_cast( light.index ) ) }; + // ...then check their individual state light.count = 0 - + ( ( lightbits & TMoverParameters::light::headlight_left ) ? 1 : 0 ) - + ( ( lightbits & TMoverParameters::light::headlight_right ) ? 1 : 0 ) - + ( ( lightbits & TMoverParameters::light::headlight_upper ) ? 1 : 0 ); + + ( ( lights & light::headlight_left ) ? 1 : 0 ) + + ( ( lights & light::headlight_right ) ? 1 : 0 ) + + ( ( lights & light::headlight_upper ) ? 1 : 0 ); if( light.count > 0 ) { - // TODO: intensity can be affected further by dim switch or other factors light.intensity = std::max( 0.0f, std::log( (float)light.count + 1.0f ) ); light.intensity *= ( light.owner->DimHeadlights ? 0.6f : 1.0f ); + // TBD, TODO: intensity can be affected further by other factors } else { light.intensity = 0.0f; } -/* - // crude catch for unmanned modules which share the light state with the controlled unit. - // why don't they get their own light bits btw ._. - // TODO, TBD: have separate light bits for each vehicle, so this override isn't necessary - // NOTE: should be no longer needed, test and delete if there's no ill effects - if( ( light.owner->Controller == AIdriver ) - && ( light.owner->Mechanik == nullptr ) ) { - - light.intensity = 0.0f; - light.count = 0; - } -*/ } else { // with battery off the lights are off diff --git a/simulation.cpp b/simulation.cpp index 181e22b3..450c35d2 100644 --- a/simulation.cpp +++ b/simulation.cpp @@ -307,11 +307,8 @@ state_manager::deserialize_node( cParser &Input, scene::scratch_data &Scratchpad } if( ( vehicle->MoverParameters->CategoryFlag == 1 ) // trains only - && ( ( vehicle->MoverParameters->SecuritySystem.SystemType != 0 ) - || ( vehicle->MoverParameters->SandCapacity > 0.0 ) ) ) { - // we check for presence of security system or sand load, as a way to determine whether the vehicle is a controllable engine - // NOTE: this isn't 100% precise, e.g. middle EZT module comes with security system, while it has no lights, and some engines - // don't have security systems fitted + && ( ( vehicle->LightList( side::front ) & ( light::headlight_left | light::headlight_right | light::headlight_upper ) != 0 ) + || ( vehicle->LightList( side::rear ) & ( light::headlight_left | light::headlight_right | light::headlight_upper ) != 0 ) ) ) { simulation::Lights.insert( vehicle ); } } @@ -603,7 +600,7 @@ state_manager::deserialize_endtrainset( cParser &Input, scene::scratch_data &Scr } if( Scratchpad.trainset.couplings.back() == coupling::faux ) { // jeśli ostatni pojazd ma sprzęg 0 to założymy mu końcówki blaszane (jak AI się odpali, to sobie poprawi) - Scratchpad.trainset.vehicles.back()->RaLightsSet( -1, TMoverParameters::light::rearendsignals ); + Scratchpad.trainset.vehicles.back()->RaLightsSet( -1, light::rearendsignals ); } // all done Scratchpad.trainset.is_open = false; From da11e689ce0472a9479f48651a28ca9ed28274e8 Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Thu, 2 Nov 2017 21:51:44 +0100 Subject: [PATCH 3/3] build 171102: mouse support for light preset switch, vehicle lights cab indicators --- Train.cpp | 432 ++++++++++++++++++++-------------------------- Train.h | 13 ++ World.cpp | 8 +- command.cpp | 2 + command.h | 6 +- keyboardinput.cpp | 4 + mouseinput.cpp | 4 +- scene.cpp | 14 +- usefull.h | 2 +- version.h | 2 +- 10 files changed, 226 insertions(+), 261 deletions(-) diff --git a/Train.cpp b/Train.cpp index 9ab64c0f..bb169cea 100644 --- a/Train.cpp +++ b/Train.cpp @@ -246,6 +246,8 @@ TTrain::commandhandler_map const TTrain::m_commandhandlers = { { user_command::motoroverloadrelaythresholdtoggle, &TTrain::OnCommand_motoroverloadrelaythresholdtoggle }, { user_command::motoroverloadrelayreset, &TTrain::OnCommand_motoroverloadrelayreset }, { user_command::heatingtoggle, &TTrain::OnCommand_heatingtoggle }, + { user_command::lightspresetactivatenext, &TTrain::OnCommand_lightspresetactivatenext }, + { user_command::lightspresetactivateprevious, &TTrain::OnCommand_lightspresetactivateprevious }, { user_command::headlighttoggleleft, &TTrain::OnCommand_headlighttoggleleft }, { user_command::headlighttoggleright, &TTrain::OnCommand_headlighttoggleright }, { user_command::headlighttoggleupper, &TTrain::OnCommand_headlighttoggleupper }, @@ -2067,6 +2069,60 @@ void TTrain::OnCommand_motoroverloadrelayreset( TTrain *Train, command_data cons } } +void TTrain::OnCommand_lightspresetactivatenext( TTrain *Train, command_data const &Command ) { + + if( Train->mvOccupied->LightsPosNo == 0 ) { + // lights are controlled by preset selector + return; + } + if( Command.action != GLFW_PRESS ) { + // one change per key press + return; + } + + if( ( Train->mvOccupied->LightsPos < Train->mvOccupied->LightsPosNo ) + || ( true == Train->mvOccupied->LightsWrap ) ) { + // active light preset is stored as value in range 1-LigthPosNo + Train->mvOccupied->LightsPos = ( + Train->mvOccupied->LightsPos < Train->mvOccupied->LightsPosNo ? + Train->mvOccupied->LightsPos + 1 : + 1 ); // wrap mode + + Train->SetLights(); + // visual feedback + if( Train->ggLightsButton.SubModel != nullptr ) { + Train->ggLightsButton.UpdateValue( Train->mvOccupied->LightsPos - 1, Train->dsbSwitch ); + } + } +} + +void TTrain::OnCommand_lightspresetactivateprevious( TTrain *Train, command_data const &Command ) { + + if( Train->mvOccupied->LightsPosNo == 0 ) { + // lights are controlled by preset selector + return; + } + if( Command.action != GLFW_PRESS ) { + // one change per key press + return; + } + + if( ( Train->mvOccupied->LightsPos > 1 ) + || ( true == Train->mvOccupied->LightsWrap ) ) { + // active light preset is stored as value in range 1-LigthPosNo + Train->mvOccupied->LightsPos = ( + Train->mvOccupied->LightsPos > 1 ? + Train->mvOccupied->LightsPos - 1 : + Train->mvOccupied->LightsPosNo ); // wrap mode + + Train->SetLights(); + // visual feedback + if( Train->ggLightsButton.SubModel != nullptr ) { + Train->ggLightsButton.UpdateValue( Train->mvOccupied->LightsPos - 1, Train->dsbSwitch ); + } + } +} + void TTrain::OnCommand_headlighttoggleleft( TTrain *Train, command_data const &Command ) { if( Train->mvOccupied->LightsPosNo > 0 ) { @@ -2900,7 +2956,8 @@ void TTrain::OnKeyDown(int cKey) DynamicObject->Mechanik->TakeControl(true); } } - else if (cKey == Global::Keys[k_UpperSign]) // ABu 060205: światło górne - +#ifdef EU07_USE_OLD_COMMAND_SYSTEM + else if (cKey == Global::Keys[k_UpperSign]) // ABu 060205: światło górne - // włączenie { if (mvOccupied->LightsPosNo > 0) //kręciolek od swiatel @@ -2917,6 +2974,7 @@ void TTrain::OnKeyDown(int cKey) } } } +#endif } else // McZapkie-240302 - klawisze bez shifta { @@ -3013,8 +3071,7 @@ void TTrain::OnKeyDown(int cKey) } } } - // McZapkie-240302 - wylaczanie automatycznego pilota (w trybie ~debugmode - // mozna tylko raz) + // McZapkie-240302 - wylaczanie automatycznego pilota (w trybie ~debugmode mozna tylko raz) else if (cKey == GLFW_KEY_Q) // bez Shift { if (DynamicObject->Mechanik) @@ -3249,6 +3306,7 @@ if } } } +#ifdef EU07_USE_OLD_COMMAND_SYSTEM else if (cKey == Global::Keys[k_UpperSign]) // ABu 060205: światło górne - // wyłączenie { @@ -3266,6 +3324,7 @@ if } } } +#endif // else if (DebugModeFlag) { // przesuwanie składu o 100m @@ -4317,9 +4376,6 @@ bool TTrain::Update( double const Deltatime ) true : false ) ); - // hunter-261211: jakis stary kod (i niezgodny z prawda), - // zahaszowalem i poprawilem - // youBy-220913: ale przyda sie do lampki samej przetwornicy btLampkaPrzetw.Turn( !mvControlled->ConverterFlag ); btLampkaNadmPrzetw.Turn( mvControlled->ConvOvldFlag ); @@ -4330,10 +4386,12 @@ bool TTrain::Update( double const Deltatime ) btLampkaBezoporowa.Turn(mvControlled->ResistorsFlagCheck() || (mvControlled->MainCtrlActualPos == 0)); // do EU04 - if ((mvControlled->Itot != 0) || (mvOccupied->BrakePress > 2) || - (mvOccupied->PipePress < 3.6)) - btLampkaStyczn.TurnOff(); // Ra: czy to jest udawanie działania - // styczników liniowych? + if( ( mvControlled->Itot != 0 ) + || ( mvOccupied->BrakePress > 2 ) + || ( mvOccupied->PipePress < 3.6 ) ) { + // Ra: czy to jest udawanie działania styczników liniowych? + btLampkaStyczn.TurnOff(); + } else if (mvOccupied->BrakePress < 1) btLampkaStyczn.TurnOn(); // mozna prowadzic rozruch if (((TestFlag(mvControlled->Couplers[1].CouplingFlag, ctrain_controll)) && @@ -4513,15 +4571,8 @@ bool TTrain::Update( double const Deltatime ) btLampkaNadmPrzetwB.TurnOn(); btLampkaPrzetwB.TurnOff(); } + } - // hunter-261211: jakis stary kod (i niezgodny z prawda), zahaszowalem - // if (tmp) - // if (tmp->MoverParameters->ConverterFlag==true) - // btLampkaNadmPrzetwB.TurnOff(); - // else - // btLampkaNadmPrzetwB.TurnOn(); - - } //**************************************************** */ if( mvControlled->Battery || mvControlled->ConverterFlag ) { switch (mvControlled->TrainType) @@ -4551,6 +4602,18 @@ bool TTrain::Update( double const Deltatime ) btLampkaForward.Turn(mvControlled->ActiveDir > 0); // jazda do przodu btLampkaBackward.Turn(mvControlled->ActiveDir < 0); // jazda do tyłu btLampkaED.Turn(mvControlled->DynamicBrakeFlag); // hamulec ED + // light indicators + // NOTE: sides are hardcoded to deal with setups where single cab is equipped with all indicators + btLampkaUpperLight.Turn( ( mvOccupied->iLights[ side::front ] & light::headlight_upper ) != 0 ); + btLampkaLeftLight.Turn( ( mvOccupied->iLights[ side::front ] & light::headlight_left ) != 0 ); + btLampkaRightLight.Turn( ( mvOccupied->iLights[ side::front ] & light::headlight_right ) != 0 ); + btLampkaLeftEndLight.Turn( ( mvOccupied->iLights[ side::front ] & light::redmarker_left ) != 0 ); + btLampkaRightEndLight.Turn( ( mvOccupied->iLights[ side::front ] & light::redmarker_right ) != 0 ); + btLampkaRearUpperLight.Turn( ( mvOccupied->iLights[ side::rear ] & light::headlight_upper ) != 0 ); + btLampkaRearLeftLight.Turn( ( mvOccupied->iLights[ side::rear ] & light::headlight_left ) != 0 ); + btLampkaRearRightLight.Turn( ( mvOccupied->iLights[ side::rear ] & light::headlight_right ) != 0 ); + btLampkaRearLeftEndLight.Turn( ( mvOccupied->iLights[ side::rear ] & light::redmarker_left ) != 0 ); + btLampkaRearRightEndLight.Turn( ( mvOccupied->iLights[ side::rear ] & light::redmarker_right ) != 0 ); } else { // gdy bateria wyłączona @@ -4566,7 +4629,19 @@ bool TTrain::Update( double const Deltatime ) btLampkaForward.TurnOff(); btLampkaBackward.TurnOff(); btLampkaED.TurnOff(); + // light indicators + btLampkaUpperLight.TurnOff(); + btLampkaLeftLight.TurnOff(); + btLampkaRightLight.TurnOff(); + btLampkaLeftEndLight.TurnOff(); + btLampkaRightEndLight.TurnOff(); + btLampkaRearUpperLight.TurnOff(); + btLampkaRearLeftLight.TurnOff(); + btLampkaRearRightLight.TurnOff(); + btLampkaRearLeftEndLight.TurnOff(); + btLampkaRearRightEndLight.TurnOff(); } + // McZapkie-080602: obroty (albo translacje) regulatorow if (ggMainCtrl.SubModel) { @@ -4830,12 +4905,6 @@ bool TTrain::Update( double const Deltatime ) ggRearRightLightButton.PutValue(-1); } #endif - if (ggLightsButton.SubModel) - { - ggLightsButton.PutValue(mvOccupied->LightsPos - 1); - ggLightsButton.Update(); - } - ggDimHeadlightsButton.Update(); //--------- // hunter-080812: poprawka na ogrzewanie w elektrykach - usuniete uzaleznienie od przetwornicy if ((((mvControlled->EngineType == ElectricSeriesMotor) && (mvControlled->Mains == true) && @@ -4909,9 +4978,7 @@ bool TTrain::Update( double const Deltatime ) } } - //****************************************** // przelaczniki - #ifdef EU07_USE_OLD_COMMAND_SYSTEM if( Console::Pressed( Global::Keys[ k_Horn ] ) ) { @@ -5652,6 +5719,7 @@ bool TTrain::Update( double const Deltatime ) ggPantCompressorButton.Update(); ggPantCompressorValve.Update(); + ggLightsButton.Update(); ggUpperLightButton.Update(); ggLeftLightButton.Update(); ggRightLightButton.Update(); @@ -5663,6 +5731,7 @@ bool TTrain::Update( double const Deltatime ) ggRearRightLightButton.Update(); ggRearLeftEndLightButton.Update(); ggRearRightEndLightButton.Update(); + ggDimHeadlightsButton.Update(); //------------ ggConverterButton.Update(); ggConverterLocalButton.Update(); @@ -5673,14 +5742,14 @@ bool TTrain::Update( double const Deltatime ) ggHornButton.Update(); ggHornLowButton.Update(); ggHornHighButton.Update(); -/* +#ifdef EU07_USE_OLD_COMMAND_SYSTEM ggUniversal1Button.Update(); ggUniversal2Button.Update(); if( Universal4Active ) { ggUniversal4Button.PermIncValue( dt ); } ggUniversal4Button.Update(); -*/ +#endif for( auto &universal : ggUniversals ) { universal.Update(); } @@ -6597,6 +6666,17 @@ void TTrain::clear_cab_controls() btLampkaWylSzybkiB.Clear(); btLampkaForward.Clear(); btLampkaBackward.Clear(); + // light indicators + btLampkaUpperLight.Clear(); + btLampkaLeftLight.Clear(); + btLampkaRightLight.Clear(); + btLampkaLeftEndLight.Clear(); + btLampkaRightEndLight.Clear(); + btLampkaRearUpperLight.Clear(); + btLampkaRearLeftLight.Clear(); + btLampkaRearRightLight.Clear(); + btLampkaRearLeftEndLight.Clear(); + btLampkaRearRightEndLight.Clear(); btCabLight.Clear(); // hunter-171012 ggLeftLightButton.Clear(); ggRightLightButton.Clear(); @@ -6706,6 +6786,8 @@ void TTrain::set_cab_controls() { ggMaxCurrentCtrl.PutValue( 1.0 ); } // lights + ggLightsButton.PutValue( mvOccupied->LightsPos - 1 ); + int const vehicleside = ( mvOccupied->ActiveCab == 1 ? side::front : @@ -6802,227 +6884,88 @@ void TTrain::set_cab_controls() { // TODO: when cleaning up break setting indicator state into a separate function, so we can reuse it } -// initializes a button matching provided label. returns: true if the label was found, false -// otherwise -// NOTE: this is temporary work-around for compiler else-if limit +// initializes a button matching provided label. returns: true if the label was found, false otherwise // TODO: refactor the cabin controls into some sensible structure -bool TTrain::initialize_button(cParser &Parser, std::string const &Label, int const Cabindex) -{ -/* - TButton *bt; // roboczy wskaźnik na obiekt animujący lampkę -*/ - // SEKCJA LAMPEK - if (Label == "i-maxft:") - { - btLampkaMaxSila.Load(Parser, DynamicObject->mdKabina); +bool TTrain::initialize_button(cParser &Parser, std::string const &Label, int const Cabindex) { + + std::unordered_map const lights = { + { "i-maxft:", btLampkaMaxSila }, + { "i-maxftt:", btLampkaPrzekrMaxSila }, + { "i-radio:", btLampkaRadio }, + { "i-manual_brake:", btLampkaHamulecReczny }, + { "i-door_blocked:", btLampkaBlokadaDrzwi }, + { "i-slippery:", btLampkaPoslizg }, + { "i-contactors:", btLampkaStyczn }, + { "i-conv_ovld:", btLampkaNadmPrzetw }, + { "i-converter:", btLampkaPrzetw }, + { "i-diff_relay:", btLampkaPrzekRozn }, + { "i-diff_relay2:", btLampkaPrzekRoznPom }, + { "i-motor_ovld:", btLampkaNadmSil }, + { "i-train_controll:", btLampkaUkrotnienie }, + { "i-brake_delay_r:", btLampkaHamPosp }, + { "i-mainbreaker:", btLampkaWylSzybki }, + { "i-vent_ovld:", btLampkaNadmWent }, + { "i-comp_ovld:", btLampkaNadmSpr }, + { "i-resistors:", btLampkaOpory }, + { "i-no_resistors:", btLampkaBezoporowa }, + { "i-no_resistors_b:", btLampkaBezoporowaB }, + { "i-highcurrent:", btLampkaWysRozr }, + { "i-vent_trim:", btLampkaWentZaluzje }, + { "i-trainheating:", btLampkaOgrzewanieSkladu }, + { "i-security_aware:", btLampkaCzuwaka }, + { "i-security_cabsignal:", btLampkaSHP }, + { "i-door_left:", btLampkaDoorLeft }, + { "i-door_right:", btLampkaDoorRight }, + { "i-departure_signal:", btLampkaDepartureSignal }, + { "i-reserve:", btLampkaRezerwa }, + { "i-scnd:", btLampkaBoczniki }, + { "i-scnd1:", btLampkaBocznik1 }, + { "i-scnd2:", btLampkaBocznik2 }, + { "i-scnd3:", btLampkaBocznik3 }, + { "i-scnd4:", btLampkaBocznik4 }, + { "i-braking:", btLampkaHamienie }, + { "i-dynamicbrake:", btLampkaED }, + { "i-braking-ezt:", btLampkaHamowanie1zes }, + { "i-braking-ezt2:", btLampkaHamowanie2zes }, + { "i-compressor:", btLampkaSprezarka }, + { "i-compressorb:", btLampkaSprezarkaB }, + { "i-voltbrake:", btLampkaNapNastHam }, + { "i-mainbreakerb:", btLampkaWylSzybkiB }, + { "i-resistorsb:", btLampkaOporyB }, + { "i-contactorsb:", btLampkaStycznB }, + { "i-conv_ovldb:", btLampkaNadmPrzetwB }, + { "i-converterb:", btLampkaPrzetwB }, + { "i-forward:", btLampkaForward }, + { "i-backward:", btLampkaBackward }, + { "i-upperlight:", btLampkaUpperLight }, + { "i-leftlight:", btLampkaLeftLight }, + { "i-rightlight:", btLampkaRightLight }, + { "i-leftend:", btLampkaLeftEndLight }, + { "i-rightend:", btLampkaRightEndLight }, + { "i-rearupperlight:", btLampkaRearUpperLight }, + { "i-rearleftlight:", btLampkaRearLeftLight }, + { "i-rearrightlight:", btLampkaRearRightLight }, + { "i-rearleftend:", btLampkaRearLeftEndLight }, + { "i-rearrightend:", btLampkaRearRightEndLight }, + { "i-cablight:", btCabLight } + }; + auto lookup = lights.find( Label ); + if( lookup != lights.end() ) { + lookup->second.Load( Parser, DynamicObject->mdKabina ); } - else if (Label == "i-maxftt:") - { - btLampkaPrzekrMaxSila.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-radio:") - { - btLampkaRadio.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-manual_brake:") - { - btLampkaHamulecReczny.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-door_blocked:") - { - btLampkaBlokadaDrzwi.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-slippery:") - { - btLampkaPoslizg.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-contactors:") - { - btLampkaStyczn.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-conv_ovld:") - { - btLampkaNadmPrzetw.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-converter:") - { - btLampkaPrzetw.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-diff_relay:") - { - btLampkaPrzekRozn.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-diff_relay2:") - { - btLampkaPrzekRoznPom.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-motor_ovld:") - { - btLampkaNadmSil.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-train_controll:") - { - btLampkaUkrotnienie.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-brake_delay_r:") - { - btLampkaHamPosp.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-mainbreaker:") - { - btLampkaWylSzybki.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-vent_ovld:") - { - btLampkaNadmWent.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-comp_ovld:") - { - btLampkaNadmSpr.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-resistors:") - { - btLampkaOpory.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-no_resistors:") - { - btLampkaBezoporowa.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-no_resistors_b:") - { - btLampkaBezoporowaB.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-highcurrent:") - { - btLampkaWysRozr.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-instrumentlight:") - { - btInstrumentLight.Load(Parser, DynamicObject->mdKabina, DynamicObject->mdModel); + + else if( Label == "i-instrumentlight:" ) { + btInstrumentLight.Load( Parser, DynamicObject->mdKabina, DynamicObject->mdModel ); InstrumentLightType = 0; } - else if (Label == "i-instrumentlight_M:") - { - btInstrumentLight.Load(Parser, DynamicObject->mdKabina, DynamicObject->mdModel); + else if( Label == "i-instrumentlight_M:" ) { + btInstrumentLight.Load( Parser, DynamicObject->mdKabina, DynamicObject->mdModel ); InstrumentLightType = 1; } - else if (Label == "i-instrumentlight_C:") - { - btInstrumentLight.Load(Parser, DynamicObject->mdKabina, DynamicObject->mdModel); + else if( Label == "i-instrumentlight_C:" ) { + btInstrumentLight.Load( Parser, DynamicObject->mdKabina, DynamicObject->mdModel ); InstrumentLightType = 2; } - else if (Label == "i-vent_trim:") - { - btLampkaWentZaluzje.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-trainheating:") - { - btLampkaOgrzewanieSkladu.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-security_aware:") - { - btLampkaCzuwaka.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-security_cabsignal:") - { - btLampkaSHP.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-door_left:") - { - btLampkaDoorLeft.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-door_right:") - { - btLampkaDoorRight.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-departure_signal:") - { - btLampkaDepartureSignal.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-reserve:") - { - btLampkaRezerwa.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-scnd:") - { - btLampkaBoczniki.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-scnd1:") - { - btLampkaBocznik1.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-scnd2:") - { - btLampkaBocznik2.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-scnd3:") - { - btLampkaBocznik3.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-scnd4:") - { - btLampkaBocznik4.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-braking:") - { - btLampkaHamienie.Load(Parser, DynamicObject->mdKabina); - } - else if( Label == "i-dynamicbrake:" ) { - - btLampkaED.Load( Parser, DynamicObject->mdKabina ); - } - else if (Label == "i-braking-ezt:") - { - btLampkaHamowanie1zes.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-braking-ezt2:") - { - btLampkaHamowanie2zes.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-compressor:") - { - btLampkaSprezarka.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-compressorb:") - { - btLampkaSprezarkaB.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-voltbrake:") - { - btLampkaNapNastHam.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-mainbreakerb:") - { - btLampkaWylSzybkiB.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-resistorsb:") - { - btLampkaOporyB.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-contactorsb:") - { - btLampkaStycznB.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-conv_ovldb:") - { - btLampkaNadmPrzetwB.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-converterb:") - { - btLampkaPrzetwB.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-forward:") - { - btLampkaForward.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-backward:") - { - btLampkaBackward.Load(Parser, DynamicObject->mdKabina); - } - else if (Label == "i-cablight:") - { // hunter-171012 - btCabLight.Load(Parser, DynamicObject->mdKabina); - } else if (Label == "i-doors:") { int i = Parser.getToken() - 1; @@ -7039,15 +6982,10 @@ bool TTrain::initialize_button(cParser &Parser, std::string const &Label, int co return true; } -// initializes a gauge matching provided label. returns: true if the label was found, false -// otherwise -// NOTE: this is temporary work-around for compiler else-if limit +// initializes a gauge matching provided label. returns: true if the label was found, false otherwise // TODO: refactor the cabin controls into some sensible structure bool TTrain::initialize_gauge(cParser &Parser, std::string const &Label, int const Cabindex) { -/* - TGauge *gg { nullptr }; // roboczy wskaźnik na obiekt animujący gałkę -*/ std::unordered_map const gauges = { { "mainctrl:", ggMainCtrl }, { "scndctrl:", ggScndCtrl }, diff --git a/Train.h b/Train.h index 61ed0e00..7beeadd4 100644 --- a/Train.h +++ b/Train.h @@ -171,6 +171,8 @@ class TTrain static void OnCommand_motoroverloadrelaythresholdtoggle( TTrain *Train, command_data const &Command ); static void OnCommand_motoroverloadrelayreset( TTrain *Train, command_data const &Command ); static void OnCommand_heatingtoggle( TTrain *Train, command_data const &Command ); + static void OnCommand_lightspresetactivatenext( TTrain *Train, command_data const &Command ); + static void OnCommand_lightspresetactivateprevious( TTrain *Train, command_data const &Command ); static void OnCommand_headlighttoggleleft( TTrain *Train, command_data const &Command ); static void OnCommand_headlighttoggleright( TTrain *Train, command_data const &Command ); static void OnCommand_headlighttoggleupper( TTrain *Train, command_data const &Command ); @@ -366,6 +368,17 @@ public: // reszta może by?publiczna TButton btLampkaHamulecReczny; TButton btLampkaForward; // Ra: lampki w przód i w ty?dla komputerowych kabin TButton btLampkaBackward; + // light indicators + TButton btLampkaUpperLight; + TButton btLampkaLeftLight; + TButton btLampkaRightLight; + TButton btLampkaLeftEndLight; + TButton btLampkaRightEndLight; + TButton btLampkaRearUpperLight; + TButton btLampkaRearLeftLight; + TButton btLampkaRearRightLight; + TButton btLampkaRearLeftEndLight; + TButton btLampkaRearRightEndLight; TButton btCabLight; // hunter-171012: lampa oswietlajaca kabine // Ra 2013-12: wirtualne "lampki" do odbijania na haslerze w PoKeys diff --git a/World.cpp b/World.cpp index 65b364f5..ee4720a2 100644 --- a/World.cpp +++ b/World.cpp @@ -682,7 +682,7 @@ void TWorld::OnKeyDown(int cKey) */ if (cKey == Global::Keys[k_Heating]) // Ra: klawisz nie jest najszczęśliwszy { // zmiana próżny/ładowny; Ra: zabrane z kabiny - auto *vehicle { std::get( simulation::Region->find_vehicle( Global::pCameraPosition, 20, false, false ) ) }; + auto *vehicle { std::get( simulation::Region->find_vehicle( Global::pCameraPosition, 10, false, false ) ) }; if (vehicle) { if (Global::shiftState ? vehicle->MoverParameters->IncBrakeMult() : @@ -695,7 +695,7 @@ void TWorld::OnKeyDown(int cKey) } else if (cKey == Global::Keys[k_EndSign]) { // Ra 2014-07: zabrane z kabiny - auto *vehicle { std::get( simulation::Region->find_vehicle( Global::pCameraPosition, 20, false, true ) ) }; + auto *vehicle { std::get( simulation::Region->find_vehicle( Global::pCameraPosition, 10, false, true ) ) }; if (vehicle) { int CouplNr = (LengthSquared3(vehicle->HeadPosition() - Camera.Pos) > @@ -724,7 +724,7 @@ void TWorld::OnKeyDown(int cKey) } else if (cKey == Global::Keys[k_IncLocalBrakeLevel]) { // zahamowanie dowolnego pojazdu - auto *vehicle { std::get( simulation::Region->find_vehicle( Global::pCameraPosition, 20, false, false ) ) }; + auto *vehicle { std::get( simulation::Region->find_vehicle( Global::pCameraPosition, 10, false, false ) ) }; if (vehicle) { if (Global::ctrlState) @@ -743,7 +743,7 @@ void TWorld::OnKeyDown(int cKey) } else if (cKey == Global::Keys[k_DecLocalBrakeLevel]) { // odhamowanie dowolnego pojazdu - auto *vehicle { std::get( simulation::Region->find_vehicle( Global::pCameraPosition, 20, false, false ) ) }; + auto *vehicle { std::get( simulation::Region->find_vehicle( Global::pCameraPosition, 10, false, false ) ) }; if (vehicle) { if (Global::ctrlState) diff --git a/command.cpp b/command.cpp index 3f4b6f56..c3d70d27 100644 --- a/command.cpp +++ b/command.cpp @@ -105,6 +105,8 @@ const int k_ProgramHelp = 48; /* // const int k_FreeFlyMode= 59; */ + { "lightspresetactivatenext", command_target::vehicle }, + { "lightspresetactivateprevious", command_target::vehicle }, { "headlighttoggleleft", command_target::vehicle }, { "headlighttoggleright", command_target::vehicle }, { "headlighttoggleupper", command_target::vehicle }, diff --git a/command.h b/command.h index a06509e5..0f9ef699 100644 --- a/command.h +++ b/command.h @@ -100,6 +100,8 @@ const int k_ProgramHelp = 48; /* // const int k_FreeFlyMode= 59; */ + lightspresetactivatenext, + lightspresetactivateprevious, headlighttoggleleft, headlighttoggleright, headlighttoggleupper, @@ -117,10 +119,6 @@ const int k_ProgramHelp = 48; interiorlightdimtoggle, instrumentlighttoggle, /* -const int k_Univ1 = 66; -const int k_Univ2 = 67; -const int k_Univ3 = 68; -const int k_Univ4 = 69; const int k_EndSign = 70; const int k_Active = 71; */ diff --git a/keyboardinput.cpp b/keyboardinput.cpp index cc7041c4..c0ff5ebf 100644 --- a/keyboardinput.cpp +++ b/keyboardinput.cpp @@ -318,6 +318,10 @@ const int k_ProgramHelp = 48; /* // const int k_FreeFlyMode= 59; */ + // lightspresetactivatenext + { GLFW_KEY_T | keymodifier::shift }, + // lightspresetactivateprevious + { GLFW_KEY_T }, // headlighttoggleleft { GLFW_KEY_Y }, // headlighttoggleright diff --git a/mouseinput.cpp b/mouseinput.cpp index 8fd53744..ddf8bee6 100644 --- a/mouseinput.cpp +++ b/mouseinput.cpp @@ -304,8 +304,8 @@ mouse_input::default_bindings() { user_command::redmarkertoggleright, user_command::none } }, { "lights_sw:", { - user_command::none, - user_command::none } }, // TODO: implement commands for lights controller + user_command::lightspresetactivatenext, + user_command::lightspresetactivateprevious } }, { "rearupperlight_sw:", { user_command::headlighttogglerearupper, user_command::none } }, diff --git a/scene.cpp b/scene.cpp index 16373e93..4d65328b 100644 --- a/scene.cpp +++ b/scene.cpp @@ -872,7 +872,12 @@ basic_region::update_traction( TDynamicObject *Vehicle, int const Pantographinde void basic_region::serialize( std::string const &Scenariofile ) const { - auto filename { Global::asCurrentSceneryPath + Scenariofile }; + auto filename { Scenariofile }; + if( filename[ 0 ] == '$' ) { + // trim leading $ char rainsted utility may add to the base name for modified .scn files + filename.erase( 0, 1 ); + } + filename = Global::asCurrentSceneryPath + filename; if( ( filename.rfind( '.' ) != std::string::npos ) && ( filename.rfind( '.' ) != filename.rfind( ".." ) + 1 ) ) { // trim extension, it's typically going to be for different file type @@ -910,7 +915,12 @@ basic_region::serialize( std::string const &Scenariofile ) const { bool basic_region::deserialize( std::string const &Scenariofile ) { - auto filename { Global::asCurrentSceneryPath + Scenariofile }; + auto filename { Scenariofile }; + if( filename[ 0 ] == '$' ) { + // trim leading $ char rainsted utility may add to the base name for modified .scn files + filename.erase( 0, 1 ); + } + filename = Global::asCurrentSceneryPath + filename; if( ( filename.rfind( '.' ) != std::string::npos ) && ( filename.rfind( '.' ) != filename.rfind( ".." ) + 1 ) ) { // trim extension, it's typically going to be for different file type diff --git a/usefull.h b/usefull.h index 8c5359ca..4f2594b3 100644 --- a/usefull.h +++ b/usefull.h @@ -52,7 +52,7 @@ Type_ clamp_circular( Type_ Value, Type_ const Range = static_cast(360) ) { Value -= Range * (int)( Value / Range ); // clamp the range to 0-360 - if( Value < 0.0 ) Value += Range; + if( Value < Type_(0) ) Value += Range; return Value; } diff --git a/version.h b/version.h index e7a0964f..9aaf2c1a 100644 --- a/version.h +++ b/version.h @@ -1,5 +1,5 @@ #pragma once #define VERSION_MAJOR 17 -#define VERSION_MINOR 1031 +#define VERSION_MINOR 1102 #define VERSION_REVISION 0