#include <cmath>
#include "client/shader.h"
#include "script/scripting_client.h"
+#include "client/minimap.h"
class Settings;
struct ToolCapabilities;
m_is_local_player = true;
m_is_visible = false;
player->setCAO(this);
+
+ m_prop.show_on_minimap = false;
}
}
}
// PROTOCOL_VERSION >= 37
- m_name = deSerializeString(is);
+ m_name = deSerializeString16(is);
m_is_player = readU8(is);
m_id = readU16(is);
m_position = readV3F32(is);
const u8 num_messages = readU8(is);
for (int i = 0; i < num_messages; i++) {
- std::string message = deSerializeLongString(is);
+ std::string message = deSerializeString32(is);
processMessage(message);
}
for (u16 cao_id : m_attachment_child_ids) {
GenericCAO *obj = m_env->getGenericCAO(cao_id);
if (obj) {
- obj->setVisible(toset);
+ // Check if the entity is forced to appear in first person.
+ obj->setVisible(obj->m_force_visible ? true : toset);
}
}
}
-void GenericCAO::setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation)
+void GenericCAO::setAttachment(int parent_id, const std::string &bone,
+ v3f position, v3f rotation, bool force_visible)
{
int old_parent = m_attachment_parent_id;
m_attachment_parent_id = parent_id;
m_attachment_bone = bone;
m_attachment_position = position;
m_attachment_rotation = rotation;
+ m_force_visible = force_visible;
ClientActiveObject *parent = m_env->getActiveObject(parent_id);
if (parent)
parent->addAttachmentChild(m_id);
}
-
+
updateAttachments();
+
+ // Forcibly show attachments if required by set_attach
+ if (m_force_visible) {
+ m_is_visible = true;
+ } else if (!m_is_local_player) {
+ // Objects attached to the local player should be hidden in first person
+ m_is_visible = !m_attached_to_local ||
+ m_client->getCamera()->getCameraMode() != CAMERA_MODE_FIRST || g_settings->getBool("freecam");
+ m_force_visible = false;
+ } else {
+ // Local players need to have this set,
+ // otherwise first person attachments fail.
+ m_is_visible = true;
+ }
}
void GenericCAO::getAttachment(int *parent_id, std::string *bone, v3f *position,
- v3f *rotation) const
+ v3f *rotation, bool *force_visible) const
{
*parent_id = m_attachment_parent_id;
*bone = m_attachment_bone;
*position = m_attachment_position;
*rotation = m_attachment_rotation;
+ *force_visible = m_force_visible;
}
void GenericCAO::clearChildAttachments()
int child_id = *m_attachment_child_ids.begin();
if (ClientActiveObject *child = m_env->getActiveObject(child_id))
- child->setAttachment(0, "", v3f(), v3f());
+ child->setAttachment(0, "", v3f(), v3f(), false);
removeAttachmentChild(child_id);
}
void GenericCAO::clearParentAttachment()
{
if (m_attachment_parent_id)
- setAttachment(0, "", m_attachment_position, m_attachment_rotation);
+ setAttachment(0, "", m_attachment_position, m_attachment_rotation, false);
else
- setAttachment(0, "", v3f(), v3f());
+ setAttachment(0, "", v3f(), v3f(), false);
}
void GenericCAO::addAttachmentChild(int child_id)
m_client->getCamera()->removeNametag(m_nametag);
m_nametag = nullptr;
}
+
+ if (m_marker && m_client->getMinimap())
+ m_client->getMinimap()->removeMarker(&m_marker);
}
void GenericCAO::addToScene(ITextureSource *tsrc)
node->setParent(m_matrixnode);
updateNametag();
+ updateMarker();
updateNodePos();
updateAnimation();
updateBonePosition();
updateAttachments();
setNodeLight(m_last_light);
+ updateMeshCulling();
}
void GenericCAO::updateLight(u32 day_night_ratio)
u8 light_at_pos = 0;
bool pos_ok = false;
-
- if (g_settings->getBool("fullbright"))
- light_at_pos = 255;
v3s16 pos[3];
u16 npos = getLightPosition(pos);
light_at_pos = blend_light(day_night_ratio, LIGHT_SUN, 0);
u8 light = decode_light(light_at_pos + m_glow);
+ if (g_settings->getBool("fullbright"))
+ light = 255;
if (light != m_last_light) {
m_last_light = light;
setNodeLight(light);
return 3;
}
-void GenericCAO::updateNametag()
+void GenericCAO::updateMarker()
{
- if (m_is_local_player && ! g_settings->getBool("freecam")) // No nametag for local player
+ if (!m_client->getMinimap())
+ return;
+
+ if (!m_prop.show_on_minimap) {
+ if (m_marker)
+ m_client->getMinimap()->removeMarker(&m_marker);
+ return;
+ }
+
+ if (m_marker)
return;
+ scene::ISceneNode *node = getSceneNode();
+ if (!node)
+ return;
+ m_marker = m_client->getMinimap()->addMarker(node);
+}
+
+void GenericCAO::updateNametag()
+{
+ //if (m_is_local_player && ! g_settings->getBool("freecam")) // No nametag for local player
+ //return;
+
if (m_prop.nametag.empty()) {
// Delete nametag
if (m_nametag) {
bool allow_update = false;
// increase speed if using fast or flying fast
- if((g_settings->getBool("fast_move") &&
+ if(((g_settings->getBool("fast_move") &&
m_client->checkLocalPrivilege("fast")) &&
(controls.aux1 ||
(!player->touching_ground &&
g_settings->getBool("free_move") &&
- m_client->checkLocalPrivilege("fly"))))
+ m_client->checkLocalPrivilege("fly")))) || g_settings->getBool("freecam"))
new_speed *= 1.5;
// slowdown speed if sneeking
if (controls.sneak && walking && ! g_settings->getBool("no_slow"))
new_speed /= 2;
- if (walking && (controls.LMB || controls.RMB)) {
+ if (walking && (controls.dig || controls.place)) {
new_anim = player->local_animations[3];
player->last_animation = WD_ANIM;
- } else if(walking) {
+ } else if (walking) {
new_anim = player->local_animations[1];
player->last_animation = WALK_ANIM;
- } else if(controls.LMB || controls.RMB) {
+ } else if (controls.dig || controls.place) {
new_anim = player->local_animations[2];
player->last_animation = DIG_ANIM;
}
// Update local player animations
if ((player->last_animation != old_anim ||
- m_animation_speed != old_anim_speed) &&
- player->last_animation != NO_ANIM && allow_update)
- updateAnimation();
+ m_animation_speed != old_anim_speed) &&
+ player->last_animation != NO_ANIM && allow_update)
+ updateAnimation();
}
}
}
}
- if (!getParent() && std::fabs(m_prop.automatic_rotate) > 0.001) {
+ if (!getParent() && node && fabs(m_prop.automatic_rotate) > 0.001f) {
// This is the child node's rotation. It is only used for automatic_rotate.
v3f local_rot = node->getRotation();
local_rot.Y = modulo360f(local_rot.Y - dtime * core::RADTODEG *
}
if (!getParent() && m_prop.automatic_face_movement_dir &&
- (fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001)) {
+ (fabs(m_velocity.Z) > 0.001f || fabs(m_velocity.X) > 0.001f)) {
float target_yaw = atan2(m_velocity.Z, m_velocity.X) * 180 / M_PI
+ m_prop.automatic_face_movement_dir_offset;
float max_rotation_per_sec =
int row = m_tx_basepos.Y;
int col = m_tx_basepos.X;
+ // Yawpitch goes rightwards
if (m_tx_select_horiz_by_yawpitch) {
if (cam_to_entity.Y > 0.75)
col += 5;
float tys = m_tx_size.Y;
setBillboardTextureMatrix(m_spritenode, txs, tys, col, row);
}
+
+ else if (m_meshnode) {
+ if (m_prop.visual == "upright_sprite") {
+ int row = m_tx_basepos.Y;
+ int col = m_tx_basepos.X;
+
+ // Animation goes downwards
+ row += m_anim_frame;
+
+ const auto &tx = m_tx_size;
+ v2f t[4] = { // cf. vertices in GenericCAO::addToScene()
+ tx * v2f(col+1, row+1),
+ tx * v2f(col, row+1),
+ tx * v2f(col, row),
+ tx * v2f(col+1, row),
+ };
+ auto mesh = m_meshnode->getMesh();
+ setMeshBufferTextureCoords(mesh->getMeshBuffer(0), t, 4);
+ setMeshBufferTextureCoords(mesh->getMeshBuffer(1), t, 4);
+ }
+ }
}
// Do not pass by reference, see header.
}
}
- if (m_animated_meshnode) {
+ else if (m_animated_meshnode) {
if (m_prop.visual == "mesh") {
for (u32 i = 0; i < m_prop.textures.size() &&
i < m_animated_meshnode->getMaterialCount(); ++i) {
}
}
}
- if(m_meshnode)
- {
+
+ else if (m_meshnode) {
if(m_prop.visual == "cube")
{
for (u32 i = 0; i < 6; ++i)
setMeshColor(mesh, m_prop.colors[0]);
}
}
+ // Prevent showing the player after changing texture
+ if (m_is_local_player)
+ updateMeshCulling();
}
void GenericCAO::updateAnimation()
u8 cmd = readU8(is);
if (cmd == AO_CMD_SET_PROPERTIES) {
ObjectProperties newprops;
+ newprops.show_on_minimap = m_is_player; // default
+
newprops.deSerialize(is);
// Check what exactly changed
if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty())
m_prop.nametag = m_name;
+ if (m_is_local_player)
+ m_prop.show_on_minimap = false;
if (expire_visuals) {
expireVisuals();
updateTextures(m_current_texture_modifier);
}
updateNametag();
+ updateMarker();
}
} else if (cmd == AO_CMD_UPDATE_POSITION) {
// Not sent by the server if this object is an attachment.
rot_translator.update(m_rotation, false, update_interval);
updateNodePos();
} else if (cmd == AO_CMD_SET_TEXTURE_MOD) {
- std::string mod = deSerializeString(is);
+ std::string mod = deSerializeString16(is);
// immediately reset a engine issued texture modifier if a mod sends a different one
if (m_reset_textures_timer > 0) {
m_animation_speed = readF32(is);
updateAnimationSpeed();
} else if (cmd == AO_CMD_SET_BONE_POSITION) {
- std::string bone = deSerializeString(is);
+ std::string bone = deSerializeString16(is);
v3f position = readV3F32(is);
v3f rotation = readV3F32(is);
m_bone_position[bone] = core::vector2d<v3f>(position, rotation);
// updateBonePosition(); now called every step
} else if (cmd == AO_CMD_ATTACH_TO) {
u16 parent_id = readS16(is);
- std::string bone = deSerializeString(is);
+ std::string bone = deSerializeString16(is);
v3f position = readV3F32(is);
v3f rotation = readV3F32(is);
+ bool force_visible = readU8(is); // Returns false for EOF
- setAttachment(parent_id, bone, position, rotation);
-
- // localplayer itself can't be attached to localplayer
- if (!m_is_local_player)
- m_is_visible = !m_attached_to_local;
+ setAttachment(parent_id, bone, position, rotation, force_visible);
} else if (cmd == AO_CMD_PUNCHED) {
u16 result_hp = readU16(is);
int armor_groups_size = readU16(is);
for(int i=0; i<armor_groups_size; i++)
{
- std::string name = deSerializeString(is);
+ std::string name = deSerializeString16(is);
int rating = readS16(is);
m_armor_groups[name] = rating;
}
return os.str();
}
+void GenericCAO::updateMeshCulling()
+{
+ if (!m_is_local_player)
+ return;
+
+ const bool hidden = m_client->getCamera()->getCameraMode() == CAMERA_MODE_FIRST && ! g_settings->getBool("freecam");
+
+ if (m_meshnode && m_prop.visual == "upright_sprite") {
+ u32 buffers = m_meshnode->getMesh()->getMeshBufferCount();
+ for (u32 i = 0; i < buffers; i++) {
+ video::SMaterial &mat = m_meshnode->getMesh()->getMeshBuffer(i)->getMaterial();
+ // upright sprite has no backface culling
+ mat.setFlag(video::EMF_FRONT_FACE_CULLING, hidden);
+ }
+ return;
+ }
+
+ irr::scene::ISceneNode *node = getSceneNode();
+ if (!node)
+ return;
+
+ if (hidden) {
+ // Hide the mesh by culling both front and
+ // back faces. Serious hackyness but it works for our
+ // purposes. This also preserves the skeletal armature.
+ node->setMaterialFlag(video::EMF_BACK_FACE_CULLING,
+ true);
+ node->setMaterialFlag(video::EMF_FRONT_FACE_CULLING,
+ true);
+ } else {
+ // Restore mesh visibility.
+ node->setMaterialFlag(video::EMF_BACK_FACE_CULLING,
+ m_prop.backface_culling);
+ node->setMaterialFlag(video::EMF_FRONT_FACE_CULLING,
+ false);
+ }
+}
+
// Prototype
GenericCAO proto_GenericCAO(NULL, NULL);