| 398 | }; |
| 399 | |
| 400 | void buildingplan_cycle(color_ostream &out, Tasks &tasks, |
| 401 | unordered_map<int32_t, PlannedBuilding> &planned_buildings, bool unsuspend_on_finalize) { |
| 402 | static const VectorsToScanLast vectors_to_scan_last; |
| 403 | |
| 404 | DEBUG(cycle,out).print( |
| 405 | "running buildingplan cycle for %zu registered buildings\n", |
| 406 | planned_buildings.size()); |
| 407 | |
| 408 | update_walkability_groups(); |
| 409 | |
| 410 | for (auto it = tasks.begin(); it != tasks.end(); ) { |
| 411 | auto vector_id = it->first; |
| 412 | // we could make this a set, but it's only a few elements |
| 413 | if (std::find(vectors_to_scan_last.vectors.begin(), |
| 414 | vectors_to_scan_last.vectors.end(), |
| 415 | vector_id) != vectors_to_scan_last.vectors.end()) { |
| 416 | ++it; |
| 417 | continue; |
| 418 | } |
| 419 | |
| 420 | auto & buckets = it->second; |
| 421 | doVector(out, vector_id, buckets, planned_buildings, unsuspend_on_finalize); |
| 422 | if (buckets.empty()) { |
| 423 | DEBUG(cycle,out).print("removing empty vector: {}; {} vector(s) left\n", |
| 424 | ENUM_KEY_STR(job_item_vector_id, vector_id), |
| 425 | tasks.size() - 1); |
| 426 | it = tasks.erase(it); |
| 427 | } |
| 428 | else |
| 429 | ++it; |
| 430 | } |
| 431 | for (auto vector_id : vectors_to_scan_last.vectors) { |
| 432 | if (tasks.count(vector_id) == 0) |
| 433 | continue; |
| 434 | auto & buckets = tasks[vector_id]; |
| 435 | doVector(out, vector_id, buckets, planned_buildings, unsuspend_on_finalize); |
| 436 | if (buckets.empty()) { |
| 437 | DEBUG(cycle,out).print("removing empty vector: {}; {} vector(s) left\n", |
| 438 | ENUM_KEY_STR(job_item_vector_id, vector_id), |
| 439 | tasks.size() - 1); |
| 440 | tasks.erase(vector_id); |
| 441 | } |
| 442 | } |
| 443 | DEBUG(cycle,out).print("cycle done; {} registered building(s) left\n", |
| 444 | planned_buildings.size()); |
| 445 | } |