Luanti 5.11.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
74
76};
77
79{
80 v3s16 p = v3s16(-1338, -1338, -1338);
81 MapBlockMesh *mesh = nullptr;
83 std::vector<v3s16> ack_list;
84 bool urgent = false;
85 std::vector<MapBlock *> map_blocks;
86
87 MeshUpdateResult() = default;
88};
89
91
93{
94public:
95 MeshUpdateWorkerThread(Client *client, MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3s16 *camera_offset);
96
97protected:
98 virtual void doUpdate();
99
100private:
105
106 // TODO: Add callback to update these when g_settings changes
108};
109
111{
112public:
114
115 // Caches the block at p and its neighbors (if needed) and queues a mesh
116 // update for the block at p
117 void updateBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent,
118 bool update_neighbors = false);
119 void putResult(const MeshUpdateResult &r);
121
122
124
125 void start();
126 void stop();
127 void wait();
128
129 bool isRunning();
130
131private:
132 void deferUpdate();
133
134
138
139 std::vector<std::unique_ptr<MeshUpdateWorkerThread>> m_workers;
140};
Definition client.h:105
Definition mapblock_mesh.h:164
Definition map.h:101
Definition mesh_generator_thread.h:111
MeshUpdateManager(Client *client)
Definition mesh_generator_thread.cpp:239
void deferUpdate()
Definition mesh_generator_thread.cpp:302
void putResult(const MeshUpdateResult &r)
Definition mesh_generator_thread.cpp:279
v3s16 m_camera_offset
Definition mesh_generator_thread.h:123
bool isRunning()
Definition mesh_generator_thread.cpp:326
MeshUpdateQueue m_queue_in
Definition mesh_generator_thread.h:135
void stop()
Definition mesh_generator_thread.cpp:314
bool getNextResult(MeshUpdateResult &r)
Definition mesh_generator_thread.cpp:287
void updateBlock(Map *map, v3s16 p, bool ack_block_to_server, bool urgent, bool update_neighbors=false)
Definition mesh_generator_thread.cpp:256
MutexedQueue< MeshUpdateResult > m_queue_out_urgent
Definition mesh_generator_thread.h:137
void start()
Definition mesh_generator_thread.cpp:308
std::vector< std::unique_ptr< MeshUpdateWorkerThread > > m_workers
Definition mesh_generator_thread.h:139
MutexedQueue< MeshUpdateResult > m_queue_out
Definition mesh_generator_thread.h:136
void wait()
Definition mesh_generator_thread.cpp:320
Definition mesh_generator_thread.h:36
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:57
~MeshUpdateQueue()
Definition mesh_generator_thread.cpp:45
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:169
MeshUpdateQueue(Client *client)
Definition mesh_generator_thread.cpp:39
void fillDataFromMapBlocks(QueuedMeshUpdate *q)
Definition mesh_generator_thread.cpp:176
bool m_cache_smooth_lighting
Definition mesh_generator_thread.h:73
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:140
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:93
MeshUpdateManager * m_manager
Definition mesh_generator_thread.h:103
v3s16 * m_camera_offset
Definition mesh_generator_thread.h:104
MeshUpdateQueue * m_queue_in
Definition mesh_generator_thread.h:102
Client * m_client
Definition mesh_generator_thread.h:101
MeshUpdateWorkerThread(Client *client, MeshUpdateQueue *queue_in, MeshUpdateManager *manager, v3s16 *camera_offset)
Definition mesh_generator_thread.cpp:201
int m_generation_interval
Definition mesh_generator_thread.h:107
virtual void doUpdate()
Definition mesh_generator_thread.cpp:208
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:79
bool urgent
Definition mesh_generator_thread.h:84
u8 solid_sides
Definition mesh_generator_thread.h:82
MeshUpdateResult()=default
v3s16 p
Definition mesh_generator_thread.h:80
std::vector< v3s16 > ack_list
Definition mesh_generator_thread.h:83
std::vector< MapBlock * > map_blocks
Definition mesh_generator_thread.h:85
MapBlockMesh * mesh
Definition mesh_generator_thread.h:81
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