1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

MeshUpdateQueue: Add a MapBlock cache that minimizes the amount of MapBlock copying done in the main thread

Cache size is configurable by the meshgen_block_cache_size (default 20 MB).

New profiler stats:
- MeshUpdateQueue MapBlock cache hit %
- MeshUpdateQueue MapBlock cache size kB

Removes one type of stutter that was seen on the client when received MapBlocks
were being handled. (the "MeshMakeData::fill" stutter)

Kind of related to at least #5239

Originally preceded by these commits, now includes them:
- Move the mesh generator thread into src/mesh_generator_thread.{cpp,h}
- mesh_generator_thread.cpp: Update code style
- MeshUpdateThread: Modify interface to house a different implementation: Actual functionality will be changed by next commits.
- MeshMakeData: Add fillBlockData() interface (so that caller can fill in stuff from eg. a MapBlock cache)
This commit is contained in:
Perttu Ahola 2017-04-15 10:55:52 +03:00 committed by celeron55
parent 4323ad163f
commit 04cc9de8f2
12 changed files with 526 additions and 278 deletions

View file

@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "particles.h"
#include "mapnode.h"
#include "tileanimation.h"
#include "mesh_generator_thread.h"
struct MeshMakeData;
class MapBlockMesh;
@ -54,88 +55,12 @@ struct MinimapMapblock;
class Camera;
class NetworkPacket;
struct QueuedMeshUpdate
{
v3s16 p;
MeshMakeData *data;
bool ack_block_to_server;
QueuedMeshUpdate();
~QueuedMeshUpdate();
};
enum LocalClientState {
LC_Created,
LC_Init,
LC_Ready
};
/*
A thread-safe queue of mesh update tasks
*/
class MeshUpdateQueue
{
public:
MeshUpdateQueue();
~MeshUpdateQueue();
/*
peer_id=0 adds with nobody to send to
*/
void addBlock(v3s16 p, MeshMakeData *data,
bool ack_block_to_server, bool urgent);
// Returned pointer must be deleted
// Returns NULL if queue is empty
QueuedMeshUpdate * pop();
u32 size()
{
MutexAutoLock lock(m_mutex);
return m_queue.size();
}
private:
std::vector<QueuedMeshUpdate*> m_queue;
std::set<v3s16> m_urgents;
Mutex m_mutex;
};
struct MeshUpdateResult
{
v3s16 p;
MapBlockMesh *mesh;
bool ack_block_to_server;
MeshUpdateResult():
p(-1338,-1338,-1338),
mesh(NULL),
ack_block_to_server(false)
{
}
};
class MeshUpdateThread : public UpdateThread
{
private:
MeshUpdateQueue m_queue_in;
int m_generation_interval;
protected:
virtual void doUpdate();
public:
MeshUpdateThread();
void enqueueUpdate(v3s16 p, MeshMakeData *data,
bool ack_block_to_server, bool urgent);
MutexedQueue<MeshUpdateResult> m_queue_out;
v3s16 m_camera_offset;
};
enum ClientEventType
{
CE_NONE,
@ -471,6 +396,7 @@ public:
float getAnimationTime();
int getCrackLevel();
v3s16 getCrackPos();
void setCrack(int level, v3s16 pos);
u16 getHP();
@ -726,11 +652,6 @@ private:
IntervalLimiter m_localdb_save_interval;
u16 m_cache_save_interval;
// TODO: Add callback to update these when g_settings changes
bool m_cache_smooth_lighting;
bool m_cache_enable_shaders;
bool m_cache_use_tangent_vertices;
ClientScripting *m_script;
bool m_modding_enabled;
UNORDERED_MAP<std::string, ModMetadata *> m_mod_storages;