]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/map.cpp
improved old map support
[dragonfireclient.git] / src / map.cpp
index c258d157b79ba3115e6eb6e403cc83fdcf589f78..ff823af94aaf05bf24da6d4650f17f515407134f 100644 (file)
@@ -1801,7 +1801,6 @@ ServerMap::ServerMap(std::string savedir):
        //m_chunksize = 4;
        //m_chunksize = 2;
        
-       // TODO: Save to and load from a file
        m_seed = (((u64)(myrand()%0xffff)<<0)
                        + ((u64)(myrand()%0xffff)<<16)
                        + ((u64)(myrand()%0xffff)<<32)
@@ -1835,11 +1834,19 @@ ServerMap::ServerMap(std::string savedir):
                        }
                        else
                        {
-                               // Load map metadata (seed, chunksize)
-                               loadMapMeta();
-                               
-                               // Load chunk metadata
-                               loadChunkMeta();
+                               try{
+                                       // Load map metadata (seed, chunksize)
+                                       loadMapMeta();
+
+                                       // Load chunk metadata
+                                       loadChunkMeta();
+                               }
+                               catch(FileNotGoodException &e){
+                                       dstream<<DTIME<<"WARNING: Server: Could not load "
+                                                       <<"metafile(s). Disabling chunk-based "
+                                                       <<"generation."<<std::endl;
+                                       m_chunksize = 0;
+                               }
                        
                                /*// Load sector (0,0) and throw and exception on fail
                                if(loadSectorFull(v2s16(0,0)) == false)
@@ -2173,6 +2180,9 @@ void addRandomObjects(MapBlock *block)
 
 void makeChunk(ChunkMakeData *data)
 {
+       if(data->no_op)
+               return;
+       
        s16 y_nodes_min = data->y_blocks_min * MAP_BLOCKSIZE;
        s16 y_nodes_max = data->y_blocks_max * MAP_BLOCKSIZE + MAP_BLOCKSIZE - 1;
        s16 h_blocks = data->y_blocks_max - data->y_blocks_min + 1;
@@ -2938,8 +2948,8 @@ void makeChunk(ChunkMakeData *data)
 
                                        // Add to transforming liquid queue (in case it'd
                                        // start flowing)
-                                       /*v3s16 p = v3s16(p2d.X, y, p2d.Y);
-                                       m_transforming_liquid.push_back(p);*/
+                                       v3s16 p = v3s16(p2d.X, y, p2d.Y);
+                                       data->transforming_liquid.push_back(p);
                                }
                                
                                // Next one
