Pause in unloaded territory instead of collide
authorJacobF <queatz@gmail.com>
Wed, 24 Aug 2011 02:10:19 +0000 (22:10 -0400)
committerPerttu Ahola <celeron55@gmail.com>
Tue, 6 Sep 2011 17:07:43 +0000 (20:07 +0300)
src/environment.cpp
src/player.cpp
src/player.h

index d6ff4d826a7d804d138cd9e6442733e2ab1e6ee1..8103b7110436ddf3c7c4c8de7eb2678b9b5e3a59 100644 (file)
@@ -1512,6 +1512,11 @@ void ClientEnvironment::step(float dtime)
                Get the speed the player is going
        */
        bool is_climbing = lplayer->is_climbing;
+       
+       /*
+               Check if the player is frozen (don't apply physics)
+       */
+       bool is_frozen = lplayer->is_frozen;
 
        f32 player_speed = 0.001; // just some small value
        player_speed = lplayer->getSpeed().getLength();
@@ -1570,7 +1575,7 @@ void ClientEnvironment::step(float dtime)
                        v3f lplayerpos = lplayer->getPosition();
                        
                        // Apply physics
-                       if(free_move == false && is_climbing == false)
+                       if(free_move == false && is_climbing == false && is_frozen == false)
                        {
                                // Gravity
                                v3f speed = lplayer->getSpeed();
index d59ae7049d3a561357942f9cf04f7b11cd2b34a9..7cfdfebb69d45ebb739f50c43b51b5bd750b9e5a 100644 (file)
@@ -330,7 +330,18 @@ 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");
@@ -503,8 +514,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);
index 9a6ad93bfacad954121dda8964f27c749cdf8cc7..13cffa205a6986f802b77d0bd2fac2f7f486badd 100644 (file)
@@ -142,6 +142,7 @@ public:
        bool in_water_stable;
        bool is_climbing;
        bool swimming_up;
+       bool is_frozen;
        
        Inventory inventory;
        // Actual inventory is backed up here when creative mode is used