Change: make GetPartialZ consistent, meaning Z of adjacent slopes continue
Previously, on a straight line of a one corner up slope with the adjacent steep sloop the Z would increase one step every two sub pixels, except for one case where one sub pixel is skipped. Similarly, a steep slope with two adjacent one corner up slopes, would have a bump in the height line along the diagonal whenever it enters/leaves the steep slope tile.
This commit is contained in:
@@ -210,137 +210,79 @@ uint ApplyFoundationToSlope(Foundation f, Slope *s)
|
||||
|
||||
|
||||
/**
|
||||
* Determines height at given coordinate of a slope
|
||||
* @param x x coordinate
|
||||
* @param y y coordinate
|
||||
* Determines height at given coordinate of a slope.
|
||||
*
|
||||
* At the northern corner (0, 0) the result is always a multiple of TILE_HEIGHT.
|
||||
* When the height is a fractional Z, then the height is rounded down. For example,
|
||||
* when at the height is 0 at x = 0 and the height is 8 at x = 16 (actually x = 0
|
||||
* of the next tile), then height is 0 at x = 1, 1 at x = 2, and 7 at x = 15.
|
||||
* @param x x coordinate (value from 0 to 15)
|
||||
* @param y y coordinate (value from 0 to 15)
|
||||
* @param corners slope to examine
|
||||
* @return height of given point of given slope
|
||||
*/
|
||||
uint GetPartialPixelZ(int x, int y, Slope corners)
|
||||
{
|
||||
if (IsHalftileSlope(corners)) {
|
||||
/* A foundation is placed on half the tile at a specific corner. This means that,
|
||||
* depending on the corner, that one half of the tile is at the maximum height. */
|
||||
switch (GetHalftileSlopeCorner(corners)) {
|
||||
case CORNER_W:
|
||||
if (x - y >= 0) return GetSlopeMaxPixelZ(corners);
|
||||
if (x > y) return GetSlopeMaxPixelZ(corners);
|
||||
break;
|
||||
|
||||
case CORNER_S:
|
||||
if (x - (y ^ 0xF) >= 0) return GetSlopeMaxPixelZ(corners);
|
||||
if (x + y >= (int)TILE_SIZE) return GetSlopeMaxPixelZ(corners);
|
||||
break;
|
||||
|
||||
case CORNER_E:
|
||||
if (y - x >= 0) return GetSlopeMaxPixelZ(corners);
|
||||
if (x <= y) return GetSlopeMaxPixelZ(corners);
|
||||
break;
|
||||
|
||||
case CORNER_N:
|
||||
if ((y ^ 0xF) - x >= 0) return GetSlopeMaxPixelZ(corners);
|
||||
if (x + y < (int)TILE_SIZE) return GetSlopeMaxPixelZ(corners);
|
||||
break;
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
int z = 0;
|
||||
|
||||
switch (RemoveHalftileSlope(corners)) {
|
||||
case SLOPE_W:
|
||||
if (x - y >= 0) {
|
||||
z = (x - y) >> 1;
|
||||
}
|
||||
break;
|
||||
case SLOPE_FLAT: return 0;
|
||||
|
||||
case SLOPE_S:
|
||||
y ^= 0xF;
|
||||
if ((x - y) >= 0) {
|
||||
z = (x - y) >> 1;
|
||||
}
|
||||
break;
|
||||
/* One corner is up.*/
|
||||
case SLOPE_N: return x + y <= (int)TILE_SIZE ? (TILE_SIZE - x - y) >> 1 : 0;
|
||||
case SLOPE_E: return y >= x ? (1 + y - x) >> 1 : 0;
|
||||
case SLOPE_S: return x + y >= (int)TILE_SIZE ? (1 + x + y - TILE_SIZE) >> 1 : 0;
|
||||
case SLOPE_W: return x >= y ? (x - y) >> 1 : 0;
|
||||
|
||||
case SLOPE_SW:
|
||||
z = (x >> 1) + 1;
|
||||
break;
|
||||
/* Two corners next to eachother are up. */
|
||||
case SLOPE_NE: return (TILE_SIZE - x) >> 1;
|
||||
case SLOPE_SE: return (y + 1) >> 1;
|
||||
case SLOPE_SW: return (x + 1) >> 1;
|
||||
case SLOPE_NW: return (TILE_SIZE - y) >> 1;
|
||||
|
||||
case SLOPE_E:
|
||||
if (y - x >= 0) {
|
||||
z = (y - x) >> 1;
|
||||
}
|
||||
break;
|
||||
/* Three corners are up on the same level. */
|
||||
case SLOPE_ENW: return x + y >= (int)TILE_SIZE ? TILE_HEIGHT - ((1 + x + y - TILE_SIZE) >> 1) : TILE_HEIGHT;
|
||||
case SLOPE_SEN: return y < x ? TILE_HEIGHT - ((x - y) >> 1) : TILE_HEIGHT;
|
||||
case SLOPE_WSE: return x + y <= (int)TILE_SIZE ? TILE_HEIGHT - ((TILE_SIZE - x - y) >> 1) : TILE_HEIGHT;
|
||||
case SLOPE_NWS: return x < y ? TILE_HEIGHT - ((1 + y - x) >> 1) : TILE_HEIGHT;
|
||||
|
||||
case SLOPE_EW:
|
||||
case SLOPE_NS:
|
||||
case SLOPE_ELEVATED:
|
||||
z = 4;
|
||||
break;
|
||||
/* Two corners at opposite sides are up. */
|
||||
case SLOPE_NS: return x + y < (int)TILE_SIZE ? (TILE_SIZE - x - y) >> 1 : (1 + x + y - TILE_SIZE) >> 1;
|
||||
case SLOPE_EW: return x >= y ? (x - y) >> 1 : (1 + y - x) >> 1;
|
||||
|
||||
case SLOPE_SE:
|
||||
z = (y >> 1) + 1;
|
||||
break;
|
||||
/* Very special cases. */
|
||||
case SLOPE_ELEVATED: return TILE_HEIGHT;
|
||||
|
||||
case SLOPE_WSE:
|
||||
z = 8;
|
||||
y ^= 0xF;
|
||||
if (x - y < 0) {
|
||||
z += (x - y) >> 1;
|
||||
}
|
||||
break;
|
||||
/* Steep slopes. The top is at 2 * TILE_HEIGHT. */
|
||||
case SLOPE_STEEP_N: return (TILE_SIZE - x + TILE_SIZE - y) >> 1;
|
||||
case SLOPE_STEEP_E: return (TILE_SIZE + 1 + y - x) >> 1;
|
||||
case SLOPE_STEEP_S: return (1 + x + y) >> 1;
|
||||
case SLOPE_STEEP_W: return (TILE_SIZE + x - y) >> 1;
|
||||
|
||||
case SLOPE_N:
|
||||
y ^= 0xF;
|
||||
if (y - x >= 0) {
|
||||
z = (y - x) >> 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case SLOPE_NW:
|
||||
z = (y ^ 0xF) >> 1;
|
||||
break;
|
||||
|
||||
case SLOPE_NWS:
|
||||
z = 8;
|
||||
if (x - y < 0) {
|
||||
z += (x - y) >> 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case SLOPE_NE:
|
||||
z = (x ^ 0xF) >> 1;
|
||||
break;
|
||||
|
||||
case SLOPE_ENW:
|
||||
z = 8;
|
||||
y ^= 0xF;
|
||||
if (y - x < 0) {
|
||||
z += (y - x) >> 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case SLOPE_SEN:
|
||||
z = 8;
|
||||
if (y - x < 0) {
|
||||
z += (y - x) >> 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case SLOPE_STEEP_S:
|
||||
z = 1 + ((x + y) >> 1);
|
||||
break;
|
||||
|
||||
case SLOPE_STEEP_W:
|
||||
z = 1 + ((x + (y ^ 0xF)) >> 1);
|
||||
break;
|
||||
|
||||
case SLOPE_STEEP_N:
|
||||
z = 1 + (((x ^ 0xF) + (y ^ 0xF)) >> 1);
|
||||
break;
|
||||
|
||||
case SLOPE_STEEP_E:
|
||||
z = 1 + (((x ^ 0xF) + y) >> 1);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user