@@ -3419,6 +3429,14 @@ void makeChunk(ChunkMakeData *data)
 
 void ServerMap::initChunkMake(ChunkMakeData &data, v2s16 chunkpos)
 {
+       if(m_chunksize == 0)
+       {
+               data.no_op = true;
+               return;
+       }
+
+       data.no_op = false;
+
        // The distance how far into the neighbors the generator is allowed to go.
        s16 max_spread_amount_sectors = 2;
        assert(max_spread_amount_sectors <= m_chunksize);
@@ -3449,7 +3467,7 @@ void ServerMap::initChunkMake(ChunkMakeData &data, v2s16 chunkpos)
                Create the whole area of this and the neighboring chunks
        */
        {
-               TimeTaker timer("generateChunkRaw() create area");
+               TimeTaker timer("initChunkMake() create area");
                
                for(s16 x=0; x<sectorpos_bigbase_size; x++)
                for(s16 z=0; z<sectorpos_bigbase_size; z++)
@@ -3503,7 +3521,7 @@ void ServerMap::initChunkMake(ChunkMakeData &data, v2s16 chunkpos)
        data.vmanip.setMap(this);
        // Add the area
        {
-               TimeTaker timer("generateChunkRaw() initialEmerge");
+               TimeTaker timer("initChunkMake() initialEmerge");
                data.vmanip.initialEmerge(bigarea_blocks_min, bigarea_blocks_max);
        }
        
@@ -3512,6 +3530,9 @@ void ServerMap::initChunkMake(ChunkMakeData &data, v2s16 chunkpos)
 MapChunk* ServerMap::finishChunkMake(ChunkMakeData &data,
                core::map<v3s16, MapBlock*> &changed_blocks)
 {
+       if(data.no_op)
+               return NULL;
+       
        /*
                Blit generated stuff to map
        */
@@ -3533,6 +3554,15 @@ MapChunk* ServerMap::finishChunkMake(ChunkMakeData &data,
                }
        }
 
+       /*
+               Copy transforming liquid information
+       */
+       while(data.transforming_liquid.size() > 0)
+       {
+               v3s16 p = data.transforming_liquid.pop_front();
+               m_transforming_liquid.push_back(p);
+       }
+
        /*
                Add random objects to blocks
        */
@@ -3590,6 +3620,7 @@ MapChunk* ServerMap::finishChunkMake(ChunkMakeData &data,
        return chunk;
 }
 
+#if 0
 // NOTE: Deprecated
 MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos,
                core::map<v3s16, MapBlock*> &changed_blocks,
@@ -3661,6 +3692,7 @@ MapChunk* ServerMap::generateChunk(v2s16 chunkpos1,
        MapChunk *chunk = getChunk(chunkpos1);
        return chunk;
 }
+#endif
 
 ServerMapSector * ServerMap::createSector(v2s16 p2d)
 {
@@ -3715,6 +3747,7 @@ ServerMapSector * ServerMap::createSector(v2s16 p2d)
        return sector;
 }
 
+#if 0
 MapSector * ServerMap::emergeSector(v2s16 p2d,
                core::map<v3s16, MapBlock*> &changed_blocks)
 {
@@ -3801,6 +3834,7 @@ MapSector * ServerMap::emergeSector(v2s16 p2d,
        */
        //return generateSector();
 }
+#endif
 
 /*
        NOTE: This is not used for main map generation, only for blocks
@@ -3817,6 +3851,14 @@ MapBlock * ServerMap::generateBlock(
        DSTACK("%s: p=(%d,%d,%d)",
                        __FUNCTION_NAME,
                        p.X, p.Y, p.Z);
+
+       // If chunks are disabled
+       /*if(m_chunksize == 0)
+       {
+               dstream<<"ServerMap::generateBlock(): Chunks disabled -> "
+                               <<"not generating."<<std::endl;
+               return NULL;
+       }*/
        
        /*dstream<<"generateBlock(): "
                        <<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
@@ -3869,6 +3911,9 @@ MapBlock * ServerMap::generateBlock(
 
                s16 surface_y = base_rock_level_2d(m_seed, p2d_nodes+v2s16(x0,z0))
                                + AVERAGE_MUD_AMOUNT;
+               // If chunks are disabled
+               if(m_chunksize == 0)
+                       surface_y = WATER_LEVEL + 1;
 
                if(surface_y < lowest_ground_y)
                        lowest_ground_y = surface_y;
@@ -4735,7 +4780,12 @@ void ServerMap::save(bool only_changed)
                                <<std::endl;
        
        saveMapMeta();
-       saveChunkMeta();
+
+       // Disable saving chunk metadata file if chunks are disabled
+       if(m_chunksize != 0)
+       {
+               saveChunkMeta();
+       }
        
        u32 sector_meta_count = 0;
        u32 block_count = 0;
@@ -4789,6 +4839,8 @@ void ServerMap::save(bool only_changed)
        }
 }
 
+#if 0
+// NOTE: Doing this is insane. Deprecated and probably broken.
 void ServerMap::loadAll()
 {
        DSTACK(__FUNCTION_NAME);
@@ -4849,6 +4901,7 @@ void ServerMap::loadAll()
        }
        dstream<<DTIME<<"ServerMap: Map loaded."<<std::endl;
 }
+#endif
 
 #if 0
 void ServerMap::saveMasterHeightmap()
@@ -4914,7 +4967,7 @@ void ServerMap::loadMapMeta()
 {
        DSTACK(__FUNCTION_NAME);
        
-       dstream<<"INFO: ServerMap::loadMapMeta(): Loading chunk metadata"
+       dstream<<"INFO: ServerMap::loadMapMeta(): Loading map metadata"
                        <<std::endl;
 
        std::string fullpath = m_savedir + "/map_meta.txt";
@@ -4923,7 +4976,7 @@ void ServerMap::loadMapMeta()
        {
                dstream<<"ERROR: ServerMap::loadMapMeta(): "
                                <<"could not open"<<fullpath<<std::endl;
-               throw FileNotGoodException("Cannot open chunk metadata");
+               throw FileNotGoodException("Cannot open map metadata");
        }
 
        Settings params;
@@ -4952,6 +5005,9 @@ void ServerMap::loadMapMeta()
 void ServerMap::saveChunkMeta()
 {
        DSTACK(__FUNCTION_NAME);
+
+       // This should not be called if chunks are disabled.
+       assert(m_chunksize != 0);
        
        u32 count = m_chunks.size();
 
@@ -5065,14 +5121,31 @@ MapSector* ServerMap::loadSectorMeta(std::string dirname)
        // Get destination
        v2s16 p2d = getSectorPos(dirname);
        std::string dir = m_savedir + "/sectors/" + dirname;
+
+       ServerMapSector *sector = NULL;
        
        std::string fullpath = dir + "/meta";
        std::ifstream is(fullpath.c_str(), std::ios_base::binary);
        if(is.good() == false)
-               throw FileNotGoodException("Cannot open sector metafile");
-
-       ServerMapSector *sector = ServerMapSector::deSerialize
-                       (is, this, p2d, m_sectors);
+       {
+               // If the directory exists anyway, it probably is in some old
+               // format. Just go ahead and create the sector.
+               if(fs::PathExists(dir))
+               {
+                       dstream<<"ServerMap::loadSectorMeta(): Sector metafile "
+                                       <<fullpath<<" doesn't exist but directory does."
+                                       <<" Continuing with a sector with no metadata."
+                                       <<std::endl;
+                       sector = createSector(p2d);
+               }
+               else
+                       throw FileNotGoodException("Cannot open sector metafile");
+       }
+       else
+       {
+               sector = ServerMapSector::deSerialize
+                               (is, this, p2d, m_sectors);
+       }
        
        sector->differs_from_disk = false;