Decouple MeshMakeData from Client

This commit is contained in:
numzero 2023-06-18 18:37:31 +03:00 committed by rubenwardy
parent 2f35b121a4
commit bf2098c07f
6 changed files with 36 additions and 34 deletions

@ -77,7 +77,7 @@ MapblockMeshGenerator::MapblockMeshGenerator(MeshMakeData *input, MeshCollector
scene::IMeshManipulator *mm):
data(input),
collector(output),
nodedef(data->m_client->ndef()),
nodedef(data->nodedef),
meshmanip(mm),
blockpos_nodes(data->m_blockpos * MAP_BLOCKSIZE),
enable_mesh_cache(g_settings->getBool("enable_mesh_cache") &&

@ -38,10 +38,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
MeshMakeData
*/
MeshMakeData::MeshMakeData(Client *client, bool use_shaders):
m_mesh_grid(client->getMeshGrid()),
side_length(MAP_BLOCKSIZE * m_mesh_grid.cell_size),
m_client(client),
MeshMakeData::MeshMakeData(const NodeDefManager *ndef, u16 side_length, bool use_shaders):
side_length(side_length),
nodedef(ndef),
m_use_shaders(use_shaders)
{}
@ -147,7 +146,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->m_client->ndef();
const NodeDefManager *ndef = data->nodedef;
u16 ambient_occlusion = 0;
u16 light_count = 0;
@ -360,7 +359,7 @@ static const v3s16 vertex_dirs_table[] = {
*/
void getNodeTileN(MapNode mn, const v3s16 &p, u8 tileindex, MeshMakeData *data, TileSpec &tile)
{
const NodeDefManager *ndef = data->m_client->ndef();
const NodeDefManager *ndef = data->nodedef;
const ContentFeatures &f = ndef->get(mn);
tile = f.tiles[tileindex];
bool has_crack = p == data->m_crack_pos_relative;
@ -380,7 +379,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->m_client->ndef();
const NodeDefManager *ndef = data->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)
@ -635,9 +634,9 @@ void PartialMeshBuffer::afterDraw() const
MapBlockMesh
*/
MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
m_tsrc(data->m_client->getTextureSource()),
m_shdrsrc(data->m_client->getShaderSource()),
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_animation_force_timer(0), // force initial animation
m_last_crack(-1),
@ -648,26 +647,27 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
m_enable_shaders = data->m_use_shaders;
m_enable_vbo = g_settings->getBool("enable_vbo");
auto mesh_grid = client->getMeshGrid();
v3s16 bp = data->m_blockpos;
// Only generate minimap mapblocks at even coordinates.
if (data->m_mesh_grid.isMeshPos(bp) && data->m_client->getMinimap()) {
m_minimap_mapblocks.resize(data->m_mesh_grid.getCellVolume(), nullptr);
if (mesh_grid.isMeshPos(bp) && client->getMinimap()) {
m_minimap_mapblocks.resize(mesh_grid.getCellVolume(), nullptr);
v3s16 ofs;
// See also client.cpp for the code that reads the array of minimap blocks.
for (ofs.Z = 0; ofs.Z < data->m_mesh_grid.cell_size; ofs.Z++)
for (ofs.Y = 0; ofs.Y < data->m_mesh_grid.cell_size; ofs.Y++)
for (ofs.X = 0; ofs.X < data->m_mesh_grid.cell_size; ofs.X++) {
for (ofs.Z = 0; ofs.Z < mesh_grid.cell_size; ofs.Z++)
for (ofs.Y = 0; ofs.Y < mesh_grid.cell_size; ofs.Y++)
for (ofs.X = 0; ofs.X < mesh_grid.cell_size; ofs.X++) {
v3s16 p = (bp + ofs) * MAP_BLOCKSIZE;
if (data->m_vmanip.getNodeNoEx(p).getContent() != CONTENT_IGNORE) {
MinimapMapblock *block = new MinimapMapblock;
m_minimap_mapblocks[data->m_mesh_grid.getOffsetIndex(ofs)] = block;
m_minimap_mapblocks[mesh_grid.getOffsetIndex(ofs)] = block;
block->getMinimapNodes(&data->m_vmanip, p);
}
}
}
v3f offset = intToFloat((data->m_blockpos - data->m_mesh_grid.getMeshPos(data->m_blockpos)) * MAP_BLOCKSIZE, BS);
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:
@ -679,7 +679,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
{
MapblockMeshGenerator(data, &collector,
data->m_client->getSceneManager()->getMeshManipulator()).generate();
client->getSceneManager()->getMeshManipulator()).generate();
}
/*
@ -1011,7 +1011,7 @@ u8 get_solid_sides(MeshMakeData *data)
std::unordered_map<v3s16, u8> results;
v3s16 ofs;
v3s16 blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE;
const NodeDefManager *ndef = data->m_client->ndef();
const NodeDefManager *ndef = data->nodedef;
u8 result = 0x3F; // all sides solid;

@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <unordered_map>
class Client;
class NodeDefManager;
class IShaderSource;
/*
@ -43,13 +44,12 @@ struct MeshMakeData
v3s16 m_blockpos = v3s16(-1337,-1337,-1337);
v3s16 m_crack_pos_relative = v3s16(-1337,-1337,-1337);
bool m_smooth_lighting = false;
MeshGrid m_mesh_grid;
u16 side_length;
Client *m_client;
const NodeDefManager *nodedef;
bool m_use_shaders;
MeshMakeData(Client *client, bool use_shaders);
MeshMakeData(const NodeDefManager *ndef, u16 side_length, bool use_shaders);
/*
Copy block data manually (to allow optimizations by the caller)
@ -179,7 +179,7 @@ class MapBlockMesh
{
public:
// Builds the mesh given
MapBlockMesh(MeshMakeData *data, v3s16 camera_offset);
MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offset);
~MapBlockMesh();
// Main animation function, parameters:

@ -189,16 +189,17 @@ void MeshUpdateQueue::done(v3s16 pos)
void MeshUpdateQueue::fillDataFromMapBlocks(QueuedMeshUpdate *q)
{
MeshMakeData *data = new MeshMakeData(m_client, m_cache_enable_shaders);
auto mesh_grid = m_client->getMeshGrid();
MeshMakeData *data = new MeshMakeData(m_client->ndef(), MAP_BLOCKSIZE * mesh_grid.cell_size, m_cache_enable_shaders);
q->data = data;
data->fillBlockDataBegin(q->p);
v3s16 pos;
int i = 0;
for (pos.X = q->p.X - 1; pos.X <= q->p.X + data->m_mesh_grid.cell_size; pos.X++)
for (pos.Z = q->p.Z - 1; pos.Z <= q->p.Z + data->m_mesh_grid.cell_size; pos.Z++)
for (pos.Y = q->p.Y - 1; pos.Y <= q->p.Y + data->m_mesh_grid.cell_size; pos.Y++) {
for (pos.X = q->p.X - 1; pos.X <= q->p.X + mesh_grid.cell_size; pos.X++)
for (pos.Z = q->p.Z - 1; pos.Z <= q->p.Z + mesh_grid.cell_size; pos.Z++)
for (pos.Y = q->p.Y - 1; pos.Y <= q->p.Y + mesh_grid.cell_size; pos.Y++) {
MapBlock *block = q->map_blocks[i++];
data->fillBlockData(pos, block ? block->getData() : block_placeholder.data);
}
@ -211,8 +212,8 @@ void MeshUpdateQueue::fillDataFromMapBlocks(QueuedMeshUpdate *q)
MeshUpdateWorkerThread
*/
MeshUpdateWorkerThread::MeshUpdateWorkerThread(MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3s16 *camera_offset) :
UpdateThread("Mesh"), m_queue_in(queue_in), m_manager(manager), m_camera_offset(camera_offset)
MeshUpdateWorkerThread::MeshUpdateWorkerThread(Client *client, MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3s16 *camera_offset) :
UpdateThread("Mesh"), m_client(client), m_queue_in(queue_in), m_manager(manager), m_camera_offset(camera_offset)
{
m_generation_interval = g_settings->getU16("mesh_generation_interval");
m_generation_interval = rangelim(m_generation_interval, 0, 50);
@ -226,7 +227,7 @@ void MeshUpdateWorkerThread::doUpdate()
sleep_ms(m_generation_interval);
ScopeProfiler sp(g_profiler, "Client: Mesh making (sum)");
MapBlockMesh *mesh_new = new MapBlockMesh(q->data, *m_camera_offset);
MapBlockMesh *mesh_new = new MapBlockMesh(m_client, q->data, *m_camera_offset);
@ -262,7 +263,7 @@ MeshUpdateManager::MeshUpdateManager(Client *client):
infostream << "MeshUpdateManager: using " << number_of_threads << " threads" << std::endl;
for (int i = 0; i < number_of_threads; i++)
m_workers.push_back(std::make_unique<MeshUpdateWorkerThread>(&m_queue_in, this, &m_camera_offset));
m_workers.push_back(std::make_unique<MeshUpdateWorkerThread>(client, &m_queue_in, this, &m_camera_offset));
}
void MeshUpdateManager::updateBlock(Map *map, v3s16 p, bool ack_block_to_server,

@ -109,12 +109,13 @@ class MeshUpdateManager;
class MeshUpdateWorkerThread : public UpdateThread
{
public:
MeshUpdateWorkerThread(MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3s16 *camera_offset);
MeshUpdateWorkerThread(Client *client, MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3s16 *camera_offset);
protected:
virtual void doUpdate();
private:
Client *m_client;
MeshUpdateQueue *m_queue_in;
MeshUpdateManager *m_manager;
v3s16 *m_camera_offset;

@ -315,7 +315,7 @@ 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, false);
MeshMakeData mesh_make_data(client->ndef(), 1, false);
MeshCollector collector(v3f(0.0f * BS), v3f());
mesh_make_data.setSmoothLighting(false);
MapblockMeshGenerator gen(&mesh_make_data, &collector,