@@ -42,6 +42,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
42
42
#include " map.h"
43
43
#include " emerge.h"
44
44
#include " util/serialize.h"
45
+ #include " jthread/jmutexautolock.h"
45
46
46
47
#define PP (x ) " (" <<(x).X<<" ," <<(x).Y<<" ," <<(x).Z<<" )"
47
48
@@ -196,12 +197,30 @@ u32 Environment::getDayNightRatio()
196
197
return time_to_daynight_ratio (m_time_of_day_f*24000 , smooth);
197
198
}
198
199
200
+ void Environment::setTimeOfDaySpeed (float speed)
201
+ {
202
+ JMutexAutoLock (this ->m_lock );
203
+ m_time_of_day_speed = speed;
204
+ }
205
+
206
+ float Environment::getTimeOfDaySpeed ()
207
+ {
208
+ JMutexAutoLock (this ->m_lock );
209
+ float retval = m_time_of_day_speed;
210
+ return retval;
211
+ }
212
+
199
213
void Environment::stepTimeOfDay (float dtime)
200
214
{
215
+ float day_speed = 0 ;
216
+ {
217
+ JMutexAutoLock (this ->m_lock );
218
+ day_speed = m_time_of_day_speed;
219
+ }
220
+
201
221
m_time_counter += dtime;
202
- f32 speed = m_time_of_day_speed * 24000 ./(24 .*3600 );
222
+ f32 speed = day_speed * 24000 ./(24 .*3600 );
203
223
u32 units = (u32)(m_time_counter*speed);
204
- m_time_counter -= (f32)units / speed;
205
224
bool sync_f = false ;
206
225
if (units > 0 ){
207
226
// Sync at overflow
@@ -211,8 +230,11 @@ void Environment::stepTimeOfDay(float dtime)
211
230
if (sync_f)
212
231
m_time_of_day_f = (float )m_time_of_day / 24000.0 ;
213
232
}
233
+ if (speed > 0 ) {
234
+ m_time_counter -= (f32)units / speed;
235
+ }
214
236
if (!sync_f){
215
- m_time_of_day_f += m_time_of_day_speed /24 /3600 *dtime;
237
+ m_time_of_day_f += day_speed /24 /3600 *dtime;
216
238
if (m_time_of_day_f > 1.0 )
217
239
m_time_of_day_f -= 1.0 ;
218
240
if (m_time_of_day_f < 0.0 )
0 commit comments