From ea6740e9002839f79053cf9d8cd78eb3fcae1b47 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 5 Feb 2011 14:55:16 +0200 Subject: [PATCH] mapgen stuff --- src/CMakeLists.txt | 1 - src/constants.h | 8 +- src/guiPauseMenu.cpp | 1 + src/heightmap.cpp | 1060 ------------------------------------------ src/heightmap.h | 572 ----------------------- src/main.cpp | 70 +-- src/map.cpp | 858 ++++++---------------------------- src/map.h | 60 +-- src/mapblock.cpp | 2 +- src/mapsector.cpp | 371 +-------------- src/mapsector.h | 63 +-- src/server.cpp | 12 +- src/server.h | 4 +- src/servermain.cpp | 14 +- src/test.cpp | 134 +----- src/utility.cpp | 230 --------- src/utility.h | 177 ------- 17 files changed, 240 insertions(+), 3397 deletions(-) delete mode 100644 src/heightmap.cpp delete mode 100644 src/heightmap.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1c5e5f6e1..8325024ee 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -58,7 +58,6 @@ set(common_SRCS socket.cpp mapblock.cpp mapsector.cpp - heightmap.cpp map.cpp player.cpp utility.cpp diff --git a/src/constants.h b/src/constants.h index c8c210b13..3c37fca87 100644 --- a/src/constants.h +++ b/src/constants.h @@ -97,12 +97,16 @@ with this program; if not, write to the Free Software Foundation, Inc., /* This is good to be a bit different than 0 so that water level - is not between to MapBlocks + is not between two MapBlocks */ -#define WATER_LEVEL 3 +#define WATER_LEVEL 1 // Length of cracking animation in count of images #define CRACK_ANIMATION_LENGTH 5 +// Some stuff needed by old code moved to here from heightmap.h +#define GROUNDHEIGHT_NOTFOUND_SETVALUE (-10e6) +#define GROUNDHEIGHT_VALID_MINVALUE ( -9e6) + #endif diff --git a/src/guiPauseMenu.cpp b/src/guiPauseMenu.cpp index d905d3222..bcf4070c9 100644 --- a/src/guiPauseMenu.cpp +++ b/src/guiPauseMenu.cpp @@ -115,6 +115,7 @@ void GUIPauseMenu::regenerateGui(v2u32 screensize) L"- Mouse left: dig blocks\n" L"- Mouse right: place blocks\n" L"- Mouse wheel: select item\n" + L"- 0...9: select item\n" L"- R: Toggle viewing all loaded chunks\n" L"- I: Inventory menu\n" L"- ESC: This menu\n" diff --git a/src/heightmap.cpp b/src/heightmap.cpp deleted file mode 100644 index bb7f2a1d1..000000000 --- a/src/heightmap.cpp +++ /dev/null @@ -1,1060 +0,0 @@ -/* -Minetest-c55 -Copyright (C) 2010 celeron55, Perttu Ahola - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -/* -(c) 2010 Perttu Ahola -*/ - -#include "heightmap.h" - -// For MAP_BLOCKSIZE -#include "mapblock.h" - -/* - ValueGenerator -*/ - -ValueGenerator* ValueGenerator::deSerialize(std::string line) -{ - std::istringstream ss(line); - //ss.imbue(std::locale("C")); - - std::string name; - std::getline(ss, name, ' '); - - if(name == "constant") - { - f32 value; - ss>>value; - - return new ConstantGenerator(value); - } - else if(name == "linear") - { - f32 height; - v2f slope; - - ss>>height; - ss>>slope.X; - ss>>slope.Y; - - return new LinearGenerator(height, slope); - } - else if(name == "power") - { - f32 height; - v2f slope; - f32 power; - - ss>>height; - ss>>slope.X; - ss>>slope.Y; - ss>>power; - - return new PowerGenerator(height, slope, power); - } - else - { - throw SerializationError - ("Invalid heightmap generator (deSerialize)"); - } -} - -/* - FixedHeightmap -*/ - -f32 FixedHeightmap::avgNeighbours(v2s16 p, s16 d) -{ - v2s16 dirs[4] = { - v2s16(1,0), - v2s16(0,1), - v2s16(-1,0), - v2s16(0,-1) - }; - f32 sum = 0.0; - f32 count = 0.0; - for(u16 i=0; i<4; i++){ - v2s16 p2 = p + dirs[i] * d; - f32 n = getGroundHeightParent(p2); - if(n < GROUNDHEIGHT_VALID_MINVALUE) - continue; - sum += n; - count += 1.0; - } - assert(count > 0.001); - return sum / count; -} - -f32 FixedHeightmap::avgDiagNeighbours(v2s16 p, s16 d) -{ - v2s16 dirs[4] = { - v2s16(1,1), - v2s16(-1,-1), - v2s16(-1,1), - v2s16(1,-1) - }; - f32 sum = 0.0; - f32 count = 0.0; - for(u16 i=0; i<4; i++){ - v2s16 p2 = p + dirs[i] * d; - f32 n = getGroundHeightParent(p2); - if(n < GROUNDHEIGHT_VALID_MINVALUE) - continue; - sum += n; - count += 1.0; - } - assert(count > 0.001); - return sum / count; -} - -/* - Adds a point to transform into a diamond pattern - center = Center of the diamond phase (center of a square) - a = Side length of the existing square (2, 4, 8, ...) - - Adds the center points of the next squares to next_squares as - dummy "true" values. -*/ -void FixedHeightmap::makeDiamond( - v2s16 center, - s16 a, - f32 randmax, - core::map &next_squares) -{ - /*dstream<<"makeDiamond(): center=" - <<"("< GROUNDHEIGHT_VALID_MINVALUE) - continue; - setGroundHeight(dirs[i] * a, corners[i]); - } - - /*dstream<<"corners filled:"< colorcount-1) - color = colorcount-1; - /*printf("rangemin=%f, rangemax=%f, h=%f -> color=%i\n", - rangemin, - rangemax, - h, - color);*/ - printf("%s", colors[color]); - //printf("\x1b[31;40m"); - //printf("\x1b[44;1m"); -#endif -} -void resetcolor() -{ -#ifndef _WIN32 - printf("\x1b[0m"); -#endif -} - -/* - UnlimitedHeightmap -*/ - -void UnlimitedHeightmap::print() -{ - s16 minx = 10000; - s16 miny = 10000; - s16 maxx = -10000; - s16 maxy = -10000; - core::map::Iterator i; - i = m_heightmaps.getIterator(); - if(i.atEnd()){ - printf("UnlimitedHeightmap::print(): empty.\n"); - return; - } - for(; i.atEnd() == false; i++) - { - v2s16 p = i.getNode()->getValue()->getPosOnMaster(); - if(p.X < minx) minx = p.X; - if(p.Y < miny) miny = p.Y; - if(p.X > maxx) maxx = p.X; - if(p.Y > maxy) maxy = p.Y; - } - minx = minx * m_blocksize; - miny = miny * m_blocksize; - maxx = (maxx+1) * m_blocksize; - maxy = (maxy+1) * m_blocksize; - printf("UnlimitedHeightmap::print(): from (%i,%i) to (%i,%i)\n", - minx, miny, maxx, maxy); - - // Calculate range - f32 rangemin = 1e10; - f32 rangemax = -1e10; - for(s32 y=miny; y<=maxy; y++){ - for(s32 x=minx; x<=maxx; x++){ - f32 h = getGroundHeight(v2s16(x,y), false); - if(h < GROUNDHEIGHT_VALID_MINVALUE) - continue; - if(h < rangemin) - rangemin = h; - if(h > rangemax) - rangemax = h; - } - } - - printf(" "); - for(s32 x=minx; x<=maxx; x++){ - printf("% .3d ", x); - } - printf("\n"); - - for(s32 y=miny; y<=maxy; y++){ - printf("% .3d ", y); - for(s32 x=minx; x<=maxx; x++){ - f32 n = getGroundHeight(v2s16(x,y), false); - if(n < GROUNDHEIGHT_VALID_MINVALUE) - printf(" - "); - else - { - setcolor(n, rangemin, rangemax); - printf("% -5.1f", getGroundHeight(v2s16(x,y), false)); - resetcolor(); - } - } - printf("\n"); - } -} - -FixedHeightmap * UnlimitedHeightmap::getHeightmap(v2s16 p_from, bool generate) -{ - DSTACK("UnlimitedHeightmap::getHeightmap()"); - /* - We want to check that all neighbours of the wanted heightmap - exist. - This is because generating the neighboring heightmaps will - modify the current one. - */ - - if(generate) - { - // Go through all neighbors (corners also) and the current one - // and generate every one of them. - for(s16 x=p_from.X-1; x<=p_from.X+1; x++) - for(s16 y=p_from.Y-1; y<=p_from.Y+1; y++) - { - v2s16 p(x,y); - - // Check if exists - core::map::Node *n = m_heightmaps.find(p); - if(n != NULL) - continue; - - // Doesn't exist - // Generate it - - FixedHeightmap *heightmap = new FixedHeightmap(this, p, m_blocksize); - - m_heightmaps.insert(p, heightmap); - - f32 corners[4]; - - s32 div = SECTOR_HEIGHTMAP_SPLIT * MAP_BLOCKSIZE; - - { - PointAttributeList *palist = m_padb->getList("hm_baseheight"); - - if(palist->empty()) - { - corners[0] = 0; - corners[1] = 0; - corners[2] = 0; - corners[3] = 0; - } - else - { -#if 0 - corners[0] = palist->getNearAttr((p+v2s16(0,0)) * div).getFloat(); - corners[1] = palist->getNearAttr((p+v2s16(1,0)) * div).getFloat(); - corners[2] = palist->getNearAttr((p+v2s16(1,1)) * div).getFloat(); - corners[3] = palist->getNearAttr((p+v2s16(0,1)) * div).getFloat(); -#endif -#if 1 - corners[0] = palist->getInterpolatedFloat((p+v2s16(0,0))*div); - corners[1] = palist->getInterpolatedFloat((p+v2s16(1,0))*div); - corners[2] = palist->getInterpolatedFloat((p+v2s16(1,1))*div); - corners[3] = palist->getInterpolatedFloat((p+v2s16(0,1))*div); -#endif - } - } - /*else - { - corners[0] = m_base_generator->getValue(p+v2s16(0,0)); - corners[1] = m_base_generator->getValue(p+v2s16(1,0)); - corners[2] = m_base_generator->getValue(p+v2s16(1,1)); - corners[3] = m_base_generator->getValue(p+v2s16(0,1)); - }*/ - - /*f32 randmax = m_randmax_generator->getValue(p); - f32 randfactor = m_randfactor_generator->getValue(p);*/ - - f32 randmax = m_padb->getList("hm_randmax") - ->getInterpolatedFloat(p*div); - f32 randfactor = m_padb->getList("hm_randfactor") - ->getInterpolatedFloat(p*div); - //dstream<<"randmax="<getGroundHeight(relpos); - if(h > GROUNDHEIGHT_VALID_MINVALUE) - return h; - } - catch(InvalidPositionException){} - /* - If on border or in the (0,0) corner, try to get from - overlapping heightmaps - */ - if(relpos.X == 0){ - try{ - FixedHeightmap * href = getHeightmap( - heightmappos-v2s16(1,0), false); - f32 h = href->getGroundHeight(v2s16(m_blocksize, relpos.Y)); - if(h > GROUNDHEIGHT_VALID_MINVALUE) - return h; - } - catch(InvalidPositionException){} - } - if(relpos.Y == 0){ - try{ - FixedHeightmap * href = getHeightmap( - heightmappos-v2s16(0,1), false); - f32 h = href->getGroundHeight(v2s16(relpos.X, m_blocksize)); - if(h > GROUNDHEIGHT_VALID_MINVALUE) - return h; - } - catch(InvalidPositionException){} - } - if(relpos.X == 0 && relpos.Y == 0){ - try{ - FixedHeightmap * href = getHeightmap( - heightmappos-v2s16(1,1), false); - f32 h = href->getGroundHeight(v2s16(m_blocksize, m_blocksize)); - if(h > GROUNDHEIGHT_VALID_MINVALUE) - return h; - } - catch(InvalidPositionException){} - } - return GROUNDHEIGHT_NOTFOUND_SETVALUE; -} - -void UnlimitedHeightmap::setGroundHeight(v2s16 p, f32 y, bool generate) -{ - bool was_set = false; - - v2s16 heightmappos = getNodeHeightmapPos(p); - v2s16 relpos = p - heightmappos*m_blocksize; - /*dstream<<"UnlimitedHeightmap::setGroundHeight((" - <setGroundHeight(relpos, y); - was_set = true; - }catch(InvalidPositionException){} - // Update in neighbour heightmap if it's at border - if(relpos.X == 0){ - try{ - FixedHeightmap * href = getHeightmap( - heightmappos-v2s16(1,0), generate); - href->setGroundHeight(v2s16(m_blocksize, relpos.Y), y); - was_set = true; - }catch(InvalidPositionException){} - } - if(relpos.Y == 0){ - try{ - FixedHeightmap * href = getHeightmap( - heightmappos-v2s16(0,1), generate); - href->setGroundHeight(v2s16(relpos.X, m_blocksize), y); - was_set = true; - }catch(InvalidPositionException){} - } - if(relpos.X == 0 && relpos.Y == 0){ - try{ - FixedHeightmap * href = getHeightmap( - heightmappos-v2s16(1,1), generate); - href->setGroundHeight(v2s16(m_blocksize, m_blocksize), y); - was_set = true; - }catch(InvalidPositionException){} - } - - if(was_set == false) - { - throw InvalidPositionException - ("UnlimitedHeightmap failed to set height"); - } -} - - -void UnlimitedHeightmap::serialize(std::ostream &os, u8 version) -{ - //dstream<<"UnlimitedHeightmap::serialize()"<getId() != VALUE_GENERATOR_ID_CONSTANT - || m_randmax_generator->getId() != VALUE_GENERATOR_ID_CONSTANT - || m_randfactor_generator->getId() != VALUE_GENERATOR_ID_CONSTANT)*/ - /*if(std::string(m_base_generator->getName()) != "constant" - || std::string(m_randmax_generator->getName()) != "constant" - || std::string(m_randfactor_generator->getName()) != "constant") - { - throw SerializationError - ("Cannot write UnlimitedHeightmap in old version: " - "Generators are not ConstantGenerators."); - }*/ - - // Dummy values - f32 basevalue = 0.0; - f32 randmax = 0.0; - f32 randfactor = 0.0; - - // Write version - os.write((char*)&version, 1); - - /* - [0] u16 blocksize - [2] s32 randmax*1000 - [6] s32 randfactor*1000 - [10] s32 basevalue*1000 - [14] u32 heightmap_count - [18] X * (v2s16 pos + heightmap) - */ - u32 heightmap_size = - FixedHeightmap::serializedLength(version, m_blocksize); - u32 heightmap_count = m_heightmaps.size(); - - //dstream<<"heightmap_size="< data(datasize); - - writeU16(&data[0], m_blocksize); - writeU32(&data[2], (s32)(randmax*1000.0)); - writeU32(&data[6], (s32)(randfactor*1000.0)); - writeU32(&data[10], (s32)(basevalue*1000.0)); - writeU32(&data[14], heightmap_count); - - core::map::Iterator j; - j = m_heightmaps.getIterator(); - u32 i=0; - for(; j.atEnd() == false; j++) - { - FixedHeightmap *hm = j.getNode()->getValue(); - v2s16 pos = j.getNode()->getKey(); - writeV2S16(&data[18+i*(4+heightmap_size)], pos); - hm->serialize(&data[18+i*(4+heightmap_size)+4], version); - i++; - } - - os.write((char*)*data, data.getSize()); - } - else if(version <= 11) - { - // Write version - os.write((char*)&version, 1); - - u8 buf[4]; - - writeU16(buf, m_blocksize); - os.write((char*)buf, 2); - - /*m_randmax_generator->serialize(os); - m_randfactor_generator->serialize(os); - m_base_generator->serialize(os);*/ - os<<"constant 0.0\n"; - os<<"constant 0.0\n"; - os<<"constant 0.0\n"; - - u32 heightmap_count = m_heightmaps.size(); - writeU32(buf, heightmap_count); - os.write((char*)buf, 4); - - u32 heightmap_size = - FixedHeightmap::serializedLength(version, m_blocksize); - - SharedBuffer hmdata(heightmap_size); - - core::map::Iterator j; - j = m_heightmaps.getIterator(); - u32 i=0; - for(; j.atEnd() == false; j++) - { - v2s16 pos = j.getNode()->getKey(); - writeV2S16(buf, pos); - os.write((char*)buf, 4); - - FixedHeightmap *hm = j.getNode()->getValue(); - hm->serialize(*hmdata, version); - os.write((char*)*hmdata, hmdata.getSize()); - - i++; - } - } - else - { - // Write version - os.write((char*)&version, 1); - - u8 buf[4]; - - writeU16(buf, m_blocksize); - os.write((char*)buf, 2); - - /*m_randmax_generator->serialize(os); - m_randfactor_generator->serialize(os); - m_base_generator->serialize(os);*/ - - u32 heightmap_count = m_heightmaps.size(); - writeU32(buf, heightmap_count); - os.write((char*)buf, 4); - - u32 heightmap_size = - FixedHeightmap::serializedLength(version, m_blocksize); - - SharedBuffer hmdata(heightmap_size); - - core::map::Iterator j; - j = m_heightmaps.getIterator(); - u32 i=0; - for(; j.atEnd() == false; j++) - { - v2s16 pos = j.getNode()->getKey(); - writeV2S16(buf, pos); - os.write((char*)buf, 4); - - FixedHeightmap *hm = j.getNode()->getValue(); - hm->serialize(*hmdata, version); - os.write((char*)*hmdata, hmdata.getSize()); - - i++; - } - } - -#if 0 - if(version <= 7) - { - /*if(m_base_generator->getId() != VALUE_GENERATOR_ID_CONSTANT - || m_randmax_generator->getId() != VALUE_GENERATOR_ID_CONSTANT - || m_randfactor_generator->getId() != VALUE_GENERATOR_ID_CONSTANT)*/ - if(std::string(m_base_generator->getName()) != "constant" - || std::string(m_randmax_generator->getName()) != "constant" - || std::string(m_randfactor_generator->getName()) != "constant") - { - throw SerializationError - ("Cannot write UnlimitedHeightmap in old version: " - "Generators are not ConstantGenerators."); - } - - f32 basevalue = ((ConstantGenerator*)m_base_generator)->m_value; - f32 randmax = ((ConstantGenerator*)m_randmax_generator)->m_value; - f32 randfactor = ((ConstantGenerator*)m_randfactor_generator)->m_value; - - // Write version - os.write((char*)&version, 1); - - /* - [0] u16 blocksize - [2] s32 randmax*1000 - [6] s32 randfactor*1000 - [10] s32 basevalue*1000 - [14] u32 heightmap_count - [18] X * (v2s16 pos + heightmap) - */ - u32 heightmap_size = - FixedHeightmap::serializedLength(version, m_blocksize); - u32 heightmap_count = m_heightmaps.size(); - - //dstream<<"heightmap_size="< data(datasize); - - writeU16(&data[0], m_blocksize); - writeU32(&data[2], (s32)(randmax*1000.0)); - writeU32(&data[6], (s32)(randfactor*1000.0)); - writeU32(&data[10], (s32)(basevalue*1000.0)); - writeU32(&data[14], heightmap_count); - - core::map::Iterator j; - j = m_heightmaps.getIterator(); - u32 i=0; - for(; j.atEnd() == false; j++) - { - FixedHeightmap *hm = j.getNode()->getValue(); - v2s16 pos = j.getNode()->getKey(); - writeV2S16(&data[18+i*(4+heightmap_size)], pos); - hm->serialize(&data[18+i*(4+heightmap_size)+4], version); - i++; - } - - os.write((char*)*data, data.getSize()); - } - else - { - // Write version - os.write((char*)&version, 1); - - u8 buf[4]; - - writeU16(buf, m_blocksize); - os.write((char*)buf, 2); - - /*m_randmax_generator->serialize(os, version); - m_randfactor_generator->serialize(os, version); - m_base_generator->serialize(os, version);*/ - m_randmax_generator->serialize(os); - m_randfactor_generator->serialize(os); - m_base_generator->serialize(os); - - u32 heightmap_count = m_heightmaps.size(); - writeU32(buf, heightmap_count); - os.write((char*)buf, 4); - - u32 heightmap_size = - FixedHeightmap::serializedLength(version, m_blocksize); - - SharedBuffer hmdata(heightmap_size); - - core::map::Iterator j; - j = m_heightmaps.getIterator(); - u32 i=0; - for(; j.atEnd() == false; j++) - { - v2s16 pos = j.getNode()->getKey(); - writeV2S16(buf, pos); - os.write((char*)buf, 4); - - FixedHeightmap *hm = j.getNode()->getValue(); - hm->serialize(*hmdata, version); - os.write((char*)*hmdata, hmdata.getSize()); - - i++; - } - } -#endif -} - -UnlimitedHeightmap * UnlimitedHeightmap::deSerialize(std::istream &is, - PointAttributeDatabase *padb) -{ - u8 version; - is.read((char*)&version, 1); - - if(!ser_ver_supported(version)) - throw VersionMismatchException("ERROR: UnlimitedHeightmap format not supported"); - - if(version <= 7) - { - /* - [0] u16 blocksize - [2] s32 randmax*1000 - [6] s32 randfactor*1000 - [10] s32 basevalue*1000 - [14] u32 heightmap_count - [18] X * (v2s16 pos + heightmap) - */ - SharedBuffer data(18); - is.read((char*)*data, 18); - if(is.gcount() != 18) - throw SerializationError - ("UnlimitedHeightmap::deSerialize: no enough input data"); - s16 blocksize = readU16(&data[0]); - // Dummy read randmax, randfactor, basevalue - /*f32 randmax = (f32)*/readU32(&data[2]) /*/ 1000.0*/; - /*f32 randfactor = (f32)*/readU32(&data[6]) /*/ 1000.0*/; - /*f32 basevalue = (f32)*/readU32(&data[10]) /*/ 1000.0*/; - u32 heightmap_count = readU32(&data[14]); - - /*dstream<<"UnlimitedHeightmap::deSerialize():" - <<" blocksize="<deSerialize(&data[4], version); - hm->m_heightmaps.insert(pos, f); - } - return hm; - } - else if(version <= 11) - { - u8 buf[4]; - - is.read((char*)buf, 2); - s16 blocksize = readU16(buf); - - // Dummy-read three lines (generators) - std::string templine; - std::getline(is, templine, '\n'); - - is.read((char*)buf, 4); - u32 heightmap_count = readU32(buf); - - u32 heightmap_size = - FixedHeightmap::serializedLength(version, blocksize); - - UnlimitedHeightmap *hm = new UnlimitedHeightmap - (blocksize, padb); - - for(u32 i=0; i data(heightmap_size); - is.read((char*)*data, heightmap_size); - if(is.gcount() != (s32)(heightmap_size)){ - delete hm; - throw SerializationError - ("UnlimitedHeightmap::deSerialize: no enough input data"); - } - FixedHeightmap *f = new FixedHeightmap(hm, pos, blocksize); - f->deSerialize(*data, version); - hm->m_heightmaps.insert(pos, f); - } - return hm; - } - else - { - u8 buf[4]; - - is.read((char*)buf, 2); - s16 blocksize = readU16(buf); - - /*ValueGenerator *maxgen = ValueGenerator::deSerialize(is); - ValueGenerator *factorgen = ValueGenerator::deSerialize(is); - ValueGenerator *basegen = ValueGenerator::deSerialize(is);*/ - - is.read((char*)buf, 4); - u32 heightmap_count = readU32(buf); - - u32 heightmap_size = - FixedHeightmap::serializedLength(version, blocksize); - - UnlimitedHeightmap *hm = new UnlimitedHeightmap - (blocksize, padb); - - for(u32 i=0; i data(heightmap_size); - is.read((char*)*data, heightmap_size); - if(is.gcount() != (s32)(heightmap_size)){ - delete hm; - throw SerializationError - ("UnlimitedHeightmap::deSerialize: no enough input data"); - } - FixedHeightmap *f = new FixedHeightmap(hm, pos, blocksize); - f->deSerialize(*data, version); - hm->m_heightmaps.insert(pos, f); - } - return hm; - } -} - - diff --git a/src/heightmap.h b/src/heightmap.h deleted file mode 100644 index aba3b050d..000000000 --- a/src/heightmap.h +++ /dev/null @@ -1,572 +0,0 @@ -/* -Minetest-c55 -Copyright (C) 2010 celeron55, Perttu Ahola - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#ifndef HEIGHTMAP_HEADER -#define HEIGHTMAP_HEADER - -#include -#include -#include - -#include "debug.h" -#include "common_irrlicht.h" -#include "exceptions.h" -#include "utility.h" -#include "serialization.h" - -#define GROUNDHEIGHT_NOTFOUND_SETVALUE (-10e6) -#define GROUNDHEIGHT_VALID_MINVALUE ( -9e6) - -class Heightmappish -{ -public: - virtual f32 getGroundHeight(v2s16 p, bool generate=true) = 0; - virtual void setGroundHeight(v2s16 p, f32 y, bool generate=true) = 0; - - v2f32 getSlope(v2s16 p) - { - f32 y0 = getGroundHeight(p, false); - - v2s16 dirs[] = { - v2s16(1,0), - v2s16(0,1), - }; - - v2f32 fdirs[] = { - v2f32(1,0), - v2f32(0,1), - }; - - v2f32 slopevector(0.0, 0.0); - - for(u16 i=0; i<2; i++){ - f32 y1 = 0.0; - f32 y2 = 0.0; - f32 count = 0.0; - - v2s16 p1 = p - dirs[i]; - y1 = getGroundHeight(p1, false); - if(y1 > GROUNDHEIGHT_VALID_MINVALUE){ - y1 -= y0; - count += 1.0; - } - else - y1 = 0; - - v2s16 p2 = p + dirs[i]; - y2 = getGroundHeight(p2, false); - if(y2 > GROUNDHEIGHT_VALID_MINVALUE){ - y2 -= y0; - count += 1.0; - } - else - y2 = 0; - - if(count < 0.001) - return v2f32(0.0, 0.0); - - /* - If y2 is higher than y1, slope is positive - */ - f32 slope = (y2 - y1)/count; - - slopevector += fdirs[i] * slope; - } - - return slopevector; - } - -}; - -// TODO: Get rid of this dummy wrapper -class Heightmap : public Heightmappish /*, public ReferenceCounted*/ -{ -}; - -class WrapperHeightmap : public Heightmap -{ - Heightmappish *m_target; -public: - - WrapperHeightmap(Heightmappish *target): - m_target(target) - { - if(target == NULL) - throw NullPointerException(); - } - - f32 getGroundHeight(v2s16 p, bool generate=true) - { - return m_target->getGroundHeight(p, generate); - } - void setGroundHeight(v2s16 p, f32 y, bool generate=true) - { - m_target->setGroundHeight(p, y, generate); - } -}; - -/* - Base class that defines a generator that gives out values at - positions in 2-dimensional space. - Can be given to UnlimitedHeightmap to feed stuff. - - These are always serialized as readable text ending in "\n" -*/ -class ValueGenerator -{ -public: - ValueGenerator(){} - virtual ~ValueGenerator(){} - - static ValueGenerator* deSerialize(std::string line); - - static ValueGenerator* deSerialize(std::istream &is) - { - std::string line; - std::getline(is, line, '\n'); - return deSerialize(line); - } - - void serializeBase(std::ostream &os) - { - os<= W || p.Y < 0 || p.Y >= H); - } - - bool atborder(v2s16 p) - { - if(overborder(p)) - return false; - return (p.X == 0 || p.X == W-1 || p.Y == 0 || p.Y == H-1); - } - - void setGroundHeight(v2s16 p, f32 y, bool generate=false) - { - /*dstream<<"FixedHeightmap::setGroundHeight((" - <setGroundHeight(nodepos_master, y, false);*/ - - // Try to set on master - bool master_got_it = false; - if(overborder(p) || atborder(p)) - { - try{ - // Position on master - v2s16 blockpos_nodes = m_pos_on_master * m_blocksize; - v2s16 nodepos_master = blockpos_nodes + p; - m_master->setGroundHeight(nodepos_master, y, false); - - master_got_it = true; - } - catch(InvalidPositionException &e) - { - } - } - - if(overborder(p)) - return master_got_it; - - setGroundHeight(p, y); - - return true; - } - - f32 getGroundHeight(v2s16 p, bool generate=false) - { - if(overborder(p)) - return GROUNDHEIGHT_NOTFOUND_SETVALUE; - return m_data[p.Y*W + p.X]; - } - - f32 getGroundHeightParent(v2s16 p) - { - /*v2s16 blockpos_nodes = m_pos_on_master * m_blocksize; - return m_master->getGroundHeight(blockpos_nodes + p, false);*/ - - if(overborder(p) == false){ - f32 h = getGroundHeight(p); - if(h > GROUNDHEIGHT_VALID_MINVALUE) - return h; - } - - // Position on master - v2s16 blockpos_nodes = m_pos_on_master * m_blocksize; - f32 h = m_master->getGroundHeight(blockpos_nodes + p, false); - return h; - } - - f32 avgNeighbours(v2s16 p, s16 d); - - f32 avgDiagNeighbours(v2s16 p, s16 d); - - void makeDiamond( - v2s16 center, - s16 a, - f32 randmax, - core::map &next_squares); - - void makeSquare( - v2s16 center, - s16 a, - f32 randmax, - core::map &next_diamonds); - - void DiamondSquare(f32 randmax, f32 randfactor); - - /* - corners: [i]=XY: [0]=00, [1]=10, [2]=11, [3]=10 - */ - void generateContinued(f32 randmax, f32 randfactor, f32 *corners); - - - static u32 serializedLength(u8 version, u16 blocksize); - u32 serializedLength(u8 version); - void serialize(u8 *dest, u8 version); - void deSerialize(u8 *source, u8 version); - /*static FixedHeightmap * deSerialize(u8 *source, u32 size, - u32 &usedsize, Heightmap *master, u8 version);*/ -}; - -class OneChildHeightmap : public Heightmap -{ - s16 m_blocksize; - -public: - - FixedHeightmap m_child; - - OneChildHeightmap(s16 blocksize): - m_blocksize(blocksize), - m_child(this, v2s16(0,0), blocksize) - { - } - - f32 getGroundHeight(v2s16 p, bool generate=true) - { - if(p.X < 0 || p.X > m_blocksize - || p.Y < 0 || p.Y > m_blocksize) - return GROUNDHEIGHT_NOTFOUND_SETVALUE; - return m_child.getGroundHeight(p); - } - void setGroundHeight(v2s16 p, f32 y, bool generate=true) - { - //dstream<<"OneChildHeightmap::setGroundHeight()"< m_blocksize - || p.Y < 0 || p.Y > m_blocksize) - throw InvalidPositionException(); - m_child.setGroundHeight(p, y); - } -}; - - -/* - This is a dynamic container of an arbitrary number of heightmaps - at arbitrary positions. - - It is able to redirect queries to the corresponding heightmaps and - it generates new heightmaps on-the-fly according to the relevant - parameters. - - It doesn't have a master heightmap because it is meant to be used - as such itself. - - Child heightmaps are spaced at m_blocksize distances, and are of - size (m_blocksize+1)*(m_blocksize+1) - - This is used as the master heightmap of a Map object. -*/ -class UnlimitedHeightmap: public Heightmap -{ -private: - - core::map m_heightmaps; - s16 m_blocksize; - - // TODO: Remove ValueGenerators - /*ValueGenerator *m_randmax_generator; - ValueGenerator *m_randfactor_generator; - ValueGenerator *m_base_generator;*/ - - PointAttributeDatabase *m_padb; - -public: - - UnlimitedHeightmap( - s16 blocksize, - /*ValueGenerator *randmax_generator, - ValueGenerator *randfactor_generator, - ValueGenerator *base_generator,*/ - PointAttributeDatabase *padb - ): - m_blocksize(blocksize), - /*m_randmax_generator(randmax_generator), - m_randfactor_generator(randfactor_generator), - m_base_generator(base_generator),*/ - m_padb(padb) - { - /*assert(m_randmax_generator != NULL); - assert(m_randfactor_generator != NULL); - assert(m_base_generator != NULL);*/ - assert(m_padb); - } - - ~UnlimitedHeightmap() - { - core::map::Iterator i; - i = m_heightmaps.getIterator(); - for(; i.atEnd() == false; i++) - { - delete i.getNode()->getValue(); - } - - /*delete m_randmax_generator; - delete m_randfactor_generator; - delete m_base_generator;*/ - } - - void print(); - - v2s16 getNodeHeightmapPos(v2s16 p) - { - return v2s16( - (p.X>=0 ? p.X : p.X-m_blocksize+1) / m_blocksize, - (p.Y>=0 ? p.Y : p.Y-m_blocksize+1) / m_blocksize); - } - - // Can throw an InvalidPositionException - FixedHeightmap * getHeightmap(v2s16 p, bool generate=true); - - f32 getGroundHeight(v2s16 p, bool generate=true); - void setGroundHeight(v2s16 p, f32 y, bool generate=true); - - /*static UnlimitedHeightmap * deSerialize(u8 *source, u32 maxsize, - u32 &usedsize, u8 version);*/ - - //SharedBuffer serialize(u8 version); - void serialize(std::ostream &os, u8 version); - static UnlimitedHeightmap * deSerialize(std::istream &istr, - PointAttributeDatabase *padb); -}; - -#endif - diff --git a/src/main.cpp b/src/main.cpp index a97d1f45d..75ee2f26b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -320,40 +320,42 @@ Doing now (most important at the top): # maybe done * not done -* Perlin noise stuff sucks in heightmap generation, fix it -* Create perlin noise functions and use them to get natural randomness - in everything. No need for attributes or fractal terrain. -* Do something about AttributeDatabase/List being too slow - - Remove it +=== Stuff to do before release +* Save map seed to a metafile (with version information) + - map/meta.txt, which should contain only plain text, something like this: + seed = O7+BZT9Vk/iVYiBlZ2dsb6zemp4xdGVysJqYmNt2X+MQ+Kg1 + chunksize = 8 + - map/chunks/ + - + - Compressed bunch of data... um, actually no. + - Make a directory for every chunk instead, which contains + sectors and blocks * Save chunk metadata on disk -* Remove all kinds of systems that are made redundant by the new map - generator - - Sector heightmaps? At least they should be made redundant. - - Sector objects -* Fix the strange mineral occurences - - Do they appear anymore? * Make server find the spawning place from the real map data, not from the heightmap - But the changing borders of chunk have to be avoided, because there is time to generate only one chunk. -* only_from_disk might not work anymore - check and fix it. * Make the generator to run in background and not blocking block placement and transfer +* only_from_disk might not work anymore - check and fix it. + +=== Stuff to do after release * Add some kind of erosion and other stuff that now is possible * Make client to fetch stuff asynchronously - Needs method SyncProcessData -* What is the problem with the server constantly saving one or a few +* Fix the problem with the server constantly saving one or a few blocks? List the first saved block, maybe it explains. - - Does it still do this? + - It is probably caused by oscillating water * Water doesn't start flowing after map generation like it should - Are there still problems? -* Better water generation (spread it to underwater caverns) +* Better water generation (spread it to underwater caverns but don't + fill dungeons that don't touch outside air) * When generating a chunk and the neighboring chunk doesn't have mud and stuff yet and the ground is fairly flat, the mud will flow to the other chunk making nasty straight walls when the other chunk is generated. Fix it. -* Save map seed to a metafile (with version information) - - Remove master heightmap +* Make a small history check to transformLiquids to detect and log + continuous oscillations, in such detail that they can be fixed. ====================================================================== @@ -666,7 +668,7 @@ public: } // Material selection - if(event.KeyInput.Key == irr::KEY_KEY_F) + /*if(event.KeyInput.Key == irr::KEY_KEY_F) { if(g_selected_item < PLAYER_INVENTORY_SIZE-1) g_selected_item++; @@ -674,6 +676,18 @@ public: g_selected_item = 0; dstream<= irr::KEY_KEY_0 + && event.KeyInput.Key <= irr::KEY_KEY_9) + { + u16 s1 = event.KeyInput.Key - irr::KEY_KEY_0; + if(event.KeyInput.Key == irr::KEY_KEY_0) + s1 = 10; + if(s1 < PLAYER_INVENTORY_SIZE) + g_selected_item = s1-1; + dstream< server; if(address == ""){ - server = new Server(map_dir, hm_params, map_params); + server = new Server(map_dir); server->start(port); } @@ -2266,7 +2268,7 @@ int main(int argc, char *argv[]) g_input->isKeyDown(irr::KEY_KEY_A), g_input->isKeyDown(irr::KEY_KEY_D), g_input->isKeyDown(irr::KEY_SPACE), - g_input->isKeyDown(irr::KEY_KEY_2), + g_input->isKeyDown(irr::KEY_KEY_E), camera_pitch, camera_yaw ); diff --git a/src/map.cpp b/src/map.cpp index 117435565..e748b1433 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -36,8 +36,7 @@ Map::Map(std::ostream &dout): m_dout(dout), m_camera_position(0,0,0), m_camera_direction(0,0,1), - m_sector_cache(NULL), - m_hwrapper(this) + m_sector_cache(NULL) { m_sector_mutex.Init(); m_camera_mutex.Init(); @@ -1730,15 +1729,14 @@ void Map::transformLiquids(core::map & modified_blocks) ServerMap */ -ServerMap::ServerMap(std::string savedir, HMParams hmp, MapParams mp): +ServerMap::ServerMap(std::string savedir): Map(dout_server), - m_heightmap(NULL), m_seed(0) { //m_chunksize = 64; - //m_chunksize = 16; - m_chunksize = 8; + //m_chunksize = 16; // Too slow + m_chunksize = 8; // Fine. Takes a few seconds. //m_chunksize = 4; //m_chunksize = 2; @@ -1753,184 +1751,6 @@ ServerMap::ServerMap(std::string savedir, HMParams hmp, MapParams mp): */ { - dstream<<"Generating map point attribute lists"<addPoint(p, Attribute(plants_amount));*/ - - float plants_amount = 0; - if(myrand()%4 == 0) - { - plants_amount = 1.5; - } - else if(myrand()%4 == 0) - { - plants_amount = 0.5; - } - else if(myrand()%2 == 0) - { - plants_amount = 0.03; - } - else - { - plants_amount = 0.0; - } - - - list_plants_amount->addPoint(p, Attribute(plants_amount)); - } - - for(u32 i=0; i<500; i++) - { - /*u32 lim = MAP_GENERATION_LIMIT; - if(i < 400) - lim = 2000;*/ - - u32 lim = 500 + MAP_GENERATION_LIMIT * i / 500; - - v3s16 p( - -lim + myrand()%(lim*2), - 0, - -lim + myrand()%(lim*2) - ); - - float caves_amount = 0; - if(myrand()%5 == 0) - { - caves_amount = 1.0; - } - else if(myrand()%3 == 0) - { - caves_amount = 0.3; - } - else - { - caves_amount = 0.05; - } - - list_caves_amount->addPoint(p, Attribute(caves_amount)); - } - - for(u32 i=0; i<500; i++) - { - /*u32 lim = MAP_GENERATION_LIMIT; - if(i < 400) - lim = 2000;*/ - - u32 lim = 500 + MAP_GENERATION_LIMIT * i / 500; - - v3s16 p( - -lim + (myrand()%(lim*2)), - 0, - -lim + (myrand()%(lim*2)) - ); - - /*s32 bh_i = (myrand()%200) - 50; - float baseheight = (float)bh_i; - - float m = 100.; - float e = 3.; - float randmax = (float)(myrand()%(int)(10.*pow(m, 1./e)))/10.; - randmax = pow(randmax, e); - - //float randmax = (float)(myrand()%60); - float randfactor = (float)(myrand()%450) / 1000.0 + 0.4;*/ - - float baseheight = 0; - float randmax = 0; - float randfactor = 0; - - /*if(myrand()%5 == 0) - { - baseheight = 100; - randmax = 50; - randfactor = 0.63; - } - else if(myrand()%6 == 0) - { - baseheight = 200; - randmax = 100; - randfactor = 0.66; - } - else if(myrand()%4 == 0) - { - baseheight = -3; - randmax = 30; - randfactor = 0.7; - } - else if(myrand()%3 == 0) - { - baseheight = 0; - randmax = 30; - randfactor = 0.63; - } - else - { - baseheight = -3; - randmax = 20; - randfactor = 0.5; - }*/ - - if(myrand()%3 < 2) - { - baseheight = 10; - randmax = 30; - randfactor = 0.7; - } - else - { - baseheight = 0; - randmax = 15; - randfactor = 0.63; - } - - list_baseheight->addPoint(p, Attribute(baseheight)); - list_randmax->addPoint(p, Attribute(randmax)); - list_randfactor->addPoint(p, Attribute(randfactor)); - } -#endif - - // Add only one entry - list_baseheight->addPoint(v3s16(0,0,0), Attribute(-4)); - list_randmax->addPoint(v3s16(0,0,0), Attribute(22)); - //list_randmax->addPoint(v3s16(0,0,0), Attribute(0)); - list_randfactor->addPoint(v3s16(0,0,0), Attribute(0.45)); - - // Easy spawn point - /*list_baseheight->addPoint(v3s16(0,0,0), Attribute(0)); - list_randmax->addPoint(v3s16(0,0,0), Attribute(10)); - list_randfactor->addPoint(v3s16(0,0,0), Attribute(0.65));*/ } /* @@ -1986,15 +1806,6 @@ ServerMap::ServerMap(std::string savedir, HMParams hmp, MapParams mp): dstream< 0.2) + seed-359, 6, 0.65); + if(a > 0.0) + //if(1) { - return 35. + 10. * noise2d_perlin( + return WATER_LEVEL + 55. * noise2d_perlin( 0.5+(float)p.X/500., 0.5+(float)p.Y/500., - seed+85039, 6, 0.55); + seed+85039, 6, 0.69); } else return -100000; @@ -2202,6 +2011,8 @@ double highlands_level_2d(u64 seed, v2s16 p) MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, core::map &changed_blocks) { + DSTACK(__FUNCTION_NAME); + /* Don't generate if already fully generated */ @@ -2226,11 +2037,13 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, s16 max_spread_amount_sectors = 2; assert(max_spread_amount_sectors <= m_chunksize); s16 max_spread_amount = max_spread_amount_sectors * MAP_BLOCKSIZE; + // Minimum amount of space left on sides for mud to fall in - s16 min_mud_fall_space = 2; + //s16 min_mud_fall_space = 2; + // Maximum diameter of stone obstacles in X and Z - s16 stone_obstacle_max_size = (max_spread_amount-min_mud_fall_space)*2; - assert(stone_obstacle_max_size/2 <= max_spread_amount-min_mud_fall_space); + /*s16 stone_obstacle_max_size = (max_spread_amount-min_mud_fall_space)*2; + assert(stone_obstacle_max_size/2 <= max_spread_amount-min_mud_fall_space);*/ s16 y_blocks_min = -4; s16 y_blocks_max = 3; @@ -2326,6 +2139,10 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, TimeTaker timer_generate("generateChunkRaw() generate"); + // Maximum height of the stone surface and obstacles. + // This is used to disable dungeon generation from going too high. + s16 stone_surface_max_y = 0; + /* Generate general ground level to full area */ @@ -2364,6 +2181,10 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, // Convert to integer s16 surface_y = (s16)surface_y_f; + + // Log it + if(surface_y > stone_surface_max_y) + stone_surface_max_y = surface_y; /* Fill ground with stone @@ -2386,12 +2207,13 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, /* Randomize some parameters */ - - u32 stone_obstacle_amount = 0; - if(myrand() % 2 == 0) - stone_obstacle_amount = myrand_range(0, myrand_range(20, 150)); - else - stone_obstacle_amount = myrand_range(0, myrand_range(20, 50)); + + //TODO + s32 stone_obstacle_count = 0; + /*s32 stone_obstacle_count = (1.0+noise2d(m_seed+90443, sectorpos_base.X, + sectorpos_base.Y))/2.0 * stone_obstacle_amount/3;*/ + + s16 stone_obstacle_max_height = 0; //u32 stone_obstacle_amount = // myrand_range(0, myrand_range(20, myrand_range(80,150))); @@ -2403,11 +2225,6 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, for(u32 i_age=0; i_age<2; i_age++) { // Aging loop - // This is set during the next operation. - // Maximum height of the stone surface and obstacles. - // This is used to disable dungeon generation from going too high. - s16 stone_surface_max_y = 0; - { // 8ms @cs=8 //TimeTaker timer1("stone obstacles"); @@ -2416,38 +2233,28 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, Add some random stone obstacles */ - for(u32 ri=0; rid)) continue; + /*// Check that under that is air (need a drop of 2) + vmanip.m_area.add_y(em, i2, -1); + if(vmanip.m_area.contains(i2) == false) + continue; + n2 = &vmanip.m_data[i2]; + if(content_walkable(n2->d)) + continue;*/ // Loop further down until not air do{ vmanip.m_area.add_y(em, i2, -1); @@ -3196,7 +3005,9 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, { MapNode *n = &vmanip.m_data[i]; if(n->d == CONTENT_MUD || n->d == CONTENT_GRASS) + { n->d = CONTENT_SAND; + } else { not_sand_counter++; @@ -3213,10 +3024,10 @@ MapChunk* ServerMap::generateChunkRaw(v2s16 chunkpos, }//timer1 { // 1ms @cs=8 - //TimeTaker timer1("plant trees"); + //TimeTaker timer1("generate trees"); /* - Plant some trees + Generate some trees */ { // Divide area into parts @@ -3616,14 +3427,6 @@ ServerMapSector * ServerMap::createSector(v2s16 p2d) return sector; } - /* - If there is no master heightmap, throw. - */ - if(m_heightmap == NULL) - { - throw InvalidPositionException("createSector(): no heightmap"); - } - /* Do not create over-limit */ @@ -3637,63 +3440,11 @@ ServerMapSector * ServerMap::createSector(v2s16 p2d) Generate blank sector */ - // Number of heightmaps in sector in each direction - u16 hm_split = SECTOR_HEIGHTMAP_SPLIT; - - // Heightmap side width - s16 hm_d = MAP_BLOCKSIZE / hm_split; - - sector = new ServerMapSector(this, p2d, hm_split); + sector = new ServerMapSector(this, p2d); // Sector position on map in nodes v2s16 nodepos2d = p2d * MAP_BLOCKSIZE; - /*dstream<<"Generating sector ("<getGroundHeight(mhm_p+v2s16(0,0)*hm_split), - m_heightmap->getGroundHeight(mhm_p+v2s16(1,0)*hm_split), - m_heightmap->getGroundHeight(mhm_p+v2s16(1,1)*hm_split), - m_heightmap->getGroundHeight(mhm_p+v2s16(0,1)*hm_split), - };*/ - - // Loop through sub-heightmaps - for(s16 y=0; ygetGroundHeight(mhm_p+v2s16(0,0)), - m_heightmap->getGroundHeight(mhm_p+v2s16(1,0)), - m_heightmap->getGroundHeight(mhm_p+v2s16(1,1)), - m_heightmap->getGroundHeight(mhm_p+v2s16(0,1)), - }; - - /*dstream<<"p_in_sector=("<setHeightmap(p_in_sector, hm); - - //hm->generateContinued(1.0, 0.5, corners); - hm->generateContinued(0.5, 0.5, corners); - - //hm->print(); - } - - // Add dummy objects - core::map *objects = new core::map; - sector->setObjects(objects); - /* Insert to container */ @@ -3812,56 +3563,25 @@ MapBlock * ServerMap::generateBlock( block->unDummify(); } - /*u8 water_material = CONTENT_WATER; - if(g_settings.getBool("endless_water")) - water_material = CONTENT_WATERSOURCE;*/ u8 water_material = CONTENT_WATERSOURCE; s32 lowest_ground_y = 32767; s32 highest_ground_y = -32768; - // DEBUG - //sector->printHeightmaps(); - for(s16 z0=0; z0 highest_ground_y) highest_ground_y = surface_y; - s32 surface_depth = 0; - - float slope = sector->getSlope(v2s16(x0,z0)).getLength(); + s32 surface_depth = 2; - //float min_slope = 0.45; - //float max_slope = 0.85; - float min_slope = 0.60; - float max_slope = 1.20; - float min_slope_depth = 5.0; - float max_slope_depth = 0; - - if(slope < min_slope) - surface_depth = min_slope_depth; - else if(slope > max_slope) - surface_depth = max_slope_depth; - else - surface_depth = (1.-(slope-min_slope)/max_slope) * min_slope_depth; - for(s16 y0=0; y0insertBlock(block); - /* - Sector object stuff - */ - - // An y-wise container of changed blocks - core::map changed_blocks_sector; - - /* - Check if any sector's objects can be placed now. - If so, place them. - */ - core::map *objects = sector->getObjects(); - core::list objects_to_remove; - for(core::map::Iterator i = objects->getIterator(); - i.atEnd() == false; i++) - { - v3s16 p = i.getNode()->getKey(); - v2s16 p2d(p.X,p.Z); - u8 d = i.getNode()->getValue(); - - // Ground level point (user for stuff that is on ground) - v3s16 gp = p; - bool ground_found = true; - - // Search real ground level - try{ - for(;;) - { - MapNode n = sector->getNode(gp); - - // If not air, go one up and continue to placing the tree - if(n.d != CONTENT_AIR) - { - gp += v3s16(0,1,0); - break; - } - - // If air, go one down - gp += v3s16(0,-1,0); - } - }catch(InvalidPositionException &e) - { - // Ground not found. - ground_found = false; - // This is most close to ground - gp += v3s16(0,1,0); - } - - try - { - - if(d == SECTOR_OBJECT_TEST) - { - if(sector->isValidArea(p + v3s16(0,0,0), - p + v3s16(0,0,0), &changed_blocks_sector)) - { - MapNode n; - n.d = CONTENT_TORCH; - sector->setNode(p, n); - objects_to_remove.push_back(p); - } - } - else if(d == SECTOR_OBJECT_TREE_1) - { - if(ground_found == false) - continue; - - v3s16 p_min = gp + v3s16(-1,0,-1); - v3s16 p_max = gp + v3s16(1,5,1); - if(sector->isValidArea(p_min, p_max, - &changed_blocks_sector)) - { - MapNode n; - n.d = CONTENT_TREE; - sector->setNode(gp+v3s16(0,0,0), n); - sector->setNode(gp+v3s16(0,1,0), n); - sector->setNode(gp+v3s16(0,2,0), n); - sector->setNode(gp+v3s16(0,3,0), n); - - n.d = CONTENT_LEAVES; - - if(myrand()%4!=0) sector->setNode(gp+v3s16(0,5,0), n); - - if(myrand()%3!=0) sector->setNode(gp+v3s16(-1,5,0), n); - if(myrand()%3!=0) sector->setNode(gp+v3s16(1,5,0), n); - if(myrand()%3!=0) sector->setNode(gp+v3s16(0,5,-1), n); - if(myrand()%3!=0) sector->setNode(gp+v3s16(0,5,1), n); - /*if(myrand()%3!=0) sector->setNode(gp+v3s16(1,5,1), n); - if(myrand()%3!=0) sector->setNode(gp+v3s16(-1,5,1), n); - if(myrand()%3!=0) sector->setNode(gp+v3s16(-1,5,-1), n); - if(myrand()%3!=0) sector->setNode(gp+v3s16(1,5,-1), n);*/ - - sector->setNode(gp+v3s16(0,4,0), n); - - sector->setNode(gp+v3s16(-1,4,0), n); - sector->setNode(gp+v3s16(1,4,0), n); - sector->setNode(gp+v3s16(0,4,-1), n); - sector->setNode(gp+v3s16(0,4,1), n); - sector->setNode(gp+v3s16(1,4,1), n); - sector->setNode(gp+v3s16(-1,4,1), n); - sector->setNode(gp+v3s16(-1,4,-1), n); - sector->setNode(gp+v3s16(1,4,-1), n); - - sector->setNode(gp+v3s16(-1,3,0), n); - sector->setNode(gp+v3s16(1,3,0), n); - sector->setNode(gp+v3s16(0,3,-1), n); - sector->setNode(gp+v3s16(0,3,1), n); - sector->setNode(gp+v3s16(1,3,1), n); - sector->setNode(gp+v3s16(-1,3,1), n); - sector->setNode(gp+v3s16(-1,3,-1), n); - sector->setNode(gp+v3s16(1,3,-1), n); - - if(myrand()%3!=0) sector->setNode(gp+v3s16(-1,2,0), n); - if(myrand()%3!=0) sector->setNode(gp+v3s16(1,2,0), n); - if(myrand()%3!=0) sector->setNode(gp+v3s16(0,2,-1), n); - if(myrand()%3!=0) sector->setNode(gp+v3s16(0,2,1), n); - /*if(myrand()%3!=0) sector->setNode(gp+v3s16(1,2,1), n); - if(myrand()%3!=0) sector->setNode(gp+v3s16(-1,2,1), n); - if(myrand()%3!=0) sector->setNode(gp+v3s16(-1,2,-1), n); - if(myrand()%3!=0) sector->setNode(gp+v3s16(1,2,-1), n);*/ - - // Objects are identified by wanted position - objects_to_remove.push_back(p); - - // Lighting has to be recalculated for this one. - sector->getBlocksInArea(p_min, p_max, - lighting_invalidated_blocks); - } - } - else if(d == SECTOR_OBJECT_BUSH_1) - { - if(ground_found == false) - continue; - - if(sector->isValidArea(gp + v3s16(0,0,0), - gp + v3s16(0,0,0), &changed_blocks_sector)) - { - MapNode n; - n.d = CONTENT_LEAVES; - sector->setNode(gp+v3s16(0,0,0), n); - - // Objects are identified by wanted position - objects_to_remove.push_back(p); - } - } - else if(d == SECTOR_OBJECT_RAVINE) - { - s16 maxdepth = -20; - v3s16 p_min = p + v3s16(-6,maxdepth,-6); - v3s16 p_max = p + v3s16(6,6,6); - if(sector->isValidArea(p_min, p_max, - &changed_blocks_sector)) - { - MapNode n; - n.d = CONTENT_STONE; - MapNode n2; - n2.d = CONTENT_AIR; - s16 depth = maxdepth + (myrand()%10); - s16 z = 0; - s16 minz = -6 - (-2); - s16 maxz = 6 -1; - for(s16 x=-6; x<=6; x++) - { - z += -1 + (myrand()%3); - if(z < minz) - z = minz; - if(z > maxz) - z = maxz; - for(s16 y=depth+(myrand()%2); y<=6; y++) - { - /*std::cout<<"("<getNode(p2).d)) - if(content_features(sector->getNode(p2).d).walkable) - sector->setNode(p2, n); - } - { - v3s16 p2 = p + v3s16(x,y,z-1); - if(content_features(sector->getNode(p2).d).walkable) - sector->setNode(p2, n2); - } - { - v3s16 p2 = p + v3s16(x,y,z+0); - if(content_features(sector->getNode(p2).d).walkable) - sector->setNode(p2, n2); - } - { - v3s16 p2 = p + v3s16(x,y,z+1); - if(content_features(sector->getNode(p2).d).walkable) - sector->setNode(p2, n); - } - - //if(sector->getNode(p+v3s16(x,y,z+1)).solidness()==2) - //if(p.Y+y <= sector->getGroundHeight(p2d+v2s16(x,z-2))+0.5) - } - } - - objects_to_remove.push_back(p); - - // Lighting has to be recalculated for this one. - sector->getBlocksInArea(p_min, p_max, - lighting_invalidated_blocks); - } - } - else - { - dstream<<"ServerMap::generateBlock(): " - "Invalid heightmap object" - <getPos().X<<"," - <getPos().Y<<"," - <getPos().Z<<")" - <getPos().X<<"," + <getPos().Y<<"," + <getPos().Z<<")" + < list2 = fs::GetDirListing + (m_savedir+"/sectors/"+i->name); + std::vector::iterator i2; + for(i2=list2.begin(); i2!=list2.end(); i2++) { - std::vector list2 = fs::GetDirListing - (m_savedir+"/sectors/"+i->name); - std::vector::iterator i2; - for(i2=list2.begin(); i2!=list2.end(); i2++) + // We want files + if(i2->dir) + continue; + try{ + loadBlock(i->name, i2->name, sector); + } + catch(InvalidFilenameException &e) { - // We want files - if(i2->dir) - continue; - try{ - loadBlock(i->name, i2->name, sector); - } - catch(InvalidFilenameException &e) - { - // This catches unknown crap in directory - } + // This catches unknown crap in directory } } } @@ -5019,46 +4480,30 @@ void ServerMap::loadAll() void ServerMap::saveMasterHeightmap() { DSTACK(__FUNCTION_NAME); + + dstream<<"DEPRECATED: "<<__FUNCTION_NAME< hmdata = m_heightmap->serialize(version); - /* - [0] u8 serialization version - [1] X master heightmap - */ - u32 fullsize = 1 + hmdata.getSize(); - SharedBuffer data(fullsize); - - data[0] = version; - memcpy(&data[1], *hmdata, hmdata.getSize()); - - o.write((const char*)*data, fullsize); -#endif - - m_heightmap->serialize(o, version); + //u8 version = SER_FMT_VER_HIGHEST; } void ServerMap::loadMasterHeightmap() { DSTACK(__FUNCTION_NAME); - std::string fullpath = m_savedir + "/master_heightmap"; + + dstream<<"DEPRECATED: "<<__FUNCTION_NAME<differs_from_disk = false; @@ -5128,23 +4573,20 @@ bool ServerMap::loadSectorFull(v2s16 p2d) return false; } - if(ENABLE_BLOCK_LOADING) + std::vector list2 = fs::GetDirListing + (m_savedir+"/sectors/"+sectorsubdir); + std::vector::iterator i2; + for(i2=list2.begin(); i2!=list2.end(); i2++) { - std::vector list2 = fs::GetDirListing - (m_savedir+"/sectors/"+sectorsubdir); - std::vector::iterator i2; - for(i2=list2.begin(); i2!=list2.end(); i2++) + // We want files + if(i2->dir) + continue; + try{ + loadBlock(sectorsubdir, i2->name, sector); + } + catch(InvalidFilenameException &e) { - // We want files - if(i2->dir) - continue; - try{ - loadBlock(sectorsubdir, i2->name, sector); - } - catch(InvalidFilenameException &e) - { - // This catches unknown crap in directory - } + // This catches unknown crap in directory } } return true; @@ -5302,7 +4744,8 @@ void ServerMap::loadBlock(std::string sectordir, std::string blockfile, MapSecto // Gets from master heightmap void ServerMap::getSectorCorners(v2s16 p2d, s16 *corners) { - assert(m_heightmap != NULL); + dstream<<"DEPRECATED: "<<__FUNCTION_NAME<getGroundHeight + /*corners[0] = m_heightmap->getGroundHeight ((p2d+v2s16(0,0))*SECTOR_HEIGHTMAP_SPLIT); corners[1] = m_heightmap->getGroundHeight ((p2d+v2s16(1,0))*SECTOR_HEIGHTMAP_SPLIT); corners[2] = m_heightmap->getGroundHeight ((p2d+v2s16(1,1))*SECTOR_HEIGHTMAP_SPLIT); corners[3] = m_heightmap->getGroundHeight - ((p2d+v2s16(0,1))*SECTOR_HEIGHTMAP_SPLIT); + ((p2d+v2s16(0,1))*SECTOR_HEIGHTMAP_SPLIT);*/ } void ServerMap::PrintInfo(std::ostream &out) @@ -5341,10 +4784,9 @@ ClientMap::ClientMap( Map(dout_client), scene::ISceneNode(parent, mgr, id), m_client(client), - mesh(NULL), m_control(control) { - mesh_mutex.Init(); + //mesh_mutex.Init(); /*m_box = core::aabbox3d(0,0,0, map->getW()*BS, map->getH()*BS, map->getD()*BS);*/ @@ -5360,13 +4802,13 @@ ClientMap::ClientMap( ClientMap::~ClientMap() { - JMutexAutoLock lock(mesh_mutex); + /*JMutexAutoLock lock(mesh_mutex); if(mesh != NULL) { mesh->drop(); mesh = NULL; - } + }*/ } MapSector * ClientMap::emergeSector(v2s16 p2d) diff --git a/src/map.h b/src/map.h index 4af529c21..b3ef47282 100644 --- a/src/map.h +++ b/src/map.h @@ -34,7 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #endif #include "common_irrlicht.h" -#include "heightmap.h" +//#include "heightmap.h" #include "mapnode.h" #include "mapblock.h" #include "mapsector.h" @@ -46,7 +46,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define MAPTYPE_SERVER 1 #define MAPTYPE_CLIENT 2 -class Map : public NodeContainer, public Heightmappish +class Map : public NodeContainer { public: @@ -273,42 +273,12 @@ protected: MapSector *m_sector_cache; v2s16 m_sector_cache_p; - WrapperHeightmap m_hwrapper; + //WrapperHeightmap m_hwrapper; // Queued transforming water nodes UniqueQueue m_transforming_liquid; }; -// Master heightmap parameters -struct HMParams -{ - HMParams() - { - blocksize = 64; - randmax = "constant 70.0"; - randfactor = "constant 0.6"; - base = "linear 0 80 0"; - } - s16 blocksize; - std::string randmax; - std::string randfactor; - std::string base; -}; - -// Map parameters -struct MapParams -{ - MapParams() - { - plants_amount = 1.0; - ravines_amount = 1.0; - //max_objects_in_block = 30; - } - float plants_amount; - float ravines_amount; - //u16 max_objects_in_block; -}; - /* ServerMap @@ -321,7 +291,7 @@ public: /* savedir: directory to which map data should be saved */ - ServerMap(std::string savedir, HMParams hmp, MapParams mp); + ServerMap(std::string savedir); ~ServerMap(); s32 mapType() const @@ -504,7 +474,16 @@ public: void save(bool only_changed); void loadAll(); - + + // TODO + void saveMapMeta(); + void loadMapMeta(); + + // TODO + void saveChunkMeta(); + void loadChunkMeta(); + + // DEPRECATED void saveMasterHeightmap(); void loadMasterHeightmap(); @@ -512,6 +491,7 @@ public: // This only saves sector-specific data such as the heightmap // (no MapBlocks) + // DEPRECATED? Sectors have no metadata anymore. void saveSectorMeta(ServerMapSector *sector); MapSector* loadSectorMeta(std::string dirname); @@ -527,17 +507,13 @@ public: void loadBlock(std::string sectordir, std::string blockfile, MapSector *sector); // Gets from master heightmap + // DEPRECATED? void getSectorCorners(v2s16 p2d, s16 *corners); // For debug printing virtual void PrintInfo(std::ostream &out); private: - // Generator parameters - UnlimitedHeightmap *m_heightmap; - MapParams m_params; - PointAttributeDatabase m_padb; - // Seed used for all kinds of randomness u64 m_seed; @@ -664,8 +640,8 @@ private: core::aabbox3d m_box; // This is the master heightmap mesh - scene::SMesh *mesh; - JMutex mesh_mutex; + //scene::SMesh *mesh; + //JMutex mesh_mutex; MapDrawControl &m_control; }; diff --git a/src/mapblock.cpp b/src/mapblock.cpp index da7d22ac5..fdc30dfd1 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -612,7 +612,7 @@ void MapBlock::updateMesh(u32 daynight_ratio) bool new_style_water = g_settings.getBool("new_style_water"); float node_water_level = 1.0; if(new_style_water) - node_water_level = 0.8; + node_water_level = 0.9; /* We are including the faces of the trailing edges of the block. diff --git a/src/mapsector.cpp b/src/mapsector.cpp index 1fd668793..a24b6c5de 100644 --- a/src/mapsector.cpp +++ b/src/mapsector.cpp @@ -176,168 +176,22 @@ void MapSector::getBlocks(core::list &dest) ServerMapSector */ -ServerMapSector::ServerMapSector(NodeContainer *parent, v2s16 pos, u16 hm_split): - MapSector(parent, pos), - m_hm_split(hm_split), - m_objects(NULL) +ServerMapSector::ServerMapSector(NodeContainer *parent, v2s16 pos): + MapSector(parent, pos) { - // hm_split has to be 1 or 2^x - assert(hm_split == 0 || hm_split == 1 || (hm_split & (hm_split-1)) == 0); - assert(hm_split * hm_split <= MAPSECTOR_FIXEDHEIGHTMAPS_MAXCOUNT); - - for(u16 i=0; igetGroundHeight(p_in_hm); - - /*if(h < GROUNDHEIGHT_VALID_MINVALUE) - { - std::cout<<"Sector heightmap ("<setGroundHeight(p_in_hm, y); - - differs_from_disk = true; } void ServerMapSector::serialize(std::ostream &os, u8 version) @@ -351,118 +205,21 @@ void ServerMapSector::serialize(std::ostream &os, u8 version) */ // Server has both of these, no need to support not having them. - assert(m_objects != NULL); + //assert(m_objects != NULL); // Write version os.write((char*)&version, 1); /* - Serialize heightmap(s) + Add stuff here, if needed */ - // Version with single heightmap - if(version <= 7) - { - u32 heightmap_size = - FixedHeightmap::serializedLength(version, MAP_BLOCKSIZE); - - SharedBuffer data(heightmap_size); - m_heightmaps[0]->serialize(*data, version); - - os.write((const char*)*data, heightmap_size); - - if(version >= 5) - { - /* - Write objects - */ - - u16 object_count; - if(m_objects->size() > 65535) - object_count = 65535; - else - object_count = m_objects->size(); - - u8 b[2]; - writeU16(b, object_count); - os.write((char*)b, 2); - - core::map::Iterator i; - i = m_objects->getIterator(); - for(; i.atEnd() == false; i++) - { - v3s16 p = i.getNode()->getKey(); - u8 d = i.getNode()->getValue(); - u8 b[7]; - writeV3S16(&b[0], p); - b[6] = d; - os.write((char*)b, 7); - } - } - } - // Version with multiple heightmaps - else - { - u8 buf[2]; - - if(m_hm_split > 255) - throw SerializationError("Sector has too many heightmaps"); - - // Write heightmap split ratio - writeU8(buf, m_hm_split); - os.write((char*)buf, 1); - - // If there are heightmaps, write them - if(m_hm_split != 0) - { - u16 hm_d = MAP_BLOCKSIZE / m_hm_split; - - u32 hm_size = FixedHeightmap::serializedLength(version, hm_d); - SharedBuffer data(hm_size); - - u16 hm_count = m_hm_split * m_hm_split; - - // Write heightmaps - for(u16 i=0; iserialize(*data, version); - os.write((const char*)*data, hm_size); - } - } - - /* - Write objects - */ - - u16 object_count; - if(m_objects->size() > 65535) - object_count = 65535; - else - object_count = m_objects->size(); - - u8 b[2]; - writeU16(b, object_count); - os.write((char*)b, 2); - - core::map::Iterator i; - i = m_objects->getIterator(); - for(; i.atEnd() == false; i++) - { - v3s16 p = i.getNode()->getKey(); - u8 d = i.getNode()->getValue(); - u8 b[7]; - writeV3S16(&b[0], p); - b[6] = d; - os.write((char*)b, 7); - } - } } ServerMapSector* ServerMapSector::deSerialize( std::istream &is, NodeContainer *parent, v2s16 p2d, - Heightmap *master_hm, core::map & sectors ) { @@ -483,82 +240,8 @@ ServerMapSector* ServerMapSector::deSerialize( throw VersionMismatchException("ERROR: MapSector format not supported"); /* - Read heightmap(s) - */ - - FixedHeightmap *hms[MAPSECTOR_FIXEDHEIGHTMAPS_MAXCOUNT]; - u16 hm_split = 0; - - // Version with a single heightmap - if(version <= 7) - { - hm_split = 1; - - u32 hm_size = - FixedHeightmap::serializedLength(version, MAP_BLOCKSIZE); - - SharedBuffer data(hm_size); - is.read((char*)*data, hm_size); - - hms[0] = new FixedHeightmap(master_hm, p2d, MAP_BLOCKSIZE); - hms[0]->deSerialize(*data, version); - } - // Version with multiple heightmaps - else - { - u8 buf[2]; - - // Read split ratio - is.read((char*)buf, 1); - hm_split = readU8(buf); - - // If there are heightmaps, read them - if(hm_split != 0) - { - u16 hm_count = hm_split * hm_split; - - if(hm_count > MAPSECTOR_FIXEDHEIGHTMAPS_MAXCOUNT) - throw SerializationError("Sector has too many heightmaps"); - - u16 hm_d = MAP_BLOCKSIZE / hm_split; - - u32 hm_size = FixedHeightmap::serializedLength(version, hm_d); - - u16 i=0; - for(s16 y=0; y data(hm_size); - is.read((char*)*data, hm_size); - - hms[i] = new FixedHeightmap(master_hm, p2d+v2s16(x,y), hm_d); - hms[i]->deSerialize(*data, version); - i++; - } - } - } - - /* - Read objects + Add necessary reading stuff here */ - - core::map *objects = new core::map; - - if(version >= 5) - { - u8 b[2]; - is.read((char*)b, 2); - u16 object_count = readU16(b); - - for(u16 i=0; iinsert(p, d); - } - } /* Get or create sector @@ -574,18 +257,13 @@ ServerMapSector* ServerMapSector::deSerialize( "at the moment, because code hasn't been tested." <getValue(); assert(sector->getId() == MAPSECTOR_SERVER); return (ServerMapSector*)sector; - - // NOTE: At least hm_split mismatch would have to be checked - - //sector = n->getValue(); } else { - sector = new ServerMapSector(parent, p2d, hm_split); + sector = new ServerMapSector(parent, p2d); sectors.insert(p2d, sector); } @@ -593,26 +271,7 @@ ServerMapSector* ServerMapSector::deSerialize( Set stuff in sector */ - // Set heightmaps - - sector->m_hm_split = hm_split; - - u16 hm_count = hm_split * hm_split; - - for(u16 i=0; im_heightmaps[i]; - sector->m_heightmaps[i] = hms[i]; - if(oldhm != NULL) - delete oldhm; - } - - // Set (or change) objects - core::map *oldfo = sector->m_objects; - sector->m_objects = objects; - if(oldfo) - delete oldfo; + // Nothing here return sector; } @@ -654,29 +313,21 @@ void ClientMapSector::deSerialize(std::istream &is) if(!ser_ver_supported(version)) throw VersionMismatchException("ERROR: MapSector format not supported"); - if(version <= 7) - throw VersionMismatchException("ERROR: MapSector format not supported"); u8 buf[2]; - // Read corners + // Dummy read corners is.read((char*)buf, 2); - s16 c0 = readU16(buf); is.read((char*)buf, 2); - s16 c1 = readU16(buf); is.read((char*)buf, 2); - s16 c2 = readU16(buf); is.read((char*)buf, 2); - s16 c3 = readU16(buf); /* Set stuff in sector */ - m_corners[0] = c0; - m_corners[1] = c1; - m_corners[2] = c2; - m_corners[3] = c3; + // Nothing here + } #endif // !SERVER diff --git a/src/mapsector.h b/src/mapsector.h index de93806b5..2888eb7b2 100644 --- a/src/mapsector.h +++ b/src/mapsector.h @@ -27,26 +27,17 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include "common_irrlicht.h" #include "mapblock.h" -#include "heightmap.h" +//#include "heightmap.h" #include "exceptions.h" /* This is an Y-wise stack of MapBlocks. */ -#define SECTOR_OBJECT_TEST 0 -#define SECTOR_OBJECT_TREE_1 1 -#define SECTOR_OBJECT_BUSH_1 2 -#define SECTOR_OBJECT_RAVINE 3 - -//#define MAPSECTOR_FIXEDHEIGHTMAPS_MAXCOUNT 4 -#define MAPSECTOR_FIXEDHEIGHTMAPS_MAXCOUNT \ - (SECTOR_HEIGHTMAP_SPLIT * SECTOR_HEIGHTMAP_SPLIT) - #define MAPSECTOR_SERVER 0 #define MAPSECTOR_CLIENT 1 -class MapSector: public NodeContainer, public Heightmappish +class MapSector: public NodeContainer { public: @@ -198,6 +189,7 @@ public: blockref->setNode(relpos, n); } + // DEPRECATED? virtual f32 getGroundHeight(v2s16 p, bool generate=false) { return GROUNDHEIGHT_NOTFOUND_SETVALUE; @@ -245,44 +237,15 @@ protected: class ServerMapSector : public MapSector { public: - ServerMapSector(NodeContainer *parent, v2s16 pos, u16 hm_split); + ServerMapSector(NodeContainer *parent, v2s16 pos); ~ServerMapSector(); u32 getId() const { return MAPSECTOR_SERVER; } - - void setHeightmap(v2s16 hm_p, FixedHeightmap *hm); - FixedHeightmap * getHeightmap(v2s16 hm_p); - - void printHeightmaps() - { - for(s16 y=0; yprint(); - } - } - void setObjects(core::map *objects) - { - m_objects = objects; - differs_from_disk = true; - } - - core::map * getObjects() - { - differs_from_disk = true; - return m_objects; - } - + // DEPRECATED? f32 getGroundHeight(v2s16 p, bool generate=false); void setGroundHeight(v2s16 p, f32 y, bool generate=false); @@ -296,20 +259,10 @@ public: std::istream &is, NodeContainer *parent, v2s16 p2d, - Heightmap *master_hm, core::map & sectors ); private: - // Heightmap(s) for the sector - FixedHeightmap *m_heightmaps[MAPSECTOR_FIXEDHEIGHTMAPS_MAXCOUNT]; - // Sector is split in m_hm_split^2 heightmaps. - // Value of 0 means there is no heightmap. - u16 m_hm_split; - // These are removed when they are drawn to blocks. - // - Each is drawn when generating blocks; When the last one of - // the needed blocks is being generated. - core::map *m_objects; }; #ifndef SERVER @@ -326,14 +279,14 @@ public: void deSerialize(std::istream &is); - s16 getCorner(u16 i) + /*s16 getCorner(u16 i) { return m_corners[i]; - } + }*/ private: // The ground height of the corners is stored in here - s16 m_corners[4]; + //s16 m_corners[4]; }; #endif diff --git a/src/server.cpp b/src/server.cpp index abf48df9a..a3baaf1a3 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1022,11 +1022,9 @@ u32 PIChecksum(core::list &l) */ Server::Server( - std::string mapsavedir, - HMParams hm_params, - MapParams map_params + std::string mapsavedir ): - m_env(new ServerMap(mapsavedir, hm_params, map_params), dout_server), + m_env(new ServerMap(mapsavedir), dout_server), m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this), m_thread(this), m_emergethread(this), @@ -1406,8 +1404,10 @@ void Server::AsyncRunStep() } } - // Trigger emergethread (it gets somehow gets to a - // non-triggered but bysy state sometimes) + /* + Trigger emergethread (it somehow gets to a non-triggered but + bysy state sometimes) + */ { float &counter = m_emergethread_trigger_timer; counter += dtime; diff --git a/src/server.h b/src/server.h index fcc37631f..d19a440d7 100644 --- a/src/server.h +++ b/src/server.h @@ -377,9 +377,7 @@ public: NOTE: Every public method should be thread-safe */ Server( - std::string mapsavedir, - HMParams hm_params, - MapParams map_params + std::string mapsavedir ); ~Server(); void start(unsigned short port); diff --git a/src/servermain.cpp b/src/servermain.cpp index 5409fcfb3..7ec397ace 100644 --- a/src/servermain.cpp +++ b/src/servermain.cpp @@ -263,18 +263,6 @@ int main(int argc, char *argv[]) init_mapnode(&irrlicht); init_mineral(&irrlicht); - // Read map parameters from settings - - HMParams hm_params; - /*hm_params.blocksize = g_settings.getU16("heightmap_blocksize"); - hm_params.randmax = g_settings.get("height_randmax"); - hm_params.randfactor = g_settings.get("height_randfactor"); - hm_params.base = g_settings.get("height_base");*/ - - MapParams map_params; - map_params.plants_amount = g_settings.getFloat("plants_amount"); - map_params.ravines_amount = g_settings.getFloat("ravines_amount"); - /* Check parameters */ @@ -316,7 +304,7 @@ int main(int argc, char *argv[]) map_dir = g_settings.get("map-dir"); // Create server - Server server(map_dir.c_str(), hm_params, map_params); + Server server(map_dir.c_str()); server.start(port); // Run server diff --git a/src/test.cpp b/src/test.cpp index d3c17f70c..e5b22a978 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -23,7 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "map.h" #include "player.h" #include "main.h" -#include "heightmap.h" #include "socket.h" #include "connection.h" #include "utility.h" @@ -628,9 +627,7 @@ struct TestMapSector parent.position_valid = false; // Create one with no heightmaps - ServerMapSector sector(&parent, v2s16(1,1), 0); - //ConstantGenerator *dummyheightmap = new ConstantGenerator(); - //sector->setHeightmap(dummyheightmap); + ServerMapSector sector(&parent, v2s16(1,1)); EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(0)); EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(1)); @@ -654,134 +651,6 @@ struct TestMapSector } }; -struct TestHeightmap -{ - void TestSingleFixed() - { - const s16 BS1 = 4; - OneChildHeightmap hm1(BS1); - - // Test that it is filled with < GROUNDHEIGHT_VALID_MINVALUE - for(s16 y=0; y<=BS1; y++){ - for(s16 x=0; x<=BS1; x++){ - v2s16 p(x,y); - assert(hm1.m_child.getGroundHeight(p) - < GROUNDHEIGHT_VALID_MINVALUE); - } - } - - hm1.m_child.setGroundHeight(v2s16(1,0), 2.0); - //hm1.m_child.print(); - assert(fabs(hm1.getGroundHeight(v2s16(1,0))-2.0)<0.001); - hm1.setGroundHeight(v2s16(0,1), 3.0); - assert(fabs(hm1.m_child.getGroundHeight(v2s16(0,1))-3.0)<0.001); - - // Fill with -1.0 - for(s16 y=0; y<=BS1; y++){ - for(s16 x=0; x<=BS1; x++){ - v2s16 p(x,y); - hm1.m_child.setGroundHeight(p, -1.0); - } - } - - f32 corners[] = {0.0, 0.0, 1.0, 1.0}; - hm1.m_child.generateContinued(0.0, 0.0, corners); - - hm1.m_child.print(); - assert(fabs(hm1.m_child.getGroundHeight(v2s16(1,0))-0.2)<0.05); - assert(fabs(hm1.m_child.getGroundHeight(v2s16(4,3))-0.7)<0.05); - assert(fabs(hm1.m_child.getGroundHeight(v2s16(4,4))-1.0)<0.05); - } - - void TestUnlimited() - { - //g_heightmap_debugprint = true; - const s16 BS1 = 4; - /*UnlimitedHeightmap hm1(BS1, - new ConstantGenerator(0.0), - new ConstantGenerator(0.0), - new ConstantGenerator(5.0));*/ - PointAttributeDatabase padb; - UnlimitedHeightmap hm1(BS1, &padb); - // Go through it so it generates itself - for(s16 y=0; y<=BS1; y++){ - for(s16 x=0; x<=BS1; x++){ - v2s16 p(x,y); - hm1.getGroundHeight(p); - } - } - // Print it - dstream<<"UnlimitedHeightmap hm1:"<setGroundHeight(p1, v1); - // Read from UnlimitedHeightmap - assert(fabs(hm1.getGroundHeight(p1)-v1)<0.001); - } - - void Random() - { - dstream<<"Running random code (get a human to check this)"<addPoint(v2s16(-BS1,0), Attribute(0)); - padb.getList("hm_randmax")->addPoint(v2s16(-BS1,0), Attribute(0)); - padb.getList("hm_randfactor")->addPoint(v2s16(-BS1,0), Attribute(0.0)); - - padb.getList("hm_baseheight")->addPoint(v2s16(0,0), Attribute(-20)); - padb.getList("hm_randmax")->addPoint(v2s16(0,0), Attribute(0)); - padb.getList("hm_randfactor")->addPoint(v2s16(0,0), Attribute(0.5)); - - padb.getList("hm_baseheight")->addPoint(v2s16(BS1*2,BS1), Attribute(0)); - padb.getList("hm_randmax")->addPoint(v2s16(BS1*2,BS1), Attribute(30)); - padb.getList("hm_randfactor")->addPoint(v2s16(BS1*2,BS1), Attribute(0.63)); - - UnlimitedHeightmap hm1(BS1, &padb); - - // Force hm1 to generate a some heightmap - hm1.getGroundHeight(v2s16(0,0)); - hm1.getGroundHeight(v2s16(0,BS1)); - /*hm1.getGroundHeight(v2s16(BS1,-1)); - hm1.getGroundHeight(v2s16(BS1-1,-1));*/ - hm1.print(); - - // Get the (0,0) and (1,0) heightmaps - /*FixedHeightmap * hr00 = hm1.getHeightmap(v2s16(0,0)); - FixedHeightmap * hr01 = hm1.getHeightmap(v2s16(1,0)); - f32 corners[] = {1.0, 1.0, 1.0, 1.0}; - hr00->generateContinued(0.0, 0.0, corners); - hm1.print();*/ - - //assert(0); - } - - void Run() - { - //srand(7); // Get constant random - srand(time(0)); // Get better random - - TestSingleFixed(); - TestUnlimited(); - Random(); - } -}; - struct TestSocket { void Run() @@ -1149,7 +1018,6 @@ void run_tests() TEST(TestVoxelManipulator); TEST(TestMapBlock); TEST(TestMapSector); - TEST(TestHeightmap); if(INTERNET_SIMULATOR == false){ TEST(TestSocket); dout_con<<"=== BEGIN RUNNING UNIT TESTS FOR CONNECTION ==="< near_list; - - for(core::list::Iterator - i = m_points.begin(); - i != m_points.end(); i++) - { - PointWithAttr &pwa = *i; - u32 d = pwa.p.getDistanceFrom(p); - - DFloat df; - df.v = pwa.attr.getFloat(); - df.d = d; - - // If near list is empty, add directly and continue - if(near_list.size() == 0) - { - near_list.push_back(df); - continue; - } - - // Get distance of farthest in near list - u32 near_d = 100000; - if(near_list.size() > 0) - { - core::list::Iterator i = near_list.begin(); - near_d = i->d; - } - - /* - If point is closer than the farthest in the near list or - there are not yet enough points on the list - */ - if(d < near_d || near_list.size() < near_wanted_count) - { - // Find the right place in the near list and put it there - - // Go from farthest to near in the near list - core::list::Iterator i = near_list.begin(); - for(; i != near_list.end(); i++) - { - // Stop when i is at the first nearer node - if(i->d < d) - break; - } - // Add df to before i - if(i == near_list.end()) - near_list.push_back(df); - else - near_list.insert_before(i, df); - - // Keep near list at right size - if(near_list.size() > near_wanted_count) - { - core::list::Iterator j = near_list.begin(); - near_list.erase(j); - } - } - } - - // Return if no values found - if(near_list.size() == 0) - return 0.0; - - /* -20:58:29 < tejeez> joka pisteelle a += arvo / etäisyys^6; b += 1 / etäisyys^6; ja -lopuks sit otetaan a/b - */ - - float a = 0; - float b = 0; - for(core::list::Iterator i = near_list.begin(); - i != near_list.end(); i++) - { - if(i->d == 0) - return i->v; - - //float dd = pow((float)i->d, 6); - float dd = pow((float)i->d, 5); - float v = i->v; - //dstream<<"dd="<d="<d<<" nearest_d_sum="<