summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/map.cpp27
-rw-r--r--src/map.h2
-rw-r--r--src/mapblock.cpp24
-rw-r--r--src/mapblock.h12
-rw-r--r--src/server.cpp2
5 files changed, 47 insertions, 20 deletions
diff --git a/src/map.cpp b/src/map.cpp
index 835aca4fb..e24bac2f2 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -923,7 +923,7 @@ void Map::updateLighting(core::map<v3s16, MapBlock*> & a_blocks,
i.atEnd() == false; i++)
{
MapBlock *block = i.getNode()->getValue();
- block->updateDayNightDiff();
+ block->expireDayNightDiff();
}
}
@@ -1084,7 +1084,7 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
i.atEnd() == false; i++)
{
MapBlock *block = i.getNode()->getValue();
- block->updateDayNightDiff();
+ block->expireDayNightDiff();
}
/*
@@ -1260,7 +1260,7 @@ void Map::removeNodeAndUpdate(v3s16 p,
i.atEnd() == false; i++)
{
MapBlock *block = i.getNode()->getValue();
- block->updateDayNightDiff();
+ block->expireDayNightDiff();
}
/*
@@ -1297,6 +1297,7 @@ void Map::removeNodeAndUpdate(v3s16 p,
bool Map::addNodeWithEvent(v3s16 p, MapNode n)
{
+ ScopeProfiler sp(g_profiler, "Map::addNodeWithEvent", SPT_AVG);
MapEditEvent event;
event.type = MEET_ADDNODE;
event.p = p;
@@ -1352,12 +1353,12 @@ bool Map::removeNodeWithEvent(v3s16 p)
return succeeded;
}
-bool Map::dayNightDiffed(v3s16 blockpos)
+bool Map::getDayNightDiff(v3s16 blockpos)
{
try{
v3s16 p = blockpos + v3s16(0,0,0);
MapBlock *b = getBlockNoCreate(p);
- if(b->dayNightDiffed())
+ if(b->getDayNightDiff())
return true;
}
catch(InvalidPositionException &e){}
@@ -1365,21 +1366,21 @@ bool Map::dayNightDiffed(v3s16 blockpos)
try{
v3s16 p = blockpos + v3s16(-1,0,0);
MapBlock *b = getBlockNoCreate(p);
- if(b->dayNightDiffed())
+ if(b->getDayNightDiff())
return true;
}
catch(InvalidPositionException &e){}
try{
v3s16 p = blockpos + v3s16(0,-1,0);
MapBlock *b = getBlockNoCreate(p);
- if(b->dayNightDiffed())
+ if(b->getDayNightDiff())
return true;
}
catch(InvalidPositionException &e){}
try{
v3s16 p = blockpos + v3s16(0,0,-1);
MapBlock *b = getBlockNoCreate(p);
- if(b->dayNightDiffed())
+ if(b->getDayNightDiff())
return true;
}
catch(InvalidPositionException &e){}
@@ -1387,21 +1388,21 @@ bool Map::dayNightDiffed(v3s16 blockpos)
try{
v3s16 p = blockpos + v3s16(1,0,0);
MapBlock *b = getBlockNoCreate(p);
- if(b->dayNightDiffed())
+ if(b->getDayNightDiff())
return true;
}
catch(InvalidPositionException &e){}
try{
v3s16 p = blockpos + v3s16(0,1,0);
MapBlock *b = getBlockNoCreate(p);
- if(b->dayNightDiffed())
+ if(b->getDayNightDiff())
return true;
}
catch(InvalidPositionException &e){}
try{
v3s16 p = blockpos + v3s16(0,0,1);
MapBlock *b = getBlockNoCreate(p);
- if(b->dayNightDiffed())
+ if(b->getDayNightDiff())
return true;
}
catch(InvalidPositionException &e){}
@@ -2294,12 +2295,12 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data,
/*
Update day/night difference cache of the MapBlocks
*/
- block->updateDayNightDiff();
+ block->expireDayNightDiff();
/*
Set block as modified
*/
block->raiseModified(MOD_STATE_WRITE_NEEDED,
- "finishBlockMake updateDayNightDiff");
+ "finishBlockMake expireDayNightDiff");
}
/*
diff --git a/src/map.h b/src/map.h
index b71f699c0..b84e123e4 100644
--- a/src/map.h
+++ b/src/map.h
@@ -226,7 +226,7 @@ public:
/*
Takes the blocks at the edges into account
*/
- bool dayNightDiffed(v3s16 blockpos);
+ bool getDayNightDiff(v3s16 blockpos);
//core::aabbox3d<s16> getDisplayedBlockArea();
diff --git a/src/mapblock.cpp b/src/mapblock.cpp
index 70cb0e370..5ad86fde4 100644
--- a/src/mapblock.cpp
+++ b/src/mapblock.cpp
@@ -49,6 +49,7 @@ MapBlock::MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef, bool dummy):
is_underground(false),
m_lighting_expired(true),
m_day_night_differs(false),
+ m_day_night_differs_expired(true),
m_generated(false),
m_timestamp(BLOCK_TIMESTAMP_UNDEFINED),
m_disk_timestamp(BLOCK_TIMESTAMP_UNDEFINED),
@@ -355,9 +356,11 @@ void MapBlock::copyFrom(VoxelManipulator &dst)
getPosRelative(), data_size);
}
-void MapBlock::updateDayNightDiff()
+void MapBlock::actuallyUpdateDayNightDiff()
{
INodeDefManager *nodemgr = m_gamedef->ndef();
+ // Running this function un-expires m_day_night_differs
+ m_day_night_differs_expired = false;
if(data == NULL)
{
@@ -404,6 +407,19 @@ void MapBlock::updateDayNightDiff()
m_day_night_differs = differs;
}
+void MapBlock::expireDayNightDiff()
+{
+ INodeDefManager *nodemgr = m_gamedef->ndef();
+
+ if(data == NULL){
+ m_day_night_differs = false;
+ m_day_night_differs_expired = false;
+ return;
+ }
+
+ m_day_night_differs_expired = true;
+}
+
s16 MapBlock::getGroundLevel(v2s16 p2d)
{
if(isDummy())
@@ -545,7 +561,7 @@ void MapBlock::serialize(std::ostream &os, u8 version, bool disk)
u8 flags = 0;
if(is_underground)
flags |= 0x01;
- if(m_day_night_differs)
+ if(getDayNightDiff())
flags |= 0x02;
if(m_lighting_expired)
flags |= 0x04;
@@ -614,6 +630,8 @@ void MapBlock::deSerialize(std::istream &is, u8 version, bool disk)
if(!ser_ver_supported(version))
throw VersionMismatchException("ERROR: MapBlock format not supported");
+ m_day_night_differs_expired = false;
+
if(version <= 21)
{
deSerialize_pre22(is, version, disk);
@@ -800,7 +818,7 @@ void MapBlock::serialize_pre22(std::ostream &os, u8 version, bool disk)
u8 flags = 0;
if(is_underground)
flags |= 0x01;
- if(m_day_night_differs)
+ if(getDayNightDiff())
flags |= 0x02;
if(m_lighting_expired)
flags |= 0x04;
diff --git a/src/mapblock.h b/src/mapblock.h
index 272da8ce3..4f61d6aa7 100644
--- a/src/mapblock.h
+++ b/src/mapblock.h
@@ -360,10 +360,17 @@ public:
Sets m_day_night_differs to appropriate value.
These methods don't care about neighboring blocks.
*/
- void updateDayNightDiff();
+ void actuallyUpdateDayNightDiff();
+ /*
+ Call this to schedule what the previous function does to be done
+ when the value is actually needed.
+ */
+ void expireDayNightDiff();
- bool dayNightDiffed()
+ bool getDayNightDiff()
{
+ if(m_day_night_differs_expired)
+ actuallyUpdateDayNightDiff();
return m_day_night_differs;
}
@@ -517,6 +524,7 @@ private:
// Whether day and night lighting differs
bool m_day_night_differs;
+ bool m_day_night_differs_expired;
bool m_generated;
diff --git a/src/server.cpp b/src/server.cpp
index ff250596d..3aa0bd04b 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -659,7 +659,7 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime,
*/
if(d >= 4)
{
- if(block->dayNightDiffed() == false)
+ if(block->getDayNightDiff() == false)
continue;
}
#endif