From cb130d9158dc4e9c456d088d5e214b7d829ccc3a Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 26 Jun 2011 00:03:58 +0300 Subject: cleaned map stuff --- src/map.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/map.h') diff --git a/src/map.h b/src/map.h index 86b6b6e18..99593a589 100644 --- a/src/map.h +++ b/src/map.h @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define MAP_HEADER #include +#include #include #include @@ -35,12 +36,17 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "common_irrlicht.h" #include "mapnode.h" #include "mapblock.h" -#include "mapsector.h" #include "constants.h" #include "voxel.h" #include "mapchunk.h" #include "nodemetadata.h" +class MapSector; +class ServerMapSector; +class ClientMapSector; + +class MapBlock; + namespace mapgen{ struct BlockMakeData; }; @@ -321,7 +327,6 @@ protected: core::map m_event_receivers; core::map m_sectors; - //JMutex m_sector_mutex; // Be sure to set this to NULL when the cached sector is deleted MapSector *m_sector_cache; @@ -547,7 +552,7 @@ public: */ MapSector * emergeSector(v2s16 p); - void deSerializeSector(v2s16 p2d, std::istream &is); + //void deSerializeSector(v2s16 p2d, std::istream &is); /* ISceneNode methods -- cgit v1.2.3 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/map.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/map.h') diff --git a/src/map.h b/src/map.h index 99593a589..406b1bc84 100644 --- a/src/map.h +++ b/src/map.h @@ -110,17 +110,17 @@ public: virtual void onMapEditEvent(MapEditEvent *event) = 0; }; -class Map : public NodeContainer +class Map /*: public NodeContainer*/ { public: Map(std::ostream &dout); virtual ~Map(); - virtual u16 nodeContainerId() const + /*virtual u16 nodeContainerId() const { return NODECONTAINER_ID_MAP; - } + }*/ virtual s32 mapType() const { -- cgit v1.2.3 From bb940a946dbca49dc03af83fe55d195bd9fdc62e Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 26 Jun 2011 02:34:36 +0300 Subject: even more code refactoring --- src/map.h | 68 ++++++--------------------------------------------------------- 1 file changed, 6 insertions(+), 62 deletions(-) (limited to 'src/map.h') diff --git a/src/map.h b/src/map.h index 406b1bc84..c64f8cbdb 100644 --- a/src/map.h +++ b/src/map.h @@ -25,27 +25,17 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include -#ifdef _WIN32 - #include - #define sleep_s(x) Sleep((x*1000)) -#else - #include - #define sleep_s(x) sleep(x) -#endif - #include "common_irrlicht.h" #include "mapnode.h" -#include "mapblock.h" +#include "mapblock_nodemod.h" #include "constants.h" #include "voxel.h" -#include "mapchunk.h" -#include "nodemetadata.h" class MapSector; class ServerMapSector; class ClientMapSector; - class MapBlock; +class NodeMetadata; namespace mapgen{ struct BlockMakeData; @@ -161,66 +151,20 @@ public: MapBlock * getBlockNoCreate(v3s16 p); // Returns NULL if not found MapBlock * getBlockNoCreateNoEx(v3s16 p); - // Gets an existing block or creates an empty one - //MapBlock * getBlockCreate(v3s16 p); // Returns InvalidPositionException if not found bool isNodeUnderground(v3s16 p); - // virtual from NodeContainer - bool isValidPosition(v3s16 p) - { - v3s16 blockpos = getNodeBlockPos(p); - MapBlock *blockref; - try{ - blockref = getBlockNoCreate(blockpos); - } - catch(InvalidPositionException &e) - { - return false; - } - return true; - /*v3s16 relpos = p - blockpos*MAP_BLOCKSIZE; - bool is_valid = blockref->isValidPosition(relpos); - return is_valid;*/ - } + bool isValidPosition(v3s16 p); - // virtual from NodeContainer // throws InvalidPositionException if not found - MapNode getNode(v3s16 p) - { - v3s16 blockpos = getNodeBlockPos(p); - MapBlock * blockref = getBlockNoCreate(blockpos); - v3s16 relpos = p - blockpos*MAP_BLOCKSIZE; + MapNode getNode(v3s16 p); - return blockref->getNodeNoCheck(relpos); - } - - // virtual from NodeContainer // throws InvalidPositionException if not found - void setNode(v3s16 p, MapNode & n) - { - v3s16 blockpos = getNodeBlockPos(p); - MapBlock * blockref = getBlockNoCreate(blockpos); - v3s16 relpos = p - blockpos*MAP_BLOCKSIZE; - blockref->setNodeNoCheck(relpos, n); - } + void setNode(v3s16 p, MapNode & n); // Returns a CONTENT_IGNORE node if not found - MapNode getNodeNoEx(v3s16 p) - { - try{ - v3s16 blockpos = getNodeBlockPos(p); - MapBlock * blockref = getBlockNoCreate(blockpos); - v3s16 relpos = p - blockpos*MAP_BLOCKSIZE; - - return blockref->getNodeNoCheck(relpos); - } - catch(InvalidPositionException &e) - { - return MapNode(CONTENT_IGNORE); - } - } + MapNode getNodeNoEx(v3s16 p); void unspreadLight(enum LightBank bank, core::map & from_nodes, -- 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/map.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/map.h') diff --git a/src/map.h b/src/map.h index c64f8cbdb..2fe749007 100644 --- a/src/map.h +++ b/src/map.h @@ -230,13 +230,18 @@ public: Updates usage timers */ void timerUpdate(float dtime); - + + // Deletes sectors and their blocks from memory // Takes cache into account - // sector mutex should be locked when calling - void deleteSectors(core::list &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 -- cgit v1.2.3 From dd22ea051a643a1ca2657958c8552849dc1ffa36 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 27 Jun 2011 00:27:17 +0300 Subject: map unloading is now a whole lot better --- src/map.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/map.h') diff --git a/src/map.h b/src/map.h index 2fe749007..71101b8e4 100644 --- a/src/map.h +++ b/src/map.h @@ -223,19 +223,23 @@ public: virtual void save(bool only_changed){assert(0);}; - // Server implements this + // Server implements this. + // Client leaves it as no-op. virtual void saveBlock(MapBlock *block){}; /* - Updates usage timers + Updates usage timers and unloads unused blocks and sectors. + Saves modified blocks before unloading on MAPTYPE_SERVER. */ - void timerUpdate(float dtime); + void timerUpdate(float dtime, float unload_timeout, + core::list *unloaded_blocks=NULL); // Deletes sectors and their blocks from memory // Takes cache into account // If deleted sector is in sector cache, clears cache void deleteSectors(core::list &list); - + +#if 0 /* Unload unused data = flush changed to disk and delete from memory, if usage timer of @@ -243,8 +247,9 @@ public: */ void unloadUnusedData(float timeout, core::list *deleted_blocks=NULL); +#endif - // For debug printing + // For debug printing. Prints "Map: ", "ServerMap: " or "ClientMap: " virtual void PrintInfo(std::ostream &out); void transformLiquids(core::map & modified_blocks); -- cgit v1.2.3 From 71f5d4b3443c6ea770463838a2c84b85d9fa3b21 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 1 Jul 2011 21:04:40 +0300 Subject: Fixed objects being sometimes not able to be stored statically in a block when block has been unloaded --- src/map.h | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'src/map.h') diff --git a/src/map.h b/src/map.h index 71101b8e4..a8aa8e679 100644 --- a/src/map.h +++ b/src/map.h @@ -57,7 +57,7 @@ enum MapEditEventType{ // Node metadata of block changed (not knowing which node exactly) // p stores block coordinate MEET_BLOCK_NODE_METADATA_CHANGED, - // Anything else + // Anything else (modified_blocks are set unsent) MEET_OTHER }; @@ -338,24 +338,13 @@ public: */ MapBlock * createBlock(v3s16 p); -#if 0 /* - NOTE: This comment might be outdated - Forcefully get a block from somewhere. - - InvalidPositionException possible if only_from_disk==true - - Parameters: - changed_blocks: Blocks that have been modified + - Memory + - Load from disk + - Generate */ - MapBlock * emergeBlock( - v3s16 p, - bool only_from_disk, - core::map &changed_blocks, - core::map &lighting_invalidated_blocks - ); -#endif + MapBlock * emergeBlock(v3s16 p, bool allow_generate=true); // Helper for placing objects on ground level s16 findGroundLevel(v2s16 p2d); -- cgit v1.2.3