summaryrefslogtreecommitdiff
path: root/src/environment.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/environment.cpp')
-rw-r--r--src/environment.cpp42
1 files changed, 35 insertions, 7 deletions
diff --git a/src/environment.cpp b/src/environment.cpp
index 93649eed5..e713ab610 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -41,11 +41,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef SERVER
#include "clientmap.h"
#endif
+#include "daynightratio.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
Environment::Environment():
- m_time_of_day(9000)
+ m_time_of_day(9000),
+ m_time_of_day_f(9000./24000),
+ m_time_of_day_speed(0),
+ m_time_counter(0)
{
}
@@ -195,17 +199,35 @@ void Environment::printPlayers(std::ostream &o)
}
}
-/*void Environment::setDayNightRatio(u32 r)
-{
- getDayNightRatio() = r;
-}*/
-
u32 Environment::getDayNightRatio()
{
- //return getDayNightRatio();
return time_to_daynight_ratio(m_time_of_day);
}
+void Environment::stepTimeOfDay(float dtime)
+{
+ m_time_counter += dtime;
+ f32 speed = m_time_of_day_speed * 24000./(24.*3600);
+ u32 units = (u32)(m_time_counter*speed);
+ m_time_counter -= (f32)units / speed;
+ bool sync_f = false;
+ if(units > 0){
+ // Sync at overflow
+ if(m_time_of_day + units >= 24000)
+ sync_f = true;
+ m_time_of_day = (m_time_of_day + units) % 24000;
+ if(sync_f)
+ m_time_of_day_f = (float)m_time_of_day / 24000.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)
+ m_time_of_day_f += 1.0;
+ }
+}
+
/*
ABMWithState
*/
@@ -893,6 +915,9 @@ void ServerEnvironment::step(float dtime)
//TimeTaker timer("ServerEnv step");
+ /* Step time of day */
+ stepTimeOfDay(dtime);
+
/*
Increment game time
*/
@@ -1861,6 +1886,9 @@ void ClientEnvironment::step(float dtime)
{
DSTACK(__FUNCTION_NAME);
+ /* Step time of day */
+ stepTimeOfDay(dtime);
+
// Get some settings
bool free_move = g_settings->getBool("free_move");