Actually fix weather
authorkwolekr <kwolekr@minetest.net>
Sun, 17 Nov 2013 06:59:04 +0000 (01:59 -0500)
committerkwolekr <kwolekr@minetest.net>
Sun, 17 Nov 2013 06:59:04 +0000 (01:59 -0500)
The real problem was that MapBlocks were not activated before getting sent to the client

src/emerge.cpp
src/environment.cpp
src/map.cpp
src/map.h
src/mapblock.cpp
src/mapblock.h

index 569f1b80a3321e2aea69c6ce34f4e2f6a6b7f1c6..167473ecf7c3bbd5dd83057d70aabbdc4e5f1449 100644 (file)
@@ -429,6 +429,8 @@ bool EmergeThread::getBlockOrStartGen(v3s16 p, MapBlock **b,
        if (!block || block->isDummy() || !block->isGenerated()) {
                EMERGE_DBG_OUT("not in memory, attempting to load from disk");
                block = map->loadBlock(p);
+               if (block && block->isGenerated())
+                       map->prepareBlock(block);
        }
 
        // If could not load and allowed to generate,
index dd160d1f7b17ddc16d082a444d7c60b846161f1e..8a52a143d1fdd707678f91ae91e930dbcea09af7 100644 (file)
@@ -809,16 +809,6 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
        
        // Activate stored objects
        activateObjects(block, dtime_s);
-       
-       // Calculate weather conditions
-       if (m_use_weather) {
-               m_map->updateBlockHeat(this, block->getPos() *  MAP_BLOCKSIZE, block);
-               m_map->updateBlockHumidity(this, block->getPos() * MAP_BLOCKSIZE, block);
-       } else {
-               block->heat     = HEAT_UNDEFINED;
-               block->humidity = HUMIDITY_UNDEFINED;
-               block->weather_update_time = 0;
-       }
 
        // Run node timers
        std::map<v3s16, NodeTimer> elapsed_timers =
index f74011933f2d53c222cf71ade69dd25ff7584652..0dbfd42f49b8d486da9293880906af6bdb8631b6 100644 (file)
@@ -2832,32 +2832,23 @@ MapBlock* ServerMap::finishBlockMake(BlockMakeData *data,
                Update weather data in blocks
        */
        ServerEnvironment *senv = &((Server *)m_gamedef)->getEnv();
-       if (senv->m_use_weather) {
-               for(s16 x=blockpos_min.X-extra_borders.X;
-                       x<=blockpos_max.X+extra_borders.X; x++)
-               for(s16 z=blockpos_min.Z-extra_borders.Z;
-                       z<=blockpos_max.Z+extra_borders.Z; z++)
-               for(s16 y=blockpos_min.Y-extra_borders.Y;
-                       y<=blockpos_max.Y+extra_borders.Y; y++)
-               {
-                       v3s16 p(x, y, z);
-                       MapBlock *block = getBlockNoCreateNoEx(p);
-                       block->weather_update_time = 0;
-                       updateBlockHeat(senv, p * MAP_BLOCKSIZE, NULL);
-                       updateBlockHumidity(senv, p * MAP_BLOCKSIZE, NULL);
-               }
-       } else {
-               for(s16 x=blockpos_min.X-extra_borders.X;
-                       x<=blockpos_max.X+extra_borders.X; x++)
-               for(s16 z=blockpos_min.Z-extra_borders.Z;
-                       z<=blockpos_max.Z+extra_borders.Z; z++)
-               for(s16 y=blockpos_min.Y-extra_borders.Y;
-                       y<=blockpos_max.Y+extra_borders.Y; y++)
-               {
-                       MapBlock *block = getBlockNoCreateNoEx(v3s16(x, y, z));
+       for(s16 x=blockpos_min.X-extra_borders.X;
+               x<=blockpos_max.X+extra_borders.X; x++)
+       for(s16 z=blockpos_min.Z-extra_borders.Z;
+               z<=blockpos_max.Z+extra_borders.Z; z++)
+       for(s16 y=blockpos_min.Y-extra_borders.Y;
+               y<=blockpos_max.Y+extra_borders.Y; y++)
+       {
+               v3s16 p(x, y, z);
+               MapBlock *block = getBlockNoCreateNoEx(p);
+               block->heat_last_update     = 0;
+               block->humidity_last_update = 0;
+               if (senv->m_use_weather) {
+                       updateBlockHeat(senv, p * MAP_BLOCKSIZE, block);
+                       updateBlockHumidity(senv, p * MAP_BLOCKSIZE, block);
+               } else {
                        block->heat     = HEAT_UNDEFINED;
                        block->humidity = HUMIDITY_UNDEFINED;
-                       block->weather_update_time = 0;
                }
        }
        
@@ -3181,6 +3172,22 @@ MapBlock * ServerMap::emergeBlock(v3s16 p, bool create_blank)
        return NULL;
 }
 
+void ServerMap::prepareBlock(MapBlock *block) {
+       ServerEnvironment *senv = &((Server *)m_gamedef)->getEnv();
+
+       // Calculate weather conditions
+       block->heat_last_update     = 0;
+       block->humidity_last_update = 0;
+       if (senv->m_use_weather) {
+               v3s16 p = block->getPos() *  MAP_BLOCKSIZE;
+               updateBlockHeat(senv, p, block);
+               updateBlockHumidity(senv, p, block);
+       } else {
+               block->heat     = HEAT_UNDEFINED;
+               block->humidity = HUMIDITY_UNDEFINED;
+       }
+}
+
 s16 ServerMap::findGroundLevel(v2s16 p2d)
 {
 #if 0
@@ -3930,7 +3937,7 @@ s16 ServerMap::updateBlockHeat(ServerEnvironment *env, v3s16 p, MapBlock *block)
        u32 gametime = env->getGameTime();
        
        if (block) {
-               if (gametime - block->weather_update_time < 10)
+               if (gametime - block->heat_last_update < 10)
                        return block->heat;
        } else {
                block = getBlockNoCreateNoEx(getNodeBlockPos(p));
@@ -3941,7 +3948,7 @@ s16 ServerMap::updateBlockHeat(ServerEnvironment *env, v3s16 p, MapBlock *block)
 
        if(block) {
                block->heat = heat;
-               block->weather_update_time = gametime;
+               block->heat_last_update = gametime;
        }
        return heat;
 }
@@ -3951,7 +3958,7 @@ s16 ServerMap::updateBlockHumidity(ServerEnvironment *env, v3s16 p, MapBlock *bl
        u32 gametime = env->getGameTime();
        
        if (block) {
-               if (gametime - block->weather_update_time < 10)
+               if (gametime - block->humidity_last_update < 10)
                        return block->humidity;
        } else {
                block = getBlockNoCreateNoEx(getNodeBlockPos(p));
@@ -3962,7 +3969,7 @@ s16 ServerMap::updateBlockHumidity(ServerEnvironment *env, v3s16 p, MapBlock *bl
                        
        if(block) {
                block->humidity = humidity;
-               block->weather_update_time = gametime;
+               block->humidity_last_update = gametime;
        }
        return humidity;
 }
index b70b18acc0ff80c9d4b85668705d780d9fe951d3..a6480c569fb706ed77aeff56b83e68fcb73c21b2 100644 (file)
--- a/src/map.h
+++ b/src/map.h
@@ -403,6 +403,9 @@ public:
 
        */
        MapBlock * emergeBlock(v3s16 p, bool create_blank=true);
+       
+       // Carries out any initialization necessary before block is sent
+       void prepareBlock(MapBlock *block);
 
        // Helper for placing objects on ground level
        s16 findGroundLevel(v2s16 p2d);
index 3fb2ec5eda0bd3bfc8f0141d3f545f752f98cf63..e45af9cdbc6775db4481194634497d02f67e03cf 100644 (file)
@@ -45,7 +45,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 MapBlock::MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef, bool dummy):
                heat(0),
                humidity(0),
-               weather_update_time(0),
+               heat_last_update(0),
+               humidity_last_update(0),
                m_parent(parent),
                m_pos(pos),
                m_gamedef(gamedef),
index e0730ffcf459093a3e4f87aef11dd14e85e15b7a..501ab75dafb944132801aa8f256fa05f3c75c34f 100644 (file)
@@ -516,7 +516,8 @@ public:
        
        s16 heat;
        s16 humidity;
-       u32 weather_update_time;
+       u32 heat_last_update;
+       u32 humidity_last_update;
 
 private:
        /*