bitmath_func.hpp File Reference

Functions related to bit mathematics. More...

Go to the source code of this file.

Defines

#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 FORCEINLINE 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 FORCEINLINE 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 FORCEINLINE 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 FORCEINLINE bool HasBit (const T x, const uint8 y)
 Checks if a bit in a value is set.
template<typename T >
static FORCEINLINE T SetBit (T &x, const uint8 y)
 Set a bit in a variable.
template<typename T >
static FORCEINLINE T ClrBit (T &x, const uint8 y)
 Clears a bit in a variable.
template<typename T >
static FORCEINLINE T ToggleBit (T &x, const uint8 y)
 Toggles a bit in a variable.
static FORCEINLINE 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 FORCEINLINE 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 FORCEINLINE bool HasExactlyOneBit (T value)
 Test whether value has exactly 1 bit set.
template<typename T >
static FORCEINLINE bool HasAtMostOneBit (T value)
 Test whether value has at most 1 bit set.
template<typename T >
static FORCEINLINE T ROL (const T x, const uint8 n)
 ROtate x Left by n.
template<typename T >
static FORCEINLINE T ROR (const T x, const uint8 n)
 ROtate x Right by n.
static FORCEINLINE uint32 BSWAP32 (uint32 x)
 Perform a 32 bits endianness bitswap on x.
static FORCEINLINE 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.

Detailed Description

Functions related to bit mathematics.

Definition in file bitmath_func.hpp.


Define Documentation

