]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/localplayer.cpp
Limit speed in collisionMoveResult for avoiding hangs
[dragonfireclient.git] / src / localplayer.cpp
index 0554302e0496a7b4c9fb742a107ec3736ef00b95..a90ae69671ce70583b353cedb1fca72da18aee92 100644 (file)
@@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "gamedef.h"
 #include "nodedef.h"
 #include "settings.h"
+#include "environment.h"
 #include "map.h"
 #include "util/numeric.h"
 
@@ -34,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 LocalPlayer::LocalPlayer(IGameDef *gamedef):
        Player(gamedef),
+       parent(0),
        isAttached(false),
        overridePosition(v3f(0,0,0)),
        last_position(v3f(0,0,0)),
@@ -57,9 +59,10 @@ LocalPlayer::~LocalPlayer()
 {
 }
 
-void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
-               core::list<CollisionInfo> *collision_info)
+void LocalPlayer::move(f32 dtime, ClientEnvironment *env, f32 pos_max_d,
+               std::list<CollisionInfo> *collision_info)
 {
+       Map *map = &env->getMap();
        INodeDefManager *nodemgr = m_gamedef->ndef();
 
        v3f position = getPosition();
@@ -97,15 +100,15 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
                if(in_liquid)
                {
                        v3s16 pp = floatToInt(position + v3f(0,BS*0.1,0), BS);
-                       in_liquid = nodemgr->get(map.getNode(pp).getContent()).isLiquid();
-                       liquid_viscosity = nodemgr->get(map.getNode(pp).getContent()).liquid_viscosity;
+                       in_liquid = nodemgr->get(map->getNode(pp).getContent()).isLiquid();
+                       liquid_viscosity = nodemgr->get(map->getNode(pp).getContent()).liquid_viscosity;
                }
                // If not in liquid, the threshold of going in is at lower y
                else
                {
                        v3s16 pp = floatToInt(position + v3f(0,BS*0.5,0), BS);
-                       in_liquid = nodemgr->get(map.getNode(pp).getContent()).isLiquid();
-                       liquid_viscosity = nodemgr->get(map.getNode(pp).getContent()).liquid_viscosity;
+                       in_liquid = nodemgr->get(map->getNode(pp).getContent()).isLiquid();
+                       liquid_viscosity = nodemgr->get(map->getNode(pp).getContent()).liquid_viscosity;
                }
        }
        catch(InvalidPositionException &e)
@@ -118,7 +121,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
        */
        try{
                v3s16 pp = floatToInt(position + v3f(0,0,0), BS);
-               in_liquid_stable = nodemgr->get(map.getNode(pp).getContent()).isLiquid();
+               in_liquid_stable = nodemgr->get(map->getNode(pp).getContent()).isLiquid();
        }
        catch(InvalidPositionException &e)
        {
@@ -132,8 +135,8 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
        try {
                v3s16 pp = floatToInt(position + v3f(0,0.5*BS,0), BS);
                v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS);
-               is_climbing = ((nodemgr->get(map.getNode(pp).getContent()).climbable ||
-               nodemgr->get(map.getNode(pp2).getContent()).climbable) && !free_move);
+               is_climbing = ((nodemgr->get(map->getNode(pp).getContent()).climbable ||
+               nodemgr->get(map->getNode(pp2).getContent()).climbable) && !free_move);
        }
        catch(InvalidPositionException &e)
        {
@@ -197,7 +200,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
 
        v3f accel_f = v3f(0,0,0);
 
-       collisionMoveResult result = collisionMoveSimple(&map, m_gamedef,
+       collisionMoveResult result = collisionMoveSimple(env, m_gamedef,
                        pos_max_d, playerbox, player_stepheight, dtime,
                        position, m_speed, accel_f);
 
@@ -219,7 +222,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
        */
        v3s16 current_node = floatToInt(position - v3f(0,BS/2,0), BS);
        if(m_sneak_node_exists &&
-          nodemgr->get(map.getNodeNoEx(m_old_node_below)).name == "air" &&
+          nodemgr->get(map->getNodeNoEx(m_old_node_below)).name == "air" &&
           m_old_node_below_type != "air")
        {
                // Old node appears to have been removed; that is,
@@ -227,7 +230,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
                m_need_to_get_new_sneak_node = false;
                m_sneak_node_exists = false;
        }
-       else if(nodemgr->get(map.getNodeNoEx(current_node)).name != "air")
+       else if(nodemgr->get(map->getNodeNoEx(current_node)).name != "air")
        {
                // We are on something, so make sure to recalculate the sneak
                // node.
@@ -267,10 +270,10 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
 
                        try{
                                // The node to be sneaked on has to be walkable
-                               if(nodemgr->get(map.getNode(p)).walkable == false)
+                               if(nodemgr->get(map->getNode(p)).walkable == false)
                                        continue;
                                // And the node above it has to be nonwalkable
-                               if(nodemgr->get(map.getNode(p+v3s16(0,1,0))).walkable == true)
+                               if(nodemgr->get(map->getNode(p+v3s16(0,1,0))).walkable == true)
                                        continue;
                        }
                        catch(InvalidPositionException &e)
@@ -331,7 +334,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
        {
                camera_barely_in_ceiling = false;
                v3s16 camera_np = floatToInt(getEyePosition(), BS);
-               MapNode n = map.getNodeNoEx(camera_np);
+               MapNode n = map->getNodeNoEx(camera_np);
                if(n.getContent() != CONTENT_IGNORE){
                        if(nodemgr->get(n).walkable && nodemgr->get(n).solidness == 2){
                                camera_barely_in_ceiling = true;
@@ -343,21 +346,21 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
                Update the node last under the player
        */
        m_old_node_below = floatToInt(position - v3f(0,BS/2,0), BS);
-       m_old_node_below_type = nodemgr->get(map.getNodeNoEx(m_old_node_below)).name;
+       m_old_node_below_type = nodemgr->get(map->getNodeNoEx(m_old_node_below)).name;
        
        /*
                Check properties of the node on which the player is standing
        */
-       const ContentFeatures &f = nodemgr->get(map.getNodeNoEx(getStandingNodePos()));
+       const ContentFeatures &f = nodemgr->get(map->getNodeNoEx(getStandingNodePos()));
        // Determine if jumping is possible
        m_can_jump = touching_ground && !in_liquid;
        if(itemgroup_get(f.groups, "disable_jump"))
                m_can_jump = false;
 }
 
-void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d)
+void LocalPlayer::move(f32 dtime, ClientEnvironment *env, f32 pos_max_d)
 {
-       move(dtime, map, pos_max_d, NULL);
+       move(dtime, env, pos_max_d, NULL);
 }
 
 void LocalPlayer::applyControl(float dtime)