]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/map.h
comments
[dragonfireclient.git] / src / map.h
index 8952bc1108faae56aab8a99afe9feace4da14b53..9140d4bf254372b50af39e9224ff101fe1714a27 100644 (file)
--- a/src/map.h
+++ b/src/map.h
@@ -41,177 +41,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "constants.h"
 #include "voxel.h"
 
-class Map;
-
-#if 0
-/*
-       A cache for short-term fast access to map data
-
-       NOTE: This doesn't really make anything more efficient
-       NOTE: Use VoxelManipulator, if possible
-       TODO: Get rid of this?
-       NOTE: CONFIRMED: THIS CACHE DOESN'T MAKE ANYTHING ANY FASTER
-*/
-class MapBlockPointerCache : public NodeContainer
-{
-public:
-       MapBlockPointerCache(Map *map);
-       ~MapBlockPointerCache();
-
-       virtual u16 nodeContainerId() const
-       {
-               return NODECONTAINER_ID_MAPBLOCKCACHE;
-       }
-
-       MapBlock * getBlockNoCreate(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;
-       }
-       
-       // virtual from NodeContainer
-       MapNode getNode(v3s16 p)
-       {
-               v3s16 blockpos = getNodeBlockPos(p);
-               MapBlock * blockref = getBlockNoCreate(blockpos);
-               v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
-
-               return blockref->getNodeNoCheck(relpos);
-       }
-
-       // virtual from NodeContainer
-       void setNode(v3s16 p, MapNode & n)
-       {
-               v3s16 blockpos = getNodeBlockPos(p);
-               MapBlock * block = getBlockNoCreate(blockpos);
-               v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
-               block->setNodeNoCheck(relpos, n);
-               m_modified_blocks[blockpos] = block;
-       }
-
-       core::map<v3s16, MapBlock*> m_modified_blocks;
-       
-private:
-       Map *m_map;
-       core::map<v3s16, MapBlock*> m_blocks;
-
-       u32 m_from_cache_count;
-       u32 m_from_map_count;
-};
-#endif
-
-class CacheLock
-{
-public:
-       CacheLock()
-       {
-               m_count = 0;
-               m_count_mutex.Init();
-               m_cache_mutex.Init();
-               m_waitcache_mutex.Init();
-       }
-
-       void cacheCreated()
-       {
-               //dstream<<"cacheCreated() begin"<<std::endl;
-               JMutexAutoLock waitcachelock(m_waitcache_mutex);
-               JMutexAutoLock countlock(m_count_mutex);
-
-               // If this is the first cache, grab the cache lock
-               if(m_count == 0)
-                       m_cache_mutex.Lock();
-                       
-               m_count++;
-
-               //dstream<<"cacheCreated() end"<<std::endl;
-       }
-
-       void cacheRemoved()
-       {
-               //dstream<<"cacheRemoved() begin"<<std::endl;
-               JMutexAutoLock countlock(m_count_mutex);
-
-               assert(m_count > 0);
-
-               m_count--;
-               
-               // If this is the last one, release the cache lock
-               if(m_count == 0)
-                       m_cache_mutex.Unlock();
-
-               //dstream<<"cacheRemoved() end"<<std::endl;
-       }
-
-       /*
-               This lock should be taken when removing stuff that can be
-               pointed by the cache.
-
-               You'll want to grab this in a SharedPtr.
-       */
-       JMutexAutoLock * waitCaches()
-       {
-               //dstream<<"waitCaches() begin"<<std::endl;
-               JMutexAutoLock waitcachelock(m_waitcache_mutex);
-               JMutexAutoLock *lock = new JMutexAutoLock(m_cache_mutex);
-               //dstream<<"waitCaches() end"<<std::endl;
-               return lock;
-       }
-
-private:
-       // Count of existing caches
-       u32 m_count;
-       JMutex m_count_mutex;
-       // This is locked always when there are some caches
-       JMutex m_cache_mutex;
-       // Locked so that when waitCaches() is called, no more caches are created
-       JMutex m_waitcache_mutex;
-};
-
 #define MAPTYPE_BASE 0
 #define MAPTYPE_SERVER 1
 #define MAPTYPE_CLIENT 2
 
 class Map : public NodeContainer, public Heightmappish
 {
-protected:
-
-       std::ostream &m_dout;
-
-       core::map<v2s16, MapSector*> m_sectors;
-       JMutex m_sector_mutex;
-
-       v3f m_camera_position;
-       v3f m_camera_direction;
-       JMutex m_camera_mutex;
-
-       // Be sure to set this to NULL when the cached sector is deleted 
-       MapSector *m_sector_cache;
-       v2s16 m_sector_cache_p;
-
-       WrapperHeightmap m_hwrapper;
-
 public:
 
-       v3s16 drawoffset; // for drawbox()
-       
-       /*
-               Used by MapBlockPointerCache.
-
-               waitCaches() can be called to remove all caches before continuing
-       */
-       CacheLock m_blockcachelock;
-
        Map(std::ostream &dout);
        virtual ~Map();
 
@@ -237,23 +74,6 @@ class Map : public NodeContainer, public Heightmappish
                m_camera_direction = dir;
        }
 
