- /* Handle ActiveBlockModifiers */
- abmhandler.apply(block, blocks_scanned, abms_run, blocks_cached);
- }
- g_profiler->avg("SEnv: active blocks", m_active_blocks.m_abm_list.size());
- g_profiler->avg("SEnv: active blocks cached", blocks_cached);
- g_profiler->avg("SEnv: active blocks scanned for ABMs", blocks_scanned);
- g_profiler->avg("SEnv: ABMs run", abms_run);
+ int blocks_scanned = 0;
+ int abms_run = 0;
+ int blocks_cached = 0;
+
+ std::vector<v3s16> output(m_active_blocks.m_abm_list.size());
+
+ // Shuffle the active blocks so that each block gets an equal chance
+ // of having its ABMs run.
+ std::copy(m_active_blocks.m_abm_list.begin(), m_active_blocks.m_abm_list.end(), output.begin());
+ std::shuffle(output.begin(), output.end(), m_rgen);
+
+ int i = 0;
+ // The time budget for ABMs is 20%.
+ u32 max_time_ms = m_cache_abm_interval * 1000 / 5;
+ for (const v3s16 &p : output) {
+ MapBlock *block = m_map->getBlockNoCreateNoEx(p);
+ if (!block)
+ continue;
+
+ i++;
+
+ // Set current time as timestamp
+ block->setTimestampNoChangedFlag(m_game_time);
+
+ /* Handle ActiveBlockModifiers */
+ abmhandler.apply(block, blocks_scanned, abms_run, blocks_cached);
+
+ u32 time_ms = timer.getTimerTime();