Mercurial > hg > openttd
changeset 15004:087f6f616f99 draft
(svn r19616) -Codechange: Increase transparency of 'Extract' by passing also the number of used bits.
author | frosch <frosch@openttd.org> |
---|---|
date | Tue, 13 Apr 2010 17:29:19 +0000 |
parents | 895f760ad105 |
children | f04b04bda68d |
files | src/cmd_helper.h src/rail_cmd.cpp src/road_cmd.cpp src/station_cmd.cpp src/water_cmd.cpp |
diffstat | 5 files changed, 12 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/cmd_helper.h +++ b/src/cmd_helper.h @@ -14,12 +14,13 @@ #include "core/enum_type.hpp" -template<typename T, uint N, typename U> static inline T Extract(U v) +template<typename T, uint S, uint N, typename U> static inline T Extract(U v) { /* Check if there are enough bits in v */ - assert_tcompile(N + EnumPropsT<T>::num_bits <= sizeof(U) * 8); - assert_tcompile(EnumPropsT<T>::end <= (1 << EnumPropsT<T>::num_bits)); - return (T)GB(v, N, EnumPropsT<T>::num_bits); + assert_tcompile(N == EnumPropsT<T>::num_bits); + assert_tcompile(S + N <= sizeof(U) * 8); + assert_tcompile(EnumPropsT<T>::end <= (1 << N)); + return (T)GB(v, S, N); } #endif
--- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -837,7 +837,7 @@ Slope tileh = GetTileSlope(tile, NULL); - DiagDirection dir = Extract<DiagDirection, 0>(p2); + DiagDirection dir = Extract<DiagDirection, 0, 2>(p2); /* Prohibit construction if * The tile is non-flat AND
--- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -464,7 +464,7 @@ p2 = (town != NULL) ? town->index : (TownID)INVALID_TOWN; } - RoadBits pieces = Extract<RoadBits, 0>(p1); + RoadBits pieces = Extract<RoadBits, 0, 4>(p1); /* do not allow building 'zero' road bits, code wouldn't handle it */ if (pieces == ROAD_NONE) return CMD_ERROR; @@ -729,7 +729,7 @@ RoadType rt = (RoadType)GB(p2, 3, 2); if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR; - Axis axis = Extract<Axis, 2>(p2); + Axis axis = Extract<Axis, 2, 1>(p2); /* Only drag in X or Y direction dictated by the direction variable */ if (axis == AXIS_X && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis if (axis == AXIS_Y && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis @@ -821,7 +821,7 @@ RoadType rt = (RoadType)GB(p2, 3, 2); if (!IsValidRoadType(rt)) return CMD_ERROR; - Axis axis = Extract<Axis, 2>(p2); + Axis axis = Extract<Axis, 2, 1>(p2); /* Only drag in X or Y direction dictated by the direction variable */ if (axis == AXIS_X && TileY(start_tile) != TileY(end_tile)) return CMD_ERROR; // x-axis if (axis == AXIS_Y && TileX(start_tile) != TileX(end_tile)) return CMD_ERROR; // y-axis @@ -886,7 +886,7 @@ */ CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - DiagDirection dir = Extract<DiagDirection, 0>(p1); + DiagDirection dir = Extract<DiagDirection, 0, 2>(p1); RoadType rt = (RoadType)GB(p1, 2, 2); if (!IsValidRoadType(rt) || !ValParamRoadType(rt)) return CMD_ERROR;
--- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1096,7 +1096,7 @@ { /* Unpack parameters */ RailType rt = (RailType)GB(p1, 0, 4); - Axis axis = Extract<Axis, 4>(p1); + Axis axis = Extract<Axis, 4, 1>(p1); byte numtracks = GB(p1, 8, 8); byte plat_len = GB(p1, 16, 8); bool adjacent = HasBit(p1, 24);
--- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -104,7 +104,7 @@ */ CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - Axis axis = Extract<Axis, 0>(p1); + Axis axis = Extract<Axis, 0, 1>(p1); TileIndex tile2 = tile + (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));