MCPcopy Create free account
hub / github.com/DFHack/dfhack / manageConstructionEvent

Function manageConstructionEvent

library/modules/EventManager.cpp:878–921  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

876}
877
878static void manageConstructionEvent(color_ostream& out) {
879 if (!df::global::world)
880 return;
881 //unordered_set<df::construction*> constructionsNow(df::global::world->event.constructions.begin(), df::global::world->event.constructions.end());
882
883 multimap<Plugin*, EventHandler> copy(handlers[EventType::CONSTRUCTION].begin(), handlers[EventType::CONSTRUCTION].end());
884
885 unordered_set<df::construction> next_construction_set; // will be swapped with constructions
886 next_construction_set.reserve(constructions.bucket_count());
887 vector<df::construction> new_constructions;
888
889 // find new constructions - swapping found constructions over from constructions to next_construction_set
890 for (auto c : df::global::world->event.constructions) {
891 auto &construction = *c;
892 auto it = constructions.find(construction);
893 if (it == constructions.end()) {
894 // handle new construction event later
895 new_constructions.emplace_back(construction);
896 }
897 else {
898 constructions.erase(it);
899 }
900 next_construction_set.emplace(construction);
901 }
902
903 constructions.swap(next_construction_set);
904
905 // now next_construction_set contains all the constructions that were removed (not found in df::global::world->event.constructions)
906 for (auto& construction : next_construction_set) {
907 // handle construction removed event
908 for (const auto &[_,handle]: copy) {
909 DEBUG(log,out).print("calling handler for destroyed construction event\n");
910 run_handler(out, EventType::CONSTRUCTION, handle, (void*) &construction);
911 }
912 }
913
914 // now handle all the new constructions
915 for (auto& construction : new_constructions) {
916 for (const auto &[_,handle]: copy) {
917 DEBUG(log,out).print("calling handler for created construction event\n");
918 run_handler(out, EventType::CONSTRUCTION, handle, (void*) &construction);
919 }
920 }
921}
922
923static void manageSyndromeEvent(color_ostream& out) {
924 if (!df::global::world)

Callers

nothing calls this directly

Calls 8

run_handlerFunction · 0.85
reserveMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
findMethod · 0.45
eraseMethod · 0.45
swapMethod · 0.45
printMethod · 0.45

Tested by

no test coverage detected