#define CLRBITS ( x,
 )     ((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.

Parameters:
x The variable to clear some bits
y The value with set bits for clearing them in the variable
Returns:
The new value of x

Definition at line 159 of file bitmath_func.hpp.

Referenced by CheckRoadSlope(), DisasterTick_Zeppeliner(), HandleCrashedAircraft(), Vehicle::PreDestructor(), GUIList< const Industry * >::RebuildDone(), NWidgetCore::SetDisabled(), GUIList< const Industry * >::SetFiltering(), GUIList< const Industry * >::SetFilterState(), GUIList< const Industry * >::SetListing(), NWidgetCore::SetLowered(), and GUIList< const Industry * >::Sort().

#define FIND_FIRST_BIT (  )     _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.

Parameters:
x The 6-bit value to check the first zero-bit
Returns:
The first position of a bit started from the LSB or 0 if x is 0.

Definition at line 192 of file bitmath_func.hpp.

Referenced by FindFirstBit2x64(), FindFirstTrack(), FloodHalftile(), RemoveFirstTrack(), and TrackBitsToTrack().

#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.

Parameters:
bitpos_var The position counter variable.
bitset_value The value which we check for set bits.

Definition at line 349 of file bitmath_func.hpp.

Referenced by TownAuthorityWindow::GetNthSetBit(), CompanyStationsWindow::OnClick(), and TileLoop_Water().

#define FOR_EACH_SET_BIT_EX ( Tbitpos_type,
bitpos_var,
Tbitset_type,
bitset_value   ) 
Value:
for (                                                                           \
    Tbitset_type ___FESBE_bits = (bitpos_var = (Tbitpos_type)0, bitset_value);    \
    ___FESBE_bits != (Tbitset_type)0;                                             \
    ___FESBE_bits = (Tbitset_type)(___FESBE_bits >> 1), bitpos_var++              \
  )                                                                               \
    if ((___FESBE_bits & 1) != 0)

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.

Parameters:
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.
See also:
FOR_EACH_SET_BIT

Definition at line 328 of file bitmath_func.hpp.

#define SETBITS ( x,
 )     ((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.

Parameters:
x The variable to set some bits
y The value with set bits for setting them in the variable
Returns:
The new value of x

Definition at line 130 of file bitmath_func.hpp.

Referenced by AirportSetBlocks(), DisasterTick_Zeppeliner(), GUIList< const Industry * >::ForceRebuild(), GUIList< const Industry * >::ForceResort(), FreeTerminal(), GUIList< const Industry * >::NeedResort(), GUIList< const Industry * >::RebuildDone(), NWidgetCore::SetDisabled(), GUIList< const Industry * >::SetFiltering(), GUIList< const Industry * >::SetFilterState(), GUIList< const Industry * >::SetListing(), NWidgetCore::SetLowered(), and GUIList< const Industry * >::SetSortType().


Function Documentation

template<typename T , typename U >
static FORCEINLINE T AB ( T &  x,
const uint8  s,
const uint8  n,
const U  i 
) [inline, static]

Add i to n bits of x starting at bit s.

This add the value of i on n bits of x starting at bit s. The parameters x, s, i are similar to GB besides 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.

Note:
Parameter x must be a variable as the result is saved there.
Parameters:
x The variable to add some bits at some position
s The startposition of the addition
n The size/window for the addition
i The value to add at the given startposition in the given window.
Returns:
The new value of x

Definition at line 79 of file bitmath_func.hpp.

Referenced by IncHouseConstructionTick(), and IncreaseRoadWorksCounter().

static FORCEINLINE uint16 BSWAP16 ( uint16  x  )  [static]

Perform a 16 bits endianness bitswap on x.

Parameters:
x the variable to bitswap
Returns:
the bitswapped value.

Definition at line 379 of file bitmath_func.hpp.

static FORCEINLINE uint32 BSWAP32 ( uint32  x  )  [static]

Perform a 32 bits endianness bitswap on x.

Parameters:
x the variable to bitswap
Returns:
the bitswapped value.

Definition at line 364 of file bitmath_func.hpp.

Referenced by GamelogPrint(), GetNewEngine(), HandleSavegameLoadCrash(), HasGRFConfig(), IsGoodGRFConfigList(), NewGRFWindow::OnClick(), PrintGrfInfo(), and SlArray().

template<typename T >
static FORCEINLINE T ClrBit ( T &  x,
const uint8  y 
) [inline, static]

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.

Parameters:
x The variable to clear the bit
y The bit position to clear
Returns:
The new value of the old value with the bit cleared

Definition at line 144 of file bitmath_func.hpp.

Referenced by AfterLoadGame(), RoadStop::AllocateBay(), RoadStop::AllocateDriveThroughBay(), 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(), CmdBuildRailroadTrack(), CmdSetTimetableStart(), Train::ConsistChanged(), ConvertOldMultiheadToNew(), CopyGRFConfigList(), GroundVehicle< RoadVehicle, VEH_ROAD >::Crash(), DrawCatenaryRailway(), FinaliseEngineArray(), FixOldVehicles(), Vehicle::HandlePathfindingResult(), LoadUnloadVehicle(), RoadStop::MakeDriveThrough(), MapSpriteMappingRecolour(), SelectCompanyLiveryWindow::OnInvalidateData(), PrepareUnload(), RemoveFirstTrack(), RemoveFirstTrackdir(), ToggleInvisibilityWithTransparency(), TryPathReserve(), UpdateTownGrowRate(), GroundVehicle< RoadVehicle, VEH_ROAD >::UpdateZPositionAndInclination(), and VehicleEnterDepot().

template<typename T >
static uint CountBits ( value  )  [inline, static]

Counts the number of set bits in a variable.

Parameters:
value the value to count the number of bits in.
Returns:
the number of bits.

Definition at line 243 of file bitmath_func.hpp.

Referenced by CalculateCompanyValue(), CheckFlatLandRoadStop(), CmdBuildRoad(), CmdConvertRail(), RemoveRoad(), 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 conguence 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.

Parameters:
x The value to search
Returns:
The position of the first bit set

Definition at line 37 of file bitmath_func.cpp.

Referenced by AllocateMap(), CalculateRefitMasks(), and ExploreSegment().

static FORCEINLINE uint8 FindFirstBit2x64 ( const int  value  )  [static]

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.

Parameters:
value The value to check the first bits
Returns:
The position of the first bit which is set
See also:
FIND_FIRST_BIT

Definition at line 208 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 conguence 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.

Parameters:
x The value to search
Returns:
The position of the last bit set

Definition at line 65 of file bitmath_func.cpp.

Referenced by BaseGraphWindow::DrawGraph().

template<typename T >
static FORCEINLINE uint GB ( const T  x,
const uint8  s,
const uint8  n 
) [inline, static]

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 startposition to read. The startposition 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).

Parameters:
x The value to read some bits.
s The startposition to read some bits.
n The number of bits to read.
Returns:
The selected bits, aligned to a LSB.

Definition at line 32 of file bitmath_func.hpp.

Referenced by AfterLoadGame(), AnimationBase< HouseAnimationBase, HouseSpec, Town, GetSimpleHouseCallback >::AnimateTile(), AreCompanyManagerFaceBitsValid(), BmpRead1(), BmpRead24(), BmpRead4(), BmpRead4Rle(), BmpRead8(), BuildObject(), BuildTownHouse(), CcBuildIndustry(), CcRoadStop(), AnimationBase< HouseAnimationBase, HouseSpec, Town, GetSimpleHouseCallback >::ChangeAnimationFrame(), ChangeIndustryProduction(), ChangeTrainDirRandomly(), CmdAutofillTimetable(), CmdBuildAirport(), CmdBuildBridge(), CmdBuildDock(), CmdBuildIndustry(), CmdBuildObject(), CmdBuildRailStation(), CmdBuildRailWaypoint(), CmdBuildRoadStop(), CmdBuildSingleSignal(), CmdBuildVehicle(), CmdChangeTimetable(), CmdClearArea(), CmdCloneOrder(), CmdCompanyCtrl(), CmdDeleteOrder(), CmdInsertOrder(), CmdLandscapeClear(), CmdLevelLand(), CmdModifyOrder(), CmdMoveOrder(), CmdMoveRailVehicle(), CmdOrderRefit(), CmdPlantTree(), CmdRefitVehicle(), CmdRemoveRoadStop(), CmdSellVehicle(), CmdSendVehicleToDepot(), CmdSetAutoReplace(), CmdSetCompanyColour(), CmdSetTimetableStart(), CmdSetVehicleOnTime(), CmdSignalTrackHelper(), CmdSkipToOrder(), CmdStartStopVehicle(), CmdTerraformLand(), Blitter_32bppBase::ComposeColourBlend(), Blitter_32bppBase::ComposeColourPANoCheck(), Blitter_32bppBase::ComposeColourRGBANoCheck(), ConvertFromOldCompanyManagerFace(), CopyFromOldName(), CreateNewIndustry(), Disaster_CoalMine_Init(), DisasterTick_Aircraft(), DisasterTick_Big_Ufo_Destroyer(), DisasterTick_Submarine(), DisasterTick_Zeppeliner(), DoCommandP(), DoCreateNewIndustry(), DrawCommonTileSeq(), DrawCommonTileSeqInGUI(), DrawMatrix(), DrawNewObjectTileInGUI(), DrawSprite(), DrawStringMultiLine(), DrawTileLayout(), BuildRailWaypointWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), DepotWindow::DrawWidget(), AIInfo::DummyConstructor(), Blitter_32bppSimple::Encode(), UnmappedChoiceList::Flush(), GamelogPrint(), AI::GameLoop(), GenerateCompanyColour(), GenerateLandscape(), GenerateTrees(), GenRandomRoadBits(), GetAiPurchaseCallbackResult(), GetBridgeAxis(), GetBridgeType(), AICargo::GetCargoLabel(), GetCargoSuffix(), GetCleanHouseType(), GetCleanIndustryGfx(), GetClearCounter(), GetClearDensity(), GetCompanyManagerFaceBits(), GetCompanyManagerFaceSprite(), Order::GetConditionComparator(), Order::GetConditionValue(), Order::GetConditionVariable(), GetCountAndDistanceOfClosestInstance(), GetCrossingRoadAxis(), Order::GetDepotActionType(), Order::GetDepotOrderType(), GetDisallowedRoadDirections(), GetDistanceFromNearbyHouse(), GetFeatureIndex(), GetFeatureNum(), GetFenceSE(), GetFenceSW(), GetFieldType(), GetGlobalVariable(), GetHouseBuildingStage(), GetHouseConstructionTick(), GetHouseProcessingTime(), GetHouseTriggers(), GetIndustryConstructionCounter(), GetIndustryConstructionStage(), GetIndustryTriggers(), GetLiftDestination(), GetLiftPosition(), Order::GetLoadType(), GetLockDirection(), GetNextArticulatedPart(), Order::GetNonStopType(), GetPresentSignals(), GetRailDepotDirection(), GetRailReservationTrackBits(), GetRailTileType(), GetRailType(), GetRawClearGround(), GetRoadBits(), GetRoadDepotDirection(), GetRoadOwner(), GetRoadside(), GetRoadTileType(), GetRoadTypes(), GetSection(), GetShipDepotAxis(), GetShipDepotDirection(), GetSignalStates(), GetStationTileRandomBits(), GetStationType(), Order::GetStopLocation(), GetStringHeight(), GetStringWithArgs(), GetTileOwner(), GetTileType(), GetTrackBits(), GetTreeCount(), GetTreeCounter(), GetTreeDensity(), GetTreeGround(), GetTreeGrowth(), GetTropicZone(), GetTunnelBridgeDirection(), GetTunnelBridgeTransportType(), Order::GetType(), GetUnicodeGlyph(), Order::GetUnloadType(), GRFParameterInfo::GetValue(), GetWaterClass(), GfxFillRect(), HandleAutoSignalPlacement(), HandleCrashedAircraft(), HandleCrashedTrain(), HandleKeypress(), RoadStop::HasFreeBay(), HeightMapNormalize(), IncHouseConstructionTick(), IncreaseRoadWorksCounter(), IndustryGetVariable(), AIOrder::InsertOrder(), IsBridgeAbove(), Load_VEHS(), LoadChunk(), LoadUnloadVehicle(), MakeCzechTownName(), Blitter_32bppBase::MakeGrey(), Blitter_32bppBase::MakeTransparent(), MapGRFStringID(), Order::MapOldOrder(), MaybeCrashAirplane(), MirrorRoadBits(), MoveWaypointsToBaseStations(), NetworkAddChatMessage(), BuildRailWaypointWindow::OnClick(), BuildRailStationWindow::OnClick(), BuildObjectWindow::OnClick(), VehicleListWindow::OnInvalidateData(), TimetableWindow::OnInvalidateData(), OrdersWindow::OnInvalidateData(), Order::Order(), PlaceTree(), PlaceTreeAtSameHeight(), PlaceTreeGroups(), PrepareTextRefStackUsage(), Packet::PrepareToSend(), ResetRestoreAllTransparency(), DeterministicSpriteGroup::Resolve(), RotateRoadBits(), ScaleAllCompanyManagerFaceBits(), SeedChance(), SetHouseType(), SetIndustryGfx(), BuildObjectWindow::SetStringParameters(), SetUnicodeGlyph(), SetWaterClassDependingOnSurroundings(), Vehicle::ShowVisualEffect(), SlCalcConvFileLen(), SlCalcConvMemLen(), AIError::StringToError(), TileHash2Bit(), TileHeight(), TileLoop_Town(), TownGetVariable(), TownHouseChangeInfo(), TrainCheckIfLineEnds(), TranslateTTDPatchCodes(), VehicleListIdentifier::Unpack(), UnpackVersion4Order(), UpdateCursorSize(), Train::UpdateDeltaXY(), Ship::UpdateDeltaXY(), RoadVehicle::UpdateDeltaXY(), Vehicle::UpdateVisualEffect(), BuildRailStationWindow::UpdateWidgetSize(), NewGRFParametersWindow::UpdateWidgetSize(), AIConfigWindow::UpdateWidgetSize(), AISettingsWindow::UpdateWidgetSize(), AIListWindow::UpdateWidgetSize(), Utf8Decode(), Utf8Encode(), Utf8EncodedCharLen(), VehicleFromPos(), VehicleFromPosXY(), VehicleRandomBits(), and ViewportAddVehicles().

template<typename T >
static FORCEINLINE bool HasAtMostOneBit ( value  )  [inline, static]

Test whether value has at most 1 bit set.

Parameters:
value the value to test.
Returns:
does value have at most 1 bit set?

Definition at line 278 of file bitmath_func.hpp.

Referenced by DrawRoadBits(), and ShowRefitOptionsList().

template<typename T >
static FORCEINLINE bool HasBit ( const T  x,
const uint8  y 
) [inline, static]

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.

Parameters:
x The value to check
y The position of the bit to check, started from the LSB
Returns:
True if the bit is set, false else.

Definition at line 98 of file bitmath_func.hpp.

Referenced by AfterLoadGame(), AfterLoadRoadStops(), AfterLoadVehicles(), AIEngineList::AIEngineList(), AITileList_StationType::AITileList_StationType(), RoadStop::AllocateBay(), AnimationBase< HouseAnimationBase, HouseSpec, Town, GetSimpleHouseCallback >::AnimateTile(), AIRoad::AreRoadTilesConnected(), TimetableWindow::BuildArrivalDepartureList(), BuildObject(), RefitWindow::BuildRefitList(), BuildReplacementVehicle(), CompanyStationsWindow::BuildStationsList(), BuildTownHouse(), CalcPercentVehicleFilled(), CalculateRefitMasks(), AIRoad::CanBuildConnectedRoadPartsHere(), CanBuildVehicleInfrastructure(), CFollowTrackT< Ttr_type_, VehicleType, T90deg_turns_allowed_, Tmask_reserved_tracks >::CanEnterNewTile(), CanEnterTile(), AIEngine::CanRefitCargo(), CanRemoveRoadWithStop(), CargoFilter(), CcRoadStop(), ChangeIndustryProduction(), CheckAllowRemoveTunnelBridge(), CheckAutoreplaceValidity(), CheckBuildableTile(), CheckFlatLandRailStation(), CheckFlatLandRoadStop(), CheckIfCallBackAllowsAvailability(), CheckIfIndustryTilesAreFree(), RoadStop::Entry::CheckIntegrity(), CheckRoadBlockedForOvertaking(), BuildRailStationWindow::CheckSelectedSize(), CleanIndustryTileTable(), RoadStop::ClearDriveThrough(), CmdAutofillTimetable(), CmdBuildAirport(), CmdBuildDock(), CmdBuildLongRoad(), CmdBuildObject(), CmdBuildRailStation(), CmdBuildRailVehicle(), CmdBuildRailWaypoint(), CmdBuildRoad(), CmdBuildRoadStop(), CmdBuildRoadVehicle(), CmdBuildSingleRail(), CmdBuildSingleSignal(), CmdBuyCompany(), CmdChangeTimetable(), CmdClearArea(), CmdCloneVehicle(), CmdDoTownAction(), CmdForceTrainProceed(), CmdFoundTown(), CmdLevelLand(), CmdMassStartStopVehicle(), CmdMoveRailVehicle(), CmdRailTrackHelper(), CmdRefitVehicle(), CmdRemoveFromRailStation(), CmdRemoveFromRailWaypoint(), CmdRemoveLongRoad(), CmdReverseTrainDirection(), CmdSellRailWagon(), CmdSetGroupReplaceProtection(), CmdSignalTrackHelper(), CmdStartStopVehicle(), CompaniesGenStatistics(), Train::ConsistChanged(), ConvertFromOldCompanyManagerFace(), ConvertOldMultiheadToNew(), Vehicle::CopyVehicleConfigAndStatistics(), Train::Crash(), CreateNewIndustryHelper(), DeliverGoods(), DisasterTick_Aircraft(), DisasterTick_Helicopter_Rotors(), DisasterTick_Submarine(), DisasterTick_Ufo(), DisasterTick_Zeppeliner(), DoCreateNewIndustry(), NWidgetScrollbar::Draw(), SettingEntry::Draw(), StationViewWindow::DrawAcceptedCargo(), DrawCanalWater(), StationViewWindow::DrawCargoRatings(), DrawCatenaryOnBridge(), DrawCatenaryRailway(), DrawCommonTileSeq(), DrawCommonTileSeqInGUI(), DrawCompanyManagerFace(), BaseGraphWindow::DrawGraph(), IndustryViewWindow::DrawInfo(), TownAuthorityWindow::DrawRatings(), DrawRoadBits(), DrawSprite(), DrawStationTile(), DrawTile_TunnelBridge(), StationViewWindow::DrawWaitingCargo(), DrawWaterLock(), VehicleViewWindow::DrawWidget(), TransparenciesWindow::DrawWidget(), TimetableWindow::DrawWidget(), CompanyStationsWindow::DrawWidget(), BuildRailWaypointWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), BuildObjectWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), GraphLegendWindow::DrawWidget(), SelectCompanyLiveryWindow::DrawWidget(), FillGRFDetails(), FillNewGRFVehicleCache(), FinalisePriceBaseMultipliers(), FindGRFConfig(), FindTrainOnTrackEnum(), FixTTOEngines(), Train::GetAccelerationStatus(), GetAcceptanceMask(), GetArticulatedRefitMasks(), GetBestCompany(), GetBestFittingSubType(), GetCanalSpriteOffset(), GetCargoSubtypeText(), GetCargoSuffix(), GetCompanyRailtypes(), GetCompanyRoadtypes(), GetDriveableTrackdirBits(), GetEngineLiveryScheme(), RoadStop::GetEntry(), GetFoundation_Town(), GetGlobalVariable(), Train::GetImage(), GetMaskOfTownActions(), GetNewCargoTypeForReplace(), GetNextArticulatedPart(), Airport::GetNumHangars(), GetOtherShipDepotTile(), NewGRFWindow::GetPalette(), Train::GetPoweredPartPower(), AICompany::GetPresidentGender(), GetRailReservationTrackBits(), GetRailStationAxis(), GetRailTypeDropDownList(), AITown::GetRating(), AIEngine::GetRoadType(), GetSingleSignalState(), GroundVehicle< RoadVehicle, VEH_ROAD >::GetSlopeResistance(), GetStringWithArgs(), GetTileSingleEntry(), BaseGraphWindow::GetValuesInterval(), GetVehicleCapacity(), Train::GetWeight(), GRFLoadConfig(), GroundSpritePaletteTransform(), HandleBankruptcyTakeover(), Vehicle::HandleLoading(), Vehicle::HandlePathfindingResult(), HandleSavegameLoadCrash(), HandleScrollbarScrolling(), HasCatenary(), HasCrossingReservation(), HasDepotReservation(), HasPowerOnRail(), HasRailtypeAvail(), HasStationReservation(), AITown::HasStatue(), HasTileRoadType(), HasTrack(), HasTunnelBridgeReservation(), HasTunnelBridgeSnowOrDesert(), HeightMapCoastLines(), HeightMapSmoothCoasts(), IndustryGetVariable(), IndustryTemporarilyRefusesCargo(), AITown::IsActionAvailable(), Vehicle::IsArticulatedPart(), IsArticulatedVehicleRefittable(), ObjectSpec::IsAvailable(), IsBridge(), IsCompatibleRail(), IsCrossingBarred(), NWidgetCore::IsDisabled(), GroundVehicle< RoadVehicle, VEH_ROAD >::IsEngine(), IsEngineBuildable(), IsEngineRefittable(), RoadStop::IsEntranceBusy(), RoadStop::IsFreeBay(), GroundVehicle< RoadVehicle, VEH_ROAD >::IsFreeWagon(), Vehicle::IsFrontEngine(), IsGoodGRFConfigList(), IsHouseCompleted(), IsIndustryCompleted(), IsInvisibilitySet(), IsLoggableGrfConfig(), NWidgetCore::IsLowered(), GroundVehicle< RoadVehicle, VEH_ROAD >::IsMultiheaded(), IsOnSnow(), IsSignalPresent(), IsSnowTile(), IsStationTileBlocked(), IsStationTileElectrifiable(), IsTransparencySet(), IsTunnel(), IsUphillTrackdir(), IsValidCompanyManagerFace(), GroundVehicle< RoadVehicle, VEH_ROAD >::IsWagon(), RoadStop::Leave(), LiftHasDestination(), LoadUnloadVehicle(), MakeDefaultName(), MakeManyOfMany(), MakeRoadNormal(), MapSpriteMappingRecolour(), MarkTrainAsStuck(), MoveWaypointsToBaseStations(), Vehicle::NeedsServicing(), NetworkAfterNewGRFScan(), NetworkCompanyIsPassworded(), NewVehicleAvailable(), NPFGetFlag(), TimetableWindow::OnClick(), BuildRailWaypointWindow::OnClick(), BuildRailStationWindow::OnClick(), OskWindow::OnClick(), NewGRFWindow::OnClick(), SelectCompanyLiveryWindow::OnClick(), SelectCompanyLiveryWindow::OnDropdownSelect(), VehicleListWindow::OnInvalidateData(), TimetableWindow::OnInvalidateData(), SmallMapWindow::OnInvalidateData(), NewGRFWindow::OnInvalidateData(), GenerateLandscapeWindow::OnInvalidateData(), SelectCompanyLiveryWindow::OnInvalidateData(), TownAuthorityWindow::OnPaint(), TimetableWindow::OnPaint(), BuildRailStationWindow::OnPaint(), SelectCompanyManagerFaceWindow::OnPaint(), StationViewWindow::OrderWaitingCargo(), PopupMainCompanyToolbMenu(), RailNoLevelCrossings(), RailVehicleLengthChanged(), RandomCompanyManagerFaceBits(), RoadStop::Entry::Rebuild(), RefitVehicle(), RemoveRoad(), ResetIndustries(), RoadFindPathToDest(), RunVehicleDayProc(), ScaleAllCompanyManagerFaceBits(), NetworkUDPSocketHandler::SendNetworkGameInfo(), BuildObjectWindow::SetStringParameters(), GenerateLandscapeWindow::SetStringParameters(), SelectCompanyLiveryWindow::SetStringParameters(), SetYearEngineAgingStops(), ShipVehicleChangeInfo(), ShowDropDownMenu(), ShowNewGrfVehicleError(), ShowRefitOptionsList(), Vehicle::ShowVisualEffect(), SlReadSimpleGamma(), SpriteLayoutPaletteTransform(), CompanyStationsWindow::StationRatingMaxSorter(), CompanyStationsWindow::StationRatingMinSorter(), SubtractMoneyFromAnyCompany(), TileLoop_Town(), TileLoop_Water(), TrackOverlapsTracks(), TrainExitDir(), TriggerIndustryProduction(), TriggerObjectAnimation(), TriggerObjectTileAnimation(), TryPathReserve(), UpdateObjectColours(), OskWindow::UpdateOskState(), UpdateStationAcceptance(), Vehicle::UpdateVisualEffect(), SelectCompanyLiveryWindow::UpdateWidgetSize(), GroundVehicle< RoadVehicle, VEH_ROAD >::UpdateZPosition(), IndustrySpec::UsesSmoothEconomy(), Utf8Decode(), VerifyAutoreplaceRefitForOrders(), GRFConfig::~GRFConfig(), and RoadStop::~RoadStop().

