mirror of https://github.com/OpenTTD/OpenTTD
Codechange: do not keep local variable for temporary string parameters
parent
e04d43f396
commit
af9b9327af
|
@ -377,8 +377,7 @@ static void FiosGetFileList(SaveLoadOperation fop, FiosGetTypeAndNameProc *callb
|
||||||
fios->type = FIOS_TYPE_DIR;
|
fios->type = FIOS_TYPE_DIR;
|
||||||
fios->mtime = 0;
|
fios->mtime = 0;
|
||||||
fios->name = d_name;
|
fios->name = d_name;
|
||||||
std::string dirname = fios->name + PATHSEP;
|
SetDParamStr(0, fios->name + PATHSEP);
|
||||||
SetDParamStr(0, dirname);
|
|
||||||
fios->title = GetString(STR_SAVELOAD_DIRECTORY);
|
fios->title = GetString(STR_SAVELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,12 +208,11 @@ public:
|
||||||
/* Location */
|
/* Location */
|
||||||
std::stringstream tile_ss;
|
std::stringstream tile_ss;
|
||||||
tile_ss << "0x" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << tile; // 0x%.4X
|
tile_ss << "0x" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << tile; // 0x%.4X
|
||||||
std::string tile_str = tile_ss.str(); // Can't pass it directly to SetDParamStr as the string is only a temporary and would be destructed before the GetString call.
|
|
||||||
|
|
||||||
SetDParam(0, TileX(tile));
|
SetDParam(0, TileX(tile));
|
||||||
SetDParam(1, TileY(tile));
|
SetDParam(1, TileY(tile));
|
||||||
SetDParam(2, GetTileZ(tile));
|
SetDParam(2, GetTileZ(tile));
|
||||||
SetDParamStr(3, tile_str);
|
SetDParamStr(3, tile_ss.str());
|
||||||
this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_LANDINFO_COORDS));
|
this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_LANDINFO_COORDS));
|
||||||
|
|
||||||
/* Local authority */
|
/* Local authority */
|
||||||
|
|
|
@ -641,8 +641,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p
|
||||||
if (error < (ptrdiff_t)lengthof(network_error_strings)) err = network_error_strings[error];
|
if (error < (ptrdiff_t)lengthof(network_error_strings)) err = network_error_strings[error];
|
||||||
/* In case of kicking a client, we assume there is a kick message in the packet if we can read one byte */
|
/* In case of kicking a client, we assume there is a kick message in the packet if we can read one byte */
|
||||||
if (error == NETWORK_ERROR_KICKED && p->CanReadFromPacket(1)) {
|
if (error == NETWORK_ERROR_KICKED && p->CanReadFromPacket(1)) {
|
||||||
std::string kick_msg = p->Recv_string(NETWORK_CHAT_LENGTH);
|
SetDParamStr(0, p->Recv_string(NETWORK_CHAT_LENGTH));
|
||||||
SetDParamStr(0, kick_msg);
|
|
||||||
ShowErrorMessage(err, STR_NETWORK_ERROR_KICK_MESSAGE, WL_CRITICAL);
|
ShowErrorMessage(err, STR_NETWORK_ERROR_KICK_MESSAGE, WL_CRITICAL);
|
||||||
} else {
|
} else {
|
||||||
ShowErrorMessage(err, INVALID_STRING_ID, WL_CRITICAL);
|
ShowErrorMessage(err, INVALID_STRING_ID, WL_CRITICAL);
|
||||||
|
|
|
@ -77,9 +77,8 @@ static void ShowNewGRFInfo(const GRFConfig *c, const Rect &r, bool show_params)
|
||||||
for (uint i = 0; i < c->error->param_value.size(); i++) {
|
for (uint i = 0; i < c->error->param_value.size(); i++) {
|
||||||
SetDParam(3 + i, c->error->param_value[i]);
|
SetDParam(3 + i, c->error->param_value[i]);
|
||||||
}
|
}
|
||||||
std::string message = GetString(c->error->message != STR_NULL ? c->error->message : STR_JUST_RAW_STRING);
|
|
||||||
|
|
||||||
SetDParamStr(0, message);
|
SetDParamStr(0, GetString(c->error->message != STR_NULL ? c->error->message : STR_JUST_RAW_STRING));
|
||||||
tr.top = DrawStringMultiLine(tr, c->error->severity);
|
tr.top = DrawStringMultiLine(tr, c->error->severity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,8 +89,7 @@ static void ShowNewGRFInfo(const GRFConfig *c, const Rect &r, bool show_params)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare and draw GRF ID */
|
/* Prepare and draw GRF ID */
|
||||||
std::string tmp = fmt::format("{:08X}", BSWAP32(c->ident.grfid));
|
SetDParamStr(0, fmt::format("{:08X}", BSWAP32(c->ident.grfid)));
|
||||||
SetDParamStr(0, tmp);
|
|
||||||
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_GRF_ID);
|
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_GRF_ID);
|
||||||
|
|
||||||
if ((_settings_client.gui.newgrf_developer_tools || _settings_client.gui.newgrf_show_old_versions) && c->version != 0) {
|
if ((_settings_client.gui.newgrf_developer_tools || _settings_client.gui.newgrf_show_old_versions) && c->version != 0) {
|
||||||
|
@ -104,17 +102,14 @@ static void ShowNewGRFInfo(const GRFConfig *c, const Rect &r, bool show_params)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare and draw MD5 sum */
|
/* Prepare and draw MD5 sum */
|
||||||
tmp = FormatArrayAsHex(c->ident.md5sum);
|
SetDParamStr(0, FormatArrayAsHex(c->ident.md5sum));
|
||||||
SetDParamStr(0, tmp);
|
|
||||||
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_MD5SUM);
|
tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_MD5SUM);
|
||||||
|
|
||||||
/* Show GRF parameter list */
|
/* Show GRF parameter list */
|
||||||
if (show_params) {
|
if (show_params) {
|
||||||
std::string params;
|
|
||||||
if (c->num_params > 0) {
|
if (c->num_params > 0) {
|
||||||
params = GRFBuildParamList(c);
|
|
||||||
SetDParam(0, STR_JUST_RAW_STRING);
|
SetDParam(0, STR_JUST_RAW_STRING);
|
||||||
SetDParamStr(1, params);
|
SetDParamStr(1, GRFBuildParamList(c));
|
||||||
} else {
|
} else {
|
||||||
SetDParam(0, STR_NEWGRF_SETTINGS_PARAMETER_NONE);
|
SetDParam(0, STR_NEWGRF_SETTINGS_PARAMETER_NONE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,8 +248,6 @@ void ScriptText::_GetEncodedText(std::back_insert_iterator<std::string> &output,
|
||||||
|
|
||||||
const std::string Text::GetDecodedText()
|
const std::string Text::GetDecodedText()
|
||||||
{
|
{
|
||||||
const std::string &encoded_text = this->GetEncodedText();
|
::SetDParamStr(0, this->GetEncodedText());
|
||||||
|
|
||||||
::SetDParamStr(0, encoded_text);
|
|
||||||
return ::GetString(STR_JUST_RAW_STRING);
|
return ::GetString(STR_JUST_RAW_STRING);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue