Skip to content

Commit bdae773

Browse files
authored
Merge branch 'DFHack:develop' into modernizecore
2 parents f9fae13 + 004b4dd commit bdae773

2 files changed

Lines changed: 18 additions & 33 deletions

File tree

library/Core.cpp

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ using std::string;
104104

105105
// FIXME: A lot of code in one file, all doing different things... there's something fishy about it.
106106

107-
static bool parseKeySpec(std::string keyspec, int *psym, int *pmod, std::string *pfocus = NULL);
107+
static bool parseKeySpec(std::string keyspec, int *psym, int *pmod, std::string *pfocus = nullptr);
108108
size_t loadScriptFiles(Core* core, color_ostream& out, const std::vector<std::string>& prefix, const std::filesystem::path& folder);
109109

110110
namespace DFHack {
@@ -211,7 +211,7 @@ thread_local int CommandDepthCounter::depth = 0;
211211

212212
void Core::cheap_tokenise(std::string const& input, std::vector<std::string>& output)
213213
{
214-
std::string *cur = NULL;
214+
std::string *cur = nullptr;
215215
size_t i = 0;
216216

217217
// Check the first non-space character
@@ -242,7 +242,7 @@ void Core::cheap_tokenise(std::string const& input, std::vector<std::string>& ou
242242
{
243243
unsigned char c = input[i];
244244
if (isspace(c)) {
245-
cur = NULL;
245+
cur = nullptr;
246246
} else {
247247
if (!cur) {
248248
output.push_back("");
@@ -281,7 +281,7 @@ static void fHKthread(IODATA * iodata)
281281
{
282282
Core * core = iodata->core;
283283
PluginManager * plug_mgr = iodata->plug_mgr;
284-
if(plug_mgr == 0 || core == 0)
284+
if(!plug_mgr || !core)
285285
{
286286
std::cerr << "Hotkey thread has croaked." << std::endl;
287287
return;
@@ -302,21 +302,6 @@ static void fHKthread(IODATA * iodata)
302302
}
303303
}
304304

305-
struct sortable
306-
{
307-
bool recolor;
308-
std::string name;
309-
std::string description;
310-
//FIXME: Nuke when MSVC stops failing at being C++11 compliant
311-
sortable(bool recolor_,const std::string& name_,const std::string & description_): recolor(recolor_), name(name_), description(description_){};
312-
bool operator <(const sortable & rhs) const
313-
{
314-
if( name < rhs.name )
315-
return true;
316-
return false;
317-
};
318-
};
319-
320305
static std::string dfhack_version_desc()
321306
{
322307
std::stringstream s;
@@ -1435,7 +1420,7 @@ static void fIOthread(IODATA * iod)
14351420
main_history.load(HISTORY_FILE.c_str());
14361421

14371422
Console & con = core->getConsole();
1438-
if (plug_mgr == 0)
1423+
if (plug_mgr == nullptr)
14391424
{
14401425
con.printerr("Something horrible happened in Core's constructor...\n");
14411426
return;
@@ -1507,18 +1492,18 @@ Core::Core() :
15071492
toolCount{0}
15081493
{
15091494
// init the console. This must be always the first step!
1510-
plug_mgr = 0;
1495+
plug_mgr = nullptr;
15111496
errorstate = false;
15121497
vinfo = 0;
15131498
memset(&(s_mods), 0, sizeof(s_mods));
15141499

15151500
// set up hotkey capture
15161501
suppress_duplicate_keyboard_events = true;
15171502
hotkey_set = NO;
1518-
last_world_data_ptr = NULL;
1519-
last_local_map_ptr = NULL;
1503+
last_world_data_ptr = nullptr;
1504+
last_local_map_ptr = nullptr;
15201505
last_pause_state = false;
1521-
top_viewscreen = NULL;
1506+
top_viewscreen = nullptr;
15221507

15231508
color_ostream::log_errors_to_stderr = true;
15241509
};
@@ -1542,7 +1527,7 @@ void Core::fatal (std::string output, const char * title)
15421527
std::cout << "DFHack fatal error: " << out.str() << std::endl;
15431528
if (!title)
15441529
title = "DFHack error!";
1545-
DFSDL::DFSDL_ShowSimpleMessageBox(0x10 /* SDL_MESSAGEBOX_ERROR */, title, out.str().c_str(), NULL);
1530+
DFSDL::DFSDL_ShowSimpleMessageBox(0x10 /* SDL_MESSAGEBOX_ERROR */, title, out.str().c_str(), nullptr);
15461531

15471532
bool is_headless = bool(getenv("DFHACK_HEADLESS"));
15481533
if (is_headless)
@@ -2015,7 +2000,7 @@ void Core::doUpdate(color_ostream &out)
20152000
Lua::Core::Reset(out, "DF code execution");
20162001

20172002
// find the current viewscreen
2018-
df::viewscreen *screen = NULL;
2003+
df::viewscreen *screen = nullptr;
20192004
if (df::global::gview)
20202005
{
20212006
screen = &df::global::gview->view;
@@ -2242,7 +2227,7 @@ namespace DFHack {
22422227
}
22432228

22442229
void Core::handleLoadAndUnloadScripts(color_ostream& out, state_change_event event) {
2245-
static const X::InitVariationTable table = X::getTable(X::computeInitVariationTable(0,
2230+
static const X::InitVariationTable table = X::getTable(X::computeInitVariationTable(nullptr,
22462231
(int)SC_WORLD_LOADED, "onLoad", "onLoadWorld", "onWorldLoaded", "",
22472232
(int)SC_WORLD_UNLOADED, "onUnload", "onUnloadWorld", "onWorldUnloaded", "",
22482233
(int)SC_MAP_LOADED, "onMapLoad", "onLoadMap", "",
@@ -2342,7 +2327,7 @@ void Core::onStateChange(color_ostream &out, state_change_event event)
23422327
else
23432328
{
23442329
char timebuf[30];
2345-
time_t rawtime = time(NULL);
2330+
time_t rawtime = time(nullptr);
23462331
struct tm * timeinfo = localtime(&rawtime);
23472332
strftime(timebuf, sizeof(timebuf), "[%Y-%m-%dT%H:%M:%S%z] ", timeinfo);
23482333
evtlog << timebuf;
@@ -2428,7 +2413,7 @@ int Core::Shutdown ( void )
24282413
if(plug_mgr)
24292414
{
24302415
delete plug_mgr;
2431-
plug_mgr = 0;
2416+
plug_mgr = nullptr;
24322417
}
24332418
// invalidate all modules
24342419
allModules.clear();
@@ -3009,7 +2994,7 @@ bool Process::patchMemory(void *target, const void* src, size_t count)
30092994
#define MODULE_GETTER(TYPE) \
30102995
TYPE * Core::get##TYPE() \
30112996
{ \
3012-
if(errorstate) return NULL;\
2997+
if(errorstate) return nullptr;\
30132998
if(!s_mods.p##TYPE)\
30142999
{\
30153000
std::unique_ptr<Module> mod = create##TYPE();\

library/include/Core.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ namespace DFHack
200200

201201
std::filesystem::path getHackPath();
202202

203-
bool isWorldLoaded() { return (last_world_data_ptr != NULL); }
204-
bool isMapLoaded() { return (last_local_map_ptr != NULL && last_world_data_ptr != NULL); }
203+
bool isWorldLoaded() { return (last_world_data_ptr != nullptr); }
204+
bool isMapLoaded() { return (last_local_map_ptr != nullptr && last_world_data_ptr != nullptr); }
205205

206206
static df::viewscreen *getTopViewscreen();
207207

@@ -252,7 +252,7 @@ namespace DFHack
252252
void operator=(Core const&); // Don't implement
253253

254254
// report error to user while failing
255-
void fatal (std::string output, const char * title = NULL);
255+
void fatal (std::string output, const char * title = nullptr);
256256

257257
// 1 = fatal failure
258258
bool errorstate;

0 commit comments

Comments
 (0)