template<typename T >
static FORCEINLINE bool HasExactlyOneBit ( value  )  [inline, static]

Test whether value has exactly 1 bit set.

Parameters:
value the value to test.
Returns:
does value have exactly 1 bit set?

Definition at line 266 of file bitmath_func.hpp.

Referenced by CheckRoadSlope(), CleanUpRoadBits(), CmdBuildBridge(), CmdBuildRoadStop(), CmdBuildTunnel(), AIStation::GetCoverageRadius(), AIStation::HasStationType(), AIWaypoint::HasWaypointType(), and AITile::IsBuildable().

template<typename T >
static FORCEINLINE T KillFirstBit ( value  )  [inline, static]

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.

Parameters:
value The value to clear the first bit
Returns:
The new value with the first bit cleared

Definition at line 231 of file bitmath_func.hpp.

Referenced by CYapfBaseT< Types >::AddMultipleNodes(), AIRail::BuildRailTrack(), CheckAllowRemoveRoad(), CheckNextTrainTile(), CmdBuildSingleSignal(), ExtendTrainReservation(), IsSafeWaitingPosition(), CYapfCostRoadT< Types >::PfCalcCost(), CYapfCostRailT< Types >::PfCalcCost(), CYapfOriginTileT< Types >::PfSetStartupNodes(), AIRail::RemoveRailTrack(), RoadFindPathToDest(), TrackBitsToTrack(), and TracksOverlap().

template<typename T >
static FORCEINLINE T ROL ( const T  x,
const uint8  n 
) [inline, static]

ROtate x Left by n.

Note:
Assumes a byte has 8 bits
Parameters:
x The value which we want to rotate
n The number how many we waht to rotate
Returns:
A bit rotated number

Definition at line 292 of file bitmath_func.hpp.

Referenced by VerifyOldNameChecksum().

template<typename T >
static FORCEINLINE T ROR ( const T  x,
const uint8  n 
) [inline, static]

ROtate x Right by n.

Note:
Assumes a byte has 8 bits
Parameters:
x The value which we want to rotate
n The number how many we waht to rotate
Returns:
A bit rotated number

Definition at line 306 of file bitmath_func.hpp.

Referenced by Randomizer::Next().

template<typename T , typename U >
static FORCEINLINE T SB ( T &  x,
const uint8  s,
const uint8  n,
const U  d 
) [inline, static]

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.

Note:
Parameter x must be a variable as the result is saved there.
To avoid unexpecting results the value of d should not use more space as the provided space of n bits (log2)
Parameters:
x The variable to change some bits
s The startposition for the new bits
n The size/window for the new bits
d The actually new bits to save in the defined position.
Returns:
The new value of x

Definition at line 56 of file bitmath_func.hpp.

