Skip to content

Commit c75ab52

Browse files
committedNov 4, 2015
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.
1 parent 64049cf commit c75ab52

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed
 

‎src/environment.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,12 @@ float Environment::getTimeOfDayF()
225225
void Environment::stepTimeOfDay(float dtime)
226226
{
227227
MutexAutoLock lock(this->m_time_lock);
228-
f32 speed = m_time_of_day_speed * 24000. / (24. * 3600);
228+
229+
// Cached in order to prevent the two reads we do to give
230+
// different results (can be written by code not under the lock)
231+
f32 cached_time_of_day_speed = m_time_of_day_speed;
232+
233+
f32 speed = cached_time_of_day_speed * 24000. / (24. * 3600);
229234
m_time_conversion_skew += dtime;
230235
u32 units = (u32)(m_time_conversion_skew * speed);
231236
bool sync_f = false;
@@ -241,7 +246,7 @@ void Environment::stepTimeOfDay(float dtime)
241246
m_time_conversion_skew -= (f32)units / speed;
242247
}
243248
if (!sync_f) {
244-
m_time_of_day_f += speed * dtime;
249+
m_time_of_day_f += cached_time_of_day_speed / 24 / 3600 * dtime;
245250
if (m_time_of_day_f > 1.0)
246251
m_time_of_day_f -= 1.0;
247252
if (m_time_of_day_f < 0.0)

0 commit comments

Comments
 (0)
Please sign in to comment.