Local time available without the clock instrument
Compute the local time value inside the TimeManager, so that the UI doesn’t need to rely on the default clock instrument (which might not exist) to show correct local time. Also fix updating of time-offset/time-zone, to be based on distance travelled instead of elapsed wall-clock time. (needs an FGData update as well) Ticket-Id: https://sourceforge.net/p/flightgear/codetickets/2514/
This commit is contained in:
parent
fb8ef10918
commit
9704c1cc93
2 changed files with 37 additions and 8 deletions
|
@ -25,7 +25,6 @@
|
||||||
#include "TimeManager.hxx"
|
#include "TimeManager.hxx"
|
||||||
|
|
||||||
#include <simgear/timing/sg_time.hxx>
|
#include <simgear/timing/sg_time.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 <simgear/structure/commands.hxx>
|
||||||
|
@ -84,7 +83,7 @@ void TimeManager::init()
|
||||||
_warp = fgGetNode("/sim/time/warp", true);
|
_warp = fgGetNode("/sim/time/warp", true);
|
||||||
_warp->addChangeListener(this);
|
_warp->addChangeListener(this);
|
||||||
_maxFrameRate = fgGetNode("/sim/frame-rate-throttle-hz", true);
|
_maxFrameRate = fgGetNode("/sim/frame-rate-throttle-hz", true);
|
||||||
|
_localTimeStringNode = fgGetNode("/sim/time/local-time-string", true);
|
||||||
_warpDelta = fgGetNode("/sim/time/warp-delta", true);
|
_warpDelta = fgGetNode("/sim/time/warp-delta", true);
|
||||||
|
|
||||||
SGPath zone(globals->get_fg_root());
|
SGPath zone(globals->get_fg_root());
|
||||||
|
@ -93,9 +92,6 @@ void TimeManager::init()
|
||||||
_impl = new SGTime(globals->get_aircraft_position(), zone, _timeOverride->getLongValue());
|
_impl = new SGTime(globals->get_aircraft_position(), zone, _timeOverride->getLongValue());
|
||||||
|
|
||||||
_warpDelta->setDoubleValue(0.0);
|
_warpDelta->setDoubleValue(0.0);
|
||||||
|
|
||||||
globals->get_event_mgr()->addTask("updateLocalTime", this,
|
|
||||||
&TimeManager::updateLocalTime, 30*60 );
|
|
||||||
updateLocalTime();
|
updateLocalTime();
|
||||||
|
|
||||||
_impl->update(globals->get_aircraft_position(), _timeOverride->getLongValue(),
|
_impl->update(globals->get_aircraft_position(), _timeOverride->getLongValue(),
|
||||||
|
@ -180,7 +176,6 @@ void TimeManager::shutdown()
|
||||||
delete _impl;
|
delete _impl;
|
||||||
_impl = NULL;
|
_impl = NULL;
|
||||||
_inited = false;
|
_inited = false;
|
||||||
globals->get_event_mgr()->removeTask("updateLocalTime");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeManager::valueChanged(SGPropertyNode* aProp)
|
void TimeManager::valueChanged(SGPropertyNode* aProp)
|
||||||
|
@ -359,11 +354,18 @@ void TimeManager::update(double dt)
|
||||||
_warp->setDoubleValue(_warp->getDoubleValue() + warpOffset);
|
_warp->setDoubleValue(_warp->getDoubleValue() + warpOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto d2 = distSqr(_lastTimeZoneCheckPosition, globals->get_aircraft_position_cart());
|
||||||
|
const auto oneNmSqr = SG_NM_TO_METER * SG_NM_TO_METER;
|
||||||
|
if (d2 > oneNmSqr) {
|
||||||
|
updateLocalTime();
|
||||||
|
}
|
||||||
|
|
||||||
_lastClockFreeze = freeze;
|
_lastClockFreeze = freeze;
|
||||||
_impl->update(globals->get_aircraft_position(),
|
_impl->update(globals->get_aircraft_position(),
|
||||||
_timeOverride->getLongValue(),
|
_timeOverride->getLongValue(),
|
||||||
_warp->getIntValue());
|
_warp->getIntValue());
|
||||||
|
|
||||||
|
updateLocalTimeString();
|
||||||
computeFrameRate();
|
computeFrameRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,7 +407,26 @@ void TimeManager::throttleUpdateRate()
|
||||||
// periodic time updater wrapper
|
// periodic time updater wrapper
|
||||||
void TimeManager::updateLocalTime()
|
void TimeManager::updateLocalTime()
|
||||||
{
|
{
|
||||||
|
_lastTimeZoneCheckPosition = globals->get_aircraft_position_cart();
|
||||||
_impl->updateLocal(globals->get_aircraft_position(), globals->get_fg_root() / "Timezone");
|
_impl->updateLocal(globals->get_aircraft_position(), globals->get_fg_root() / "Timezone");
|
||||||
|
// synchronous update, since somebody might need that
|
||||||
|
updateLocalTimeString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimeManager::updateLocalTimeString()
|
||||||
|
{
|
||||||
|
time_t cur_time = _impl->get_cur_time();
|
||||||
|
struct tm* aircraftLocalTime = fgLocaltime(&cur_time, _impl->get_zonename());
|
||||||
|
static char buf[16];
|
||||||
|
snprintf(buf, 16, "%.2d:%.2d:%.2d",
|
||||||
|
aircraftLocalTime->tm_hour,
|
||||||
|
aircraftLocalTime->tm_min, aircraftLocalTime->tm_sec);
|
||||||
|
|
||||||
|
// check against current string to avoid changes all the time
|
||||||
|
const char* s = _localTimeStringNode->getStringValue();
|
||||||
|
if (strcmp(s, buf) != 0) {
|
||||||
|
_localTimeStringNode->setStringValue(buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeManager::initTimeOffset()
|
void TimeManager::initTimeOffset()
|
||||||
|
|
|
@ -21,8 +21,9 @@
|
||||||
#ifndef FG_TIME_TIMEMANAGER_HXX
|
#ifndef FG_TIME_TIMEMANAGER_HXX
|
||||||
#define FG_TIME_TIMEMANAGER_HXX
|
#define FG_TIME_TIMEMANAGER_HXX
|
||||||
|
|
||||||
#include <simgear/structure/subsystem_mgr.hxx>
|
|
||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
|
#include <simgear/structure/subsystem_mgr.hxx>
|
||||||
|
#include <simgear/math/SGVec3.hxx>
|
||||||
|
|
||||||
// forward decls
|
// forward decls
|
||||||
class SGTime;
|
class SGTime;
|
||||||
|
@ -56,6 +57,7 @@ public:
|
||||||
inline double getSteadyClockSec() const { return _steadyClock; }
|
inline double getSteadyClockSec() const { return _steadyClock; }
|
||||||
|
|
||||||
double getSimSpeedUpFactor() const;
|
double getSimSpeedUpFactor() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// test class is a friend so we can fake elapsed system time
|
// test class is a friend so we can fake elapsed system time
|
||||||
friend class TimeManagerTests;
|
friend class TimeManagerTests;
|
||||||
|
@ -73,6 +75,8 @@ private:
|
||||||
|
|
||||||
void updateLocalTime();
|
void updateLocalTime();
|
||||||
|
|
||||||
|
void updateLocalTimeString();
|
||||||
|
|
||||||
// set up a time offset (aka warp) if one is specified
|
// set up a time offset (aka warp) if one is specified
|
||||||
void initTimeOffset();
|
void initTimeOffset();
|
||||||
|
|
||||||
|
@ -97,6 +101,7 @@ private:
|
||||||
SGPropertyNode_ptr _computeDrift;
|
SGPropertyNode_ptr _computeDrift;
|
||||||
SGPropertyNode_ptr _frameWait;
|
SGPropertyNode_ptr _frameWait;
|
||||||
SGPropertyNode_ptr _maxFrameRate;
|
SGPropertyNode_ptr _maxFrameRate;
|
||||||
|
SGPropertyNode_ptr _localTimeStringNode;
|
||||||
|
|
||||||
bool _lastClockFreeze;
|
bool _lastClockFreeze;
|
||||||
bool _adjustWarpOnUnfreeze;
|
bool _adjustWarpOnUnfreeze;
|
||||||
|
@ -111,6 +116,9 @@ private:
|
||||||
double _steadyClock;
|
double _steadyClock;
|
||||||
int _frameCount;
|
int _frameCount;
|
||||||
|
|
||||||
|
// we update TZ after moving more than a threshold distance
|
||||||
|
SGVec3d _lastTimeZoneCheckPosition;
|
||||||
|
|
||||||
SGPropertyNode_ptr _sceneryLoaded;
|
SGPropertyNode_ptr _sceneryLoaded;
|
||||||
SGPropertyNode_ptr _modelHz;
|
SGPropertyNode_ptr _modelHz;
|
||||||
SGPropertyNode_ptr _timeDelta, _simTimeDelta;
|
SGPropertyNode_ptr _timeDelta, _simTimeDelta;
|
||||||
|
|
Loading…
Add table
Reference in a new issue