@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
20
20
#include " minimap.h"
21
21
#include " logoutputbuffer.h"
22
22
#include " jthread/jmutexautolock.h"
23
+ #include " jthread/jsemaphore.h"
23
24
#include " clientmap.h"
24
25
#include " settings.h"
25
26
#include " nodedef.h"
@@ -47,16 +48,15 @@ MinimapUpdateQueue::~MinimapUpdateQueue()
47
48
{
48
49
JMutexAutoLock lock (m_mutex);
49
50
50
- for (std::vector <QueuedMinimapUpdate*>::iterator
51
+ for (std::list <QueuedMinimapUpdate*>::iterator
51
52
i = m_queue.begin ();
52
- i != m_queue.end (); i++)
53
- {
53
+ i != m_queue.end (); ++i) {
54
54
QueuedMinimapUpdate *q = *i;
55
55
delete q;
56
56
}
57
57
}
58
58
59
- void MinimapUpdateQueue::addBlock (v3s16 pos, MinimapMapblock *data)
59
+ bool MinimapUpdateQueue::addBlock (v3s16 pos, MinimapMapblock *data)
60
60
{
61
61
DSTACK (__FUNCTION_NAME);
62
62
@@ -66,15 +66,14 @@ void MinimapUpdateQueue::addBlock(v3s16 pos, MinimapMapblock *data)
66
66
Find if block is already in queue.
67
67
If it is, update the data and quit.
68
68
*/
69
- for (std::vector <QueuedMinimapUpdate*>::iterator
69
+ for (std::list <QueuedMinimapUpdate*>::iterator
70
70
i = m_queue.begin ();
71
- i != m_queue.end (); i++)
72
- {
71
+ i != m_queue.end (); ++i) {
73
72
QueuedMinimapUpdate *q = *i;
74
73
if (q->pos == pos) {
75
74
delete q->data ;
76
75
q->data = data;
77
- return ;
76
+ return false ;
78
77
}
79
78
}
80
79
@@ -85,16 +84,16 @@ void MinimapUpdateQueue::addBlock(v3s16 pos, MinimapMapblock *data)
85
84
q->pos = pos;
86
85
q->data = data;
87
86
m_queue.push_back (q);
87
+ return true ;
88
88
}
89
89
90
90
QueuedMinimapUpdate * MinimapUpdateQueue::pop ()
91
91
{
92
92
JMutexAutoLock lock (m_mutex);
93
93
94
- for (std::vector <QueuedMinimapUpdate*>::iterator
94
+ for (std::list <QueuedMinimapUpdate*>::iterator
95
95
i = m_queue.begin ();
96
- i != m_queue.end (); i++)
97
- {
96
+ i != m_queue.end (); i++) {
98
97
QueuedMinimapUpdate *q = *i;
99
98
m_queue.erase (i);
100
99
return q;
@@ -106,6 +105,22 @@ QueuedMinimapUpdate * MinimapUpdateQueue::pop()
106
105
Minimap update thread
107
106
*/
108
107
108
+ void MinimapUpdateThread::Stop ()
109
+ {
110
+ JThread::Stop ();
111
+
112
+ // give us a nudge
113
+ m_queue_sem.Post ();
114
+ }
115
+
116
+ void MinimapUpdateThread::enqueue_Block (v3s16 pos, MinimapMapblock *data)
117
+ {
118
+ if (m_queue.addBlock (pos, data))
119
+ // we had to allocate a new block
120
+ m_queue_sem.Post ();
121
+ }
122
+
123
+
109
124
void *MinimapUpdateThread::Thread ()
110
125
{
111
126
ThreadStarted ();
@@ -120,8 +135,13 @@ void *MinimapUpdateThread::Thread()
120
135
121
136
while (!StopRequested ()) {
122
137
138
+ m_queue_sem.Wait ();
139
+ if (StopRequested ()) break ;
140
+
123
141
while (m_queue.size ()) {
124
142
QueuedMinimapUpdate *q = m_queue.pop ();
143
+ if (!q)
144
+ break ;
125
145
std::map<v3s16, MinimapMapblock *>::iterator it;
126
146
it = m_blocks_cache.find (q->pos );
127
147
if (q->data ) {
@@ -138,7 +158,6 @@ void *MinimapUpdateThread::Thread()
138
158
data->map_invalidated = false ;
139
159
}
140
160
}
141
- // sleep_ms(10);
142
161
}
143
162
END_DEBUG_EXCEPTION_HANDLER (errorstream)
144
163
@@ -266,7 +285,7 @@ Mapper::~Mapper()
266
285
267
286
void Mapper::addBlock (v3s16 pos, MinimapMapblock *data)
268
287
{
269
- m_minimap_update_thread->m_queue . addBlock (pos, data);
288
+ m_minimap_update_thread->enqueue_Block (pos, data);
270
289
}
271
290
272
291
MinimapMode Mapper::getMinimapMode ()
0 commit comments