Initialize ABM timer to random value to spread processing
authorPerttu Ahola <celeron55@gmail.com>
Mon, 2 Jan 2012 19:06:38 +0000 (21:06 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Mon, 2 Jan 2012 19:06:38 +0000 (21:06 +0200)
src/environment.cpp
src/environment.h

index 53a7fdf9befd938a3d947dfd1c0ec3c3f084311d..20ecaff14d1fd3b54fd1e48a710c7e5f82a53749 100644 (file)
@@ -203,6 +203,19 @@ u32 Environment::getDayNightRatio()
        return time_to_daynight_ratio(m_time_of_day);
 }
 
+/*
+       ABMWithState
+*/
+
+ABMWithState::ABMWithState(ActiveBlockModifier *abm_):
+       abm(abm_),
+       timer(0)
+{
+       // Initialize timer to random value to spread processing
+       float itv = abm->getTriggerInterval();
+       timer = myrand_range(-0.51*itv, 0.51*itv);
+}
+
 /*
        ActiveBlockList
 */
index f8df77f79cfa937b612f66dc58ec2d636d951433..beb49885c558bed51858189a5daba427fbb089a3 100644 (file)
@@ -129,10 +129,7 @@ struct ABMWithState
        ActiveBlockModifier *abm;
        float timer;
 
-       ABMWithState(ActiveBlockModifier *abm_):
-               abm(abm_),
-               timer(0)
-       {}
+       ABMWithState(ActiveBlockModifier *abm_);
 };
 
 /*