Codechange: Remove FOR_EACH_SET_CARGO_ID

This commit is contained in:
glx22 2021-06-13 04:29:24 +02:00 committed by Loïc Guilloux
parent 89ab8b79a5
commit a543a4b7bb
5 changed files with 9 additions and 15 deletions

View File

@ -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/bitmath_func.hpp"
#include "core/span_type.hpp" #include "core/span_type.hpp"
#include <vector> #include <vector>
@ -195,6 +196,6 @@ static inline bool IsCargoInClass(CargoID c, CargoClass cc)
return (CargoSpec::Get(c)->classes & cc) != 0; return (CargoSpec::Get(c)->classes & cc) != 0;
} }
#define FOR_EACH_SET_CARGO_ID(var, cargo_bits) FOR_EACH_SET_BIT_EX(CargoID, var, CargoTypes, cargo_bits) using SetCargoBitIterator = SetBitIterator<CargoID, CargoTypes>;
#endif /* CARGOTYPE_H */ #endif /* CARGOTYPE_H */

View File

@ -1480,9 +1480,8 @@ static void HandleStationRefit(Vehicle *v, CargoArray &consist_capleft, Station
bool is_auto_refit = new_cid == CT_AUTO_REFIT; bool is_auto_refit = new_cid == CT_AUTO_REFIT;
if (is_auto_refit) { if (is_auto_refit) {
/* Get a refittable cargo type with waiting cargo for next_station or INVALID_STATION. */ /* Get a refittable cargo type with waiting cargo for next_station or INVALID_STATION. */
CargoID cid;
new_cid = v_start->cargo_type; new_cid = v_start->cargo_type;
FOR_EACH_SET_CARGO_ID(cid, refit_mask) { for (CargoID cid : SetCargoBitIterator(refit_mask)) {
if (st->goods[cid].cargo.HasCargoFor(next_station)) { if (st->goods[cid].cargo.HasCargoFor(next_station)) {
/* Try to find out if auto-refitting would succeed. In case the refit is allowed, /* Try to find out if auto-refitting would succeed. In case the refit is allowed,
* the returned refit capacity will be greater than zero. */ * the returned refit capacity will be greater than zero. */

View File

@ -65,8 +65,7 @@ void LinkGraphOverlay::RebuildCache()
StationLinkMap &seen_links = this->cached_links[from]; StationLinkMap &seen_links = this->cached_links[from];
uint supply = 0; uint supply = 0;
CargoID c; for (CargoID c : SetCargoBitIterator(this->cargo_mask)) {
FOR_EACH_SET_CARGO_ID(c, this->cargo_mask) {
if (!CargoSpec::Get(c)->IsValid()) continue; if (!CargoSpec::Get(c)->IsValid()) continue;
if (!LinkGraph::IsValidID(sta->goods[c].link_graph)) continue; if (!LinkGraph::IsValidID(sta->goods[c].link_graph)) continue;
const LinkGraph &lg = *LinkGraph::Get(sta->goods[c].link_graph); const LinkGraph &lg = *LinkGraph::Get(sta->goods[c].link_graph);
@ -192,8 +191,7 @@ inline bool LinkGraphOverlay::IsLinkVisible(Point pta, Point ptb, const DrawPixe
*/ */
void LinkGraphOverlay::AddLinks(const Station *from, const Station *to) void LinkGraphOverlay::AddLinks(const Station *from, const Station *to)
{ {
CargoID c; for (CargoID c : SetCargoBitIterator(this->cargo_mask)) {
FOR_EACH_SET_CARGO_ID(c, this->cargo_mask) {
if (!CargoSpec::Get(c)->IsValid()) continue; if (!CargoSpec::Get(c)->IsValid()) continue;
const GoodsEntry &ge = from->goods[c]; const GoodsEntry &ge = from->goods[c];
if (!LinkGraph::IsValidID(ge.link_graph) || if (!LinkGraph::IsValidID(ge.link_graph) ||

View File

@ -8902,8 +8902,7 @@ static void CalculateRefitMasks()
if (cargo_map_for_first_refittable != nullptr) { if (cargo_map_for_first_refittable != nullptr) {
/* Use first refittable cargo from cargo translation table */ /* Use first refittable cargo from cargo translation table */
byte best_local_slot = 0xFF; byte best_local_slot = 0xFF;
CargoID cargo_type; for (CargoID cargo_type : SetCargoBitIterator(ei->refit_mask)) {
FOR_EACH_SET_CARGO_ID(cargo_type, ei->refit_mask) {
byte local_slot = cargo_map_for_first_refittable[cargo_type]; byte local_slot = cargo_map_for_first_refittable[cargo_type];
if (local_slot < best_local_slot) { if (local_slot < best_local_slot) {
best_local_slot = local_slot; best_local_slot = local_slot;

View File

@ -273,8 +273,7 @@ protected:
{ {
int diff = 0; int diff = 0;
CargoID j; for (CargoID j : SetCargoBitIterator(cargo_filter)) {
FOR_EACH_SET_CARGO_ID(j, cargo_filter) {
diff += a->goods[j].cargo.TotalCount() - b->goods[j].cargo.TotalCount(); diff += a->goods[j].cargo.TotalCount() - b->goods[j].cargo.TotalCount();
} }
@ -286,8 +285,7 @@ protected:
{ {
int diff = 0; int diff = 0;
CargoID j; for (CargoID j : SetCargoBitIterator(cargo_filter)) {
FOR_EACH_SET_CARGO_ID(j, cargo_filter) {
diff += a->goods[j].cargo.AvailableCount() - b->goods[j].cargo.AvailableCount(); diff += a->goods[j].cargo.AvailableCount() - b->goods[j].cargo.AvailableCount();
} }
@ -300,8 +298,7 @@ protected:
byte maxr1 = 0; byte maxr1 = 0;
byte maxr2 = 0; byte maxr2 = 0;
CargoID j; for (CargoID j : SetCargoBitIterator(cargo_filter)) {
FOR_EACH_SET_CARGO_ID(j, cargo_filter) {
if (a->goods[j].HasRating()) maxr1 = std::max(maxr1, a->goods[j].rating); if (a->goods[j].HasRating()) maxr1 = std::max(maxr1, a->goods[j].rating);
if (b->goods[j].HasRating()) maxr2 = std::max(maxr2, b->goods[j].rating); if (b->goods[j].HasRating()) maxr2 = std::max(maxr2, b->goods[j].rating);
} }