Go to the source code of this file.
Defines | |
#define | HASBITS(x, y) ((x) & (y)) |
Check several bits in a value. | |
#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 occure of a bit in a 6-bit value (from right). | |
#define | FOR_EACH_SET_BIT(i, b) |
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 from 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 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 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. |
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 156 of file bitmath_func.hpp.
Referenced by DisasterTick_Zeppeliner().
#define FIND_FIRST_BIT | ( | x | ) | _ffb_64[(x)] |
Returns the first occure of a 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 188 of file bitmath_func.hpp.
Referenced by DeleteLastWagon(), FindFirstBit2x64(), FindFirstTrack(), FloodHalftile(), RemoveFirstTrack(), and TrackBitsToTrack().
#define FOR_EACH_SET_BIT | ( | i, | |||
b | ) |
Value:
for (i = 0; b != 0; i++, b >>= 1) \ if (b & 1)
This macros is used to do an operation for each set bit in a variable. The first variable can be reused in the operation due to it's the bit position counter. The second variable will be cleared during the usage
i | The position counter | |
b | The value which we check for set bits |
Definition at line 290 of file bitmath_func.hpp.
Referenced by GetNthSetBit(), RoadFindPathToDest(), and TileLoop_Water().
#define HASBITS | ( | x, | |||
y | ) | ((x) & (y)) |
Check several bits in a value.
This macro checks if a value contains at least one bit of an other value.
x | The first value | |
y | The second value |
Definition at line 100 of file bitmath_func.hpp.
Referenced by AddGRFString(), AirportSetBlocks(), BuildTownHouse(), CmdBuildRailWagon(), CmdMoveRailVehicle(), CmdSellAircraft(), CmdSellRailWagon(), CmdSellRoadVeh(), CmdSellShip(), and GrowTownWithBridge().
#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 128 of file bitmath_func.hpp.
Referenced by AirportSetBlocks(), and DisasterTick_Zeppeliner().
static 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.
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. |
Definition at line 67 of file bitmath_func.hpp.
Referenced by IncHouseConstructionTick().
static uint16 BSWAP16 | ( | uint16 | x | ) | [inline, static] |
Perform a 16 bits endianness bitswap on x.
x | the variable to bitswap |
Definition at line 318 of file bitmath_func.hpp.
static uint32 BSWAP32 | ( | uint32 | x | ) | [inline, static] |
Perform a 32 bits endianness bitswap on x.
x | the variable to bitswap |
Definition at line 308 of file bitmath_func.hpp.
Referenced by IsGoodGRFConfigList(), and SlArray().
static 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.
x | The variable to clear the bit | |
y | The bit position to clear |
Definition at line 141 of file bitmath_func.hpp.
Referenced by RoadStop::AllocateBay(), RoadStop::AllocateDriveThroughBay(), ClearArticulatedPart(), ClearFreeWagon(), ClearFrontEngine(), ClearMultiheaded(), ClearSingleBridgeMiddle(), ClearTrainEngine(), ClearTrainWagon(), CmdAutofillTimetable(), CmdBuildRailroadTrack(), CmdModifyOrder(), CmdSendAircraftToHangar(), CmdSendRoadVehToDepot(), CmdSendShipToDepot(), CmdSendTrainToDepot(), ConvertOldMultiheadToNew(), CopyGRFConfigList(), DrawCatenaryRailway(), GraphicsNew(), LoadUnloadVehicle(), MapSpriteMappingRecolour(), NPFSetFlag(), RemoveFirstTrack(), RemoveFirstTrackdir(), ReverseTrainDirection(), TrainConsistChanged(), UpdateTownGrowRate(), and VehiclePayment().
static uint CountBits | ( | T | value | ) | [inline, static] |
Counts the number of set bits in a variable.
value | the value to count the number of bits in. |
Definition at line 237 of file bitmath_func.hpp.
Referenced by CheckRoadSlope(), CleanUpRoadBits(), CmdBuildRoad(), CmdBuildRoadStop(), CmdConvertRail(), DrawRoadBits(), 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.
x | The value to search |
Definition at line 30 of file bitmath_func.cpp.
Referenced by AllocateMap(), and ExploreSegment().
static uint8 FindFirstBit2x64 | ( | const int | value | ) | [inline, static] |
Finds the position of the first 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 204 of file bitmath_func.hpp.
References FIND_FIRST_BIT.
Referenced by CYapfBaseT< Types >::AddMultipleNodes(), FindFirstTrackdir(), CYapfOriginTileT< Types >::PfSetStartupNodes(), RemoveFirstTrackdir(), and RoadFindPathToDest().
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.
x | The value to search |
Definition at line 58 of file bitmath_func.cpp.
Referenced by DrawGraph().
static 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).
x | The value to read some bits. | |
s | The startposition to read some bits. | |
n | The number of bits to read. |
Definition at line 24 of file bitmath_func.hpp.
Referenced by ArePlayerFaceBitsValid(), BmpRead1(), BmpRead24(), BmpRead4(), BmpRead4Rle(), BmpRead8(), BuildTownHouse(), ChangeIndustryProduction(), CmdAutofillTimetable(), CmdBuildBridge(), CmdBuildIndustry(), CmdBuildLongRoad(), CmdBuildRailroadStation(), CmdBuildRoad(), CmdBuildRoadDepot(), CmdBuildRoadStop(), CmdBuildSingleSignal(), CmdBuildTunnel(), CmdChangeTimetable(), CmdCloneOrder(), CmdDepotMassAutoReplace(), CmdDepotSellAllVehicles(), CmdInsertOrder(), CmdMassStartStopVehicle(), CmdModifyOrder(), CmdMoveOrder(), CmdMoveRailVehicle(), CmdOrderRefit(), CmdPlantTree(), CmdPlayerCtrl(), CmdRailTrackHelper(), CmdRefitAircraft(), CmdRefitRailVehicle(), CmdRefitRoadVeh(), CmdRefitShip(), CmdRemoveLongRoad(), CmdRemoveRoad(), CmdRemoveSingleSignal(), CmdRestoreOrderIndex(), CmdSetAutoReplace(), CmdSetPlayerColor(), CmdSetVehicleOnTime(), CmdSignalTrackHelper(), CmdStartStopAircraft(), CmdStartStopRoadVeh(), CmdStartStopShip(), CmdStartStopTrain(), ConvertFromOldPlayerFace(), Disaster_CoalMine_Init(), DisasterTick_Airplane(), DisasterTick_Big_Ufo_Destroyer(), DisasterTick_Helicopter(), DisasterTick_Submarine(), DisasterTick_Zeppeliner(), DoCommandP(), DoPlaceMoreTrees(), DrawStringMultiCenter(), EnlargeCompanyHQ(), GenRandomRoadBits(), GetBridgeAxis(), GetBridgeType(), GetClearCounter(), GetClearDensity(), GetClearGround(), GetCompanyHQSection(), GetCompanyHQSize(), GetCountAndDistanceOfClosestInstance(), GetDisallowedRoadDirections(), GetFenceSE(), GetFenceSW(), GetFieldType(), GetGlobalVariable(), GetHouseAnimationFrame(), GetHouseBuildingStage(), GetHouseConstructionTick(), GetHouseTriggers(), GetHouseType(), GetIndustryConstructionCounter(), GetIndustryConstructionStage(), GetIndustryTriggers(), GetLiftDestination(), GetLiftPosition(), GetNewsDisplayValue(), GetPlayerFaceBits(), GetPlayerFaceSprite(), GetPresentSignals(), GetRailDepotDirection(), GetRailTileType(), GetRailType(), GetSignalStates(), GetStringWithArgs(), GetTileType(), GetTrackBits(), GetTreeCount(), GetTreeCounter(), GetTreeDensity(), GetTreeGround(), GetTreeGrowth(), GetTropicZone(), GetTunnelBridgeDirection(), GetTunnelBridgeTransportType(), GetUnicodeGlyph(), GetWaypointAxis(), GroupWndProc(), HandleAutoSignalPlacement(), HandleKeypress(), RoadStop::HasFreeBay(), IncHouseConstructionTick(), IndustryGetVariable(), IsBridgeAbove(), LoadChunk(), LoadUnloadVehicle(), MapGRFStringID(), MirrorRoadBits(), Randomizer::Next(), PlaceMoreTrees(), PlaceTree(), PlaceTreeAtSameHeight(), PopupMainToolbMenu(), PrepareTextRefStackUsage(), ResetRestoreAllTransparency(), ResizeWindow(), RotateRoadBits(), ScaleAllPlayerFaceBits(), SelectPlayerFaceWndProc(), SetHouseAnimationFrame(), SetHouseType(), SetIndustryGfx(), SetUnicodeGlyph(), SlCalcConvFileLen(), SlCalcConvMemLen(), TileHeight(), TileLoop_Town(), TownGetVariable(), TownHouseChangeInfo(), TrainCheckIfLineEnds(), TrainConsistChanged(), UnpackOldOrder(), UnpackVersion4Order(), Utf8EncodedCharLen(), VehicleFromPos(), VehicleFromPosXY(), and VehicleRandomBits().
static 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.
x | The value to check | |
y | The position of the bit to check, started from the LSB |
Definition at line 85 of file bitmath_func.hpp.
Referenced by AfterLoadVehicles(), RoadStop::AllocateBay(), AreValidRoadTypes(), BuildStationsList(), BuildTownHouse(), CalcPercentVehicleFilled(), CalculateRefitMasks(), CanBuildVehicleInfrastructure(), CanCargoServiceIndustry(), CFollowTrackT< Ttr_type_, T90deg_turns_allowed_ >::CanEnterNewTile(), CanEnterTile(), CanRefitTo(), ChangeIndustryProduction(), CheckFlatLandBelow(), CheckRoadBlockedForOvertaking(), CheckSendAircraftToHangarForReplacement(), CmdBuildAircraft(), CmdBuildAirport(), CmdBuildDock(), CmdBuildLongRoad(), CmdBuildRailroadStation(), CmdBuildRailVehicle(), CmdBuildRoad(), CmdBuildRoadStop(), CmdBuildRoadVeh(), CmdBuildSingleRail(), CmdBuildSingleSignal(), CmdChangeTimetable(), CmdCloneVehicle(), CmdDeleteOrder(), CmdDoTownAction(), CmdMassStartStopVehicle(), CmdModifyOrder(), CmdMoveRailVehicle(), CmdOrderRefit(), CmdRailTrackHelper(), CmdRefitAircraft(), CmdRefitRailVehicle(), CmdRefitRoadVeh(), CmdRefitShip(), CmdRemoveLongRoad(), CmdReverseTrainDirection(), CmdSellRailWagon(), CmdSendAircraftToHangar(), CmdSendRoadVehToDepot(), CmdSendShipToDepot(), CmdSendTrainToDepot(), CmdSetAutoReplace(), CmdSetGroupReplaceProtection(), CmdSignalTrackHelper(), CmdSkipToOrder(), ConvertFromOldPlayerFace(), ConvertOldMultiheadToNew(), CreateNewIndustryHelper(), DeliverGoodsToIndustry(), DisasterTick_Airplane(), DisasterTick_Helicopter(), DisasterTick_Helicopter_Rotors(), DisasterTick_Submarine(), DisasterTick_Ufo(), DisasterTick_Zeppeliner(), DrawBridgePillars(), DrawCatenaryRailway(), DrawGraph(), DrawPlayerFace(), DrawRoadBits(), DrawStationTile(), DrawStationViewWindow(), DrawTile_TunnelBridge(), DrawVehicleViewWindow(), FindFirstRefittableCargo(), GenerateReplaceVehList(), GetAcceptanceMask(), GetDriveableTrackdirBits(), GetMaskOfTownActions(), GetPlayerRailtypes(), GetPlayerRoadtypes(), GetSingleSignalState(), GetStringWithArgs(), GetTileSingleEntry(), GetTrainAcceleration(), GraphicsNew(), HasPowerOnRail(), HasRailtypeAvail(), HasTrack(), HasTunnelBridgeSnowOrDesert(), IndustryGetVariable(), IsArticulatedPart(), IsBridge(), IsCompatibleRail(), IsEngineBuildable(), RoadStop::IsEntranceBusy(), RoadStop::IsFreeBay(), IsFreeWagon(), IsFrontEngine(), IsGoodGRFConfigList(), IsHouseCompleted(), IsIndustryCompleted(), IsMultiheaded(), IsSignalPresent(), IsTrainEngine(), IsTrainWagon(), IsTransparencySet(), IsTunnel(), IsUphillTrackdir(), IsValidPlayerFace(), LiftHasDestination(), LoadUnloadVehicle(), make_manyofmany(), MakeDefaultWaypointName(), MakeSingleHouseBigger(), MapSpriteMappingRecolour(), NPFGetFlag(), RailVehicleChangeInfo(), RailVehicleLengthChanged(), RandomPlayerFaceBits(), RemoveRoad(), ResetIndustries(), RoadFindPathToDest(), RoadVehicleChangeInfo(), ScaleAllPlayerFaceBits(), SelectPlayerFaceWndProc(), ShipVehicleChangeInfo(), ShowPlayerStations(), ShowRefitOptionsList(), SlReadSimpleGamma(), StationRatingMaxSorter(), TileLoop_Town(), TileLoop_Water(), TownAuthorityWndProc(), TrainCargoChanged(), TrainConsistChanged(), TrainExitDir(), TrainPowerChanged(), UpdateStationAcceptance(), VehicleEnteredDepotThisTick(), VehiclePayment(), and WhoCanServiceIndustry().
static T KillFirstBit | ( | T | 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.
value | The value to clear the first bit |
Definition at line 226 of file bitmath_func.hpp.
Referenced by CYapfBaseT< Types >::AddMultipleNodes(), CmdBuildSingleSignal(), CYapfOriginTileT< Types >::PfSetStartupNodes(), RoadFindPathToDest(), TrackBitsToTrack(), and TracksOverlap().
static T ROL | ( | const T | x, | |
const uint8 | n | |||
) | [inline, static] |
ROtate x Left by n.
x | The value which we want to rotate | |
n | The number how many we waht to rotate |
Definition at line 261 of file bitmath_func.hpp.
static T ROR | ( | const T | x, | |
const uint8 | n | |||
) | [inline, static] |
ROtate x Right by n.
x | The value which we want to rotate | |
n | The number how many we waht to rotate |
Definition at line 274 of file bitmath_func.hpp.
Referenced by Randomizer::Next().
static T SB | ( | T & | x, | |
const uint8 | s, | |||
const uint8 | n, | |||
const U | d | |||
) | [inline, static] |
Set n bits from 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 b isn't "big" enough. This is not a bug, its a feature.
To avoid unexpecting results the value of b should not use more space as the provided space of n bits (log2)
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. |
Definition at line 46 of file bitmath_func.hpp.
Referenced by CmdSignalTrackHelper(), GenericPlaceSignals(), GetGlobalVariable(), HaltLift(), HandleAutoSignalPlacement(), IndustryProductionCallback(), LoadUnloadVehicle(), MakeClear(), RailVehicleChangeInfo(), ResetIndustryConstructionStage(), SetClearCounter(), SetDisallowedRoadDirections(), RoadStop::SetEntranceBusy(), SetFenceSE(), SetFenceSW(), SetFieldType(), SetHasSignals(), SetHouseAnimationFrame(), SetHouseCompleted(), SetHouseTriggers(), SetHouseType(), SetIndustryCompleted(), SetIndustryConstructionCounter(), SetIndustryConstructionStage(), SetIndustryGfx(), SetIndustryTriggers(), SetLiftDestination(), SetLiftPosition(), SetNewsDisplayValue(), SetPlayerFaceBits(), SetPresentSignals(), SetRailType(), SetSignalStates(), SetTileHeight(), SetTileType(), SetTrackBits(), SetTreeCount(), SetTreeCounter(), SetTreeGroundDensity(), SetTreeGrowth(), SetTropicZone(), SetTunnelBridgeSnowOrDesert(), and UpdateStationAcceptance().
static 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.
x | The variable to set a bit | |
y | The bit position to set |
Definition at line 113 of file bitmath_func.hpp.
Referenced by AddChildSpriteScreen(), AddSortableSpriteToDraw(), BuildTownHouse(), CalculateRefitMasks(), CmdAutofillTimetable(), CmdBuildAircraft(), CmdBuildAirport(), CmdBuildBuoy(), CmdBuildDock(), CmdBuildRailroadStation(), CmdBuildRailVehicle(), CmdBuildRoadStop(), CmdBuildRoadVeh(), CmdBuildShip(), CmdCloneVehicle(), CmdRemoveRailroadTrack(), CmdRemoveSignalTrack(), CmdSendAircraftToHangar(), CmdSendRoadVehToDepot(), CmdSendShipToDepot(), CmdSendTrainToDepot(), CmdSignalTrackHelper(), ConvertFromOldPlayerFace(), ConvertOldMultiheadToNew(), CopyGRFConfigList(), DrawCatenaryRailway(), RoadStop::FreeBay(), GetCountAndDistanceOfClosestInstance(), GetPlayerRailtypes(), GetPlayerRoadtypes(), GetValidAirports(), IsGoodGRFConfigList(), LoadUnloadVehicle(), lookup_manyofmany(), MakeDefaultWaypointName(), MapSpriteMappingRecolour(), NPFSetFlag(), RailVehicleLengthChanged(), SetArticulatedPart(), SetBridgeMiddle(), SetFreeWagon(), SetFrontEngine(), SetLiftDestination(), SetMultiheaded(), SettingsDisableElrail(), SetTrainEngine(), SetTrainWagon(), TownActionBuildStatue(), TrainConsistChanged(), UpdateTownGrowRate(), and VehiclePayment().
static 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.
x | The varliable to toggle the bit | |
y | The bit position to toggle |
Definition at line 169 of file bitmath_func.hpp.
Referenced by CmdModifyOrder(), CmdRailTrackHelper(), CmdReverseTrainDirection(), CmdSendAircraftToHangar(), CmdSendRoadVehToDepot(), CmdSendShipToDepot(), CmdSendTrainToDepot(), CmdSignalTrackHelper(), ReverseTrainDirection(), ToggleTransparency(), and ToggleTransparencyLock().