build 180622. time zone bias calculation fix, track events fix, passenger stop distance calculation fix

This commit is contained in:
tmj-fstate
2018-06-22 18:24:48 +02:00
parent c0bf973c58
commit c40d0abcf9
9 changed files with 79 additions and 45 deletions

View File

@@ -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);

View File

@@ -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 );
}
}

View File

@@ -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);

View File

@@ -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

View File

@@ -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 *)&registrytimezoneinfo, &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

View File

@@ -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 {

View File

@@ -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<float>( 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 );

32
sun.cpp
View File

@@ -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<float>( 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

View File

@@ -1,5 +1,5 @@
#pragma once
#define VERSION_MAJOR 18
#define VERSION_MINOR 621
#define VERSION_MINOR 622
#define VERSION_REVISION 0