diff --git a/library/Core.cpp b/library/Core.cpp index 032e2b0be..1d4f52a56 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -1459,12 +1459,9 @@ void Core::fatal (std::string output) con.print("\n"); } fprintf(stderr, "%s\n", out.str().c_str()); -#ifndef LINUX_BUILD - out << "Check file stderr.log for details\n"; - MessageBox(0,out.str().c_str(),"DFHack error!", MB_OK | MB_ICONERROR); -#else + out << "Check file stderr.log for details.\n"; std::cout << "DFHack fatal error: " << out.str() << std::endl; -#endif + DFSDL::DFSDL_ShowSimpleMessageBox(0x10 /* SDL_MESSAGEBOX_ERROR */, "DFHack error!", out.str().c_str(), NULL); bool is_headless = bool(getenv("DFHACK_HEADLESS")); if (is_headless) @@ -1506,6 +1503,12 @@ bool Core::InitMainThread() { std::cerr << "DFHack build: " << Version::git_description() << "\n" << "Starting with working directory: " << Filesystem::getcwd() << std::endl; + std::cerr << "Binding to SDL.\n"; + if (!DFSDL::init(con)) { + fatal("cannot bind SDL libraries"); + return false; + } + // find out what we are... #ifdef LINUX_BUILD const char * path = "hack/symbols.xml"; @@ -1692,11 +1695,6 @@ bool Core::InitSimulationThread() return false; } - std::cerr << "Binding to SDL.\n"; - if (!DFSDL::init(con)) { - fatal("cannot bind SDL libraries"); - return false; - } if (DFSteam::init(con)) { std::cerr << "Found Steam.\n"; DFSteam::launchSteamDFHackIfNecessary(con); diff --git a/library/include/modules/DFSDL.h b/library/include/modules/DFSDL.h index b70255ec8..c96147dfb 100644 --- a/library/include/modules/DFSDL.h +++ b/library/include/modules/DFSDL.h @@ -6,6 +6,7 @@ struct SDL_Surface; struct SDL_Rect; struct SDL_PixelFormat; +struct SDL_Window; union SDL_Event; namespace DFHack @@ -50,6 +51,7 @@ DFHACK_EXPORT int DFSDL_PushEvent(SDL_Event *event); DFHACK_EXPORT void DFSDL_free(void *ptr); DFHACK_EXPORT SDL_PixelFormat* DFSDL_AllocFormat(uint32_t pixel_format); DFHACK_EXPORT SDL_Surface* DFSDL_CreateRGBSurfaceWithFormat(uint32_t flags, int width, int height, int depth, uint32_t format); +DFHACK_EXPORT int DFSDL_ShowSimpleMessageBox(uint32_t flags, const char *title, const char *message, SDL_Window *window); // submitted and returned text is UTF-8 // see wrapper functions below for cp-437 variants diff --git a/library/modules/DFSDL.cpp b/library/modules/DFSDL.cpp index 398a9c8b2..dec43a1c5 100644 --- a/library/modules/DFSDL.cpp +++ b/library/modules/DFSDL.cpp @@ -43,6 +43,7 @@ char * (*g_SDL_GetClipboardText)(); void (*g_SDL_free)(void *); SDL_PixelFormat* (*g_SDL_AllocFormat)(uint32_t pixel_format) = nullptr; SDL_Surface* (*g_SDL_CreateRGBSurfaceWithFormat)(uint32_t flags, int width, int height, int depth, uint32_t format) = nullptr; +int (*g_SDL_ShowSimpleMessageBox)(uint32_t flags, const char *title, const char *message, SDL_Window *window) = nullptr; bool DFSDL::init(color_ostream &out) { for (auto &lib_str : SDL_LIBS) { @@ -85,6 +86,7 @@ bool DFSDL::init(color_ostream &out) { bind(g_sdl_handle, SDL_free); bind(g_sdl_handle, SDL_AllocFormat); bind(g_sdl_handle, SDL_CreateRGBSurfaceWithFormat); + bind(g_sdl_handle, SDL_ShowSimpleMessageBox); #undef bind DEBUG(dfsdl,out).print("sdl successfully loaded\n"); @@ -159,6 +161,11 @@ SDL_Surface* DFSDL::DFSDL_CreateRGBSurfaceWithFormat(uint32_t flags, int width, return g_SDL_CreateRGBSurfaceWithFormat(flags, width, height, depth, format); } +int DFSDL::DFSDL_ShowSimpleMessageBox(uint32_t flags, const char *title, const char *message, SDL_Window *window) { + if (!g_SDL_ShowSimpleMessageBox) + return -1; + return g_SDL_ShowSimpleMessageBox(flags, title, message, window); +} DFHACK_EXPORT std::string DFHack::getClipboardTextCp437() { if (!g_sdl_handle || g_SDL_HasClipboardText() != SDL_TRUE) diff --git a/plugins/remotefortressreader/remotefortressreader.cpp b/plugins/remotefortressreader/remotefortressreader.cpp index 6b5733970..1570a0e60 100644 --- a/plugins/remotefortressreader/remotefortressreader.cpp +++ b/plugins/remotefortressreader/remotefortressreader.cpp @@ -130,7 +130,6 @@ using namespace DFHack; using namespace df::enums; using namespace RemoteFortressReader; -using namespace std; DFHACK_PLUGIN("RemoteFortressReader"); @@ -193,7 +192,7 @@ const char* growth_locations[] = { #include "df/art_image.h" #include "df/art_image_chunk.h" #include "df/art_image_ref.h" -command_result loadArtImageChunk(color_ostream &out, vector & parameters) +command_result loadArtImageChunk(color_ostream &out, std::vector & parameters) { if (parameters.size() != 1) return CR_WRONG_USAGE; @@ -214,7 +213,7 @@ command_result loadArtImageChunk(color_ostream &out, vector & parameter return CR_OK; } -command_result RemoteFortressReader_version(color_ostream &out, vector ¶meters) +command_result RemoteFortressReader_version(color_ostream &out, std::vector ¶meters) { out.print(RFR_VERSION); return CR_OK; @@ -645,7 +644,7 @@ void CopyMat(RemoteFortressReader::MatPair * mat, int type, int index) } -map hashes; +std::map hashes; bool IsTiletypeChanged(DFCoord pos) { @@ -663,7 +662,7 @@ bool IsTiletypeChanged(DFCoord pos) return false; } -map waterHashes; +std::map waterHashes; bool IsDesignationChanged(DFCoord pos) { @@ -681,7 +680,7 @@ bool IsDesignationChanged(DFCoord pos) return false; } -map buildingHashes; +std::map buildingHashes; bool IsBuildingChanged(DFCoord pos) { @@ -700,7 +699,7 @@ bool IsBuildingChanged(DFCoord pos) return changed; } -map spatterHashes; +std::map spatterHashes; bool IsspatterChanged(DFCoord pos) { @@ -737,7 +736,7 @@ bool IsspatterChanged(DFCoord pos) return false; } -map itemHashes; +std::map itemHashes; bool isItemChanged(int i) { @@ -755,7 +754,7 @@ bool isItemChanged(int i) return false; } -bool areItemsChanged(vector * items) +bool areItemsChanged(std::vector * items) { bool result = false; for (size_t i = 0; i < items->size(); i++) @@ -766,7 +765,7 @@ bool areItemsChanged(vector * items) return result; } -map engravingHashes; +std::map engravingHashes; bool isEngravingNew(int index) {