Skip to content

Commit

Permalink
In getNodeTile, use a descriptive struct for the lookup table
Browse files Browse the repository at this point in the history
  • Loading branch information
numberZero authored and sfan5 committed Jun 22, 2023
1 parent d676520 commit 729671d
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/client/mapblock_mesh.cpp
Expand Up @@ -395,13 +395,14 @@ void getNodeTile(MapNode mn, const v3s16 &p, const v3s16 &dir, MeshMakeData *dat
// 5 = (0,0,-1)
// 6 = (0,-1,0)
// 7 = (-1,0,0)
u8 dir_i = ((dir.X + 2 * dir.Y + 3 * dir.Z) & 7) * 2;
u8 dir_i = (dir.X + 2 * dir.Y + 3 * dir.Z) & 7;

// Get rotation for things like chests
u8 facedir = mn.getFaceDir(ndef, true);

static const u16 dir_to_tile[24 * 16] =
{
static const struct {
u8 tile, rotation;
} dir_to_tile[24][8] = {
// 0 +X +Y +Z -Z -Y -X -> value=tile,rotation
0,0, 2,0 , 0,0 , 4,0 , 0,0, 5,0 , 1,0 , 3,0 , // rotate around y+ 0 - 3
0,0, 4,0 , 0,3 , 3,0 , 0,0, 2,0 , 1,1 , 5,0 ,
Expand Down Expand Up @@ -432,11 +433,9 @@ void getNodeTile(MapNode mn, const v3s16 &p, const v3s16 &dir, MeshMakeData *dat
0,0, 5,2 , 1,3 , 3,2 , 0,0, 2,2 , 0,1 , 4,2 ,
0,0, 2,2 , 1,0 , 5,2 , 0,0, 4,2 , 0,0 , 3,2 ,
0,0, 4,2 , 1,1 , 2,2 , 0,0, 3,2 , 0,3 , 5,2

};
u16 tile_index = facedir * 16 + dir_i;
getNodeTileN(mn, p, dir_to_tile[tile_index], data, tile);
tile.rotation = tile.world_aligned ? 0 : dir_to_tile[tile_index + 1];
getNodeTileN(mn, p, dir_to_tile[facedir][dir_i].tile, data, tile);
tile.rotation = tile.world_aligned ? 0 : dir_to_tile[facedir][dir_i].rotation;
}

static void applyTileColor(PreMeshBuffer &pmb)
Expand Down

0 comments on commit 729671d

Please sign in to comment.