Skip to content

Commit

Permalink
MeshMakeData: Explain members, and add grid size and minimap flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Desour committed Jan 8, 2025
1 parent 8f89209 commit c651422
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 35 deletions.
8 changes: 4 additions & 4 deletions src/client/content_mapblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const std::string MapblockMeshGenerator::raillike_groupname = "connect_to_railli
MapblockMeshGenerator::MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output):
data(input),
collector(output),
nodedef(data->nodedef),
nodedef(data->m_nodedef),
blockpos_nodes(data->m_blockpos * MAP_BLOCKSIZE)
{
}
Expand Down Expand Up @@ -1773,9 +1773,9 @@ void MapblockMeshGenerator::generate()
{
ZoneScoped;

for (cur_node.p.Z = 0; cur_node.p.Z < data->side_length; cur_node.p.Z++)
for (cur_node.p.Y = 0; cur_node.p.Y < data->side_length; cur_node.p.Y++)
for (cur_node.p.X = 0; cur_node.p.X < data->side_length; cur_node.p.X++) {
for (cur_node.p.Z = 0; cur_node.p.Z < data->m_side_length; cur_node.p.Z++)
for (cur_node.p.Y = 0; cur_node.p.Y < data->m_side_length; cur_node.p.Y++)
for (cur_node.p.X = 0; cur_node.p.X < data->m_side_length; cur_node.p.X++) {
cur_node.n = data->m_vmanip.getNodeNoEx(blockpos_nodes + cur_node.p);
cur_node.f = &nodedef->get(cur_node.n);
drawNode();
Expand Down
50 changes: 25 additions & 25 deletions src/client/mapblock_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
MeshMakeData
*/

MeshMakeData::MeshMakeData(const NodeDefManager *ndef, u16 side_length):
side_length(side_length),
nodedef(ndef)
MeshMakeData::MeshMakeData(const NodeDefManager *ndef,
u16 side_length, MeshGrid mesh_grid) :
m_side_length(side_length),
m_mesh_grid(mesh_grid),
m_nodedef(ndef)
{}

void MeshMakeData::fillBlockDataBegin(const v3s16 &blockpos)
Expand All @@ -38,8 +40,9 @@ void MeshMakeData::fillBlockDataBegin(const v3s16 &blockpos)
v3s16 blockpos_nodes = m_blockpos*MAP_BLOCKSIZE;

m_vmanip.clear();
// extra 1 block thick layer around the mesh
VoxelArea voxel_area(blockpos_nodes - v3s16(1,1,1) * MAP_BLOCKSIZE,
blockpos_nodes + v3s16(1,1,1) * (side_length + MAP_BLOCKSIZE /* extra layer of blocks around the mesh */) - v3s16(1,1,1));
blockpos_nodes + v3s16(1,1,1) * (m_side_length + MAP_BLOCKSIZE) - v3s16(1,1,1));
m_vmanip.addArea(voxel_area);
}

Expand Down Expand Up @@ -128,7 +131,7 @@ u16 getFaceLight(MapNode n, MapNode n2, const NodeDefManager *ndef)
static u16 getSmoothLightCombined(const v3s16 &p,
const std::array<v3s16,8> &dirs, MeshMakeData *data)
{
const NodeDefManager *ndef = data->nodedef;
const NodeDefManager *ndef = data->m_nodedef;

u16 ambient_occlusion = 0;
u16 light_count = 0;
Expand Down Expand Up @@ -316,7 +319,7 @@ void final_color_blend(video::SColor *result,
*/
void getNodeTileN(MapNode mn, const v3s16 &p, u8 tileindex, MeshMakeData *data, TileSpec &tile)
{
const NodeDefManager *ndef = data->nodedef;
const NodeDefManager *ndef = data->m_nodedef;
const ContentFeatures &f = ndef->get(mn);
tile = f.tiles[tileindex];
bool has_crack = p == data->m_crack_pos_relative;
Expand All @@ -336,7 +339,7 @@ void getNodeTileN(MapNode mn, const v3s16 &p, u8 tileindex, MeshMakeData *data,
*/
void getNodeTile(MapNode mn, const v3s16 &p, const v3s16 &dir, MeshMakeData *data, TileSpec &tile)
{
const NodeDefManager *ndef = data->nodedef;
const NodeDefManager *ndef = data->m_nodedef;

// Direction must be (1,0,0), (-1,0,0), (0,1,0), (0,-1,0),
// (0,0,1), (0,0,-1) or (0,0,0)
Expand Down Expand Up @@ -588,7 +591,7 @@ void PartialMeshBuffer::draw(video::IVideoDriver *driver) const
MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offset):
m_tsrc(client->getTextureSource()),
m_shdrsrc(client->getShaderSource()),
m_bounding_sphere_center((data->side_length * 0.5f - 0.5f) * BS),
m_bounding_sphere_center((data->m_side_length * 0.5f - 0.5f) * BS),
m_animation_force_timer(0), // force initial animation
m_last_crack(-1)
{
Expand All @@ -597,10 +600,12 @@ MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offs
for (auto &m : m_mesh)
m = make_irr<scene::SMesh>();

auto mesh_grid = client->getMeshGrid();
auto mesh_grid = data->m_mesh_grid;
v3s16 bp = data->m_blockpos;
// Only generate minimap mapblocks at even coordinates.
if (mesh_grid.isMeshPos(bp) && client->getMinimap()) {
// Only generate minimap mapblocks at grid aligned coordinates.
// FIXME: ^ doesn't really make sense. and in practice, bp is always aligned
if (mesh_grid.isMeshPos(bp) && data->m_generate_minimap) {
// meshgen area always fits into a grid cell
m_minimap_mapblocks.resize(mesh_grid.getCellVolume(), nullptr);
v3s16 ofs;

Expand All @@ -617,15 +622,10 @@ MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offs
}
}

// algin vertices to mesh grid, not meshgen area
v3f offset = intToFloat((data->m_blockpos - mesh_grid.getMeshPos(data->m_blockpos)) * MAP_BLOCKSIZE, BS);

MeshCollector collector(m_bounding_sphere_center, offset);
/*
Add special graphics:
- torches
- flowing water
- fences
- whatever
*/

{
MapblockMeshGenerator(data, &collector).generate();
Expand Down Expand Up @@ -743,7 +743,7 @@ MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offs
}
}

m_bsp_tree.buildTree(&m_transparent_triangles, data->side_length);
m_bsp_tree.buildTree(&m_transparent_triangles, data->m_side_length);

// Check if animation is required for this mesh
m_has_animation =
Expand Down Expand Up @@ -954,19 +954,19 @@ u8 get_solid_sides(MeshMakeData *data)
{
std::unordered_map<v3s16, u8> results;
v3s16 blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE;
const NodeDefManager *ndef = data->nodedef;
const NodeDefManager *ndef = data->m_nodedef;

u8 result = 0x3F; // all sides solid;

for (s16 i = 0; i < data->side_length && result != 0; i++)
for (s16 j = 0; j < data->side_length && result != 0; j++) {
for (s16 i = 0; i < data->m_side_length && result != 0; i++)
for (s16 j = 0; j < data->m_side_length && result != 0; j++) {
v3s16 positions[6] = {
v3s16(0, i, j),
v3s16(data->side_length - 1, i, j),
v3s16(data->m_side_length - 1, i, j),
v3s16(i, 0, j),
v3s16(i, data->side_length - 1, j),
v3s16(i, data->m_side_length - 1, j),
v3s16(i, j, 0),
v3s16(i, j, data->side_length - 1)
v3s16(i, j, data->m_side_length - 1)
};

for (u8 k = 0; k < 6; k++) {
Expand Down
16 changes: 13 additions & 3 deletions src/client/mapblock_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,25 @@ struct MinimapMapblock;
struct MeshMakeData
{
VoxelManipulator m_vmanip;

// base pos of meshgen area, in blocks
v3s16 m_blockpos = v3s16(-1337,-1337,-1337);
// size of meshgen area, in nodes.
// vmanip will have at least an extra 1 node onion layer.
// area is expected to fit into mesh grid cell.
u16 m_side_length;
// vertex positions will be relative to this grid
MeshGrid m_mesh_grid;

// relative to blockpos
v3s16 m_crack_pos_relative = v3s16(-1337,-1337,-1337);
bool m_generate_minimap = false;
bool m_smooth_lighting = false;
bool m_enable_water_reflections = false;
u16 side_length;

const NodeDefManager *nodedef;
const NodeDefManager *m_nodedef;

MeshMakeData(const NodeDefManager *ndef, u16 side_length);
MeshMakeData(const NodeDefManager *ndef, u16 side_lingth, MeshGrid mesh_grid);

/*
Copy block data manually (to allow optimizations by the caller)
Expand Down
4 changes: 3 additions & 1 deletion src/client/mesh_generator_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ void MeshUpdateQueue::done(v3s16 pos)
void MeshUpdateQueue::fillDataFromMapBlocks(QueuedMeshUpdate *q)
{
auto mesh_grid = m_client->getMeshGrid();
MeshMakeData *data = new MeshMakeData(m_client->ndef(), MAP_BLOCKSIZE * mesh_grid.cell_size);
MeshMakeData *data = new MeshMakeData(m_client->ndef(),
MAP_BLOCKSIZE * mesh_grid.cell_size, mesh_grid);
q->data = data;

data->fillBlockDataBegin(q->p);
Expand All @@ -192,6 +193,7 @@ void MeshUpdateQueue::fillDataFromMapBlocks(QueuedMeshUpdate *q)
}

data->setCrack(q->crack_level, q->crack_pos);
data->m_generate_minimap = !!m_client->getMinimap();
data->m_smooth_lighting = m_cache_smooth_lighting;
data->m_enable_water_reflections = m_cache_enable_water_reflections;
}
Expand Down
3 changes: 2 additions & 1 deletion src/client/wieldmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,9 @@ void WieldMeshSceneNode::setExtruded(const std::string &imagename,
static scene::SMesh *createSpecialNodeMesh(Client *client, MapNode n,
std::vector<ItemPartColor> *colors, const ContentFeatures &f)
{
MeshMakeData mesh_make_data(client->ndef(), 1);
MeshMakeData mesh_make_data(client->ndef(), 1, client->getMeshGrid());
MeshCollector collector(v3f(0.0f * BS), v3f());
mesh_make_data.m_generate_minimap = false;
mesh_make_data.m_smooth_lighting = false;
mesh_make_data.m_enable_water_reflections = false;
MapblockMeshGenerator gen(&mesh_make_data, &collector);
Expand Down
3 changes: 2 additions & 1 deletion src/unittest/test_content_mapblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class MockGameDef : public DummyGameDef {

MeshMakeData makeSingleNodeMMD(bool smooth_lighting = true)
{
MeshMakeData data{ndef(), 1};
MeshMakeData data{ndef(), 1, MeshGrid{1}};
data.m_generate_minimap = false;
data.m_smooth_lighting = smooth_lighting;
data.m_enable_water_reflections = false;
data.m_blockpos = {0, 0, 0};
Expand Down

0 comments on commit c651422

Please sign in to comment.