Initial commit of mapgen v.2. Lacks configuration and saving to disk.
[oweals/minetest.git] / src / map.h
index 3b34cd899e4edbb3e75bda9c3b2dc89998021f07..3385d7c68a99d18d66ea129ef5a054c805d97f66 100644 (file)
--- a/src/map.h
+++ b/src/map.h
@@ -41,74 +41,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "constants.h"
 #include "voxel.h"
 
-class Map;
-
-/*
-       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;
-};
-
 class CacheLock
 {
 public:
@@ -207,6 +139,9 @@ public:
                Used by MapBlockPointerCache.
 
                waitCaches() can be called to remove all caches before continuing
+
+               TODO: Remove this, MapBlockPointerCache doesn't exist anymore,
+                     because it doesn't give any speed benefits
        */
        CacheLock m_blockcachelock;
 
@@ -274,7 +209,8 @@ public:
        
        // Returns InvalidPositionException if not found
        MapBlock * getBlockNoCreate(v3s16 p);
-       //virtual MapBlock * getBlock(v3s16 p, bool generate=true);
+       // Returns NULL if not found
+       MapBlock * getBlockNoCreateNoEx(v3s16 p);
        
        // Returns InvalidPositionException if not found
        f32 getGroundHeight(v2s16 p, bool generate=false);
@@ -302,6 +238,7 @@ public:
        }
        
        // virtual from NodeContainer
+       // throws InvalidPositionException if not found
        MapNode getNode(v3s16 p)
        {
                v3s16 blockpos = getNodeBlockPos(p);
@@ -312,6 +249,7 @@ public:
        }
 
        // virtual from NodeContainer
+       // throws InvalidPositionException if not found
        void setNode(v3s16 p, MapNode & n)
        {
                v3s16 blockpos = getNodeBlockPos(p);
@@ -386,7 +324,7 @@ public:
 #endif
 
        /*
-               Takes the blocks at the leading edges into account
+               Takes the blocks at the edges into account
        */
        bool dayNightDiffed(v3s16 blockpos);
 
@@ -443,6 +381,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:
@@ -529,8 +473,10 @@ public:
        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;
@@ -538,16 +484,45 @@ private:
 
 #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,
-                       s16 &viewing_range_nodes,
-                       bool &viewing_range_all,
+                       MapDrawControl &control,
                        scene::ISceneNode* parent,
                        scene::ISceneManager* mgr,
                        s32 id
@@ -613,10 +588,8 @@ private:
        // This is the master heightmap mesh
        scene::SMesh *mesh;
        JMutex mesh_mutex;
-
-       JMutex &m_range_mutex;
-       s16 &m_viewing_range_nodes;
-       bool &m_viewing_range_all;
+       
+       MapDrawControl &m_control;
 };
 
 #endif