Skip to content

Commit

Permalink
Minimap: show player markers
Browse files Browse the repository at this point in the history
  • Loading branch information
RealBadAngel authored and est31 committed Feb 19, 2016
1 parent 5dbaa68 commit 5f4ed94
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ class Camera

void removeNametag(Nametag *nametag);

std::list<Nametag *> *getNametags()
{ return &m_nametags; }

void drawNametags();

private:
Expand Down
69 changes: 69 additions & 0 deletions src/minimap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ 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();
Expand Down Expand Up @@ -250,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();
Expand All @@ -274,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;
Expand Down Expand Up @@ -468,6 +472,7 @@ void Mapper::drawMinimap()
if (!minimap_texture)
return;

updateActiveMarkers();
v2u32 screensize = porting::getWindowSize();
const u32 size = 0.25 * screensize.Y;

Expand Down Expand Up @@ -527,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));
}
}

////
Expand Down
6 changes: 6 additions & 0 deletions src/minimap.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <map>
#include <string>
#include <vector>
#include "camera.h"

#define MINIMAP_MAX_SX 512
#define MINIMAP_MAX_SY 512
Expand Down Expand Up @@ -82,6 +83,7 @@ struct MinimapData {
video::ITexture *minimap_overlay_round;
video::ITexture *minimap_overlay_square;
video::ITexture *player_marker;
video::ITexture *object_marker_red;
};

struct QueuedMinimapUpdate {
Expand Down Expand Up @@ -138,9 +140,12 @@ class Mapper {
video::IImage *heightmap_image);

scene::SMeshBuffer *getMinimapMeshBuffer();

void updateActiveMarkers();
void drawMinimap();

video::IVideoDriver *driver;
Client* client;
MinimapData *data;

private:
Expand All @@ -153,6 +158,7 @@ class Mapper {
u16 m_surface_mode_scan_height;
f32 m_angle;
Mutex m_mutex;
std::list<v2f> m_active_markers;
};

#endif
Binary file added textures/base/pack/object_marker_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

2 comments on commit 5f4ed94

@BlockMen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be disabled somehow?

@est31
Copy link
Contributor

@est31 est31 commented on 5f4ed94 Feb 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can disable whole minimap from server side, this is possible right now. If you want to disable player markers from client side, use a transparent texture.

I'm preparing a patch that allows fine grained control of the minimap from server side, so that you can allow general minimap use, but disallow use of e.g. showing players.

Please sign in to comment.