diff --git a/src/fios.h b/src/fios.h index 971294b0aa..c31b2a5cb8 100644 --- a/src/fios.h +++ b/src/fios.h @@ -33,7 +33,7 @@ using CompanyPropertiesMap = std::map>; struct LoadCheckData { bool checkable; ///< True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.) StringID error; ///< Error message from loading. INVALID_STRING_ID if no error. - std::string error_msg; ///< Data to pass to SetDParamStr when displaying #error. + std::string error_msg; ///< Data to pass to string parameters when displaying #error. uint32_t map_size_x, map_size_y; TimerGameCalendar::Date current_date; diff --git a/src/gfx.cpp b/src/gfx.cpp index 1ee1256a70..8d5b4fe090 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -856,7 +856,7 @@ Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize) } /** - * Get bounding box of a string. Uses parameters set by #SetDParam if needed. + * Get bounding box of a string. * Has the same restrictions as #GetStringBoundingBox(std::string_view str, FontSize start_fontsize). * @param strid String to examine. * @return Width and height of the bounding box for the string in pixels. diff --git a/src/strings.cpp b/src/strings.cpp index c13cbb6f4a..cba5a84288 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -59,19 +59,6 @@ TextDirection _current_text_dir; ///< Text direction of the currently selected l std::unique_ptr _current_collator; ///< Collator for the language currently in use. #endif /* WITH_ICU_I18N */ -ArrayStringParameters<20> _global_string_params; - -/** - * Prepare the string parameters for the next formatting run. This means - * resetting the type information and resetting the offset to the begin. - */ -void StringParameters::PrepareForNextRun() -{ - for (auto ¶m : this->parameters) param.type = 0; - this->offset = 0; -} - - /** * Get the next parameter from our parameters. * This updates the offset, so the next time this is called the next parameter @@ -224,26 +211,6 @@ std::string EncodedString::GetDecodedString() const return GetString(STR_JUST_RAW_STRING, this->string); } -/** - * Set a string parameter \a v at index \a n in the global string parameter array. - * @param n Index of the string parameter. - * @param v Value of the string parameter. - */ -void SetDParam(size_t n, uint64_t v) -{ - _global_string_params.SetParam(n, v); -} - -/** - * Get the current string parameter at index \a n from the global string parameter array. - * @param n Index of the string parameter. - * @return Value of the requested string parameter. - */ -uint64_t GetDParam(size_t n) -{ - return std::get(_global_string_params.GetParam(n)); -} - /** * Get some number that is suitable for string size computations. * @param count Number of digits which shall be displayable. @@ -260,17 +227,6 @@ uint64_t GetParamMaxDigits(uint count, FontSize size) return val; } -/** - * Set DParam n to some number that is suitable for string size computations. - * @param n Index of the string parameter. - * @param count Number of digits which shall be displayable. - * @param size Font of the number - */ -void SetDParamMaxDigits(size_t n, uint count, FontSize size) -{ - SetDParam(n, GetParamMaxDigits(count, size)); -} - /** * Get some number that is suitable for string size computations. * @param max_value The biggest value which shall be displayed. @@ -289,56 +245,6 @@ uint64_t GetParamMaxValue(uint64_t max_value, uint min_count, FontSize size) return GetParamMaxDigits(std::max(min_count, num_digits), size); } -/** - * Set DParam n to some number that is suitable for string size computations. - * @param n Index of the string parameter. - * @param max_value The biggest value which shall be displayed. - * For the result only the number of digits of \a max_value matter. - * @param min_count Minimum number of digits independent of \a max. - * @param size Font of the number - */ -void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize size) -{ - SetDParam(n, GetParamMaxValue(max_value, min_count, size)); -} - -/** - * Copy the parameters from the backup into the global string parameter array. - * @param backup The backup to copy from. - */ -void CopyInDParam(const std::span backup) -{ - for (size_t i = 0; i < backup.size(); i++) { - _global_string_params.SetParam(i, backup[i]); - } -} - -/** - * Copy \a num string parameters from the global string parameter array to the \a backup. - * @param backup The backup to write to. - * @param num Number of string parameters to copy. - */ -void CopyOutDParam(std::vector &backup, size_t num) -{ - backup.resize(num); - for (size_t i = 0; i < backup.size(); i++) { - backup[i] = _global_string_params.GetParam(i); - } -} - -/** - * Checks whether the global string parameters have changed compared to the given backup. - * @param backup The backup to check against. - * @return True when the parameters have changed, otherwise false. - */ -bool HaveDParamChanged(const std::span backup) -{ - for (size_t i = 0; i < backup.size(); i++) { - if (backup[i] != _global_string_params.GetParam(i)) return true; - } - return false; -} - static void StationGetSpecialString(StringBuilder &builder, StationFacilities x); static bool GetSpecialNameString(StringBuilder &builder, StringID string, StringParameters &args); @@ -503,28 +409,24 @@ void GetStringWithArgs(StringBuilder &builder, StringID string, std::span params) @@ -556,39 +458,6 @@ std::string GetStringWithArgs(StringID string, std::span args) return result; } -/** - * This function is used to "bind" a C string to a OpenTTD dparam slot. - * @param n slot of the string - * @param str string to bind - */ -void SetDParamStr(size_t n, const char *str) -{ - _global_string_params.SetParam(n, str); -} - -/** - * This function is used to "bind" the C string of a std::string to a OpenTTD dparam slot. - * The caller has to ensure that the std::string reference remains valid while the string is shown. - * @param n slot of the string - * @param str string to bind - */ -void SetDParamStr(size_t n, const std::string &str) -{ - _global_string_params.SetParam(n, str); -} - -/** - * This function is used to "bind" the std::string to a OpenTTD dparam slot. - * Contrary to the other \c SetDParamStr functions, this moves the string into - * the parameter slot. - * @param n slot of the string - * @param str string to bind - */ -void SetDParamStr(size_t n, std::string &&str) -{ - _global_string_params.SetParam(n, std::move(str)); -} - static const char *GetDecimalSeparator() { const char *decimal_separator = _settings_game.locale.digit_decimal_separator.c_str(); diff --git a/src/strings_func.h b/src/strings_func.h index 25db9feed2..740e76321c 100644 --- a/src/strings_func.h +++ b/src/strings_func.h @@ -81,7 +81,7 @@ uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type); * Pack velocity and vehicle type for use with SCC_VELOCITY string parameter. * @param speed Display speed for parameter. * @param type Type of vehicle for parameter. - * @return Bit-packed velocity and vehicle type, for use with SetDParam(). + * @return Bit-packed velocity and vehicle type, for use with string parameters. */ inline int64_t PackVelocity(uint speed, VehicleType type) { @@ -93,30 +93,6 @@ inline int64_t PackVelocity(uint speed, VehicleType type) uint64_t GetParamMaxValue(uint64_t max_value, uint min_count = 0, FontSize size = FS_NORMAL); uint64_t GetParamMaxDigits(uint count, FontSize size = FS_NORMAL); -void SetDParam(size_t n, uint64_t v); -void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count = 0, FontSize size = FS_NORMAL); -void SetDParamMaxDigits(size_t n, uint count, FontSize size = FS_NORMAL); - -void SetDParam(size_t n, ConvertibleThroughBase auto v) -{ - SetDParam(n, v.base()); -} - -void SetDParamMaxValue(size_t n, ConvertibleThroughBase auto max_value, uint min_count = 0, FontSize size = FS_NORMAL) -{ - SetDParamMaxValue(n, max_value.base(), min_count, size); -} - -void SetDParamStr(size_t n, const char *str); -void SetDParamStr(size_t n, const std::string &str); -void SetDParamStr(size_t n, std::string &&str); - -void CopyInDParam(const std::span backup); -void CopyOutDParam(std::vector &backup, size_t num); -bool HaveDParamChanged(const std::span backup); - -uint64_t GetDParam(size_t n); - extern TextDirection _current_text_dir; ///< Text direction of the currently selected language void InitializeLanguagePacks(); diff --git a/src/strings_internal.h b/src/strings_internal.h index a8869afe71..6a73db44a4 100644 --- a/src/strings_internal.h +++ b/src/strings_internal.h @@ -35,7 +35,6 @@ public: StringParameters(std::span parameters = {}) : parameters(parameters) {} - void PrepareForNextRun(); void SetTypeOfNextParameter(char32_t type) { this->next_type = type; } /** @@ -126,7 +125,7 @@ public: /** * Get a new instance of StringParameters that is a "range" into the * remaining existing parameters. Upon destruction the offset in the parent - * is not updated. However, calls to SetDParam do update the parameters. + * is not updated. However, calls to SetParam do update the parameters. * * The returned StringParameters must not outlive this StringParameters. * @return A "range" of the string parameters. @@ -136,7 +135,7 @@ public: /** * Get a new instance of StringParameters that is a "range" into the * remaining existing parameters from the given offset. Upon destruction the - * offset in the parent is not updated. However, calls to SetDParam do + * offset in the parent is not updated. However, calls to SetParam do * update the parameters. * * The returned StringParameters must not outlive this StringParameters. @@ -199,38 +198,6 @@ public: } }; -/** - * Extension of StringParameters with its own statically sized buffer for - * the parameters. - */ -template -class ArrayStringParameters : public StringParameters { - std::array params{}; ///< The actual parameters - -public: - ArrayStringParameters() - { - this->parameters = std::span(params.data(), params.size()); - } - - ArrayStringParameters(ArrayStringParameters&& other) noexcept - { - *this = std::move(other); - } - - ArrayStringParameters& operator=(ArrayStringParameters &&other) noexcept - { - this->offset = other.offset; - this->next_type = other.next_type; - this->params = std::move(other.params); - this->parameters = std::span(params.data(), params.size()); - return *this; - } - - ArrayStringParameters(const ArrayStringParameters &other) = delete; - ArrayStringParameters& operator=(const ArrayStringParameters &other) = delete; -}; - /** * Equivalent to the std::back_insert_iterator in function, with some * convenience helpers for string concatenation. diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 64a08d04d6..c4cbfa4b2f 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -8,7 +8,6 @@ add_test_files( mock_spritecache.cpp mock_spritecache.h string_func.cpp - strings_func.cpp test_main.cpp test_network_crypto.cpp test_script_admin.cpp diff --git a/src/tests/strings_func.cpp b/src/tests/strings_func.cpp deleted file mode 100644 index 119bdfb79e..0000000000 --- a/src/tests/strings_func.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is part of OpenTTD. - * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. - * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . - */ - -/** @file strings_func.cpp Test functionality from strings_func. */ - -#include "../stdafx.h" - -#include "../3rdparty/catch2/catch.hpp" - -#include "../strings_func.h" - -TEST_CASE("HaveDParamChanged") -{ - SetDParam(0, 0); - SetDParamStr(1, "some string"); - - std::vector backup; - CopyOutDParam(backup, 2); - - CHECK(HaveDParamChanged(backup) == false); - - /* A different parameter 0 (both string and numeric). */ - SetDParam(0, 1); - CHECK(HaveDParamChanged(backup) == true); - - SetDParamStr(0, "some other string"); - CHECK(HaveDParamChanged(backup) == true); - - /* Back to the original state, nothing should have changed. */ - SetDParam(0, 0); - CHECK(HaveDParamChanged(backup) == false); - - /* A different parameter 1 (both string and numeric). */ - SetDParamStr(1, "some other string"); - CHECK(HaveDParamChanged(backup) == true); - - SetDParam(1, 0); - CHECK(HaveDParamChanged(backup) == true); - - /* Back to the original state, nothing should have changed. */ - SetDParamStr(1, "some string"); - CHECK(HaveDParamChanged(backup) == false); - - /* Changing parameter 2 should not have any effect, as the backup is only 2 long. */ - SetDParam(2, 3); - CHECK(HaveDParamChanged(backup) == false); - -} diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 1fa97b20bb..51cc130e49 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -512,13 +512,13 @@ public: } /** - * Gets the speed in km-ish/h that can be sent into SetDParam for string processing. + * Gets the speed in km-ish/h that can be sent into string parameters for string processing. * @return the vehicle's speed */ virtual int GetDisplaySpeed() const { return 0; } /** - * Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing. + * Gets the maximum speed in km-ish/h that can be sent into string parameters for string processing. * @return the vehicle's maximum speed */ virtual int GetDisplayMaxSpeed() const { return 0; } @@ -599,19 +599,19 @@ public: virtual Trackdir GetVehicleTrackdir() const { return INVALID_TRACKDIR; } /** - * Gets the running cost of a vehicle that can be sent into SetDParam for string processing. + * Gets the running cost of a vehicle that can be sent into string parameters for string processing. * @return the vehicle's running cost */ Money GetDisplayRunningCost() const { return (this->GetRunningCost() >> 8); } /** - * Gets the profit vehicle had this year. It can be sent into SetDParam for string processing. + * Gets the profit vehicle had this year. It can be sent into string parameters for string processing. * @return the vehicle's profit this year */ Money GetDisplayProfitThisYear() const { return (this->profit_this_year >> 8); } /** - * Gets the profit vehicle had last year. It can be sent into SetDParam for string processing. + * Gets the profit vehicle had last year. It can be sent into string parameters for string processing. * @return the vehicle's profit last year */ Money GetDisplayProfitLastYear() const { return (this->profit_last_year >> 8); } diff --git a/src/window.cpp b/src/window.cpp index 09c84b2350..eb540dfe8a 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -502,7 +502,6 @@ bool Window::SetFocusedWidget(WidgetID widget_index) std::string Window::GetWidgetString([[maybe_unused]] WidgetID widget, StringID stringid) const { if (stringid == STR_NULL) return {}; - this->SetStringParameters(widget); return GetString(stringid); } diff --git a/src/window_gui.h b/src/window_gui.h index 6d81dd441d..8d1718717b 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -616,14 +616,6 @@ public: */ virtual void UpdateWidgetSize([[maybe_unused]] WidgetID widget, [[maybe_unused]] Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) {} - /** - * Initialize string parameters for a widget. - * Calls to this function are made during initialization to measure the size (that is as part of #InitNested()), during drawing, - * and while re-initializing the window. Only for widgets that render text initializing is requested. - * @param widget Widget number. - */ - virtual void SetStringParameters([[maybe_unused]] WidgetID widget) const {} - /** * Get the raw string for a widget. * Calls to this function are also made during initialization to measure the size (that is as part of #InitNested()), during drawing,