]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/content_cao.cpp
Prevent world creation if the world already exists
[dragonfireclient.git] / src / content_cao.cpp
index 03387d030f020e23ea29e1a71a358805f2c3f20d..aa5c2d674039ab054fbbe3f71dd5292c27de0c5e 100644 (file)
@@ -3,16 +3,16 @@ Minetest-c55
 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
 
 This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+GNU Lesser General Public License for more details.
 
-You should have received a copy of the GNU General Public License along
+You should have received a copy of the GNU Lesser General Public License along
 with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
@@ -30,12 +30,17 @@ 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"
+
 class Settings;
 struct ToolCapabilities;
 
@@ -575,6 +580,7 @@ class GenericCAO : public ClientActiveObject
        float m_reset_textures_timer;
        bool m_visuals_expired;
        float m_step_distance_counter;
+       u8 m_last_light;
 
 public:
        GenericCAO(IGameDef *gamedef, ClientEnvironment *env):
@@ -604,7 +610,8 @@ class GenericCAO : public ClientActiveObject
                m_anim_timer(0),
                m_reset_textures_timer(-1),
                m_visuals_expired(false),
-               m_step_distance_counter(0)
+               m_step_distance_counter(0),
+               m_last_light(255)
        {
                if(gamedef == NULL)
                        ClientActiveObject::registerType(getType(), create);
@@ -707,8 +714,8 @@ class GenericCAO : public ClientActiveObject
                        m_spritenode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
                        m_spritenode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
                        m_spritenode->setMaterialFlag(video::EMF_FOG_ENABLE, true);
-                       m_spritenode->setColor(video::SColor(255,0,0,0));
-                       m_spritenode->setVisible(false); /* Set visible when brightness is known */
+                       u8 li = m_last_light;
+                       m_spritenode->setColor(video::SColor(255,li,li,li));
                        m_spritenode->setSize(m_prop.visual_size*BS);
                        {
                                const float txs = 1.0 / 1;
@@ -724,7 +731,8 @@ class GenericCAO : public ClientActiveObject
                        double dy = BS*m_prop.visual_size.Y/2;
                        { // Front
                        scene::IMeshBuffer *buf = new scene::SMeshBuffer();
-                       video::SColor c(255,255,255,255);
+                       u8 li = m_last_light;
+                       video::SColor c(255,li,li,li);
                        video::S3DVertex vertices[4] =
                        {
                                video::S3DVertex(-dx,-dy,0, 0,0,0, c, 0,1),
@@ -745,7 +753,8 @@ class GenericCAO : public ClientActiveObject
                        }
                        { // Back
                        scene::IMeshBuffer *buf = new scene::SMeshBuffer();
-                       video::SColor c(255,255,255,255);
+                       u8 li = m_last_light;
+                       video::SColor c(255,li,li,li);
                        video::S3DVertex vertices[4] =
                        {
                                video::S3DVertex(dx,-dy,0, 0,0,0, c, 1,1),
@@ -776,9 +785,27 @@ class GenericCAO : public ClientActiveObject
                        m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
                        mesh->drop();
                        
-                       m_meshnode->setScale(v3f(1));
-                       // Will be shown when we know the brightness
-                       m_meshnode->setVisible(false);
+                       m_meshnode->setScale(v3f(m_prop.visual_size.X,
+                                       m_prop.visual_size.Y,
+                                       m_prop.visual_size.X));
+                       u8 li = m_last_light;
+                       setMeshColor(m_meshnode->getMesh(), video::SColor(255,li,li,li));
+               } else if(m_prop.visual == "wielditem"){
+                       infostream<<"GenericCAO::addToScene(): node"<<std::endl;
+                       infostream<<"textures: "<<m_prop.textures.size()<<std::endl;
+                       if(m_prop.textures.size() >= 1){
+                               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;
+                               m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
+                               
+                               m_meshnode->setScale(v3f(m_prop.visual_size.X/2,
+                                               m_prop.visual_size.Y/2,
+                                               m_prop.visual_size.X/2));
+                               u8 li = m_last_light;
+                               setMeshColor(m_meshnode->getMesh(), video::SColor(255,li,li,li));
+                       }
                } else {
                        infostream<<"GenericCAO::addToScene(): \""<<m_prop.visual
                                        <<"\" not supported"<<std::endl;
@@ -811,6 +838,7 @@ 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);
@@ -855,22 +883,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;
@@ -910,6 +940,10 @@ class GenericCAO : public ClientActiveObject
                                updateTextures("");
                        }
                }
+               if(fabs(m_prop.automatic_rotate) > 0.001){
+                       m_yaw += dtime * m_prop.automatic_rotate * 180 / M_PI;
+                       updateNodePos();
+               }
        }
 
        void updateTexturePos()
@@ -933,7 +967,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;
@@ -1058,10 +1092,16 @@ class GenericCAO : public ClientActiveObject
                        m_position = readV3F1000(is);
                        m_velocity = readV3F1000(is);
                        m_acceleration = readV3F1000(is);
-                       m_yaw = readF1000(is);
+                       if(fabs(m_prop.automatic_rotate) < 0.001)
+                               m_yaw = readF1000(is);
                        bool do_interpolate = readU8(is);
                        bool is_end_position = readU8(is);
                        float update_interval = readF1000(is);
+
+                       // Place us a bit higher if we're physical, to not sink into
+                       // the ground due to sucky collision detection...
+                       if(m_prop.physical)
+                               m_position += v3f(0,0.002,0);
                        
                        if(do_interpolate){
                                if(!m_prop.physical)