From c40d0abcf98f7230cbcccbc90bf0c8ff71465885 Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Fri, 22 Jun 2018 18:24:48 +0200 Subject: [PATCH] build 180622. time zone bias calculation fix, track events fix, passenger stop distance calculation fix --- Driver.cpp | 9 +++++---- Track.cpp | 11 ++++++++++- Track.h | 1 + TrkFoll.cpp | 8 ++++---- World.cpp | 39 +++++++++++++++++++++++++++++++++++++++ World.h | 3 +++ moon.cpp | 19 +++++++++---------- sun.cpp | 32 +++++++------------------------- version.h | 2 +- 9 files changed, 79 insertions(+), 45 deletions(-) diff --git a/Driver.cpp b/Driver.cpp index 761ec82f..ebecd129 100644 --- a/Driver.cpp +++ b/Driver.cpp @@ -873,11 +873,12 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN auto Par1 = sSpeedTable[i].evEvent->ValueGet(1); auto Par2 = sSpeedTable[i].evEvent->ValueGet(2); if ((Par2 > 0) || (fLength < -Par2)) { //użyj tego W4 - if (Par1 < 0) { //środek - L = -Par1 - fMinProximityDist - fLength * 0.5; - } + if (Par1 < 0) { + L = -Par1; + } else { - L = Par1; + //środek + L = Par1 - fMinProximityDist - fLength * 0.5; } L = std::max(0.0, std::min(L, std::abs(Par2) - fMinProximityDist - fLength)); sSpeedTable[i].UpdateDistance(L); diff --git a/Track.cpp b/Track.cpp index 92232675..a1404217 100644 --- a/Track.cpp +++ b/Track.cpp @@ -924,9 +924,18 @@ bool TTrack::AssignForcedEvents(TEvent *NewEventPlus, TEvent *NewEventMinus) void TTrack::QueueEvents( event_sequence const &Events, TDynamicObject const *Owner ) { + for( auto const &event : Events ) { + if( event.second != nullptr ) { + simulation::Events.AddToQuery( event.second, Owner ); + } + } +} + +void TTrack::QueueEvents( event_sequence const &Events, TDynamicObject const *Owner, double const Delaylimit ) { + for( auto const &event : Events ) { if( ( event.second != nullptr ) - && ( event.second->fDelay <= -1.0 ) ) { + && ( event.second->fDelay <= Delaylimit) ) { simulation::Events.AddToQuery( event.second, Owner ); } } diff --git a/Track.h b/Track.h index 39c11f1a..97f30815 100644 --- a/Track.h +++ b/Track.h @@ -248,6 +248,7 @@ public: bool AssignEvents(); bool AssignForcedEvents(TEvent *NewEventPlus, TEvent *NewEventMinus); void QueueEvents( event_sequence const &Events, TDynamicObject const *Owner ); + void QueueEvents( event_sequence const &Events, TDynamicObject const *Owner, double const Delaylimit ); bool CheckDynamicObject(TDynamicObject *Dynamic); bool AddDynamicObject(TDynamicObject *Dynamic); bool RemoveDynamicObject(TDynamicObject *Dynamic); diff --git a/TrkFoll.cpp b/TrkFoll.cpp index 9d8d802a..37029750 100644 --- a/TrkFoll.cpp +++ b/TrkFoll.cpp @@ -245,11 +245,11 @@ bool TTrackFollower::Move(double fDistance, bool bPrimary) { // tylko gdy początkowe ustawienie, dodajemy eventy stania do kolejki if (Owner->MoverParameters->ActiveCab != 0) { - pCurrentTrack->QueueEvents( pCurrentTrack->m_events1, Owner ); - pCurrentTrack->QueueEvents( pCurrentTrack->m_events2, Owner ); + pCurrentTrack->QueueEvents( pCurrentTrack->m_events1, Owner, -1.0 ); + pCurrentTrack->QueueEvents( pCurrentTrack->m_events2, Owner, -1.0 ); } - pCurrentTrack->QueueEvents( pCurrentTrack->m_events1all, Owner ); - pCurrentTrack->QueueEvents( pCurrentTrack->m_events2all, Owner ); + pCurrentTrack->QueueEvents( pCurrentTrack->m_events1all, Owner, -1.0 ); + pCurrentTrack->QueueEvents( pCurrentTrack->m_events2all, Owner, -1.0 ); } fCurrentDistance = s; return ComputatePosition(); // przeliczenie XYZ, true o ile nie wyjechał na NULL diff --git a/World.cpp b/World.cpp index 37be858b..20f235b4 100644 --- a/World.cpp +++ b/World.cpp @@ -74,6 +74,45 @@ simulation_time::init() { } m_yearday = year_day( m_time.wDay, m_time.wMonth, m_time.wYear ); + + // calculate time zone bias + // retrieve relevant time zone info from system registry (or fall back on supplied default) + // TODO: select timezone matching defined geographic location and/or country + struct registry_time_zone_info { + long Bias; + long StandardBias; + long DaylightBias; + SYSTEMTIME StandardDate; + SYSTEMTIME DaylightDate; + } registrytimezoneinfo = { -60, 0, -60, { 0, 10, 0, 5, 3, 0, 0, 0 }, { 0, 3, 0, 5, 2, 0, 0, 0 } }; + +#ifdef _WIN32 + TCHAR timezonekeyname[] { TEXT( "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\Central European Standard Time" ) }; + HKEY timezonekey { NULL }; + DWORD size { sizeof( registrytimezoneinfo ) }; + if( ::RegOpenKeyEx( HKEY_LOCAL_MACHINE, timezonekeyname, 0, KEY_QUERY_VALUE, &timezonekey ) == ERROR_SUCCESS ) { + ::RegQueryValueEx( timezonekey, "TZI", NULL, NULL, (BYTE *)®istrytimezoneinfo, &size ); + } +#endif + TIME_ZONE_INFORMATION timezoneinfo { 0 }; + timezoneinfo.Bias = registrytimezoneinfo.Bias; + timezoneinfo.DaylightBias = registrytimezoneinfo.DaylightBias; + timezoneinfo.DaylightDate = registrytimezoneinfo.DaylightDate; + timezoneinfo.StandardBias = registrytimezoneinfo.StandardBias; + timezoneinfo.StandardDate = registrytimezoneinfo.StandardDate; + + auto zonebias { timezoneinfo.Bias }; + if( m_yearday < year_day( timezoneinfo.DaylightDate.wDay, timezoneinfo.DaylightDate.wMonth, m_time.wYear ) ) { + zonebias += timezoneinfo.StandardBias; + } + else if( m_yearday < year_day( timezoneinfo.StandardDate.wDay, timezoneinfo.StandardDate.wMonth, m_time.wYear ) ) { + zonebias += timezoneinfo.DaylightBias; + } + else { + zonebias += timezoneinfo.StandardBias; + } + + m_timezonebias = ( zonebias / 60.0 ); } void diff --git a/World.h b/World.h index 5db1287d..731af207 100644 --- a/World.h +++ b/World.h @@ -44,6 +44,8 @@ public: year_day( int Day, int const Month, int const Year ) const; int julian_day() const; + double + zone_bias() const { return m_timezonebias; } private: // calculates day and month from given day of year @@ -54,6 +56,7 @@ private: double m_milliseconds{ 0.0 }; int m_yearday; char m_monthdaycounts[ 2 ][ 13 ]; + double m_timezonebias{ 0.0 }; }; namespace simulation { diff --git a/moon.cpp b/moon.cpp index 68bbfe51..b40d5356 100644 --- a/moon.cpp +++ b/moon.cpp @@ -14,10 +14,6 @@ cMoon::cMoon() { setLocation( 19.00f, 52.00f ); // default location roughly in centre of Poland m_observer.press = 1013.0; // surface pressure, millibars m_observer.temp = 15.0; // ambient dry-bulb temperature, degrees C - - TIME_ZONE_INFORMATION timezoneinfo; // TODO: timezone dependant on geographic location - ::GetTimeZoneInformation( &timezoneinfo ); - m_observer.timezone = -timezoneinfo.Bias / 60.0f; } cMoon::~cMoon() { gluDeleteQuadric( moonsphere ); } @@ -25,16 +21,20 @@ cMoon::~cMoon() { gluDeleteQuadric( moonsphere ); } void cMoon::init() { - moonsphere = gluNewQuadric(); - gluQuadricNormals( moonsphere, GLU_SMOOTH ); + m_observer.timezone = -1.0 * simulation::Time.zone_bias(); // NOTE: we're calculating phase just once, because it's unlikely simulation will last a few days, // plus a sudden texture change would be pretty jarring phase(); + + moonsphere = gluNewQuadric(); + gluQuadricNormals( moonsphere, GLU_SMOOTH ); } void cMoon::update() { + m_observer.temp = Global.AirTemperature; + move(); glm::vec3 position( 0.f, 0.f, -1.f ); position = glm::rotateX( position, glm::radians( static_cast( m_body.elevref ) ) ); @@ -118,7 +118,7 @@ void cMoon::move() { if( m_observer.minute >= 0 ) { localtime.wMinute = m_observer.minute; } if( m_observer.second >= 0 ) { localtime.wSecond = m_observer.second; } - double ut = + double localut = localtime.wHour + localtime.wMinute / 60.0 // too low resolution, noticeable skips + localtime.wSecond / 3600.0; // good enough in normal circumstances @@ -131,11 +131,10 @@ void cMoon::move() { + 275 * localtime.wMonth / 9 + localtime.wDay - 730530 - + ( ut / 24.0 ); + + ( localut / 24.0 ); // Universal Coordinated (Greenwich standard) time - m_observer.utime = ut * 3600.0; - m_observer.utime = m_observer.utime / 3600.0 - m_observer.timezone; + m_observer.utime = localut - m_observer.timezone; // obliquity of the ecliptic m_body.oblecl = clamp_circular( 23.4393 - 3.563e-7 * daynumber ); diff --git a/sun.cpp b/sun.cpp index 9f6e0a82..fc264f76 100644 --- a/sun.cpp +++ b/sun.cpp @@ -21,34 +21,17 @@ cSun::~cSun() { gluDeleteQuadric( sunsphere ); } void cSun::init() { + m_observer.timezone = -1.0 * simulation::Time.zone_bias(); + sunsphere = gluNewQuadric(); gluQuadricNormals( sunsphere, GLU_SMOOTH ); - - // calculate and set timezone for the current date of the simulation - // TODO: timezone dependant on geographic location - TIME_ZONE_INFORMATION timezoneinfo; - ::GetTimeZoneInformation( &timezoneinfo ); - // account for potential daylight/normal time bias - // NOTE: we're using xp-compatible time zone information and current year, instead of 'historically proper' values - auto zonebias { timezoneinfo.Bias }; - auto const year { simulation::Time.data().wYear }; - auto const yearday { simulation::Time.year_day() }; - if( yearday < simulation::Time.year_day( timezoneinfo.DaylightDate.wDay, timezoneinfo.DaylightDate.wMonth, year ) ) { - zonebias += timezoneinfo.StandardBias; - } - else if( yearday < simulation::Time.year_day( timezoneinfo.StandardDate.wDay, timezoneinfo.StandardDate.wMonth, year ) ) { - zonebias += timezoneinfo.DaylightBias; - } - else { - zonebias += timezoneinfo.StandardBias; - } - - m_observer.timezone = -zonebias / 60.0f; } void cSun::update() { + m_observer.temp = Global.AirTemperature; + move(); glm::vec3 position( 0.f, 0.f, -1.f ); position = glm::rotateX( position, glm::radians( static_cast( m_body.elevref ) ) ); @@ -141,7 +124,7 @@ void cSun::move() { if( m_observer.minute >= 0 ) { localtime.wMinute = m_observer.minute; } if( m_observer.second >= 0 ) { localtime.wSecond = m_observer.second; } - double ut = + double localut = localtime.wHour + localtime.wMinute / 60.0 // too low resolution, noticeable skips + localtime.wSecond / 3600.0; // good enough in normal circumstances @@ -154,11 +137,10 @@ void cSun::move() { + 275 * localtime.wMonth / 9 + localtime.wDay - 730530 - + ( ut / 24.0 ); + + ( localut / 24.0 ); // Universal Coordinated (Greenwich standard) time - m_observer.utime = ut * 3600.0; - m_observer.utime = m_observer.utime / 3600.0 - m_observer.timezone; + m_observer.utime = localut - m_observer.timezone; // perihelion longitude m_body.phlong = 282.9404 + 4.70935e-5 * daynumber; // w // orbit eccentricity diff --git a/version.h b/version.h index 28fab244..be52643b 100644 --- a/version.h +++ b/version.h @@ -1,5 +1,5 @@ #pragma once #define VERSION_MAJOR 18 -#define VERSION_MINOR 621 +#define VERSION_MINOR 622 #define VERSION_REVISION 0