diff options
Diffstat (limited to 'src/content_cao.cpp')
-rw-r--r-- | src/content_cao.cpp | 86 |
1 files changed, 45 insertions, 41 deletions
diff --git a/src/content_cao.cpp b/src/content_cao.cpp index ac283da88..7f1293ac3 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -44,6 +44,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "camera.h" // CameraModes #include "wieldmesh.h" #include "log.h" +#include <algorithm> class Settings; struct ToolCapabilities; @@ -705,26 +706,11 @@ scene::ISceneNode* GenericCAO::getSceneNode() return NULL; } -scene::IMeshSceneNode* GenericCAO::getMeshSceneNode() -{ - return m_meshnode; -} - scene::IAnimatedMeshSceneNode* GenericCAO::getAnimatedMeshSceneNode() { return m_animated_meshnode; } -WieldMeshSceneNode* GenericCAO::getWieldMeshSceneNode() -{ - return m_wield_meshnode; -} - -scene::IBillboardSceneNode* GenericCAO::getSpriteSceneNode() -{ - return m_spritenode; -} - void GenericCAO::setChildrenVisible(bool toset) { for (std::vector<u16>::size_type i = 0; i < m_children.size(); i++) { @@ -849,6 +835,11 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr, video::S3DVertex( dx, dy, 0, 0,0,0, c, 0,0), video::S3DVertex(-dx, dy, 0, 0,0,0, c, 1,0), }; + if (m_is_player) { + // Move minimal Y position to 0 (feet position) + for (size_t i = 0; i < 4; i++) + vertices[i].Pos.Y += dy; + } u16 indices[] = {0,1,2,2,3,0}; buf->append(vertices, 4, indices, 6); // Set material @@ -868,6 +859,11 @@ void GenericCAO::addToScene(scene::ISceneManager *smgr, video::S3DVertex(-dx, dy, 0, 0,0,0, c, 0,0), video::S3DVertex( dx, dy, 0, 0,0,0, c, 1,0), }; + if (m_is_player) { + // Move minimal Y position to 0 (feet position) + for (size_t i = 0; i < 4; i++) + vertices[i].Pos.Y += dy; + } u16 indices[] = {0,1,2,2,3,0}; buf->append(vertices, 4, indices, 6); // Set material @@ -1041,12 +1037,9 @@ void GenericCAO::updateNodePos() void GenericCAO::step(float dtime, ClientEnvironment *env) { // Handel model of local player instantly to prevent lags - if(m_is_local_player) - { + if (m_is_local_player) { LocalPlayer *player = m_env->getLocalPlayer(); - - if (m_is_visible) - { + if (m_is_visible) { int old_anim = player->last_animation; float old_anim_speed = player->last_animation_speed; m_position = player->getPosition() + v3f(0,BS,0); @@ -1054,7 +1047,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) m_acceleration = v3f(0,0,0); pos_translator.vect_show = m_position; m_yaw = player->getYaw(); - PlayerControl controls = player->getPlayerControl(); + const PlayerControl &controls = player->getPlayerControl(); bool walking = false; if (controls.up || controls.down || controls.left || controls.right || @@ -1075,11 +1068,10 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) m_client->checkLocalPrivilege("fly")))) new_speed *= 1.5; // slowdown speed if sneeking - if(controls.sneak && walking) + if (controls.sneak && walking) new_speed /= 2; - if(walking && (controls.LMB || controls.RMB)) - { + if (walking && (controls.LMB || controls.RMB)) { new_anim = player->local_animations[3]; player->last_animation = WD_ANIM; } else if(walking) { @@ -1092,8 +1084,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) // Apply animations if input detected and not attached // or set idle animation - if ((new_anim.X + new_anim.Y) > 0 && !player->isAttached) - { + if ((new_anim.X + new_anim.Y) > 0 && !player->isAttached) { allow_update = true; m_animation_range = new_anim; m_animation_speed = new_speed; @@ -1101,8 +1092,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) } else { player->last_animation = NO_ANIM; - if (old_anim != NO_ANIM) - { + if (old_anim != NO_ANIM) { m_animation_range = player->local_animations[0]; updateAnimation(); } @@ -1204,16 +1194,17 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) float moved = lastpos.getDistanceFrom(pos_translator.vect_show); m_step_distance_counter += moved; - if(m_step_distance_counter > 1.5*BS) - { - m_step_distance_counter = 0; - if(!m_is_local_player && m_prop.makes_footstep_sound) - { + if (m_step_distance_counter > 1.5f * BS) { + m_step_distance_counter = 0.0f; + if (!m_is_local_player && m_prop.makes_footstep_sound) { INodeDefManager *ndef = m_client->ndef(); - v3s16 p = floatToInt(getPosition() + v3f(0, - (m_prop.collisionbox.MinEdge.Y-0.5)*BS, 0), BS); + v3s16 p = floatToInt(getPosition() + + v3f(0.0f, (m_prop.collisionbox.MinEdge.Y - 0.5f) * BS, 0.0f), BS); MapNode n = m_env->getMap().getNodeNoEx(p); SimpleSoundSpec spec = ndef->get(n).sound_footstep; + // Reduce footstep gain, as non-local-player footsteps are + // somehow louder. + spec.gain *= 0.6f; m_client->sound()->playSoundAt(spec, false, getPosition()); } } @@ -1313,7 +1304,7 @@ void GenericCAO::updateTexturePos() } } -void GenericCAO::updateTextures(const std::string mod) +void GenericCAO::updateTextures(std::string mod) { ITextureSource *tsrc = m_client->tsrc(); @@ -1374,6 +1365,13 @@ void GenericCAO::updateTextures(const std::string mod) material.setFlag(video::EMF_LIGHTING, false); material.setFlag(video::EMF_BILINEAR_FILTER, false); + // don't filter low-res textures, makes them look blurry + // player models have a res of 64 + const core::dimension2d<u32> &size = texture->getOriginalSize(); + const u32 res = std::min(size.Height, size.Width); + use_trilinear_filter &= res > 64; + use_bilinear_filter &= res > 64; + m_animated_meshnode->getMaterial(i) .setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter); m_animated_meshnode->getMaterial(i) @@ -1589,6 +1587,10 @@ void GenericCAO::processMessage(const std::string &data) m_initial_tx_basepos_set = true; m_tx_basepos = m_prop.initial_sprite_basepos; } + if (m_is_local_player) { + LocalPlayer *player = m_env->getLocalPlayer(); + player->makes_footstep_sound = m_prop.makes_footstep_sound; + } if ((m_is_player && !m_is_local_player) && m_prop.nametag == "") m_prop.nametag = m_name; @@ -1751,7 +1753,7 @@ void GenericCAO::processMessage(const std::string &data) m_smgr, m_env, m_position, m_prop.visual_size * BS); m_env->addSimpleObject(simple); - } else { + } else if (m_reset_textures_timer < 0) { // TODO: Execute defined fast response // Flashing shall suffice as there is no definition m_reset_textures_timer = 0.05; @@ -1822,10 +1824,12 @@ bool GenericCAO::directReportPunch(v3f dir, const ItemStack *punchitem, } // TODO: Execute defined fast response // Flashing shall suffice as there is no definition - m_reset_textures_timer = 0.05; - if(result.damage >= 2) - m_reset_textures_timer += 0.05 * result.damage; - updateTextures(m_current_texture_modifier + "^[brighten"); + if (m_reset_textures_timer < 0) { + m_reset_textures_timer = 0.05; + if (result.damage >= 2) + m_reset_textures_timer += 0.05 * result.damage; + updateTextures(m_current_texture_modifier + "^[brighten"); + } } return false; |