From 40518920665f96fec42f7dcd3ade0782ffd3838a Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Tue, 12 Mar 2019 18:49:06 +0100 Subject: [PATCH] maintenance: minor code tweaks --- DynObj.cpp | 2 ++ simulationtime.cpp | 16 +++++++++++----- simulationtime.h | 3 +++ sun.cpp | 14 ++++---------- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/DynObj.cpp b/DynObj.cpp index 6ca495d3..5f17393f 100644 --- a/DynObj.cpp +++ b/DynObj.cpp @@ -2298,6 +2298,8 @@ void TDynamicObject::LoadExchange( int const Disembark, int const Embark, int co } } */ + if( Platform == 0 ) { return; } // edge case, if there's no accessible platforms discard the request + m_exchange.unload_count += Disembark; m_exchange.load_count += Embark; m_exchange.platforms = Platform; diff --git a/simulationtime.cpp b/simulationtime.cpp index b2574756..f1c5531e 100644 --- a/simulationtime.cpp +++ b/simulationtime.cpp @@ -121,7 +121,7 @@ scenario_time::update( double const Deltatime ) { } m_time.wHour -= 24; } - int leap { ( m_time.wYear % 4 == 0 ) && ( m_time.wYear % 100 != 0 ) || ( m_time.wYear % 400 == 0 ) }; + int leap { is_leap( m_time.wYear ) }; while( m_time.wDay > m_monthdaycounts[ leap ][ m_time.wMonth ] ) { m_time.wDay -= m_monthdaycounts[ leap ][ m_time.wMonth ]; @@ -130,7 +130,7 @@ scenario_time::update( double const Deltatime ) { if( m_time.wMonth > 12 ) { ++m_time.wYear; - leap = ( m_time.wYear % 4 == 0 ) && ( m_time.wYear % 100 != 0 ) || ( m_time.wYear % 400 == 0 ); + leap = is_leap( m_time.wYear ); m_time.wMonth -= 12; } } @@ -144,7 +144,7 @@ scenario_time::year_day( int Day, const int Month, const int Year ) const { { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } }; - int const leap { ( Year % 4 == 0 ) && ( Year % 100 != 0 ) || ( Year % 400 == 0 ) }; + int const leap { is_leap( Year ) }; for( int i = 1; i < Month; ++i ) Day += daytab[ leap ][ i ]; @@ -159,7 +159,7 @@ scenario_time::daymonth( WORD &Day, WORD &Month, WORD const Year, WORD const Yea { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } }; - int const leap { ( Year % 4 == 0 ) && ( Year % 100 != 0 ) || ( Year % 400 == 0 ) }; + int const leap { is_leap( Year ) }; WORD idx = 1; while( ( idx < 13 ) && ( Yearday >= daytab[ leap ][ idx ] ) ) { @@ -222,7 +222,7 @@ scenario_time::day_of_month( int const Week, int const Weekday, int const Month, { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } }; - int const leap { ( Year % 4 == 0 ) && ( Year % 100 != 0 ) || ( Year % 400 == 0 ) }; + int const leap { is_leap( Year ) }; while( day > daytab[ leap ][ Month ] ) { day -= 7; @@ -248,4 +248,10 @@ scenario_time::convert_transition_time( SYSTEMTIME &Time ) const { Time.wDay = day_of_month( Time.wDay, Time.wDayOfWeek + 1, Time.wMonth, m_time.wYear ); } +bool +scenario_time::is_leap( int const Year ) const { + + return ( ( Year % 4 == 0 ) && ( ( Year % 100 != 0 ) || ( Year % 400 == 0 ) ) ); + +} //--------------------------------------------------------------------------- diff --git a/simulationtime.h b/simulationtime.h index 45f4352e..58a8b317 100644 --- a/simulationtime.h +++ b/simulationtime.h @@ -61,6 +61,9 @@ private: // returns number of days between specified days of week int weekdays( int const First, int const Second ) const; + // returns true if specified year is a leap year, false otherwise + bool + is_leap( int const Year ) const; SYSTEMTIME m_time; double m_milliseconds{ 0.0 }; diff --git a/sun.cpp b/sun.cpp index 0acf3864..b2cce6a6 100644 --- a/sun.cpp +++ b/sun.cpp @@ -185,17 +185,11 @@ void cSun::move() { m_body.rascen = clamp_circular( radtodeg * std::atan2( top, bottom ) ); - // Greenwich mean sidereal time - m_observer.gmst = 6.697375 + 0.0657098242 * daynumber + m_observer.utime; + // Greenwich mean sidereal time (hours) + m_observer.gmst = clamp_circular( 6.697375 + 0.0657098242 * daynumber + m_observer.utime, 24.0 ); - m_observer.gmst -= 24.0 * (int)( m_observer.gmst / 24.0 ); - if( m_observer.gmst < 0.0 ) m_observer.gmst += 24.0; - - // local mean sidereal time - m_observer.lmst = m_observer.gmst * 15.0 + m_observer.longitude; - - m_observer.lmst -= 360.0 * (int)( m_observer.lmst / 360.0 ); - if( m_observer.lmst < 0.0 ) m_observer.lmst += 360.0; + // local mean sidereal time (deg) + m_observer.lmst = clamp_circular( m_observer.gmst * 15.0 + m_observer.longitude ); // hour angle m_body.hrang = m_observer.lmst - m_body.rascen;