Referenced by AfterLoadGame(), CmdSignalTrackHelper(), NWidgetMatrix::Draw(), RoadStop::Enter(), GenericPlaceSignals(), GetGlobalVariable(), GetPlatformInfo(), NWidgetMatrix::GetWidgetFromPos(), HaltLift(), HandleAutoSignalPlacement(), IndustryProductionCallback(), LoadUnloadVehicle(), MakeBridgeRamp(), MakeClear(), MakeField(), MakeLockTile(), MakeObject(), MakeRailTunnel(), MakeRoadCrossing(), MakeRoadDepot(), MakeRoadNormal(), MakeRoadTunnel(), MakeShipDepot(), MakeShore(), MakeStation(), MakeTree(), MakeWater(), MoveBuoysToWaypoints(), NPFSetFlag(), SelectStationWindow< T >::OnClick(), PlaceAirport(), PlaceRoadStop(), ResetIndustryConstructionStage(), SetClearCounter(), SetClearDensity(), SetCompanyManagerFaceBits(), Order::SetConditionComparator(), Order::SetConditionValue(), Order::SetConditionVariable(), SetCrossingBarred(), SetCrossingReservation(), Order::SetDepotActionType(), Order::SetDepotOrderType(), SetDepotReservation(), SetDisallowedRoadDirections(), RoadStop::SetEntranceBusy(), SetFenceSE(), SetFenceSW(), 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(), SetTileHeight(), SetTileOwner(), SetTileType(), SetTrackBits(), SetTrackReservation(), SetTreeCounter(), SetTreeGroundDensity(), SetTreeGrowth(), SetTropicZone(), SetTunnelBridgeReservation(), SetTunnelBridgeSnowOrDesert(), Order::SetUnloadType(), NWidgetMatrix::SetupSmallestSize(), GRFParameterInfo::SetValue(), SetWaterClass(), ShipVehicleChangeInfo(), TerminateRoadWorks(), TownHouseChangeInfo(), UpdateStationAcceptance(), Vehicle::UpdateVisualEffect(), and VerifyOldNameChecksum().

