| 407 | } |
| 408 | |
| 409 | void DFHack::EventManager::manageEvents(color_ostream& out) { |
| 410 | static const std::array<eventManager_t, EventType::EVENT_MAX> eventManager = compileManagerArray(); |
| 411 | if ( !gameLoaded ) { |
| 412 | return; |
| 413 | } |
| 414 | if (!df::global::world) |
| 415 | return; |
| 416 | |
| 417 | CoreSuspender suspender; |
| 418 | |
| 419 | int32_t tick = df::global::world->frame_counter; |
| 420 | TRACE(log,out).print("processing events at tick {}\n", tick); |
| 421 | |
| 422 | auto &core = Core::getInstance(); |
| 423 | auto &counters = core.perf_counters; |
| 424 | for ( size_t a = 0; a < EventType::EVENT_MAX; a++ ) { |
| 425 | if ( handlers[a].empty() ) |
| 426 | continue; |
| 427 | int32_t eventFrequency = -100; |
| 428 | if ( a != EventType::TICK ) |
| 429 | for (auto &[_,handle] : handlers[a]) { |
| 430 | if (handle.freq < eventFrequency || eventFrequency == -100 ) |
| 431 | eventFrequency = handle.freq; |
| 432 | } |
| 433 | else eventFrequency = 1; |
| 434 | |
| 435 | if ( tick >= eventLastTick[a] && tick - eventLastTick[a] < eventFrequency ) |
| 436 | continue; |
| 437 | |
| 438 | uint32_t start_ms = core.p->getTickCount(); |
| 439 | eventManager[a](out); |
| 440 | eventLastTick[a] = tick; |
| 441 | counters.incCounter(counters.event_manager_event_total_ms[a], start_ms); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | static void manageTickEvent(color_ostream& out) { |
| 446 | if (!df::global::world) |
nothing calls this directly
no test coverage detected