summaryrefslogtreecommitdiff
path: root/src/environment.cpp
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2015-11-04 06:44:55 +0100
committerest31 <MTest31@outlook.com>2015-11-04 07:12:02 +0100
commitc75ab521153b928e6718d7d3ac4c2104f13ac1e4 (patch)
treea14b366faea33208a6adc3ad450a9217aff138bf /src/environment.cpp
parent64049cf72ae240c774e07c7fd45e1dc7cc95e780 (diff)
downloadminetest-c75ab521153b928e6718d7d3ac4c2104f13ac1e4.tar.gz
minetest-c75ab521153b928e6718d7d3ac4c2104f13ac1e4.tar.bz2
minetest-c75ab521153b928e6718d7d3ac4c2104f13ac1e4.zip
Fix time progressing too fast
Before, time progressed wrongly. This was due to a mistake in how m_time_of_day_f was calculated, and a regression of the last two commits.
Diffstat (limited to 'src/environment.cpp')
-rw-r--r--src/environment.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/environment.cpp b/src/environment.cpp
index 76b7ec1e0..38316cb31 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -225,7 +225,12 @@ float Environment::getTimeOfDayF()
void Environment::stepTimeOfDay(float dtime)
{
MutexAutoLock lock(this->m_time_lock);
- f32 speed = m_time_of_day_speed * 24000. / (24. * 3600);
+
+ // Cached in order to prevent the two reads we do to give
+ // different results (can be written by code not under the lock)
+ f32 cached_time_of_day_speed = m_time_of_day_speed;
+
+ f32 speed = cached_time_of_day_speed * 24000. / (24. * 3600);
m_time_conversion_skew += dtime;
u32 units = (u32)(m_time_conversion_skew * speed);
bool sync_f = false;
@@ -241,7 +246,7 @@ void Environment::stepTimeOfDay(float dtime)
m_time_conversion_skew -= (f32)units / speed;
}
if (!sync_f) {
- m_time_of_day_f += speed * dtime;
+ m_time_of_day_f += cached_time_of_day_speed / 24 / 3600 * dtime;
if (m_time_of_day_f > 1.0)
m_time_of_day_f -= 1.0;
if (m_time_of_day_f < 0.0)