]> git.lizzy.rs Git - minetest.git/blobdiff - src/player.cpp
Fix some "Conditional jump or move depends on uninitialised value(s)" valgrind detections
[minetest.git] / src / player.cpp
index be478e8693efce74dfe42d21cb2a5bb1403e71db..6a774251cc110289edc22137c4a976b1760080f0 100644 (file)
@@ -22,17 +22,23 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "connection.h"
 #include "constants.h"
 #include "utility.h"
-
+#ifndef SERVER
+#include <ITextSceneNode.h>
+#endif
+#include "settings.h"
 
 Player::Player():
        touching_ground(false),
        in_water(false),
        in_water_stable(false),
+       is_climbing(false),
        swimming_up(false),
+       is_frozen(false),
        inventory_backup(NULL),
        craftresult_is_preview(true),
        hp(20),
        peer_id(PEER_ID_INEXISTENT),
+       m_selected_item(0),
        m_pitch(0),
        m_yaw(0),
        m_speed(0,0,0),
@@ -47,6 +53,11 @@ Player::~Player()
        delete inventory_backup;
 }
 
+void Player::wieldItem(u16 item)
+{
+       m_selected_item = item;
+}
+
 void Player::resetInventory()
 {
        inventory.clear();
@@ -324,10 +335,21 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
        /*
                Calculate new position
        */
-       position += m_speed * dtime;
+       if(is_frozen) {
+               // Still move very slowly so as not to feel all completely stuck
+               position += m_speed * dtime * 0.001;
+       }
+       else {
+               position += m_speed * dtime;
+       }
+       
+       /*
+               If the player enters an unloaded chunk this is set to true.
+       */
+       is_frozen = false;
 
        // Skip collision detection if a special movement mode is used
-       bool free_move = g_settings.getBool("free_move");
+       bool free_move = g_settings->getBool("free_move");
        if(free_move)
        {
                setPosition(position);
@@ -497,8 +519,11 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
                }
                catch(InvalidPositionException &e)
                {
-                       // Doing nothing here will block the player from
-                       // walking over map borders
+                       if(!is_frozen) {
+                               // freeze when entering unloaded areas
+                               is_frozen = true;
+                       }
+                       continue;
                }
 
                core::aabbox3d<f32> nodebox = getNodeBox(v3s16(x,y,z), BS);
@@ -734,9 +759,9 @@ void LocalPlayer::applyControl(float dtime)
        
        v3f speed = v3f(0,0,0);
 
-       bool free_move = g_settings.getBool("free_move");
-       bool fast_move = g_settings.getBool("fast_move");
-       bool continuous_forward = g_settings.getBool("continuous_forward");
+       bool free_move = g_settings->getBool("free_move");
+       bool fast_move = g_settings->getBool("fast_move");
+       bool continuous_forward = g_settings->getBool("continuous_forward");
 
        if(free_move || is_climbing)
        {