@@ -1398,97 +1398,42 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
1398
1398
break ;}
1399
1399
case NDT_RAILLIKE:
1400
1400
{
1401
- bool is_rail_x [] = { false , false }; /* x-1, x+1 */
1402
- bool is_rail_z [] = { false , false }; /* z-1, z+1 */
1403
-
1404
- bool is_rail_z_minus_y [] = { false , false }; /* z-1, z+1; y-1 */
1405
- bool is_rail_x_minus_y [] = { false , false }; /* x-1, z+1; y-1 */
1406
- bool is_rail_z_plus_y [] = { false , false }; /* z-1, z+1; y+1 */
1407
- bool is_rail_x_plus_y [] = { false , false }; /* x-1, x+1; y+1 */
1408
-
1409
- MapNode n_minus_x = data->m_vmanip .getNodeNoEx (blockpos_nodes + v3s16 (x-1 ,y,z));
1410
- MapNode n_plus_x = data->m_vmanip .getNodeNoEx (blockpos_nodes + v3s16 (x+1 ,y,z));
1411
- MapNode n_minus_z = data->m_vmanip .getNodeNoEx (blockpos_nodes + v3s16 (x,y,z-1 ));
1412
- MapNode n_plus_z = data->m_vmanip .getNodeNoEx (blockpos_nodes + v3s16 (x,y,z+1 ));
1413
- MapNode n_plus_x_plus_y = data->m_vmanip .getNodeNoEx (blockpos_nodes + v3s16 (x+1 , y+1 , z));
1414
- MapNode n_plus_x_minus_y = data->m_vmanip .getNodeNoEx (blockpos_nodes + v3s16 (x+1 , y-1 , z));
1415
- MapNode n_minus_x_plus_y = data->m_vmanip .getNodeNoEx (blockpos_nodes + v3s16 (x-1 , y+1 , z));
1416
- MapNode n_minus_x_minus_y = data->m_vmanip .getNodeNoEx (blockpos_nodes + v3s16 (x-1 , y-1 , z));
1417
- MapNode n_plus_z_plus_y = data->m_vmanip .getNodeNoEx (blockpos_nodes + v3s16 (x, y+1 , z+1 ));
1418
- MapNode n_minus_z_plus_y = data->m_vmanip .getNodeNoEx (blockpos_nodes + v3s16 (x, y+1 , z-1 ));
1419
- MapNode n_plus_z_minus_y = data->m_vmanip .getNodeNoEx (blockpos_nodes + v3s16 (x, y-1 , z+1 ));
1420
- MapNode n_minus_z_minus_y = data->m_vmanip .getNodeNoEx (blockpos_nodes + v3s16 (x, y-1 , z-1 ));
1401
+ bool is_rail_x[6 ]; /* (-1,-1,0) X (1,-1,0) (-1,0,0) X (1,0,0) (-1,1,0) X (1,1,0) */
1402
+ bool is_rail_z[6 ];
1421
1403
1422
1404
content_t thiscontent = n.getContent ();
1423
1405
std::string groupname = " connect_to_raillike" ; // name of the group that enables connecting to raillike nodes of different kind
1424
1406
int self_group = ((ItemGroupList) nodedef->get (n).groups )[groupname];
1425
1407
1426
- if ((nodedef->get (n_minus_x).drawtype == NDT_RAILLIKE
1427
- && ((ItemGroupList) nodedef->get (n_minus_x).groups )[groupname] != self_group)
1428
- || n_minus_x.getContent () == thiscontent)
1429
- is_rail_x[0 ] = true ;
1430
-
1431
- if ((nodedef->get (n_minus_x_minus_y).drawtype == NDT_RAILLIKE
1432
- && ((ItemGroupList) nodedef->get (n_minus_x_minus_y).groups )[groupname] != self_group)
1433
- || n_minus_x_minus_y.getContent () == thiscontent)
1434
- is_rail_x_minus_y[0 ] = true ;
1435
-
1436
- if ((nodedef->get (n_minus_x_plus_y).drawtype == NDT_RAILLIKE
1437
- && ((ItemGroupList) nodedef->get (n_minus_x_plus_y).groups )[groupname] != self_group)
1438
- || n_minus_x_plus_y.getContent () == thiscontent)
1439
- is_rail_x_plus_y[0 ] = true ;
1440
-
1441
- if ((nodedef->get (n_plus_x).drawtype == NDT_RAILLIKE
1442
- && ((ItemGroupList) nodedef->get (n_plus_x).groups )[groupname] != self_group)
1443
- || n_plus_x.getContent () == thiscontent)
1444
- is_rail_x[1 ] = true ;
1445
-
1446
- if ((nodedef->get (n_plus_x_minus_y).drawtype == NDT_RAILLIKE
1447
- && ((ItemGroupList) nodedef->get (n_plus_x_minus_y).groups )[groupname] != self_group)
1448
- || n_plus_x_minus_y.getContent () == thiscontent)
1449
- is_rail_x_minus_y[1 ] = true ;
1450
-
1451
- if ((nodedef->get (n_plus_x_plus_y).drawtype == NDT_RAILLIKE
1452
- && ((ItemGroupList) nodedef->get (n_plus_x_plus_y).groups )[groupname] != self_group)
1453
- || n_plus_x_plus_y.getContent () == thiscontent)
1454
- is_rail_x_plus_y[1 ] = true ;
1455
-
1456
- if ((nodedef->get (n_minus_z).drawtype == NDT_RAILLIKE
1457
- && ((ItemGroupList) nodedef->get (n_minus_z).groups )[groupname] != self_group)
1458
- || n_minus_z.getContent () == thiscontent)
1459
- is_rail_z[0 ] = true ;
1460
-
1461
- if ((nodedef->get (n_minus_z_minus_y).drawtype == NDT_RAILLIKE
1462
- && ((ItemGroupList) nodedef->get (n_minus_z_minus_y).groups )[groupname] != self_group)
1463
- || n_minus_z_minus_y.getContent () == thiscontent)
1464
- is_rail_z_minus_y[0 ] = true ;
1465
-
1466
- if ((nodedef->get (n_minus_z_plus_y).drawtype == NDT_RAILLIKE
1467
- && ((ItemGroupList) nodedef->get (n_minus_z_plus_y).groups )[groupname] != self_group)
1468
- || n_minus_z_plus_y.getContent () == thiscontent)
1469
- is_rail_z_plus_y[0 ] = true ;
1470
-
1471
- if ((nodedef->get (n_plus_z).drawtype == NDT_RAILLIKE
1472
- && ((ItemGroupList) nodedef->get (n_plus_z).groups )[groupname] != self_group)
1473
- || n_plus_z.getContent () == thiscontent)
1474
- is_rail_z[1 ] = true ;
1475
-
1476
- if ((nodedef->get (n_plus_z_minus_y).drawtype == NDT_RAILLIKE
1477
- && ((ItemGroupList) nodedef->get (n_plus_z_minus_y).groups )[groupname] != self_group)
1478
- || n_plus_z_minus_y.getContent () == thiscontent)
1479
- is_rail_z_minus_y[1 ] = true ;
1480
-
1481
- if ((nodedef->get (n_plus_z_plus_y).drawtype == NDT_RAILLIKE
1482
- && ((ItemGroupList) nodedef->get (n_plus_z_plus_y).groups )[groupname] != self_group)
1483
- || n_plus_z_plus_y.getContent () == thiscontent)
1484
- is_rail_z_plus_y[1 ] = true ;
1485
-
1486
- bool is_rail_x_all[] = {false , false };
1487
- bool is_rail_z_all[] = {false , false };
1488
- is_rail_x_all[0 ]=is_rail_x[0 ] || is_rail_x_minus_y[0 ] || is_rail_x_plus_y[0 ];
1489
- is_rail_x_all[1 ]=is_rail_x[1 ] || is_rail_x_minus_y[1 ] || is_rail_x_plus_y[1 ];
1490
- is_rail_z_all[0 ]=is_rail_z[0 ] || is_rail_z_minus_y[0 ] || is_rail_z_plus_y[0 ];
1491
- is_rail_z_all[1 ]=is_rail_z[1 ] || is_rail_z_minus_y[1 ] || is_rail_z_plus_y[1 ];
1408
+ u8 index = 0 ;
1409
+ for (s8 y0 = -1 ; y0 <= 1 ; y0 ++) {
1410
+ // Prevent from indexing never used coordinates
1411
+ for (s8 xz = -1 ; xz <= 1 ; xz++) {
1412
+ if (xz == 0 )
1413
+ continue ;
1414
+ MapNode n_xy = data->m_vmanip .getNodeNoEx (blockpos_nodes + v3s16 (x + xz, y + y0 , z));
1415
+ MapNode n_zy = data->m_vmanip .getNodeNoEx (blockpos_nodes + v3s16 (x, y + y0 , z + xz));
1416
+ ContentFeatures def_xy = nodedef->get (n_xy);
1417
+ ContentFeatures def_zy = nodedef->get (n_zy);
1418
+
1419
+ // Check if current node would connect with the rail
1420
+ is_rail_x[index ] = ((def_xy.drawtype == NDT_RAILLIKE
1421
+ && ((ItemGroupList) def_xy.groups )[groupname] == self_group)
1422
+ || n_xy.getContent () == thiscontent);
1423
+
1424
+ is_rail_z[index ] = ((def_zy.drawtype == NDT_RAILLIKE
1425
+ && ((ItemGroupList) def_zy.groups )[groupname] == self_group)
1426
+ || n_zy.getContent () == thiscontent);
1427
+ index ++;
1428
+ }
1429
+ }
1430
+
1431
+ bool is_rail_x_all[2 ]; // [0] = negative x, [1] = positive x coordinate from the current node position
1432
+ bool is_rail_z_all[2 ];
1433
+ is_rail_x_all[0 ] = is_rail_x[0 ] || is_rail_x[2 ] || is_rail_x[4 ];
1434
+ is_rail_x_all[1 ] = is_rail_x[1 ] || is_rail_x[3 ] || is_rail_x[5 ];
1435
+ is_rail_z_all[0 ] = is_rail_z[0 ] || is_rail_z[2 ] || is_rail_z[4 ];
1436
+ is_rail_z_all[1 ] = is_rail_z[1 ] || is_rail_z[3 ] || is_rail_z[5 ];
1492
1437
1493
1438
// reasonable default, flat straight unrotated rail
1494
1439
bool is_straight = true ;
@@ -1497,58 +1442,55 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
1497
1442
u8 tileindex = 0 ;
1498
1443
1499
1444
// check for sloped rail
1500
- if (is_rail_x_plus_y[0 ] || is_rail_x_plus_y[1 ] || is_rail_z_plus_y[0 ] || is_rail_z_plus_y[1 ])
1501
- {
1502
- adjacencies = 5 ; // 5 means sloped
1445
+ if (is_rail_x[4 ] || is_rail_x[5 ] || is_rail_z[4 ] || is_rail_z[5 ]) {
1446
+ adjacencies = 5 ; // 5 means sloped
1503
1447
is_straight = true ; // sloped is always straight
1504
- }
1505
- else
1506
- {
1448
+ } else {
1507
1449
// is really straight, rails on both sides
1508
1450
is_straight = (is_rail_x_all[0 ] && is_rail_x_all[1 ]) || (is_rail_z_all[0 ] && is_rail_z_all[1 ]);
1509
1451
adjacencies = is_rail_x_all[0 ] + is_rail_x_all[1 ] + is_rail_z_all[0 ] + is_rail_z_all[1 ];
1510
1452
}
1511
1453
1512
1454
switch (adjacencies) {
1513
1455
case 1 :
1514
- if (is_rail_x_all[0 ] || is_rail_x_all[1 ])
1456
+ if (is_rail_x_all[0 ] || is_rail_x_all[1 ])
1515
1457
angle = 90 ;
1516
1458
break ;
1517
1459
case 2 :
1518
- if (!is_straight)
1460
+ if (!is_straight)
1519
1461
tileindex = 1 ; // curved
1520
- if (is_rail_x_all[0 ] && is_rail_x_all[1 ])
1462
+ if (is_rail_x_all[0 ] && is_rail_x_all[1 ])
1521
1463
angle = 90 ;
1522
- if (is_rail_z_all[0 ] && is_rail_z_all[1 ]){
1523
- if (is_rail_z_plus_y[ 0 ])
1464
+ if (is_rail_z_all[0 ] && is_rail_z_all[1 ]) {
1465
+ if (is_rail_z[ 4 ])
1524
1466
angle = 180 ;
1525
1467
}
1526
- else if (is_rail_x_all[0 ] && is_rail_z_all[0 ])
1468
+ else if (is_rail_x_all[0 ] && is_rail_z_all[0 ])
1527
1469
angle = 270 ;
1528
- else if (is_rail_x_all[0 ] && is_rail_z_all[1 ])
1470
+ else if (is_rail_x_all[0 ] && is_rail_z_all[1 ])
1529
1471
angle = 180 ;
1530
- else if (is_rail_x_all[1 ] && is_rail_z_all[1 ])
1472
+ else if (is_rail_x_all[1 ] && is_rail_z_all[1 ])
1531
1473
angle = 90 ;
1532
1474
break ;
1533
1475
case 3 :
1534
1476
// here is where the potential to 'switch' a junction is, but not implemented at present
1535
1477
tileindex = 2 ; // t-junction
1536
1478
if (!is_rail_x_all[1 ])
1537
- angle= 180 ;
1479
+ angle = 180 ;
1538
1480
if (!is_rail_z_all[0 ])
1539
- angle= 90 ;
1481
+ angle = 90 ;
1540
1482
if (!is_rail_z_all[1 ])
1541
- angle= 270 ;
1483
+ angle = 270 ;
1542
1484
break ;
1543
1485
case 4 :
1544
1486
tileindex = 3 ; // crossing
1545
1487
break ;
1546
1488
case 5 : // sloped
1547
- if (is_rail_z_plus_y[ 0 ])
1489
+ if (is_rail_z[ 4 ])
1548
1490
angle = 180 ;
1549
- if (is_rail_x_plus_y[ 0 ])
1491
+ if (is_rail_x[ 4 ])
1550
1492
angle = 90 ;
1551
- if (is_rail_x_plus_y[ 1 ])
1493
+ if (is_rail_x[ 5 ])
1552
1494
angle = -90 ;
1553
1495
break ;
1554
1496
default :
@@ -1566,7 +1508,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
1566
1508
float s = BS/2 ;
1567
1509
1568
1510
short g = -1 ;
1569
- if (is_rail_x_plus_y[ 0 ] || is_rail_x_plus_y[ 1 ] || is_rail_z_plus_y[ 0 ] || is_rail_z_plus_y[ 1 ])
1511
+ if (is_rail_x[ 4 ] || is_rail_x[ 5 ] || is_rail_z[ 4 ] || is_rail_z[ 5 ])
1570
1512
g = 1 ; // Object is at a slope
1571
1513
1572
1514
video::S3DVertex vertices[4 ] =
0 commit comments