1
0
Fork 0

Compare commits

...

5 Commits

Author SHA1 Message Date
SamuXarick 93bf037cd0
Merge 3d8dad2cc6 into 13759e9f23 2025-07-25 07:41:57 +00:00
Peter Nelson 13759e9f23
Fix: Display GRFID in correct hex format. (#14478) 2025-07-25 08:41:48 +01:00
translators 3e06c69e26 Update: Translations from eints
portuguese: 1 change by jcteotonio
polish: 6 changes by pAter-exe
2025-07-25 04:47:26 +00:00
SamuXarick 3d8dad2cc6 Codechange: Optimize FlowRiver
Make all height_tile int to allow comparison between heights generated from TileHeight and heights generated from IsTileFlat.
Make the first check IsWaterTile as that is the first thing that should be checked for FlowRiver recursive calls. Swaps position with height_begin.
Change FlatSet to std::unordered_set which is faster at the contains function.
Change std::list to std::vector to be a queue, but do not pop items from it when advancing the queue. The tiles in it are ordered by insertion which is what's needed for the n-th tile to make lake_centre.
count is not required. It can be extracted from either the unordered set or the vector.
Swap the order of checks for determining the validity of lake_centre tile, making IsTileFlat and DistanceManhattan the last ones to check as I believe are the most computational.
2025-05-08 12:26:39 +01:00
SamuXarick 7ddbd1643e Codechange: Implementation of std::hash for StrongType::Typedef 2025-05-08 10:15:21 +01:00
5 changed files with 55 additions and 27 deletions

View File

@ -158,4 +158,31 @@ namespace StrongType {
};
}
/**
* Implementation of std::hash for StrongType::Typedef.
*
* This specialization of std::hash allows hashing of StrongType::Typedef instances
* by leveraging the hash of the base type.
*
* Example Usage:
* using MyType = StrongType::Typedef<int, struct MyTypeTag>;
* std::unordered_map<MyType, std::string> my_map;
*
* @tparam TBaseType The underlying type of the StrongType::Typedef.
* @tparam TProperties Additional properties for the StrongType::Typedef.
*/
template <typename TBaseType, typename... TProperties>
struct std::hash<StrongType::Typedef<TBaseType, TProperties...>> {
/**
* Computes the hash value for a StrongType::Typedef instance.
*
* @param t The StrongType::Typedef instance to hash.
* @return The hash value of the base type of t.
*/
std::size_t operator()(const StrongType::Typedef<TBaseType, TProperties...> &t) const noexcept
{
return std::hash<TBaseType>()(t.base());
}
};
#endif /* STRONG_TYPEDEF_TYPE_HPP */

View File

@ -27,7 +27,6 @@
#include "effectvehicle_func.h"
#include "landscape_type.h"
#include "animated_tile_func.h"
#include "core/flatset_type.hpp"
#include "core/random_func.hpp"
#include "object_base.h"
#include "company_func.h"
@ -43,6 +42,8 @@
#include "table/strings.h"
#include "table/sprites.h"
#include <unordered_set>
#include "safeguards.h"
extern const TileTypeProcs
@ -1300,28 +1301,26 @@ public:
*/
static std::tuple<bool, bool> FlowRiver(TileIndex spring, TileIndex begin, uint min_river_length)
{
uint height_begin = TileHeight(begin);
if (IsWaterTile(begin)) {
return { DistanceManhattan(spring, begin) > min_river_length, GetTileZ(begin) == 0 };
}
FlatSet<TileIndex> marks;
int height_begin = TileHeight(begin);
std::unordered_set<TileIndex> marks;
marks.insert(begin);
/* Breadth first search for the closest tile we can flow down to. */
std::list<TileIndex> queue;
std::vector<TileIndex> queue;
queue.push_back(begin);
/* Breadth first search for the closest tile we can flow down to. */
bool found = false;
uint count = 0; // Number of tiles considered; to be used for lake location guessing.
TileIndex end;
do {
end = queue.front();
queue.pop_front();
for (size_t i = 0; i != queue.size(); i++) {
end = queue[i];
uint height_end = TileHeight(end);
if (IsTileFlat(end) && (height_end < height_begin || (height_end == height_begin && IsWaterTile(end)))) {
int height_end;
if (IsTileFlat(end, &height_end) && (height_end < height_begin || (height_end == height_begin && IsWaterTile(end)))) {
found = true;
break;
}
@ -1330,31 +1329,29 @@ static std::tuple<bool, bool> FlowRiver(TileIndex spring, TileIndex begin, uint
TileIndex t = end + TileOffsByDiagDir(d);
if (IsValidTile(t) && !marks.contains(t) && FlowsDown(end, t)) {
marks.insert(t);
count++;
queue.push_back(t);
}
}
} while (!queue.empty());
}
bool main_river = false;
if (found) {
/* Flow further down hill. */
std::tie(found, main_river) = FlowRiver(spring, end, min_river_length);
} else if (count > 32) {
} else if (queue.size() > 32) {
/* Maybe we can make a lake. Find the Nth of the considered tiles. */
auto cit = marks.cbegin();
std::advance(cit, RandomRange(count - 1));
TileIndex lake_centre = *cit;
TileIndex lake_centre = queue[RandomRange(static_cast<uint32_t>(queue.size()))];
int height_lake;
if (IsValidTile(lake_centre) &&
/* A river, or lake, can only be built on flat slopes. */
IsTileFlat(lake_centre) &&
/* We want the lake to be built at the height of the river. */
TileHeight(begin) == TileHeight(lake_centre) &&
/* We don't want the lake at the entry of the valley. */
lake_centre != begin &&
/* We don't want lakes in the desert. */
(_settings_game.game_creation.landscape != LandscapeType::Tropic || GetTropicZone(lake_centre) != TROPICZONE_DESERT) &&
/* A river, or lake, can only be built on flat slopes. */
IsTileFlat(lake_centre, &height_lake) &&
/* We want the lake to be built at the height of the river. */
height_lake == height_begin &&
/* We only want a lake if the river is long enough. */
DistanceManhattan(spring, lake_centre) > min_river_length) {
end = lake_centre;
@ -1364,7 +1361,7 @@ static std::tuple<bool, bool> FlowRiver(TileIndex spring, TileIndex begin, uint
/* Run the loop twice, so artefacts from going circular in one direction get (mostly) hidden. */
for (uint loops = 0; loops < 2; ++loops) {
for (auto tile : SpiralTileSequence(lake_centre, diameter)) {
MakeLake(tile, height_begin);
MakeLake(tile, height_lake);
}
}
@ -1372,7 +1369,6 @@ static std::tuple<bool, bool> FlowRiver(TileIndex spring, TileIndex begin, uint
}
}
marks.clear();
if (found) RiverBuilder::Exec(begin, end, spring, main_river);
return { found, main_river };
}

View File

@ -1010,11 +1010,14 @@ STR_GRAPH_CARGO_ENABLE_ALL :{TINY_FONT}{BLA
STR_GRAPH_CARGO_DISABLE_ALL :{TINY_FONT}{BLACK}Żaden
STR_GRAPH_CARGO_TOOLTIP_ENABLE_ALL :{BLACK}Wyświetl wszystkie ładunki na wykresie stawek za ładunek
STR_GRAPH_CARGO_TOOLTIP_DISABLE_ALL :{BLACK}Ukryj wszystkie ładunki na wykresie stawek za ładunek
STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO :{BLACK}Przełącz ukrywanie/wyświetlanie wykresu danego typu ładunku
STR_GRAPH_CARGO_PAYMENT_TOGGLE_CARGO :{BLACK}Przełącz ukrywanie/wyświetlanie wykresu ładunku danego typu
STR_GRAPH_CARGO_PAYMENT_CARGO :{TINY_FONT}{BLACK}{STRING}
STR_GRAPH_INDUSTRY_CAPTION :{WHITE}{INDUSTRY} - Historia Ładunków
STR_GRAPH_INDUSTRY_RANGE_PRODUCED :Wyprodukowano
STR_GRAPH_INDUSTRY_RANGE_TRANSPORTED :Przetransportowano
STR_GRAPH_INDUSTRY_RANGE_DELIVERED :Dostarczono
STR_GRAPH_INDUSTRY_RANGE_WAITING :Oczekujący
STR_GRAPH_PERFORMANCE_DETAIL_TOOLTIP :{BLACK}Pokaż szczegóły oceny wydajności
@ -4403,6 +4406,8 @@ STR_INDUSTRY_VIEW_PRODUCTION_LAST_MONTH_TITLE :{BLACK}Wyproduk
STR_INDUSTRY_VIEW_PRODUCTION_LAST_MINUTE_TITLE :{BLACK}Wyprodukowano w poprzedniej minucie:
STR_INDUSTRY_VIEW_TRANSPORTED :{YELLOW}{CARGO_LONG}{STRING}{BLACK} ({COMMA}% przetransportowano)
STR_INDUSTRY_VIEW_LOCATION_TOOLTIP :{BLACK}Wyśrodkuj widok główny na lokalizacji przedsiębiorstwa. Użyj Ctrl, aby otworzyć nowy podgląd na jego lokalizację
STR_INDUSTRY_VIEW_CARGO_GRAPH :{BLACK}Wykres Produkcji
STR_INDUSTRY_VIEW_CARGO_GRAPH_TOOLTIP :{BLACK}Wyświetl na wykresie historię stanu ładunków w tym przedsiębiorstwie
STR_INDUSTRY_VIEW_PRODUCTION_LEVEL :{BLACK}Poziom produkcji: {YELLOW}{COMMA}%
STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE :{YELLOW}Przedsiębiorstwo ogłosiło likwidację!

View File

@ -20,7 +20,7 @@
##id 0x0000
STR_NULL :
STR_EMPTY :
STR_UNDEFINED :(frase indefinida)
STR_UNDEFINED :(cadeia de caracteres indefinida)
STR_JUST_NOTHING :Nada
# Cargo related strings

View File

@ -59,7 +59,7 @@ static ChangeInfoResult LoadTranslationTable(uint first, uint last, ByteReader &
GRFFile *grf_override = GetCurrentGRFOverride();
if (grf_override != nullptr) {
/* GRF override is present, copy the translation table to the overridden GRF as well. */
GrfMsg(1, "LoadTranslationTable: Copying {} translation table to override GRFID '{}'", name, std::byteswap(grf_override->grfid));
GrfMsg(1, "LoadTranslationTable: Copying {} translation table to override GRFID {:08X}", name, std::byteswap(grf_override->grfid));
std::vector<T> &override_table = gettable(*grf_override);
override_table = translation_table;
}