diff --git a/src/client.cpp b/src/client.cpp index 248cd8a..449b0c2 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -333,16 +333,16 @@ void Client::step(float dtime) true, &deleted_blocks);*/ // Delete whole sectors - u32 num = m_env.getMap().unloadUnusedData + m_env.getMap().unloadUnusedData (delete_unused_sectors_timeout, - false, &deleted_blocks); + &deleted_blocks); - if(num > 0) + if(deleted_blocks.size() > 0) { /*dstream<getBlockNoCreateNoEx(p); if(block==NULL) continue; + + // Reset block usage timer + block->resetUsageTimer(); // Set current time as timestamp block->setTimestampNoChangedFlag(m_game_time); diff --git a/src/map.cpp b/src/map.cpp index 5bf2786..2cf7bb2 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1388,8 +1388,6 @@ bool Map::dayNightDiffed(v3s16 blockpos) */ void Map::timerUpdate(float dtime) { - //JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out - core::map::Iterator si; si = m_sectors.getIterator(); @@ -1407,38 +1405,27 @@ void Map::timerUpdate(float dtime) } } -void Map::deleteSectors(core::list &list, bool only_blocks) +void Map::deleteSectors(core::list &list) { core::list::Iterator j; for(j=list.begin(); j!=list.end(); j++) { MapSector *sector = m_sectors[*j]; - if(only_blocks) - { - sector->deleteBlocks(); - } - else - { - /* - If sector is in sector cache, remove it from there - */ - if(m_sector_cache == sector) - { - m_sector_cache = NULL; - } - /* - Remove from map and delete - */ - m_sectors.remove(*j); - delete sector; - } + // If sector is in sector cache, remove it from there + if(m_sector_cache == sector) + m_sector_cache = NULL; + // Remove from map and delete + m_sectors.remove(*j); + delete sector; } } -u32 Map::unloadUnusedData(float timeout, bool only_blocks, +void Map::unloadUnusedData(float timeout, core::list *deleted_blocks) { core::list sector_deletion_queue; + u32 deleted_blocks_count = 0; + u32 saved_blocks_count = 0; core::map::Iterator si = m_sectors.getIterator(); for(; si.atEnd() == false; si++) @@ -1453,14 +1440,18 @@ u32 Map::unloadUnusedData(float timeout, bool only_blocks, i != blocks.end(); i++) { MapBlock *block = (*i); - + if(block->getUsageTimer() > timeout) { // Save if modified if(block->getModified() != MOD_STATE_CLEAN) + { saveBlock(block); + saved_blocks_count++; + } // Delete from memory sector->deleteBlock(block); + deleted_blocks_count++; } else { @@ -1474,36 +1465,14 @@ u32 Map::unloadUnusedData(float timeout, bool only_blocks, } } -#if 0 - core::map::Iterator i = m_sectors.getIterator(); - for(; i.atEnd() == false; i++) - { - MapSector *sector = i.getNode()->getValue(); - /* - Delete sector from memory if it hasn't been used in a long time - */ - if(sector->usage_timer > timeout) - { - sector_deletion_queue.push_back(i.getNode()->getKey()); + deleteSectors(sector_deletion_queue); - if(deleted_blocks != NULL) - { - // Collect positions of blocks of sector - MapSector *sector = i.getNode()->getValue(); - core::list blocks; - sector->getBlocks(blocks); - for(core::list::Iterator i = blocks.begin(); - i != blocks.end(); i++) - { - deleted_blocks->push_back((*i)->getPos()); - } - } - } - } -#endif + dstream<<"Map: Unloaded "<vmanip.print(dstream);*/ @@ -2095,10 +2066,11 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data, //TimeTaker timer("finishBlockMake() blitBackAll"); data->vmanip->blitBackAll(&changed_blocks); } -#if 1 - dstream<<"finishBlockMake: changed_blocks.size()=" - < &list, bool only_blocks); + // If deleted sector is in sector cache, clears cache + void deleteSectors(core::list &list); - // Returns count of deleted sectors - u32 unloadUnusedData(float timeout, bool only_blocks=false, + /* + Unload unused data + = flush changed to disk and delete from memory, if usage timer of + block is more than timeout + */ + void unloadUnusedData(float timeout, core::list *deleted_blocks=NULL); // For debug printing diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 7036cd0..c125e67 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -38,7 +38,7 @@ MapBlock::MapBlock(Map *parent, v3s16 pos, bool dummy): m_generated(false), m_objects(this), m_timestamp(BLOCK_TIMESTAMP_UNDEFINED), - m_usage_timer(BLOCK_TIMESTAMP_UNDEFINED) + m_usage_timer(0) { data = NULL; if(dummy == false) diff --git a/src/mapgen.cpp b/src/mapgen.cpp index e481ee3..4a2a39a 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -1389,7 +1389,7 @@ void make_block(BlockMakeData *data) /* Create a block-specific seed */ - u32 blockseed = (data->seed%0x100000000) + full_node_min.Z*38134234 + u32 blockseed = (u32)(data->seed%0x100000000) + full_node_min.Z*38134234 + full_node_min.Y*42123 + full_node_min.X*23; /* diff --git a/src/server.cpp b/src/server.cpp index 2ee94f3..b65f0bd 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1831,17 +1831,21 @@ void Server::AsyncRunStep() JMutexAutoLock lock(m_env_mutex); if(((ServerMap*)(&m_env.getMap()))->isSavingEnabled() == true) { + // Unload unused data (delete from memory) + m_env.getMap().unloadUnusedData( + g_settings.getFloat("server_unload_unused_sectors_timeout")); + /*u32 deleted_count = m_env.getMap().unloadUnusedData( + g_settings.getFloat("server_unload_unused_sectors_timeout")); + */ + // Save only changed parts m_env.getMap().save(true); - // Delete unused sectors - u32 deleted_count = m_env.getMap().unloadUnusedData( - g_settings.getFloat("server_unload_unused_sectors_timeout")); - if(deleted_count > 0) + /*if(deleted_count > 0) { dout_server<<"Server: Unloaded "<