u32 Environment::getDayNightRatio()
{
- if(m_enable_day_night_ratio_override)
+ MutexAutoLock(this->m_time_lock);
+ if (m_enable_day_night_ratio_override)
return m_day_night_ratio_override;
- return time_to_daynight_ratio(m_time_of_day_f*24000, m_cache_enable_shaders);
+ return time_to_daynight_ratio(m_time_of_day_f * 24000, m_cache_enable_shaders);
}
void Environment::setTimeOfDaySpeed(float speed)
{
- MutexAutoLock(this->m_timeofday_lock);
+ MutexAutoLock(this->m_time_lock);
m_time_of_day_speed = speed;
}
float Environment::getTimeOfDaySpeed()
{
- MutexAutoLock(this->m_timeofday_lock);
+ MutexAutoLock(this->m_time_lock);
float retval = m_time_of_day_speed;
return retval;
}
void Environment::stepTimeOfDay(float dtime)
{
- // getTimeOfDaySpeed lock the value we need to prevent MT problems
- float day_speed = getTimeOfDaySpeed();
+ MutexAutoLock(this->m_time_lock);
m_time_counter += dtime;
- f32 speed = day_speed * 24000./(24.*3600);
- u32 units = (u32)(m_time_counter*speed);
+ f32 speed = m_time_of_day_speed * 24000. / (24. * 3600);
+ u32 units = (u32)(m_time_counter * speed);
bool sync_f = false;
- if(units > 0){
+ if (units > 0) {
// Sync at overflow
- if(m_time_of_day + units >= 24000)
+ if (m_time_of_day + units >= 24000)
sync_f = true;
m_time_of_day = (m_time_of_day + units) % 24000;
- if(sync_f)
+ if (sync_f)
m_time_of_day_f = (float)m_time_of_day / 24000.0;
}
if (speed > 0) {
m_time_counter -= (f32)units / speed;
}
- if(!sync_f){
- m_time_of_day_f += day_speed/24/3600*dtime;
- if(m_time_of_day_f > 1.0)
+ if (!sync_f) {
+ m_time_of_day_f += m_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)
+ if (m_time_of_day_f < 0.0)
m_time_of_day_f += 1.0;
}
}
protected:
// peer_ids in here should be unique, except that there may be many 0s
std::vector<Player*> m_players;
+
+
+ /*
+ * Below: values under m_time_lock
+ */
// Time of day in milli-hours (0-23999); determines day and night
u32 m_time_of_day;
// Time of day in 0...1
// Overriding the day-night ratio is useful for custom sky visuals
bool m_enable_day_night_ratio_override;
u32 m_day_night_ratio_override;
+ /*
+ * Above: values under m_time_lock
+ */
/* TODO: Add a callback function so these can be updated when a setting
* changes. At this point in time it doesn't matter (e.g. /set
bool m_cache_enable_shaders;
private:
- Mutex m_timeofday_lock;
Mutex m_time_lock;
};
void Send(NetworkPacket* pkt);
- // Environment must be locked when called
+ // Both setter and getter need no envlock,
+ // can be called freely from threads
void setTimeOfDay(u32 time);
+ inline u32 getTimeOfDay();
/*
Shall be called with the environment locked.