2015-06-22 04:34:56 +02:00
|
|
|
/*
|
|
|
|
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"
|
2018-04-03 21:58:29 +02:00
|
|
|
#include <cmath>
|
2017-08-16 22:11:45 +02:00
|
|
|
#include "client.h"
|
2015-06-22 04:34:56 +02:00
|
|
|
#include "clientmap.h"
|
|
|
|
#include "settings.h"
|
2017-08-18 19:25:07 +02:00
|
|
|
#include "shader.h"
|
2017-01-11 09:03:07 +01:00
|
|
|
#include "mapblock.h"
|
2017-06-26 20:11:17 +02:00
|
|
|
#include "client/renderingengine.h"
|
2020-10-04 15:24:29 +02:00
|
|
|
#include "gettext.h"
|
2015-06-22 04:34:56 +02:00
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
////
|
|
|
|
//// MinimapUpdateThread
|
|
|
|
////
|
2015-06-22 04:34:56 +02:00
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
MinimapUpdateThread::~MinimapUpdateThread()
|
2015-06-22 04:34:56 +02:00
|
|
|
{
|
2017-08-16 22:11:45 +02:00
|
|
|
for (auto &it : m_blocks_cache) {
|
|
|
|
delete it.second;
|
2015-07-08 06:45:24 +02:00
|
|
|
}
|
2015-06-22 04:34:56 +02:00
|
|
|
|
2017-08-16 22:11:45 +02:00
|
|
|
for (auto &q : m_update_queue) {
|
2015-07-08 06:45:24 +02:00
|
|
|
delete q.data;
|
2015-06-22 04:34:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
bool MinimapUpdateThread::pushBlockUpdate(v3s16 pos, MinimapMapblock *data)
|
2015-06-22 04:34:56 +02:00
|
|
|
{
|
2015-04-07 12:13:12 +02:00
|
|
|
MutexAutoLock lock(m_queue_mutex);
|
2015-07-08 06:45:24 +02:00
|
|
|
|
|
|
|
// Find if block is already in queue.
|
|
|
|
// If it is, update the data and quit.
|
2017-08-18 18:18:25 +02:00
|
|
|
for (QueuedMinimapUpdate &q : m_update_queue) {
|
2015-07-08 06:45:24 +02:00
|
|
|
if (q.pos == pos) {
|
|
|
|
delete q.data;
|
|
|
|
q.data = data;
|
2015-06-27 18:11:24 +02:00
|
|
|
return false;
|
2015-06-22 04:34:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
// Add the block
|
|
|
|
QueuedMinimapUpdate q;
|
|
|
|
q.pos = pos;
|
|
|
|
q.data = data;
|
|
|
|
m_update_queue.push_back(q);
|
|
|
|
|
2015-06-27 18:11:24 +02:00
|
|
|
return true;
|
2015-06-22 04:34:56 +02:00
|
|
|
}
|
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
bool MinimapUpdateThread::popBlockUpdate(QueuedMinimapUpdate *update)
|
2015-06-22 04:34:56 +02:00
|
|
|
{
|
2015-04-07 12:13:12 +02:00
|
|
|
MutexAutoLock lock(m_queue_mutex);
|
2015-06-22 04:34:56 +02:00
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
if (m_update_queue.empty())
|
|
|
|
return false;
|
2015-06-22 04:34:56 +02:00
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
*update = m_update_queue.front();
|
|
|
|
m_update_queue.pop_front();
|
2015-06-22 04:34:56 +02:00
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MinimapUpdateThread::enqueueBlock(v3s16 pos, MinimapMapblock *data)
|
2015-06-27 18:11:24 +02:00
|
|
|
{
|
2015-07-08 06:45:24 +02:00
|
|
|
pushBlockUpdate(pos, data);
|
2015-06-29 11:06:03 +02:00
|
|
|
deferUpdate();
|
2015-06-27 18:11:24 +02:00
|
|
|
}
|
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
|
2015-06-29 11:06:03 +02:00
|
|
|
void MinimapUpdateThread::doUpdate()
|
2015-06-28 14:45:47 +02:00
|
|
|
{
|
2015-07-08 06:45:24 +02:00
|
|
|
QueuedMinimapUpdate update;
|
|
|
|
|
|
|
|
while (popBlockUpdate(&update)) {
|
|
|
|
if (update.data) {
|
2015-07-19 01:35:47 +02:00
|
|
|
// Swap two values in the map using single lookup
|
|
|
|
std::pair<std::map<v3s16, MinimapMapblock*>::iterator, bool>
|
|
|
|
result = m_blocks_cache.insert(std::make_pair(update.pos, update.data));
|
2017-03-22 21:41:02 +01:00
|
|
|
if (!result.second) {
|
2015-07-19 01:35:47 +02:00
|
|
|
delete result.first->second;
|
|
|
|
result.first->second = update.data;
|
|
|
|
}
|
2015-07-08 06:45:24 +02:00
|
|
|
} else {
|
|
|
|
std::map<v3s16, MinimapMapblock *>::iterator it;
|
|
|
|
it = m_blocks_cache.find(update.pos);
|
|
|
|
if (it != m_blocks_cache.end()) {
|
|
|
|
delete it->second;
|
|
|
|
m_blocks_cache.erase(it);
|
|
|
|
}
|
2015-06-22 04:34:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-04 15:24:29 +02:00
|
|
|
|
|
|
|
if (data->map_invalidated && (
|
|
|
|
data->mode.type == MINIMAP_TYPE_RADAR ||
|
|
|
|
data->mode.type == MINIMAP_TYPE_SURFACE)) {
|
|
|
|
getMap(data->pos, data->mode.map_size, data->mode.scan_height);
|
2015-07-08 06:45:24 +02:00
|
|
|
data->map_invalidated = false;
|
2015-06-28 12:17:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-23 14:04:39 +01:00
|
|
|
void MinimapUpdateThread::getMap(v3s16 pos, s16 size, s16 height)
|
2015-06-22 04:34:56 +02:00
|
|
|
{
|
2017-02-23 14:04:39 +01:00
|
|
|
v3s16 pos_min(pos.X - size / 2, pos.Y - height / 2, pos.Z - size / 2);
|
|
|
|
v3s16 pos_max(pos_min.X + size - 1, pos.Y + height / 2, pos_min.Z + size - 1);
|
|
|
|
v3s16 blockpos_min = getNodeBlockPos(pos_min);
|
|
|
|
v3s16 blockpos_max = getNodeBlockPos(pos_max);
|
|
|
|
|
|
|
|
// clear the map
|
|
|
|
for (int z = 0; z < size; z++)
|
|
|
|
for (int x = 0; x < size; x++) {
|
|
|
|
MinimapPixel &mmpixel = data->minimap_scan[x + z * size];
|
|
|
|
mmpixel.air_count = 0;
|
|
|
|
mmpixel.height = 0;
|
|
|
|
mmpixel.n = MapNode(CONTENT_AIR);
|
2015-06-22 04:34:56 +02:00
|
|
|
}
|
2015-07-08 06:45:24 +02:00
|
|
|
|
2017-02-23 14:04:39 +01:00
|
|
|
// draw the map
|
|
|
|
v3s16 blockpos;
|
|
|
|
for (blockpos.Z = blockpos_min.Z; blockpos.Z <= blockpos_max.Z; ++blockpos.Z)
|
|
|
|
for (blockpos.Y = blockpos_min.Y; blockpos.Y <= blockpos_max.Y; ++blockpos.Y)
|
|
|
|
for (blockpos.X = blockpos_min.X; blockpos.X <= blockpos_max.X; ++blockpos.X) {
|
|
|
|
std::map<v3s16, MinimapMapblock *>::const_iterator pblock =
|
|
|
|
m_blocks_cache.find(blockpos);
|
|
|
|
if (pblock == m_blocks_cache.end())
|
|
|
|
continue;
|
|
|
|
const MinimapMapblock &block = *pblock->second;
|
|
|
|
|
|
|
|
v3s16 block_node_min(blockpos * MAP_BLOCKSIZE);
|
|
|
|
v3s16 block_node_max(block_node_min + MAP_BLOCKSIZE - 1);
|
|
|
|
// clip
|
|
|
|
v3s16 range_min = componentwise_max(block_node_min, pos_min);
|
|
|
|
v3s16 range_max = componentwise_min(block_node_max, pos_max);
|
|
|
|
|
|
|
|
v3s16 pos;
|
|
|
|
pos.Y = range_min.Y;
|
|
|
|
for (pos.Z = range_min.Z; pos.Z <= range_max.Z; ++pos.Z)
|
|
|
|
for (pos.X = range_min.X; pos.X <= range_max.X; ++pos.X) {
|
|
|
|
v3s16 inblock_pos = pos - block_node_min;
|
|
|
|
const MinimapPixel &in_pixel =
|
|
|
|
block.data[inblock_pos.Z * MAP_BLOCKSIZE + inblock_pos.X];
|
|
|
|
|
|
|
|
v3s16 inmap_pos = pos - pos_min;
|
|
|
|
MinimapPixel &out_pixel =
|
|
|
|
data->minimap_scan[inmap_pos.X + inmap_pos.Z * size];
|
|
|
|
|
|
|
|
out_pixel.air_count += in_pixel.air_count;
|
|
|
|
if (in_pixel.n.param0 != CONTENT_AIR) {
|
|
|
|
out_pixel.n = in_pixel.n;
|
|
|
|
out_pixel.height = inmap_pos.Y + in_pixel.height;
|
2015-06-22 04:34:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
////
|
|
|
|
//// Mapper
|
|
|
|
////
|
|
|
|
|
2017-06-26 20:11:17 +02:00
|
|
|
Minimap::Minimap(Client *client)
|
2015-06-22 04:34:56 +02:00
|
|
|
{
|
2016-02-18 17:17:17 +01:00
|
|
|
this->client = client;
|
2017-06-26 20:11:17 +02:00
|
|
|
this->driver = RenderingEngine::get_video_driver();
|
2015-07-08 06:45:24 +02:00
|
|
|
this->m_tsrc = client->getTextureSource();
|
|
|
|
this->m_shdrsrc = client->getShaderSource();
|
|
|
|
this->m_ndef = client->getNodeDefManager();
|
2015-06-22 04:34:56 +02:00
|
|
|
|
2015-11-08 22:19:34 +01:00
|
|
|
m_angle = 0.f;
|
2020-10-04 15:24:29 +02:00
|
|
|
m_current_mode_index = 0;
|
2015-11-08 22:19:34 +01:00
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
// Initialize static settings
|
2015-06-22 04:34:56 +02:00
|
|
|
m_enable_shaders = g_settings->getBool("enable_shaders");
|
2015-07-08 06:45:24 +02:00
|
|
|
m_surface_mode_scan_height =
|
|
|
|
g_settings->getBool("minimap_double_scan_height") ? 256 : 128;
|
|
|
|
|
2020-10-04 15:24:29 +02:00
|
|
|
// Initialize minimap modes
|
|
|
|
addMode(MINIMAP_TYPE_OFF);
|
|
|
|
addMode(MINIMAP_TYPE_SURFACE, 256);
|
|
|
|
addMode(MINIMAP_TYPE_SURFACE, 128);
|
|
|
|
addMode(MINIMAP_TYPE_SURFACE, 64);
|
|
|
|
addMode(MINIMAP_TYPE_RADAR, 512);
|
|
|
|
addMode(MINIMAP_TYPE_RADAR, 256);
|
|
|
|
addMode(MINIMAP_TYPE_RADAR, 128);
|
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
// Initialize minimap data
|
2015-06-22 04:34:56 +02:00
|
|
|
data = new MinimapData;
|
2020-10-04 15:24:29 +02:00
|
|
|
data->map_invalidated = true;
|
|
|
|
|
2015-06-22 04:34:56 +02:00
|
|
|
data->minimap_shape_round = g_settings->getBool("minimap_shape_round");
|
2015-07-08 06:45:24 +02:00
|
|
|
|
|
|
|
// Get round minimap textures
|
|
|
|
data->minimap_mask_round = driver->createImage(
|
|
|
|
m_tsrc->getTexture("minimap_mask_round.png"),
|
|
|
|
core::position2d<s32>(0, 0),
|
|
|
|
core::dimension2d<u32>(MINIMAP_MAX_SX, MINIMAP_MAX_SY));
|
|
|
|
data->minimap_overlay_round = m_tsrc->getTexture("minimap_overlay_round.png");
|
|
|
|
|
|
|
|
// Get square minimap textures
|
|
|
|
data->minimap_mask_square = driver->createImage(
|
|
|
|
m_tsrc->getTexture("minimap_mask_square.png"),
|
|
|
|
core::position2d<s32>(0, 0),
|
|
|
|
core::dimension2d<u32>(MINIMAP_MAX_SX, MINIMAP_MAX_SY));
|
|
|
|
data->minimap_overlay_square = m_tsrc->getTexture("minimap_overlay_square.png");
|
|
|
|
|
|
|
|
// Create player marker texture
|
|
|
|
data->player_marker = m_tsrc->getTexture("player_marker.png");
|
2016-02-18 17:17:17 +01:00
|
|
|
// Create object marker texture
|
|
|
|
data->object_marker_red = m_tsrc->getTexture("object_marker_red.png");
|
2015-07-08 06:45:24 +02:00
|
|
|
|
2020-10-04 15:24:29 +02:00
|
|
|
setModeIndex(0);
|
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
// Create mesh buffer for minimap
|
2015-06-22 04:34:56 +02:00
|
|
|
m_meshbuffer = getMinimapMeshBuffer();
|
2015-07-08 06:45:24 +02:00
|
|
|
|
|
|
|
// Initialize and start thread
|
|
|
|
m_minimap_update_thread = new MinimapUpdateThread();
|
2015-06-22 04:34:56 +02:00
|
|
|
m_minimap_update_thread->data = data;
|
2015-04-07 12:13:12 +02:00
|
|
|
m_minimap_update_thread->start();
|
2015-06-22 04:34:56 +02:00
|
|
|
}
|
|
|
|
|
2017-03-16 10:34:54 +01:00
|
|
|
Minimap::~Minimap()
|
2015-06-22 04:34:56 +02:00
|
|
|
{
|
2015-04-07 12:13:12 +02:00
|
|
|
m_minimap_update_thread->stop();
|
|
|
|
m_minimap_update_thread->wait();
|
2015-07-08 06:45:24 +02:00
|
|
|
|
2015-06-22 04:34:56 +02:00
|
|
|
m_meshbuffer->drop();
|
2015-07-08 06:45:24 +02:00
|
|
|
|
2015-06-22 04:34:56 +02:00
|
|
|
data->minimap_mask_round->drop();
|
|
|
|
data->minimap_mask_square->drop();
|
2015-07-08 06:45:24 +02:00
|
|
|
|
2015-06-22 04:34:56 +02:00
|
|
|
driver->removeTexture(data->texture);
|
|
|
|
driver->removeTexture(data->heightmap_texture);
|
|
|
|
driver->removeTexture(data->minimap_overlay_round);
|
|
|
|
driver->removeTexture(data->minimap_overlay_square);
|
2016-02-18 17:17:17 +01:00
|
|
|
driver->removeTexture(data->object_marker_red);
|
2015-07-08 06:45:24 +02:00
|
|
|
|
2020-10-19 20:38:15 +02:00
|
|
|
for (MinimapMarker *m : m_markers)
|
|
|
|
delete m;
|
|
|
|
m_markers.clear();
|
|
|
|
|
2015-06-22 04:34:56 +02:00
|
|
|
delete data;
|
|
|
|
delete m_minimap_update_thread;
|
|
|
|
}
|
|
|
|
|
2017-03-16 10:34:54 +01:00
|
|
|
void Minimap::addBlock(v3s16 pos, MinimapMapblock *data)
|
2015-06-22 04:34:56 +02:00
|
|
|
{
|
2015-07-08 06:45:24 +02:00
|
|
|
m_minimap_update_thread->enqueueBlock(pos, data);
|
2015-06-22 04:34:56 +02:00
|
|
|
}
|
|
|
|
|
2017-03-16 10:34:54 +01:00
|
|
|
void Minimap::toggleMinimapShape()
|
2015-06-22 04:34:56 +02:00
|
|
|
{
|
2015-04-07 12:13:12 +02:00
|
|
|
MutexAutoLock lock(m_mutex);
|
2015-07-08 06:45:24 +02:00
|
|
|
|
2015-06-22 04:34:56 +02:00
|
|
|
data->minimap_shape_round = !data->minimap_shape_round;
|
2015-07-08 06:45:24 +02:00
|
|
|
g_settings->setBool("minimap_shape_round", data->minimap_shape_round);
|
2015-06-30 21:14:28 +02:00
|
|
|
m_minimap_update_thread->deferUpdate();
|
2015-06-22 04:34:56 +02:00
|
|
|
}
|
|
|
|
|
2017-04-14 09:04:41 +02:00
|
|
|
void Minimap::setMinimapShape(MinimapShape shape)
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(m_mutex);
|
2017-06-18 19:55:15 +02:00
|
|
|
|
2017-04-14 09:04:41 +02:00
|
|
|
if (shape == MINIMAP_SHAPE_SQUARE)
|
|
|
|
data->minimap_shape_round = false;
|
|
|
|
else if (shape == MINIMAP_SHAPE_ROUND)
|
|
|
|
data->minimap_shape_round = true;
|
2017-06-18 19:55:15 +02:00
|
|
|
|
2017-04-14 09:04:41 +02:00
|
|
|
g_settings->setBool("minimap_shape_round", data->minimap_shape_round);
|
2017-06-18 19:55:15 +02:00
|
|
|
m_minimap_update_thread->deferUpdate();
|
2017-04-14 09:04:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MinimapShape Minimap::getMinimapShape()
|
|
|
|
{
|
|
|
|
if (data->minimap_shape_round) {
|
|
|
|
return MINIMAP_SHAPE_ROUND;
|
|
|
|
}
|
2017-08-18 18:18:25 +02:00
|
|
|
|
|
|
|
return MINIMAP_SHAPE_SQUARE;
|
2017-04-14 09:04:41 +02:00
|
|
|
}
|
|
|
|
|
2020-10-04 15:24:29 +02:00
|
|
|
void Minimap::setModeIndex(size_t index)
|
2015-06-22 04:34:56 +02:00
|
|
|
{
|
2015-04-07 12:13:12 +02:00
|
|
|
MutexAutoLock lock(m_mutex);
|
2015-07-08 06:45:24 +02:00
|
|
|
|
2020-10-04 15:24:29 +02:00
|
|
|
if (index < m_modes.size()) {
|
|
|
|
data->mode = m_modes[index];
|
|
|
|
m_current_mode_index = index;
|
|
|
|
} else {
|
2021-02-22 20:25:16 +01:00
|
|
|
data->mode = MinimapModeDef{MINIMAP_TYPE_OFF, gettext("Minimap hidden"), 0, 0, ""};
|
2020-10-04 15:24:29 +02:00
|
|
|
m_current_mode_index = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->map_invalidated = true;
|
2015-07-08 06:45:24 +02:00
|
|
|
|
2020-10-04 15:24:29 +02:00
|
|
|
if (m_minimap_update_thread)
|
|
|
|
m_minimap_update_thread->deferUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Minimap::addMode(MinimapModeDef mode)
|
|
|
|
{
|
|
|
|
// Check validity
|
|
|
|
if (mode.type == MINIMAP_TYPE_TEXTURE) {
|
|
|
|
if (mode.texture.empty())
|
|
|
|
return;
|
|
|
|
if (mode.scale < 1)
|
|
|
|
mode.scale = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int zoom = -1;
|
|
|
|
|
|
|
|
// Build a default standard label
|
|
|
|
if (mode.label == "") {
|
|
|
|
switch (mode.type) {
|
|
|
|
case MINIMAP_TYPE_OFF:
|
2021-02-22 20:25:16 +01:00
|
|
|
mode.label = gettext("Minimap hidden");
|
2020-10-04 15:24:29 +02:00
|
|
|
break;
|
|
|
|
case MINIMAP_TYPE_SURFACE:
|
2021-02-22 20:25:16 +01:00
|
|
|
mode.label = gettext("Minimap in surface mode, Zoom x%d");
|
2020-10-04 15:24:29 +02:00
|
|
|
if (mode.map_size > 0)
|
|
|
|
zoom = 256 / mode.map_size;
|
|
|
|
break;
|
|
|
|
case MINIMAP_TYPE_RADAR:
|
2021-02-22 20:25:16 +01:00
|
|
|
mode.label = gettext("Minimap in radar mode, Zoom x%d");
|
2020-10-04 15:24:29 +02:00
|
|
|
if (mode.map_size > 0)
|
|
|
|
zoom = 512 / mode.map_size;
|
|
|
|
break;
|
|
|
|
case MINIMAP_TYPE_TEXTURE:
|
2021-02-22 20:25:16 +01:00
|
|
|
mode.label = gettext("Minimap in texture mode");
|
2020-10-04 15:24:29 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-02-22 20:25:16 +01:00
|
|
|
// else: Custom labels need mod-provided client-side translation
|
2020-10-04 15:24:29 +02:00
|
|
|
|
|
|
|
if (zoom >= 0) {
|
|
|
|
char label_buf[1024];
|
|
|
|
porting::mt_snprintf(label_buf, sizeof(label_buf),
|
|
|
|
mode.label.c_str(), zoom);
|
|
|
|
mode.label = label_buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_modes.push_back(mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Minimap::addMode(MinimapType type, u16 size, std::string label,
|
|
|
|
std::string texture, u16 scale)
|
|
|
|
{
|
|
|
|
MinimapModeDef mode;
|
|
|
|
mode.type = type;
|
|
|
|
mode.label = label;
|
|
|
|
mode.map_size = size;
|
|
|
|
mode.texture = texture;
|
|
|
|
mode.scale = scale;
|
|
|
|
switch (type) {
|
|
|
|
case MINIMAP_TYPE_SURFACE:
|
|
|
|
mode.scan_height = m_surface_mode_scan_height;
|
|
|
|
break;
|
|
|
|
case MINIMAP_TYPE_RADAR:
|
|
|
|
mode.scan_height = 32;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mode.scan_height = 0;
|
|
|
|
}
|
|
|
|
addMode(mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Minimap::nextMode()
|
|
|
|
{
|
|
|
|
if (m_modes.empty())
|
|
|
|
return;
|
|
|
|
m_current_mode_index++;
|
|
|
|
if (m_current_mode_index >= m_modes.size())
|
|
|
|
m_current_mode_index = 0;
|
|
|
|
|
|
|
|
setModeIndex(m_current_mode_index);
|
2015-06-22 04:34:56 +02:00
|
|
|
}
|
|
|
|
|
2017-03-16 10:34:54 +01:00
|
|
|
void Minimap::setPos(v3s16 pos)
|
2015-06-22 04:34:56 +02:00
|
|
|
{
|
2015-07-08 06:45:24 +02:00
|
|
|
bool do_update = false;
|
|
|
|
|
|
|
|
{
|
2015-04-07 12:13:12 +02:00
|
|
|
MutexAutoLock lock(m_mutex);
|
2015-07-08 06:45:24 +02:00
|
|
|
|
|
|
|
if (pos != data->old_pos) {
|
|
|
|
data->old_pos = data->pos;
|
|
|
|
data->pos = pos;
|
|
|
|
do_update = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_update)
|
2015-06-29 11:06:03 +02:00
|
|
|
m_minimap_update_thread->deferUpdate();
|
2015-07-08 06:45:24 +02:00
|
|
|
}
|
|
|
|
|
2017-03-16 10:34:54 +01:00
|
|
|
void Minimap::setAngle(f32 angle)
|
2015-07-08 06:45:24 +02:00
|
|
|
{
|
|
|
|
m_angle = angle;
|
|
|
|
}
|
|
|
|
|
2017-03-16 10:34:54 +01:00
|
|
|
void Minimap::blitMinimapPixelsToImageRadar(video::IImage *map_image)
|
2015-07-08 06:45:24 +02:00
|
|
|
{
|
2017-03-22 21:41:02 +01:00
|
|
|
video::SColor c(240, 0, 0, 0);
|
2020-10-04 15:24:29 +02:00
|
|
|
for (s16 x = 0; x < data->mode.map_size; x++)
|
|
|
|
for (s16 z = 0; z < data->mode.map_size; z++) {
|
|
|
|
MinimapPixel *mmpixel = &data->minimap_scan[x + z * data->mode.map_size];
|
2015-07-08 06:45:24 +02:00
|
|
|
|
|
|
|
if (mmpixel->air_count > 0)
|
|
|
|
c.setGreen(core::clamp(core::round32(32 + mmpixel->air_count * 8), 0, 255));
|
2017-03-22 21:41:02 +01:00
|
|
|
else
|
|
|
|
c.setGreen(0);
|
2015-07-08 06:45:24 +02:00
|
|
|
|
2020-10-04 15:24:29 +02:00
|
|
|
map_image->setPixel(x, data->mode.map_size - z - 1, c);
|
2015-07-08 06:45:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-16 10:34:54 +01:00
|
|
|
void Minimap::blitMinimapPixelsToImageSurface(
|
2015-07-08 06:45:24 +02:00
|
|
|
video::IImage *map_image, video::IImage *heightmap_image)
|
|
|
|
{
|
2017-03-22 21:41:02 +01:00
|
|
|
// This variable creation/destruction has a 1% cost on rendering minimap
|
|
|
|
video::SColor tilecolor;
|
2020-10-04 15:24:29 +02:00
|
|
|
for (s16 x = 0; x < data->mode.map_size; x++)
|
|
|
|
for (s16 z = 0; z < data->mode.map_size; z++) {
|
|
|
|
MinimapPixel *mmpixel = &data->minimap_scan[x + z * data->mode.map_size];
|
2015-07-08 06:45:24 +02:00
|
|
|
|
2017-01-12 15:46:30 +01:00
|
|
|
const ContentFeatures &f = m_ndef->get(mmpixel->n);
|
|
|
|
const TileDef *tile = &f.tiledef[0];
|
2017-03-22 21:41:02 +01:00
|
|
|
|
2017-01-12 15:46:30 +01:00
|
|
|
// Color of the 0th tile (mostly this is the topmost)
|
|
|
|
if(tile->has_color)
|
|
|
|
tilecolor = tile->color;
|
|
|
|
else
|
|
|
|
mmpixel->n.getColor(f, &tilecolor);
|
2017-03-22 21:41:02 +01:00
|
|
|
|
2017-01-12 15:46:30 +01:00
|
|
|
tilecolor.setRed(tilecolor.getRed() * f.minimap_color.getRed() / 255);
|
2017-03-22 21:41:02 +01:00
|
|
|
tilecolor.setGreen(tilecolor.getGreen() * f.minimap_color.getGreen() / 255);
|
2017-01-12 15:46:30 +01:00
|
|
|
tilecolor.setBlue(tilecolor.getBlue() * f.minimap_color.getBlue() / 255);
|
|
|
|
tilecolor.setAlpha(240);
|
|
|
|
|
2020-10-04 15:24:29 +02:00
|
|
|
map_image->setPixel(x, data->mode.map_size - z - 1, tilecolor);
|
2015-07-08 06:45:24 +02:00
|
|
|
|
|
|
|
u32 h = mmpixel->height;
|
2020-10-04 15:24:29 +02:00
|
|
|
heightmap_image->setPixel(x,data->mode.map_size - z - 1,
|
2015-07-08 06:45:24 +02:00
|
|
|
video::SColor(255, h, h, h));
|
2015-06-28 14:45:47 +02:00
|
|
|
}
|
2015-06-22 04:34:56 +02:00
|
|
|
}
|
|
|
|
|
2017-03-16 10:34:54 +01:00
|
|
|
video::ITexture *Minimap::getMinimapTexture()
|
2015-06-22 04:34:56 +02:00
|
|
|
{
|
|
|
|
// update minimap textures when new scan is ready
|
2020-10-04 15:24:29 +02:00
|
|
|
if (data->map_invalidated && data->mode.type != MINIMAP_TYPE_TEXTURE)
|
2015-07-08 06:45:24 +02:00
|
|
|
return data->texture;
|
|
|
|
|
|
|
|
// create minimap and heightmap images in memory
|
2020-10-04 15:24:29 +02:00
|
|
|
core::dimension2d<u32> dim(data->mode.map_size, data->mode.map_size);
|
2015-07-08 06:45:24 +02:00
|
|
|
video::IImage *map_image = driver->createImage(video::ECF_A8R8G8B8, dim);
|
|
|
|
video::IImage *heightmap_image = driver->createImage(video::ECF_A8R8G8B8, dim);
|
|
|
|
video::IImage *minimap_image = driver->createImage(video::ECF_A8R8G8B8,
|
|
|
|
core::dimension2d<u32>(MINIMAP_MAX_SX, MINIMAP_MAX_SY));
|
|
|
|
|
|
|
|
// Blit MinimapPixels to images
|
2020-10-04 15:24:29 +02:00
|
|
|
switch(data->mode.type) {
|
|
|
|
case MINIMAP_TYPE_OFF:
|
|
|
|
break;
|
|
|
|
case MINIMAP_TYPE_SURFACE:
|
2015-07-08 06:45:24 +02:00
|
|
|
blitMinimapPixelsToImageSurface(map_image, heightmap_image);
|
2020-10-04 15:24:29 +02:00
|
|
|
break;
|
|
|
|
case MINIMAP_TYPE_RADAR:
|
|
|
|
blitMinimapPixelsToImageRadar(map_image);
|
|
|
|
break;
|
|
|
|
case MINIMAP_TYPE_TEXTURE:
|
|
|
|
// Want to use texture source, to : 1 find texture, 2 cache it
|
|
|
|
video::ITexture* texture = m_tsrc->getTexture(data->mode.texture);
|
|
|
|
video::IImage* image = driver->createImageFromData(
|
|
|
|
texture->getColorFormat(), texture->getSize(), texture->lock(), true, false);
|
|
|
|
texture->unlock();
|
|
|
|
|
|
|
|
auto dim = image->getDimension();
|
|
|
|
|
|
|
|
map_image->fill(video::SColor(255, 0, 0, 0));
|
|
|
|
|
|
|
|
image->copyTo(map_image,
|
|
|
|
irr::core::vector2d<int> {
|
|
|
|
((data->mode.map_size - (static_cast<int>(dim.Width))) >> 1)
|
|
|
|
- data->pos.X / data->mode.scale,
|
|
|
|
((data->mode.map_size - (static_cast<int>(dim.Height))) >> 1)
|
|
|
|
+ data->pos.Z / data->mode.scale
|
|
|
|
});
|
|
|
|
image->drop();
|
|
|
|
}
|
2015-07-08 06:45:24 +02:00
|
|
|
|
|
|
|
map_image->copyToScaling(minimap_image);
|
|
|
|
map_image->drop();
|
|
|
|
|
|
|
|
video::IImage *minimap_mask = data->minimap_shape_round ?
|
|
|
|
data->minimap_mask_round : data->minimap_mask_square;
|
|
|
|
|
|
|
|
if (minimap_mask) {
|
|
|
|
for (s16 y = 0; y < MINIMAP_MAX_SY; y++)
|
|
|
|
for (s16 x = 0; x < MINIMAP_MAX_SX; x++) {
|
2017-03-22 21:41:02 +01:00
|
|
|
const video::SColor &mask_col = minimap_mask->getPixel(x, y);
|
2015-07-08 06:45:24 +02:00
|
|
|
if (!mask_col.getAlpha())
|
|
|
|
minimap_image->setPixel(x, y, video::SColor(0,0,0,0));
|
2015-06-22 04:34:56 +02:00
|
|
|
}
|
2015-07-08 06:45:24 +02:00
|
|
|
}
|
2015-06-22 04:34:56 +02:00
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
if (data->texture)
|
|
|
|
driver->removeTexture(data->texture);
|
|
|
|
if (data->heightmap_texture)
|
|
|
|
driver->removeTexture(data->heightmap_texture);
|
2015-06-22 04:34:56 +02:00
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
data->texture = driver->addTexture("minimap__", minimap_image);
|
|
|
|
data->heightmap_texture =
|
|
|
|
driver->addTexture("minimap_heightmap__", heightmap_image);
|
|
|
|
minimap_image->drop();
|
|
|
|
heightmap_image->drop();
|
2015-06-22 04:34:56 +02:00
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
data->map_invalidated = true;
|
2015-06-22 04:34:56 +02:00
|
|
|
|
|
|
|
return data->texture;
|
|
|
|
}
|
|
|
|
|
2017-03-16 10:34:54 +01:00
|
|
|
v3f Minimap::getYawVec()
|
2015-06-22 04:34:56 +02:00
|
|
|
{
|
|
|
|
if (data->minimap_shape_round) {
|
2015-07-08 06:45:24 +02:00
|
|
|
return v3f(
|
2018-04-03 21:58:29 +02:00
|
|
|
std::cos(m_angle * core::DEGTORAD),
|
|
|
|
std::sin(m_angle * core::DEGTORAD),
|
2015-07-08 06:45:24 +02:00
|
|
|
1.0);
|
2015-06-22 04:34:56 +02:00
|
|
|
}
|
2017-08-18 18:18:25 +02:00
|
|
|
|
|
|
|
return v3f(1.0, 0.0, 1.0);
|
2015-06-22 04:34:56 +02:00
|
|
|
}
|
|
|
|
|
2017-03-16 10:34:54 +01:00
|
|
|
scene::SMeshBuffer *Minimap::getMinimapMeshBuffer()
|
2015-06-22 04:34:56 +02:00
|
|
|
{
|
|
|
|
scene::SMeshBuffer *buf = new scene::SMeshBuffer();
|
|
|
|
buf->Vertices.set_used(4);
|
2015-07-08 06:45:24 +02:00
|
|
|
buf->Indices.set_used(6);
|
2017-03-22 21:41:02 +01:00
|
|
|
static const video::SColor c(255, 255, 255, 255);
|
2015-06-22 04:34:56 +02:00
|
|
|
|
|
|
|
buf->Vertices[0] = video::S3DVertex(-1, -1, 0, 0, 0, 1, c, 0, 1);
|
|
|
|
buf->Vertices[1] = video::S3DVertex(-1, 1, 0, 0, 0, 1, c, 0, 0);
|
|
|
|
buf->Vertices[2] = video::S3DVertex( 1, 1, 0, 0, 0, 1, c, 1, 0);
|
|
|
|
buf->Vertices[3] = video::S3DVertex( 1, -1, 0, 0, 0, 1, c, 1, 1);
|
|
|
|
|
|
|
|
buf->Indices[0] = 0;
|
|
|
|
buf->Indices[1] = 1;
|
|
|
|
buf->Indices[2] = 2;
|
|
|
|
buf->Indices[3] = 2;
|
|
|
|
buf->Indices[4] = 3;
|
|
|
|
buf->Indices[5] = 0;
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2017-03-16 10:34:54 +01:00
|
|
|
void Minimap::drawMinimap()
|
2015-06-22 04:34:56 +02:00
|
|
|
{
|
2020-10-04 15:24:29 +02:00
|
|
|
// Non hud managed minimap drawing (legacy minimap)
|
|
|
|
v2u32 screensize = RenderingEngine::get_instance()->getWindowSize();
|
|
|
|
const u32 size = 0.25 * screensize.Y;
|
|
|
|
|
|
|
|
drawMinimap(core::rect<s32>(
|
|
|
|
screensize.X - size - 10, 10,
|
|
|
|
screensize.X - 10, size + 10));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Minimap::drawMinimap(core::rect<s32> rect) {
|
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
video::ITexture *minimap_texture = getMinimapTexture();
|
|
|
|
if (!minimap_texture)
|
|
|
|
return;
|
|
|
|
|
2020-10-04 15:24:29 +02:00
|
|
|
if (data->mode.type == MINIMAP_TYPE_OFF)
|
|
|
|
return;
|
|
|
|
|
2016-02-18 17:17:17 +01:00
|
|
|
updateActiveMarkers();
|
2015-06-22 04:34:56 +02:00
|
|
|
|
|
|
|
core::rect<s32> oldViewPort = driver->getViewPort();
|
|
|
|
core::matrix4 oldProjMat = driver->getTransform(video::ETS_PROJECTION);
|
|
|
|
core::matrix4 oldViewMat = driver->getTransform(video::ETS_VIEW);
|
2015-07-08 06:45:24 +02:00
|
|
|
|
2020-10-04 15:24:29 +02:00
|
|
|
driver->setViewPort(rect);
|
2015-07-08 06:45:24 +02:00
|
|
|
driver->setTransform(video::ETS_PROJECTION, core::matrix4());
|
2015-06-22 04:34:56 +02:00
|
|
|
driver->setTransform(video::ETS_VIEW, core::matrix4());
|
2015-07-08 06:45:24 +02:00
|
|
|
|
|
|
|
core::matrix4 matrix;
|
2015-06-22 04:34:56 +02:00
|
|
|
matrix.makeIdentity();
|
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
video::SMaterial &material = m_meshbuffer->getMaterial();
|
|
|
|
material.setFlag(video::EMF_TRILINEAR_FILTER, true);
|
|
|
|
material.Lighting = false;
|
|
|
|
material.TextureLayer[0].Texture = minimap_texture;
|
|
|
|
material.TextureLayer[1].Texture = data->heightmap_texture;
|
2015-06-22 04:34:56 +02:00
|
|
|
|
2020-10-04 15:24:29 +02:00
|
|
|
if (m_enable_shaders && data->mode.type == MINIMAP_TYPE_SURFACE) {
|
2020-12-19 20:57:10 +01:00
|
|
|
u16 sid = m_shdrsrc->getShader("minimap_shader", TILE_MATERIAL_ALPHA);
|
2015-07-08 06:45:24 +02:00
|
|
|
material.MaterialType = m_shdrsrc->getShaderInfo(sid).material;
|
|
|
|
} else {
|
2015-06-22 04:34:56 +02:00
|
|
|
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
2015-07-08 06:45:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data->minimap_shape_round)
|
|
|
|
matrix.setRotationDegrees(core::vector3df(0, 0, 360 - m_angle));
|
|
|
|
|
|
|
|
// Draw minimap
|
|
|
|
driver->setTransform(video::ETS_WORLD, matrix);
|
|
|
|
driver->setMaterial(material);
|
|
|
|
driver->drawMeshBuffer(m_meshbuffer);
|
|
|
|
|
|
|
|
// Draw overlay
|
|
|
|
video::ITexture *minimap_overlay = data->minimap_shape_round ?
|
|
|
|
data->minimap_overlay_round : data->minimap_overlay_square;
|
|
|
|
material.TextureLayer[0].Texture = minimap_overlay;
|
|
|
|
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
|
|
|
driver->setMaterial(material);
|
|
|
|
driver->drawMeshBuffer(m_meshbuffer);
|
|
|
|
|
2018-05-18 22:45:14 +02:00
|
|
|
// Draw player marker on minimap
|
|
|
|
if (data->minimap_shape_round) {
|
|
|
|
matrix.setRotationDegrees(core::vector3df(0, 0, 0));
|
|
|
|
} else {
|
2015-07-08 06:45:24 +02:00
|
|
|
matrix.setRotationDegrees(core::vector3df(0, 0, m_angle));
|
2015-06-22 04:34:56 +02:00
|
|
|
}
|
2018-05-18 22:45:14 +02:00
|
|
|
|
|
|
|
material.TextureLayer[0].Texture = data->player_marker;
|
|
|
|
driver->setTransform(video::ETS_WORLD, matrix);
|
|
|
|
driver->setMaterial(material);
|
|
|
|
driver->drawMeshBuffer(m_meshbuffer);
|
2015-06-22 04:34:56 +02:00
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
// Reset transformations
|
2015-06-22 04:34:56 +02:00
|
|
|
driver->setTransform(video::ETS_VIEW, oldViewMat);
|
|
|
|
driver->setTransform(video::ETS_PROJECTION, oldProjMat);
|
|
|
|
driver->setViewPort(oldViewPort);
|
2016-02-18 17:17:17 +01:00
|
|
|
|
|
|
|
// Draw player markers
|
2020-10-04 15:24:29 +02:00
|
|
|
v2s32 s_pos(rect.UpperLeftCorner.X, rect.UpperLeftCorner.Y);
|
2016-02-18 17:17:17 +01:00
|
|
|
core::dimension2di imgsize(data->object_marker_red->getOriginalSize());
|
|
|
|
core::rect<s32> img_rect(0, 0, imgsize.Width, imgsize.Height);
|
|
|
|
static const video::SColor col(255, 255, 255, 255);
|
|
|
|
static const video::SColor c[4] = {col, col, col, col};
|
2018-04-03 21:58:29 +02:00
|
|
|
f32 sin_angle = std::sin(m_angle * core::DEGTORAD);
|
|
|
|
f32 cos_angle = std::cos(m_angle * core::DEGTORAD);
|
2020-10-04 15:24:29 +02:00
|
|
|
s32 marker_size2 = 0.025 * (float)rect.getWidth();;
|
2016-02-18 17:17:17 +01:00
|
|
|
for (std::list<v2f>::const_iterator
|
|
|
|
i = m_active_markers.begin();
|
|
|
|
i != m_active_markers.end(); ++i) {
|
|
|
|
v2f posf = *i;
|
|
|
|
if (data->minimap_shape_round) {
|
|
|
|
f32 t1 = posf.X * cos_angle - posf.Y * sin_angle;
|
|
|
|
f32 t2 = posf.X * sin_angle + posf.Y * cos_angle;
|
|
|
|
posf.X = t1;
|
|
|
|
posf.Y = t2;
|
|
|
|
}
|
2020-10-04 15:24:29 +02:00
|
|
|
posf.X = (posf.X + 0.5) * (float)rect.getWidth();
|
|
|
|
posf.Y = (posf.Y + 0.5) * (float)rect.getHeight();
|
2016-02-18 17:17:17 +01:00
|
|
|
core::rect<s32> dest_rect(
|
|
|
|
s_pos.X + posf.X - marker_size2,
|
|
|
|
s_pos.Y + posf.Y - marker_size2,
|
|
|
|
s_pos.X + posf.X + marker_size2,
|
|
|
|
s_pos.Y + posf.Y + marker_size2);
|
|
|
|
driver->draw2DImage(data->object_marker_red, dest_rect,
|
|
|
|
img_rect, &dest_rect, &c[0], true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-19 20:38:15 +02:00
|
|
|
MinimapMarker* Minimap::addMarker(scene::ISceneNode *parent_node)
|
|
|
|
{
|
|
|
|
MinimapMarker *m = new MinimapMarker(parent_node);
|
|
|
|
m_markers.push_back(m);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Minimap::removeMarker(MinimapMarker **m)
|
|
|
|
{
|
|
|
|
m_markers.remove(*m);
|
|
|
|
delete *m;
|
|
|
|
*m = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-03-16 10:34:54 +01:00
|
|
|
void Minimap::updateActiveMarkers()
|
2016-02-18 17:17:17 +01:00
|
|
|
{
|
|
|
|
video::IImage *minimap_mask = data->minimap_shape_round ?
|
|
|
|
data->minimap_mask_round : data->minimap_mask_square;
|
|
|
|
|
|
|
|
m_active_markers.clear();
|
2020-10-19 20:38:15 +02:00
|
|
|
v3f cam_offset = intToFloat(client->getCamera()->getOffset(), BS);
|
|
|
|
v3s16 pos_offset = data->pos - v3s16(data->mode.map_size / 2,
|
|
|
|
data->mode.scan_height / 2,
|
|
|
|
data->mode.map_size / 2);
|
|
|
|
|
|
|
|
for (MinimapMarker *marker : m_markers) {
|
|
|
|
v3s16 pos = floatToInt(marker->parent_node->getAbsolutePosition() +
|
|
|
|
cam_offset, BS) - pos_offset;
|
2020-10-04 15:24:29 +02:00
|
|
|
if (pos.X < 0 || pos.X > data->mode.map_size ||
|
|
|
|
pos.Y < 0 || pos.Y > data->mode.scan_height ||
|
|
|
|
pos.Z < 0 || pos.Z > data->mode.map_size) {
|
2016-02-18 17:17:17 +01:00
|
|
|
continue;
|
|
|
|
}
|
2020-10-04 15:24:29 +02:00
|
|
|
pos.X = ((float)pos.X / data->mode.map_size) * MINIMAP_MAX_SX;
|
|
|
|
pos.Z = ((float)pos.Z / data->mode.map_size) * MINIMAP_MAX_SY;
|
2017-03-22 21:41:02 +01:00
|
|
|
const video::SColor &mask_col = minimap_mask->getPixel(pos.X, pos.Z);
|
2016-02-18 17:17:17 +01:00
|
|
|
if (!mask_col.getAlpha()) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-08-18 18:18:25 +02:00
|
|
|
|
|
|
|
m_active_markers.emplace_back(((float)pos.X / (float)MINIMAP_MAX_SX) - 0.5,
|
|
|
|
(1.0 - (float)pos.Z / (float)MINIMAP_MAX_SY) - 0.5);
|
2016-02-18 17:17:17 +01:00
|
|
|
}
|
2015-06-22 04:34:56 +02:00
|
|
|
}
|
2015-07-08 06:45:24 +02:00
|
|
|
|
|
|
|
////
|
|
|
|
//// MinimapMapblock
|
|
|
|
////
|
|
|
|
|
2017-07-26 07:35:09 +02:00
|
|
|
void MinimapMapblock::getMinimapNodes(VoxelManipulator *vmanip, const v3s16 &pos)
|
2015-07-08 06:45:24 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
for (s16 x = 0; x < MAP_BLOCKSIZE; x++)
|
|
|
|
for (s16 z = 0; z < MAP_BLOCKSIZE; z++) {
|
|
|
|
s16 air_count = 0;
|
|
|
|
bool surface_found = false;
|
|
|
|
MinimapPixel *mmpixel = &data[z * MAP_BLOCKSIZE + x];
|
|
|
|
|
|
|
|
for (s16 y = MAP_BLOCKSIZE -1; y >= 0; y--) {
|
|
|
|
v3s16 p(x, y, z);
|
|
|
|
MapNode n = vmanip->getNodeNoEx(pos + p);
|
|
|
|
if (!surface_found && n.getContent() != CONTENT_AIR) {
|
|
|
|
mmpixel->height = y;
|
2017-01-12 15:46:30 +01:00
|
|
|
mmpixel->n = n;
|
2015-07-08 06:45:24 +02:00
|
|
|
surface_found = true;
|
|
|
|
} else if (n.getContent() == CONTENT_AIR) {
|
|
|
|
air_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!surface_found)
|
2017-01-12 15:46:30 +01:00
|
|
|
mmpixel->n = MapNode(CONTENT_AIR);
|
2015-07-08 06:45:24 +02:00
|
|
|
|
|
|
|
mmpixel->air_count = air_count;
|
|
|
|
}
|
|
|
|
}
|