Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
mesh_generator_thread.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013, 2017 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include <ctime>
8#include <mutex>
9#include <unordered_map>
10#include <unordered_set>
11#include "mapblock_mesh.h"
13#include "util/thread.h"
14#include <vector>
15#include <memory>
16#include <unordered_map>
17
19{
20 v3s16 p = v3s16(-1337, -1337, -1337);
21 std::vector<v3s16> ack_list;
22 int crack_level = -1;
24 MeshMakeData *data = nullptr; // This is generated in MeshUpdateQueue::pop()
25 std::vector<MapBlock *> map_blocks;
26 bool urgent = false;
27
28 QueuedMeshUpdate() = default;
30};
31
32/*
33 A thread-safe queue of mesh update tasks and a cache of MapBlock data
34*/
36{
42
43public:
45
47
48 // Caches the block at p and its neighbors (if needed) and queues a mesh
49 // update for the block at p
50 bool addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent);
51
52 // Returned pointer must be deleted
53 // Returns NULL if queue is empty
55
56 // Marks a position as finished, unblocking the next update
57 void done(v3s16 pos);
58
59 u32 size()
60 {
62 return m_queue.size();
63 }
64
65private:
67 std::vector<QueuedMeshUpdate *> m_queue;
68 std::unordered_set<v3s16> m_urgents;
69 std::unordered_set<v3s16> m_inflight_blocks;
70 std::mutex m_mutex;
71
72 // TODO: Add callback to update these when g_settings changes
75
78};
79
81{
82 v3s16 p = v3s16(-1338, -1338, -1338);
83 MapBlockMesh *mesh = nullptr;
85 std::vector<v3s16> ack_list;
86 bool urgent = false;
87 std::vector<MapBlock *> map_blocks;
88
89 MeshUpdateResult() = default;
90};
91
93
95{
96public:
97 MeshUpdateWorkerThread(Client *client, MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3s16 *camera_offset);
98
99protected:
100 virtual void doUpdate();
101
102private:
107
108 // TODO: Add callback to update these when g_settings changes
110};
111
113{
114public:
116
117 // Caches the block at p and its neighbors (if needed) and queues a mesh
118 // update for the block at p
119 void updateBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent,
120 bool update_neighbors = false);
121 void putResult(const MeshUpdateResult &r);
123
124
126
127 void start();
128 void stop();
129 void wait();
130
131 bool isRunning();
132
133private:
134 void deferUpdate();
135
136
140
141 std::vector<std::unique_ptr<MeshUpdateWorkerThread>> m_workers;
142};
Definition client.h:105
Definition mapblock_mesh.h:165
Definition map.h:101
Definition mesh_generator_thread.h:113
MeshUpdateManager(Client *client)
Definition mesh_generator_thread.cpp:240
void deferUpdate()
Definition mesh_generator_thread.cpp:303
void putResult(const MeshUpdateResult &r)
Definition mesh_generator_thread.cpp:280
v3s16 m_camera_offset
Definition mesh_generator_thread.h:125
bool isRunning()
Definition mesh_generator_thread.cpp:327
MeshUpdateQueue m_queue_in
Definition mesh_generator_thread.h:137
void stop()
Definition mesh_generator_thread.cpp:315
bool getNextResult(MeshUpdateResult &r)
Definition mesh_generator_thread.cpp:288
void updateBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent, bool update_neighbors=false)
Definition mesh_generator_thread.cpp:257
MutexedQueue< MeshUpdateResult > m_queue_out_urgent
Definition mesh_generator_thread.h:139
void start()
Definition mesh_generator_thread.cpp:309
std::vector< std::unique_ptr< MeshUpdateWorkerThread > > m_workers
Definition mesh_generator_thread.h:141
MutexedQueue< MeshUpdateResult > m_queue_out
Definition mesh_generator_thread.h:138
void wait()
Definition mesh_generator_thread.cpp:321
Definition mesh_generator_thread.h:36
bool m_cache_enable_shaders
Definition mesh_generator_thread.h:73
std::unordered_set< v3s16 > m_urgents
Definition mesh_generator_thread.h:68
bool addBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent)
Definition mesh_generator_thread.cpp:58
~MeshUpdateQueue()
Definition mesh_generator_thread.cpp:46
std::mutex m_mutex
Definition mesh_generator_thread.h:70
std::vector< QueuedMeshUpdate * > m_queue
Definition mesh_generator_thread.h:67
u32 size()
Definition mesh_generator_thread.h:59
void done(v3s16 pos)
Definition mesh_generator_thread.cpp:170
MeshUpdateQueue(Client *client)
Definition mesh_generator_thread.cpp:39
void fillDataFromMapBlocks(QueuedMeshUpdate *q)
Definition mesh_generator_thread.cpp:177
bool m_cache_smooth_lighting
Definition mesh_generator_thread.h:74
UpdateMode
Definition mesh_generator_thread.h:38
@ SKIP_UPDATE_IF_ALREADY_CACHED
Definition mesh_generator_thread.h:40
@ FORCE_UPDATE
Definition mesh_generator_thread.h:39
QueuedMeshUpdate * pop()
Definition mesh_generator_thread.cpp:141
std::unordered_set< v3s16 > m_inflight_blocks
Definition mesh_generator_thread.h:69
Client * m_client
Definition mesh_generator_thread.h:66
Definition mesh_generator_thread.h:95
MeshUpdateManager * m_manager
Definition mesh_generator_thread.h:105
v3s16 * m_camera_offset
Definition mesh_generator_thread.h:106
MeshUpdateQueue * m_queue_in
Definition mesh_generator_thread.h:104
Client * m_client
Definition mesh_generator_thread.h:103
MeshUpdateWorkerThread(Client *client, MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3s16 *camera_offset)
Definition mesh_generator_thread.cpp:202
int m_generation_interval
Definition mesh_generator_thread.h:109
virtual void doUpdate()
Definition mesh_generator_thread.cpp:209
Definition container.h:117
Definition thread.h:174
core::vector3d< s16 > v3s16
Definition irr_v3d.h:13
std::lock_guard< std::mutex > MutexAutoLock
Definition mutex_auto_lock.h:31
Definition activeobjectmgr.cpp:11
Definition mapblock_mesh.h:30
Definition mesh_generator_thread.h:81
bool urgent
Definition mesh_generator_thread.h:86
u8 solid_sides
Definition mesh_generator_thread.h:84
MeshUpdateResult()=default
v3s16 p
Definition mesh_generator_thread.h:82
std::vector< v3s16 > ack_list
Definition mesh_generator_thread.h:85
std::vector< MapBlock * > map_blocks
Definition mesh_generator_thread.h:87
MapBlockMesh * mesh
Definition mesh_generator_thread.h:83
Definition mesh_generator_thread.h:19
QueuedMeshUpdate()=default
~QueuedMeshUpdate()
Definition mesh_generator_thread.cpp:30
int crack_level
Definition mesh_generator_thread.h:22
v3s16 p
Definition mesh_generator_thread.h:20
MeshMakeData * data
Definition mesh_generator_thread.h:24
std::vector< v3s16 > ack_list
Definition mesh_generator_thread.h:21
std::vector< MapBlock * > map_blocks
Definition mesh_generator_thread.h:25
bool urgent
Definition mesh_generator_thread.h:26
v3s16 crack_pos
Definition mesh_generator_thread.h:23
static std::string p(std::string path)
Definition test_filesys.cpp:53