From 52d99fef31daa60903053bc565b6b9d3a31a2bc8 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 11 Feb 2011 19:55:42 +0200 Subject: fully working i guess --- src/map.cpp | 309 +++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 266 insertions(+), 43 deletions(-) (limited to 'src/map.cpp') diff --git a/src/map.cpp b/src/map.cpp index e4992618d..ba958d148 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1741,10 +1741,10 @@ ServerMap::ServerMap(std::string savedir): //m_chunksize = 2; // TODO: Save to and load from a file - m_seed = (((u64)myrand()<<0)%0x7fff) - + (((u64)myrand()<<16)%0x7fff) - + (((u64)myrand()<<32)%0x7fff) - + (((u64)myrand()<<48)%0x7fff); + m_seed = (((u64)(myrand()%0xffff)<<0) + + ((u64)(myrand()%0xffff)<<16) + + ((u64)(myrand()%0xffff)<<32) + + ((u64)(myrand()%0xffff)<<48)); /* Experimental and debug stuff @@ -1774,16 +1774,24 @@ ServerMap::ServerMap(std::string savedir): } else { - // Load master heightmap - loadMasterHeightmap(); + // Load map metadata (seed, chunksize) + loadMapMeta(); - // Load sector (0,0) and throw and exception on fail + // Load chunk metadata + loadChunkMeta(); + + /*// Load sector (0,0) and throw and exception on fail if(loadSectorFull(v2s16(0,0)) == false) - throw LoadError("Failed to load sector (0,0)"); + throw LoadError("Failed to load sector (0,0)");*/ - dstream<setIsVolatile(false); chunk->setGenLevel(GENERATED_FULLY); - // Return it + + /* + Save changed parts of map + */ + save(true); + + /* + Return central chunk (which was requested) + */ return chunk; } @@ -4543,7 +4606,8 @@ void ServerMap::save(bool only_changed) dstream< list = fs::GetDirListing(m_savedir+"/sectors/"); @@ -4657,6 +4722,7 @@ void ServerMap::loadAll() dstream<::Iterator + i = m_chunks.getIterator(); + i.atEnd()==false; i++) + { + v2s16 p = i.getNode()->getKey(); + MapChunk *chunk = i.getNode()->getValue(); + // Write position + writeV2S16(buf, p); + os.write((char*)buf, 4); + // Write chunk data + chunk->serialize(os, version); + } +} + +void ServerMap::loadChunkMeta() +{ + DSTACK(__FUNCTION_NAME); + + dstream<<"INFO: ServerMap::loadChunkMeta(): Loading chunk metadata" + <deSerialize(is, version); + m_chunks.insert(p, chunk); + } +} void ServerMap::saveSectorMeta(ServerMapSector *sector) { -- cgit v1.2.3