From f7478422a408dc3f30a41f3d8095af573e747edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Sun, 15 Jan 2023 07:41:32 +0100 Subject: [PATCH] Preprocessor purge round 16: DEBUG --- meson.build | 2 +- src/Config.template.h | 2 +- src/PowderToyFontEditor.cpp | 24 ++++++++------ src/PowderToySDL.cpp | 59 ++++++++++++++++++----------------- src/Update.cpp | 32 +++++++++---------- src/client/Client.cpp | 3 +- src/client/GameSave.cpp | 14 +++++---- src/common/macosx.h | 10 ------ src/graphics/Graphics.cpp | 20 ++++++------ src/gui/game/IntroText.h | 7 +++-- src/gui/game/PropertyTool.cpp | 16 +++++----- src/gui/interface/Window.cpp | 32 +++---------------- src/gui/interface/Window.h | 2 -- 13 files changed, 101 insertions(+), 122 deletions(-) delete mode 100644 src/common/macosx.h diff --git a/meson.build b/meson.build index 34b90c974..457c2fa2e 100644 --- a/meson.build +++ b/meson.build @@ -331,7 +331,7 @@ conf_data.set('BETA', is_beta ? 'true' : 'false') conf_data.set('INSTALL_CHECK', get_option('install_check') ? 'true' : 'false') conf_data.set('IGNORE_UPDATES', get_option('ignore_updates') ? 'true' : 'false') conf_data.set('MOD_ID', mod_id) -conf_data.set('DEBUG', is_debug) +conf_data.set('DEBUG', is_debug ? 'true' : 'false') conf_data.set('SNAPSHOT', is_snapshot ? 'true' : 'false') conf_data.set('MOD', is_mod ? 'true' : 'false') conf_data.set('SNAPSHOT_ID', get_option('snapshot_id')) diff --git a/src/Config.template.h b/src/Config.template.h index 55405e141..cdd7792b1 100644 --- a/src/Config.template.h +++ b/src/Config.template.h @@ -2,12 +2,12 @@ #include // Boolean macros (defined / not defined), would be great to get rid of them all. -#mesondefine DEBUG #mesondefine LIN #mesondefine AND #mesondefine WIN #mesondefine MACOSX +constexpr bool DEBUG = @DEBUG@; constexpr bool X86 = @X86@; constexpr bool BETA = @BETA@; constexpr bool SNAPSHOT = @SNAPSHOT@; diff --git a/src/PowderToyFontEditor.cpp b/src/PowderToyFontEditor.cpp index 2d0136c9d..9ae824aff 100644 --- a/src/PowderToyFontEditor.cpp +++ b/src/PowderToyFontEditor.cpp @@ -15,7 +15,8 @@ #include #endif #ifdef MACOSX -# include "common/macosx.h" +# include +# include #endif #include @@ -299,9 +300,10 @@ void EventProcess(SDL_Event event) engine->onMouseClick(event.motion.x, event.motion.y, mouseButton); mouseDown = true; -#if !defined(NDEBUG) && !defined(DEBUG) - SDL_CaptureMouse(SDL_TRUE); -#endif + if constexpr (!DEBUG) + { + SDL_CaptureMouse(SDL_TRUE); + } break; case SDL_MOUSEBUTTONUP: // if mouse hasn't moved yet, sdl will send 0,0. We don't want that @@ -314,9 +316,10 @@ void EventProcess(SDL_Event event) engine->onMouseUnclick(mousex, mousey, mouseButton); mouseDown = false; -#if !defined(NDEBUG) && !defined(DEBUG) - SDL_CaptureMouse(SDL_FALSE); -#endif + if constexpr (!DEBUG) + { + SDL_CaptureMouse(SDL_FALSE); + } break; case SDL_WINDOWEVENT: { @@ -418,9 +421,10 @@ void EngineProcess() showDoubleScreenDialog = false; } } -#ifdef DEBUG - std::cout << "Breaking out of EngineProcess" << std::endl; -#endif + if constexpr (DEBUG) + { + std::cout << "Breaking out of EngineProcess" << std::endl; + } } int main(int argc, char * argv[]) diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp index 97a322370..652703510 100644 --- a/src/PowderToySDL.cpp +++ b/src/PowderToySDL.cpp @@ -7,7 +7,8 @@ #include #include #ifdef WIN -#include +# include +# include #endif #include @@ -22,10 +23,6 @@ # include #endif #ifdef MACOSX -# ifdef DEBUG -# undef DEBUG -# define DEBUG 1 -# endif # include #endif #include @@ -380,9 +377,10 @@ void EventProcess(SDL_Event event) engine->onMouseClick(mousex, mousey, mouseButton); mouseDown = true; -#if !defined(NDEBUG) && !defined(DEBUG) - SDL_CaptureMouse(SDL_TRUE); -#endif + if constexpr (!DEBUG) + { + SDL_CaptureMouse(SDL_TRUE); + } break; case SDL_MOUSEBUTTONUP: // if mouse hasn't moved yet, sdl will send 0,0. We don't want that @@ -395,9 +393,10 @@ void EventProcess(SDL_Event event) engine->onMouseUnclick(mousex, mousey, mouseButton); mouseDown = false; -#if !defined(NDEBUG) && !defined(DEBUG) - SDL_CaptureMouse(SDL_FALSE); -#endif + if constexpr (!DEBUG) + { + SDL_CaptureMouse(SDL_FALSE); + } break; case SDL_WINDOWEVENT: { @@ -527,9 +526,10 @@ void EngineProcess() LargeScreenDialog(); } } -#ifdef DEBUG - std::cout << "Breaking out of EngineProcess" << std::endl; -#endif + if constexpr (DEBUG) + { + std::cout << "Breaking out of EngineProcess" << std::endl; + } } void BlueScreen(String detailMessage) @@ -605,8 +605,11 @@ int GuessBestScale() int main(int argc, char * argv[]) { -#if defined(DEBUG) && defined(_MSC_VER) - _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG); +#ifdef WIN + if constexpr (DEBUG) + { + _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG); + } #endif currentWidth = WINDOWW; currentHeight = WINDOWH; @@ -818,8 +821,7 @@ int main(int argc, char * argv[]) engine->Begin(WINDOWW, WINDOWH); engine->SetFastQuit(Client::Ref().GetPrefBool("FastQuit", true)); -#if !defined(DEBUG) - bool enableBluescreen = !true_arg(arguments["disable-bluescreen"]); + bool enableBluescreen = !DEBUG && !true_arg(arguments["disable-bluescreen"]); if (enableBluescreen) { //Get ready to catch any dodgy errors @@ -828,7 +830,6 @@ int main(int argc, char * argv[]) signal(SIGILL, SigHandler); signal(SIGABRT, SigHandler); } -#endif if constexpr (X86) { @@ -844,9 +845,10 @@ int main(int argc, char * argv[]) auto openArg = arguments["open"]; if (openArg.has_value()) { -#ifdef DEBUG - std::cout << "Loading " << openArg.value() << std::endl; -#endif + if constexpr (DEBUG) + { + std::cout << "Loading " << openArg.value() << std::endl; + } if (Platform::FileExists(openArg.value())) { try @@ -900,9 +902,10 @@ int main(int argc, char * argv[]) if (!saveIdPart.size()) throw std::runtime_error("No Save ID"); -#ifdef DEBUG - std::cout << "Got Ptsave: id: " << saveIdPart << std::endl; -#endif + if constexpr (DEBUG) + { + std::cout << "Got Ptsave: id: " << saveIdPart << std::endl; + } int saveId = saveIdPart.ToNumber(); SaveInfo * newSave = Client::Ref().GetSave(saveId, 0); @@ -927,7 +930,6 @@ int main(int argc, char * argv[]) SaveWindowPosition(); }; -#if !defined(DEBUG) if (enableBluescreen) { try @@ -940,8 +942,9 @@ int main(int argc, char * argv[]) } } else -#endif - wrapWithBluescreen(); // the else branch of the if in the #if !defined(DEBUG) + { + wrapWithBluescreen(); + } ui::Engine::Ref().CloseWindow(); delete gameController; diff --git a/src/Update.cpp b/src/Update.cpp index 1952377ce..f33ca0128 100644 --- a/src/Update.cpp +++ b/src/Update.cpp @@ -101,29 +101,28 @@ int update_finish() #ifdef WIN ByteString exeName = Platform::ExecutableName(), updName; int timeout = 5, err; - -#ifdef DEBUG - printf("Update: Current EXE name: %s\n", exeName.c_str()); -#endif - + if constexpr (DEBUG) + { + printf("Update: Current EXE name: %s\n", exeName.c_str()); + } updName = exeName; ByteString extension = exeName.substr(exeName.length() - 4); if (extension == ".exe") updName = exeName.substr(0, exeName.length() - 4); updName = updName + "_upd.exe"; - -#ifdef DEBUG - printf("Update: Temp EXE name: %s\n", updName.c_str()); -#endif - + if constexpr (DEBUG) + { + printf("Update: Temp EXE name: %s\n", updName.c_str()); + } while (!Platform::RemoveFile(updName)) { err = GetLastError(); if (err == ERROR_FILE_NOT_FOUND) { -#ifdef DEBUG - printf("Update: Temp file not deleted\n"); -#endif + if constexpr (DEBUG) + { + printf("Update: Temp file not deleted\n"); + } // Old versions of powder toy name their update files with _update.exe, delete that upgrade file here updName = exeName; ByteString extension = exeName.substr(exeName.length() - 4); @@ -137,9 +136,10 @@ int update_finish() timeout--; if (timeout <= 0) { -#ifdef DEBUG - printf("Update: Delete timeout\n"); -#endif + if constexpr (DEBUG) + { + printf("Update: Delete timeout\n"); + } return 1; } } diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 2d99d5e81..61bd376c3 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -13,7 +13,8 @@ #include #ifdef MACOSX -# include "common/macosx.h" +# include +# include #endif #ifdef LIN diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 34655f5b0..075ca8df8 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -1329,9 +1329,10 @@ void GameSave::readPSv(const std::vector &dataVec) const auto *data = reinterpret_cast(&bsonData[0]); dataLength = bsonData.size(); -#ifdef DEBUG - std::cout << "Parsing " << dataLength << " bytes of data, version " << ver << std::endl; -#endif + if constexpr (DEBUG) + { + std::cout << "Parsing " << dataLength << " bytes of data, version " << ver << std::endl; + } if (dataLength < bw*bh) throw ParseException(ParseException::Corrupt, "Save data corrupt (missing data)"); @@ -2538,9 +2539,10 @@ std::pair> GameSave::serialiseOPS() const } auto compressedSize = int(outputData.size()); -#ifdef DEBUG - printf("compressed data: %d\n", compressedSize); -#endif + if constexpr (DEBUG) + { + printf("compressed data: %d\n", compressedSize); + } outputData.resize(compressedSize + 12); auto header = (unsigned char *)&outputData[compressedSize]; diff --git a/src/common/macosx.h b/src/common/macosx.h deleted file mode 100644 index d902c1ad0..000000000 --- a/src/common/macosx.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#ifdef DEBUG -# undef DEBUG -# define DEBUG 1 -#else -# define DEBUG 0 -#endif -#include -#include diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp index fddd42b62..c77e1d8b5 100644 --- a/src/graphics/Graphics.cpp +++ b/src/graphics/Graphics.cpp @@ -238,9 +238,10 @@ pixel *Graphics::resample_img(pixel *src, int sw, int sh, int rw, int rh) return (pixel*)resultImage; #else -#ifdef DEBUG - std::cout << "Resampling " << sw << "x" << sh << " to " << rw << "x" << rh << std::endl; -#endif + if constexpr (DEBUG) + { + std::cout << "Resampling " << sw << "x" << sh << " to " << rw << "x" << rh << std::endl; + } bool stairstep = false; if(rw < sw || rh < sh) { @@ -257,12 +258,13 @@ pixel *Graphics::resample_img(pixel *src, int sw, int sh, int rw, int rh) if(((fxint & (fxint-1)) == 0 && fxf < 0.1f) || ((fyint & (fyint-1)) == 0 && fyf < 0.1f)) stairstep = true; -#ifdef DEBUG - if(stairstep) - std::cout << "Downsampling by " << fx << "x" << fy << " using stairstepping" << std::endl; - else - std::cout << "Downsampling by " << fx << "x" << fy << " without stairstepping" << std::endl; -#endif + if constexpr (DEBUG) + { + if(stairstep) + std::cout << "Downsampling by " << fx << "x" << fy << " using stairstepping" << std::endl; + else + std::cout << "Downsampling by " << fx << "x" << fy << " without stairstepping" << std::endl; + } } int y, x, fxceil, fyceil; diff --git a/src/gui/game/IntroText.h b/src/gui/game/IntroText.h index 8daef2ed3..b8448d857 100644 --- a/src/gui/game/IntroText.h +++ b/src/gui/game/IntroText.h @@ -62,9 +62,10 @@ inline ByteString IntroText() { sb << " NOHTTP"; } -#ifdef DEBUG - sb << " DEBUG"; -#endif + if constexpr (DEBUG) + { + sb << " DEBUG"; + } if constexpr (ENFORCE_HTTPS) { sb << " HTTPS"; diff --git a/src/gui/game/PropertyTool.cpp b/src/gui/game/PropertyTool.cpp index 92fafd84c..0b414c206 100644 --- a/src/gui/game/PropertyTool.cpp +++ b/src/gui/game/PropertyTool.cpp @@ -162,11 +162,10 @@ void PropertyWindow::SetProperty(bool warn) new ErrorMessage("Could not set property", "Invalid particle type"); return; } - -#ifdef DEBUG - std::cout << "Got int value " << v << std::endl; -#endif - + if constexpr (DEBUG) + { + std::cout << "Got int value " << v << std::endl; + } tool->propValue.Integer = v; break; } @@ -187,9 +186,10 @@ void PropertyWindow::SetProperty(bool warn) { v = value.ToNumber(); } -#ifdef DEBUG - std::cout << "Got uint value " << v << std::endl; -#endif + if constexpr (DEBUG) + { + std::cout << "Got uint value " << v << std::endl; + } tool->propValue.UInteger = v; break; } diff --git a/src/gui/interface/Window.cpp b/src/gui/interface/Window.cpp index 49475db7d..b9e621075 100644 --- a/src/gui/interface/Window.cpp +++ b/src/gui/interface/Window.cpp @@ -19,9 +19,7 @@ Window::Window(Point _position, Point _size): cancelButton(NULL), focusedComponent_(NULL), hoverComponent(NULL), -#ifdef DEBUG debugMode(false), -#endif halt(false), destruct(false), stop(false) @@ -197,7 +195,6 @@ void Window::DoDraw() Components[i]->Draw(scrpos); } } -#ifdef DEBUG if (debugMode) { if (focusedComponent_==Components[i]) @@ -209,7 +206,6 @@ void Window::DoDraw() ui::Engine::Ref().g->fillrect(Components[i]->Position.X+Position.X, Components[i]->Position.Y+Position.Y, Components[i]->Size.X, Components[i]->Size.Y, 255, 0, 0, 90); } } -#endif } // the component the mouse is hovering over and the focused component are always drawn last if (hoverComponent && hoverComponent->Visible && hoverComponent->GetParent() == NULL) @@ -236,7 +232,6 @@ void Window::DoDraw() focusedComponent_->Draw(scrpos); } } -#ifdef DEBUG if (debugMode) { if (focusedComponent_) @@ -260,16 +255,13 @@ void Window::DoDraw() } return; } -#endif } void Window::DoTick(float dt) { -#ifdef DEBUG if (debugMode) return; -#endif if (DoesTextInput || (focusedComponent_ && focusedComponent_->Visible && focusedComponent_->Enabled && focusedComponent_->DoesTextInput)) { @@ -311,8 +303,7 @@ void Window::DoTick(float dt) void Window::DoKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { -#ifdef DEBUG - if (key == SDLK_TAB && ctrl) + if (DEBUG && key == SDLK_TAB && ctrl) debugMode = !debugMode; if (debugMode) { @@ -395,7 +386,6 @@ void Window::DoKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, b } return; } -#endif //on key press if (focusedComponent_ != NULL) { @@ -418,10 +408,8 @@ void Window::DoKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, b void Window::DoKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) { -#ifdef DEBUG if(debugMode) return; -#endif //on key unpress if (focusedComponent_ != NULL) { @@ -437,10 +425,8 @@ void Window::DoKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, void Window::DoTextInput(String text) { -#ifdef DEBUG if (debugMode) return; -#endif //on key unpress if (focusedComponent_ != NULL) { @@ -482,10 +468,10 @@ void Window::DoMouseDown(int x_, int y_, unsigned button) if (x >= Components[i]->Position.X && y >= Components[i]->Position.Y && x < Components[i]->Position.X + Components[i]->Size.X && y < Components[i]->Position.Y + Components[i]->Size.Y) { FocusComponent(Components[i]); -#ifdef DEBUG - if (!debugMode) -#endif - Components[i]->OnMouseClick(x - Components[i]->Position.X, y - Components[i]->Position.Y, button); + if (!DEBUG || !debugMode) + { + Components[i]->OnMouseClick(x - Components[i]->Position.X, y - Components[i]->Position.Y, button); + } clickState = true; break; } @@ -495,10 +481,8 @@ void Window::DoMouseDown(int x_, int y_, unsigned button) if (!clickState) FocusComponent(NULL); -#ifdef DEBUG if (debugMode) return; -#endif //on mouse down for (int i = Components.size() - 1; i > -1 && !halt; --i) @@ -522,10 +506,8 @@ void Window::DoMouseMove(int x_, int y_, int dx, int dy) //on mouse move (if true, and inside) int x = x_ - Position.X; int y = y_ - Position.Y; -#ifdef DEBUG if (debugMode) return; -#endif for (int i = Components.size() - 1; i > -1 && !halt; --i) { if (Components[i]->Enabled && Components[i]->Visible) @@ -578,10 +560,8 @@ void Window::DoMouseUp(int x_, int y_, unsigned button) { int x = x_ - Position.X; int y = y_ - Position.Y; -#ifdef DEBUG if (debugMode) return; -#endif //on mouse unclick for (int i = Components.size() - 1; i >= 0 && !halt; --i) { @@ -612,10 +592,8 @@ void Window::DoMouseWheel(int x_, int y_, int d) { int x = x_ - Position.X; int y = y_ - Position.Y; -#ifdef DEBUG if (debugMode) return; -#endif //on mouse wheel focused for (int i = Components.size() - 1; i >= 0 && !halt; --i) { diff --git a/src/gui/interface/Window.h b/src/gui/interface/Window.h index 6cb6f10b5..a00131952 100644 --- a/src/gui/interface/Window.h +++ b/src/gui/interface/Window.h @@ -113,9 +113,7 @@ namespace ui Component *hoverComponent; ChromeStyle chrome; -#ifdef DEBUG bool debugMode; -#endif //These controls allow a component to call the destruction of the Window inside an event (called by the Window) void finalise(); bool halt;