summaryrefslogtreecommitdiff
path: root/src/minimap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/minimap.cpp')
-rw-r--r--src/minimap.cpp94
1 files changed, 82 insertions, 12 deletions
diff --git a/src/minimap.cpp b/src/minimap.cpp
index d1fb3867d..8cd0a7beb 100644
--- a/src/minimap.cpp
+++ b/src/minimap.cpp
@@ -18,16 +18,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
#include "minimap.h"
-#include <math.h>
-#include "logoutputbuffer.h"
-#include "jthread/jmutexautolock.h"
-#include "jthread/jsemaphore.h"
+#include "threading/mutex_auto_lock.h"
+#include "threading/semaphore.h"
#include "clientmap.h"
#include "settings.h"
#include "nodedef.h"
#include "porting.h"
#include "util/numeric.h"
#include "util/string.h"
+#include <math.h>
////
@@ -52,7 +51,7 @@ MinimapUpdateThread::~MinimapUpdateThread()
bool MinimapUpdateThread::pushBlockUpdate(v3s16 pos, MinimapMapblock *data)
{
- JMutexAutoLock lock(m_queue_mutex);
+ MutexAutoLock lock(m_queue_mutex);
// Find if block is already in queue.
// If it is, update the data and quit.
@@ -78,7 +77,7 @@ bool MinimapUpdateThread::pushBlockUpdate(v3s16 pos, MinimapMapblock *data)
bool MinimapUpdateThread::popBlockUpdate(QueuedMinimapUpdate *update)
{
- JMutexAutoLock lock(m_queue_mutex);
+ MutexAutoLock lock(m_queue_mutex);
if (m_update_queue.empty())
return false;
@@ -212,11 +211,14 @@ void MinimapUpdateThread::getMap(v3s16 pos, s16 size, s16 height, bool is_radar)
Mapper::Mapper(IrrlichtDevice *device, Client *client)
{
+ this->client = client;
this->driver = device->getVideoDriver();
this->m_tsrc = client->getTextureSource();
this->m_shdrsrc = client->getShaderSource();
this->m_ndef = client->getNodeDefManager();
+ m_angle = 0.f;
+
// Initialize static settings
m_enable_shaders = g_settings->getBool("enable_shaders");
m_surface_mode_scan_height =
@@ -249,6 +251,8 @@ Mapper::Mapper(IrrlichtDevice *device, Client *client)
// Create player marker texture
data->player_marker = m_tsrc->getTexture("player_marker.png");
+ // Create object marker texture
+ data->object_marker_red = m_tsrc->getTexture("object_marker_red.png");
// Create mesh buffer for minimap
m_meshbuffer = getMinimapMeshBuffer();
@@ -256,13 +260,13 @@ Mapper::Mapper(IrrlichtDevice *device, Client *client)
// Initialize and start thread
m_minimap_update_thread = new MinimapUpdateThread();
m_minimap_update_thread->data = data;
- m_minimap_update_thread->Start();
+ m_minimap_update_thread->start();
}
Mapper::~Mapper()
{
- m_minimap_update_thread->Stop();
- m_minimap_update_thread->Wait();
+ m_minimap_update_thread->stop();
+ m_minimap_update_thread->wait();
m_meshbuffer->drop();
@@ -273,6 +277,7 @@ Mapper::~Mapper()
driver->removeTexture(data->heightmap_texture);
driver->removeTexture(data->minimap_overlay_round);
driver->removeTexture(data->minimap_overlay_square);
+ driver->removeTexture(data->object_marker_red);
delete data;
delete m_minimap_update_thread;
@@ -290,7 +295,7 @@ MinimapMode Mapper::getMinimapMode()
void Mapper::toggleMinimapShape()
{
- JMutexAutoLock lock(m_mutex);
+ MutexAutoLock lock(m_mutex);
data->minimap_shape_round = !data->minimap_shape_round;
g_settings->setBool("minimap_shape_round", data->minimap_shape_round);
@@ -312,7 +317,7 @@ void Mapper::setMinimapMode(MinimapMode mode)
if (mode >= MINIMAP_MODE_COUNT)
return;
- JMutexAutoLock lock(m_mutex);
+ MutexAutoLock lock(m_mutex);
data->is_radar = modedefs[mode].is_radar;
data->scan_height = modedefs[mode].scan_height;
@@ -327,7 +332,7 @@ void Mapper::setPos(v3s16 pos)
bool do_update = false;
{
- JMutexAutoLock lock(m_mutex);
+ MutexAutoLock lock(m_mutex);
if (pos != data->old_pos) {
data->old_pos = data->pos;
@@ -467,6 +472,7 @@ void Mapper::drawMinimap()
if (!minimap_texture)
return;
+ updateActiveMarkers();
v2u32 screensize = porting::getWindowSize();
const u32 size = 0.25 * screensize.Y;
@@ -526,6 +532,70 @@ void Mapper::drawMinimap()
driver->setTransform(video::ETS_VIEW, oldViewMat);
driver->setTransform(video::ETS_PROJECTION, oldProjMat);
driver->setViewPort(oldViewPort);
+
+ // Draw player markers
+ v2s32 s_pos(screensize.X - size - 10, 10);
+ 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};
+ f32 sin_angle = sin(m_angle * core::DEGTORAD);
+ f32 cos_angle = cos(m_angle * core::DEGTORAD);
+ s32 marker_size2 = 0.025 * (float)size;
+ 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;
+ }
+ posf.X = (posf.X + 0.5) * (float)size;
+ posf.Y = (posf.Y + 0.5) * (float)size;
+ 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);
+ }
+}
+
+void Mapper::updateActiveMarkers ()
+{
+ video::IImage *minimap_mask = data->minimap_shape_round ?
+ data->minimap_mask_round : data->minimap_mask_square;
+
+ std::list<Nametag *> *nametags = client->getCamera()->getNametags();
+
+ m_active_markers.clear();
+
+ for (std::list<Nametag *>::const_iterator
+ i = nametags->begin();
+ i != nametags->end(); ++i) {
+ Nametag *nametag = *i;
+ v3s16 pos = floatToInt(nametag->parent_node->getPosition() +
+ intToFloat(client->getCamera()->getOffset(), BS), BS);
+ pos -= data->pos - v3s16(data->map_size / 2,
+ data->scan_height / 2,
+ data->map_size / 2);
+ if (pos.X < 0 || pos.X > data->map_size ||
+ pos.Y < 0 || pos.Y > data->scan_height ||
+ pos.Z < 0 || pos.Z > data->map_size) {
+ continue;
+ }
+ pos.X = ((float)pos.X / data->map_size) * MINIMAP_MAX_SX;
+ pos.Z = ((float)pos.Z / data->map_size) * MINIMAP_MAX_SY;
+ video::SColor mask_col = minimap_mask->getPixel(pos.X, pos.Z);
+ if (!mask_col.getAlpha()) {
+ continue;
+ }
+ m_active_markers.push_back(v2f(((float)pos.X / (float)MINIMAP_MAX_SX) - 0.5,
+ (1.0 - (float)pos.Z / (float)MINIMAP_MAX_SY) - 0.5));
+ }
}
////