OpenTTD
|
Functions related to bit mathematics. More...
Go to the source code of this file.
Macros | |
#define | SETBITS(x, y) ((x) |= (y)) |
Sets several bits in a variable. | |
#define | CLRBITS(x, y) ((x) &= ~(y)) |
Clears several bits in a variable. | |
#define | FIND_FIRST_BIT(x) _ffb_64[(x)] |
Returns the first non-zero bit in a 6-bit value (from right). | |
#define | FOR_EACH_SET_BIT_EX(Tbitpos_type, bitpos_var, Tbitset_type, bitset_value) |
Do an operation for each set bit in a value. | |
#define | FOR_EACH_SET_BIT(bitpos_var, bitset_value) FOR_EACH_SET_BIT_EX(uint, bitpos_var, uint, bitset_value) |
Do an operation for each set set bit in a value. |
Functions | |
template<typename T > | |
static uint | GB (const T x, const uint8 s, const uint8 n) |
Fetch n bits from x, started at bit s. | |
template<typename T , typename U > | |
static T | SB (T &x, const uint8 s, const uint8 n, const U d) |
Set n bits in x starting at bit s to d. | |
template<typename T , typename U > | |
static T | AB (T &x, const uint8 s, const uint8 n, const U i) |
Add i to n bits of x starting at bit s. | |
template<typename T > | |
static bool | HasBit (const T x, const uint8 y) |
Checks if a bit in a value is set. | |
template<typename T > | |
static T | SetBit (T &x, const uint8 y) |
Set a bit in a variable. | |
template<typename T > | |
static T | ClrBit (T &x, const uint8 y) |
Clears a bit in a variable. | |
template<typename T > | |
static T | ToggleBit (T &x, const uint8 y) |
Toggles a bit in a variable. | |
static uint8 | FindFirstBit2x64 (const int value) |
Finds the position of the first non-zero bit in an integer. | |
uint8 | FindFirstBit (uint32 x) |
Search the first set bit in a 32 bit variable. | |
uint8 | FindLastBit (uint64 x) |
Search the last set bit in a 64 bit variable. | |
template<typename T > | |
static T | KillFirstBit (T value) |
Clear the first bit in an integer. | |
template<typename T > | |
static uint | CountBits (T value) |
Counts the number of set bits in a variable. | |
template<typename T > | |
static bool | HasExactlyOneBit (T value) |
Test whether value has exactly 1 bit set. | |
template<typename T > | |
static bool | HasAtMostOneBit (T value) |
Test whether value has at most 1 bit set. | |
template<typename T > | |
static T | ROL (const T x, const uint8 n) |
ROtate x Left by n. | |
template<typename T > | |
static T | ROR (const T x, const uint8 n) |
ROtate x Right by n. | |
static uint32 | BSWAP32 (uint32 x) |
Perform a 32 bits endianness bitswap on x. | |
static uint16 | BSWAP16 (uint16 x) |
Perform a 16 bits endianness bitswap on x. |
Variables | |
const uint8 | _ffb_64 [64] |
Lookup table to check which bit is set in a 6 bit variable. |
Functions related to bit mathematics.
Definition in file bitmath_func.hpp.
#define CLRBITS | ( | x, | |
y | |||
) | ((x) &= ~(y)) |
Clears several bits in a variable.
This macro clears several bits in a variable. The bits to clear are provided by a value. The new value is also returned.
x | The variable to clear some bits |
y | The value with set bits for clearing them in the variable |
Definition at line 168 of file bitmath_func.hpp.
Referenced by CheckRoadSlope(), Window::DisableAllWidgetHighlight(), DisasterTick_Zeppeliner(), DropdownWindow::DropdownWindow(), HandleCrashedAircraft(), Vehicle::PreDestructor(), GUIList< const Sign *, StringFilter & >::RebuildDone(), NWidgetCore::SetDisabled(), GUIList< const Sign *, StringFilter & >::SetFiltering(), GUIList< const Sign *, StringFilter & >::SetFilterState(), NWidgetCore::SetHighlighted(), BaseSettingEntry::SetLastField(), GUIList< const Sign *, StringFilter & >::SetListing(), NWidgetCore::SetLowered(), Window::SetWidgetHighlight(), GUIList< const Sign *, StringFilter & >::Sort(), SettingEntry::UpdateFilterState(), SettingsPage::UpdateFilterState(), and UpdateWindows().
#define FIND_FIRST_BIT | ( | x | ) | _ffb_64[(x)] |
Returns the first non-zero bit in a 6-bit value (from right).
Returns the position of the first bit that is not zero, counted from the LSB. Ie, 110100 returns 2, 000001 returns 0, etc. When x == 0 returns 0.
x | The 6-bit value to check the first zero-bit |
Definition at line 202 of file bitmath_func.hpp.
Referenced by CmdBuildRoadStop(), FindFirstBit2x64(), FindFirstTrack(), FloodHalftile(), RemoveFirstTrack(), TrackBitsToTrack(), and TrainController().
#define FOR_EACH_SET_BIT | ( | bitpos_var, | |
bitset_value | |||
) | FOR_EACH_SET_BIT_EX(uint, bitpos_var, uint, bitset_value) |
Do an operation for each set set bit in a value.
This macros is used to do an operation for each set bit in a variable. The first parameter is a variable that is used as the bit position counter. The second parameter is an expression of the bits we need to iterate over. This expression will be evaluated once.
bitpos_var | The position counter variable. |
bitset_value | The value which we check for set bits. |
Definition at line 361 of file bitmath_func.hpp.
Referenced by DrawStationTile(), TownAuthorityWindow::GetNthSetBit(), CompanyStationsWindow::OnClick(), TileLoop_Water(), and TranslateRefitMask().
#define FOR_EACH_SET_BIT_EX | ( | Tbitpos_type, | |
bitpos_var, | |||
Tbitset_type, | |||
bitset_value | |||
) |
Do an operation for each set bit in a value.
This macros is used to do an operation for each set bit in a variable. The second parameter is a variable that is used as the bit position counter. The fourth parameter is an expression of the bits we need to iterate over. This expression will be evaluated once.
Tbitpos_type | Type of the position counter variable. |
bitpos_var | The position counter variable. |
Tbitset_type | Type of the bitset value. |
bitset_value | The bitset value which we check for bits. |
Definition at line 340 of file bitmath_func.hpp.
#define SETBITS | ( | x, | |
y | |||
) | ((x) |= (y)) |
Sets several bits in a variable.
This macro sets several bits in a variable. The bits to set are provided by a value. The new value is also returned.
x | The variable to set some bits |
y | The value with set bits for setting them in the variable |
Definition at line 138 of file bitmath_func.hpp.
Referenced by AirportSetBlocks(), DisasterTick_Zeppeliner(), GUIList< const Sign *, StringFilter & >::ForceRebuild(), GUIList< const Sign *, StringFilter & >::ForceResort(), FreeTerminal(), GUIList< const Sign *, StringFilter & >::NeedResort(), GUIList< const Sign *, StringFilter & >::RebuildDone(), NWidgetCore::SetDisabled(), GUIList< const Sign *, StringFilter & >::SetFiltering(), GUIList< const Sign *, StringFilter & >::SetFilterState(), NWidgetCore::SetHighlighted(), BaseSettingEntry::SetLastField(), GUIList< const Sign *, StringFilter & >::SetListing(), NWidgetCore::SetLowered(), GUIList< const Sign *, StringFilter & >::SetSortType(), SettingEntry::UpdateFilterState(), and SettingsPage::UpdateFilterState().
|
inlinestatic |
Add i to n bits of x starting at bit s.
This adds the value of i on n bits of x starting at bit s. The parameters x, s, i are similar to GB. Besides, \ a x must be a variable as the result are saved there. An overflow does not affect the following bits of the given bit window and is simply ignored.
x | The variable to add some bits at some position |
s | The start position of the addition |
n | The size/window for the addition |
i | The value to add at the given start position in the given window. |
Definition at line 85 of file bitmath_func.hpp.
Referenced by IncHouseConstructionTick(), and IncreaseRoadWorksCounter().
|
inlinestatic |
Perform a 16 bits endianness bitswap on x.
x | the variable to bitswap |
Definition at line 395 of file bitmath_func.hpp.
|
inlinestatic |
Perform a 32 bits endianness bitswap on x.
x | the variable to bitswap |
Definition at line 380 of file bitmath_func.hpp.
Referenced by CargoChangeInfo(), GamelogPrint(), GetNewEngine(), ContentInfo::GetTextfile(), HandleNode(), HandleSavegameLoadCrash(), HasGRFConfig(), IsGoodGRFConfigList(), LoadNewGRF(), LoadNewGRFSound(), LoadTranslationTable(), MakePNGImage(), ObjectChangeInfo(), PrintGrfInfo(), RailTypeChangeInfo(), ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(), SetNewGRFOverride(), ShowMissingContentWindow(), SlArray(), StationChangeInfo(), BasePersistentStorageArray::SwitchMode(), and TranslateGRFStrings().
|
inlinestatic |
Clears a bit in a variable.
This function clears a bit in a variable. The variable is changed and the value is also returned. Parameter y defines the bit to clear and starts at the LSB with 0.
x | The variable to clear the bit |
y | The bit position to clear |
Definition at line 153 of file bitmath_func.hpp.
Referenced by AfterLoadGame(), AircraftHandleDestTooFar(), RoadStop::AllocateBay(), RoadStop::AllocateDriveThroughBay(), Vehicle::BeginLoading(), CargoChangeInfo(), ChangeOwnershipOfCompanyItems(), GroundVehicle< RoadVehicle, VEH_ROAD >::ClearArticulatedPart(), RoadStop::ClearDriveThrough(), GroundVehicle< RoadVehicle, VEH_ROAD >::ClearEngine(), GroundVehicle< RoadVehicle, VEH_ROAD >::ClearFreeWagon(), GroundVehicle< RoadVehicle, VEH_ROAD >::ClearFrontEngine(), GroundVehicle< RoadVehicle, VEH_ROAD >::ClearMultiheaded(), ClearSingleBridgeMiddle(), ClearSnow(), GroundVehicle< RoadVehicle, VEH_ROAD >::ClearWagon(), CmdAutofillTimetable(), CmdBuildBridge(), CmdBuildRailroadTrack(), CmdSetTimetableStart(), CmdSignalTrackHelper(), Train::ConsistChanged(), ConvertOldMultiheadToNew(), CopyGRFConfigList(), GroundVehicle< RoadVehicle, VEH_ROAD >::Crash(), Vehicle::DeleteUnreachedImplicitOrders(), DrawRailCatenaryRailway(), FeatureTownName(), FinaliseEngineArray(), FindSubsidyTownCargoRoute(), FixOldVehicles(), Vehicle::HandlePathfindingResult(), LoadNewGRF(), LoadSpriteTables(), LoadUnloadVehicle(), RoadStop::MakeDriveThrough(), MapSpriteMappingRecolour(), SelectCompanyLiveryWindow::OnInvalidateData(), ParamSet(), PrepareUnload(), ReadSpriteLayout(), ReadSpriteLayoutSprite(), LinkRefresher::RefreshLinks(), RemoveFirstTrack(), RemoveFirstTrackdir(), ReverseTrainDirection(), StationHandleBigTick(), StationMonthlyLoop(), SwapTrainFlags(), ToggleInvisibilityWithTransparency(), TryPathReserve(), UpdateTownGrowRate(), UpdateVehicleTimetable(), GroundVehicle< RoadVehicle, VEH_ROAD >::UpdateZPositionAndInclination(), and VehicleEnterDepot().
|
inlinestatic |
Counts the number of set bits in a variable.
value | the value to count the number of bits in. |
Definition at line 253 of file bitmath_func.hpp.
Referenced by AfterLoadCompanyStats(), CalculateCompanyValue(), CheckFlatLandRoadStop(), CmdBuildBridge(), CmdBuildRoad(), CmdBuildRoadStop(), CmdBuildSingleRail(), CmdBuildSingleSignal(), CmdConvertRail(), CmdGoalQuestion(), CmdRemoveRoadStop(), CmdRemoveSingleRail(), CmdRemoveSingleSignal(), EnginesDailyLoop(), FindSubsidyTownCargoRoute(), RailTypeScopeResolver::GetRandomBits(), RemoveRoad(), ShowBuildBridgeWindow(), ShowRefitOptionsList(), and UpdateCompanyRatingAndValue().
uint8 FindFirstBit | ( | uint32 | x | ) |
Search the first set bit in a 32 bit variable.
This algorithm is a static implementation of a log congruence search algorithm. It checks the first half if there is a bit set search there further. And this way further. If no bit is set return 0.
x | The value to search |
Definition at line 39 of file bitmath_func.cpp.
Referenced by AllocateMap(), CalculateRefitMasks(), and ExploreSegment().
|
inlinestatic |
Finds the position of the first non-zero bit in an integer.
This function returns the position of the first bit set in the integer. It does only check the bits of the bitmask 0x3F3F (0011111100111111) and checks only the bits of the bitmask 0x3F00 if and only if the lower part 0x00FF is 0. This results the bits at 0x00C0 must be also zero to check the bits at 0x3F00.
value | The value to check the first bits |
Definition at line 218 of file bitmath_func.hpp.
References FIND_FIRST_BIT.
Referenced by CYapfBaseT< Types >::AddMultipleNodes(), FindFirstTrackdir(), NPFRoadVehicleChooseTrack(), CYapfCostRoadT< Types >::PfCalcCost(), CYapfCostRailT< Types >::PfCalcCost(), CYapfOriginTileT< Types >::PfSetStartupNodes(), RemoveFirstTrackdir(), RoadFindPathToDest(), and YapfRoadVehicleChooseTrack().
uint8 FindLastBit | ( | uint64 | x | ) |
Search the last set bit in a 64 bit variable.
This algorithm is a static implementation of a log congruence search algorithm. It checks the second half if there is a bit set search there further. And this way further. If no bit is set return 0.
x | The value to search |
Definition at line 67 of file bitmath_func.cpp.
Referenced by BaseGraphWindow::DrawGraph().
|
inlinestatic |
Fetch n bits from x, started at bit s.
This function can be used to fetch n bits from the value x. The s value set the start position to read. The start position is count from the LSB and starts at 0
. The result starts at a LSB, as this isn't just an and-bitmask but also some bit-shifting operations. GB(0xFF, 2, 1) will so return 0x01 (0000 0001) instead of 0x04 (0000 0100).
x | The value to read some bits. |
s | The start position to read some bits. |
n | The number of bits to read. |
Definition at line 34 of file bitmath_func.hpp.
Referenced by AfterLoadGame(), AirportChangeInfo(), AmbientSoundEffectCallback(), AnimationBase< IndustryAnimationBase, IndustryTileSpec, Industry, int, GetSimpleIndustryCallback >::AnimateTile(), Buffer::AppendUtf8(), AreCompanyManagerFaceBitsValid(), BmpRead1(), BmpRead24(), BmpRead4(), BmpRead4Rle(), BmpRead8(), BuildObject(), BuildTownHouse(), CcAddVehicleNewGroup(), CcBuildIndustry(), CcRoadStop(), AnimationBase< IndustryAnimationBase, IndustryTileSpec, Industry, int, GetSimpleIndustryCallback >::ChangeAnimationFrame(), ChangeIndustryProduction(), ChangeTrainDirRandomly(), CmdAddVehicleGroup(), CmdAlterGroup(), CmdAutofillTimetable(), CmdBuildAirport(), CmdBuildBridge(), CmdBuildDock(), CmdBuildIndustry(), CmdBuildObject(), CmdBuildRailStation(), CmdBuildRailWaypoint(), CmdBuildRoadStop(), CmdBuildSingleSignal(), CmdBuildVehicle(), CmdChangeBankBalance(), CmdChangeServiceInt(), CmdChangeTimetable(), CmdClearArea(), CmdCloneOrder(), CmdCompanyCtrl(), CmdCreateGoal(), CmdCreateStoryPage(), CmdCreateStoryPageElement(), CmdCreateSubsidy(), CmdCustomNewsItem(), CmdDeleteOrder(), CmdGoalQuestion(), CmdInsertOrder(), CmdLandscapeClear(), CmdLevelLand(), CmdModifyOrder(), CmdMoveOrder(), CmdMoveRailVehicle(), CmdOrderRefit(), CmdPlantTree(), CmdRefitVehicle(), CmdRemoveRoadStop(), CmdSellVehicle(), CmdSendVehicleToDepot(), CmdSetAutoReplace(), CmdSetCompanyColour(), CmdSetStoryPageDate(), CmdSetStoryPageTitle(), CmdSetTimetableStart(), CmdSetVehicleOnTime(), CmdSetVehicleVisibility(), CmdShowStoryPage(), CmdSignalTrackHelper(), CmdSkipToOrder(), CmdStartStopVehicle(), CmdTerraformLand(), CmdTownCargoGoal(), CmdTownGrowthRate(), CmdUpdateStoryPageElement(), Convert8bitBooleanCallback(), ConvertFromOldCompanyManagerFace(), Blitter_32bppAnim::CopyFromBuffer(), CopyFromOldName(), CreateNewIndustry(), DecodeMonitorCargoType(), DecodeMonitorCompany(), DecodeMonitorIndustry(), DecodeMonitorTown(), Disaster_CoalMine_Init(), DisasterTick_Aircraft(), DisasterTick_Big_Ufo_Destroyer(), DisasterTick_Submarine(), DisasterTick_Zeppeliner(), DoCommandP(), DoCreateNewIndustry(), Blitter_32bppOptimized::Draw(), Blitter_32bppAnim::Draw(), DrawCommonTileSeq(), DrawCommonTileSeqInGUI(), DrawMatrix(), DrawNewObjectTileInGUI(), DrawSprite(), DrawSpriteViewport(), DrawTileLayout(), BuildObjectWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), BuildRailWaypointWindow::DrawWidget(), AIInfo::DummyConstructor(), Extract(), FeatureTownName(), UnmappedChoiceList::Flush(), FormatString(), GamelogPrint(), AI::GameLoop(), GenerateCompanyColour(), GenerateLandscape(), GenerateTrees(), GenRandomRoadBits(), GetAiPurchaseCallbackResult(), GetBridgeAxis(), GetBridgeType(), GetCargoSuffix(), GetCleanHouseType(), GetCleanIndustryGfx(), GetClearCounter(), GetClearDensity(), GetCompanyManagerFaceBits(), GetCompanyManagerFaceSprite(), Order::GetConditionComparator(), Order::GetConditionValue(), Order::GetConditionVariable(), GetCountAndDistanceOfClosestInstance(), GetCrossingRoadAxis(), Order::GetDepotActionType(), Order::GetDepotOrderType(), GetDisallowedRoadDirections(), GetDistanceFromNearbyHouse(), GetFeatureIndex(), GetFeatureNum(), GetFence(), GetFieldType(), GetHouseBuildingStage(), GetHouseConstructionTick(), GetHouseProcessingTime(), GetHouseTriggers(), GetIndustryConstructionCounter(), GetIndustryConstructionStage(), GetIndustryTriggers(), GetLiftDestination(), GetLiftPosition(), GetLoadAmount(), Order::GetLoadType(), GetLockDirection(), GetLockPart(), GetNearbyTile(), Waypoint::GetNewGRFVariable(), GetNextArticulatedPart(), Order::GetNonStopType(), GetPresentSignals(), GetRailDepotDirection(), GetRailReservationTrackBits(), GetRailTileType(), GetRailType(), RailTypeScopeResolver::GetRandomBits(), GetRawClearGround(), GetRefitCostFactor(), GetRoadBits(), GetRoadDepotDirection(), GetRoadOwner(), GetRoadside(), GetRoadTileType(), GetRoadTypes(), VehicleResolverObject::GetScope(), GetShipDepotAxis(), GetShipDepotPart(), GetSignalStates(), GetStationTileRandomBits(), GetStationType(), Order::GetStopLocation(), GetStringWithArgs(), GetTileOwner(), GetTileType(), GetTrackBits(), GetTreeCount(), GetTreeCounter(), GetTreeDensity(), GetTreeGround(), GetTreeGrowth(), GetTropicZone(), GetTunnelBridgeDirection(), GetTunnelBridgeTransportType(), Order::GetType(), SpriteFontCache::GetUnicodeGlyph(), Order::GetUnloadType(), GRFParameterInfo::GetValue(), IndustriesScopeResolver::GetVariable(), TownScopeResolver::GetVariable(), HouseScopeResolver::GetVariable(), VehicleScopeResolver::GetVariable(), StationScopeResolver::GetVariable(), GetWaterClass(), GetWaterTileType(), GfxFillRect(), GlobalVarChangeInfo(), HandleAutoSignalPlacement(), HandleCrashedAircraft(), HandleCrashedTrain(), RoadStop::HasFreeBay(), HeightMapNormalize(), IncHouseConstructionTick(), IncreaseRoadWorksCounter(), IndustriesChangeInfo(), IndustrytilesChangeInfo(), IsBridgeAbove(), Load_VEHS(), LoadChunk(), MakeCzechTownName(), MapGRFStringID(), MapNewGRFIndustryType(), Order::MapOldOrder(), MaybeCrashAirplane(), MirrorRoadBits(), MoveWaypointsToBaseStations(), BuildObjectWindow::OnClick(), BuildRailStationWindow::OnClick(), BuildRailWaypointWindow::OnClick(), TimetableWindow::OnInvalidateData(), OrdersWindow::OnInvalidateData(), VehicleListWindow::OnInvalidateData(), Order::Order(), Blitter_32bppAnim::PaletteAnimate(), ParamSet(), PlaceTree(), PlaceTreeAtSameHeight(), PlaceTreeGroups(), Packet::PrepareToSend(), ReadSpriteLayoutSprite(), ResetRestoreAllTransparency(), DeterministicSpriteGroup::Resolve(), River_Hash(), RotateRoadBits(), ScaleAllCompanyManagerFaceBits(), SeedChance(), Packet::Send_uint16(), Packet::Send_uint32(), Packet::Send_uint64(), SetHouseType(), SetIndustryGfx(), BuildObjectWindow::SetStringParameters(), SpriteFontCache::SetUnicodeGlyph(), SetWaterClassDependingOnSurroundings(), Vehicle::ShowVisualEffect(), SlCalcConvFileLen(), SlCalcConvMemLen(), SpawnAdvancedVisualEffect(), SoundDriver_Win32::Start(), StartTextRefStackUsage(), StartupOneEngine(), StationMonthlyLoop(), TileHash2Bit(), TileLoop_Town(), TownHouseChangeInfo(), TrainCheckIfLineEnds(), TranslateTTDPatchCodes(), TryBuildLightHouse(), VehicleListIdentifier::UnpackIfValid(), UnpackVersion4Order(), UpdateCursorSize(), Vehicle::UpdateVisualEffect(), Utf8Decode(), Utf8Encode(), Utf8EncodedCharLen(), VehicleFromPos(), VehicleFromPosXY(), VehicleRandomBits(), ViewportAddVehicles(), and LanguageWriter::WriteLang().
|
inlinestatic |
Test whether value has at most 1 bit set.
value | the value to test. |
Definition at line 288 of file bitmath_func.hpp.
Referenced by DrawRoadBits(), and ShowRefitOptionsList().
|
inlinestatic |
Checks if a bit in a value is set.
This function checks if a bit inside a value is set or not. The y value specific the position of the bit, started at the LSB and count from 0
.
x | The value to check |
y | The position of the bit to check, started from the LSB |
Definition at line 105 of file bitmath_func.hpp.
Referenced by AcceptEnginePreview(), AddArticulatedParts(), NewGRFWindow::AddGRFToActive(), LinkGraph::AddNode(), AfterLoadGame(), AfterLoadRoadStops(), AfterLoadVehicles(), AircraftHandleDestTooFar(), AircraftVehicleChangeInfo(), RoadStop::AllocateBay(), AnimationBase< IndustryAnimationBase, IndustryTileSpec, Industry, int, GetSimpleIndustryCallback >::AnimateTile(), Vehicle::BeginLoading(), TimetableWindow::BuildArrivalDepartureList(), GameOptionsWindow::BuildDropDownList(), BuildObject(), RefitWindow::BuildRefitList(), BuildReplacementVehicle(), CompanyStationsWindow::BuildStationsList(), BuildTownHouse(), CalcPercentVehicleFilled(), CalculateRefitMasks(), CanBuildVehicleInfrastructure(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanEnterNewTile(), CanEnterTile(), CanRemoveRoadWithStop(), CanStationTileHavePylons(), CanStationTileHaveWires(), CargoFilter(), CcRoadStop(), ChangeIndustryProduction(), ChangeOwnershipOfCompanyItems(), CheckAllowRemoveTunnelBridge(), CheckAutoreplaceValidity(), CheckBuildableTile(), CheckFlatLandRailStation(), CheckFlatLandRoadStop(), CheckIfIndustryTilesAreFree(), RoadStop::Entry::CheckIntegrity(), CheckRoadBlockedForOvertaking(), BuildRailStationWindow::CheckSelectedSize(), CleanIndustryTileTable(), RoadStop::ClearDriveThrough(), CmdAddVehicleGroup(), CmdAlterGroup(), CmdAutofillTimetable(), CmdBuildAirport(), CmdBuildBridge(), CmdBuildDock(), CmdBuildIndustry(), CmdBuildLongRoad(), CmdBuildObject(), CmdBuildRailStation(), CmdBuildRailVehicle(), CmdBuildRailWaypoint(), CmdBuildRoad(), CmdBuildRoadStop(), CmdBuildRoadVehicle(), CmdBuildSingleRail(), CmdBuildSingleSignal(), CmdBuyCompany(), CmdChangeServiceInt(), CmdClearArea(), CmdCloneVehicle(), CmdConvertRail(), CmdDoTownAction(), CmdForceTrainProceed(), CmdFoundTown(), CmdLevelLand(), CmdMassStartStopVehicle(), CmdMoveRailVehicle(), CmdRailTrackHelper(), CmdRefitVehicle(), CmdRemoveFromRailStation(), CmdRemoveFromRailWaypoint(), CmdRemoveLongRoad(), CmdRemoveRoadStop(), CmdReverseTrainDirection(), CmdSellRailWagon(), CmdSetAutoReplace(), CmdSetGroupReplaceProtection(), CmdSetTimetableStart(), CmdSignalTrackHelper(), CmdStartStopVehicle(), CompaniesGenStatistics(), Train::ConsistChanged(), ConvertFromOldCompanyManagerFace(), ConvertOldMultiheadToNew(), BaseConsist::CopyConsistPropertiesFrom(), CountArticulatedParts(), Train::Crash(), CreateGroupFromGroupID(), CreateNewIndustryHelper(), Vehicle::DeleteUnreachedImplicitOrders(), DeliverGoods(), Engine::DetermineCapacity(), DisasterTick_Aircraft(), DisasterTick_Helicopter_Rotors(), DisasterTick_Submarine(), DisasterTick_Ufo(), DisasterTick_Zeppeliner(), DoCreateNewIndustry(), BaseSettingEntry::Draw(), NWidgetScrollbar::Draw(), StationViewWindow::DrawAcceptedCargo(), DrawBridgeMiddle(), DrawCanalWater(), DrawCommonTileSeq(), DrawCommonTileSeqInGUI(), DrawCompanyManagerFace(), DrawEngineList(), BaseGraphWindow::DrawGraph(), IndustryViewWindow::DrawInfo(), DrawRailCatenaryOnBridge(), DrawRailCatenaryRailway(), TownAuthorityWindow::DrawRatings(), DrawRoadBits(), DrawSprite(), DrawSpriteViewport(), DrawStationTile(), DrawTile_TunnelBridge(), DrawWaterLock(), TransparenciesWindow::DrawWidget(), GraphLegendWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), TownViewWindow::DrawWidget(), TimetableWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), CompanyInfrastructureWindow::DrawWidget(), VehicleViewWindow::DrawWidget(), ErrorUnknownCallbackResult(), FeatureTownName(), FillGRFDetails(), FillNewGRFVehicleCache(), SignList::FilterSignList(), FinalisePriceBaseMultipliers(), FindGRFConfig(), FindSubsidyCargoDestination(), FindSubsidyIndustryCargoRoute(), FindTrainOnTrackEnum(), FixTTOEngines(), FormatString(), Train::GetAccelerationStatus(), GetAcceptanceMask(), GetArticulatedRefitMasks(), GetArticulatedVehicleCargoesAndRefits(), GetBestFittingSubType(), GetCanalSpriteOffset(), GetCapacityOfArticulatedParts(), GetCargoSubtypeText(), GetCargoSuffix(), GetCompanyRailtypes(), GetCompanyRoadtypes(), GetDriveableTrackdirBits(), GetEngineLiveryScheme(), RoadStop::GetEntry(), GetFoundation_Town(), GetGlobalVariable(), FreeTypeFontCache::GetGlyph(), Train::GetImage(), GetIndustryProbabilityCallback(), GetLoadAmount(), GetMaskOfTownActions(), GetNewCargoTypeForReplace(), GetNextArticulatedPart(), Airport::GetNumHangars(), NewGRFWindow::GetPalette(), Train::GetPoweredPartPower(), GetPreviewCompany(), GetRailReservationTrackBits(), GetRailStationAxis(), GetRailTypeDropDownList(), GetRefitCostFactor(), GetSingleSignalState(), GroundVehicle< RoadVehicle, VEH_ROAD >::GetSlopeResistance(), GetTileSingleEntry(), GetTLG(), CompanyInfrastructureWindow::GetTotalMaintenanceCost(), BaseGraphWindow::GetValuesInterval(), IndustriesScopeResolver::GetVariable(), HouseScopeResolver::GetVariable(), StationScopeResolver::GetVariable(), GetWaterTileType(), Train::GetWeight(), GRFLoadConfig(), GroundSpritePaletteTransform(), HandleBankruptcyTakeover(), Vehicle::HandleBreakdown(), Vehicle::HandleLoading(), Vehicle::HandlePathfindingResult(), LinkRefresher::HandleRefit(), HandleSavegameLoadCrash(), HandleScrollbarScrolling(), HasCPUIDFlag(), HasCrossingReservation(), HasDepotReservation(), HasGrfMiscBit(), HasPowerOnRail(), HasRailCatenary(), HasRailtypeAvail(), GoodsEntry::HasRating(), HasStationReservation(), HasTileRoadType(), HasTrack(), HasTunnelBridgeReservation(), HasTunnelBridgeSnowOrDesert(), HeightMapCoastLines(), HeightMapCurves(), HeightMapSmoothCoasts(), IndustriesChangeInfo(), IndustryTemporarilyRefusesCargo(), IsArticulatedEngine(), Vehicle::IsArticulatedPart(), IsArticulatedVehicleRefittable(), IsBridge(), IsCompatibleRail(), IsCrossingBarred(), NWidgetCore::IsDisabled(), Engine::IsEnabled(), GroundVehicle< RoadVehicle, VEH_ROAD >::IsEngine(), IsEngineBuildable(), IsEngineRefittable(), RoadStop::IsEntranceBusy(), ObjectSpec::IsEverAvailable(), RoadStop::IsFreeBay(), GroundVehicle< RoadVehicle, VEH_ROAD >::IsFreeWagon(), Vehicle::IsFrontEngine(), IsGoodGRFConfigList(), Engine::IsHidden(), NWidgetCore::IsHighlighted(), IsHouseCompleted(), IsIndustryCompleted(), IsInvisibilitySet(), IsLoggableGrfConfig(), NWidgetCore::IsLowered(), GroundVehicle< RoadVehicle, VEH_ROAD >::IsMultiheaded(), IsOnSnow(), IsSignalPresent(), IsSnowTile(), IsStationAvailable(), IsStationTileBlocked(), IsTransparencySet(), Order::IsTravelTimetabled(), IsTunnel(), IsUphillTrackdir(), IsValidCompanyManagerFace(), GroundVehicle< RoadVehicle, VEH_ROAD >::IsWagon(), Order::IsWaitTimetabled(), RoadStop::Leave(), LiftHasDestination(), LoadNewGRF(), LoadNewGRFFile(), LoadUnloadVehicle(), MakeDefaultName(), MakeManyOfMany(), MakeRoadNormal(), MapNewGRFIndustryType(), MapSpriteMappingRecolour(), MarkTrainAsStuck(), MonitorMonitorsIndustry(), MoveWaypointsToBaseStations(), Vehicle::NeedsServicing(), NetworkAfterNewGRFScan(), NetworkCompanyIsPassworded(), NewVehicleAvailable(), NPFGetFlag(), OskWindow::OnClick(), TimetableWindow::OnClick(), SelectCompanyLiveryWindow::OnClick(), NewGRFWindow::OnClick(), BuildRailStationWindow::OnClick(), SelectCompanyLiveryWindow::OnDropdownSelect(), TimetableWindow::OnInvalidateData(), GenerateLandscapeWindow::OnInvalidateData(), SelectCompanyLiveryWindow::OnInvalidateData(), NewGRFWindow::OnInvalidateData(), VehicleListWindow::OnInvalidateData(), TownAuthorityWindow::OnPaint(), TimetableWindow::OnPaint(), BuildRailStationWindow::OnPaint(), SelectCompanyManagerFaceWindow::OnPaint(), SignList::OwnerVisibilityFilter(), ParamSet(), PerformStationTileSlopeCheck(), PlayVehicleSound(), PopupMainCompanyToolbMenu(), LinkRefresher::PredictNextOrder(), NewGRFSpriteLayout::PrepareLayout(), PrepareUnload(), NewGRFSpriteLayout::ProcessRegisters(), RailNoLevelCrossings(), RailVehicleChangeInfo(), RandomCompanyManagerFaceBits(), ReadSpriteLayout(), ReadSpriteLayoutSprite(), RoadStop::Entry::Rebuild(), LinkGraphOverlay::RebuildCache(), RefitVehicle(), LinkRefresher::RefreshLinks(), RemoveRoad(), ResetCustomIndustries(), ResetIndustries(), ResetNewGRFErrors(), StationResolverObject::ResolveReal(), ReverseTrainDirection(), RoadFindPathToDest(), RoadVehicleChangeInfo(), RunVehicleDayProc(), ScaleAllCompanyManagerFaceBits(), NetworkUDPSocketHandler::SendNetworkGameInfo(), ServerNetworkGameSocketHandler::SendNewGRFCheck(), LinkGraphLegendWindow::SetOverlay(), BuildObjectWindow::SetStringParameters(), GenerateLandscapeWindow::SetStringParameters(), SelectCompanyLiveryWindow::SetStringParameters(), SetYearEngineAgingStops(), ShipVehicleChangeInfo(), ShowDropDownMenu(), ShowMissingContentWindow(), ShowNewGrfVehicleError(), Vehicle::ShowVisualEffect(), SlReadSimpleGamma(), SpawnAdvancedVisualEffect(), SpriteLayoutPaletteTransform(), StartupOneEngine(), CompanyStationsWindow::StationRatingMinSorter(), SubtractMoneyFromAnyCompany(), SwapTrainFlags(), SwitchNewGRFBlitter(), TileLoop_Town(), TileLoop_Water(), ToolbarOptionsClick(), TownDirectoryWindow::TownRatingSorter(), TrackOverlapsTracks(), TrainController(), TrainExitDir(), TriggerIndustryProduction(), TriggerObjectAnimation(), TriggerObjectTileAnimation(), TriggerStationRandomisation(), TriggerWatchedCargoCallbacks(), TryPathReserve(), OrdersWindow::UpdateAutoRefitState(), UpdateObjectColours(), OskWindow::UpdateOskState(), UpdateStationAcceptance(), UpdateVehicleTimetable(), Vehicle::UpdateVisualEffect(), SelectCompanyLiveryWindow::UpdateWidgetSize(), CompanyInfrastructureWindow::UpdateWidgetSize(), GroundVehicle< RoadVehicle, VEH_ROAD >::UpdateZPosition(), IndustrySpec::UsesSmoothEconomy(), Utf8Decode(), VehicleLengthChanged(), VerifyAutoreplaceRefitForOrders(), GRFConfig::~GRFConfig(), and RoadStop::~RoadStop().
|
inlinestatic |
Test whether value has exactly 1 bit set.
value | the value to test. |
Definition at line 276 of file bitmath_func.hpp.
Referenced by CheckFlatLandRoadStop(), CheckRoadSlope(), CmdBuildBridge(), CmdBuildRoad(), CmdBuildRoadStop(), CmdBuildSingleRail(), and CmdBuildTunnel().
|
inlinestatic |
Clear the first bit in an integer.
This function returns a value where the first bit (from LSB) is cleared. So, 110100 returns 110000, 000001 returns 000000, etc.
value | The value to clear the first bit |
Definition at line 241 of file bitmath_func.hpp.
Referenced by CYapfBaseT< Types >::AddMultipleNodes(), CheckAllowRemoveRoad(), CheckNextTrainTile(), CmdBuildSingleSignal(), ExtendTrainReservation(), IsSafeWaitingPosition(), CYapfCostRoadT< Types >::PfCalcCost(), CYapfCostRailT< Types >::PfCalcCost(), CYapfOriginTileT< Types >::PfSetStartupNodes(), RoadFindPathToDest(), TrackBitsToTrack(), and TracksOverlap().
|
inlinestatic |
ROtate x Left by n.
x | The value which we want to rotate |
n | The number how many we want to rotate |
Definition at line 303 of file bitmath_func.hpp.
Referenced by StringData::HashStr(), VerifyOldNameChecksum(), and StringData::VersionHashStr().
|
inlinestatic |
ROtate x Right by n.
x | The value which we want to rotate |
n | The number how many we want to rotate |
Definition at line 318 of file bitmath_func.hpp.
Referenced by Randomizer::Next().
|
inlinestatic |
Set n bits in x starting at bit s to d.
This function sets n bits from x which started as bit s to the value of d. The parameters x, s and n works the same as the parameters of GB. The result is saved in x again. Unused bits in the window provided by n are set to 0 if the value of d isn't "big" enough. This is not a bug, its a feature.
x | The variable to change some bits |
s | The start position for the new bits |
n | The size/window for the new bits |
d | The actually new bits to save in the defined position. |
Definition at line 60 of file bitmath_func.hpp.
Referenced by AfterLoadGame(), AircraftVehicleChangeInfo(), ClearEnginesHiddenFlagOfCompany(), CmdSetVehicleVisibility(), CmdSignalTrackHelper(), NWidgetMatrix::Draw(), EncodeCargoIndustryMonitor(), EncodeCargoTownMonitor(), RoadStop::Enter(), GenericPlaceSignals(), GetGlobalVariable(), GetPlatformInfo(), NWidgetMatrix::GetWidgetFromPos(), HaltLift(), HandleAutoSignalPlacement(), IndustriesChangeInfo(), IndustryProductionCallback(), LoadUnloadVehicle(), MakeBridgeRamp(), MakeField(), MakeLockTile(), MakeObject(), MakeRailTunnel(), MakeRoadCrossing(), MakeRoadDepot(), MakeRoadNormal(), MakeRoadTunnel(), MakeShipDepot(), MakeShore(), MakeStation(), MakeTree(), MakeWater(), MoveBuoysToWaypoints(), NetworkServerUpdateCompanyPassworded(), NPFSetFlag(), SelectStationWindow< T >::OnClick(), PlaceAirport(), PlaceRoadStop(), RailVehicleChangeInfo(), ReadSpriteLayoutSprite(), ResetIndustryConstructionStage(), RoadVehicleChangeInfo(), SetClearCounter(), SetClearDensity(), SetCompanyManagerFaceBits(), Order::SetConditionComparator(), Order::SetConditionValue(), Order::SetConditionVariable(), SetCrossingBarred(), SetCrossingReservation(), Order::SetDepotActionType(), Order::SetDepotOrderType(), SetDepotReservation(), SetDisallowedRoadDirections(), RoadStop::SetEntranceBusy(), SetFence(), SetFieldType(), SetHasSignals(), SetHouseCompleted(), SetHouseProcessingTime(), SetHouseTriggers(), SetHouseType(), SetIndustryCompleted(), SetIndustryConstructionCounter(), SetIndustryConstructionStage(), SetIndustryGfx(), SetIndustryTriggers(), SetLiftDestination(), SetLiftPosition(), Order::SetLoadType(), Order::SetNonStopType(), SetPresentSignals(), SetRailStationReservation(), SetRailType(), SetRoadBits(), SetRoadOwner(), SetRoadside(), SetRoadTypes(), SetSignalStates(), SetStationTileRandomBits(), Order::SetStopLocation(), GRFConfig::SetSuitablePalette(), SetTileOwner(), SetTileType(), SetTrackBits(), SetTrackReservation(), Order::SetTravelTimetabled(), SetTreeCounter(), SetTreeGroundDensity(), SetTreeGrowth(), SetTropicZone(), SetTunnelBridgeReservation(), SetTunnelBridgeSnowOrDesert(), Order::SetUnloadType(), NWidgetMatrix::SetupSmallestSize(), GRFParameterInfo::SetValue(), Order::SetWaitTimetabled(), SetWaterClass(), ShipVehicleChangeInfo(), StationMonthlyLoop(), TerminateRoadWorks(), TownHouseChangeInfo(), UpdateStationAcceptance(), Vehicle::UpdateVisualEffect(), and VerifyOldNameChecksum().
|
inlinestatic |
Set a bit in a variable.
This function sets a bit in a variable. The variable is changed and the value is also returned. Parameter y defines the bit and starts at the LSB with 0.
x | The variable to set a bit |
y | The bit position to set |
Definition at line 123 of file bitmath_func.hpp.
Referenced by AcceptEnginePreview(), AddChildSpriteScreen(), AddSortableSpriteToDraw(), AfterLoadGame(), AircraftHandleDestTooFar(), AircraftVehicleChangeInfo(), BuildStationPart(), BuildTownHouse(), CalculateRefitMasks(), CargoChangeInfo(), ChangeOwnershipOfCompanyItems(), ChangeTownRating(), CheckIfTrainNeedsService(), RoadStop::ClearDriveThrough(), CmdAutofillTimetable(), CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRoadVehicle(), CmdBuildShip(), CmdCloneVehicle(), CmdRemoveRailroadTrack(), CmdRemoveRoadStop(), CmdRemoveSignalTrack(), CmdSignalTrackHelper(), CmdStartStopVehicle(), Train::ConsistChanged(), ConvertFromOldCompanyManagerFace(), ConvertOldMultiheadToNew(), BaseConsist::CopyConsistPropertiesFrom(), CopyGRFConfigList(), DeliverGoods(), DisplayVehicleSortDropDown(), SettingsPage::Draw(), StationViewWindow::DrawAcceptedCargo(), DrawBridgeMiddle(), DrawCommonTileSeq(), DrawRailCatenaryRailway(), DrawStationCoverageAreaText(), EncodeCargoIndustryMonitor(), EnginesDailyLoop(), RoadStop::Enter(), ErrorUnknownCallbackResult(), FinaliseEngineArray(), FixOldVehicles(), RoadStop::FreeBay(), GetArticulatedVehicleCargoesAndRefits(), GetAvailableVehicleCargoTypes(), GetCompanyRoadtypes(), GetCountAndDistanceOfClosestInstance(), GetGlobalVariable(), GetMaskOfAllowedCurrencies(), Airport::GetNumHangars(), HouseScopeResolver::GetVariable(), StationScopeResolver::GetVariable(), GRFLoadConfig(), GRFUnsafe(), HandleBankruptcyTakeover(), ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig(), Vehicle::HandlePathfindingResult(), IndustriesChangeInfo(), InitializeSortedCargoSpecs(), InsertOrder(), IsGoodGRFConfigList(), Vehicle::LeaveStation(), LoadNewGRF(), LoadUnloadVehicle(), LookupManyOfMany(), MakeDefaultName(), RoadStop::MakeDriveThrough(), MakeSnow(), Order::MapOldOrder(), MapSpriteMappingRecolour(), MarkTrainAsStuck(), NewVehicleAvailable(), CompanyStationsWindow::OnClick(), TimetableWindow::OnClick(), GenerateLandscapeWindow::OnClick(), PaymentRatesGraphWindow::OnClick(), GraphLegendWindow::OnInvalidateData(), ParamSet(), PlaceRoadStop(), LinkRefresher::PredictNextOrder(), NewGRFSpriteLayout::PrepareLayout(), PrepareUnload(), RailTypeChangeInfo(), RailVehicleChangeInfo(), ReadSpriteLayoutSprite(), LinkRefresher::RefreshLinks(), RoadVehicleChangeInfo(), ScrollbarClickPositioning(), Vehicle::SendToDepot(), GroundVehicle< RoadVehicle, VEH_ROAD >::SetArticulatedPart(), SetBridgeMiddle(), GroundVehicle< RoadVehicle, VEH_ROAD >::SetEngine(), GroundVehicle< RoadVehicle, VEH_ROAD >::SetFreeWagon(), GroundVehicle< RoadVehicle, VEH_ROAD >::SetFrontEngine(), SetLiftDestination(), GroundVehicle< RoadVehicle, VEH_ROAD >::SetMultiheaded(), SmallMapWindow::SetOverlayCargoMask(), SettingsDisableElrail(), SetupCargoForClimate(), GroundVehicle< RoadVehicle, VEH_ROAD >::SetWagon(), ShipVehicleChangeInfo(), ShowNewGrfVehicleError(), StartupEngines(), SwapTrainFlags(), ToggleInvisibilityWithTransparency(), TownActionBuildStatue(), TownHouseChangeInfo(), TranslateRefitMask(), TriggerStationRandomisation(), TriggerWatchedCargoCallbacks(), UpdateOrderDest(), LinkGraphLegendWindow::UpdateOverlayCargoes(), LinkGraphLegendWindow::UpdateOverlayCompanies(), BaseGraphWindow::UpdateStatistics(), UpdateTownCargoes(), UpdateTownGrowRate(), UpdateVehicleTimetable(), Vehicle::UpdateVisualEffect(), and GroundVehicle< RoadVehicle, VEH_ROAD >::UpdateZPositionAndInclination().
|
inlinestatic |
Toggles a bit in a variable.
This function toggles a bit in a variable. The variable is changed and the value is also returned. Parameter y defines the bit to toggle and starts at the LSB with 0.
x | The variable to toggle the bit |
y | The bit position to toggle |
Definition at line 183 of file bitmath_func.hpp.
Referenced by CmdBuildObject(), CmdRailTrackHelper(), CmdReverseTrainDirection(), CmdSignalTrackHelper(), BaseConsist::CopyConsistPropertiesFrom(), MenuClickSettings(), GraphLegendWindow::OnClick(), OskWindow::OnClick(), CompanyStationsWindow::OnClick(), GenerateLandscapeWindow::OnClick(), SelectCompanyLiveryWindow::OnClick(), PaymentRatesGraphWindow::OnClick(), PerformStationTileSlopeCheck(), ReverseTrainDirection(), ToggleInvisibility(), ToggleSnow(), ToggleTransparency(), ToggleTransparencyLock(), and Vehicle::UpdateVisualEffect().