EventManager: first draft.

develop
expwnent 2012-12-14 21:05:38 -05:00
parent 0c70a448d0
commit 747723187f
6 changed files with 41 additions and 3 deletions

@ -111,6 +111,7 @@ include/modules/Burrows.h
include/modules/Constructions.h
include/modules/Units.h
include/modules/Engravings.h
include/modules/EventManager.h
include/modules/Gui.h
include/modules/Items.h
include/modules/Job.h
@ -133,6 +134,7 @@ modules/Burrows.cpp
modules/Constructions.cpp
modules/Units.cpp
modules/Engravings.cpp
modules/EventManager.cpp
modules/Gui.cpp
modules/Items.cpp
modules/Job.cpp

@ -44,6 +44,7 @@ using namespace std;
#include "VersionInfo.h"
#include "PluginManager.h"
#include "ModuleFactory.h"
#include "modules/EventManager.h"
#include "modules/Gui.h"
#include "modules/World.h"
#include "modules/Graphic.h"
@ -1238,6 +1239,8 @@ static int buildings_timer = 0;
void Core::onUpdate(color_ostream &out)
{
EventManager::manageEvents(out);
// convert building reagents
if (buildings_do_onupdate && (++buildings_timer & 1))
buildings_onUpdate(out);

@ -47,7 +47,7 @@ namespace DFHack
{
namespace Job {
// Duplicate the job structure. It is not linked into any DF lists.
DFHACK_EXPORT df::job *cloneJobStruct(df::job *job);
DFHACK_EXPORT df::job *cloneJobStruct(df::job *job, bool keepWorkerData=false);
// Delete a cloned structure.
DFHACK_EXPORT void deleteJobStruct(df::job *job);

@ -54,7 +54,7 @@ using namespace std;
using namespace DFHack;
using namespace df::enums;
df::job *DFHack::Job::cloneJobStruct(df::job *job)
df::job *DFHack::Job::cloneJobStruct(df::job *job, bool keepWorkerData)
{
CHECK_NULL_POINTER(job);
@ -75,7 +75,7 @@ df::job *DFHack::Job::cloneJobStruct(df::job *job)
{
df::general_ref *ref = pnew->references[i];
if (virtual_cast<df::general_ref_unit_workerst>(ref))
if (!keepWorkerData && virtual_cast<df::general_ref_unit_workerst>(ref))
vector_erase_at(pnew->references, i);
else
pnew->references[i] = ref->clone();

@ -130,6 +130,7 @@ if (BUILD_SUPPORTED)
#DFHACK_PLUGIN(versionosd versionosd.cpp)
DFHACK_PLUGIN(misery misery.cpp)
#DFHACK_PLUGIN(dfstream dfstream.cpp LINK_LIBRARIES clsocket dfhack-tinythread)
DFHACK_PLUGIN(eventExample eventExample.cpp)
endif()

@ -0,0 +1,32 @@
#include "Console.h"
#include "Core.h"
#include "Export.h"
#include "modules/EventManager.h"
#include "DataDefs.h"
using namespace DFHack;
DFHACK_PLUGIN("eventExample");
void jobInitiated(color_ostream& out, void* job);
void jobCompleted(color_ostream& out, void* job);
DFhackCExport command_result plugin_init(color_ostream &out, std::vector<PluginCommand> &commands) {
EventManager::EventHandler initiateHandler(jobInitiated);
EventManager::EventHandler completeHandler(jobCompleted);
EventManager::registerListener(EventManager::EventType::JOB_INITIATED, initiateHandler, NULL);
EventManager::registerListener(EventManager::EventType::JOB_COMPLETED, completeHandler, NULL);
return CR_OK;
}
void jobInitiated(color_ostream& out, void* job) {
out.print("Job initiated! 0x%X\n", job);
}
void jobCompleted(color_ostream& out, void* job) {
out.print("Job completed! 0x%X\n", job);
}