Changeset - r22106:9f889ce267c7
[Not reviewed]
master
0 2 0
frosch - 9 years ago 2015-05-09 09:24:19
frosch@openttd.org
(svn r27277) -Codechange: Make _displayed_industries a std::bitset.
2 files changed with 18 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/industry_gui.cpp
Show inline comments
 
@@ -42,12 +42,12 @@
 

	
 
#include "table/strings.h"
 

	
 
#include <bitset>
 

	
 
#include "safeguards.h"
 

	
 
bool _ignore_restrictions;
 
uint64 _displayed_industries; ///< Communication from the industry chain window to the smallmap window about what industries to display.
 

	
 
assert_compile(NUM_INDUSTRYTYPES <= 64); // Make sure all industry types fit in _displayed_industries.
 
std::bitset<NUM_INDUSTRYTYPES> _displayed_industries; ///< Communication from the industry chain window to the smallmap window about what industries to display.
 

	
 
/** Cargo suffix type (for which window is it requested) */
 
enum CargoSuffixType {
 
@@ -229,7 +229,7 @@ class BuildIndustryWindow : public Windo
 
		 * The tests performed after the enabled allow to load the industries
 
		 * In the same way they are inserted by grf (if any)
 
		 */
 
		for (uint8 i = 0; i < NUM_INDUSTRYTYPES; i++) {
 
		for (uint i = 0; i < NUM_INDUSTRYTYPES; i++) {
 
			IndustryType ind = _sorted_industry_types[i];
 
			const IndustrySpec *indsp = GetIndustrySpec(ind);
 
			if (indsp->enabled) {
 
@@ -2295,7 +2295,8 @@ struct IndustryCargoesWindow : public Wi
 
	{
 
		this->GetWidget<NWidgetCore>(WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION;
 
		this->ind_cargo = it;
 
		_displayed_industries = 1ULL << it;
 
		_displayed_industries.reset();
 
		_displayed_industries.set(it);
 

	
 
		this->fields.Clear();
 
		CargoesRow *row = this->fields.Append();
 
@@ -2339,12 +2340,12 @@ struct IndustryCargoesWindow : public Wi
 

	
 
			if (HasCommonValidCargo(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo), indsp->produced_cargo, lengthof(indsp->produced_cargo))) {
 
				this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
 
				SetBit(_displayed_industries, it);
 
				_displayed_industries.set(it);
 
				supp_count++;
 
			}
 
			if (HasCommonValidCargo(central_sp->produced_cargo, lengthof(central_sp->produced_cargo), indsp->accepts_cargo, lengthof(indsp->accepts_cargo))) {
 
				this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 4, it);
 
				SetBit(_displayed_industries, it);
 
				_displayed_industries.set(it);
 
				cust_count++;
 
			}
 
		}
 
@@ -2373,7 +2374,7 @@ struct IndustryCargoesWindow : public Wi
 
	{
 
		this->GetWidget<NWidgetCore>(WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_CARGO_CAPTION;
 
		this->ind_cargo = cid + NUM_INDUSTRYTYPES;
 
		_displayed_industries = 0;
 
		_displayed_industries.reset();
 

	
 
		this->fields.Clear();
 
		CargoesRow *row = this->fields.Append();
 
@@ -2408,12 +2409,12 @@ struct IndustryCargoesWindow : public Wi
 

	
 
			if (HasCommonValidCargo(&cid, 1, indsp->produced_cargo, lengthof(indsp->produced_cargo))) {
 
				this->PlaceIndustry(1 + supp_count * num_indrows / num_supp, 0, it);
 
				SetBit(_displayed_industries, it);
 
				_displayed_industries.set(it);
 
				supp_count++;
 
			}
 
			if (HasCommonValidCargo(&cid, 1, indsp->accepts_cargo, lengthof(indsp->accepts_cargo))) {
 
				this->PlaceIndustry(1 + cust_count * num_indrows / num_cust, 2, it);
 
				SetBit(_displayed_industries, it);
 
				_displayed_industries.set(it);
 
				cust_count++;
 
			}
 
		}
 
@@ -2604,7 +2605,7 @@ struct IndustryCargoesWindow : public Wi
 

	
 
			case WID_IC_IND_DROPDOWN: {
 
				DropDownList *lst = new DropDownList;
 
				for (uint8 i = 0; i < NUM_INDUSTRYTYPES; i++) {
 
				for (uint i = 0; i < NUM_INDUSTRYTYPES; i++) {
 
					IndustryType ind = _sorted_industry_types[i];
 
					const IndustrySpec *indsp = GetIndustrySpec(ind);
 
					if (!indsp->enabled) continue;
 
@@ -2691,7 +2692,7 @@ const int IndustryCargoesWindow::VERT_TE
 
static void ShowIndustryCargoesWindow(IndustryType id)
 
{
 
	if (id >= NUM_INDUSTRYTYPES) {
 
		for (uint8 i = 0; i < NUM_INDUSTRYTYPES; i++) {
 
		for (uint i = 0; i < NUM_INDUSTRYTYPES; i++) {
 
			const IndustrySpec *indsp = GetIndustrySpec(_sorted_industry_types[i]);
 
			if (indsp->enabled) {
 
				id = _sorted_industry_types[i];
src/smallmap_gui.cpp
Show inline comments
 
@@ -28,6 +28,8 @@
 

	
 
#include "table/strings.h"
 

	
 
#include <bitset>
 

	
 
#include "safeguards.h"
 

	
 
static int _smallmap_industry_count; ///< Number of used industries
 
@@ -175,7 +177,7 @@ void BuildIndustriesLegend()
 
	uint j = 0;
 

	
 
	/* Add each name */
 
	for (uint8 i = 0; i < NUM_INDUSTRYTYPES; i++) {
 
	for (uint i = 0; i < NUM_INDUSTRYTYPES; i++) {
 
		IndustryType ind = _sorted_industry_types[i];
 
		const IndustrySpec *indsp = GetIndustrySpec(ind);
 
		if (indsp->enabled) {
 
@@ -1507,11 +1509,11 @@ int SmallMapWindow::GetPositionOnLegend(
 
			break;
 

	
 
		case 0: {
 
			extern uint64 _displayed_industries;
 
			extern std::bitset<NUM_INDUSTRYTYPES> _displayed_industries;
 
			if (this->map_type != SMT_INDUSTRY) this->SwitchMapType(SMT_INDUSTRY);
 

	
 
			for (int i = 0; i != _smallmap_industry_count; i++) {
 
				_legend_from_industries[i].show_on_map = HasBit(_displayed_industries, _legend_from_industries[i].type);
 
				_legend_from_industries[i].show_on_map = _displayed_industries.test(_legend_from_industries[i].type);
 
			}
 
			break;
 
		}
0 comments (0 inline, 0 general)