template<typename T >
static FORCEINLINE T SetBit ( T &  x,
const uint8  y 
) [inline, static]

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.

Parameters:
x The variable to set a bit
y The bit position to set
Returns:
The new value of the old value with the bit set

Definition at line 115 of file bitmath_func.hpp.

Referenced by AddChildSpriteScreen(), AddSortableSpriteToDraw(), AfterLoadGame(), BuildTownHouse(), CalculateRefitMasks(), ChangeTownRating(), RoadStop::ClearDriveThrough(), CmdAutofillTimetable(), CmdBuildAircraft(), CmdBuildAirport(), CmdBuildDock(), CmdBuildRailStation(), CmdBuildRailVehicle(), CmdBuildRoadStop(), CmdBuildRoadVehicle(), CmdBuildShip(), CmdCloneVehicle(), CmdRemoveRailroadTrack(), CmdRemoveSignalTrack(), CmdSignalTrackHelper(), CmdStartStopVehicle(), IndustryCargoesWindow::ComputeCargoDisplay(), IndustryCargoesWindow::ComputeIndustryDisplay(), Train::ConsistChanged(), ConvertFromOldCompanyManagerFace(), ConvertOldMultiheadToNew(), CopyGRFConfigList(), Vehicle::CopyVehicleConfigAndStatistics(), DeliverGoods(), DoDrawVehicle(), SettingEntry::Draw(), StationViewWindow::DrawAcceptedCargo(), DrawCatenaryRailway(), DrawCommonTileSeq(), DrawStationCoverageAreaText(), RoadStop::Enter(), FinaliseEngineArray(), FixOldVehicles(), RoadStop::FreeBay(), GetAvailableVehicleCargoTypes(), GetBestCompany(), GetCompanyRoadtypes(), GetCountAndDistanceOfClosestInstance(), GetGlobalVariable(), Airport::GetNumHangars(), GRFLoadConfig(), HandleBankruptcyTakeover(), ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig(), Vehicle::HandlePathfindingResult(), IsGoodGRFConfigList(), Vehicle::LeaveStation(), LoadUnloadVehicle(), LookupManyOfMany(), MakeDefaultName(), RoadStop::MakeDriveThrough(), MakeSnow(), Order::MapOldOrder(), MapSpriteMappingRecolour(), MarkTrainAsStuck(), NewVehicleAvailable(), TimetableWindow::OnClick(), CompanyStationsWindow::OnClick(), PaymentRatesGraphWindow::OnClick(), GenerateLandscapeWindow::OnClick(), BuildVehicleWindow::OnClick(), GraphLegendWindow::OnInvalidateData(), StationViewWindow::OrderWaitingCargo(), PlaceRoadStop(), PrepareUnload(), ScrollbarClickPositioning(), 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(), SettingsDisableElrail(), SetupCargoForClimate(), GroundVehicle< RoadVehicle, VEH_ROAD >::SetWagon(), ShowNewGrfVehicleError(), ToggleInvisibilityWithTransparency(), TownActionBuildStatue(), BaseGraphWindow::UpdateStatistics(), UpdateTownGrowRate(), Vehicle::UpdateVisualEffect(), and GroundVehicle< RoadVehicle, VEH_ROAD >::UpdateZPositionAndInclination().

template<typename T >
static FORCEINLINE T ToggleBit ( T &  x,
const uint8  y 
) [inline, static]

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.

Parameters:
x The varliable to toggle the bit
y The bit position to toggle
Returns:
The new value of the old value with the bit toggled

Definition at line 173 of file bitmath_func.hpp.

Referenced by CmdRailTrackHelper(), CmdReverseTrainDirection(), CmdSignalTrackHelper(), CompanyStationsWindow::OnClick(), OskWindow::OnClick(), PaymentRatesGraphWindow::OnClick(), GraphLegendWindow::OnClick(), GenerateLandscapeWindow::OnClick(), SelectCompanyLiveryWindow::OnClick(), ToggleInvisibility(), ToggleSnow(), ToggleTransparency(), ToggleTransparencyLock(), and Vehicle::UpdateVisualEffect().


Generated on Thu Apr 14 00:48:25 2011 for OpenTTD by  doxygen 1.6.1