Preprocessor purge round 16: DEBUG

This commit is contained in:
Tamás Bálint Misius
2023-01-15 07:41:32 +01:00
parent f0ffa2eeb1
commit f7478422a4
13 changed files with 101 additions and 122 deletions

View File

@@ -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('INSTALL_CHECK', get_option('install_check') ? 'true' : 'false')
conf_data.set('IGNORE_UPDATES', get_option('ignore_updates') ? 'true' : 'false') conf_data.set('IGNORE_UPDATES', get_option('ignore_updates') ? 'true' : 'false')
conf_data.set('MOD_ID', mod_id) 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('SNAPSHOT', is_snapshot ? 'true' : 'false')
conf_data.set('MOD', is_mod ? 'true' : 'false') conf_data.set('MOD', is_mod ? 'true' : 'false')
conf_data.set('SNAPSHOT_ID', get_option('snapshot_id')) conf_data.set('SNAPSHOT_ID', get_option('snapshot_id'))

View File

@@ -2,12 +2,12 @@
#include <cstdint> #include <cstdint>
// Boolean macros (defined / not defined), would be great to get rid of them all. // Boolean macros (defined / not defined), would be great to get rid of them all.
#mesondefine DEBUG
#mesondefine LIN #mesondefine LIN
#mesondefine AND #mesondefine AND
#mesondefine WIN #mesondefine WIN
#mesondefine MACOSX #mesondefine MACOSX
constexpr bool DEBUG = @DEBUG@;
constexpr bool X86 = @X86@; constexpr bool X86 = @X86@;
constexpr bool BETA = @BETA@; constexpr bool BETA = @BETA@;
constexpr bool SNAPSHOT = @SNAPSHOT@; constexpr bool SNAPSHOT = @SNAPSHOT@;

View File

@@ -15,7 +15,8 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#ifdef MACOSX #ifdef MACOSX
# include "common/macosx.h" # include <mach-o/dyld.h>
# include <ApplicationServices/ApplicationServices.h>
#endif #endif
#include <SDL.h> #include <SDL.h>
@@ -299,9 +300,10 @@ void EventProcess(SDL_Event event)
engine->onMouseClick(event.motion.x, event.motion.y, mouseButton); engine->onMouseClick(event.motion.x, event.motion.y, mouseButton);
mouseDown = true; mouseDown = true;
#if !defined(NDEBUG) && !defined(DEBUG) if constexpr (!DEBUG)
SDL_CaptureMouse(SDL_TRUE); {
#endif SDL_CaptureMouse(SDL_TRUE);
}
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
// if mouse hasn't moved yet, sdl will send 0,0. We don't want that // 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); engine->onMouseUnclick(mousex, mousey, mouseButton);
mouseDown = false; mouseDown = false;
#if !defined(NDEBUG) && !defined(DEBUG) if constexpr (!DEBUG)
SDL_CaptureMouse(SDL_FALSE); {
#endif SDL_CaptureMouse(SDL_FALSE);
}
break; break;
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
{ {
@@ -418,9 +421,10 @@ void EngineProcess()
showDoubleScreenDialog = false; showDoubleScreenDialog = false;
} }
} }
#ifdef DEBUG if constexpr (DEBUG)
std::cout << "Breaking out of EngineProcess" << std::endl; {
#endif std::cout << "Breaking out of EngineProcess" << std::endl;
}
} }
int main(int argc, char * argv[]) int main(int argc, char * argv[])

View File

