MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / OnSmoothTerrain

Method OnSmoothTerrain

editor/TerrainDialog.cpp:1416–1504  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1414}
1415
1416void CTerrainDialog::OnSmoothTerrain() {
1417 uint8_t *src_data;
1418 int y, x;
1419
1420 if (Num_terrain_selected == 0) {
1421 OutrageMessageBox("This operation works on selected cells. You have no cells selected!");
1422 return;
1423 }
1424
1425 if ((MessageBox("Are you sure you wish to smooth the terrain? This operation cannot be undone.", "Question",
1426 MB_YESNO)) == IDNO)
1427 return;
1428
1429 src_data = (uint8_t *)mem_malloc(TERRAIN_WIDTH * TERRAIN_DEPTH);
1430 ASSERT(src_data); // Ran out of memory!
1431
1432 for (int i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++)
1433 src_data[i] = Terrain_seg[i].ypos;
1434
1435 int w = TERRAIN_WIDTH;
1436 int h = TERRAIN_DEPTH;
1437
1438 for (y = 0; y < h; y++) {
1439 for (x = 0; x < w; x++) {
1440 if (!TerrainSelected[y * w + x])
1441 continue;
1442
1443 int total = 0;
1444 int num = 0;
1445
1446 total += src_data[y * w + x];
1447 num++;
1448
1449 // Left edge
1450 if (x != 0) {
1451
1452 total += src_data[y * w + (x - 1)];
1453 num++;
1454
1455 if (y != 0) {
1456 total += src_data[(y - 1) * w + (x - 1)];
1457 num++;
1458 }
1459
1460 if (y != h - 1) {
1461 total += src_data[(y + 1) * w + (x - 1)];
1462 num++;
1463 }
1464 }
1465
1466 // Right edge
1467 if (x != (w - 1)) {
1468 total += src_data[(y)*w + (x + 1)];
1469 num++;
1470
1471 if (y != 0) {
1472 total += src_data[(y - 1) * w + (x + 1)];
1473 num++;

Callers

nothing calls this directly

Calls 2

OutrageMessageBoxFunction · 0.85
BuildMinMaxTerrainFunction · 0.85

Tested by

no test coverage detected