diff --git a/library/Core.cpp b/library/Core.cpp index e06dd3f3c..4550fe25e 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -651,7 +651,7 @@ bool Core::Init() // initialize data defs virtual_identity::Init(this); - InitDataDefGlobals(this); + df::global::InitGlobals(); // create mutex for syncing with interactive tasks StackMutex = new mutex(); diff --git a/library/DataDefs.cpp b/library/DataDefs.cpp index cd8a8ed7c..d328d7a17 100644 --- a/library/DataDefs.cpp +++ b/library/DataDefs.cpp @@ -206,22 +206,3 @@ int DFHack::findBitfieldField(const std::string &name, int size, const bitfield_ return -1; } - -#define SIMPLE_GLOBAL(name,tname) \ - tname *df::global::name = NULL; -#define GLOBAL(name,tname) SIMPLE_GLOBAL(name,df::tname) -DF_KNOWN_GLOBALS -#undef GLOBAL -#undef SIMPLE_GLOBAL - -void DFHack::InitDataDefGlobals(Core *core) { - OffsetGroup *global_table = core->vinfo->getGroup("global"); - void * tmp; - -#define SIMPLE_GLOBAL(name,tname) \ - if (global_table->getSafeAddress(#name,tmp)) df::global::name = (tname*)tmp; -#define GLOBAL(name,tname) SIMPLE_GLOBAL(name,df::tname) -DF_KNOWN_GLOBALS -#undef GLOBAL -#undef SIMPLE_GLOBAL -} diff --git a/library/DataStatics.cpp b/library/DataStatics.cpp index f47c0fe05..63eb596e1 100644 --- a/library/DataStatics.cpp +++ b/library/DataStatics.cpp @@ -1,6 +1,7 @@ #include "Internal.h" #include "DataDefs.h" #include "MiscUtils.h" +#include "VersionInfo.h" #include "df/world.h" #include "df/world_data.h" @@ -13,6 +14,13 @@ namespace { inline T &_toref(T *&p) { return *p; } } +#define INIT_GLOBAL_FUNCTION_PREFIX \ + DFHack::OffsetGroup *global_table_ = DFHack::Core::getInstance().vinfo->getGroup("global"); \ + void * tmp_; + +#define INIT_GLOBAL_FUNCTION_ITEM(type,name) \ + if (global_table_->getSafeAddress(#name,tmp_)) name = (type*)tmp_; + // Instantiate all the static objects #include "df/static.inc" #include "df/static.enums.inc" diff --git a/library/include/DataDefs.h b/library/include/DataDefs.h index 1e72e9a1f..7ef64ef5e 100644 --- a/library/include/DataDefs.h +++ b/library/include/DataDefs.h @@ -237,38 +237,8 @@ namespace df #define FOR_ENUM_ITEMS(enum,iter) \ for(df::enum iter = ENUM_FIRST_ITEM(enum); iter <= ENUM_LAST_ITEM(enum); iter = df::enum(1+int(iter))) -namespace df { -#define DF_KNOWN_GLOBALS \ - GLOBAL(cursor,cursor) \ - GLOBAL(selection_rect,selection_rect) \ - GLOBAL(world,world) \ - GLOBAL(ui,ui) \ - GLOBAL(gview,interface) \ - GLOBAL(init,init) \ - GLOBAL(d_init,d_init) \ - SIMPLE_GLOBAL(job_next_id,int) \ - SIMPLE_GLOBAL(ui_look_cursor,int) \ - SIMPLE_GLOBAL(ui_workshop_job_cursor,int) \ - SIMPLE_GLOBAL(ui_building_item_cursor,int) \ - SIMPLE_GLOBAL(ui_workshop_in_add,bool) \ - SIMPLE_GLOBAL(ui_selected_unit,int) \ - SIMPLE_GLOBAL(cur_year,int) \ - SIMPLE_GLOBAL(cur_year_tick,int) \ - GLOBAL(ui_sidebar_menus,ui_sidebar_menus) \ - GLOBAL(ui_build_selector,ui_build_selector) \ - GLOBAL(ui_look_list,ui_look_list) \ - GLOBAL(ui_unit_view_mode, ui_unit_view_mode) \ - GLOBAL(gps, graphic) \ - - -#define SIMPLE_GLOBAL(name,tname) \ - namespace global { extern DFHACK_EXPORT tname *name; } -#define GLOBAL(name,tname) \ - struct tname; SIMPLE_GLOBAL(name,tname) -DF_KNOWN_GLOBALS -#undef GLOBAL -#undef SIMPLE_GLOBAL -} +// Global object pointers +#include "df/global_objects.h" // A couple of headers that have to be included at once #include "df/coord2d.h" diff --git a/library/xml b/library/xml index 032d4fea9..3b20ecfbf 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 032d4fea9c6b821d258c8a413e56efe274d9572c +Subproject commit 3b20ecfbfcb7b801dbe83b1c22f183ca6085af9e