Changeset - r7932:6b853bdb39ea
[Not reviewed]
master
0 15 0
skidd13 - 17 years ago 2007-11-20 14:11:19
skidd13@openttd.org
(svn r11485) -Codechange: Remove the doubled function ToggleBitT and rename the remaining to fit with the naming style
15 files changed with 29 insertions and 34 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -571,13 +571,13 @@ CommandCost CmdSendAircraftToHangar(Tile
 
		if (!!(p2 & DEPOT_SERVICE) == HasBit(v->current_order.flags, OFB_HALT_IN_DEPOT)) {
 
			/* We called with a different DEPOT_SERVICE setting.
 
			 * Now we change the setting to apply the new one and let the vehicle head for the same hangar.
 
			 * Note: the if is (true for requesting service == true for ordered to stop in hangar) */
 
			if (flags & DC_EXEC) {
 
				ClrBit(v->current_order.flags, OFB_PART_OF_ORDERS);
 
				TOGGLEBIT(v->current_order.flags, OFB_HALT_IN_DEPOT);
 
				ToggleBit(v->current_order.flags, OFB_HALT_IN_DEPOT);
 
				InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
 
			}
 
			return CommandCost();
 
		}
 

	
 
		if (p2 & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of hangar orders
src/graph_gui.cpp
Show inline comments
 
@@ -278,13 +278,13 @@ static void GraphLegendWndProc(Window *w
 
			break;
 
		}
 

	
 
		case WE_CLICK:
 
			if (!IS_INT_INSIDE(e->we.click.widget, 3, 11)) return;
 

	
 
			TOGGLEBIT(_legend_excluded_players, e->we.click.widget - 3);
 
			ToggleBit(_legend_excluded_players, e->we.click.widget - 3);
 
			ToggleWidgetLoweredState(w, e->we.click.widget);
 
			SetWindowDirty(w);
 
			InvalidateWindow(WC_INCOME_GRAPH, 0);
 
			InvalidateWindow(WC_OPERATING_PROFIT, 0);
 
			InvalidateWindow(WC_DELIVERED_CARGO, 0);
 
			InvalidateWindow(WC_PERFORMANCE_HISTORY, 0);
 
@@ -757,13 +757,13 @@ static void CargoPaymentRatesWndProc(Win
 
			DrawString(2 + 84, 24 - 9, STR_7063_PAYMENT_FOR_DELIVERING, TC_FROMSTRING);
 
			break;
 
		}
 

	
 
		case WE_CLICK:
 
			if (e->we.click.widget >= 3) {
 
				TOGGLEBIT(_legend_excluded_cargo, e->we.click.widget - 3);
 
				ToggleBit(_legend_excluded_cargo, e->we.click.widget - 3);
 
				ToggleWidgetLoweredState(w, e->we.click.widget);
 
				SetWindowDirty(w);
 
			}
 
			break;
 
	}
 
}
src/helpers.hpp
Show inline comments
 
@@ -146,17 +146,12 @@ template <typename Tenum_t> struct TinyE
 
	{
 
		if (++m_val >= end) m_val -= (storage_type)(end - begin);
 
		return *this;
 
	}
 
};
 

	
 
template <typename T> void ToggleBitT(T &t, int bit_index)
 
{
 
	t = (T)(t ^ ((T)1 << bit_index));
 
}
 

	
 
/**
 
 * Overflow safe template for integers, i.e. integers that will never overflow
 
 * you multiply the maximum value with 2, or add 2, or substract somethng from
 
 * the minimum value, etc.
 
 * @param T     the type these integers are stored with.
 
 * @param T_MAX the maximum value for the integers.
src/macros.h
Show inline comments
 
@@ -276,15 +276,15 @@ template<typename T> static inline T Clr
 
 * to toggle and starts at the LSB with 0.
 
 *
 
 * @param x The varliable to toggle the bit
 
 * @param y The bit position to toggle
 
 * @return The new value of the old value with the bit toggled
 
 */
 
template<typename T> static inline T TOGGLEBIT(T& x, const uint8 y)
 
template<typename T> static inline T ToggleBit(T& x, const uint8 y)
 
{
 
	return x ^= (T)1U << y;
 
	return x = (T)(x ^ (T)(1U << y));
 
}
 

	
 

	
 
/* checking more bits. Maybe unneccessary, but easy to use */
 
/**
 
 * Check several bits in a value.
src/main_gui.cpp
Show inline comments
 
@@ -164,18 +164,18 @@ static void MenuClickSettings(int index)
 
		case 0: ShowGameOptions();      return;
 
		case 1: ShowGameDifficulty();   return;
 
		case 2: ShowPatchesSelection(); return;
 
		case 3: ShowNewGRFSettings(!_networking, true, true, &_grfconfig);   return;
 
		case 4: ShowTransparencyToolbar(); break;
 

	
 
		case  6: TOGGLEBIT(_display_opt, DO_SHOW_TOWN_NAMES);    break;
 
		case  7: TOGGLEBIT(_display_opt, DO_SHOW_STATION_NAMES); break;
 
		case  8: TOGGLEBIT(_display_opt, DO_SHOW_SIGNS);         break;
 
		case  9: TOGGLEBIT(_display_opt, DO_WAYPOINTS);          break;
 
		case 10: TOGGLEBIT(_display_opt, DO_FULL_ANIMATION);     break;
 
		case 11: TOGGLEBIT(_display_opt, DO_FULL_DETAIL);        break;
 
		case  6: ToggleBit(_display_opt, DO_SHOW_TOWN_NAMES);    break;
 
		case  7: ToggleBit(_display_opt, DO_SHOW_STATION_NAMES); break;
 
		case  8: ToggleBit(_display_opt, DO_SHOW_SIGNS);         break;
 
		case  9: ToggleBit(_display_opt, DO_WAYPOINTS);          break;
 
		case 10: ToggleBit(_display_opt, DO_FULL_ANIMATION);     break;
 
		case 11: ToggleBit(_display_opt, DO_FULL_DETAIL);        break;
 
		case 12:
 
			ToggleTransparency(TO_TREES);
 
			ToggleTransparency(TO_HOUSES);
 
			break;
 
		case 13: ToggleTransparency(TO_SIGNS);                   break;
 
	}
src/order_cmd.cpp
Show inline comments
 
@@ -682,24 +682,24 @@ CommandCost CmdModifyOrder(TileIndex til
 
		return CMD_ERROR;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		switch (p2) {
 
		case OFB_FULL_LOAD:
 
			TOGGLEBIT(order->flags, OFB_FULL_LOAD);
 
			ToggleBit(order->flags, OFB_FULL_LOAD);
 
			if (order->type != OT_GOTO_DEPOT) ClrBit(order->flags, OFB_UNLOAD);
 
			break;
 
		case OFB_UNLOAD:
 
			TOGGLEBIT(order->flags, OFB_UNLOAD);
 
			ToggleBit(order->flags, OFB_UNLOAD);
 
			ClrBit(order->flags, OFB_FULL_LOAD);
 
			break;
 
		case OFB_NON_STOP:
 
			TOGGLEBIT(order->flags, OFB_NON_STOP);
 
			ToggleBit(order->flags, OFB_NON_STOP);
 
			break;
 
		case OFB_TRANSFER:
 
			TOGGLEBIT(order->flags, OFB_TRANSFER);
 
			ToggleBit(order->flags, OFB_TRANSFER);
 
			break;
 
		default: NOT_REACHED();
 
		}
 

	
 
		/* Update the windows and full load flags, also for vehicles that share the same order list */
 
		{
 
@@ -717,13 +717,13 @@ CommandCost CmdModifyOrder(TileIndex til
 
				 * so do not care and those orders should not be active
 
				 * when this function is called.
 
				 */
 
				if (sel_ord == u->cur_order_index &&
 
						u->current_order.type != OT_GOTO_DEPOT &&
 
						HasBit(u->current_order.flags, OFB_FULL_LOAD) != HasBit(order->flags, OFB_FULL_LOAD)) {
 
					TOGGLEBIT(u->current_order.flags, OFB_FULL_LOAD);
 
					ToggleBit(u->current_order.flags, OFB_FULL_LOAD);
 
				}
 
				InvalidateVehicleOrder(u);
 
			}
 
		}
 
	}
 

	
src/player_gui.cpp
Show inline comments
 
@@ -399,13 +399,13 @@ static void SelectPlayerLiveryWndProc(Wi
 
					/* If clicking on the left edge, toggle using the livery */
 
					if (e->we.click.pt.x < 10) {
 
						DoCommandP(0, j | (2 << 8), !GetPlayer((PlayerID)w->window_number)->livery[j].in_use, NULL, CMD_SET_PLAYER_COLOR);
 
					}
 

	
 
					if (_ctrl_pressed) {
 
						TOGGLEBIT(WP(w, livery_d).sel, j);
 
						ToggleBit(WP(w, livery_d).sel, j);
 
					} else {
 
						WP(w, livery_d).sel = 1 << j;
 
					}
 
					SetWindowDirty(w);
 
					break;
 
				}
src/rail_cmd.cpp
Show inline comments
 
