Fix a few potential gotcha's in setting up start time.
This commit is contained in:
parent
0f6e4e1c74
commit
b10715833c
2 changed files with 24 additions and 23 deletions
|
@ -1276,6 +1276,7 @@ void fgInitTimeOffset() {
|
|||
= fgGetNode("/sim/time/cur-time-override", true);
|
||||
|
||||
// Handle potential user specified time offsets
|
||||
int orig_warp = globals->get_warp();
|
||||
SGTime *t = globals->get_time_params();
|
||||
time_t cur_time = t->get_cur_time();
|
||||
time_t currGMT = sgTimeGetGMT( gmtime(&cur_time) );
|
||||
|
@ -1328,8 +1329,10 @@ void fgInitTimeOffset() {
|
|||
"FG_TIME::Unsupported offset type " << offset_type );
|
||||
exit( -1 );
|
||||
}
|
||||
globals->set_warp( warp );
|
||||
t->update( 0.0, 0.0, cur_time_override->getLongValue(),
|
||||
globals->set_warp( orig_warp + warp );
|
||||
t->update( longitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
|
||||
latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
|
||||
cur_time_override->getLongValue(),
|
||||
globals->get_warp() );
|
||||
|
||||
SG_LOG( SG_GENERAL, SG_INFO, "After fgInitTimeOffset(): warp = "
|
||||
|
|
|
@ -35,7 +35,9 @@
|
|||
#include "sunsolver.hxx"
|
||||
|
||||
|
||||
const time_t day_secs = 86400;
|
||||
static const time_t day_secs = 86400;
|
||||
static const time_t half_day_secs = day_secs / 2;
|
||||
static const time_t step_secs = 60;
|
||||
|
||||
static double sun_angle( const SGTime &t, sgVec3 world_up,
|
||||
double lon_rad, double lat_rad ) {
|
||||
|
@ -96,7 +98,10 @@ time_t fgTimeSecondsUntilNoon( time_t cur_time,
|
|||
double best_angle = 180.0;
|
||||
time_t best_time = cur_time;
|
||||
|
||||
for ( time_t secs = cur_time; secs < cur_time + day_secs; secs += 300 ) {
|
||||
for ( time_t secs = cur_time - half_day_secs;
|
||||
secs < cur_time + half_day_secs;
|
||||
secs += step_secs )
|
||||
{
|
||||
t.update( lon_rad, lat_rad, secs, 0 );
|
||||
double angle = sun_angle( t, world_up, lon_rad, lat_rad );
|
||||
if ( angle < best_angle ) {
|
||||
|
@ -107,10 +112,6 @@ time_t fgTimeSecondsUntilNoon( time_t cur_time,
|
|||
}
|
||||
}
|
||||
|
||||
if ( best_time > day_secs / 2 ) {
|
||||
best_time -= day_secs;
|
||||
}
|
||||
|
||||
return best_time - cur_time;
|
||||
}
|
||||
|
||||
|
@ -133,7 +134,10 @@ time_t fgTimeSecondsUntilMidnight( time_t cur_time,
|
|||
double best_angle = 0.0;
|
||||
time_t best_time = cur_time;
|
||||
|
||||
for ( time_t secs = cur_time; secs < cur_time + day_secs; secs += 300 ) {
|
||||
for ( time_t secs = cur_time - half_day_secs;
|
||||
secs < cur_time + half_day_secs;
|
||||
secs += step_secs )
|
||||
{
|
||||
t.update( lon_rad, lat_rad, secs, 0 );
|
||||
double angle = sun_angle( t, world_up, lon_rad, lat_rad );
|
||||
if ( angle > best_angle ) {
|
||||
|
@ -144,10 +148,6 @@ time_t fgTimeSecondsUntilMidnight( time_t cur_time,
|
|||
}
|
||||
}
|
||||
|
||||
if ( best_time > day_secs / 2 ) {
|
||||
best_time -= day_secs;
|
||||
}
|
||||
|
||||
return best_time - cur_time;
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,10 @@ time_t fgTimeSecondsUntilDusk( time_t cur_time,
|
|||
double last_angle = -99999.0;
|
||||
time_t best_time = cur_time;
|
||||
|
||||
for ( time_t secs = cur_time; secs < cur_time + day_secs; secs += 300 ) {
|
||||
for ( time_t secs = cur_time - half_day_secs;
|
||||
secs < cur_time + half_day_secs;
|
||||
secs += step_secs )
|
||||
{
|
||||
t.update( lon_rad, lat_rad, secs, 0 );
|
||||
double angle = sun_angle( t, world_up, lon_rad, lat_rad );
|
||||
double diff = fabs( angle - 90.0 );
|
||||
|
@ -187,10 +190,6 @@ time_t fgTimeSecondsUntilDusk( time_t cur_time,
|
|||
last_angle = angle;
|
||||
}
|
||||
|
||||
if ( best_time > day_secs / 2 ) {
|
||||
best_time -= day_secs;
|
||||
}
|
||||
|
||||
return best_time - cur_time;
|
||||
}
|
||||
|
||||
|
@ -214,7 +213,10 @@ time_t fgTimeSecondsUntilDawn( time_t cur_time,
|
|||
double last_angle = -99999.0;
|
||||
time_t best_time = cur_time;
|
||||
|
||||
for ( time_t secs = cur_time; secs < cur_time + day_secs; secs += 300 ) {
|
||||
for ( time_t secs = cur_time - half_day_secs;
|
||||
secs < cur_time + half_day_secs;
|
||||
secs += step_secs )
|
||||
{
|
||||
t.update( lon_rad, lat_rad, secs, 0 );
|
||||
double angle = sun_angle( t, world_up, lon_rad, lat_rad );
|
||||
double diff = fabs( angle - 90.0 );
|
||||
|
@ -230,9 +232,5 @@ time_t fgTimeSecondsUntilDawn( time_t cur_time,
|
|||
last_angle = angle;
|
||||
}
|
||||
|
||||
if ( best_time > day_secs / 2 ) {
|
||||
best_time -= day_secs;
|
||||
}
|
||||
|
||||
return best_time - cur_time;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue