Merge lp:~bi0ha2ard/stellarium/timefix into lp:stellarium

Proposed by Alexander Wolf
Status: Merged
Approved by: Alexander Wolf
Approved revision: 6569
Merged at revision: 6571
Proposed branch: lp:~bi0ha2ard/stellarium/timefix
Merge into: lp:stellarium
Diff against target: 97 lines (+25/-2)
2 files modified
src/core/StelCore.cpp (+21/-2)
src/core/StelCore.hpp (+4/-0)
To merge this branch: bzr merge lp:~bi0ha2ard/stellarium/timefix
Reviewer Review Type Date Requested Status
Fabien Chéreau Approve
Alexander Wolf Approve
Guillaume Chereau Pending
treaves Pending
Review via email: mp+206209@code.launchpad.net

Description of the change

Felix Zeltner proposed improvements for time syncing with operating system for minimize drift of time when Stellarium worked long time.

To post a comment you must log in.
Revision history for this message
Alexander Wolf (alexwolf) wrote :

Looks like this patch is good but it need for testing (2-3 days for working Stellarium) :)

review: Approve
Revision history for this message
Fabien Chéreau (xalioth) wrote :

lastTimeChangeJDay variable is not necessary, simply do JDay += (StelApp::getTotalRunTime() - lastTimeChangeTime) / ONE_OVER_JD_SECOND

Also be careful with variable naming: lastTimeChangeTime -> timeOfLastJDayUpdate

StelCore::resetSync() can then be replaced by a simpler
timeOfLastJDayUpdate = StelApp::getTotalRunTime();

Isn't it?

review: Needs Fixing
Revision history for this message
Felix Z. (bi0ha2ard) wrote :

> lastTimeChangeJDay variable is not necessary, simply do JDay +=
> (StelApp::getTotalRunTime() - lastTimeChangeTime) / ONE_OVER_JD_SECOND
>
> Also be careful with variable naming: lastTimeChangeTime ->
> timeOfLastJDayUpdate
>
> StelCore::resetSync() can then be replaced by a simpler
> timeOfLastJDayUpdate = StelApp::getTotalRunTime();
>
> Isn't it?

No, lastTimeChangeJDay is necessary, otherwise you'd have to set lastTimeChangeTime every time updateTime() is called and you get the same behaviour as before because StelApp::getTotalRunTime() - lastTimeChangeTime would be the same as deltaTime.
This means you would be adding up small slices of time as before hence introducing one of the errors again.

lp:~bi0ha2ard/stellarium/timefix updated
6569. By bi0ha2ard

Variable names changed

Revision history for this message
Fabien Chéreau (xalioth) wrote :

OK I see. OK then. Try at least to name the variables with more meaningful
names!
Fab

On Thu, Feb 13, 2014 at 5:20 PM, Felix Z. <email address hidden>wrote:

> > lastTimeChangeJDay variable is not necessary, simply do JDay +=
> > (StelApp::getTotalRunTime() - lastTimeChangeTime) / ONE_OVER_JD_SECOND
> >
> > Also be careful with variable naming: lastTimeChangeTime ->
> > timeOfLastJDayUpdate
> >
> > StelCore::resetSync() can then be replaced by a simpler
> > timeOfLastJDayUpdate = StelApp::getTotalRunTime();
> >
> > Isn't it?
>
> No, lastTimeChangeJDay is necessary, otherwise you'd have to set
> lastTimeChangeTime every time updateTime() is called and you get the same
> behaviour as before because StelApp::getTotalRunTime() - lastTimeChangeTime
> would be the same as deltaTime.
> This means you would be adding up small slices of time as before hence
> introducing one of the errors again.
> --
> https://code.launchpad.net/~bi0ha2ard/stellarium/timefix/+merge/206209
> You are reviewing the proposed merge of lp:~bi0ha2ard/stellarium/timefix
> into lp:stellarium.
>

Revision history for this message
Felix Z. (bi0ha2ard) wrote :

OK, variable names changed in next commit.

> OK I see. OK then. Try at least to name the variables with more meaningful
> names!
> Fab
>
>
> On Thu, Feb 13, 2014 at 5:20 PM, Felix Z. <email address hidden>wrote:
>
> > > lastTimeChangeJDay variable is not necessary, simply do JDay +=
> > > (StelApp::getTotalRunTime() - lastTimeChangeTime) / ONE_OVER_JD_SECOND
> > >
> > > Also be careful with variable naming: lastTimeChangeTime ->
> > > timeOfLastJDayUpdate
> > >
> > > StelCore::resetSync() can then be replaced by a simpler
> > > timeOfLastJDayUpdate = StelApp::getTotalRunTime();
> > >
> > > Isn't it?
> >
> > No, lastTimeChangeJDay is necessary, otherwise you'd have to set
> > lastTimeChangeTime every time updateTime() is called and you get the same
> > behaviour as before because StelApp::getTotalRunTime() - lastTimeChangeTime
> > would be the same as deltaTime.
> > This means you would be adding up small slices of time as before hence
> > introducing one of the errors again.
> > --
> > https://code.launchpad.net/~bi0ha2ard/stellarium/timefix/+merge/206209
> > You are reviewing the proposed merge of lp:~bi0ha2ard/stellarium/timefix
> > into lp:stellarium.
> >

Revision history for this message
Fabien Chéreau (xalioth) wrote :

ok, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/core/StelCore.cpp'
2--- src/core/StelCore.cpp 2014-02-10 11:06:35 +0000
3+++ src/core/StelCore.cpp 2014-02-13 17:24:14 +0000
4@@ -53,6 +53,7 @@
5 const double StelCore::JD_MINUTE=0.00069444444444444444444;
6 const double StelCore::JD_HOUR =0.041666666666666666666;
7 const double StelCore::JD_DAY =1.;
8+const double StelCore::ONE_OVER_JD_SECOND = 24 * 60 * 60;
9
10
11 StelCore::StelCore() : movementMgr(NULL), geodesicGrid(NULL), currentProjectionType(ProjectionStereographic), position(NULL), timeSpeed(JD_SECOND), JDay(0.)
12@@ -771,6 +772,7 @@
13 void StelCore::setJDay(double JD)
14 {
15 JDay=JD;
16+ resetSync();
17 }
18
19 double StelCore::getJDay() const
20@@ -781,6 +783,7 @@
21 void StelCore::setMJDay(double MJD)
22 {
23 JDay=MJD+2400000.5;
24+ resetSync();
25 }
26
27 double StelCore::getMJDay() const
28@@ -800,7 +803,9 @@
29
30 void StelCore::setTimeRate(double ts)
31 {
32- timeSpeed=ts; emit timeRateChanged(timeSpeed);
33+ timeSpeed=ts;
34+ resetSync();
35+ emit timeRateChanged(timeSpeed);
36 }
37
38 double StelCore::getTimeRate() const
39@@ -1223,7 +1228,15 @@
40 // Increment time
41 void StelCore::updateTime(double deltaTime)
42 {
43- JDay+=timeSpeed*deltaTime;
44+ if (getRealTimeSpeed())
45+ {
46+ // Get rid of the error from the 1 /
47+ JDay = JDayOfLastJDayUpdate + (StelApp::getTotalRunTime() - secondsOfLastJDayUpdate) / ONE_OVER_JD_SECOND;
48+ }
49+ else
50+ {
51+ JDay = JDayOfLastJDayUpdate + (StelApp::getTotalRunTime() - secondsOfLastJDayUpdate) * timeSpeed;
52+ }
53
54 // Fix time limits to -100000 to +100000 to prevent bugs
55 if (JDay>38245309.499988) JDay = 38245309.499988;
56@@ -1249,6 +1262,12 @@
57 solsystem->computePositions(getJDay(), position->getHomePlanet()->getHeliocentricEclipticPos());
58 }
59
60+void StelCore::resetSync()
61+{
62+ JDayOfLastJDayUpdate = getJDay();
63+ secondsOfLastJDayUpdate = StelApp::getTotalRunTime();
64+}
65+
66 void StelCore::setStartupTimeMode(const QString& s)
67 {
68 startupTimeMode = s;
69
70=== modified file 'src/core/StelCore.hpp'
71--- src/core/StelCore.hpp 2013-12-27 09:25:21 +0000
72+++ src/core/StelCore.hpp 2014-02-13 17:24:14 +0000
73@@ -259,6 +259,7 @@
74 static const double JD_MINUTE;
75 static const double JD_HOUR;
76 static const double JD_DAY;
77+ static const double ONE_OVER_JD_SECOND;
78
79 //! Get the sidereal time shifted by the observer longitude
80 //! @return the local sidereal time in radian
81@@ -534,6 +535,7 @@
82
83 void updateTransformMatrices();
84 void updateTime(double deltaTime);
85+ void resetSync();
86
87 // Matrices used for every coordinate transfo
88 Mat4d matHeliocentricEclipticToAltAz; // Transform from heliocentric ecliptic (Vsop87) to observer-centric altazimuthal coordinate
89@@ -559,6 +561,8 @@
90 double presetSkyTime;
91 QTime initTodayTime;
92 QString startupTimeMode;
93+ double secondsOfLastJDayUpdate; // Time in seconds when the time rate or time last changed
94+ double JDayOfLastJDayUpdate; // JDay when the time rate or time last changed
95
96 // Variables for custom equation of Delta-T
97 Vec3f deltaTCustomEquationCoeff;