-       /*void StartUpdater()
-       {
-               updater.Start();
-       }
-
-       void StopUpdater()
-       {
-               updater.setRun(false);
-               while(updater.IsRunning())
-                       sleep_s(1);
-       }
-
-       bool UpdaterIsRunning()
-       {
-               return updater.IsRunning();
-       }*/
-
        static core::aabbox3d<f32> getNodeBox(v3s16 p)
        {
                return core::aabbox3d<f32>(
@@ -273,7 +93,7 @@ class Map : public NodeContainer, public Heightmappish
                their differing fetch methods.
        */
        virtual MapSector * emergeSector(v2s16 p) = 0;
-       
+
        // Returns InvalidPositionException if not found
        MapBlock * getBlockNoCreate(v3s16 p);
        // Returns NULL if not found
@@ -384,10 +204,13 @@ class Map : public NodeContainer, public Heightmappish
        void expireMeshes(bool only_daynight_diffed);
        
        /*
-               Updates the faces of the given block and blocks on the
+               Update the faces of the given block and blocks on the
                leading edge.
        */
        void updateMeshes(v3s16 blockpos, u32 daynight_ratio);
+       
+       // Update meshes that touch the node
+       //void updateNodeMeshes(v3s16 nodepos, u32 daynight_ratio);
 #endif
 
        /*
@@ -416,6 +239,32 @@ class Map : public NodeContainer, public Heightmappish
 
        // For debug printing
        virtual void PrintInfo(std::ostream &out);
+       
+       void transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks);
+
+       /*
+               Variables
+       */
+       
+protected:
+
+       std::ostream &m_dout;
+
+       core::map<v2s16, MapSector*> m_sectors;
+       JMutex m_sector_mutex;
+
+       v3f m_camera_position;
+       v3f m_camera_direction;
+       JMutex m_camera_mutex;
+
+       // Be sure to set this to NULL when the cached sector is deleted 
+       MapSector *m_sector_cache;
+       v2s16 m_sector_cache_p;
+
+       WrapperHeightmap m_hwrapper;
+       
+       // Queued transforming water nodes
+       UniqueQueue<v3s16> m_transforming_liquid;
 };
 
 // Master heightmap parameters
@@ -448,6 +297,12 @@ struct MapParams
        //u16 max_objects_in_block;
 };
 
+/*
+       ServerMap
+
+       This is the only map class that is able to generate map.
+*/
+
 class ServerMap : public Map
 {
 public:
@@ -534,8 +389,10 @@ class ServerMap : public Map
        virtual void PrintInfo(std::ostream &out);
 
 private:
+       // Generator parameters
        UnlimitedHeightmap *m_heightmap;
        MapParams m_params;
+       PointAttributeDatabase m_padb;
 
        std::string m_savedir;
        bool m_map_saving_enabled;
@@ -543,16 +400,45 @@ class ServerMap : public Map
 
 #ifndef SERVER
 
+struct MapDrawControl
+{
+       MapDrawControl():
+               range_all(false),
+               wanted_range(50),
+               wanted_max_blocks(0),
+               wanted_min_range(0),
+               blocks_drawn(0),
+               blocks_would_have_drawn(0)
+       {
+       }
+       // Overrides limits by drawing everything
+       bool range_all;
+       // Wanted drawing range
+       float wanted_range;
+       // Maximum number of blocks to draw
+       u32 wanted_max_blocks;
+       // Blocks in this range are drawn regardless of number of blocks drawn
+       float wanted_min_range;
+       // Number of blocks rendered is written here by the renderer
+       u32 blocks_drawn;
+       // Number of blocks that would have been drawn in wanted_range
+       u32 blocks_would_have_drawn;
+};
+
 class Client;
 
+/*
+       ClientMap
+       
+       This is the only map class that is able to render itself on screen.
+*/
+
 class ClientMap : public Map, public scene::ISceneNode
 {
 public:
        ClientMap(
                        Client *client,
-                       JMutex &range_mutex,
-                       float &viewing_range_nodes,
-                       bool &viewing_range_all,
+                       MapDrawControl &control,
                        scene::ISceneNode* parent,
                        scene::ISceneManager* mgr,
                        s32 id
@@ -600,10 +486,16 @@ class ClientMap : public Map, public scene::ISceneNode
        /*
                Methods for setting temporary modifications to nodes for
                drawing.
-               Return value is position of changed block.
+
+               Returns true if something changed.
+               
+               All blocks whose mesh could have been changed are inserted
+               to affected_blocks.
        */
-       v3s16 setTempMod(v3s16 p, NodeMod mod);
-       v3s16 clearTempMod(v3s16 p);
+       bool setTempMod(v3s16 p, NodeMod mod,
+                       core::map<v3s16, MapBlock*> *affected_blocks=NULL);
+       bool clearTempMod(v3s16 p,
+                       core::map<v3s16, MapBlock*> *affected_blocks=NULL);
        // Efficient implementation needs a cache of TempMods
        //void clearTempMods();
 
@@ -618,10 +510,8 @@ class ClientMap : public Map, public scene::ISceneNode
        // This is the master heightmap mesh
        scene::SMesh *mesh;
        JMutex mesh_mutex;
-
-       JMutex &m_range_mutex;
-       float &m_viewing_range_nodes;
-       bool &m_viewing_range_all;
+       
+       MapDrawControl &m_control;
 };
 
 #endif
@@ -642,7 +532,7 @@ class MapVoxelManipulator : public VoxelManipulator
 
        void blitBack(core::map<v3s16, MapBlock*> & modified_blocks);
 
-private:
+protected:
        Map *m_map;
        /*
                NOTE: This might be used or not
@@ -653,5 +543,18 @@ class MapVoxelManipulator : public VoxelManipulator
        core::map<v3s16, bool> m_loaded_blocks;
 };
 
+class ManualMapVoxelManipulator : public MapVoxelManipulator
+{
+public:
+       ManualMapVoxelManipulator(Map *map);
+       virtual ~ManualMapVoxelManipulator();
+       
+       virtual void emerge(VoxelArea a, s32 caller_id=-1);
+
+       void initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max);
+
+protected:
+};
+
 #endif