diff options
author | est31 <MTest31@outlook.com> | 2015-10-27 21:03:59 +0100 |
---|---|---|
committer | est31 <MTest31@outlook.com> | 2015-10-27 23:19:17 +0100 |
commit | ca8e56c15a26bc5f3d1dffe5fd39e1ca4b82d6f8 (patch) | |
tree | cc5d8627278d725f630e9df99b14a6b5964b4543 /src/environment.cpp | |
parent | c406438b95e3df181961add56a2511b96bd9d690 (diff) | |
download | minetest-ca8e56c15a26bc5f3d1dffe5fd39e1ca4b82d6f8.tar.gz minetest-ca8e56c15a26bc5f3d1dffe5fd39e1ca4b82d6f8.tar.bz2 minetest-ca8e56c15a26bc5f3d1dffe5fd39e1ca4b82d6f8.zip |
Environment: Time of day fixes and add serverside getter
-> Put access to time variables under the time lock.
-> Merge both time locks, there is no point to have two locks.
-> Fix the lock being released too early in Environment::setTimeOfDay
-> Add serverside getter so that you don't have to get
the environment if you only have the server
Diffstat (limited to 'src/environment.cpp')
-rw-r--r-- | src/environment.cpp | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/environment.cpp b/src/environment.cpp index 0b37212e5..c15fe795e 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -180,20 +180,21 @@ std::vector<Player*> Environment::getPlayers(bool ignore_disconnected) 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; } @@ -221,29 +222,28 @@ float Environment::getTimeOfDayF() 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; } } |