@@ -7,7 +7,8 @@
#include <climits> #include <climits>
#include <cstdint> #include <cstdint>
#ifdef WIN #ifdef WIN
#include <direct.h> # include <direct.h>
# include <crtdbg.h>
#endif #endif
#include <SDL.h> #include <SDL.h>
@@ -22,10 +23,6 @@
# include <unistd.h> # include <unistd.h>
#endif #endif
#ifdef MACOSX #ifdef MACOSX
# ifdef DEBUG
# undef DEBUG
# define DEBUG 1
# endif
# include <CoreServices/CoreServices.h> # include <CoreServices/CoreServices.h>
#endif #endif
#include <sys/stat.h> #include <sys/stat.h>
@@ -380,9 +377,10 @@ void EventProcess(SDL_Event event)
engine->onMouseClick(mousex, mousey, mouseButton); engine->onMouseClick(mousex, mousey, mouseButton);
mouseDown = true; mouseDown = true;
#if !defined(NDEBUG) && !defined(DEBUG) if constexpr (!DEBUG)
SDL_CaptureMouse(SDL_TRUE); {
#endif SDL_CaptureMouse(SDL_TRUE);
}
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
// if mouse hasn't moved yet, sdl will send 0,0. We don't want that // 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); engine->onMouseUnclick(mousex, mousey, mouseButton);
mouseDown = false; mouseDown = false;
#if !defined(NDEBUG) && !defined(DEBUG) if constexpr (!DEBUG)
SDL_CaptureMouse(SDL_FALSE); {
#endif SDL_CaptureMouse(SDL_FALSE);
}
break; break;
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
{ {
@@ -527,9 +526,10 @@ void EngineProcess()
LargeScreenDialog(); LargeScreenDialog();
} }
} }
#ifdef DEBUG if constexpr (DEBUG)
std::cout << "Breaking out of EngineProcess" << std::endl; {
#endif std::cout << "Breaking out of EngineProcess" << std::endl;
}
} }
void BlueScreen(String detailMessage) void BlueScreen(String detailMessage)
@@ -605,8 +605,11 @@ int GuessBestScale()
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
#if defined(DEBUG) && defined(_MSC_VER) #ifdef WIN
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG); if constexpr (DEBUG)
{
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
}
#endif #endif
currentWidth = WINDOWW; currentWidth = WINDOWW;
currentHeight = WINDOWH; currentHeight = WINDOWH;
@@ -818,8 +821,7 @@ int main(int argc, char * argv[])
engine->Begin(WINDOWW, WINDOWH); engine->Begin(WINDOWW, WINDOWH);
engine->SetFastQuit(Client::Ref().GetPrefBool("FastQuit", true)); engine->SetFastQuit(Client::Ref().GetPrefBool("FastQuit", true));
#if !defined(DEBUG) bool enableBluescreen = !DEBUG && !true_arg(arguments["disable-bluescreen"]);
bool enableBluescreen = !true_arg(arguments["disable-bluescreen"]);
if (enableBluescreen) if (enableBluescreen)
{ {
//Get ready to catch any dodgy errors //Get ready to catch any dodgy errors
@@ -828,7 +830,6 @@ int main(int argc, char * argv[])
signal(SIGILL, SigHandler); signal(SIGILL, SigHandler);
signal(SIGABRT, SigHandler); signal(SIGABRT, SigHandler);
} }
#endif
if constexpr (X86) if constexpr (X86)
{ {
@@ -844,9 +845,10 @@ int main(int argc, char * argv[])
auto openArg = arguments["open"]; auto openArg = arguments["open"];
if (openArg.has_value()) if (openArg.has_value())
{ {
#ifdef DEBUG if constexpr (DEBUG)
std::cout << "Loading " << openArg.value() << std::endl; {
#endif std::cout << "Loading " << openArg.value() << std::endl;
}
if (Platform::FileExists(openArg.value())) if (Platform::FileExists(openArg.value()))
{ {
try try
@@ -900,9 +902,10 @@ int main(int argc, char * argv[])
if (!saveIdPart.size()) if (!saveIdPart.size())
throw std::runtime_error("No Save ID"); throw std::runtime_error("No Save ID");
#ifdef DEBUG if constexpr (DEBUG)
std::cout << "Got Ptsave: id: " << saveIdPart << std::endl; {
#endif std::cout << "Got Ptsave: id: " << saveIdPart << std::endl;
}
int saveId = saveIdPart.ToNumber<int>(); int saveId = saveIdPart.ToNumber<int>();
SaveInfo * newSave = Client::Ref().GetSave(saveId, 0); SaveInfo * newSave = Client::Ref().GetSave(saveId, 0);
@@ -927,7 +930,6 @@ int main(int argc, char * argv[])
SaveWindowPosition(); SaveWindowPosition();
}; };
#if !defined(DEBUG)
if (enableBluescreen) if (enableBluescreen)
{ {
try try
@@ -940,8 +942,9 @@ int main(int argc, char * argv[])
} }
} }
else else
#endif {
wrapWithBluescreen(); // the else branch of the if in the #if !defined(DEBUG) wrapWithBluescreen();
}
ui::Engine::Ref().CloseWindow(); ui::Engine::Ref().CloseWindow();
delete gameController; delete gameController;

View File

@@ -101,29 +101,28 @@ int update_finish()
#ifdef WIN #ifdef WIN
ByteString exeName = Platform::ExecutableName(), updName; ByteString exeName = Platform::ExecutableName(), updName;
int timeout = 5, err; int timeout = 5, err;
if constexpr (DEBUG)
#ifdef DEBUG {
printf("Update: Current EXE name: %s\n", exeName.c_str()); printf("Update: Current EXE name: %s\n", exeName.c_str());
#endif }
updName = exeName; updName = exeName;
ByteString extension = exeName.substr(exeName.length() - 4); ByteString extension = exeName.substr(exeName.length() - 4);
if (extension == ".exe") if (extension == ".exe")
updName = exeName.substr(0, exeName.length() - 4); updName = exeName.substr(0, exeName.length() - 4);
updName = updName + "_upd.exe"; updName = updName + "_upd.exe";
if constexpr (DEBUG)
#ifdef DEBUG {
printf("Update: Temp EXE name: %s\n", updName.c_str()); printf("Update: Temp EXE name: %s\n", updName.c_str());
#endif }
while (!Platform::RemoveFile(updName)) while (!Platform::RemoveFile(updName))
{ {
err = GetLastError(); err = GetLastError();
if (err == ERROR_FILE_NOT_FOUND) if (err == ERROR_FILE_NOT_FOUND)
{ {
#ifdef DEBUG if constexpr (DEBUG)
printf("Update: Temp file not deleted\n"); {
#endif printf("Update: Temp file not deleted\n");
}
// Old versions of powder toy name their update files with _update.exe, delete that upgrade file here // Old versions of powder toy name their update files with _update.exe, delete that upgrade file here
updName = exeName; updName = exeName;
ByteString extension = exeName.substr(exeName.length() - 4); ByteString extension = exeName.substr(exeName.length() - 4);
@@ -137,9 +136,10 @@ int update_finish()
timeout--; timeout--;
if (timeout <= 0) if (timeout <= 0)
{ {
#ifdef DEBUG if constexpr (DEBUG)
printf("Update: Delete timeout\n"); {
#endif printf("Update: Delete timeout\n");
}
return 1; return 1;
} }
} }

View File

@@ -13,7 +13,8 @@
#include <fstream> #include <fstream>
#ifdef MACOSX #ifdef MACOSX
# include "common/macosx.h" # include <mach-o/dyld.h>
# include <ApplicationServices/ApplicationServices.h>
#endif #endif
#ifdef LIN #ifdef LIN

View File

@@ -1329,9 +1329,10 @@ void GameSave::readPSv(const std::vector<char> &dataVec)
const auto *data = reinterpret_cast<unsigned char *>(&bsonData[0]); const auto *data = reinterpret_cast<unsigned char *>(&bsonData[0]);
dataLength = bsonData.size(); dataLength = bsonData.size();
#ifdef DEBUG if constexpr (DEBUG)
std::cout << "Parsing " << dataLength << " bytes of data, version " << ver << std::endl; {
#endif std::cout << "Parsing " << dataLength << " bytes of data, version " << ver << std::endl;
}
if (dataLength < bw*bh) if (dataLength < bw*bh)
throw ParseException(ParseException::Corrupt, "Save data corrupt (missing data)"); throw ParseException(ParseException::Corrupt, "Save data corrupt (missing data)");
@@ -2538,9 +2539,10 @@ std::pair<bool, std::vector<char>> GameSave::serialiseOPS() const
} }
auto compressedSize = int(outputData.size()); auto compressedSize = int(outputData.size());
#ifdef DEBUG if constexpr (DEBUG)
printf("compressed data: %d\n", compressedSize); {
#endif printf("compressed data: %d\n", compressedSize);
}
outputData.resize(compressedSize + 12); outputData.resize(compressedSize + 12);
auto header = (unsigned char *)&outputData[compressedSize]; auto header = (unsigned char *)&outputData[compressedSize];

View File

@@ -1,10 +0,0 @@
#pragma once
#ifdef DEBUG
# undef DEBUG
# define DEBUG 1
#else
# define DEBUG 0
#endif
#include <mach-o/dyld.h>
#include <ApplicationServices/ApplicationServices.h>

View File

@@ -238,9 +238,10 @@ pixel *Graphics::resample_img(pixel *src, int sw, int sh, int rw, int rh)
return (pixel*)resultImage; return (pixel*)resultImage;
#else #else
#ifdef DEBUG if constexpr (DEBUG)
std::cout << "Resampling " << sw << "x" << sh << " to " << rw << "x" << rh << std::endl; {
#endif std::cout << "Resampling " << sw << "x" << sh << " to " << rw << "x" << rh << std::endl;
}
bool stairstep = false; bool stairstep = false;
if(rw < sw || rh < sh) 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)) if(((fxint & (fxint-1)) == 0 && fxf < 0.1f) || ((fyint & (fyint-1)) == 0 && fyf < 0.1f))
stairstep = true; stairstep = true;
#ifdef DEBUG if constexpr (DEBUG)
if(stairstep) {
std::cout << "Downsampling by " << fx << "x" << fy << " using stairstepping" << std::endl; if(stairstep)
else std::cout << "Downsampling by " << fx << "x" << fy << " using stairstepping" << std::endl;
std::cout << "Downsampling by " << fx << "x" << fy << " without stairstepping" << std::endl; else
#endif std::cout << "Downsampling by " << fx << "x" << fy << " without stairstepping" << std::endl;
}
} }
int y, x, fxceil, fyceil; int y, x, fxceil, fyceil;

View File

@@ -62,9 +62,10 @@ inline ByteString IntroText()
{ {
sb << " NOHTTP"; sb << " NOHTTP";
} }
#ifdef DEBUG if constexpr (DEBUG)
sb << " DEBUG"; {
#endif sb << " DEBUG";
}
if constexpr (ENFORCE_HTTPS) if constexpr (ENFORCE_HTTPS)
{ {
sb << " HTTPS"; sb << " HTTPS";

View File

@@ -162,11 +162,10 @@ void PropertyWindow::SetProperty(bool warn)
new ErrorMessage("Could not set property", "Invalid particle type"); new ErrorMessage("Could not set property", "Invalid particle type");
return; return;
} }
if constexpr (DEBUG)
#ifdef DEBUG {
std::cout << "Got int value " << v << std::endl; std::cout << "Got int value " << v << std::endl;
#endif }
tool->propValue.Integer = v; tool->propValue.Integer = v;
break; break;
} }
@@ -187,9 +186,10 @@ void PropertyWindow::SetProperty(bool warn)
{ {
v = value.ToNumber<unsigned int>(); v = value.ToNumber<unsigned int>();
} }
#ifdef DEBUG if constexpr (DEBUG)
std::cout << "Got uint value " << v << std::endl; {
#endif std::cout << "Got uint value " << v << std::endl;
}
tool->propValue.UInteger = v; tool->propValue.UInteger = v;
break; break;
} }

View File

@@ -19,9 +19,7 @@ Window::Window(Point _position, Point _size):
cancelButton(NULL), cancelButton(NULL),
focusedComponent_(NULL), focusedComponent_(NULL),
hoverComponent(NULL), hoverComponent(NULL),
#ifdef DEBUG
debugMode(false), debugMode(false),
#endif
halt(false), halt(false),
destruct(false), destruct(false),
stop(false) stop(false)
@@ -197,7 +195,6 @@ void Window::DoDraw()
Components[i]->Draw(scrpos); Components[i]->Draw(scrpos);
} }
} }
#ifdef DEBUG
if (debugMode) if (debugMode)
{ {
if (focusedComponent_==Components[i]) 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); 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 // the component the mouse is hovering over and the focused component are always drawn last
if (hoverComponent && hoverComponent->Visible && hoverComponent->GetParent() == NULL) if (hoverComponent && hoverComponent->Visible && hoverComponent->GetParent() == NULL)
@@ -236,7 +232,6 @@ void Window::DoDraw()
focusedComponent_->Draw(scrpos); focusedComponent_->Draw(scrpos);
} }
} }
#ifdef DEBUG
if (debugMode) if (debugMode)
{ {
if (focusedComponent_) if (focusedComponent_)
@@ -260,16 +255,13 @@ void Window::DoDraw()
} }
return; return;
} }
#endif
} }
void Window::DoTick(float dt) void Window::DoTick(float dt)
{ {
#ifdef DEBUG
if (debugMode) if (debugMode)
return; return;
#endif
if (DoesTextInput || (focusedComponent_ && focusedComponent_->Visible && focusedComponent_->Enabled && focusedComponent_->DoesTextInput)) 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) void Window::DoKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt)
{ {
#ifdef DEBUG if (DEBUG && key == SDLK_TAB && ctrl)
if (key == SDLK_TAB && ctrl)
debugMode = !debugMode; debugMode = !debugMode;
if (debugMode) if (debugMode)
{ {
@@ -395,7 +386,6 @@ void Window::DoKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, b
} }
return; return;
} }
#endif
//on key press //on key press
if (focusedComponent_ != NULL) 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) void Window::DoKeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt)
{ {
#ifdef DEBUG
if(debugMode) if(debugMode)
return; return;
#endif
//on key unpress //on key unpress
if (focusedComponent_ != NULL) 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) void Window::DoTextInput(String text)
{ {
#ifdef DEBUG
if (debugMode) if (debugMode)
return; return;
#endif
//on key unpress //on key unpress
if (focusedComponent_ != NULL) 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) 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]); FocusComponent(Components[i]);
#ifdef DEBUG if (!DEBUG || !debugMode)
if (!debugMode) {
#endif Components[i]->OnMouseClick(x - Components[i]->Position.X, y - Components[i]->Position.Y, button);
Components[i]->OnMouseClick(x - Components[i]->Position.X, y - Components[i]->Position.Y, button); }
clickState = true; clickState = true;
break; break;
} }
@@ -495,10 +481,8 @@ void Window::DoMouseDown(int x_, int y_, unsigned button)
if (!clickState) if (!clickState)
FocusComponent(NULL); FocusComponent(NULL);
#ifdef DEBUG
if (debugMode) if (debugMode)
return; return;
#endif
//on mouse down //on mouse down
for (int i = Components.size() - 1; i > -1 && !halt; --i) 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) //on mouse move (if true, and inside)
int x = x_ - Position.X; int x = x_ - Position.X;
int y = y_ - Position.Y; int y = y_ - Position.Y;
#ifdef DEBUG
if (debugMode) if (debugMode)
return; return;
#endif
for (int i = Components.size() - 1; i > -1 && !halt; --i) for (int i = Components.size() - 1; i > -1 && !halt; --i)
{ {
if (Components[i]->Enabled && Components[i]->Visible) 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 x = x_ - Position.X;
int y = y_ - Position.Y; int y = y_ - Position.Y;
#ifdef DEBUG
if (debugMode) if (debugMode)
return; return;
#endif
//on mouse unclick //on mouse unclick
for (int i = Components.size() - 1; i >= 0 && !halt; --i) 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 x = x_ - Position.X;
int y = y_ - Position.Y; int y = y_ - Position.Y;
#ifdef DEBUG
if (debugMode) if (debugMode)
return; return;
#endif
//on mouse wheel focused //on mouse wheel focused
for (int i = Components.size() - 1; i >= 0 && !halt; --i) for (int i = Components.size() - 1; i >= 0 && !halt; --i)
{ {

View File

@@ -113,9 +113,7 @@ namespace ui
Component *hoverComponent; Component *hoverComponent;
ChromeStyle chrome; ChromeStyle chrome;
#ifdef DEBUG
bool debugMode; bool debugMode;
#endif
//These controls allow a component to call the destruction of the Window inside an event (called by the Window) //These controls allow a component to call the destruction of the Window inside an event (called by the Window)
void finalise(); void finalise();
bool halt; bool halt;