mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
(svn r23092) -Codechange: create a non-pixel version of some of the Get*PixelZ functions, and let Get*PixelZ wrap around the new function (multiplying the Z by TILE_HEIGHT) just like TileHeight and TilePixelHeight
This commit is contained in:
parent
7757a2ed40
commit
a36551dbb4
@ -63,16 +63,16 @@ TileIndex GetOtherBridgeEnd(TileIndex tile)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height ('z') of a bridge in pixels.
|
||||
* Get the height ('z') of a bridge.
|
||||
* @param tile the bridge ramp tile to get the bridge height from
|
||||
* @return the height of the bridge in pixels
|
||||
* @return the height of the bridge.
|
||||
*/
|
||||
uint GetBridgePixelHeight(TileIndex t)
|
||||
uint GetBridgeHeight(TileIndex t)
|
||||
{
|
||||
uint h;
|
||||
Slope tileh = GetTilePixelSlope(t, &h);
|
||||
Slope tileh = GetTileSlope(t, &h);
|
||||
Foundation f = GetBridgeFoundation(tileh, DiagDirToAxis(GetTunnelBridgeDirection(t)));
|
||||
|
||||
/* one height level extra for the ramp */
|
||||
return h + TILE_HEIGHT + ApplyPixelFoundationToSlope(f, &tileh);
|
||||
return h + 1 + ApplyFoundationToSlope(f, &tileh);
|
||||
}
|
||||
|
@ -89,7 +89,16 @@ TileIndex GetNorthernBridgeEnd(TileIndex t);
|
||||
TileIndex GetSouthernBridgeEnd(TileIndex t);
|
||||
TileIndex GetOtherBridgeEnd(TileIndex t);
|
||||
|
||||
uint GetBridgePixelHeight(TileIndex tile);
|
||||
uint GetBridgeHeight(TileIndex tile);
|
||||
/**
|
||||
* Get the height ('z') of a bridge in pixels.
|
||||
* @param tile the bridge ramp tile to get the bridge height from
|
||||
* @return the height of the bridge in pixels
|
||||
*/
|
||||
static inline uint GetBridgePixelHeight(TileIndex tile)
|
||||
{
|
||||
return GetBridgeHeight(tile) * TILE_HEIGHT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the bridge over the given axis.
|
||||
|
@ -94,12 +94,12 @@ static SnowLine *_snow_line = NULL;
|
||||
* @param s The #Slope to modify.
|
||||
* @return Increment to the tile Z coordinate.
|
||||
*/
|
||||
uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
|
||||
uint ApplyFoundationToSlope(Foundation f, Slope *s)
|
||||
{
|
||||
if (!IsFoundation(f)) return 0;
|
||||
|
||||
if (IsLeveledFoundation(f)) {
|
||||
uint dz = TILE_HEIGHT + (IsSteepSlope(*s) ? TILE_HEIGHT : 0);
|
||||
uint dz = 1 + (IsSteepSlope(*s) ? 1 : 0);
|
||||
*s = SLOPE_FLAT;
|
||||
return dz;
|
||||
}
|
||||
@ -114,7 +114,7 @@ uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint dz = IsSteepSlope(*s) ? TILE_HEIGHT : 0;
|
||||
uint dz = IsSteepSlope(*s) ? 1 : 0;
|
||||
Corner highest_corner = GetHighestSlopeCorner(*s);
|
||||
|
||||
switch (f) {
|
||||
@ -290,10 +290,10 @@ uint GetSlopePixelZ(int x, int y)
|
||||
* @param corner The corner.
|
||||
* @return Z position of corner relative to TileZ.
|
||||
*/
|
||||
int GetSlopePixelZInCorner(Slope tileh, Corner corner)
|
||||
int GetSlopeZInCorner(Slope tileh, Corner corner)
|
||||
{
|
||||
assert(!IsHalftileSlope(tileh));
|
||||
return ((tileh & SlopeWithOneCornerRaised(corner)) != 0 ? TILE_HEIGHT : 0) + (tileh == SteepSlope(corner) ? TILE_HEIGHT : 0);
|
||||
return ((tileh & SlopeWithOneCornerRaised(corner)) != 0 ? 1 : 0) + (tileh == SteepSlope(corner) ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -337,11 +337,11 @@ void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int *z1, int *z2)
|
||||
* @param z returns the z of the foundation slope. (Can be NULL, if not needed)
|
||||
* @return The slope on top of the foundation.
|
||||
*/
|
||||
Slope GetFoundationPixelSlope(TileIndex tile, uint *z)
|
||||
Slope GetFoundationSlope(TileIndex tile, uint *z)
|
||||
{
|
||||
Slope tileh = GetTilePixelSlope(tile, z);
|
||||
Slope tileh = GetTileSlope(tile, z);
|
||||
Foundation f = _tile_type_procs[GetTileType(tile)]->get_foundation_proc(tile, tileh);
|
||||
uint z_inc = ApplyPixelFoundationToSlope(f, &tileh);
|
||||
uint z_inc = ApplyFoundationToSlope(f, &tileh);
|
||||
if (z != NULL) *z += z_inc;
|
||||
return tileh;
|
||||
}
|
||||
|
@ -35,11 +35,41 @@ byte HighestSnowLine();
|
||||
byte LowestSnowLine();
|
||||
void ClearSnowLine();
|
||||
|
||||
int GetSlopeZInCorner(Slope tileh, Corner corner);
|
||||
Slope GetFoundationSlope(TileIndex tile, uint *z);
|
||||
|
||||
uint GetPartialPixelZ(int x, int y, Slope corners);
|
||||
uint GetSlopePixelZ(int x, int y);
|
||||
void GetSlopePixelZOnEdge(Slope tileh, DiagDirection edge, int *z1, int *z2);
|
||||
int GetSlopePixelZInCorner(Slope tileh, Corner corner);
|
||||
Slope GetFoundationPixelSlope(TileIndex tile, uint *z);
|
||||
|
||||
/**
|
||||
* Determine the Z height of a corner relative to TileZ.
|
||||
*
|
||||
* @pre The slope must not be a halftile slope.
|
||||
*
|
||||
* @param tileh The slope.
|
||||
* @param corner The corner.
|
||||
* @return Z position of corner relative to TileZ.
|
||||
*/
|
||||
static inline int GetSlopePixelZInCorner(Slope tileh, Corner corner)
|
||||
{
|
||||
return GetSlopeZInCorner(tileh, corner) * TILE_HEIGHT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get slope of a tile on top of a (possible) foundation
|
||||
* If a tile does not have a foundation, the function returns the same as GetTilePixelSlope.
|
||||
*
|
||||
* @param tile The tile of interest.
|
||||
* @param z returns the z of the foundation slope. (Can be NULL, if not needed)
|
||||
* @return The slope on top of the foundation.
|
||||
*/
|
||||
static inline Slope GetFoundationPixelSlope(TileIndex tile, uint *z)
|
||||
{
|
||||
Slope s = GetFoundationSlope(tile, z);
|
||||
if (z != NULL) *z *= TILE_HEIGHT;
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
|
||||
@ -84,7 +114,20 @@ static inline Point InverseRemapCoords(int x, int y)
|
||||
return pt;
|
||||
}
|
||||
|
||||
uint ApplyPixelFoundationToSlope(Foundation f, Slope *s);
|
||||
uint ApplyFoundationToSlope(Foundation f, Slope *s);
|
||||
/**
|
||||
* Applies a foundation to a slope.
|
||||
*
|
||||
* @pre Foundation and slope must be valid combined.
|
||||
* @param f The #Foundation.
|
||||
* @param s The #Slope to modify.
|
||||
* @return Increment to the tile Z coordinate.
|
||||
*/
|
||||
static inline uint ApplyPixelFoundationToSlope(Foundation f, Slope *s)
|
||||
{
|
||||
return ApplyFoundationToSlope(f, s) * TILE_HEIGHT;
|
||||
}
|
||||
|
||||
void DrawFoundation(TileInfo *ti, Foundation f);
|
||||
bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here);
|
||||
bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here);
|
||||
|
@ -159,11 +159,22 @@ static inline Corner GetHalftileSlopeCorner(Slope s)
|
||||
* @param s The #Slope.
|
||||
* @return Relative height of highest corner.
|
||||
*/
|
||||
static inline uint GetSlopeMaxPixelZ(Slope s)
|
||||
static inline uint GetSlopeMaxZ(Slope s)
|
||||
{
|
||||
if (s == SLOPE_FLAT) return 0;
|
||||
if (IsSteepSlope(s)) return 2 * TILE_HEIGHT;
|
||||
return TILE_HEIGHT;
|
||||
if (IsSteepSlope(s)) return 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
|
||||
*
|
||||
* @param s The #Slope.
|
||||
* @return Relative height of highest corner.
|
||||
*/
|
||||
static inline uint GetSlopeMaxPixelZ(Slope s)
|
||||
{
|
||||
return GetSlopeMaxZ(s) * TILE_HEIGHT;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,13 +18,13 @@
|
||||
* @param h If not \c NULL, pointer to storage of z height
|
||||
* @return Slope of the tile, except for the HALFTILE part
|
||||
*/
|
||||
Slope GetTilePixelSlope(TileIndex tile, uint *h)
|
||||
Slope GetTileSlope(TileIndex tile, uint *h)
|
||||
{
|
||||
assert(tile < MapSize());
|
||||
|
||||
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY() ||
|
||||
(_settings_game.construction.freeform_edges && (TileX(tile) == 0 || TileY(tile) == 0))) {
|
||||
if (h != NULL) *h = TileHeight(tile) * TILE_HEIGHT;
|
||||
if (h != NULL) *h = TileHeight(tile);
|
||||
return SLOPE_FLAT;
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ Slope GetTilePixelSlope(TileIndex tile, uint *h)
|
||||
if ((d -= min) != 0) r += (--d << 4) + SLOPE_S;
|
||||
if ((b -= min) != 0) r += (--b << 4) + SLOPE_W;
|
||||
|
||||
if (h != NULL) *h = min * TILE_HEIGHT;
|
||||
if (h != NULL) *h = min;
|
||||
|
||||
return (Slope)r;
|
||||
}
|
||||
@ -64,7 +64,7 @@ Slope GetTilePixelSlope(TileIndex tile, uint *h)
|
||||
* @param tile Tile to compute height of
|
||||
* @return Minimum height of the tile
|
||||
*/
|
||||
uint GetTilePixelZ(TileIndex tile)
|
||||
uint GetTileZ(TileIndex tile)
|
||||
{
|
||||
if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return 0;
|
||||
|
||||
@ -73,7 +73,7 @@ uint GetTilePixelZ(TileIndex tile)
|
||||
h = min(h, TileHeight(tile + TileDiffXY(0, 1))); // E corner
|
||||
h = min(h, TileHeight(tile + TileDiffXY(1, 1))); // S corner
|
||||
|
||||
return h * TILE_HEIGHT;
|
||||
return h;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,7 +81,7 @@ uint GetTilePixelZ(TileIndex tile)
|
||||
* @param t Tile to compute height of
|
||||
* @return Maximum height of the tile
|
||||
*/
|
||||
uint GetTileMaxPixelZ(TileIndex t)
|
||||
uint GetTileMaxZ(TileIndex t)
|
||||
{
|
||||
if (TileX(t) == MapMaxX() || TileY(t) == MapMaxY()) return 0;
|
||||
|
||||
@ -90,5 +90,5 @@ uint GetTileMaxPixelZ(TileIndex t)
|
||||
h = max(h, TileHeight(t + TileDiffXY(0, 1))); // E corner
|
||||
h = max(h, TileHeight(t + TileDiffXY(1, 1))); // S corner
|
||||
|
||||
return h * TILE_HEIGHT;
|
||||
return h;
|
||||
}
|
||||
|
@ -226,9 +226,42 @@ static inline void SetAnimationFrame(TileIndex t, byte frame)
|
||||
_me[t].m7 = frame;
|
||||
}
|
||||
|
||||
Slope GetTilePixelSlope(TileIndex tile, uint *h);
|
||||
uint GetTilePixelZ(TileIndex tile);
|
||||
uint GetTileMaxPixelZ(TileIndex tile);
|
||||
Slope GetTileSlope(TileIndex tile, uint *h = NULL);
|
||||
uint GetTileZ(TileIndex tile);
|
||||
uint GetTileMaxZ(TileIndex tile);
|
||||
|
||||
/**
|
||||
* Return the slope of a given tile
|
||||
* @param tile Tile to compute slope of
|
||||
* @param h If not \c NULL, pointer to storage of z height
|
||||
* @return Slope of the tile, except for the HALFTILE part
|
||||
*/
|
||||
static inline Slope GetTilePixelSlope(TileIndex tile, uint *h)
|
||||
{
|
||||
Slope s = GetTileSlope(tile, h);
|
||||
if (h != NULL) *h *= TILE_HEIGHT;
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bottom height of the tile
|
||||
* @param tile Tile to compute height of
|
||||
* @return Minimum height of the tile
|
||||
*/
|
||||
static inline uint GetTilePixelZ(TileIndex tile)
|
||||
{
|
||||
return GetTileZ(tile) * TILE_HEIGHT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top height of the tile
|
||||
* @param t Tile to compute height of
|
||||
* @return Maximum height of the tile
|
||||
*/
|
||||
static inline uint GetTileMaxPixelZ(TileIndex tile)
|
||||
{
|
||||
return GetTileMaxZ(tile) * TILE_HEIGHT;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user