- added map generating script
authorPerttu Ahola <celeron55@gmail.com>
Mon, 29 Nov 2010 10:16:17 +0000 (12:16 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Mon, 29 Nov 2010 10:16:17 +0000 (12:16 +0200)
- dropped support for versions older than 2 because of lighting support

genmap.py [new file with mode: 0755]
src/client.cpp
src/map.cpp
src/serialization.h

diff --git a/genmap.py b/genmap.py
new file mode 100755 (executable)
index 0000000..8949888
--- /dev/null
+++ b/genmap.py
@@ -0,0 +1,38 @@
+#!/usr/bin/python
+
+import struct
+import random
+
+def getrand():
+       i = random.randrange(0,2)
+       if i==0:
+               return 0
+       return 254
+
+"""
+Map format:
+map/sectors/XXXXZZZZ/YYYY
+
+XXXX,YYYY,ZZZZ = coordinates in hexadecimal
+
+fffe = -2
+ffff = -1
+0000 =  0
+0001 =  1
+"""
+
+f = open("map/sectors/00000000/ffff", "wb")
+
+# version
+f.write(struct.pack('B', 2))
+# is_underground
+f.write(struct.pack('B', 0))
+
+for i in range(0,16*16*16):
+       # Material content
+       f.write(struct.pack('B', getrand()))
+       # Brightness
+       f.write(struct.pack('B', 15))
+
+f.close()
+
index cf9feed7d470ed09cc4413e0092469d2481a86a9..b461549d2fbf2b36b100eb15df732325ca09105d 100644 (file)
@@ -148,9 +148,9 @@ void Client::step(float dtime)
                counter -= dtime;
                if(counter <= 0.0)
                {
-                       counter = 10.0;
+                       counter = 20.0;
                        
-                       dout_client<<"Client packetcounter:"<<std::endl;
+                       dout_client<<"Client packetcounter (20s):"<<std::endl;
                        m_packetcounter.print(dout_client);
                        m_packetcounter.clear();
                }
index f5b63d5af5a06532d029a34f55f3f33e9e1d050a..1fbaf0899043e13f2d8c14885ae89681ec64289b 100644 (file)
@@ -1780,16 +1780,15 @@ MapBlock * ServerMap::emergeBlock(
                                MapNode n;
                                n.d = MATERIAL_MESE;
                                
-                               if(rand()%8 == 0)
-                                       block->setNode(cp, n);
+                               if(is_ground_material(block->getNode(cp).d))
+                                       if(rand()%8 == 0)
+                                               block->setNode(cp, n);
 
                                for(u16 i=0; i<26; i++)
                                {
-                                       if(!is_ground_material(block->getNode(cp+g_26dirs[i]).d))
-                                               continue;
-
-                                       if(rand()%8 == 0)
-                                               block->setNode(cp+g_26dirs[i], n);
+                                       if(is_ground_material(block->getNode(cp+g_26dirs[i]).d))
+                                               if(rand()%8 == 0)
+                                                       block->setNode(cp+g_26dirs[i], n);
                                }
                        }
                }
@@ -1798,15 +1797,25 @@ MapBlock * ServerMap::emergeBlock(
        /*
                Create a few rats in empty blocks underground
        */
-       /*if(is_underground && low_block_is_empty == true)
+       if(is_underground)
        {
                //for(u16 i=0; i<2; i++)
                {
-                       v3s16 pos(8, 1, 8);
-                       RatObject *obj = new RatObject(NULL, -1, intToFloat(pos));
-                       block->addObject(obj);
+                       v3s16 cp(
+                               (rand()%(MAP_BLOCKSIZE-2))+1,
+                               (rand()%(MAP_BLOCKSIZE-2))+1,
+                               (rand()%(MAP_BLOCKSIZE-2))+1
+                       );
+
+                       // Check that the place is empty
+                       //if(!is_ground_material(block->getNode(cp).d))
+                       if(1)
+                       {
+                               RatObject *obj = new RatObject(NULL, -1, intToFloat(cp));
+                               block->addObject(obj);
+                       }
                }
-       }*/
+       }
        
        /*
                Add block to sector.
@@ -2491,31 +2500,8 @@ void ServerMap::loadBlock(std::string sectordir, std::string blockfile, MapSecto
                Convert old formats to new and save
        */
 
-       if(version == 0 || version == 1)
-       {
-               dstream<<"Block ("<<p3d.X<<","<<p3d.Y<<","<<p3d.Z<<")"
-                               " is in old format. Updating lighting and saving"
-                               " modified blocks in new format."<<std::endl;
-
-               // Old version has zero lighting, update it
-               core::map<v3s16, MapBlock*> blocks_changed;
-               blocks_changed.insert(block->getPos(), block);
-               core::map<v3s16, MapBlock*> modified_blocks;
-               updateLighting(blocks_changed, modified_blocks);
-               
-               // Close input file
-               is.close();
-               
-               // Save modified blocks
-               core::map<v3s16, MapBlock * >::Iterator i = modified_blocks.getIterator();
-               for(; i.atEnd() == false; i++)
-               {
-                       MapBlock *b2 = i.getNode()->getValue();
-                       saveBlock(b2);
-               }
-       }
-       // Save blocks in new format
-       else if(version < SER_FMT_VER_HIGHEST)
+       // Save old format blocks in new format
+       if(version < SER_FMT_VER_HIGHEST)
        {
                saveBlock(block);
        }
index fd9b39535680cf3910089e2bfd04a8a90f99cabf..b55625a4bb075630434ba83540945dca5041b97f 100644 (file)
              loadable by any version. Other compatibility is not
                  maintained.
        Serialization format versions:
+       == Unsupported ==
        0: original networked test with 1-byte nodes
        1: update with 2-byte nodes
+       == Supported ==
        2: lighting is transmitted in param
        3: optional fetching of far blocks
        4: block compression
@@ -31,7 +33,7 @@
 // Highest supported serialization version
 #define SER_FMT_VER_HIGHEST 9
 // Lowest supported serialization version
-#define SER_FMT_VER_LOWEST 0
+#define SER_FMT_VER_LOWEST 2
 
 #define ser_ver_supported(v) (v >= SER_FMT_VER_LOWEST && v <= SER_FMT_VER_HIGHEST)