aboutsummaryrefslogtreecommitdiff
path: root/src/mapsector.cpp
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2024-06-28 08:00:00 +0800
committerRunxi Yu <me@runxiyu.org>2024-06-28 08:00:00 +0800
commit11c7849bdf53557bc327fee06bddbbf1e23c4512 (patch)
treea90dba953d7cc9584c979ad3b6772f55c58f42ed /src/mapsector.cpp
parent53dd648c96b899b706f30de656896713d7e8ff08 (diff)
downloadhax-minetest-server-11c7849bdf53557bc327fee06bddbbf1e23c4512.tar.gz
hax-minetest-server-11c7849bdf53557bc327fee06bddbbf1e23c4512.zip
Hax's version of Minetest Server 5.6.0
Diffstat (limited to 'src/mapsector.cpp')
-rw-r--r--src/mapsector.cpp51
1 files changed, 20 insertions, 31 deletions
diff --git a/src/mapsector.cpp b/src/mapsector.cpp
index 3eefa5410..4060864bd 100644
--- a/src/mapsector.cpp
+++ b/src/mapsector.cpp
@@ -27,54 +27,40 @@ MapSector::MapSector(Map *parent, v2s16 pos, IGameDef *gamedef):
m_pos(pos),
m_gamedef(gamedef)
{
+ for (s16 i = -65536/MAP_BLOCKSIZE/2; i < 65536/MAP_BLOCKSIZE/2; i++) {
+ m_blocks[i] = nullptr;
+ }
+ m_blocks_used = 0;
}
MapSector::~MapSector()
{
deleteBlocks();
+ free(&m_blocks[-65536/MAP_BLOCKSIZE/2]);
}
void MapSector::deleteBlocks()
{
- // Clear cache
- m_block_cache = nullptr;
-
// Delete all
- for (auto &block : m_blocks) {
- delete block.second;
+ for (s16 i = -65536/MAP_BLOCKSIZE/2; i < 65536/MAP_BLOCKSIZE/2; i++) {
+ if (m_blocks[i])
+ delete m_blocks[i];
}
-
- // Clear container
- m_blocks.clear();
}
MapBlock * MapSector::getBlockBuffered(s16 y)
{
- MapBlock *block;
-
- if (m_block_cache && y == m_block_cache_y) {
- return m_block_cache;
- }
-
- // If block doesn't exist, return NULL
- std::unordered_map<s16, MapBlock*>::const_iterator n = m_blocks.find(y);
- block = (n != m_blocks.end() ? n->second : nullptr);
-
- // Cache the last result
- m_block_cache_y = y;
- m_block_cache = block;
-
- return block;
+ return m_blocks[y];
}
MapBlock * MapSector::getBlockNoCreateNoEx(s16 y)
{
- return getBlockBuffered(y);
+ return (y > -2048 && y < 2047) ? getBlockBuffered(y) : nullptr;
}
MapBlock * MapSector::createBlankBlockNoInsert(s16 y)
{
- assert(getBlockBuffered(y) == NULL); // Pre-condition
+ assert(getBlockBuffered(y) == nullptr); // Pre-condition
v3s16 blockpos_map(m_pos.X, y, m_pos.Y);
@@ -88,6 +74,7 @@ MapBlock * MapSector::createBlankBlock(s16 y)
MapBlock *block = createBlankBlockNoInsert(y);
m_blocks[y] = block;
+ m_blocks_used++;
return block;
}
@@ -106,17 +93,18 @@ void MapSector::insertBlock(MapBlock *block)
// Insert into container
m_blocks[block_y] = block;
+ m_blocks_used++;
}
void MapSector::deleteBlock(MapBlock *block)
{
s16 block_y = block->getPos().Y;
- // Clear from cache
- m_block_cache = nullptr;
-
// Remove from container
- m_blocks.erase(block_y);
+ if (m_blocks[block_y]) {
+ m_blocks_used--;
+ m_blocks[block_y] = nullptr;
+ }
// Delete
delete block;
@@ -124,7 +112,8 @@ void MapSector::deleteBlock(MapBlock *block)
void MapSector::getBlocks(MapBlockVect &dest)
{
- for (auto &block : m_blocks) {
- dest.push_back(block.second);
+ for (s16 i = -65536/MAP_BLOCKSIZE/2; i < 65536/MAP_BLOCKSIZE/2; i++) {
+ if (m_blocks[i])
+ dest.push_back(m_blocks[i]);
}
}