1
0
Fork 0

Codechange: remove offset parameter for copying DParams in and out

pull/11000/head
Rubidium 2023-06-11 15:56:13 +02:00 committed by rubidium42
parent d42ef3a0ef
commit 6c6f365d2f
6 changed files with 17 additions and 19 deletions

View File

@ -210,7 +210,7 @@ public:
{ {
switch (widget) { switch (widget) {
case WID_EM_MESSAGE: { 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->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); this->height_summary = GetStringHeight(this->summary_msg, size->width);
@ -279,7 +279,7 @@ public:
void SetStringParameters(int widget) const override 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 void DrawWidget(const Rect &r, int widget) const override
@ -292,7 +292,7 @@ public:
} }
case WID_EM_MESSAGE: 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->textref_stack_size > 0) StartTextRefStackUsage(this->textref_stack_grffile, this->textref_stack_size, this->textref_stack);
if (this->detailed_msg == INVALID_STRING_ID) { if (this->detailed_msg == INVALID_STRING_ID) {

View File

@ -1111,7 +1111,7 @@ struct QueryWindow : public Window {
{ {
/* Create a backup of the variadic arguments to strings because it will be /* Create a backup of the variadic arguments to strings because it will be
* overridden pretty often. We will copy these back for drawing */ * 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->message = message;
this->proc = callback; this->proc = callback;
this->parent = parent; this->parent = parent;
@ -1140,7 +1140,7 @@ struct QueryWindow : public Window {
switch (widget) { switch (widget) {
case WID_Q_CAPTION: case WID_Q_CAPTION:
case WID_Q_TEXT: case WID_Q_TEXT:
CopyInDParam(0, this->params, lengthof(this->params)); CopyInDParam(this->params, lengthof(this->params));
break; break;
} }
} }

View File

@ -361,7 +361,7 @@ struct NewsWindow : Window {
break; break;
case WID_N_MESSAGE: 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; str = this->ni->string_id;
break; break;
@ -429,7 +429,7 @@ struct NewsWindow : Window {
break; break;
case WID_N_MESSAGE: 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); DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->ni->string_id, TC_FROMSTRING, SA_CENTER);
break; break;
@ -582,7 +582,7 @@ private:
StringID GetCompanyMessageString() const StringID GetCompanyMessageString() const
{ {
/* Company news with a face have a separate headline, so the normal message is shifted by two params */ /* 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]; 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? */ /* show this news message in colour? */
if (TimerGameCalendar::year >= _settings_client.gui.coloured_news_year) this->flags |= NF_INCOLOUR; 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) 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. */ /* 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); std::string message = StrMakeValid(GetString(ni->string_id), SVS_REPLACE_TAB_CR_NL_WITH_SPACE);

View File

@ -39,7 +39,7 @@
static bool DrawScrollingStatusText(const NewsItem *ni, int scroll_pos, int left, int right, int top, int bottom) 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. */ /* Replace newlines and the likes with spaces. */
std::string message = StrMakeValid(GetString(ni->string_id), SVS_REPLACE_TAB_CR_NL_WITH_SPACE); std::string message = StrMakeValid(GetString(ni->string_id), SVS_REPLACE_TAB_CR_NL_WITH_SPACE);

View File

@ -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. * 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 src Source array of string parameters.
* @param num Number of string parameters to copy. * @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. * Copy \a num string parameters from the global string parameter array to the \a dst array.
* @param dst Destination array of string parameters. * @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. * @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);
} }
/** /**

View File

@ -218,8 +218,8 @@ void SetDParamStr(uint n, const char *str);
void SetDParamStr(uint n, const std::string &str); void SetDParamStr(uint n, const std::string &str);
void SetDParamStr(uint n, std::string &&str) = delete; // block passing temporaries to SetDParamStr void SetDParamStr(uint n, std::string &&str) = delete; // block passing temporaries to SetDParamStr
void CopyInDParam(int offs, const uint64 *src, int num); void CopyInDParam(const uint64 *src, int num);
void CopyOutDParam(uint64 *dst, int offs, int num); void CopyOutDParam(uint64 *dst, int num);
void CopyOutDParam(uint64 *dst, const char **strings, StringID string, int num); void CopyOutDParam(uint64 *dst, const char **strings, StringID string, int num);
/** /**