Skip to content

Commit c441baa

Browse files
committedNov 12, 2020
Fix overloaded virtual warnings with get/setAttachment()
1 parent 8eb2cba commit c441baa

File tree

2 files changed

+29
-32
lines changed

2 files changed

+29
-32
lines changed
 

Diff for: ‎src/client/content_cao.cpp

+25-24
Original file line numberDiff line numberDiff line change
@@ -460,18 +460,20 @@ void GenericCAO::setChildrenVisible(bool toset)
460460
GenericCAO *obj = m_env->getGenericCAO(cao_id);
461461
if (obj) {
462462
// Check if the entity is forced to appear in first person.
463-
obj->setVisible(obj->isForcedVisible() ? true : toset);
463+
obj->setVisible(obj->m_force_visible ? true : toset);
464464
}
465465
}
466466
}
467467

468-
void GenericCAO::setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation)
468+
void GenericCAO::setAttachment(int parent_id, const std::string &bone,
469+
v3f position, v3f rotation, bool force_visible)
469470
{
470471
int old_parent = m_attachment_parent_id;
471472
m_attachment_parent_id = parent_id;
472473
m_attachment_bone = bone;
473474
m_attachment_position = position;
474475
m_attachment_rotation = rotation;
476+
m_force_visible = force_visible;
475477

476478
ClientActiveObject *parent = m_env->getActiveObject(parent_id);
477479

@@ -482,15 +484,30 @@ void GenericCAO::setAttachment(int parent_id, const std::string &bone, v3f posit
482484
parent->addAttachmentChild(m_id);
483485
}
484486
updateAttachments();
487+
488+
// Forcibly show attachments if required by set_attach
489+
if (m_force_visible) {
490+
m_is_visible = true;
491+
} else if (!m_is_local_player) {
492+
// Objects attached to the local player should be hidden in first person
493+
m_is_visible = !m_attached_to_local ||
494+
m_client->getCamera()->getCameraMode() != CAMERA_MODE_FIRST;
495+
m_force_visible = false;
496+
} else {
497+
// Local players need to have this set,
498+
// otherwise first person attachments fail.
499+
m_is_visible = true;
500+
}
485501
}
486502

487503
void GenericCAO::getAttachment(int *parent_id, std::string *bone, v3f *position,
488-
v3f *rotation) const
504+
v3f *rotation, bool *force_visible) const
489505
{
490506
*parent_id = m_attachment_parent_id;
491507
*bone = m_attachment_bone;
492508
*position = m_attachment_position;
493509
*rotation = m_attachment_rotation;
510+
*force_visible = m_force_visible;
494511
}
495512

496513
void GenericCAO::clearChildAttachments()
@@ -509,9 +526,9 @@ void GenericCAO::clearChildAttachments()
509526
void GenericCAO::clearParentAttachment()
510527
{
511528
if (m_attachment_parent_id)
512-
setAttachment(0, "", m_attachment_position, m_attachment_rotation);
529+
setAttachment(0, "", m_attachment_position, m_attachment_rotation, false);
513530
else
514-
setAttachment(0, "", v3f(), v3f());
531+
setAttachment(0, "", v3f(), v3f(), false);
515532
}
516533

517534
void GenericCAO::addAttachmentChild(int child_id)
@@ -1781,25 +1798,9 @@ void GenericCAO::processMessage(const std::string &data)
17811798
std::string bone = deSerializeString16(is);
17821799
v3f position = readV3F32(is);
17831800
v3f rotation = readV3F32(is);
1784-
m_force_visible = readU8(is); // Returns false for EOF
1785-
1786-
setAttachment(parent_id, bone, position, rotation);
1787-
1788-
// Forcibly show attachments if required by set_attach
1789-
if (m_force_visible)
1790-
m_is_visible = true;
1791-
// localplayer itself can't be attached to localplayer
1792-
else if (!m_is_local_player) {
1793-
// Objects attached to the local player should be hidden in first
1794-
// person provided the forced boolean isn't set.
1795-
m_is_visible = !m_attached_to_local ||
1796-
m_client->getCamera()->getCameraMode() != CAMERA_MODE_FIRST;
1797-
m_force_visible = false;
1798-
} else {
1799-
// Local players need to have this set,
1800-
// otherwise first person attachments fail.
1801-
m_is_visible = true;
1802-
}
1801+
bool force_visible = readU8(is); // Returns false for EOF
1802+
1803+
setAttachment(parent_id, bone, position, rotation, force_visible);
18031804
} else if (cmd == AO_CMD_PUNCHED) {
18041805
u16 result_hp = readU16(is);
18051806

Diff for: ‎src/client/content_cao.h

+4-8
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class GenericCAO : public ClientActiveObject
111111
v3f m_attachment_position;
112112
v3f m_attachment_rotation;
113113
bool m_attached_to_local = false;
114+
bool m_force_visible = false;
114115

115116
int m_anim_frame = 0;
116117
int m_anim_num_frames = 1;
@@ -126,7 +127,6 @@ class GenericCAO : public ClientActiveObject
126127
float m_step_distance_counter = 0.0f;
127128
u8 m_last_light = 255;
128129
bool m_is_visible = false;
129-
bool m_force_visible = false;
130130
s8 m_glow = 0;
131131
// Material
132132
video::E_MATERIAL_TYPE m_material_type;
@@ -218,15 +218,11 @@ class GenericCAO : public ClientActiveObject
218218
m_is_visible = toset;
219219
}
220220

221-
inline bool isForcedVisible() const
222-
{
223-
return m_force_visible;
224-
}
225-
226221
void setChildrenVisible(bool toset);
227-
void setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation);
222+
void setAttachment(int parent_id, const std::string &bone, v3f position,
223+
v3f rotation, bool force_visible);
228224
void getAttachment(int *parent_id, std::string *bone, v3f *position,
229-
v3f *rotation) const;
225+
v3f *rotation, bool *force_visible) const;
230226
void clearChildAttachments();
231227
void clearParentAttachment();
232228
void addAttachmentChild(int child_id);

0 commit comments

Comments
 (0)
Please sign in to comment.