forked from Mirrorlandia_minetest/minetest
Decouple MeshMakeData from Client
This commit is contained in:
parent
2f35b121a4
commit
bf2098c07f
@ -77,7 +77,7 @@ MapblockMeshGenerator::MapblockMeshGenerator(MeshMakeData *input, MeshCollector
|
|||||||
scene::IMeshManipulator *mm):
|
scene::IMeshManipulator *mm):
|
||||||
data(input),
|
data(input),
|
||||||
collector(output),
|
collector(output),
|
||||||
nodedef(data->m_client->ndef()),
|
nodedef(data->nodedef),
|
||||||
meshmanip(mm),
|
meshmanip(mm),
|
||||||
blockpos_nodes(data->m_blockpos * MAP_BLOCKSIZE),
|
blockpos_nodes(data->m_blockpos * MAP_BLOCKSIZE),
|
||||||
enable_mesh_cache(g_settings->getBool("enable_mesh_cache") &&
|
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::MeshMakeData(Client *client, bool use_shaders):
|
MeshMakeData::MeshMakeData(const NodeDefManager *ndef, u16 side_length, bool use_shaders):
|
||||||
m_mesh_grid(client->getMeshGrid()),
|
side_length(side_length),
|
||||||
side_length(MAP_BLOCKSIZE * m_mesh_grid.cell_size),
|
nodedef(ndef),
|
||||||
m_client(client),
|
|
||||||
m_use_shaders(use_shaders)
|
m_use_shaders(use_shaders)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -147,7 +146,7 @@ u16 getFaceLight(MapNode n, MapNode n2, const NodeDefManager *ndef)
|
|||||||
static u16 getSmoothLightCombined(const v3s16 &p,
|
static u16 getSmoothLightCombined(const v3s16 &p,
|
||||||
const std::array<v3s16,8> &dirs, MeshMakeData *data)
|
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 ambient_occlusion = 0;
|
||||||
u16 light_count = 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)
|
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);
|
const ContentFeatures &f = ndef->get(mn);
|
||||||
tile = f.tiles[tileindex];
|
tile = f.tiles[tileindex];
|
||||||
bool has_crack = p == data->m_crack_pos_relative;
|
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)
|
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),
|
// 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)
|
// (0,0,1), (0,0,-1) or (0,0,0)
|
||||||
@ -635,9 +634,9 @@ void PartialMeshBuffer::afterDraw() const
|
|||||||
MapBlockMesh
|
MapBlockMesh
|
||||||
*/
|
*/
|
||||||
|
|
||||||
MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
|
MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offset):
|
||||||
m_tsrc(data->m_client->getTextureSource()),
|
m_tsrc(client->getTextureSource()),
|
||||||
m_shdrsrc(data->m_client->getShaderSource()),
|
m_shdrsrc(client->getShaderSource()),
|
||||||
m_bounding_sphere_center((data->side_length * 0.5f - 0.5f) * BS),
|
m_bounding_sphere_center((data->side_length * 0.5f - 0.5f) * BS),
|
||||||
m_animation_force_timer(0), // force initial animation
|
m_animation_force_timer(0), // force initial animation
|
||||||
m_last_crack(-1),
|
m_last_crack(-1),
|
||||||
@ -648,26 +647,27 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
|
|||||||
m_enable_shaders = data->m_use_shaders;
|
m_enable_shaders = data->m_use_shaders;
|
||||||
m_enable_vbo = g_settings->getBool("enable_vbo");
|
m_enable_vbo = g_settings->getBool("enable_vbo");
|
||||||
|
|
||||||
|
auto mesh_grid = client->getMeshGrid();
|
||||||
v3s16 bp = data->m_blockpos;
|
v3s16 bp = data->m_blockpos;
|
||||||
// Only generate minimap mapblocks at even coordinates.
|
// Only generate minimap mapblocks at even coordinates.
|
||||||
if (data->m_mesh_grid.isMeshPos(bp) && data->m_client->getMinimap()) {
|
if (mesh_grid.isMeshPos(bp) && client->getMinimap()) {
|
||||||
m_minimap_mapblocks.resize(data->m_mesh_grid.getCellVolume(), nullptr);
|
m_minimap_mapblocks.resize(mesh_grid.getCellVolume(), nullptr);
|
||||||
v3s16 ofs;
|
v3s16 ofs;
|
||||||
|
|
||||||
// See also client.cpp for the code that reads the array of minimap blocks.
|
// 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.Z = 0; ofs.Z < mesh_grid.cell_size; ofs.Z++)
|
||||||
for (ofs.Y = 0; ofs.Y < data->m_mesh_grid.cell_size; ofs.Y++)
|
for (ofs.Y = 0; ofs.Y < mesh_grid.cell_size; ofs.Y++)
|
||||||
for (ofs.X = 0; ofs.X < data->m_mesh_grid.cell_size; ofs.X++) {
|
for (ofs.X = 0; ofs.X < mesh_grid.cell_size; ofs.X++) {
|
||||||
v3s16 p = (bp + ofs) * MAP_BLOCKSIZE;
|
v3s16 p = (bp + ofs) * MAP_BLOCKSIZE;
|
||||||
if (data->m_vmanip.getNodeNoEx(p).getContent() != CONTENT_IGNORE) {
|
if (data->m_vmanip.getNodeNoEx(p).getContent() != CONTENT_IGNORE) {
|
||||||
MinimapMapblock *block = new MinimapMapblock;
|
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);
|
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);
|
MeshCollector collector(m_bounding_sphere_center, offset);
|
||||||
/*
|
/*
|
||||||
Add special graphics:
|
Add special graphics:
|
||||||
@ -679,7 +679,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
|
|||||||
|
|
||||||
{
|
{
|
||||||
MapblockMeshGenerator(data, &collector,
|
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;
|
std::unordered_map<v3s16, u8> results;
|
||||||
v3s16 ofs;
|
v3s16 ofs;
|
||||||
v3s16 blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE;
|
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;
|
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>
|
#include <unordered_map>
|
||||||
|
|
||||||
class Client;
|
class Client;
|
||||||
|
class NodeDefManager;
|
||||||
class IShaderSource;
|
class IShaderSource;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -43,13 +44,12 @@ struct MeshMakeData
|
|||||||
v3s16 m_blockpos = v3s16(-1337,-1337,-1337);
|
v3s16 m_blockpos = v3s16(-1337,-1337,-1337);
|
||||||
v3s16 m_crack_pos_relative = v3s16(-1337,-1337,-1337);
|
v3s16 m_crack_pos_relative = v3s16(-1337,-1337,-1337);
|
||||||
bool m_smooth_lighting = false;
|
bool m_smooth_lighting = false;
|
||||||
MeshGrid m_mesh_grid;
|
|
||||||
u16 side_length;
|
u16 side_length;
|
||||||
|
|
||||||
Client *m_client;
|
const NodeDefManager *nodedef;
|
||||||
bool m_use_shaders;
|
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)
|
Copy block data manually (to allow optimizations by the caller)
|
||||||
@ -179,7 +179,7 @@ class MapBlockMesh
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Builds the mesh given
|
// Builds the mesh given
|
||||||
MapBlockMesh(MeshMakeData *data, v3s16 camera_offset);
|
MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offset);
|
||||||
~MapBlockMesh();
|
~MapBlockMesh();
|
||||||
|
|
||||||
// Main animation function, parameters:
|
// Main animation function, parameters:
|
||||||
|
@ -189,16 +189,17 @@ void MeshUpdateQueue::done(v3s16 pos)
|
|||||||
|
|
||||||
void MeshUpdateQueue::fillDataFromMapBlocks(QueuedMeshUpdate *q)
|
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;
|
q->data = data;
|
||||||
|
|
||||||
data->fillBlockDataBegin(q->p);
|
data->fillBlockDataBegin(q->p);
|
||||||
|
|
||||||
v3s16 pos;
|
v3s16 pos;
|
||||||
int i = 0;
|
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.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 + data->m_mesh_grid.cell_size; pos.Z++)
|
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 + data->m_mesh_grid.cell_size; pos.Y++) {
|
for (pos.Y = q->p.Y - 1; pos.Y <= q->p.Y + mesh_grid.cell_size; pos.Y++) {
|
||||||
MapBlock *block = q->map_blocks[i++];
|
MapBlock *block = q->map_blocks[i++];
|
||||||
data->fillBlockData(pos, block ? block->getData() : block_placeholder.data);
|
data->fillBlockData(pos, block ? block->getData() : block_placeholder.data);
|
||||||
}
|
}
|
||||||
@ -211,8 +212,8 @@ void MeshUpdateQueue::fillDataFromMapBlocks(QueuedMeshUpdate *q)
|
|||||||
MeshUpdateWorkerThread
|
MeshUpdateWorkerThread
|
||||||
*/
|
*/
|
||||||
|
|
||||||
MeshUpdateWorkerThread::MeshUpdateWorkerThread(MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3s16 *camera_offset) :
|
MeshUpdateWorkerThread::MeshUpdateWorkerThread(Client *client, MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3s16 *camera_offset) :
|
||||||
UpdateThread("Mesh"), m_queue_in(queue_in), m_manager(manager), m_camera_offset(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 = g_settings->getU16("mesh_generation_interval");
|
||||||
m_generation_interval = rangelim(m_generation_interval, 0, 50);
|
m_generation_interval = rangelim(m_generation_interval, 0, 50);
|
||||||
@ -226,7 +227,7 @@ void MeshUpdateWorkerThread::doUpdate()
|
|||||||
sleep_ms(m_generation_interval);
|
sleep_ms(m_generation_interval);
|
||||||
ScopeProfiler sp(g_profiler, "Client: Mesh making (sum)");
|
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;
|
infostream << "MeshUpdateManager: using " << number_of_threads << " threads" << std::endl;
|
||||||
|
|
||||||
for (int i = 0; i < number_of_threads; i++)
|
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,
|
void MeshUpdateManager::updateBlock(Map *map, v3s16 p, bool ack_block_to_server,
|
||||||
|
@ -109,12 +109,13 @@ class MeshUpdateManager;
|
|||||||
class MeshUpdateWorkerThread : public UpdateThread
|
class MeshUpdateWorkerThread : public UpdateThread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MeshUpdateWorkerThread(MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3s16 *camera_offset);
|
MeshUpdateWorkerThread(Client *client, MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3s16 *camera_offset);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void doUpdate();
|
virtual void doUpdate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Client *m_client;
|
||||||
MeshUpdateQueue *m_queue_in;
|
MeshUpdateQueue *m_queue_in;
|
||||||
MeshUpdateManager *m_manager;
|
MeshUpdateManager *m_manager;
|
||||||
v3s16 *m_camera_offset;
|
v3s16 *m_camera_offset;
|
||||||
|
@ -315,7 +315,7 @@ void WieldMeshSceneNode::setExtruded(const std::string &imagename,
|
|||||||
static scene::SMesh *createSpecialNodeMesh(Client *client, MapNode n,
|
static scene::SMesh *createSpecialNodeMesh(Client *client, MapNode n,
|
||||||
std::vector<ItemPartColor> *colors, const ContentFeatures &f)
|
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());
|
MeshCollector collector(v3f(0.0f * BS), v3f());
|
||||||
mesh_make_data.setSmoothLighting(false);
|
mesh_make_data.setSmoothLighting(false);
|
||||||
MapblockMeshGenerator gen(&mesh_make_data, &collector,
|
MapblockMeshGenerator gen(&mesh_make_data, &collector,
|
||||||
|
Loading…
Reference in New Issue
Block a user