File tree 1 file changed +7
-2
lines changed
1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -225,7 +225,12 @@ float Environment::getTimeOfDayF()
225
225
void Environment::stepTimeOfDay (float dtime)
226
226
{
227
227
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 );
229
234
m_time_conversion_skew += dtime;
230
235
u32 units = (u32)(m_time_conversion_skew * speed);
231
236
bool sync_f = false ;
@@ -241,7 +246,7 @@ void Environment::stepTimeOfDay(float dtime)
241
246
m_time_conversion_skew -= (f32)units / speed;
242
247
}
243
248
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;
245
250
if (m_time_of_day_f > 1.0 )
246
251
m_time_of_day_f -= 1.0 ;
247
252
if (m_time_of_day_f < 0.0 )
You can’t perform that action at this time.
0 commit comments