X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fclient%2Fcontent_cao.cpp;h=ec1fd1c2affadd2c718ab8207a1728d9b3889bd4;hb=21df26984da91143c15587f5a03c98d68c3adc4e;hp=d89bb53b31881a7123bd0328268f275dd50557b2;hpb=eabf05758e3ba5f6f4bb1b8d1d1f02179b84e410;p=dragonfireclient.git diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index d89bb53b3..ec1fd1c2a 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -46,6 +46,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include "client/shader.h" +#include "script/scripting_client.h" #include "client/minimap.h" class Settings; @@ -253,7 +254,7 @@ void TestCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) u16 indices[] = {0,1,2,2,3,0}; buf->append(vertices, 4, indices, 6); // Set material - buf->getMaterial().setFlag(video::EMF_LIGHTING, false); + buf->getMaterial().setFlag(video::EMF_LIGHTING, true); // false buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false); buf->getMaterial().setTexture(0, tsrc->getTextureForMesh("rat.png")); buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false); @@ -489,11 +490,14 @@ void GenericCAO::setAttachment(int parent_id, const std::string &bone, ClientActiveObject *parent = m_env->getActiveObject(parent_id); if (parent_id != old_parent) { + if (old_parent) + m_waiting_for_reattach = 10; if (auto *o = m_env->getActiveObject(old_parent)) o->removeAttachmentChild(m_id); if (parent) parent->addAttachmentChild(m_id); } + updateAttachments(); // Forcibly show attachments if required by set_attach @@ -502,7 +506,7 @@ void GenericCAO::setAttachment(int parent_id, const std::string &bone, } 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; + m_client->getCamera()->getCameraMode() != CAMERA_MODE_FIRST || g_settings->getBool("freecam"); m_force_visible = false; } else { // Local players need to have this set, @@ -854,6 +858,14 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) } } } + + if (m_client->modsLoaded() && m_client->getScript()->on_object_add(m_id)) { + removeFromScene(false); + return; + } + + if (m_client->modsLoaded()) + m_client->getScript()->on_object_properties_change(m_id); } void GenericCAO::updateLight(u32 day_night_ratio) @@ -887,6 +899,9 @@ void GenericCAO::updateLight(u32 day_night_ratio) if (!m_enable_shaders) final_color_blend(&light, light_at_pos, day_night_ratio); + if (g_settings->getBool("fullbright")) + light = video::SColor(0xFFFFFFFF); + if (light != m_last_light) { m_last_light = light; setNodeLight(light); @@ -967,8 +982,8 @@ void GenericCAO::updateMarker() void GenericCAO::updateNametag() { - if (m_is_local_player) // No nametag for local player - return; + //if (m_is_local_player && ! g_settings->getBool("freecam")) // No nametag for local player + //return; if (m_prop.nametag.empty() || m_prop.nametag_color.getAlpha() == 0) { // Delete nametag @@ -989,13 +1004,14 @@ void GenericCAO::updateNametag() // Add nametag m_nametag = m_client->getCamera()->addNametag(node, m_prop.nametag, m_prop.nametag_color, - m_prop.nametag_bgcolor, pos); + m_prop.nametag_bgcolor, pos, nametag_images); } else { // Update nametag m_nametag->text = m_prop.nametag; m_nametag->textcolor = m_prop.nametag_color; m_nametag->bgcolor = m_prop.nametag_bgcolor; m_nametag->pos = pos; + m_nametag->setImages(nametag_images); } } @@ -1023,10 +1039,12 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) // Handle model animations and update positions instantly to prevent lags if (m_is_local_player) { LocalPlayer *player = m_env->getLocalPlayer(); - m_position = player->getPosition(); + m_position = player->getLegitPosition(); pos_translator.val_current = m_position; - m_rotation.Y = wrapDegrees_0_360(player->getYaw()); - rot_translator.val_current = m_rotation; + if (! g_settings->getBool("freecam")) { + m_rotation.Y = wrapDegrees_0_360(player->getYaw()); + rot_translator.val_current = m_rotation; + } if (m_is_visible) { int old_anim = player->last_animation; @@ -1037,7 +1055,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) f32 new_speed = player->local_animation_speed; bool walking = false; - if (controls.movement_speed > 0.001f) { + if (controls.movement_speed > 0.001f && ! g_settings->getBool("freecam")) { new_speed *= controls.movement_speed; walking = true; } @@ -1046,15 +1064,15 @@ void GenericCAO::step(float dtime, ClientEnvironment *env) 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 sneaking - if (controls.sneak && walking) + if (controls.sneak && walking && ! g_settings->getBool("no_slow")) new_speed /= 2; if (walking && (controls.dig || controls.place)) { @@ -1665,6 +1683,57 @@ bool GenericCAO::visualExpiryRequired(const ObjectProperties &new_) const (uses_legacy_texture && old.textures != new_.textures); } +void GenericCAO::setProperties(ObjectProperties newprops) +{ + // Check what exactly changed + bool expire_visuals = visualExpiryRequired(newprops); + bool textures_changed = m_prop.textures != newprops.textures; + + // Apply changes + m_prop = std::move(newprops); + + m_selection_box = m_prop.selectionbox; + m_selection_box.MinEdge *= BS; + m_selection_box.MaxEdge *= BS; + + m_tx_size.X = 1.0f / m_prop.spritediv.X; + m_tx_size.Y = 1.0f / m_prop.spritediv.Y; + + if(!m_initial_tx_basepos_set){ + 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; + aabb3f collision_box = m_prop.collisionbox; + collision_box.MinEdge *= BS; + collision_box.MaxEdge *= BS; + player->setCollisionbox(collision_box); + player->setEyeHeight(m_prop.eye_height); + player->setZoomFOV(m_prop.zoom_fov); + } + + 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(); + } else { + infostream << "GenericCAO: properties updated but expiring visuals" + << " not necessary" << std::endl; + if (textures_changed) { + // don't update while punch texture modifier is active + if (m_reset_textures_timer < 0) + updateTextures(m_current_texture_modifier); + } + updateNametag(); + updateMarker(); + } +} + void GenericCAO::processMessage(const std::string &data) { //infostream<<"GenericCAO: Got message"<modsLoaded()) + m_client->getScript()->on_object_properties_change(m_id); - m_selection_box = m_prop.selectionbox; - m_selection_box.MinEdge *= BS; - m_selection_box.MaxEdge *= BS; - - m_tx_size.X = 1.0f / m_prop.spritediv.X; - m_tx_size.Y = 1.0f / m_prop.spritediv.Y; - - if(!m_initial_tx_basepos_set){ - 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; - aabb3f collision_box = m_prop.collisionbox; - collision_box.MinEdge *= BS; - collision_box.MaxEdge *= BS; - player->setCollisionbox(collision_box); - player->setEyeHeight(m_prop.eye_height); - player->setZoomFOV(m_prop.zoom_fov); - } - - 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(); - } else { - infostream << "GenericCAO: properties updated but expiring visuals" - << " not necessary" << std::endl; - if (textures_changed) { - // don't update while punch texture modifier is active - if (m_reset_textures_timer < 0) - 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. // We might however get here if the server notices the object being detached before the client. @@ -1788,6 +1815,11 @@ void GenericCAO::processMessage(const std::string &data) if(m_is_local_player) { + Client *client = m_env->getGameDef(); + + if (client->modsLoaded() && client->getScript()->on_recieve_physics_override(override_speed, override_jump, override_gravity, sneak, sneak_glitch, new_move)) + return; + LocalPlayer *player = m_env->getLocalPlayer(); player->physics_override_speed = override_speed; player->physics_override_jump = override_jump; @@ -1886,6 +1918,9 @@ void GenericCAO::processMessage(const std::string &data) // Same as 'ObjectRef::l_remove' if (!m_is_player) clearChildAttachments(); + } else { + if (m_client->modsLoaded()) + m_client->getScript()->on_object_hp_change(m_id); } } else if (cmd == AO_CMD_UPDATE_ARMOR_GROUPS) { m_armor_groups.clear(); @@ -1972,7 +2007,7 @@ void GenericCAO::updateMeshCulling() if (!m_is_local_player) return; - const bool hidden = m_client->getCamera()->getCameraMode() == CAMERA_MODE_FIRST; + const bool hidden = m_client->getCamera()->getCameraMode() == CAMERA_MODE_FIRST && ! g_settings->getBool("freecam"); scene::ISceneNode *node = getSceneNode();