mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Use multiple threads for mesh generation (#13062)
Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
parent
03e710160f
commit
89e7f72c92
8 changed files with 183 additions and 57 deletions
|
@ -26,6 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "mapblock_mesh.h"
|
||||
#include "threading/mutex_auto_lock.h"
|
||||
#include "util/thread.h"
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
struct CachedMapBlockData
|
||||
{
|
||||
|
@ -75,6 +77,9 @@ public:
|
|||
// Returns NULL if queue is empty
|
||||
QueuedMeshUpdate *pop();
|
||||
|
||||
// Marks a position as finished, unblocking the next update
|
||||
void done(v3s16 pos);
|
||||
|
||||
u32 size()
|
||||
{
|
||||
MutexAutoLock lock(m_mutex);
|
||||
|
@ -86,6 +91,7 @@ private:
|
|||
std::vector<QueuedMeshUpdate *> m_queue;
|
||||
std::unordered_set<v3s16> m_urgents;
|
||||
std::unordered_map<v3s16, CachedMapBlockData *> m_cache;
|
||||
std::unordered_set<v3s16> m_inflight_blocks;
|
||||
u64 m_next_cache_cleanup; // milliseconds
|
||||
std::mutex m_mutex;
|
||||
|
||||
|
@ -111,25 +117,53 @@ struct MeshUpdateResult
|
|||
MeshUpdateResult() = default;
|
||||
};
|
||||
|
||||
class MeshUpdateThread : public UpdateThread
|
||||
class MeshUpdateManager;
|
||||
|
||||
class MeshUpdateWorkerThread : public UpdateThread
|
||||
{
|
||||
public:
|
||||
MeshUpdateThread(Client *client);
|
||||
MeshUpdateWorkerThread(MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3s16 *camera_offset);
|
||||
|
||||
protected:
|
||||
virtual void doUpdate();
|
||||
|
||||
private:
|
||||
MeshUpdateQueue *m_queue_in;
|
||||
MeshUpdateManager *m_manager;
|
||||
v3s16 *m_camera_offset;
|
||||
|
||||
// TODO: Add callback to update these when g_settings changes
|
||||
int m_generation_interval;
|
||||
};
|
||||
|
||||
class MeshUpdateManager
|
||||
{
|
||||
public:
|
||||
MeshUpdateManager(Client *client);
|
||||
|
||||
// Caches the block at p and its neighbors (if needed) and queues a mesh
|
||||
// update for the block at p
|
||||
void updateBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent,
|
||||
bool update_neighbors = false);
|
||||
void putResult(const MeshUpdateResult &r);
|
||||
bool getNextResult(MeshUpdateResult &r);
|
||||
|
||||
|
||||
v3s16 m_camera_offset;
|
||||
MutexedQueue<MeshUpdateResult> m_queue_out;
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
void wait();
|
||||
|
||||
bool isRunning();
|
||||
|
||||
private:
|
||||
void deferUpdate();
|
||||
|
||||
|
||||
MeshUpdateQueue m_queue_in;
|
||||
MutexedQueue<MeshUpdateResult> m_queue_out;
|
||||
MutexedQueue<MeshUpdateResult> m_queue_out_urgent;
|
||||
|
||||
// TODO: Add callback to update these when g_settings changes
|
||||
int m_generation_interval;
|
||||
|
||||
protected:
|
||||
virtual void doUpdate();
|
||||
std::vector<std::unique_ptr<MeshUpdateWorkerThread>> m_workers;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue