EventManager: fixed a problem with constructionHandler.

develop
expwnent 2013-10-20 14:14:02 -04:00
parent 82c9ca3ce2
commit 39553cfb6d
3 changed files with 43 additions and 9 deletions

@ -7,6 +7,9 @@
#include "ColorText.h"
#include "PluginManager.h"
#include "Console.h"
#include "DataDefs.h"
#include <df/coord.h>
namespace DFHack {
namespace EventManager {
@ -63,4 +66,18 @@ namespace DFHack {
}
}
namespace std {
template <>
struct hash<df::coord> {
std::size_t operator()(const df::coord& c) const {
size_t r = 17;
const size_t m = 65537;
r = m*(r+c.x);
r = m*(r+c.y);
r = m*(r+c.z);
return r;
}
};
}
#endif

@ -151,7 +151,7 @@ static int32_t nextBuilding;
static unordered_set<int32_t> buildings;
//construction
static unordered_set<df::construction*> constructions;
static unordered_map<df::coord, df::construction> constructions;
static bool gameLoaded;
//invasion
@ -510,28 +510,35 @@ static void manageConstructionEvent(color_ostream& out) {
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());
unordered_set<df::coord> toDelete;
for ( auto a = constructions.begin(); a != constructions.end(); a++ ) {
df::construction* construction = *a;
if ( constructionsNow.find(construction) != constructionsNow.end() )
df::construction& construction = (*a).second;
if ( df::construction::find(construction.pos) != NULL )
continue;
//construction removed
toDelete.insert((*a).first);
for ( auto b = copy.begin(); b != copy.end(); b++ ) {
EventHandler handle = (*b).second;
handle.eventHandler(out, (void*)construction);
handle.eventHandler(out, (void*)&construction);
}
}
for ( auto a = toDelete.begin(); a != toDelete.end(); a++ ) {
constructions.erase(*a);
}
for ( auto a = constructionsNow.begin(); a != constructionsNow.end(); a++ ) {
df::construction* construction = *a;
if ( constructions.find(construction) != constructions.end() )
bool b = constructions.find(construction->pos) != constructions.end();
constructions[construction->pos] = *construction;
if ( b )
continue;
//construction created
for ( auto b = copy.begin(); b != copy.end(); b++ ) {
EventHandler handle = (*b).second;
handle.eventHandler(out, (void*)construction);
}
}
constructions.clear();
constructions.insert(constructionsNow.begin(), constructionsNow.end());
}
static void manageSyndromeEvent(color_ostream& out) {

@ -6,6 +6,8 @@
#include "modules/EventManager.h"
#include "DataDefs.h"
#include "df/construction.h"
#include "df/coord.h"
#include "df/item.h"
#include "df/job.h"
#include "df/world.h"
@ -105,6 +107,14 @@ void building(color_ostream& out, void* ptr) {
void construction(color_ostream& out, void* ptr) {
out.print("Construction created/destroyed: 0x%X\n", ptr);
df::construction* constr = (df::construction*)ptr;
df::coord pos = constr->pos;
out.print(" (%d,%d,%d)\n", pos.x, pos.y, pos.z);
if ( df::construction::find(pos) == NULL )
out.print(" construction destroyed\n");
else
out.print(" construction created\n");
}
void syndrome(color_ostream& out, void* ptr) {