/*
Minetest
Copyright (C) 2010-2015 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "minimap.h"
#include <cmath>
#include "client.h"
#include "clientmap.h"
#include "settings.h"
#include "shader.h"
#include "mapblock.h"
#include "client/renderingengine.h"
#include "gettext.h"
////
//// MinimapUpdateThread
////
MinimapUpdateThread::~MinimapUpdateThread()
{
for (auto &it : m_blocks_cache) {
delete it.second;
}
for (auto &q : m_update_queue) {
delete q.data;
}
}
bool MinimapUpdateThread::pushBlockUpdate(v3s16 pos, MinimapMapblock *data)
{
MutexAutoLock lock(m_queue_mutex);
// Find if block is already in queue.
// If it is, update the data and quit.
for (QueuedMinimapUpdate &q : m_update_queue) {
if (q.pos == pos) {
delete q.data;
q.data = data;
return false;
}
}
// Add the block
QueuedMinimapUpdate q;
q.pos = pos;
q.data = data;
m_update_queue.push_back(q);
return true;
}
bool MinimapUpdateThread::popBlockUpdate(QueuedMinimapUpdate *update)
{
MutexAutoLock lock(m_queue_mutex);
if (m_update_queue.empty())
return false;
|