Skip to content

Commit c72d1ac

Browse files
committed
Fixed Edge Tiles
Edge tiles now properly place into the terrain
1 parent af606b0 commit c72d1ac

File tree

1 file changed

+43
-57
lines changed

1 file changed

+43
-57
lines changed

src/TerrainGen/Terrain_Gen.cpp

Lines changed: 43 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,9 +1260,9 @@ Dictionary TerrainGen::generate(
12601260
//
12611261
// Phase 2 : Determine the Tile's Rotation
12621262
//
1263-
// Models: ramps/cliffs/water_edge start with HIGH side pointing −Z (NORTH).
1264-
// Corner models start with HIGH at (−Z, +X) i.e., NE corner.
1265-
// Rotation indices: NORTH=0, EAST=16, SOUTH=10, WEST=22
1263+
// Models: Ramp Corner's/ Cliff Corner's / Water Corner's start with HIGH at (−Z, +X)
1264+
// i.e., NE corner.
1265+
// Ramps / Cliffs / Water Edge's point at -Z (North)
12661266
//
12671267
// T = Target Cell / Target Tile
12681268
// +----+----+----+
@@ -1326,59 +1326,48 @@ Dictionary TerrainGen::generate(
13261326
int nwTile = safe_tile_at(x - 1, y + 1); // m1
13271327

13281328
if (tile_id == RAMP || tile_id == CLIFF || tile_id == WATER_EDGE) {
1329-
// Point HIGH side toward the highest GROUND neighbor (uphill)
1330-
float best_diff = -1e9f;
1331-
if (sTile == GROUND) {
1332-
float d = float(sHeight) - float(c_height);
1333-
if (d > best_diff) {
1334-
best_diff = d;
1335-
rotation_val = SOUTH;
1336-
}
1337-
}
1338-
if (nTile == GROUND) {
1339-
float d = float(nHeight) - float(c_height);
1340-
if (d > best_diff) {
1341-
best_diff = d;
1342-
rotation_val = NORTH;
1343-
}
1329+
// +----+----+----+
1330+
// | m1 | m2 | m3 |
1331+
// +----+----+----+
1332+
// | m4 | T | m5 |
1333+
// +----+----+----+
1334+
// | m6 | m7 | m8 |
1335+
// +----+----+----+
1336+
1337+
// Cardinal's
1338+
//
1339+
// N (m7), E (m5), S (m2), W (m4)
1340+
//
1341+
// Only two possible combinations an edge piece can be placed
1342+
// Since an edge piece must connect from lower elevation to
1343+
// higher elevation.
1344+
// Thus, m2 + m7 vs m4 + m5
1345+
//
1346+
// Of those two combinations, there is two ways to rotate
1347+
//
1348+
1349+
// North is higher than South
1350+
// Point to m7
1351+
if (nHeight == sHeight + 1 && static_cast<TileType>(nTile) == GROUND) {
1352+
rotation_val = NORTH;
13441353
}
1345-
if (eTile == GROUND) {
1346-
float d = float(eHeight) - float(c_height);
1347-
if (d > best_diff) {
1348-
best_diff = d;
1349-
rotation_val = EAST;
1350-
}
1354+
1355+
// South is higher than North
1356+
// Point to m2
1357+
if (sHeight == nHeight + 1 && static_cast<TileType>(sTile) == GROUND) {
1358+
rotation_val = SOUTH;
13511359
}
1352-
if (wTile == GROUND) {
1353-
float d = float(wHeight) - float(c_height);
1354-
if (d > best_diff) {
1355-
best_diff = d;
1356-
rotation_val = WEST;
1357-
}
1360+
1361+
// East is higher than West
1362+
// Point to m5
1363+
if (eHeight == wHeight + 1 && static_cast<TileType>(eTile) == GROUND) {
1364+
rotation_val = EAST;
13581365
}
13591366

1360-
// Fallback: if no GROUND neighbor higher, use steepest slope regardless of type
1361-
if (best_diff <= -1e8f) {
1362-
float bd = -1e9f;
1363-
float dN = float(nHeight) - float(c_height);
1364-
float dS = float(sHeight) - float(c_height);
1365-
float dE = float(eHeight) - float(c_height);
1366-
float dW = float(wHeight) - float(c_height);
1367-
if (dN > bd) {
1368-
bd = dN;
1369-
}
1370-
if (dS > bd) {
1371-
bd = dS;
1372-
rotation_val = SOUTH;
1373-
}
1374-
if (dE > bd) {
1375-
bd = dE;
1376-
rotation_val = EAST;
1377-
}
1378-
if (dW > bd) {
1379-
bd = dW;
1380-
rotation_val = WEST;
1381-
}
1367+
// West is higher than East
1368+
// Point to m4
1369+
if (wHeight == eHeight + 1 && static_cast<TileType>(wTile) == GROUND) {
1370+
rotation_val = WEST;
13821371
}
13831372
}
13841373

@@ -1393,10 +1382,9 @@ Dictionary TerrainGen::generate(
13931382
//
13941383
// T should consider m2 + m5, m5 + m7, m7 + m4, and m4 + m2; for cliffs and ramps
13951384
// Then it should find the highest elevation of ground piece at, m3, m8, m6, m1
1396-
// Then it should decide the rotation by rotating the cliff corner / ramp corner / water corner
1397-
// toward the higher elevation
1385+
// Then it should decide the rotation by rotating the corner toward the higher elevation
13981386
//
1399-
// Corner meshes: choose the corner defined by edge tiles around T, then aim toward the higher diagonal ground
1387+
// choose corner defined by edge tiles around T, aim toward the higher diagonal ground
14001388
//
14011389
else if (tile_id == RAMP_CORNER || tile_id == CLIFF_CORNER || tile_id == WATER_CORNER) {
14021390
int ROT_CORNER_NE = WEST;
@@ -1429,8 +1417,6 @@ Dictionary TerrainGen::generate(
14291417
const bool swGround = (static_cast<TileType>(swTile) == GROUND);
14301418
const bool nwGround = (static_cast<TileType>(nwTile) == GROUND);
14311419

1432-
// TODO : Find Cardinal Pairs
1433-
14341420
// +----+----+----+
14351421
// | m1 | m2 | m3 |
14361422
// +----+----+----+

0 commit comments

Comments
 (0)