#include "minimap.h"
#include "logoutputbuffer.h"
#include "jthread/jmutexautolock.h"
+#include "jthread/jsemaphore.h"
#include "clientmap.h"
#include "settings.h"
#include "nodedef.h"
{
JMutexAutoLock lock(m_mutex);
- for (std::vector<QueuedMinimapUpdate*>::iterator
+ for (std::list<QueuedMinimapUpdate*>::iterator
i = m_queue.begin();
- i != m_queue.end(); i++)
- {
+ i != m_queue.end(); ++i) {
QueuedMinimapUpdate *q = *i;
delete q;
}
}
-void MinimapUpdateQueue::addBlock(v3s16 pos, MinimapMapblock *data)
+bool MinimapUpdateQueue::addBlock(v3s16 pos, MinimapMapblock *data)
{
DSTACK(__FUNCTION_NAME);
Find if block is already in queue.
If it is, update the data and quit.
*/
- for (std::vector<QueuedMinimapUpdate*>::iterator
+ for (std::list<QueuedMinimapUpdate*>::iterator
i = m_queue.begin();
- i != m_queue.end(); i++)
- {
+ i != m_queue.end(); ++i) {
QueuedMinimapUpdate *q = *i;
if (q->pos == pos) {
delete q->data;
q->data = data;
- return;
+ return false;
}
}
q->pos = pos;
q->data = data;
m_queue.push_back(q);
+ return true;
}
QueuedMinimapUpdate * MinimapUpdateQueue::pop()
{
JMutexAutoLock lock(m_mutex);
- for (std::vector<QueuedMinimapUpdate*>::iterator
+ for (std::list<QueuedMinimapUpdate*>::iterator
i = m_queue.begin();
- i != m_queue.end(); i++)
- {
+ i != m_queue.end(); i++) {
QueuedMinimapUpdate *q = *i;
m_queue.erase(i);
return q;
Minimap update thread
*/
+void MinimapUpdateThread::Stop()
+{
+ JThread::Stop();
+
+ // give us a nudge
+ m_queue_sem.Post();
+}
+
+void MinimapUpdateThread::enqueue_Block(v3s16 pos, MinimapMapblock *data)
+{
+ if (m_queue.addBlock(pos, data))
+ // we had to allocate a new block
+ m_queue_sem.Post();
+}
+
+
void *MinimapUpdateThread::Thread()
{
ThreadStarted();
while (!StopRequested()) {
+ m_queue_sem.Wait();
+ if (StopRequested()) break;
+
while (m_queue.size()) {
QueuedMinimapUpdate *q = m_queue.pop();
+ if (!q)
+ break;
std::map<v3s16, MinimapMapblock *>::iterator it;
it = m_blocks_cache.find(q->pos);
if (q->data) {
data->map_invalidated = false;
}
}
- // sleep_ms(10);
}
END_DEBUG_EXCEPTION_HANDLER(errorstream)
void Mapper::addBlock (v3s16 pos, MinimapMapblock *data)
{
- m_minimap_update_thread->m_queue.addBlock(pos, data);
+ m_minimap_update_thread->enqueue_Block(pos, data);
}
MinimapMode Mapper::getMinimapMode()
#include "client.h"
#include "voxel.h"
#include "jthread/jmutex.h"
+#include "jthread/jsemaphore.h"
#include <map>
#include <string>
#include <vector>
~MinimapUpdateQueue();
- void addBlock(v3s16 pos, MinimapMapblock *data);
+ bool addBlock(v3s16 pos, MinimapMapblock *data);
+ // blocking!!
QueuedMinimapUpdate *pop();
u32 size()
}
private:
- std::vector<QueuedMinimapUpdate*> m_queue;
+ std::list<QueuedMinimapUpdate*> m_queue;
JMutex m_mutex;
};
class MinimapUpdateThread : public JThread
{
private:
+ JSemaphore m_queue_sem;
+ MinimapUpdateQueue m_queue;
public:
MinimapUpdateThread(IrrlichtDevice *device, Client *client)
MinimapPixel *getMinimapPixel (v3s16 pos, s16 height, s16 &pixel_height);
s16 getAirCount (v3s16 pos, s16 height);
video::SColor getColorFromId(u16 id);
+
+ void enqueue_Block(v3s16 pos, MinimapMapblock *data);
+
IrrlichtDevice *device;
Client *client;
video::IVideoDriver *driver;
ITextureSource *tsrc;
+ void Stop();
void *Thread();
MinimapData *data;
- MinimapUpdateQueue m_queue;
std::map<v3s16, MinimapMapblock *> m_blocks_cache;
};