From 641e877441b0e5c84ac33f7ec03cbde89ddafd74 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 27 May 2018 22:28:07 +0100 Subject: [PATCH] Change grfmsg to be a macro which checks the debug level first This is to avoid doing a sprintf when the result will be thrown away --- src/newgrf.cpp | 2 +- src/newgrf.h | 4 +++- src/newgrf_class_func.h | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/newgrf.cpp b/src/newgrf.cpp index b43f427010..e2c6e37d3c 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -377,7 +377,7 @@ static GRFLineToSpriteOverride _grf_line_to_action6_sprite_override; * @param severity debugging severity level, see debug.h * @param str message in printf() format */ -void CDECL grfmsg(int severity, const char *str, ...) +void CDECL _intl_grfmsg(int severity, const char *str, ...) { char buf[1024]; va_list va; diff --git a/src/newgrf.h b/src/newgrf.h index 5a8217b27f..f34d5c5a89 100644 --- a/src/newgrf.h +++ b/src/newgrf.h @@ -15,6 +15,7 @@ #include "cargotype.h" #include "rail_type.h" #include "fileio_type.h" +#include "debug.h" #include "core/bitmath_func.hpp" #include "core/alloc_type.hpp" #include "core/smallvec_type.hpp" @@ -188,7 +189,8 @@ void ReloadNewGRFData(); // in saveload/afterload.cpp void ResetNewGRFData(); void ResetPersistentNewGRFData(); -void CDECL grfmsg(int severity, const char *str, ...) WARN_FORMAT(2, 3); +#define grfmsg(severity, ...) if ((severity) == 0 || _debug_grf_level >= (severity)) _intl_grfmsg(severity, __VA_ARGS__) +void CDECL _intl_grfmsg(int severity, const char *str, ...) WARN_FORMAT(2, 3); bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile); diff --git a/src/newgrf_class_func.h b/src/newgrf_class_func.h index c2a30992ae..7e5d10e6a7 100644 --- a/src/newgrf_class_func.h +++ b/src/newgrf_class_func.h @@ -9,6 +9,7 @@ /** @file newgrf_class_func.h Implementation of the NewGRF class' functions. */ +#include "newgrf.h" #include "newgrf_class.h" #include "table/strings.h"