mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Remove FOR_ALL_SORTED_STANDARD_CARGOSPECS
parent
87eb997be0
commit
5844027eb8
|
@ -1186,8 +1186,7 @@ struct BuildVehicleWindow : Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Collect available cargo types for filtering. */
|
/* Collect available cargo types for filtering. */
|
||||||
const CargoSpec *cs;
|
for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
|
||||||
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
|
|
||||||
this->cargo_filter[filter_items] = cs->Index();
|
this->cargo_filter[filter_items] = cs->Index();
|
||||||
this->cargo_filter_texts[filter_items] = cs->name;
|
this->cargo_filter_texts[filter_items] = cs->name;
|
||||||
filter_items++;
|
filter_items++;
|
||||||
|
|
|
@ -149,8 +149,8 @@ SpriteID CargoSpec::GetCargoIcon() const
|
||||||
return sprite;
|
return sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<const CargoSpec *> _sorted_cargo_specs; ///< Cargo specifications sorted alphabetically by name.
|
std::vector<const CargoSpec *> _sorted_cargo_specs; ///< Cargo specifications sorted alphabetically by name.
|
||||||
uint8 _sorted_standard_cargo_specs_size; ///< Number of standard cargo specifications stored in the _sorted_cargo_specs array.
|
span<const CargoSpec *> _sorted_standard_cargo_specs; ///< Standard cargo specifications sorted alphabetically by name.
|
||||||
|
|
||||||
/** Sort cargo specifications by their name. */
|
/** Sort cargo specifications by their name. */
|
||||||
static bool CargoSpecNameSorter(const CargoSpec * const &a, const CargoSpec * const &b)
|
static bool CargoSpecNameSorter(const CargoSpec * const &a, const CargoSpec * const &b)
|
||||||
|
@ -196,13 +196,16 @@ void InitializeSortedCargoSpecs()
|
||||||
/* Sort cargo specifications by cargo class and name. */
|
/* Sort cargo specifications by cargo class and name. */
|
||||||
std::sort(_sorted_cargo_specs.begin(), _sorted_cargo_specs.end(), &CargoSpecClassSorter);
|
std::sort(_sorted_cargo_specs.begin(), _sorted_cargo_specs.end(), &CargoSpecClassSorter);
|
||||||
|
|
||||||
|
/* Count the number of standard cargos and fill the mask. */
|
||||||
_standard_cargo_mask = 0;
|
_standard_cargo_mask = 0;
|
||||||
|
uint8 nb_standard_cargo = 0;
|
||||||
_sorted_standard_cargo_specs_size = 0;
|
|
||||||
for (const auto &cargo : _sorted_cargo_specs) {
|
for (const auto &cargo : _sorted_cargo_specs) {
|
||||||
if (cargo->classes & CC_SPECIAL) break;
|
if (cargo->classes & CC_SPECIAL) break;
|
||||||
_sorted_standard_cargo_specs_size++;
|
nb_standard_cargo++;
|
||||||
SetBit(_standard_cargo_mask, cargo->Index());
|
SetBit(_standard_cargo_mask, cargo->Index());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* _sorted_standard_cargo_specs is a subset of _sorted_cargo_specs. */
|
||||||
|
_sorted_standard_cargo_specs = { _sorted_cargo_specs.data(), nb_standard_cargo };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "gfx_type.h"
|
#include "gfx_type.h"
|
||||||
#include "strings_type.h"
|
#include "strings_type.h"
|
||||||
#include "landscape_type.h"
|
#include "landscape_type.h"
|
||||||
|
#include "core/span_type.hpp"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
/** Globally unique label of a cargo type. */
|
/** Globally unique label of a cargo type. */
|
||||||
|
@ -181,7 +182,7 @@ CargoID GetDefaultCargoID(LandscapeID l, CargoType ct);
|
||||||
|
|
||||||
void InitializeSortedCargoSpecs();
|
void InitializeSortedCargoSpecs();
|
||||||
extern std::vector<const CargoSpec *> _sorted_cargo_specs;
|
extern std::vector<const CargoSpec *> _sorted_cargo_specs;
|
||||||
extern uint8 _sorted_standard_cargo_specs_size;
|
extern span<const CargoSpec *> _sorted_standard_cargo_specs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does cargo \a c have cargo class \a cc?
|
* Does cargo \a c have cargo class \a cc?
|
||||||
|
@ -196,11 +197,4 @@ static inline bool IsCargoInClass(CargoID c, CargoClass cc)
|
||||||
|
|
||||||
#define FOR_EACH_SET_CARGO_ID(var, cargo_bits) FOR_EACH_SET_BIT_EX(CargoID, var, CargoTypes, cargo_bits)
|
#define FOR_EACH_SET_CARGO_ID(var, cargo_bits) FOR_EACH_SET_BIT_EX(CargoID, var, CargoTypes, cargo_bits)
|
||||||
|
|
||||||
/**
|
|
||||||
* Loop header for iterating over 'real' cargoes, sorted by name. Phony cargoes like regearing cargoes are skipped.
|
|
||||||
* @param var Reference getting the cargospec.
|
|
||||||
* @see CargoSpec
|
|
||||||
*/
|
|
||||||
#define FOR_ALL_SORTED_STANDARD_CARGOSPECS(var) for (uint8 index = 0; index < _sorted_standard_cargo_specs_size && (var = _sorted_cargo_specs[index], true); index++)
|
|
||||||
|
|
||||||
#endif /* CARGOTYPE_H */
|
#endif /* CARGOTYPE_H */
|
||||||
|
|
|
@ -892,7 +892,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
|
||||||
|
|
||||||
this->CreateNestedTree();
|
this->CreateNestedTree();
|
||||||
this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR);
|
this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR);
|
||||||
this->vscroll->SetCount(_sorted_standard_cargo_specs_size);
|
this->vscroll->SetCount(static_cast<int>(_sorted_standard_cargo_specs.size()));
|
||||||
|
|
||||||
/* Initialise the dataset */
|
/* Initialise the dataset */
|
||||||
this->OnHundredthTick();
|
this->OnHundredthTick();
|
||||||
|
@ -911,8 +911,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
|
||||||
this->excluded_data = 0;
|
this->excluded_data = 0;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
const CargoSpec *cs;
|
for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
|
||||||
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
|
|
||||||
if (HasBit(_legend_excluded_cargo, cs->Index())) SetBit(this->excluded_data, i);
|
if (HasBit(_legend_excluded_cargo, cs->Index())) SetBit(this->excluded_data, i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -925,8 +924,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CargoSpec *cs;
|
for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
|
||||||
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
|
|
||||||
SetDParam(0, cs->name);
|
SetDParam(0, cs->name);
|
||||||
Dimension d = GetStringBoundingBox(STR_GRAPH_CARGO_PAYMENT_CARGO);
|
Dimension d = GetStringBoundingBox(STR_GRAPH_CARGO_PAYMENT_CARGO);
|
||||||
d.width += this->legend_width + 4; // colour field
|
d.width += this->legend_width + 4; // colour field
|
||||||
|
@ -958,8 +956,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
|
||||||
int pos = this->vscroll->GetPosition();
|
int pos = this->vscroll->GetPosition();
|
||||||
int max = pos + this->vscroll->GetCapacity();
|
int max = pos + this->vscroll->GetCapacity();
|
||||||
|
|
||||||
const CargoSpec *cs;
|
for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
|
||||||
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
|
|
||||||
if (pos-- > 0) continue;
|
if (pos-- > 0) continue;
|
||||||
if (--max < 0) break;
|
if (--max < 0) break;
|
||||||
|
|
||||||
|
@ -993,8 +990,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
|
||||||
case WID_CPR_DISABLE_CARGOES: {
|
case WID_CPR_DISABLE_CARGOES: {
|
||||||
/* Add all cargoes to the excluded lists. */
|
/* Add all cargoes to the excluded lists. */
|
||||||
int i = 0;
|
int i = 0;
|
||||||
const CargoSpec *cs;
|
for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
|
||||||
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
|
|
||||||
SetBit(_legend_excluded_cargo, cs->Index());
|
SetBit(_legend_excluded_cargo, cs->Index());
|
||||||
SetBit(this->excluded_data, i);
|
SetBit(this->excluded_data, i);
|
||||||
i++;
|
i++;
|
||||||
|
@ -1007,8 +1003,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
|
||||||
uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_CPR_MATRIX);
|
uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_CPR_MATRIX);
|
||||||
if (row >= this->vscroll->GetCount()) return;
|
if (row >= this->vscroll->GetCount()) return;
|
||||||
|
|
||||||
const CargoSpec *cs;
|
for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
|
||||||
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
|
|
||||||
if (row-- > 0) continue;
|
if (row-- > 0) continue;
|
||||||
|
|
||||||
ToggleBit(_legend_excluded_cargo, cs->Index());
|
ToggleBit(_legend_excluded_cargo, cs->Index());
|
||||||
|
@ -1047,8 +1042,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
|
||||||
this->UpdateExcludedData();
|
this->UpdateExcludedData();
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
const CargoSpec *cs;
|
for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
|
||||||
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
|
|
||||||
this->colours[i] = cs->legend_colour;
|
this->colours[i] = cs->legend_colour;
|
||||||
for (uint j = 0; j != 20; j++) {
|
for (uint j = 0; j != 20; j++) {
|
||||||
this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, cs->Index());
|
this->cost[i][j] = GetTransportedGoodsIncome(10, 20, j * 4 + 4, cs->Index());
|
||||||
|
|
|
@ -1375,8 +1375,7 @@ protected:
|
||||||
filter_items++;
|
filter_items++;
|
||||||
|
|
||||||
/* Collect available cargo types for filtering. */
|
/* Collect available cargo types for filtering. */
|
||||||
const CargoSpec *cs;
|
for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
|
||||||
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
|
|
||||||
this->cargo_filter[filter_items] = cs->Index();
|
this->cargo_filter[filter_items] = cs->Index();
|
||||||
this->cargo_filter_texts[filter_items] = cs->name;
|
this->cargo_filter_texts[filter_items] = cs->name;
|
||||||
filter_items++;
|
filter_items++;
|
||||||
|
@ -2995,8 +2994,7 @@ struct IndustryCargoesWindow : public Window {
|
||||||
|
|
||||||
case WID_IC_CARGO_DROPDOWN: {
|
case WID_IC_CARGO_DROPDOWN: {
|
||||||
DropDownList lst;
|
DropDownList lst;
|
||||||
const CargoSpec *cs;
|
for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
|
||||||
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
|
|
||||||
lst.emplace_back(new DropDownListStringItem(cs->name, cs->Index(), false));
|
lst.emplace_back(new DropDownListStringItem(cs->name, cs->Index(), false));
|
||||||
}
|
}
|
||||||
if (!lst.empty()) {
|
if (!lst.empty()) {
|
||||||
|
|
|
@ -347,10 +347,12 @@ public:
|
||||||
this->FinishInitNested(window_number);
|
this->FinishInitNested(window_number);
|
||||||
this->owner = (Owner)this->window_number;
|
this->owner = (Owner)this->window_number;
|
||||||
|
|
||||||
const CargoSpec *cs;
|
uint8 index = 0;
|
||||||
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
|
for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
|
||||||
if (!HasBit(this->cargo_filter, cs->Index())) continue;
|
if (HasBit(this->cargo_filter, cs->Index())) {
|
||||||
this->LowerWidget(WID_STL_CARGOSTART + index);
|
this->LowerWidget(WID_STL_CARGOSTART + index);
|
||||||
|
}
|
||||||
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->cargo_filter == this->cargo_filter_max) this->cargo_filter = _cargo_mask;
|
if (this->cargo_filter == this->cargo_filter_max) this->cargo_filter = _cargo_mask;
|
||||||
|
@ -396,8 +398,7 @@ public:
|
||||||
|
|
||||||
/* Determine appropriate width for mini station rating graph */
|
/* Determine appropriate width for mini station rating graph */
|
||||||
this->rating_width = 0;
|
this->rating_width = 0;
|
||||||
const CargoSpec *cs;
|
for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
|
||||||
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
|
|
||||||
this->rating_width = std::max(this->rating_width, GetStringBoundingBox(cs->abbrev).width);
|
this->rating_width = std::max(this->rating_width, GetStringBoundingBox(cs->abbrev).width);
|
||||||
}
|
}
|
||||||
/* Approximately match original 16 pixel wide rating bars by multiplying string width by 1.6 */
|
/* Approximately match original 16 pixel wide rating bars by multiplying string width by 1.6 */
|
||||||
|
@ -465,8 +466,8 @@ public:
|
||||||
x += rtl ? -text_spacing : text_spacing;
|
x += rtl ? -text_spacing : text_spacing;
|
||||||
|
|
||||||
/* show cargo waiting and station ratings */
|
/* show cargo waiting and station ratings */
|
||||||
for (uint j = 0; j < _sorted_standard_cargo_specs_size; j++) {
|
for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
|
||||||
CargoID cid = _sorted_cargo_specs[j]->Index();
|
CargoID cid = cs->Index();
|
||||||
if (st->goods[cid].cargo.TotalCount() > 0) {
|
if (st->goods[cid].cargo.TotalCount() > 0) {
|
||||||
/* For RTL we work in exactly the opposite direction. So
|
/* For RTL we work in exactly the opposite direction. So
|
||||||
* decrement the space needed first, then draw to the left
|
* decrement the space needed first, then draw to the left
|
||||||
|
@ -581,7 +582,7 @@ public:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_STL_CARGOALL: {
|
case WID_STL_CARGOALL: {
|
||||||
for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) {
|
for (uint i = 0; i < _sorted_standard_cargo_specs.size(); i++) {
|
||||||
this->LowerWidget(WID_STL_CARGOSTART + i);
|
this->LowerWidget(WID_STL_CARGOSTART + i);
|
||||||
}
|
}
|
||||||
this->LowerWidget(WID_STL_NOCARGOWAITING);
|
this->LowerWidget(WID_STL_NOCARGOWAITING);
|
||||||
|
@ -607,7 +608,7 @@ public:
|
||||||
this->include_empty = !this->include_empty;
|
this->include_empty = !this->include_empty;
|
||||||
this->ToggleWidgetLoweredState(WID_STL_NOCARGOWAITING);
|
this->ToggleWidgetLoweredState(WID_STL_NOCARGOWAITING);
|
||||||
} else {
|
} else {
|
||||||
for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) {
|
for (uint i = 0; i < _sorted_standard_cargo_specs.size(); i++) {
|
||||||
this->RaiseWidget(WID_STL_CARGOSTART + i);
|
this->RaiseWidget(WID_STL_CARGOSTART + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -629,7 +630,7 @@ public:
|
||||||
ToggleBit(this->cargo_filter, cs->Index());
|
ToggleBit(this->cargo_filter, cs->Index());
|
||||||
this->ToggleWidgetLoweredState(widget);
|
this->ToggleWidgetLoweredState(widget);
|
||||||
} else {
|
} else {
|
||||||
for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) {
|
for (uint i = 0; i < _sorted_standard_cargo_specs.size(); i++) {
|
||||||
this->RaiseWidget(WID_STL_CARGOSTART + i);
|
this->RaiseWidget(WID_STL_CARGOSTART + i);
|
||||||
}
|
}
|
||||||
this->RaiseWidget(WID_STL_NOCARGOWAITING);
|
this->RaiseWidget(WID_STL_NOCARGOWAITING);
|
||||||
|
@ -724,7 +725,7 @@ static NWidgetBase *CargoWidgets(int *biggest_index)
|
||||||
{
|
{
|
||||||
NWidgetHorizontal *container = new NWidgetHorizontal();
|
NWidgetHorizontal *container = new NWidgetHorizontal();
|
||||||
|
|
||||||
for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) {
|
for (uint i = 0; i < _sorted_standard_cargo_specs.size(); i++) {
|
||||||
NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, WID_STL_CARGOSTART + i);
|
NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, WID_STL_CARGOSTART + i);
|
||||||
panel->SetMinimalSize(14, 0);
|
panel->SetMinimalSize(14, 0);
|
||||||
panel->SetMinimalTextLines(1, 0, FS_NORMAL);
|
panel->SetMinimalTextLines(1, 0, FS_NORMAL);
|
||||||
|
@ -733,7 +734,7 @@ static NWidgetBase *CargoWidgets(int *biggest_index)
|
||||||
panel->SetDataTip(0, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE);
|
panel->SetDataTip(0, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE);
|
||||||
container->Add(panel);
|
container->Add(panel);
|
||||||
}
|
}
|
||||||
*biggest_index = WID_STL_CARGOSTART + _sorted_standard_cargo_specs_size;
|
*biggest_index = WID_STL_CARGOSTART + static_cast<int>(_sorted_standard_cargo_specs.size());
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1859,8 +1860,7 @@ struct StationViewWindow : public Window {
|
||||||
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_STATION_VIEW_SUPPLY_RATINGS_TITLE);
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_STATION_VIEW_SUPPLY_RATINGS_TITLE);
|
||||||
y += FONT_HEIGHT_NORMAL;
|
y += FONT_HEIGHT_NORMAL;
|
||||||
|
|
||||||
const CargoSpec *cs;
|
for (const CargoSpec *cs : _sorted_standard_cargo_specs) {
|
||||||
FOR_ALL_SORTED_STANDARD_CARGOSPECS(cs) {
|
|
||||||
const GoodsEntry *ge = &st->goods[cs->Index()];
|
const GoodsEntry *ge = &st->goods[cs->Index()];
|
||||||
if (!ge->HasRating()) continue;
|
if (!ge->HasRating()) continue;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue