From 6c6f365d2fe86106ce2186a04e898f6f9597650c Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sun, 11 Jun 2023 15:56:13 +0200 Subject: [PATCH] Codechange: remove offset parameter for copying DParams in and out --- src/error_gui.cpp | 6 +++--- src/misc_gui.cpp | 4 ++-- src/news_gui.cpp | 10 +++++----- src/statusbar_gui.cpp | 2 +- src/strings.cpp | 10 ++++------ src/strings_func.h | 4 ++-- 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/error_gui.cpp b/src/error_gui.cpp index fee7d040c2..b7b5fe75bd 100644 --- a/src/error_gui.cpp +++ b/src/error_gui.cpp @@ -210,7 +210,7 @@ public: { switch (widget) { case WID_EM_MESSAGE: { - CopyInDParam(0, this->decode_params, lengthof(this->decode_params)); + CopyInDParam(this->decode_params, lengthof(this->decode_params)); if (this->textref_stack_size > 0) StartTextRefStackUsage(this->textref_stack_grffile, this->textref_stack_size, this->textref_stack); this->height_summary = GetStringHeight(this->summary_msg, size->width); @@ -279,7 +279,7 @@ public: void SetStringParameters(int widget) const override { - if (widget == WID_EM_CAPTION) CopyInDParam(0, this->decode_params, lengthof(this->decode_params)); + if (widget == WID_EM_CAPTION) CopyInDParam(this->decode_params, lengthof(this->decode_params)); } void DrawWidget(const Rect &r, int widget) const override @@ -292,7 +292,7 @@ public: } case WID_EM_MESSAGE: - CopyInDParam(0, this->decode_params, lengthof(this->decode_params)); + CopyInDParam(this->decode_params, lengthof(this->decode_params)); if (this->textref_stack_size > 0) StartTextRefStackUsage(this->textref_stack_grffile, this->textref_stack_size, this->textref_stack); if (this->detailed_msg == INVALID_STRING_ID) { diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index c4dd6cb93e..a94a71fe5d 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -1111,7 +1111,7 @@ struct QueryWindow : public Window { { /* Create a backup of the variadic arguments to strings because it will be * overridden pretty often. We will copy these back for drawing */ - CopyOutDParam(this->params, 0, lengthof(this->params)); + CopyOutDParam(this->params, lengthof(this->params)); this->message = message; this->proc = callback; this->parent = parent; @@ -1140,7 +1140,7 @@ struct QueryWindow : public Window { switch (widget) { case WID_Q_CAPTION: case WID_Q_TEXT: - CopyInDParam(0, this->params, lengthof(this->params)); + CopyInDParam(this->params, lengthof(this->params)); break; } } diff --git a/src/news_gui.cpp b/src/news_gui.cpp index 6527528741..ce4da6ba96 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -361,7 +361,7 @@ struct NewsWindow : Window { break; case WID_N_MESSAGE: - CopyInDParam(0, this->ni->params, lengthof(this->ni->params)); + CopyInDParam(this->ni->params, lengthof(this->ni->params)); str = this->ni->string_id; break; @@ -429,7 +429,7 @@ struct NewsWindow : Window { break; case WID_N_MESSAGE: - CopyInDParam(0, this->ni->params, lengthof(this->ni->params)); + CopyInDParam(this->ni->params, lengthof(this->ni->params)); DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->ni->string_id, TC_FROMSTRING, SA_CENTER); break; @@ -582,7 +582,7 @@ private: StringID GetCompanyMessageString() const { /* Company news with a face have a separate headline, so the normal message is shifted by two params */ - CopyInDParam(0, this->ni->params + 2, lengthof(this->ni->params) - 2); + CopyInDParam(this->ni->params + 2, lengthof(this->ni->params) - 2); return this->ni->params[1]; } @@ -804,7 +804,7 @@ NewsItem::NewsItem(StringID string_id, NewsType type, NewsFlag flags, NewsRefere { /* show this news message in colour? */ if (TimerGameCalendar::year >= _settings_client.gui.coloured_news_year) this->flags |= NF_INCOLOUR; - CopyOutDParam(this->params, 0, lengthof(this->params)); + CopyOutDParam(this->params, lengthof(this->params)); } /** @@ -1099,7 +1099,7 @@ void ShowLastNewsMessage() */ static void DrawNewsString(uint left, uint right, int y, TextColour colour, const NewsItem *ni) { - CopyInDParam(0, ni->params, lengthof(ni->params)); + CopyInDParam(ni->params, lengthof(ni->params)); /* Get the string, replaces newlines with spaces and remove control codes from the string. */ std::string message = StrMakeValid(GetString(ni->string_id), SVS_REPLACE_TAB_CR_NL_WITH_SPACE); diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp index 3bb731a706..ee505f7334 100644 --- a/src/statusbar_gui.cpp +++ b/src/statusbar_gui.cpp @@ -39,7 +39,7 @@ static bool DrawScrollingStatusText(const NewsItem *ni, int scroll_pos, int left, int right, int top, int bottom) { - CopyInDParam(0, ni->params, lengthof(ni->params)); + CopyInDParam(ni->params, lengthof(ni->params)); /* Replace newlines and the likes with spaces. */ std::string message = StrMakeValid(GetString(ni->string_id), SVS_REPLACE_TAB_CR_NL_WITH_SPACE); diff --git a/src/strings.cpp b/src/strings.cpp index 3ad0934dd7..4c358fa78d 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -128,24 +128,22 @@ void SetDParamMaxDigits(uint n, uint count, FontSize size) /** * Copy \a num string parameters from array \a src into the global string parameter array. - * @param offs Index in the global array to copy the first string parameter to. * @param src Source array of string parameters. * @param num Number of string parameters to copy. */ -void CopyInDParam(int offs, const uint64 *src, int num) +void CopyInDParam(const uint64 *src, int num) { - MemCpyT(_global_string_params.GetPointerToOffset(offs), src, num); + MemCpyT(_global_string_params.GetPointerToOffset(0), src, num); } /** * Copy \a num string parameters from the global string parameter array to the \a dst array. * @param dst Destination array of string parameters. - * @param offs Index in the global array to copy the first string parameter from. * @param num Number of string parameters to copy. */ -void CopyOutDParam(uint64 *dst, int offs, int num) +void CopyOutDParam(uint64 *dst, int num) { - MemCpyT(dst, _global_string_params.GetPointerToOffset(offs), num); + MemCpyT(dst, _global_string_params.GetPointerToOffset(0), num); } /** diff --git a/src/strings_func.h b/src/strings_func.h index 6d70c2df8c..7c34c4a252 100644 --- a/src/strings_func.h +++ b/src/strings_func.h @@ -218,8 +218,8 @@ void SetDParamStr(uint n, const char *str); void SetDParamStr(uint n, const std::string &str); void SetDParamStr(uint n, std::string &&str) = delete; // block passing temporaries to SetDParamStr -void CopyInDParam(int offs, const uint64 *src, int num); -void CopyOutDParam(uint64 *dst, int offs, int num); +void CopyInDParam(const uint64 *src, int num); +void CopyOutDParam(uint64 *dst, int num); void CopyOutDParam(uint64 *dst, const char **strings, StringID string, int num); /**