@@ -663,13 +663,13 @@ static CommandCost CmdRailTrackHelper(Ti
 

	
 
		if (tile == end_tile) break;
 

	
 
		tile += ToTileIndexDiff(_trackdelta[trackdir]);
 

	
 
		/* toggle railbit for the non-diagonal tracks */
 
		if (!IsDiagonalTrackdir(trackdir)) ToggleBitT(trackdir, 0);
 
		if (!IsDiagonalTrackdir(trackdir)) ToggleBit(trackdir, 0);
 
	}
 

	
 
	return (total_cost.GetCost() == 0) ? CMD_ERROR : total_cost;
 
}
 

	
 
/** Build rail on a stretch of track.
 
@@ -1030,13 +1030,13 @@ static CommandCost CmdSignalTrackHelper(
 
			signal_ctr++;
 

	
 
			/* toggle railbit for the non-diagonal tracks (|, -- tracks) */
 
			if (IsDiagonalTrackdir(trackdir)) {
 
				signal_ctr++;
 
			} else {
 
				ToggleBitT(trackdir, 0);
 
				ToggleBit(trackdir, 0);
 
			}
 
		}
 
	}
 

	
 
	return error ? CMD_ERROR : total_cost;
 
}
src/road_map.h
Show inline comments
 
@@ -215,13 +215,13 @@ static inline bool IsOnSnow(TileIndex t)
 
	return HasBit(_m[t].m3, 7);
 
}
 

	
 
#define ToggleDesert ToggleSnow
 
static inline void ToggleSnow(TileIndex t)
 
{
 
	TOGGLEBIT(_m[t].m3, 7);
 
	ToggleBit(_m[t].m3, 7);
 
}
 

	
 

	
 
enum Roadside {
 
	ROADSIDE_BARREN           = 0,
 
