From cde3d38766a19ddbe001e70573eb521eaf62cc66 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Wed, 26 Dec 2012 03:15:16 -0500 Subject: [PATCH] Clean up EmergeManager, do initial work on Mapgen configuration --- src/map.cpp | 65 ++++++++++++++++++--- src/mapgen.cpp | 132 ++++++++++++++++++++++++------------------ src/mapgen.h | 142 +++++++++++++++++++++++++++++++++++++--------- src/mapgen_v6.cpp | 117 ++++++++++++++++++++++---------------- src/scriptapi.cpp | 8 +++ src/server.cpp | 12 ++-- 6 files changed, 327 insertions(+), 149 deletions(-) diff --git a/src/map.cpp b/src/map.cpp index 3f18ef2e..d6d8c561 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -2019,8 +2019,8 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef, EmergeManager *emer { m_seed = g_settings->getU64("fixed_map_seed"); } - emerge->seed = m_seed; - emerge->water_level = g_settings->getS16("default_water_level"); + //emerge->params.seed = m_seed; + //emerge->params.water_level = g_settings->getS16("default_water_level"); //mapgen version //chunksize //noiseparams @@ -3078,8 +3078,31 @@ void ServerMap::saveMapMeta() } Settings params; - params.setU64("seed", m_seed); - params.setS16("water_level", m_emerge->water_level); + + params.setS16("mg_version", m_emerge->mg_version); + + params.setU64("seed", m_emerge->params->seed); + params.setS16("water_level", m_emerge->params->water_level); + params.setS16("chunksize", m_emerge->params->chunksize); + params.setS32("flags", m_emerge->params->flags); + switch (m_emerge->mg_version) { + case 6: + { + MapgenV6Params *v6params = m_emerge->params; + + params.setFloat("freq_desert", v6params->freq_desert); + params.setFloat("freq_beach", v6params->freq_beach); + + break; + } + case 7: + { + MapgenV7Params *v7params = m_emerge->params; + break; + } + default: + ; //complain here + } params.writeLines(os); @@ -3119,10 +3142,36 @@ void ServerMap::loadMapMeta() params.parseConfigLine(line); } - m_seed = params.getU64("seed"); - m_emerge->seed = m_seed; - m_emerge->water_level = params.getS16("water_level"); - //m_emerge->np = ; + m_emerge->mg_version = params.getS16("mg_version"); + m_emerge->setMapgenParams(); + + m_emerge->params->seed = params.getU64("seed"); + m_emerge->params->water_level = params.getS16("water_level"); + m_emerge->params->chunksize = params.getS16("chunksize"); + m_emerge->params->flags = params.getS32("flags"); + + m_seed = m_emerge->params->seed; + + switch (m_emerge->mg_version) { + case 6: + { + MapgenV6Params *v6params = m_emerge->params; + + v6params->freq_desert = params.getFloat("freq_desert"); + v6params->freq_beach = params.getFloat("freq_beach"); + + break; + } + case 7: + { + MapgenV7Params *v6params = m_emerge->params; + + break; + } + default: + ; //complain here + } + verbosestream<<"ServerMap::loadMapMeta(): "<<"seed="<generating = false; this->id = mapgenid; - this->seed = (int)seed; this->biomedef = biomedef; - this->csize = v3s16(5, 5, 5) * MAP_BLOCKSIZE; /////////////////get this from config! - this->water_level = g_settings->getS16("default_water_level"); ////fix this! - this->ystride = csize.X; + this->seed = params->seed; + this->csize = v3s16(1, 1, 1) * params->chunksize * MAP_BLOCKSIZE; /////////////////get this from config! + this->water_level = params->water_level; + + //g_settings->getS16("default_water_level"); + + /* this->np_terrain = np_terrain; this->np_bgroup = np_bgroup; this->np_heat = np_heat; this->np_humidity = np_humidity; - noise_terrain = new Noise(np_terrain, seed, csize.X, csize.Y); - noise_bgroup = new Noise(np_bgroup, seed, csize.X, csize.Y); - noise_heat = new Noise(np_heat, seed, csize.X, csize.Y); - noise_humidity = new Noise(np_humidity, seed, csize.X, csize.Y); + */ + noise_terrain = new Noise(params->np_terrain, seed, csize.X, csize.Y); + noise_bgroup = new Noise(params->np_bgroup, seed, csize.X, csize.Y); + noise_heat = new Noise(params->np_heat, seed, csize.X, csize.Y); + noise_humidity = new Noise(params->np_humidity, seed, csize.X, csize.Y); this->ndef = biomedef->ndef; n_air = MapNode(ndef->getId("mapgen_air")); @@ -122,9 +110,6 @@ void MapgenV7::makeChunk(BlockMakeData *data) { this->ystride = em.X; this->zstride = em.Y * em.X; - if (node_max.X - node_min.X != 80) - printf("uhoh, diff = %d, ystride = %d\n", node_max.X - node_min.X, ystride); - node_min = (data->blockpos_min) * MAP_BLOCKSIZE; node_max = (data->blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1); v3s16 full_node_min = (data->blockpos_min - 1) * MAP_BLOCKSIZE; @@ -166,18 +151,18 @@ void MapgenV7::makeChunk(BlockMakeData *data) { } -void MapgenV7::updateLiquid(v3s16 node_min, v3s16 node_max) { +void MapgenV7::updateLiquid(v3s16 nmin, v3s16 nmax) { bool isliquid, wasliquid; u32 i; - for (s16 z = node_min.Z; z <= node_max.Z; z++) { - for (s16 x = node_min.X; x <= node_max.X; x++) { + for (s16 z = nmin.Z; z <= nmax.Z; z++) { + for (s16 x = nmin.X; x <= nmax.X; x++) { v2s16 p2d(x, z); wasliquid = true; v3s16 em = vmanip->m_area.getExtent(); - i = vmanip->m_area.index(v3s16(p2d.X, node_max.Y, p2d.Y)); + i = vmanip->m_area.index(v3s16(p2d.X, nmax.Y, p2d.Y)); - for (s16 y = node_max.Y; y >= node_min.Y; y--) { + for (s16 y = nmax.Y; y >= nmin.Y; y--) { isliquid = ndef->get(vmanip->m_data[i]).isLiquid(); //there was a change between liquid and nonliquid, add to queue if (isliquid != wasliquid) @@ -191,12 +176,12 @@ void MapgenV7::updateLiquid(v3s16 node_min, v3s16 node_max) { } -void MapgenV7::updateLighting(v3s16 node_min, v3s16 node_max) { +void MapgenV7::updateLighting(v3s16 nmin, v3s16 nmax) { enum LightBank banks[2] = {LIGHTBANK_DAY, LIGHTBANK_NIGHT}; - VoxelArea a(node_min - v3s16(1,0,1) * MAP_BLOCKSIZE, - node_max + v3s16(1,0,1) * MAP_BLOCKSIZE); - bool block_is_underground = (water_level > node_max.Y); + VoxelArea a(nmin - v3s16(1,0,1) * MAP_BLOCKSIZE, + nmax + v3s16(1,0,1) * MAP_BLOCKSIZE); + bool block_is_underground = (water_level > nmax.Y); bool sunlight = !block_is_underground; ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update", SPT_AVG); @@ -215,20 +200,55 @@ void MapgenV7::updateLighting(v3s16 node_min, v3s16 node_max) { } -EmergeManager::EmergeManager(IGameDef *gamedef) { - this->seed = 0; - this->water_level = 0; - this->np_terrain = &nparams_mtdefault; - this->np_bgroup = &nparams_def_bgroup; - this->np_heat = &nparams_def_heat; - this->np_humidity = &nparams_def_humidity; +EmergeManager::EmergeManager(IGameDef *gamedef, int mg_version) { + this->mg_version = mg_version; + this->biomedef = new BiomeDefManager(gamedef); - this->biomedef = new BiomeDefManager(gamedef); + this->params = NULL; + setMapgenParams(); } EmergeManager::~EmergeManager() { delete biomedef; + delete params; +} + + +Mapgen *EmergeManager::getMapgen() { + if (!mapgen) { + switch (mg_version) { + case 6: + mapgen = new MapgenV6(0, params); + break; + case 7: + mapgen = new MapgenV7(biomedef, 0, params); + break; + default: + errorstream << "EmergeManager: Unsupported mapgen version " + << mg_version << ", falling back to V6" << std::endl; + mg_version = 6; + mapgen = new MapgenV6(0, mgv6params); + } + } + return mapgen; +} + + +void EmergeManager::setMapgenParams() { + if (params) + delete params; + + switch (mg_version) { + case 6: + params = new MapgenV6Params(); + break; + case 7: + params = new MapgenV7Params(); + break; + default: //////do something here! + ; + } } diff --git a/src/mapgen.h b/src/mapgen.h index 76ae73c5..81de0d17 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -58,18 +58,110 @@ struct BlockMakeData { }; +/////////////////// Mapgen flags +#define MG_TREES 0x01 +#define MG_CAVES 0x02 +#define MG_DUNGEONS 0x04 +#define MGV6_FORESTS 0x08 +#define MGV6_BIOME_BLEND 0x10 + +#define AVERAGE_MUD_AMOUNT 4 + +/////////////////// Mapgen V6 perlin noise default values +NoiseParams nparams_v6_def_terrain_base = + {-AVERAGE_MUD_AMOUNT, 20.0, v3f(250.0, 250.0, 250.0), 82341, 5, 0.6}; +NoiseParams nparams_v6_def_terrain_higher = + {20.0, 16.0, v3f(500.0, 500.0, 500.0), 85309, 5, 0.6}; +NoiseParams nparams_v6_def_steepness = + {0.85, 0.5, v3f(125.0, 125.0, 125.0), -932, 5, 0.7}; +NoiseParams nparams_v6_def_height_select = + {0.5, 1.0, v3f(250.0, 250.0, 250.0), 4213, 5, 0.69}; +NoiseParams nparams_v6_def_trees = + {0.0, 1.0, v3f(125.0, 125.0, 125.0), 2, 4, 0.66}; +NoiseParams nparams_v6_def_mud = + {AVERAGE_MUD_AMOUNT, 2.0, v3f(200.0, 200.0, 200.0), 91013, 3, 0.55}; +NoiseParams nparams_v6_def_beach = + {0.0, 1.0, v3f(250.0, 250.0, 250.0), 59420, 3, 0.50}; +NoiseParams nparams_v6_def_biome = + {0.0, 1.0, v3f(250.0, 250.0, 250.0), 9130, 3, 0.50}; +NoiseParams nparams_v6_def_cave = + {6.0, 6.0, v3f(250.0, 250.0, 250.0), 34329, 3, 0.50}; + +/////////////////// Mapgen V7 perlin noise default values +NoiseParams nparams_v7_def_terrain = + {10.0, 12.0, v3f(350., 350., 350.), 82341, 5, 0.6}; //terrain +NoiseParams nparams_v7_def_bgroup = + {0.5, 1/(2*1.6), v3f(350., 350., 350.), 5923, 2, 0.60}; //0 to 1 +NoiseParams nparams_v7_def_heat = + {25.0, 50.0, v3f(500., 500., 500.), 35293, 1, 0.00}; //-25 to 75 +NoiseParams nparams_v7_def_humidity = + {50, 100/(2*1.6), v3f(750., 750., 750.), 12094, 2, 0.60}; //0 to 100 + +struct MapgenParams { + int seed; + int water_level; + int chunksize; + u32 flags; + + MapgenParams() { + seed = 0; + water_level = 1; + chunksize = 5; + flags = MG_TREES | MG_CAVES | MGV6_BIOME_BLEND; + } + +}; + +struct MapgenV6Params : public MapgenParams { + float freq_desert; + float freq_beach; + NoiseParams *np_terrain_base; + NoiseParams *np_terrain_higher; + NoiseParams *np_steepness; + NoiseParams *np_height_select; + NoiseParams *np_trees; + NoiseParams *np_mud; + NoiseParams *np_beach; + NoiseParams *np_biome; + NoiseParams *np_cave; + + MapgenV6Params() { + freq_desert = 0.45; + freq_beach = 0.15; + np_terrain_base = &nparams_v6_def_terrain_base; + np_terrain_higher = &nparams_v6_def_terrain_higher; + np_steepness = &nparams_v6_def_steepness; + np_height_select = &nparams_v6_def_height_select; + np_trees = &nparams_v6_def_trees; + np_mud = &nparams_v6_def_mud; + np_beach = &nparams_v6_def_beach; + np_biome = &nparams_v6_def_biome; + np_cave = &nparams_v6_def_cave; + } +}; + +struct MapgenV7Params : public MapgenParams { + NoiseParams *np_terrain; + NoiseParams *np_bgroup; + NoiseParams *np_heat; + NoiseParams *np_humidity; + + MapgenV7Params() { + np_terrain = &nparams_v7_def_terrain; + np_bgroup = &nparams_v7_def_bgroup; + np_heat = &nparams_v7_def_heat; + np_humidity = &nparams_v7_def_humidity; + } +}; + + class Mapgen { public: - int seed; int water_level; - bool generating; int id; - - //virtual Mapgen(BiomeDefManager *biomedef, int mapgenid=0, u64 seed=0); - //virtual ~Mapgen(); virtual void makeChunk(BlockMakeData *data) {}; //Legacy functions for Farmesh (pending removal) @@ -109,9 +201,11 @@ public: float *map_biome; float *map_cave; - bool use_smooth_biome_trans; + u32 flags; + float freq_desert; + float freq_beach; - MapgenV6(int mapgenid=0, u64 seed=0); + MapgenV6(int mapgenid, MapgenV6Params *params); ~MapgenV6(); void makeChunk(BlockMakeData *data); @@ -142,8 +236,6 @@ public: int zstride; v3s16 csize; - //int seed; - //int water_level; Noise *noise_terrain; Noise *noise_bgroup; @@ -160,24 +252,20 @@ public: bool generating; int id; + u32 flags; +/* NoiseParams *np_terrain; NoiseParams *np_bgroup; NoiseParams *np_heat; - NoiseParams *np_humidity; + NoiseParams *np_humidity;*/ //should these be broken off into a "commonly used nodes" class? MapNode n_air; MapNode n_water; MapNode n_lava; - MapgenV7(BiomeDefManager *biomedef, int mapgenid=0, u64 seed=0); - MapgenV7(BiomeDefManager *biomedef, int mapgenid, u64 seed, - NoiseParams *np_terrain, NoiseParams *np_bgroup, - NoiseParams *np_heat, NoiseParams *np_humidity); - void init(BiomeDefManager *biomedef, int mapgenid, u64 seed, - NoiseParams *np_terrain, NoiseParams *np_bgroup, - NoiseParams *np_heat, NoiseParams *np_humidity); + MapgenV7(BiomeDefManager *biomedef, int mapgenid, MapgenV7Params *params); ~MapgenV7(); void makeChunk(BlockMakeData *data); @@ -193,23 +281,21 @@ public: class EmergeManager { public: //settings - u64 seed; - int water_level; - NoiseParams *np_terrain; - NoiseParams *np_bgroup; - NoiseParams *np_heat; - NoiseParams *np_humidity; + int mg_version; + MapgenParams *params; + + //mapgen objects here + Mapgen *mapgen; //biome manager BiomeDefManager *biomedef; - //mapgen objects here - - EmergeManager(IGameDef *gamedef); + EmergeManager(IGameDef *gamedef, int mg_version=6); ~EmergeManager(); - void addBlockToQueue(); - + Mapgen *getMapgen(); + void setMapgenParams(); + void addBlockToQueue(); //mapgen helper methods Biome *getBiomeAtPoint(v3s16 p); diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp index b1c2583b..f31a754d 100644 --- a/src/mapgen_v6.cpp +++ b/src/mapgen_v6.cpp @@ -32,9 +32,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "settings.h" // For g_settings #include "main.h" // For g_profiler +/* #define AVERAGE_MUD_AMOUNT 4 - NoiseParams nparams_v6_def_terrain_base = {-AVERAGE_MUD_AMOUNT, 20.0, v3f(250.0, 250.0, 250.0), 82341, 5, 0.6}; NoiseParams nparams_v6_def_terrain_higher = @@ -51,42 +51,54 @@ NoiseParams nparams_v6_def_beach = {0.0, 1.0, v3f(250.0, 250.0, 250.0), 59420, 3, 0.50}; NoiseParams nparams_v6_def_biome = {0.0, 1.0, v3f(250.0, 250.0, 250.0), 9130, 3, 0.50}; -//NoiseParams nparams_v6_def_cave = -// {6.0, 6.0, v3f(250.0, 250.0, 250.0), 34329, 3, 0.50}; - +NoiseParams nparams_v6_def_cave = + {6.0, 6.0, v3f(250.0, 250.0, 250.0), 34329, 3, 0.50}; + + +MapgenV6Params mg_def_params_v6 = { + 0, + 1, + 5, + MG_TREES | MG_CAVES | MGV6_BIOME_BLEND, + 0.45, + 0.15, + &nparams_v6_def_terrain_base, + &nparams_v6_def_terrain_higher, + &nparams_v6_def_steepness, + &nparams_v6_def_height_select, + &nparams_v6_def_trees, + &nparams_v6_def_mud, + &nparams_v6_def_beach, + &nparams_v6_def_biome, + &nparams_v6_def_cave +}; +*/ -NoiseParams *np_terrain_base = &nparams_v6_def_terrain_base; -NoiseParams *np_terrain_higher = &nparams_v6_def_terrain_higher; -NoiseParams *np_steepness = &nparams_v6_def_steepness; -NoiseParams *np_height_select = &nparams_v6_def_height_select; -NoiseParams *np_trees = &nparams_v6_def_trees; -NoiseParams *np_mud = &nparams_v6_def_mud; -NoiseParams *np_beach = &nparams_v6_def_beach; -NoiseParams *np_biome = &nparams_v6_def_biome; -//NoiseParams *np_cave = &nparams_v6_def_cave; +/////////////////////////////////////////////////////////////////////////////// -MapgenV6::MapgenV6(int mapgenid, u64 seed) { +MapgenV6::MapgenV6(int mapgenid, MapgenV6Params *params) { this->generating = false; this->id = mapgenid; - this->seed = (int)seed; - this->water_level = 1; + this->seed = params->seed; + this->water_level = params->water_level; + this->flags = flags; + this->csize = v3s16(1, 1, 1) * params->chunksize * MAP_BLOCKSIZE; - this->csize = v3s16(5, 5, 5) * MAP_BLOCKSIZE; /////////////////get this from config! - this->ystride = csize.X; + this->freq_desert = params->freq_desert; + this->freq_beach = params->freq_beach; - this->use_smooth_biome_trans = g_settings->getBool("mgv6_use_smooth_biome_trans"); + this->ystride = csize.X; //////fix this - noise_terrain_base = new Noise(np_terrain_base, seed, csize.X, csize.Y); - noise_terrain_higher = new Noise(np_terrain_higher, seed, csize.X, csize.Y); - noise_steepness = new Noise(np_steepness, seed, csize.X, csize.Y); - noise_height_select = new Noise(np_height_select, seed, csize.X, csize.Y); - noise_trees = new Noise(np_trees, seed, csize.X, csize.Y); - noise_mud = new Noise(np_mud, seed, csize.X, csize.Y); - noise_beach = new Noise(np_beach, seed, csize.X, csize.Y); - noise_biome = new Noise(np_biome, seed, csize.X, csize.Y); - //noise_cave = new Noise(np_cave, seed, csize.X, csize.Y); + noise_terrain_base = new Noise(params->np_terrain_base, seed, csize.X, csize.Y); + noise_terrain_higher = new Noise(params->np_terrain_higher, seed, csize.X, csize.Y); + noise_steepness = new Noise(params->np_steepness, seed, csize.X, csize.Y); + noise_height_select = new Noise(params->np_height_select, seed, csize.X, csize.Y); + noise_trees = new Noise(params->np_trees, seed, csize.X, csize.Y); + noise_mud = new Noise(params->np_mud, seed, csize.X, csize.Y); + noise_beach = new Noise(params->np_beach, seed, csize.X, csize.Y); + noise_biome = new Noise(params->np_biome, seed, csize.X, csize.Y); map_terrain_base = noise_terrain_base->result; map_terrain_higher = noise_terrain_higher->result; @@ -96,7 +108,6 @@ MapgenV6::MapgenV6(int mapgenid, u64 seed) { map_mud = noise_mud->result; map_beach = noise_beach->result; map_biome = noise_biome->result; - //map_cave = noise_cave->result; } @@ -294,9 +305,7 @@ double MapgenV6::base_rock_level_2d(u64 seed, v2s16 p) 0.5+(float)p.X/250., 0.5+(float)p.Y/250., seed+82341, 5, 0.6);*/ double base = water_level + map_terrain_base[index]; - //return base; -//printf("%f ", base); -//return base; + // Higher ground level /*double higher = (double)WATER_LEVEL + 20. + 16. * noise2d_perlin( 0.5+(float)p.X/500., 0.5+(float)p.Y/500., @@ -316,6 +325,7 @@ double MapgenV6::base_rock_level_2d(u64 seed, v2s16 p) b = pow(b, 7); b *= 5; b = rangelim(b, 0.5, 1000.0); + // Values 1.5...100 give quite horrible looking slopes if(b > 1.5 && b < 100.0){ if(b < 10.0) @@ -323,22 +333,19 @@ double MapgenV6::base_rock_level_2d(u64 seed, v2s16 p) else b = 100.0; } - //dstream<<"b="<getEmergeManager()->biomedef; + if (!bmgr) { + verbosestream << "register_biome_groups: BiomeDefManager not active" << std::endl; + return 0; + } lua_pushnil(L); for (int i = 1; lua_next(L, index) != 0; i++) { @@ -4484,6 +4488,10 @@ static int l_register_biome(lua_State *L) IWritableNodeDefManager *ndef = get_server(L)->getWritableNodeDefManager(); BiomeDefManager *bmgr = get_server(L)->getEmergeManager()->biomedef; + if (!bmgr) { + verbosestream << "register_biome: BiomeDefManager not active" << std::endl; + return 0; + } groupid = getintfield_default(L, index, "group_id", 0); diff --git a/src/server.cpp b/src/server.cpp index 22c828bc..03faace0 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -172,12 +172,8 @@ void * EmergeThread::Thread() ServerMap &map = ((ServerMap&)m_server->m_env->getMap()); EmergeManager *emerge = m_server->m_emerge; + Mapgen *mapgen = emerge->getMapgen(); - Mapgen *mapgen; - if (g_settings->getS16("use_mapgen_version") == 7) ////////this is okay for now, fix later - mapgen = new MapgenV7( m_server->m_emerge->biomedef,/*mapgenid*/ 0, map.getSeed()); - else - mapgen = new MapgenV6(0, map.getSeed()); /* Get block info from queue, emerge them and send them to clients. @@ -800,6 +796,7 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime, } else { if(nearest_emergefull_d == -1) nearest_emergefull_d = d; + goto queue_full_break; } // get next one. @@ -988,7 +985,7 @@ Server::Server( infostream<<"- game: "<getS16("use_mapgen_version")); // Create rollback manager std::string rollback_path = m_path_world+DIR_DELIM+"rollback.txt"; @@ -1097,7 +1094,8 @@ Server::Server( m_nodedef->updateAliases(m_itemdef); // Add default biomes after nodedef had its aliases added - m_emerge->biomedef->addDefaultBiomes(); + if (m_emerge->biomedef) + m_emerge->biomedef->addDefaultBiomes(); // Initialize Environment -- 2.30.2