mirror of
https://github.com/moparisthebest/minetest
synced 2024-11-13 21:05:10 -05:00
ASyncRunStep doesn't need to lock when do setTimeOfDaySpeed.
* setTimeOfDaySpeed already lock a mutex when modify the value, we don't need to lock all environment. * add a fine grain lock for getTimeOfDay and setTimeOfDay to solve environment multithread modifications on this value
This commit is contained in:
parent
1b2f64473e
commit
7f8f9785d7
@ -203,24 +203,42 @@ u32 Environment::getDayNightRatio()
|
|||||||
|
|
||||||
void Environment::setTimeOfDaySpeed(float speed)
|
void Environment::setTimeOfDaySpeed(float speed)
|
||||||
{
|
{
|
||||||
JMutexAutoLock(this->m_lock);
|
JMutexAutoLock(this->m_timeofday_lock);
|
||||||
m_time_of_day_speed = speed;
|
m_time_of_day_speed = speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Environment::getTimeOfDaySpeed()
|
float Environment::getTimeOfDaySpeed()
|
||||||
{
|
{
|
||||||
JMutexAutoLock(this->m_lock);
|
JMutexAutoLock(this->m_timeofday_lock);
|
||||||
float retval = m_time_of_day_speed;
|
float retval = m_time_of_day_speed;
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Environment::setTimeOfDay(u32 time)
|
||||||
|
{
|
||||||
|
JMutexAutoLock(this->m_time_lock);
|
||||||
|
m_time_of_day = time;
|
||||||
|
m_time_of_day_f = (float)time / 24000.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 Environment::getTimeOfDay()
|
||||||
|
{
|
||||||
|
JMutexAutoLock(this->m_time_lock);
|
||||||
|
u32 retval = m_time_of_day;
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Environment::getTimeOfDayF()
|
||||||
|
{
|
||||||
|
JMutexAutoLock(this->m_time_lock);
|
||||||
|
float retval = m_time_of_day_f;
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
void Environment::stepTimeOfDay(float dtime)
|
void Environment::stepTimeOfDay(float dtime)
|
||||||
{
|
{
|
||||||
float day_speed = 0;
|
// getTimeOfDaySpeed lock the value we need to prevent MT problems
|
||||||
{
|
float day_speed = getTimeOfDaySpeed();
|
||||||
JMutexAutoLock(this->m_lock);
|
|
||||||
day_speed = m_time_of_day_speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_time_counter += dtime;
|
m_time_counter += dtime;
|
||||||
f32 speed = day_speed * 24000./(24.*3600);
|
f32 speed = day_speed * 24000./(24.*3600);
|
||||||
|
@ -81,22 +81,13 @@ public:
|
|||||||
u32 getDayNightRatio();
|
u32 getDayNightRatio();
|
||||||
|
|
||||||
// 0-23999
|
// 0-23999
|
||||||
virtual void setTimeOfDay(u32 time)
|
virtual void setTimeOfDay(u32 time);
|
||||||
{
|
u32 getTimeOfDay();
|
||||||
m_time_of_day = time;
|
float getTimeOfDayF();
|
||||||
m_time_of_day_f = (float)time / 24000.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 getTimeOfDay()
|
|
||||||
{ return m_time_of_day; }
|
|
||||||
|
|
||||||
float getTimeOfDayF()
|
|
||||||
{ return m_time_of_day_f; }
|
|
||||||
|
|
||||||
void stepTimeOfDay(float dtime);
|
void stepTimeOfDay(float dtime);
|
||||||
|
|
||||||
void setTimeOfDaySpeed(float speed);
|
void setTimeOfDaySpeed(float speed);
|
||||||
|
|
||||||
float getTimeOfDaySpeed();
|
float getTimeOfDaySpeed();
|
||||||
|
|
||||||
void setDayNightRatioOverride(bool enable, u32 value)
|
void setDayNightRatioOverride(bool enable, u32 value)
|
||||||
@ -134,7 +125,8 @@ protected:
|
|||||||
bool m_cache_enable_shaders;
|
bool m_cache_enable_shaders;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JMutex m_lock;
|
JMutex m_timeofday_lock;
|
||||||
|
JMutex m_time_lock;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -535,9 +535,6 @@ void Server::AsyncRunStep(bool initial_step)
|
|||||||
/*
|
/*
|
||||||
Update time of day and overall game time
|
Update time of day and overall game time
|
||||||
*/
|
*/
|
||||||
{
|
|
||||||
JMutexAutoLock envlock(m_env_mutex);
|
|
||||||
|
|
||||||
m_env->setTimeOfDaySpeed(g_settings->getFloat("time_speed"));
|
m_env->setTimeOfDaySpeed(g_settings->getFloat("time_speed"));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -545,14 +542,12 @@ void Server::AsyncRunStep(bool initial_step)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
m_time_of_day_send_timer -= dtime;
|
m_time_of_day_send_timer -= dtime;
|
||||||
if(m_time_of_day_send_timer < 0.0)
|
if(m_time_of_day_send_timer < 0.0) {
|
||||||
{
|
|
||||||
m_time_of_day_send_timer = g_settings->getFloat("time_send_interval");
|
m_time_of_day_send_timer = g_settings->getFloat("time_send_interval");
|
||||||
u16 time = m_env->getTimeOfDay();
|
u16 time = m_env->getTimeOfDay();
|
||||||
float time_speed = g_settings->getFloat("time_speed");
|
float time_speed = g_settings->getFloat("time_speed");
|
||||||
SendTimeOfDay(PEER_ID_INEXISTENT, time, time_speed);
|
SendTimeOfDay(PEER_ID_INEXISTENT, time, time_speed);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
JMutexAutoLock lock(m_env_mutex);
|
JMutexAutoLock lock(m_env_mutex);
|
||||||
|
Loading…
Reference in New Issue
Block a user