Factor timeofday command into the TimeManager
This commit is contained in:
parent
5bae2e3d37
commit
436abe1e62
3 changed files with 29 additions and 86 deletions
|
@ -33,7 +33,6 @@
|
||||||
#include <Scenery/scenery.hxx>
|
#include <Scenery/scenery.hxx>
|
||||||
#include <Scripting/NasalSys.hxx>
|
#include <Scripting/NasalSys.hxx>
|
||||||
#include <Sound/sample_queue.hxx>
|
#include <Sound/sample_queue.hxx>
|
||||||
#include <Time/sunsolver.hxx>
|
|
||||||
#include <Airports/xmlloader.hxx>
|
#include <Airports/xmlloader.hxx>
|
||||||
|
|
||||||
#include "fg_init.hxx"
|
#include "fg_init.hxx"
|
||||||
|
@ -699,85 +698,6 @@ do_set_dewpoint_degc (const SGPropertyNode * arg)
|
||||||
return do_set_dewpoint_sea_level_degc(dummy.get_dewpoint_sea_level_degc());
|
return do_set_dewpoint_sea_level_degc(dummy.get_dewpoint_sea_level_degc());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/**
|
|
||||||
* Update the lighting manually.
|
|
||||||
*/
|
|
||||||
static bool
|
|
||||||
do_timeofday (const SGPropertyNode * arg)
|
|
||||||
{
|
|
||||||
const string &offset_type = arg->getStringValue("timeofday", "noon");
|
|
||||||
|
|
||||||
static const SGPropertyNode *longitude
|
|
||||||
= fgGetNode("/position/longitude-deg");
|
|
||||||
static const SGPropertyNode *latitude
|
|
||||||
= fgGetNode("/position/latitude-deg");
|
|
||||||
|
|
||||||
int orig_warp = globals->get_warp();
|
|
||||||
SGTime *t = globals->get_time_params();
|
|
||||||
time_t cur_time = t->get_cur_time();
|
|
||||||
// cout << "cur_time = " << cur_time << endl;
|
|
||||||
// cout << "orig_warp = " << orig_warp << endl;
|
|
||||||
|
|
||||||
int warp = 0;
|
|
||||||
if ( offset_type == "real" ) {
|
|
||||||
warp = -orig_warp;
|
|
||||||
} else if ( offset_type == "dawn" ) {
|
|
||||||
warp = fgTimeSecondsUntilSunAngle( cur_time,
|
|
||||||
longitude->getDoubleValue()
|
|
||||||
* SGD_DEGREES_TO_RADIANS,
|
|
||||||
latitude->getDoubleValue()
|
|
||||||
* SGD_DEGREES_TO_RADIANS,
|
|
||||||
90.0, true );
|
|
||||||
} else if ( offset_type == "morning" ) {
|
|
||||||
warp = fgTimeSecondsUntilSunAngle( cur_time,
|
|
||||||
longitude->getDoubleValue()
|
|
||||||
* SGD_DEGREES_TO_RADIANS,
|
|
||||||
latitude->getDoubleValue()
|
|
||||||
* SGD_DEGREES_TO_RADIANS,
|
|
||||||
75.0, true );
|
|
||||||
} else if ( offset_type == "noon" ) {
|
|
||||||
warp = fgTimeSecondsUntilSunAngle( cur_time,
|
|
||||||
longitude->getDoubleValue()
|
|
||||||
* SGD_DEGREES_TO_RADIANS,
|
|
||||||
latitude->getDoubleValue()
|
|
||||||
* SGD_DEGREES_TO_RADIANS,
|
|
||||||
0.0, true );
|
|
||||||
} else if ( offset_type == "afternoon" ) {
|
|
||||||
warp = fgTimeSecondsUntilSunAngle( cur_time,
|
|
||||||
longitude->getDoubleValue()
|
|
||||||
* SGD_DEGREES_TO_RADIANS,
|
|
||||||
latitude->getDoubleValue()
|
|
||||||
* SGD_DEGREES_TO_RADIANS,
|
|
||||||
60.0, false );
|
|
||||||
} else if ( offset_type == "dusk" ) {
|
|
||||||
warp = fgTimeSecondsUntilSunAngle( cur_time,
|
|
||||||
longitude->getDoubleValue()
|
|
||||||
* SGD_DEGREES_TO_RADIANS,
|
|
||||||
latitude->getDoubleValue()
|
|
||||||
* SGD_DEGREES_TO_RADIANS,
|
|
||||||
90.0, false );
|
|
||||||
} else if ( offset_type == "evening" ) {
|
|
||||||
warp = fgTimeSecondsUntilSunAngle( cur_time,
|
|
||||||
longitude->getDoubleValue()
|
|
||||||
* SGD_DEGREES_TO_RADIANS,
|
|
||||||
latitude->getDoubleValue()
|
|
||||||
* SGD_DEGREES_TO_RADIANS,
|
|
||||||
100.0, false );
|
|
||||||
} else if ( offset_type == "midnight" ) {
|
|
||||||
warp = fgTimeSecondsUntilSunAngle( cur_time,
|
|
||||||
longitude->getDoubleValue()
|
|
||||||
* SGD_DEGREES_TO_RADIANS,
|
|
||||||
latitude->getDoubleValue()
|
|
||||||
* SGD_DEGREES_TO_RADIANS,
|
|
||||||
180.0, false );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fgSetInt("/sim/time/warp", orig_warp + warp);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Built-in command: toggle a bool property value.
|
* Built-in command: toggle a bool property value.
|
||||||
|
@ -1468,7 +1388,6 @@ static struct {
|
||||||
{ "set-dewpoint-sea-level-air-temp-degc", do_set_dewpoint_sea_level_degc },
|
{ "set-dewpoint-sea-level-air-temp-degc", do_set_dewpoint_sea_level_degc },
|
||||||
{ "set-dewpoint-temp-degc", do_set_dewpoint_degc },
|
{ "set-dewpoint-temp-degc", do_set_dewpoint_degc },
|
||||||
*/
|
*/
|
||||||
{ "timeofday", do_timeofday },
|
|
||||||
{ "property-toggle", do_property_toggle },
|
{ "property-toggle", do_property_toggle },
|
||||||
{ "property-assign", do_property_assign },
|
{ "property-assign", do_property_assign },
|
||||||
{ "property-adjust", do_property_adjust },
|
{ "property-adjust", do_property_adjust },
|
||||||
|
|
|
@ -35,16 +35,32 @@
|
||||||
#include <simgear/structure/event_mgr.hxx>
|
#include <simgear/structure/event_mgr.hxx>
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
#include <simgear/timing/lowleveltime.h>
|
#include <simgear/timing/lowleveltime.h>
|
||||||
|
#include <simgear/structure/commands.hxx>
|
||||||
|
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
#include <Time/sunsolver.hxx>
|
#include <Time/sunsolver.hxx>
|
||||||
|
|
||||||
|
static bool do_timeofday (const SGPropertyNode * arg)
|
||||||
|
{
|
||||||
|
const string &offset_type = arg->getStringValue("timeofday", "noon");
|
||||||
|
int offset = arg->getIntValue("offset", 0);
|
||||||
|
TimeManager* self = (TimeManager*) globals->get_subsystem("time");
|
||||||
|
if (offset_type == "real") {
|
||||||
|
// without this, setting 'real' time is a no-op, since the current
|
||||||
|
// wrap value (orig_warp) is retained in setTimeOffset. Ick.
|
||||||
|
fgSetInt("/sim/time/warp", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
self->setTimeOffset(offset_type, offset);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
TimeManager::TimeManager() :
|
TimeManager::TimeManager() :
|
||||||
_inited(false),
|
_inited(false),
|
||||||
_impl(NULL)
|
_impl(NULL)
|
||||||
{
|
{
|
||||||
|
SGCommandMgr::instance()->addCommand("timeofday", do_timeofday);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeManager::init()
|
void TimeManager::init()
|
||||||
|
@ -345,6 +361,14 @@ void TimeManager::updateLocalTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeManager::initTimeOffset()
|
void TimeManager::initTimeOffset()
|
||||||
|
{
|
||||||
|
|
||||||
|
int offset = fgGetInt("/sim/startup/time-offset");
|
||||||
|
string offset_type = fgGetString("/sim/startup/time-offset-type");
|
||||||
|
setTimeOffset(offset_type, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimeManager::setTimeOffset(const std::string& offset_type, int offset)
|
||||||
{
|
{
|
||||||
// Handle potential user specified time offsets
|
// Handle potential user specified time offsets
|
||||||
int orig_warp = _warp->getIntValue();
|
int orig_warp = _warp->getIntValue();
|
||||||
|
@ -355,8 +379,6 @@ void TimeManager::initTimeOffset()
|
||||||
sgTimeGetGMT( fgLocaltime(&cur_time, _impl->get_zonename() ) );
|
sgTimeGetGMT( fgLocaltime(&cur_time, _impl->get_zonename() ) );
|
||||||
|
|
||||||
// Okay, we now have several possible scenarios
|
// Okay, we now have several possible scenarios
|
||||||
int offset = fgGetInt("/sim/startup/time-offset");
|
|
||||||
string offset_type = fgGetString("/sim/startup/time-offset-type");
|
|
||||||
double lon = _longitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
|
double lon = _longitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
|
||||||
double lat = _latitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
|
double lat = _latitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
|
||||||
int warp = 0;
|
int warp = 0;
|
||||||
|
@ -394,12 +416,12 @@ void TimeManager::initTimeOffset()
|
||||||
warp = offset - (aircraftLocalTime - currGMT)- cur_time;
|
warp = offset - (aircraftLocalTime - currGMT)- cur_time;
|
||||||
} else {
|
} else {
|
||||||
SG_LOG( SG_GENERAL, SG_ALERT,
|
SG_LOG( SG_GENERAL, SG_ALERT,
|
||||||
"TimeManager::initTimeOffset: unsupported offset: " << offset_type );
|
"TimeManager::setTimeOffset: unsupported offset: " << offset_type );
|
||||||
warp = 0;
|
warp = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_warp->setIntValue( orig_warp + warp );
|
_warp->setIntValue( orig_warp + warp );
|
||||||
|
|
||||||
SG_LOG( SG_GENERAL, SG_INFO, "After fgInitTimeOffset(): warp = "
|
SG_LOG( SG_GENERAL, SG_INFO, "After TimeManager::setTimeOffset(): warp = "
|
||||||
<< _warp->getIntValue() );
|
<< _warp->getIntValue() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,8 @@ public:
|
||||||
|
|
||||||
// SGPropertyChangeListener overrides
|
// SGPropertyChangeListener overrides
|
||||||
virtual void valueChanged(SGPropertyNode *);
|
virtual void valueChanged(SGPropertyNode *);
|
||||||
|
|
||||||
|
void setTimeOffset(const std::string& offset_type, int offset);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue