Skip to content

Commit 660115c

Browse files
authoredOct 19, 2020
Decouple entity minimap markers from nametags replacing with show_on_minimap property (#10443)
1 parent b826e39 commit 660115c

11 files changed

+86
-12
lines changed
 

‎doc/lua_api.txt

+4
Original file line numberDiff line numberDiff line change
@@ -6880,6 +6880,10 @@ Player properties need to be saved manually.
68806880

68816881
shaded = true,
68826882
-- Setting this to 'false' disables diffuse lighting of entity
6883+
6884+
show_on_minimap = false,
6885+
-- Defaults to true for players, false for other entities.
6886+
-- If set to true the entity will show as a marker on the minimap.
68836887
}
68846888

68856889
Entity definition

‎src/client/camera.h

-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ class Camera
169169

170170
void removeNametag(Nametag *nametag);
171171

172-
const std::list<Nametag *> &getNametags() { return m_nametags; }
173-
174172
void drawNametags();
175173

176174
inline void addArmInertia(f32 player_yaw);

‎src/client/client.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ Client::~Client()
326326
}
327327

328328
delete m_minimap;
329+
m_minimap = nullptr;
330+
329331
delete m_media_downloader;
330332
}
331333

‎src/client/content_cao.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
4747
#include <algorithm>
4848
#include <cmath>
4949
#include "client/shader.h"
50+
#include "client/minimap.h"
5051

5152
class Settings;
5253
struct ToolCapabilities;
@@ -566,6 +567,9 @@ void GenericCAO::removeFromScene(bool permanent)
566567
m_client->getCamera()->removeNametag(m_nametag);
567568
m_nametag = nullptr;
568569
}
570+
571+
if (m_marker && m_client->getMinimap())
572+
m_client->getMinimap()->removeMarker(&m_marker);
569573
}
570574

571575
void GenericCAO::addToScene(ITextureSource *tsrc)
@@ -794,6 +798,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
794798
node->setParent(m_matrixnode);
795799

796800
updateNametag();
801+
updateMarker();
797802
updateNodePos();
798803
updateAnimation();
799804
updateBonePosition();
@@ -885,6 +890,23 @@ u16 GenericCAO::getLightPosition(v3s16 *pos)
885890
return 3;
886891
}
887892

893+
void GenericCAO::updateMarker()
894+
{
895+
if (!m_prop.show_on_minimap) {
896+
if (m_marker)
897+
m_client->getMinimap()->removeMarker(&m_marker);
898+
return;
899+
}
900+
901+
if (m_marker)
902+
return;
903+
904+
scene::ISceneNode *node = getSceneNode();
905+
if (!node)
906+
return;
907+
m_marker = m_client->getMinimap()->addMarker(node);
908+
}
909+
888910
void GenericCAO::updateNametag()
889911
{
890912
if (m_is_local_player) // No nametag for local player
@@ -1576,6 +1598,8 @@ void GenericCAO::processMessage(const std::string &data)
15761598
u8 cmd = readU8(is);
15771599
if (cmd == AO_CMD_SET_PROPERTIES) {
15781600
ObjectProperties newprops;
1601+
newprops.show_on_minimap = m_is_player; // default
1602+
15791603
newprops.deSerialize(is);
15801604

15811605
// Check what exactly changed
@@ -1609,6 +1633,8 @@ void GenericCAO::processMessage(const std::string &data)
16091633

16101634
if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty())
16111635
m_prop.nametag = m_name;
1636+
if (m_is_local_player)
1637+
m_prop.show_on_minimap = false;
16121638

16131639
if (expire_visuals) {
16141640
expireVisuals();
@@ -1621,6 +1647,7 @@ void GenericCAO::processMessage(const std::string &data)
16211647
updateTextures(m_current_texture_modifier);
16221648
}
16231649
updateNametag();
1650+
updateMarker();
16241651
}
16251652
} else if (cmd == AO_CMD_UPDATE_POSITION) {
16261653
// Not sent by the server if this object is an attachment.

‎src/client/content_cao.h

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3030
class Camera;
3131
class Client;
3232
struct Nametag;
33+
struct MinimapMarker;
3334

3435
/*
3536
SmoothTranslator
@@ -84,6 +85,7 @@ class GenericCAO : public ClientActiveObject
8485
scene::IBillboardSceneNode *m_spritenode = nullptr;
8586
scene::IDummyTransformationSceneNode *m_matrixnode = nullptr;
8687
Nametag *m_nametag = nullptr;
88+
MinimapMarker *m_marker = nullptr;
8789
v3f m_position = v3f(0.0f, 10.0f * BS, 0);
8890
v3f m_velocity;
8991
v3f m_acceleration;
@@ -254,6 +256,8 @@ class GenericCAO : public ClientActiveObject
254256

255257
void updateNametag();
256258

259+
void updateMarker();
260+
257261
void updateNodePos();
258262

259263
void step(float dtime, ClientEnvironment *env);

‎src/client/minimap.cpp

+26-9
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ Minimap::~Minimap()
252252
driver->removeTexture(data->minimap_overlay_square);
253253
driver->removeTexture(data->object_marker_red);
254254

255+
for (MinimapMarker *m : m_markers)
256+
delete m;
257+
m_markers.clear();
258+
255259
delete data;
256260
delete m_minimap_update_thread;
257261
}
@@ -678,21 +682,34 @@ void Minimap::drawMinimap(core::rect<s32> rect) {
678682
}
679683
}
680684

685+
MinimapMarker* Minimap::addMarker(scene::ISceneNode *parent_node)
686+
{
687+
MinimapMarker *m = new MinimapMarker(parent_node);
688+
m_markers.push_back(m);
689+
return m;
690+
}
691+
692+
void Minimap::removeMarker(MinimapMarker **m)
693+
{
694+
m_markers.remove(*m);
695+
delete *m;
696+
*m = nullptr;
697+
}
698+
681699
void Minimap::updateActiveMarkers()
682700
{
683701
video::IImage *minimap_mask = data->minimap_shape_round ?
684702
data->minimap_mask_round : data->minimap_mask_square;
685703

686-
const std::list<Nametag *> &nametags = client->getCamera()->getNametags();
687-
688704
m_active_markers.clear();
689-
690-
for (Nametag *nametag : nametags) {
691-
v3s16 pos = floatToInt(nametag->parent_node->getAbsolutePosition() +
692-
intToFloat(client->getCamera()->getOffset(), BS), BS);
693-
pos -= data->pos - v3s16(data->mode.map_size / 2,
694-
data->mode.scan_height / 2,
695-
data->mode.map_size / 2);
705+
v3f cam_offset = intToFloat(client->getCamera()->getOffset(), BS);
706+
v3s16 pos_offset = data->pos - v3s16(data->mode.map_size / 2,
707+
data->mode.scan_height / 2,
708+
data->mode.map_size / 2);
709+
710+
for (MinimapMarker *marker : m_markers) {
711+
v3s16 pos = floatToInt(marker->parent_node->getAbsolutePosition() +
712+
cam_offset, BS) - pos_offset;
696713
if (pos.X < 0 || pos.X > data->mode.map_size ||
697714
pos.Y < 0 || pos.Y > data->mode.scan_height ||
698715
pos.Z < 0 || pos.Z > data->mode.map_size) {

‎src/client/minimap.h

+11
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ struct MinimapModeDef {
4848
u16 scale;
4949
};
5050

51+
struct MinimapMarker {
52+
MinimapMarker(scene::ISceneNode *parent_node):
53+
parent_node(parent_node)
54+
{
55+
}
56+
scene::ISceneNode *parent_node;
57+
};
5158
struct MinimapPixel {
5259
//! The topmost node that the minimap displays.
5360
MapNode n;
@@ -142,6 +149,9 @@ class Minimap {
142149

143150
scene::SMeshBuffer *getMinimapMeshBuffer();
144151

152+
MinimapMarker* addMarker(scene::ISceneNode *parent_node);
153+
void removeMarker(MinimapMarker **marker);
154+
145155
void updateActiveMarkers();
146156
void drawMinimap();
147157
void drawMinimap(core::rect<s32> rect);
@@ -162,5 +172,6 @@ class Minimap {
162172
u16 m_surface_mode_scan_height;
163173
f32 m_angle;
164174
std::mutex m_mutex;
175+
std::list<MinimapMarker*> m_markers;
165176
std::list<v2f> m_active_markers;
166177
};

‎src/object_properties.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ std::string ObjectProperties::dump()
7070
os << ", use_texture_alpha=" << use_texture_alpha;
7171
os << ", damage_texture_modifier=" << damage_texture_modifier;
7272
os << ", shaded=" << shaded;
73+
os << ", show_on_minimap=" << show_on_minimap;
7374
return os.str();
7475
}
7576

@@ -118,6 +119,7 @@ void ObjectProperties::serialize(std::ostream &os) const
118119
writeU8(os, use_texture_alpha);
119120
os << serializeString16(damage_texture_modifier);
120121
writeU8(os, shaded);
122+
writeU8(os, show_on_minimap);
121123

122124
// Add stuff only at the bottom.
123125
// Never remove anything, because we don't want new versions of this
@@ -174,7 +176,11 @@ void ObjectProperties::deSerialize(std::istream &is)
174176
damage_texture_modifier = deSerializeString16(is);
175177
u8 tmp = readU8(is);
176178
if (is.eof())
177-
throw SerializationError("");
179+
return;
178180
shaded = tmp;
181+
tmp = readU8(is);
182+
if (is.eof())
183+
return;
184+
show_on_minimap = tmp;
179185
} catch (SerializationError &e) {}
180186
}

‎src/object_properties.h

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct ObjectProperties
6262
float zoom_fov = 0.0f;
6363
bool use_texture_alpha = false;
6464
bool shaded = true;
65+
bool show_on_minimap = false;
6566

6667
ObjectProperties();
6768
std::string dump();

‎src/script/common/c_content.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ void read_object_properties(lua_State *L, int index,
331331
getfloatfield(L, -1, "zoom_fov", prop->zoom_fov);
332332
getboolfield(L, -1, "use_texture_alpha", prop->use_texture_alpha);
333333
getboolfield(L, -1, "shaded", prop->shaded);
334+
getboolfield(L, -1, "show_on_minimap", prop->show_on_minimap);
334335

335336
getstringfield(L, -1, "damage_texture_modifier", prop->damage_texture_modifier);
336337
}
@@ -419,6 +420,8 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
419420
lua_setfield(L, -2, "shaded");
420421
lua_pushlstring(L, prop->damage_texture_modifier.c_str(), prop->damage_texture_modifier.size());
421422
lua_setfield(L, -2, "damage_texture_modifier");
423+
lua_pushboolean(L, prop->show_on_minimap);
424+
lua_setfield(L, -2, "show_on_minimap");
422425
}
423426

424427
/******************************************************************************/

‎src/server/player_sao.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t p
5555
m_prop.backface_culling = false;
5656
m_prop.makes_footstep_sound = true;
5757
m_prop.stepheight = PLAYER_DEFAULT_STEPHEIGHT * BS;
58+
m_prop.show_on_minimap = true;
5859
m_hp = m_prop.hp_max;
5960
m_breath = m_prop.breath_max;
6061
// Disable zoom in survival mode using a value of 0

0 commit comments

Comments
 (0)
Please sign in to comment.