Skip to content

Commit e396fb2

Browse files
committedNov 17, 2013
Actually fix weather
The real problem was that MapBlocks were not activated before getting sent to the client
1 parent 90e7832 commit e396fb2

File tree

6 files changed

+44
-40
lines changed

6 files changed

+44
-40
lines changed
 

‎src/emerge.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,8 @@ bool EmergeThread::getBlockOrStartGen(v3s16 p, MapBlock **b,
429429
if (!block || block->isDummy() || !block->isGenerated()) {
430430
EMERGE_DBG_OUT("not in memory, attempting to load from disk");
431431
block = map->loadBlock(p);
432+
if (block && block->isGenerated())
433+
map->prepareBlock(block);
432434
}
433435

434436
// If could not load and allowed to generate,

‎src/environment.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -809,16 +809,6 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
809809

810810
// Activate stored objects
811811
activateObjects(block, dtime_s);
812-
813-
// Calculate weather conditions
814-
if (m_use_weather) {
815-
m_map->updateBlockHeat(this, block->getPos() * MAP_BLOCKSIZE, block);
816-
m_map->updateBlockHumidity(this, block->getPos() * MAP_BLOCKSIZE, block);
817-
} else {
818-
block->heat = HEAT_UNDEFINED;
819-
block->humidity = HUMIDITY_UNDEFINED;
820-
block->weather_update_time = 0;
821-
}
822812

823813
// Run node timers
824814
std::map<v3s16, NodeTimer> elapsed_timers =

‎src/map.cpp

+35-28
Original file line numberDiff line numberDiff line change
@@ -2832,32 +2832,23 @@ MapBlock* ServerMap::finishBlockMake(BlockMakeData *data,
28322832
Update weather data in blocks
28332833
*/
28342834
ServerEnvironment *senv = &((Server *)m_gamedef)->getEnv();
2835-
if (senv->m_use_weather) {
2836-
for(s16 x=blockpos_min.X-extra_borders.X;
2837-
x<=blockpos_max.X+extra_borders.X; x++)
2838-
for(s16 z=blockpos_min.Z-extra_borders.Z;
2839-
z<=blockpos_max.Z+extra_borders.Z; z++)
2840-
for(s16 y=blockpos_min.Y-extra_borders.Y;
2841-
y<=blockpos_max.Y+extra_borders.Y; y++)
2842-
{
2843-
v3s16 p(x, y, z);
2844-
MapBlock *block = getBlockNoCreateNoEx(p);
2845-
block->weather_update_time = 0;
2846-
updateBlockHeat(senv, p * MAP_BLOCKSIZE, NULL);
2847-
updateBlockHumidity(senv, p * MAP_BLOCKSIZE, NULL);
2848-
}
2849-
} else {
2850-
for(s16 x=blockpos_min.X-extra_borders.X;
2851-
x<=blockpos_max.X+extra_borders.X; x++)
2852-
for(s16 z=blockpos_min.Z-extra_borders.Z;
2853-
z<=blockpos_max.Z+extra_borders.Z; z++)
2854-
for(s16 y=blockpos_min.Y-extra_borders.Y;
2855-
y<=blockpos_max.Y+extra_borders.Y; y++)
2856-
{
2857-
MapBlock *block = getBlockNoCreateNoEx(v3s16(x, y, z));
2835+
for(s16 x=blockpos_min.X-extra_borders.X;
2836+
x<=blockpos_max.X+extra_borders.X; x++)
2837+
for(s16 z=blockpos_min.Z-extra_borders.Z;
2838+
z<=blockpos_max.Z+extra_borders.Z; z++)
2839+
for(s16 y=blockpos_min.Y-extra_borders.Y;
2840+
y<=blockpos_max.Y+extra_borders.Y; y++)
2841+
{
2842+
v3s16 p(x, y, z);
2843+
MapBlock *block = getBlockNoCreateNoEx(p);
2844+
block->heat_last_update = 0;
2845+
block->humidity_last_update = 0;
2846+
if (senv->m_use_weather) {
2847+
updateBlockHeat(senv, p * MAP_BLOCKSIZE, block);
2848+
updateBlockHumidity(senv, p * MAP_BLOCKSIZE, block);
2849+
} else {
28582850
block->heat = HEAT_UNDEFINED;
28592851
block->humidity = HUMIDITY_UNDEFINED;
2860-
block->weather_update_time = 0;
28612852
}
28622853
}
28632854

@@ -3181,6 +3172,22 @@ MapBlock * ServerMap::emergeBlock(v3s16 p, bool create_blank)
31813172
return NULL;
31823173
}
31833174

3175+
void ServerMap::prepareBlock(MapBlock *block) {
3176+
ServerEnvironment *senv = &((Server *)m_gamedef)->getEnv();
3177+
3178+
// Calculate weather conditions
3179+
block->heat_last_update = 0;
3180+
block->humidity_last_update = 0;
3181+
if (senv->m_use_weather) {
3182+
v3s16 p = block->getPos() * MAP_BLOCKSIZE;
3183+
updateBlockHeat(senv, p, block);
3184+
updateBlockHumidity(senv, p, block);
3185+
} else {
3186+
block->heat = HEAT_UNDEFINED;
3187+
block->humidity = HUMIDITY_UNDEFINED;
3188+
}
3189+
}
3190+
31843191
s16 ServerMap::findGroundLevel(v2s16 p2d)
31853192
{
31863193
#if 0
@@ -3930,7 +3937,7 @@ s16 ServerMap::updateBlockHeat(ServerEnvironment *env, v3s16 p, MapBlock *block)
39303937
u32 gametime = env->getGameTime();
39313938

39323939
if (block) {
3933-
if (gametime - block->weather_update_time < 10)
3940+
if (gametime - block->heat_last_update < 10)
39343941
return block->heat;
39353942
} else {
39363943
block = getBlockNoCreateNoEx(getNodeBlockPos(p));
@@ -3941,7 +3948,7 @@ s16 ServerMap::updateBlockHeat(ServerEnvironment *env, v3s16 p, MapBlock *block)
39413948

39423949
if(block) {
39433950
block->heat = heat;
3944-
block->weather_update_time = gametime;
3951+
block->heat_last_update = gametime;
39453952
}
39463953
return heat;
39473954
}
@@ -3951,7 +3958,7 @@ s16 ServerMap::updateBlockHumidity(ServerEnvironment *env, v3s16 p, MapBlock *bl
39513958
u32 gametime = env->getGameTime();
39523959

39533960
if (block) {
3954-
if (gametime - block->weather_update_time < 10)
3961+
if (gametime - block->humidity_last_update < 10)
39553962
return block->humidity;
39563963
} else {
39573964
block = getBlockNoCreateNoEx(getNodeBlockPos(p));
@@ -3962,7 +3969,7 @@ s16 ServerMap::updateBlockHumidity(ServerEnvironment *env, v3s16 p, MapBlock *bl
39623969

39633970
if(block) {
39643971
block->humidity = humidity;
3965-
block->weather_update_time = gametime;
3972+
block->humidity_last_update = gametime;
39663973
}
39673974
return humidity;
39683975
}

‎src/map.h

+3
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,9 @@ class ServerMap : public Map
403403
404404
*/
405405
MapBlock * emergeBlock(v3s16 p, bool create_blank=true);
406+
407+
// Carries out any initialization necessary before block is sent
408+
void prepareBlock(MapBlock *block);
406409

407410
// Helper for placing objects on ground level
408411
s16 findGroundLevel(v2s16 p2d);

‎src/mapblock.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
4545
MapBlock::MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef, bool dummy):
4646
heat(0),
4747
humidity(0),
48-
weather_update_time(0),
48+
heat_last_update(0),
49+
humidity_last_update(0),
4950
m_parent(parent),
5051
m_pos(pos),
5152
m_gamedef(gamedef),

‎src/mapblock.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,8 @@ class MapBlock /*: public NodeContainer*/
516516

517517
s16 heat;
518518
s16 humidity;
519-
u32 weather_update_time;
519+
u32 heat_last_update;
520+
u32 humidity_last_update;
520521

521522
private:
522523
/*

0 commit comments

Comments
 (0)
Please sign in to comment.