From 2915bd5518150955ed1581110527f4bb4adadfe8 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 26 Jun 2011 01:31:43 +0300 Subject: more reorganizing of map code --- src/mapblock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mapblock.cpp') diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 2f6a4b850..7036cd035 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., MapBlock */ -MapBlock::MapBlock(NodeContainer *parent, v3s16 pos, bool dummy): +MapBlock::MapBlock(Map *parent, v3s16 pos, bool dummy): m_parent(parent), m_pos(pos), m_modified(MOD_STATE_WRITE_NEEDED), -- cgit v1.2.3 From 3fccc67eb7c530c280e9b496e22288ffa772152d Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 26 Jun 2011 21:53:11 +0300 Subject: fixed block unloading from memory (a better fix coming next) --- src/client.cpp | 10 +++--- src/defaultsettings.cpp | 1 + src/environment.cpp | 3 ++ src/map.cpp | 95 ++++++++++++++++++++----------------------------- src/map.h | 15 +++++--- src/mapblock.cpp | 2 +- src/mapgen.cpp | 2 +- src/server.cpp | 16 +++++---- 8 files changed, 70 insertions(+), 74 deletions(-) (limited to 'src/mapblock.cpp') diff --git a/src/client.cpp b/src/client.cpp index 248cd8a4c..449b0c2f2 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 5bf278667..2cf7bb2e5 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 7036cd035..c125e67c8 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 e481ee30c..4a2a39aec 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 2ee94f345..b65f0bdb5 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 "< Date: Sat, 2 Jul 2011 01:07:54 +0300 Subject: initial steps in doing content type extension --- src/content_mapnode.cpp | 1 - src/mapblock.cpp | 59 ++++++--------------- src/mapnode.cpp | 92 +++++++++++++++++++++++++++++++- src/mapnode.h | 138 +++++++++++++++--------------------------------- src/serialization.h | 5 +- 5 files changed, 151 insertions(+), 144 deletions(-) (limited to 'src/mapblock.cpp') diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp index 403fb66d3..d82ccc5c9 100644 --- a/src/content_mapnode.cpp +++ b/src/content_mapnode.cpp @@ -151,7 +151,6 @@ void content_mapnode_init() // Deprecated i = CONTENT_COALSTONE; f = &content_features(i); - //f->translate_to = new MapNode(CONTENT_STONE, MINERAL_COAL); f->setAllTextures("stone.png^mineral_coal.png"); f->is_ground_content = true; setStoneLikeDiggingProperties(f->digging_properties, 1.5); diff --git a/src/mapblock.cpp b/src/mapblock.cpp index c125e67c8..647a17756 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -607,24 +607,20 @@ void MapBlock::serialize(std::ostream &os, u8 version) Get data */ - SharedBuffer databuf(nodecount*3); - - // Get contents + // Serialize nodes + SharedBuffer databuf_nodelist(nodecount*3); for(u32 i=0; i databuf(nodecount*3); for(u32 i=0; id< 0) + param = 0; + else + param = source[1]; + } + else if(version <= 9) + { + d = source[0]; + param = source[1]; + } + else + { + d = source[0]; + param = source[1]; + param2 = source[2]; + + // Convert from old version to new + if(version <= 18) + { + // In these versions, CONTENT_IGNORE and CONTENT_AIR + // are 255 and 254 + if(d == 255) + d = CONTENT_IGNORE; + else if(d == 254) + d = CONTENT_AIR; + } + } +} + /* Gets lighting value at face of node diff --git a/src/mapnode.h b/src/mapnode.h index eb4b17e48..36d48fb9e 100644 --- a/src/mapnode.h +++ b/src/mapnode.h @@ -36,6 +36,13 @@ with this program; if not, write to the Free Software Foundation, Inc., - Tile = TileSpec at some side of a node of some content type */ +/* + Ranges: + 0x000...0x07f: param2 is fully usable + 0x800...0xfff: param2 lower 4 bytes are free +*/ +typedef u16 content_t; + /* Initializes all kind of stuff in here. Many things depend on this. @@ -59,14 +66,16 @@ void init_mapnode(); Doesn't create faces with anything and is considered being out-of-map in the game map. */ -#define CONTENT_IGNORE 255 +//#define CONTENT_IGNORE 255 +#define CONTENT_IGNORE 127 #define CONTENT_IGNORE_DEFAULT_PARAM 0 /* The common material through which the player can walk and which is transparent to light */ -#define CONTENT_AIR 254 +//#define CONTENT_AIR 254 +#define CONTENT_AIR 126 /* Content feature list @@ -94,7 +103,7 @@ class NodeMetadata; struct ContentFeatures { // If non-NULL, content is translated to this when deserialized - MapNode *translate_to; + //MapNode *translate_to; // Type of MapNode::param ContentParamType param_type; @@ -154,7 +163,7 @@ struct ContentFeatures void reset() { - translate_to = NULL; + //translate_to = NULL; param_type = CPT_NONE; inventory_texture = NULL; is_ground_content = false; @@ -399,20 +408,30 @@ enum LightBank struct MapNode { - // Content - u8 d; + /* + Main content + 0x00-0x7f: Short content type + 0x80-0xff: Long content type (param2>>4 makes up low bytes) + */ + union + { + u8 param0; + u8 d; + }; /* Misc parameter. Initialized to 0. - For light_propagates() blocks, this is light intensity, stored logarithmically from 0 to LIGHT_MAX. Sunlight is LIGHT_SUN, which is LIGHT_MAX+1. - - Contains 2 values, day- and night lighting. Each takes 4 bits. + - Contains 2 values, day- and night lighting. Each takes 4 bits. + - Mineral content (should be removed from here) + - Uhh... well, most blocks have light or nothing in here. */ union { - s8 param; u8 param1; + s8 param; }; /* @@ -437,14 +456,6 @@ struct MapNode param2 = a_param2; } - /*MapNode & operator=(const MapNode &other) - { - d = other.d; - param = other.param; - param2 = other.param2; - return *this; - }*/ - bool operator==(const MapNode &other) { return (d == other.d @@ -452,6 +463,16 @@ struct MapNode && param2 == other.param2); } + // To be used everywhere + content_t getContent() + { + return d; + } + void setContent(content_t c) + { + d = c; + } + /* These four are DEPRECATED I guess. -c55 */ @@ -566,88 +587,15 @@ struct MapNode MINERAL_NONE if doesn't contain or isn't able to contain mineral. */ u8 getMineral(); - + /* - These serialization functions are used when informing client - of a single node add. - - NOTE: When loading a MapBlock, these are not used. Should they? + Serialization functions */ - static u32 serializedLength(u8 version) - { - if(!ser_ver_supported(version)) - throw VersionMismatchException("ERROR: MapNode format not supported"); - - if(version == 0) - return 1; - else if(version <= 9) - return 2; - else - return 3; - } - void serialize(u8 *dest, u8 version) - { - if(!ser_ver_supported(version)) - throw VersionMismatchException("ERROR: MapNode format not supported"); - - if(version == 0) - { - dest[0] = d; - } - else if(version <= 9) - { - dest[0] = d; - dest[1] = param; - } - else - { - dest[0] = d; - dest[1] = param; - dest[2] = param2; - } - } - void deSerialize(u8 *source, u8 version) - { - if(!ser_ver_supported(version)) - throw VersionMismatchException("ERROR: MapNode format not supported"); - - if(version == 0) - { - d = source[0]; - } - else if(version == 1) - { - d = source[0]; - // This version doesn't support saved lighting - if(light_propagates() || light_source() > 0) - param = 0; - else - param = source[1]; - } - else if(version <= 9) - { - d = source[0]; - param = source[1]; - } - else - { - d = source[0]; - param = source[1]; - param2 = source[2]; - } - - // Translate deprecated stuff - // NOTE: This doesn't get used because MapBlock handles node - // parameters directly - MapNode *translate_to = content_features(d).translate_to; - if(translate_to) - { - dstream<<"MapNode: WARNING: Translating "<d<