	ROADSIDE_GRASS            = 1,
src/roadveh_cmd.cpp
Show inline comments
 
@@ -479,13 +479,13 @@ CommandCost CmdSendRoadVehToDepot(TileIn
 
		if (!!(p2 & DEPOT_SERVICE) == HasBit(v->current_order.flags, OFB_HALT_IN_DEPOT)) {
 
			/* We called with a different DEPOT_SERVICE setting.
 
			 * Now we change the setting to apply the new one and let the vehicle head for the same depot.
 
			 * Note: the if is (true for requesting service == true for ordered to stop in depot) */
 
			if (flags & DC_EXEC) {
 
				ClrBit(v->current_order.flags, OFB_PART_OF_ORDERS);
 
				TOGGLEBIT(v->current_order.flags, OFB_HALT_IN_DEPOT);
 
				ToggleBit(v->current_order.flags, OFB_HALT_IN_DEPOT);
 
				InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
 
			}
 
			return CommandCost();
 
		}
 

	
 
		if (p2 & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of depot orders
src/ship_cmd.cpp
Show inline comments
 
@@ -1007,13 +1007,13 @@ CommandCost CmdSendShipToDepot(TileIndex
 
		if (!!(p2 & DEPOT_SERVICE) == HasBit(v->current_order.flags, OFB_HALT_IN_DEPOT)) {
 
			/* We called with a different DEPOT_SERVICE setting.
 
			 * Now we change the setting to apply the new one and let the vehicle head for the same depot.
 
			 * Note: the if is (true for requesting service == true for ordered to stop in depot)          */
 
			if (flags & DC_EXEC) {
 
				ClrBit(v->current_order.flags, OFB_PART_OF_ORDERS);
 
				TOGGLEBIT(v->current_order.flags, OFB_HALT_IN_DEPOT);
 
				ToggleBit(v->current_order.flags, OFB_HALT_IN_DEPOT);
 
				InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
 
			}
 
			return CommandCost();
 
		}
 

	
 
		if (p2 & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of depot orders
src/station_gui.cpp
Show inline comments
 
@@ -397,13 +397,13 @@ static void PlayerStationsWndProc(Window
 
				case STATIONLIST_WIDGET_TRAIN:
 
				case STATIONLIST_WIDGET_TRUCK:
 
				case STATIONLIST_WIDGET_BUS:
 
				case STATIONLIST_WIDGET_AIRPLANE:
 
				case STATIONLIST_WIDGET_SHIP:
 
					if (_ctrl_pressed) {
 
						TOGGLEBIT(facilities, e->we.click.widget - STATIONLIST_WIDGET_TRAIN);
 
						ToggleBit(facilities, e->we.click.widget - STATIONLIST_WIDGET_TRAIN);
 
						ToggleWidgetLoweredState(w, e->we.click.widget);
 
					} else {
 
						for (uint i = 0; facilities != 0; i++, facilities >>= 1) {
 
							if (HasBit(facilities, 0)) RaiseWindowWidget(w, i + STATIONLIST_WIDGET_TRAIN);
 
						}
 
						SetBit(facilities, e->we.click.widget - STATIONLIST_WIDGET_TRAIN);
 
@@ -484,13 +484,13 @@ static void PlayerStationsWndProc(Window
 
							if (!GetCargo(c)->IsValid()) continue;
 
							if (e->we.click.widget - STATIONLIST_WIDGET_CARGOSTART == i) break;
 
							i++;
 
						}
 

	
 
						if (_ctrl_pressed) {
 
							TOGGLEBIT(_cargo_filter, c);
 
							ToggleBit(_cargo_filter, c);
 
							ToggleWidgetLoweredState(w, e->we.click.widget);
 
						} else {
 
							for (uint i = STATIONLIST_WIDGET_CARGOSTART; i < w->widget_count; i++) {
 
								RaiseWindowWidget(w, i);
 
							}
 
							RaiseWindowWidget(w, STATIONLIST_WIDGET_NOCARGOWAITING);
src/train_cmd.cpp
Show inline comments
 
@@ -1648,23 +1648,23 @@ CommandCost CmdReverseTrainDirection(Til
 
		/* make sure the vehicle is stopped in the depot */
 
		if (CheckTrainStoppedInDepot(front) < 0) {
 
			return_cmd_error(STR_881A_TRAINS_CAN_ONLY_BE_ALTERED);
 
		}
 

	
 
		if (flags & DC_EXEC) {
 
			TOGGLEBIT(v->u.rail.flags, VRF_REVERSE_DIRECTION);
 
			ToggleBit(v->u.rail.flags, VRF_REVERSE_DIRECTION);
 
			InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 
			InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 
		}
 
	} else {
 
		/* turn the whole train around */
 
		if (v->vehstatus & VS_CRASHED || v->breakdown_ctr != 0) return CMD_ERROR;
 

	
 
		if (flags & DC_EXEC) {
 
			if (_patches.realistic_acceleration && v->cur_speed != 0) {
 
				TOGGLEBIT(v->u.rail.flags, VRF_REVERSING);
 
				ToggleBit(v->u.rail.flags, VRF_REVERSING);
 
			} else {
 
				v->cur_speed = 0;
 
				SetLastSpeed(v, 0);
 
				ReverseTrainDirection(v);
 
			}
 
		}
 
@@ -1905,13 +1905,13 @@ CommandCost CmdSendTrainToDepot(TileInde
 
		if (!!(p2 & DEPOT_SERVICE) == HasBit(v->current_order.flags, OFB_HALT_IN_DEPOT)) {
 
			/* We called with a different DEPOT_SERVICE setting.
 
			 * Now we change the setting to apply the new one and let the vehicle head for the same depot.
 
			 * Note: the if is (true for requesting service == true for ordered to stop in depot)          */
 
			if (flags & DC_EXEC) {
 
				ClrBit(v->current_order.flags, OFB_PART_OF_ORDERS);
 
				TOGGLEBIT(v->current_order.flags, OFB_HALT_IN_DEPOT);
 
				ToggleBit(v->current_order.flags, OFB_HALT_IN_DEPOT);
 
				InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
 
			}
 
			return CommandCost();
 
		}
 

	
 
		if (p2 & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of depot orders
src/transparency.h
Show inline comments
 
@@ -42,13 +42,13 @@ static inline bool IsTransparencySet(Tra
 
 * Toggle the transparency option bit
 
 *
 
 * @param to the structure which transparency option is toggle
 
 */
 
static inline void ToggleTransparency(TransparencyOption to)
 
{
 
	TOGGLEBIT(_transparency_opt, to);
 
	ToggleBit(_transparency_opt, to);
 
}
 

	
 
/** Toggle all transparency options (except signs) or restore the stored transparencies */
 
static inline void ResetRestoreAllTransparency()
 
{
 
	/* backup of the original transparencies or if all transparencies false toggle them to true */
src/window.h
Show inline comments
 
@@ -711,13 +711,13 @@ static inline void SetWindowWidgetLowere
 
 * @param w : Window on which the widget is located
 
 * @param widget_index : index of this widget in the window
 
 */
 
static inline void ToggleWidgetLoweredState(Window *w, byte widget_index)
 
{
 
	assert(widget_index < w->widget_count);
 
	TOGGLEBIT(w->widget[widget_index].display_flags, WIDG_LOWERED);
 
	ToggleBit(w->widget[widget_index].display_flags, WIDG_LOWERED);
 
}
 

	
 
/**
 
 * Marks a widget as lowered.
 
 * @param w : Window on which the widget is located
 
 * @param widget_index : index of this widget in the window
0 comments (0 inline, 0 general)