]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/content_cao.cpp
Fix trees growing into any type of node
[dragonfireclient.git] / src / content_cao.cpp
index cbcf66ef75d00798cdfc5c0dc44cce4a0c3ff526..cb14cf39564014ca155a025a2a4186fee265362f 100644 (file)
@@ -30,13 +30,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "clientobject.h"
 #include "content_object.h"
 #include "mesh.h"
-#include "utility.h" // For IntervalLimiter
 #include "itemdef.h"
 #include "tool.h"
 #include "content_cso.h"
 #include "sound.h"
 #include "nodedef.h"
 #include "localplayer.h"
+#include "util/numeric.h" // For IntervalLimiter
+#include "util/serialize.h"
+#include "util/mathconstants.h"
+#include "map.h"
+#include <IMeshManipulator.h>
+
 class Settings;
 struct ToolCapabilities;
 
@@ -793,8 +798,15 @@ class GenericCAO : public ClientActiveObject
                                infostream<<"textures[0]: "<<m_prop.textures[0]<<std::endl;
                                IItemDefManager *idef = m_gamedef->idef();
                                ItemStack item(m_prop.textures[0], 1, 0, "", idef);
-                               scene::IMesh *mesh = item.getDefinition(idef).wield_mesh;
+                               scene::IMesh *item_mesh = item.getDefinition(idef).wield_mesh;
+                               
+                               // Copy mesh to be able to set unique vertex colors
+                               scene::IMeshManipulator *manip =
+                                               irr->getVideoDriver()->getMeshManipulator();
+                               scene::IMesh *mesh = manip->createMeshUniquePrimitives(item_mesh);
+
                                m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
+                               mesh->drop();
                                
                                m_meshnode->setScale(v3f(m_prop.visual_size.X/2,
                                                m_prop.visual_size.Y/2,
@@ -834,15 +846,17 @@ class GenericCAO : public ClientActiveObject
        {
                bool is_visible = (m_hp != 0);
                u8 li = decode_light(light_at_pos);
-               m_last_light = li;
-               video::SColor color(255,li,li,li);
-               if(m_meshnode){
-                       setMeshColor(m_meshnode->getMesh(), color);
-                       m_meshnode->setVisible(is_visible);
-               }
-               if(m_spritenode){
-                       m_spritenode->setColor(color);
-                       m_spritenode->setVisible(is_visible);
+               if(li != m_last_light){
+                       m_last_light = li;
+                       video::SColor color(255,li,li,li);
+                       if(m_meshnode){
+                               setMeshColor(m_meshnode->getMesh(), color);
+                               m_meshnode->setVisible(is_visible);
+                       }
+                       if(m_spritenode){
+                               m_spritenode->setColor(color);
+                               m_spritenode->setVisible(is_visible);
+                       }
                }
        }
 
@@ -879,22 +893,24 @@ class GenericCAO : public ClientActiveObject
                        box.MinEdge *= BS;
                        box.MaxEdge *= BS;
                        collisionMoveResult moveresult;
-                       f32 pos_max_d = BS*0.25; // Distance per iteration
+                       f32 pos_max_d = BS*0.125; // Distance per iteration
+                       f32 stepheight = 0;
                        v3f p_pos = m_position;
                        v3f p_velocity = m_velocity;
+                       v3f p_acceleration = m_acceleration;
                        IGameDef *gamedef = env->getGameDef();
-                       moveresult = collisionMovePrecise(&env->getMap(), gamedef,
-                                       pos_max_d, box, dtime, p_pos, p_velocity);
+                       moveresult = collisionMoveSimple(&env->getMap(), gamedef,
+                                       pos_max_d, box, stepheight, dtime,
+                                       p_pos, p_velocity, p_acceleration);
                        // Apply results
                        m_position = p_pos;
                        m_velocity = p_velocity;
+                       m_acceleration = p_acceleration;
                        
                        bool is_end_position = moveresult.collides;
                        pos_translator.update(m_position, is_end_position, dtime);
                        pos_translator.translate(dtime);
                        updateNodePos();
-
-                       m_velocity += dtime * m_acceleration;
                } else {
                        m_position += dtime * m_velocity + 0.5 * dtime * dtime * m_acceleration;
                        m_velocity += dtime * m_acceleration;
@@ -935,7 +951,7 @@ class GenericCAO : public ClientActiveObject
                        }
                }
                if(fabs(m_prop.automatic_rotate) > 0.001){
-                       m_yaw += dtime * m_prop.automatic_rotate * 180 / PI;
+                       m_yaw += dtime * m_prop.automatic_rotate * 180 / M_PI;
                        updateNodePos();
                }
        }
@@ -961,7 +977,7 @@ class GenericCAO : public ClientActiveObject
                                else if(cam_to_entity.Y < -0.75)
                                        col += 4;
                                else{
-                                       float mob_dir = atan2(cam_to_entity.Z, cam_to_entity.X) / PI * 180.;
+                                       float mob_dir = atan2(cam_to_entity.Z, cam_to_entity.X) / M_PI * 180.;
                                        float dir = mob_dir - m_yaw;
                                        dir = wrapDegrees_180(dir);
                                        //infostream<<"id="<<m_id<<" dir="<<dir<<std::endl;