diff --git a/library/include/modules/EventManager.h b/library/include/modules/EventManager.h index f73977ab4f0..b5df573c714 100644 --- a/library/include/modules/EventManager.h +++ b/library/include/modules/EventManager.h @@ -44,8 +44,8 @@ namespace DFHack { struct EventHandler { typedef void (*callback_t)(color_ostream&, void*); //called when the event happens - callback_t eventHandler; - int32_t freq; //how often event is allowed to fire (in ticks) use 0 to always fire when possible + const callback_t eventHandler; + const int32_t freq; //how often event is allowed to fire (in ticks) use 0 to always fire when possible int32_t when = -1; //when to fire event (global tick count) EventHandler(callback_t eventHandlerIn, int32_t freqIn) : @@ -146,7 +146,6 @@ namespace std { size_t r = 17; const size_t m = 65537; r = m*(r+(intptr_t)h.eventHandler); - r = m*(r+h.when); r = m*(r+h.freq); return r; } diff --git a/library/modules/EventManager.cpp b/library/modules/EventManager.cpp index 32f08d39973..6606e3ea7a9 100644 --- a/library/modules/EventManager.cpp +++ b/library/modules/EventManager.cpp @@ -94,7 +94,7 @@ int32_t DFHack::EventManager::registerTick(EventHandler handler, int32_t when, P } } handler.when = when; - tickQueue.insert(pair(handler.when, handler)); + tickQueue.emplace(handler.when, handler); // we don't track this handler, this allows registerTick to retain the old behaviour of needing to re-register the tick event //handlers[EventType::TICK].insert(pair(plugin,handler)); // since the event isn't added to the handlers, we don't need to unregister these events diff --git a/plugins/devel/eventExample.cpp b/plugins/devel/eventExample.cpp index 8d03222c344..a20045a33d6 100644 --- a/plugins/devel/eventExample.cpp +++ b/plugins/devel/eventExample.cpp @@ -97,12 +97,12 @@ command_result eventExample(color_ostream& out, vector& parameters) { EventManager::registerTick(timeHandler, 4, plugin_self); EventManager::registerTick(timeHandler, 8, plugin_self); int32_t t = EventManager::registerTick(timeHandler, 16, plugin_self); - timeHandler.freq = t; + timeHandler.when = t; EventManager::unregister(EventManager::EventType::TICK, timeHandler, plugin_self); t = EventManager::registerTick(timeHandler, 32, plugin_self); t = EventManager::registerTick(timeHandler, 32, plugin_self); t = EventManager::registerTick(timeHandler, 32, plugin_self); - timeHandler.freq = t; + timeHandler.when = t; EventManager::unregister(EventManager::EventType::TICK, timeHandler, plugin_self); EventManager::unregister(EventManager::EventType::TICK, timeHandler, plugin_self);