Retypes the EventManager's constructions container

develop
Josh Cooper 2022-04-18 13:40:22 -07:00 committed by Myk
parent d6b2629cfc
commit ff2bd8d953
1 changed files with 23 additions and 22 deletions

@ -210,7 +210,7 @@ static int32_t nextBuilding;
static unordered_set<int32_t> buildings; static unordered_set<int32_t> buildings;
//construction //construction
static unordered_map<df::coord, df::construction> constructions; static unordered_set<df::construction> constructions;
static bool gameLoaded; static bool gameLoaded;
//syndrome //syndrome
@ -306,7 +306,7 @@ void DFHack::EventManager::onStateChange(color_ostream& out, state_change_event
out.print("EventManager.onLoad null position of construction.\n"); out.print("EventManager.onLoad null position of construction.\n");
continue; continue;
} }
constructions[c->pos] = *c; constructions.emplace(*c);
} }
for (auto b : df::global::world->buildings.all) { for (auto b : df::global::world->buildings.all) {
Buildings::updateBuildings(out, (void*)intptr_t(b->id)); Buildings::updateBuildings(out, (void*)intptr_t(b->id));
@ -714,33 +714,34 @@ static void manageConstructionEvent(color_ostream& out) {
return; return;
//unordered_set<df::construction*> constructionsNow(df::global::world->constructions.begin(), df::global::world->constructions.end()); //unordered_set<df::construction*> constructionsNow(df::global::world->constructions.begin(), df::global::world->constructions.end());
multimap<Plugin*,EventHandler> copy(handlers[EventType::CONSTRUCTION].begin(), handlers[EventType::CONSTRUCTION].end()); multimap<Plugin*, EventHandler> copy(handlers[EventType::CONSTRUCTION].begin(), handlers[EventType::CONSTRUCTION].end());
for (auto iter = constructions.begin(); iter != constructions.end(); ) { // find & send construction removals
df::construction& construction = iter->second; for (auto iter = constructions.begin(); iter != constructions.end();) {
if ( df::construction::find(construction.pos) != nullptr ) { auto &construction = *iter;
// if we can't find it, it was removed
if (df::construction::find(construction.pos) != nullptr) {
++iter; ++iter;
continue; continue;
} }
//construction removed // send construction to handlers, because it was removed
//out.print("Removed construction (%d,%d,%d)\n", construction.pos.x,construction.pos.y,construction.pos.z); for (const auto &key_value: copy) {
for (auto &key_value : copy) { EventHandler handle = key_value.second;
EventHandler &handle = key_value.second; handle.eventHandler(out, (void*) &construction);
handle.eventHandler(out, (void*)&construction);
} }
// erase from existent constructions
iter = constructions.erase(iter); iter = constructions.erase(iter);
} }
//for ( auto a = constructionsNow.begin(); a != constructionsNow.end(); a++ ) { // find & send construction additions
for (auto construction : df::global::world->constructions) { for (auto c: df::global::world->constructions) {
if(constructions.count(construction->pos)) { auto &construction = *c;
continue; // add construction to constructions, if it isn't already present
} if (constructions.emplace(construction).second) {
constructions[construction->pos] = *construction; // send construction to handlers, because it is new
//construction created for (const auto &key_value: copy) {
//out.print("Created construction (%d,%d,%d)\n", construction->pos.x,construction->pos.y,construction->pos.z); EventHandler handle = key_value.second;
for (auto &key_value : copy) { handle.eventHandler(out, (void*) &construction);
EventHandler &handle = key_value.second; }
handle.eventHandler(out, (void*)construction);
} }
} }
} }