mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Detect air-only blocks instead of day/night differences (#14264)
* Detect air-only blocks instead day/night differences * Write !is_air into the former day-night-diff bit on disk, so that old server can still read maps written by new servers * Only set is_air bit when reading from disk
This commit is contained in:
parent
0d30a3071a
commit
0d4b489545
5 changed files with 52 additions and 75 deletions
|
@ -186,57 +186,27 @@ void MapBlock::copyFrom(VoxelManipulator &dst)
|
|||
getPosRelative(), data_size);
|
||||
}
|
||||
|
||||
void MapBlock::actuallyUpdateDayNightDiff()
|
||||
void MapBlock::actuallyUpdateIsAir()
|
||||
{
|
||||
const NodeDefManager *nodemgr = m_gamedef->ndef();
|
||||
// Running this function un-expires m_is_air
|
||||
m_is_air_expired = false;
|
||||
|
||||
// Running this function un-expires m_day_night_differs
|
||||
m_day_night_differs_expired = false;
|
||||
|
||||
bool differs = false;
|
||||
|
||||
/*
|
||||
Check if any lighting value differs
|
||||
*/
|
||||
|
||||
MapNode previous_n(CONTENT_IGNORE);
|
||||
bool only_air = true;
|
||||
for (u32 i = 0; i < nodecount; i++) {
|
||||
MapNode n = data[i];
|
||||
|
||||
// If node is identical to previous node, don't verify if it differs
|
||||
if (n == previous_n)
|
||||
continue;
|
||||
|
||||
differs = !n.isLightDayNightEq(nodemgr->getLightingFlags(n));
|
||||
if (differs)
|
||||
MapNode &n = data[i];
|
||||
if (n.getContent() != CONTENT_AIR) {
|
||||
only_air = false;
|
||||
break;
|
||||
previous_n = n;
|
||||
}
|
||||
|
||||
/*
|
||||
If some lighting values differ, check if the whole thing is
|
||||
just air. If it is just air, differs = false
|
||||
*/
|
||||
if (differs) {
|
||||
bool only_air = true;
|
||||
for (u32 i = 0; i < nodecount; i++) {
|
||||
MapNode &n = data[i];
|
||||
if (n.getContent() != CONTENT_AIR) {
|
||||
only_air = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (only_air)
|
||||
differs = false;
|
||||
}
|
||||
|
||||
// Set member variable
|
||||
m_day_night_differs = differs;
|
||||
m_is_air = only_air;
|
||||
}
|
||||
|
||||
void MapBlock::expireDayNightDiff()
|
||||
void MapBlock::expireIsAirCache()
|
||||
{
|
||||
m_day_night_differs_expired = true;
|
||||
m_is_air_expired = true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -369,7 +339,12 @@ void MapBlock::serialize(std::ostream &os_compressed, u8 version, bool disk, int
|
|||
u8 flags = 0;
|
||||
if(is_underground)
|
||||
flags |= 0x01;
|
||||
if(getDayNightDiff())
|
||||
// This flag used to be day-night-differs, and it is no longer used.
|
||||
// We write it anyway so that old servers can still use this.
|
||||
// Above ground isAir implies !day-night-differs, !isAir is good enough for old servers
|
||||
// to check whether above ground blocks should be sent.
|
||||
// See RemoteClient::getNextBlocks(...)
|
||||
if(!isAir())
|
||||
flags |= 0x02;
|
||||
if (!m_generated)
|
||||
flags |= 0x08;
|
||||
|
@ -473,7 +448,7 @@ void MapBlock::deSerialize(std::istream &in_compressed, u8 version, bool disk)
|
|||
|
||||
TRACESTREAM(<<"MapBlock::deSerialize "<<getPos()<<std::endl);
|
||||
|
||||
m_day_night_differs_expired = false;
|
||||
m_is_air_expired = true;
|
||||
|
||||
if(version <= 21)
|
||||
{
|
||||
|
@ -489,7 +464,9 @@ void MapBlock::deSerialize(std::istream &in_compressed, u8 version, bool disk)
|
|||
|
||||
u8 flags = readU8(is);
|
||||
is_underground = (flags & 0x01) != 0;
|
||||
m_day_night_differs = (flags & 0x02) != 0;
|
||||
// IMPORTANT: when the version is bumped to 30 we can read m_is_air from here
|
||||
// m_is_air = (flags & 0x02) == 0;
|
||||
|
||||
if (version < 27)
|
||||
m_lighting_complete = 0xFFFF;
|
||||
else
|
||||
|
@ -599,6 +576,10 @@ void MapBlock::deSerialize(std::istream &in_compressed, u8 version, bool disk)
|
|||
<<": Node timers (ver>=25)"<<std::endl);
|
||||
m_node_timers.deSerialize(is, version);
|
||||
}
|
||||
|
||||
u16 dummy;
|
||||
m_is_air = nimap.size() == 1 && nimap.getId("air", dummy);
|
||||
m_is_air_expired = false;
|
||||
}
|
||||
|
||||
TRACESTREAM(<<"MapBlock::deSerialize "<<getPos()
|
||||
|
@ -647,7 +628,7 @@ void MapBlock::deSerialize_pre22(std::istream &is, u8 version, bool disk)
|
|||
{
|
||||
// Initialize default flags
|
||||
is_underground = false;
|
||||
m_day_night_differs = false;
|
||||
m_is_air = false;
|
||||
m_lighting_complete = 0xFFFF;
|
||||
m_generated = true;
|
||||
|
||||
|
@ -713,7 +694,6 @@ void MapBlock::deSerialize_pre22(std::istream &is, u8 version, bool disk)
|
|||
u8 flags;
|
||||
is.read((char*)&flags, 1);
|
||||
is_underground = (flags & 0x01) != 0;
|
||||
m_day_night_differs = (flags & 0x02) != 0;
|
||||
if (version >= 18)
|
||||
m_generated = (flags & 0x08) == 0;
|
||||
|
||||
|
@ -798,9 +778,13 @@ void MapBlock::deSerialize_pre22(std::istream &is, u8 version, bool disk)
|
|||
// If supported, read node definition id mapping
|
||||
if (version >= 21) {
|
||||
nimap.deSerialize(is);
|
||||
u16 dummy;
|
||||
m_is_air = nimap.size() == 1 && nimap.getId("air", dummy);
|
||||
// Else set the legacy mapping
|
||||
} else {
|
||||
content_mapnode_get_name_id_mapping(&nimap);
|
||||
m_is_air = false;
|
||||
m_is_air_expired = true;
|
||||
}
|
||||
correctBlockNodeIds(&nimap, data, m_gamedef);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue