1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Reduce EnvRef:set_node() time tenfold by postponing the dayNightDiff update until it is actually needed

This commit is contained in:
Perttu Ahola 2012-03-29 00:28:48 +03:00
parent 418041d906
commit 02c035c548
5 changed files with 47 additions and 20 deletions

View file

@ -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;