From d10223254ab9363eb1b6f8cc7aa6b99965940cee Mon Sep 17 00:00:00 2001 From: kwolekr Date: Mon, 11 Mar 2013 21:32:52 -0400 Subject: Clean up Mapgen --- src/mapgen.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/mapgen.h') diff --git a/src/mapgen.h b/src/mapgen.h index 911e87537..67ea9fbd4 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -72,6 +72,11 @@ public: int water_level; bool generating; int id; + ManualMapVoxelManipulator *vm; + INodeDefManager *ndef; + + void updateLiquid(UniqueQueue *trans_liquid, v3s16 nmin, v3s16 nmax); + void updateLighting(v3s16 nmin, v3s16 nmax); virtual void makeChunk(BlockMakeData *data) {}; virtual int getGroundLevelAtPoint(v2s16 p) = 0; -- cgit v1.2.3 From 1f1ad9fd23b07a1c1b5477ee0dbf2c4fdaabccef Mon Sep 17 00:00:00 2001 From: kwolekr Date: Fri, 15 Mar 2013 22:43:35 -0400 Subject: Optimize Mapgen::updateLighting(), add setLighting() --- src/mapgen.cpp | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- src/mapgen.h | 4 ++ 2 files changed, 113 insertions(+), 8 deletions(-) (limited to 'src/mapgen.h') diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 156863170..699b51789 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -51,21 +51,19 @@ FlagDesc flagdesc_mapgen[] = { void Mapgen::updateLiquid(UniqueQueue *trans_liquid, v3s16 nmin, v3s16 nmax) { bool isliquid, wasliquid; - u32 i; + v3s16 em = vm->m_area.getExtent(); 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 = vm->m_area.getExtent(); - i = vm->m_area.index(v3s16(p2d.X, nmax.Y, p2d.Y)); - + + u32 i = vm->m_area.index(x, nmax.Y, z); for (s16 y = nmax.Y; y >= nmin.Y; y--) { isliquid = ndef->get(vm->m_data[i]).isLiquid(); // there was a change between liquid and nonliquid, add to queue if (isliquid != wasliquid) - trans_liquid->push_back(v3s16(p2d.X, y, p2d.Y)); + trans_liquid->push_back(v3s16(x, y, z)); wasliquid = isliquid; vm->m_area.add_y(em, i, -1); @@ -75,7 +73,108 @@ void Mapgen::updateLiquid(UniqueQueue *trans_liquid, v3s16 nmin, v3s16 nm } +void Mapgen::setLighting(v3s16 nmin, v3s16 nmax, u8 light) { + ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update", SPT_AVG); + VoxelArea a(nmin - v3s16(1,0,1) * MAP_BLOCKSIZE, + nmax + v3s16(1,0,1) * MAP_BLOCKSIZE); + + for (int z = a.MinEdge.Z; z <= a.MaxEdge.Z; z++) { + for (int y = a.MinEdge.Y; y <= a.MaxEdge.Y; y++) { + u32 i = vm->m_area.index(a.MinEdge.X, y, z); + for (int x = a.MinEdge.X; x <= a.MaxEdge.X; x++, i++) + vm->m_data[i].param1 = light; + } + } +} + + +void Mapgen::lightSpread(VoxelArea &a, v3s16 p, u8 light) { + if (light <= 1 || !a.contains(p)) + return; + + u32 vi = vm->m_area.index(p); + MapNode &nn = vm->m_data[vi]; + + light--; + // should probably compare masked, but doesn't seem to make a difference + if (light <= nn.param1 || !ndef->get(nn).light_propagates) + return; + + nn.param1 = light; + + lightSpread(a, p + v3s16(0, 0, 1), light); + lightSpread(a, p + v3s16(0, 1, 0), light); + lightSpread(a, p + v3s16(1, 0, 0), light); + lightSpread(a, p - v3s16(0, 0, 1), light); + lightSpread(a, p - v3s16(0, 1, 0), light); + lightSpread(a, p - v3s16(1, 0, 0), light); +} + + void Mapgen::updateLighting(v3s16 nmin, v3s16 nmax) { + VoxelArea a(nmin - v3s16(1,0,1) * MAP_BLOCKSIZE, + nmax + v3s16(1,0,1) * MAP_BLOCKSIZE); + bool block_is_underground = (water_level >= nmax.Y); + + ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update", SPT_AVG); + //TimeTaker t("updateLighting"); + + // first, send vertical rays of sunshine downward + v3s16 em = vm->m_area.getExtent(); + for (int z = a.MinEdge.Z; z <= a.MaxEdge.Z; z++) { + for (int x = a.MinEdge.X; x <= a.MaxEdge.X; x++) { + // see if we can get a light value from the overtop + u32 i = vm->m_area.index(x, a.MaxEdge.Y + 1, z); + if (vm->m_data[i].getContent() == CONTENT_IGNORE) { + if (block_is_underground) + continue; + } else if ((vm->m_data[i].param1 & 0x0F) != LIGHT_SUN) { + continue; + } + vm->m_area.add_y(em, i, -1); + + for (int y = a.MaxEdge.Y; y >= a.MinEdge.Y; y--) { + MapNode &n = vm->m_data[i]; + if (!ndef->get(n).sunlight_propagates) + break; + n.param1 = LIGHT_SUN; + vm->m_area.add_y(em, i, -1); + } + } + } + + // now spread the sunlight and light up any sources + for (int z = a.MinEdge.Z; z <= a.MaxEdge.Z; z++) { + for (int y = a.MinEdge.Y; y <= a.MaxEdge.Y; y++) { + u32 i = vm->m_area.index(a.MinEdge.X, y, z); + for (int x = a.MinEdge.X; x <= a.MaxEdge.X; x++, i++) { + MapNode &n = vm->m_data[i]; + if (n.getContent() == CONTENT_IGNORE || + !ndef->get(n).light_propagates) + continue; + + u8 light_produced = ndef->get(n).light_source & 0x0F; + if (light_produced) + n.param1 = light_produced; + + u8 light = n.param1 & 0x0F; + if (light) { + lightSpread(a, v3s16(x, y, z + 1), light); + lightSpread(a, v3s16(x, y + 1, z ), light); + lightSpread(a, v3s16(x + 1, y, z ), light); + lightSpread(a, v3s16(x, y, z - 1), light); + lightSpread(a, v3s16(x, y - 1, z ), light); + lightSpread(a, v3s16(x - 1, y, z ), light); + } + } + } + } + + //printf("updateLighting: %dms\n", t.stop()); +} + + +void Mapgen::updateLightingOld(v3s16 nmin, v3s16 nmax) { enum LightBank banks[2] = {LIGHTBANK_DAY, LIGHTBANK_NIGHT}; VoxelArea a(nmin - v3s16(1,0,1) * MAP_BLOCKSIZE, @@ -84,14 +183,16 @@ void Mapgen::updateLighting(v3s16 nmin, v3s16 nmax) { bool sunlight = !block_is_underground; ScopeProfiler sp(g_profiler, "EmergeThread: mapgen lighting update", SPT_AVG); + for (int i = 0; i < 2; i++) { enum LightBank bank = banks[i]; - std::set light_sources; - std::map unlight_from; + std::set light_sources; + std::map unlight_from; voxalgo::clearLightAndCollectSources(*vm, a, bank, ndef, light_sources, unlight_from); voxalgo::propagateSunlight(*vm, a, sunlight, light_sources, ndef); + vm->unspreadLight(bank, unlight_from, light_sources, ndef); vm->spreadLight(bank, light_sources, ndef); } diff --git a/src/mapgen.h b/src/mapgen.h index 67ea9fbd4..e5b0b6399 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -46,6 +46,7 @@ class ManualMapVoxelManipulator; class VoxelManipulator; class INodeDefManager; class BlockMakeData; +class VoxelArea; struct MapgenParams { std::string mg_name; @@ -76,7 +77,10 @@ public: INodeDefManager *ndef; void updateLiquid(UniqueQueue *trans_liquid, v3s16 nmin, v3s16 nmax); + void setLighting(v3s16 nmin, v3s16 nmax, u8 light); + void lightSpread(VoxelArea &a, v3s16 p, u8 light); void updateLighting(v3s16 nmin, v3s16 nmax); + void updateLightingOld(v3s16 nmin, v3s16 nmax); virtual void makeChunk(BlockMakeData *data) {}; virtual int getGroundLevelAtPoint(v2s16 p) = 0; -- cgit v1.2.3 From 6823ce99a7deabe410dd8b143b688cd364490cec Mon Sep 17 00:00:00 2001 From: kwolekr Date: Sat, 16 Mar 2013 17:06:11 -0400 Subject: Re-add jungles, apple trees --- minetest.conf.example | 9 ++++-- src/content_abm.cpp | 18 ++++++++--- src/defaultsettings.cpp | 6 ++-- src/mapgen.cpp | 13 +++++--- src/mapgen.h | 2 +- src/mapgen_v6.cpp | 81 +++++++++++++++++++++++++++++++++++-------------- src/mapgen_v6.h | 22 ++++++++++---- src/treegen.cpp | 11 +++++-- 8 files changed, 118 insertions(+), 44 deletions(-) (limited to 'src/mapgen.h') diff --git a/minetest.conf.example b/minetest.conf.example index 41a691b1a..649717ee8 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -314,22 +314,25 @@ #water_level = 1 # Size of chunks to be generated. #chunksize = 5 -# Map generation attributes. Currently supported: trees, caves, flat, v6_biome_blend +# Map generation attributes. Currently supported: trees, caves, flat, v6_biome_blend, v6_jungles #mg_flags = trees, caves, v6_biome_blend # How large deserts and beaches are #mgv6_freq_desert = 0.45 #mgv6_freq_beach = 0.15 # Perlin noise attributes for different map generation parameters # Offset, scale, spread factor, seed offset, number of octaves, persistence -#mgv6_np_terrain_base = -4, 20, (250.0, 250, 250), 82341, 5, 0.6 +#mgv6_np_terrain_base = -4, 20, (250, 250, 250), 82341, 5, 0.6 #mgv6_np_terrain_higher = 20, 16, (500, 500, 500), 85039, 5, 0.6 #mgv6_np_steepness = 0.85, 0.5, (125, 125, 125), -932, 5, 0.7 #mgv6_np_height_select = 0.5, 1, (250, 250, 250), 4213, 5, 0.69 -#mgv6_np_trees = 0, 1, (125, 125, 125), 2, 4, 0.66 #mgv6_np_mud = 4, 2, (200, 200, 200), 91013, 3, 0.55 #mgv6_np_beach = 0, 1, (250, 250, 250), 59420, 3, 0.50 #mgv6_np_biome = 0, 1, (250, 250, 250), 9130, 3, 0.50 #mgv6_np_cave = 6, 6, (250, 250, 250), 34329, 3, 0.50 +#mgv6_np_humidity = 0.5, 0.5, (500, 500, 500), 72384, 4, 0.66 +#mgv6_np_trees = 0, 1, (125, 125, 125), 2, 4, 0.66 +#mgv6_np_apple_trees = 0, 1, (100, 100, 100), 342902, 3, 0.45 + #mgv7_np_terrain = 10, 12, (350, 350, 350), 82341, 5, 0.6 #mgv7_np_bgroup = 0.5, 0.3125, (350, 350, 350), 5923, 2, 0.6 #mgv7_np_heat = 25, 50, (500, 500, 500), 35293, 1, 0 diff --git a/src/content_abm.cpp b/src/content_abm.cpp index a88450095..e50edddd7 100644 --- a/src/content_abm.cpp +++ b/src/content_abm.cpp @@ -99,6 +99,7 @@ public: { std::set s; s.insert("sapling"); + s.insert("junglesapling"); return s; } virtual float getTriggerInterval() @@ -111,16 +112,25 @@ public: INodeDefManager *ndef = env->getGameDef()->ndef(); ServerMap *map = &env->getServerMap(); - actionstream<<"A sapling grows into a tree at " - <getId("junglesapling"); + + actionstream <<"A " << (is_jungle_tree ? "jungle " : "") + << "sapling grows into a tree at " + << PP(p) << std::endl; std::map modified_blocks; v3s16 tree_p = p; ManualMapVoxelManipulator vmanip(map); v3s16 tree_blockp = getNodeBlockPos(tree_p); vmanip.initialEmerge(tree_blockp - v3s16(1,1,1), tree_blockp + v3s16(1,1,1)); - bool is_apple_tree = myrand()%4 == 0; - treegen::make_tree(vmanip, tree_p, is_apple_tree, ndef, myrand()); + + if (is_jungle_tree) { + treegen::make_jungletree(vmanip, tree_p, ndef, myrand()); + } else { + bool is_apple_tree = myrand() % 4 == 0; + treegen::make_tree(vmanip, tree_p, is_apple_tree, ndef, myrand()); + } + vmanip.blitBackAll(&modified_blocks); // update lighting diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 8f878648a..f7724fa11 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -219,15 +219,17 @@ void set_default_settings(Settings *settings) settings->setDefault("mgv6_freq_desert", "0.45"); settings->setDefault("mgv6_freq_beach", "0.15"); - settings->setDefault("mgv6_np_terrain_base", "-4, 20, (250.0, 250, 250), 82341, 5, 0.6"); + settings->setDefault("mgv6_np_terrain_base", "-4, 20, (250, 250, 250), 82341, 5, 0.6"); settings->setDefault("mgv6_np_terrain_higher", "20, 16, (500, 500, 500), 85039, 5, 0.6"); settings->setDefault("mgv6_np_steepness", "0.85, 0.5, (125, 125, 125), -932, 5, 0.7"); settings->setDefault("mgv6_np_height_select", "0.5, 1, (250, 250, 250), 4213, 5, 0.69"); - settings->setDefault("mgv6_np_trees", "0, 1, (125, 125, 125), 2, 4, 0.66"); settings->setDefault("mgv6_np_mud", "4, 2, (200, 200, 200), 91013, 3, 0.55"); settings->setDefault("mgv6_np_beach", "0, 1, (250, 250, 250), 59420, 3, 0.50"); settings->setDefault("mgv6_np_biome", "0, 1, (250, 250, 250), 9130, 3, 0.50"); settings->setDefault("mgv6_np_cave", "6, 6, (250, 250, 250), 34329, 3, 0.50"); + settings->setDefault("mgv6_np_humidity", "0.5, 0.5, (500, 500, 500), 72384, 4, 0.66"); + settings->setDefault("mgv6_np_trees", "0, 1, (125, 125, 125), 2, 4, 0.66"); + settings->setDefault("mgv6_np_apple_trees", "0, 1, (100, 100, 100), 342902, 3, 0.45"); settings->setDefault("mgv7_np_terrain", "10, 12, (350, 350, 350), 82341, 5, 0.6"); settings->setDefault("mgv7_np_bgroup", "0.5, 0.3125, (350, 350, 350), 5923, 2, 0.6"); diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 699b51789..4316be6fe 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -39,7 +39,7 @@ FlagDesc flagdesc_mapgen[] = { {"trees", MG_TREES}, {"caves", MG_CAVES}, {"dungeons", MG_DUNGEONS}, - {"v6_forests", MGV6_FORESTS}, + {"v6_jungles", MGV6_JUNGLES}, {"v6_biome_blend", MGV6_BIOME_BLEND}, {"flat", MG_FLAT}, {NULL, 0} @@ -209,16 +209,19 @@ bool MapgenV6Params::readParams(Settings *settings) { np_terrain_higher = settings->getNoiseParams("mgv6_np_terrain_higher"); np_steepness = settings->getNoiseParams("mgv6_np_steepness"); np_height_select = settings->getNoiseParams("mgv6_np_height_select"); - np_trees = settings->getNoiseParams("mgv6_np_trees"); np_mud = settings->getNoiseParams("mgv6_np_mud"); np_beach = settings->getNoiseParams("mgv6_np_beach"); np_biome = settings->getNoiseParams("mgv6_np_biome"); np_cave = settings->getNoiseParams("mgv6_np_cave"); + np_humidity = settings->getNoiseParams("mgv6_np_humidity"); + np_trees = settings->getNoiseParams("mgv6_np_trees"); + np_apple_trees = settings->getNoiseParams("mgv6_np_apple_trees"); bool success = np_terrain_base && np_terrain_higher && np_steepness && np_height_select && np_trees && np_mud && - np_beach && np_biome && np_cave; + np_beach && np_biome && np_cave && + np_humidity && np_apple_trees; return success; } @@ -231,11 +234,13 @@ void MapgenV6Params::writeParams(Settings *settings) { settings->setNoiseParams("mgv6_np_terrain_higher", np_terrain_higher); settings->setNoiseParams("mgv6_np_steepness", np_steepness); settings->setNoiseParams("mgv6_np_height_select", np_height_select); - settings->setNoiseParams("mgv6_np_trees", np_trees); settings->setNoiseParams("mgv6_np_mud", np_mud); settings->setNoiseParams("mgv6_np_beach", np_beach); settings->setNoiseParams("mgv6_np_biome", np_biome); settings->setNoiseParams("mgv6_np_cave", np_cave); + settings->setNoiseParams("mgv6_np_humidity", np_humidity); + settings->setNoiseParams("mgv6_np_trees", np_trees); + settings->setNoiseParams("mgv6_np_apple_trees", np_apple_trees); } diff --git a/src/mapgen.h b/src/mapgen.h index e5b0b6399..3f3cd424d 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -32,7 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define MG_TREES 0x01 #define MG_CAVES 0x02 #define MG_DUNGEONS 0x04 -#define MGV6_FORESTS 0x08 +#define MGV6_JUNGLES 0x08 #define MGV6_BIOME_BLEND 0x10 #define MG_FLAT 0x20 diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp index b60758310..dca4e5353 100644 --- a/src/mapgen_v6.cpp +++ b/src/mapgen_v6.cpp @@ -45,8 +45,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 = @@ -55,6 +53,12 @@ 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_humidity = + {0.5, 0.5, v3f(500.0, 500.0, 500.0), 72384, 4, 0.66}; +NoiseParams nparams_v6_def_trees = + {0.0, 1.0, v3f(125.0, 125.0, 125.0), 2, 4, 0.66}; +NoiseParams nparams_v6_def_apple_trees = + {0.0, 1.0, v3f(100.0, 100.0, 100.0), 342902, 3, 0.45}; /////////////////////////////////////////////////////////////////////////////// @@ -74,13 +78,15 @@ MapgenV6::MapgenV6(int mapgenid, MapgenV6Params *params) { this->ystride = csize.X; //////fix this - np_cave = params->np_cave; + np_cave = params->np_cave; + np_humidity = params->np_humidity; + np_trees = params->np_trees; + np_apple_trees = params->np_apple_trees; 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); @@ -92,7 +98,6 @@ MapgenV6::~MapgenV6() { delete noise_terrain_higher; delete noise_steepness; delete noise_height_select; - delete noise_trees; delete noise_mud; delete noise_beach; delete noise_biome; @@ -234,12 +239,6 @@ int MapgenV6::getGroundLevelAtPoint(v2s16 p) { //////////////////////// Noise functions -float MapgenV6::getTreeAmount(v2s16 p) { - int index = (p.Y - node_min.Z) * ystride + (p.X - node_min.X); - return getTreeAmount(index); -} - - float MapgenV6::getMudAmount(v2s16 p) { int index = (p.Y - node_min.Z) * ystride + (p.X - node_min.X); return getMudAmount(index); @@ -258,13 +257,30 @@ BiomeType MapgenV6::getBiome(v2s16 p) { } -float MapgenV6::getTreeAmount(int index) +float MapgenV6::getHumidity(v2s16 p) +{ + /*double noise = noise2d_perlin( + 0.5+(float)p.X/500, 0.5+(float)p.Y/500, + seed+72384, 4, 0.66); + noise = (noise + 1.0)/2.0;*/ + + float noise = NoisePerlin2D(np_humidity, p.X, p.Y, seed); + + if (noise < 0.0) + noise = 0.0; + if (noise > 1.0) + noise = 1.0; + return noise; +} + + +float MapgenV6::getTreeAmount(v2s16 p) { /*double noise = noise2d_perlin( 0.5+(float)p.X/125, 0.5+(float)p.Y/125, seed+2, 4, 0.66);*/ - float noise = noise_trees->result[index]; + float noise = NoisePerlin2D(np_trees, p.X, p.Y, seed); float zeroval = -0.39; if (noise < zeroval) return 0; @@ -273,6 +289,18 @@ float MapgenV6::getTreeAmount(int index) } +bool MapgenV6::getHaveAppleTree(v2s16 p) +{ + /*is_apple_tree = noise2d_perlin( + 0.5+(float)p.X/100, 0.5+(float)p.Z/100, + data->seed+342902, 3, 0.45) > 0.2;*/ + + float noise = NoisePerlin2D(np_apple_trees, p.X, p.Y, seed); + + return noise > 0.2; +} + + float MapgenV6::getMudAmount(int index) { if (flags & MG_FLAT) @@ -465,12 +493,6 @@ void MapgenV6::calculateNoise() { x + 0.5 * noise_height_select->np->spread.X, z + 0.5 * noise_height_select->np->spread.Z); } - - if (flags & MG_TREES) { - noise_trees->perlinMap2D( - x + 0.5 * noise_trees->np->spread.X, - z + 0.5 * noise_trees->np->spread.Z); - } if (!(flags & MG_FLAT)) { noise_mud->perlinMap2D( @@ -762,6 +784,8 @@ void MapgenV6::addDirtGravelBlobs() { void MapgenV6::placeTrees() { + //TimeTaker t("placeTrees"); + // Divide area into parts s16 div = 8; s16 sidelen = central_area_size.X / div; @@ -784,8 +808,13 @@ void MapgenV6::placeTrees() { node_min.X + sidelen + sidelen * x0 - 1, node_min.Z + sidelen + sidelen * z0 - 1 ); - // Amount of trees - u32 tree_count = area * getTreeAmount(p2d_center); /////////////optimize this! + + // Amount of trees, jungle area + u32 tree_count = area * getTreeAmount(p2d_center); + bool is_jungle = (flags & MGV6_JUNGLES) && (getHumidity(p2d_center) > 0.75); + if (is_jungle) + tree_count *= 4; + // Put trees in random places on part of division for (u32 i = 0; i < tree_count; i++) { s16 x = myrand_range(p2d_min.X, p2d_max.X); @@ -806,10 +835,18 @@ void MapgenV6::placeTrees() { continue; } p.Y++; + // Make a tree - treegen::make_tree(*vm, p, false, ndef, myrand()); + if (is_jungle) { + treegen::make_jungletree(*vm, p, ndef, myrand()); + } else { + bool is_apple_tree = (myrand_range(0, 3) == 0) && + getHaveAppleTree(v2s16(x, z)); + treegen::make_tree(*vm, p, is_apple_tree, ndef, myrand()); + } } } + //printf("placeTrees: %dms\n", t.stop()); } diff --git a/src/mapgen_v6.h b/src/mapgen_v6.h index 7b1e31020..89d72300a 100644 --- a/src/mapgen_v6.h +++ b/src/mapgen_v6.h @@ -35,11 +35,13 @@ extern NoiseParams nparams_v6_def_terrain_base; extern NoiseParams nparams_v6_def_terrain_higher; extern NoiseParams nparams_v6_def_steepness; extern NoiseParams nparams_v6_def_height_select; -extern NoiseParams nparams_v6_def_trees; extern NoiseParams nparams_v6_def_mud; extern NoiseParams nparams_v6_def_beach; extern NoiseParams nparams_v6_def_biome; extern NoiseParams nparams_v6_def_cave; +extern NoiseParams nparams_v6_def_humidity; +extern NoiseParams nparams_v6_def_trees; +extern NoiseParams nparams_v6_def_apple_trees; struct MapgenV6Params : public MapgenParams { float freq_desert; @@ -48,12 +50,14 @@ struct MapgenV6Params : public MapgenParams { 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; - + NoiseParams *np_humidity; + NoiseParams *np_trees; + NoiseParams *np_apple_trees; + MapgenV6Params() { freq_desert = 0.45; freq_beach = 0.15; @@ -61,11 +65,14 @@ struct MapgenV6Params : public MapgenParams { 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; + np_humidity = &nparams_v6_def_humidity; + np_trees = &nparams_v6_def_trees; + np_apple_trees = &nparams_v6_def_apple_trees; + } bool readParams(Settings *settings); @@ -90,11 +97,13 @@ public: Noise *noise_terrain_higher; Noise *noise_steepness; Noise *noise_height_select; - Noise *noise_trees; Noise *noise_mud; Noise *noise_beach; Noise *noise_biome; NoiseParams *np_cave; + NoiseParams *np_humidity; + NoiseParams *np_trees; + NoiseParams *np_apple_trees; float freq_desert; float freq_beach; @@ -126,8 +135,9 @@ public: bool block_is_underground(u64 seed, v3s16 blockpos); s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision); + float getHumidity(v2s16 p); float getTreeAmount(v2s16 p); - float getTreeAmount(int index); + bool getHaveAppleTree(v2s16 p); float getMudAmount(v2s16 p); float getMudAmount(int index); bool getHaveBeach(v2s16 p); diff --git a/src/treegen.cpp b/src/treegen.cpp index 5ddf1132d..9df528a21 100644 --- a/src/treegen.cpp +++ b/src/treegen.cpp @@ -510,8 +510,15 @@ v3f transposeMatrix(irr::core::matrix4 M, v3f v) void make_jungletree(VoxelManipulator &vmanip, v3s16 p0, INodeDefManager *ndef, int seed) { - MapNode treenode(ndef->getId("mapgen_jungletree")); - MapNode leavesnode(ndef->getId("mapgen_leaves")); + content_t c_tree = ndef->getId("mapgen_jungletree"); + content_t c_leaves = ndef->getId("mapgen_jungleleaves"); + if (c_tree == CONTENT_IGNORE) + c_tree = ndef->getId("mapgen_tree"); + if (c_leaves == CONTENT_IGNORE) + c_leaves = ndef->getId("mapgen_leaves"); + + MapNode treenode(c_tree); + MapNode leavesnode(c_leaves); PseudoRandom pr(seed); for(s16 x=-1; x<=1; x++) -- cgit v1.2.3 From 939397dd6e9cf26358b7e7f07aa58b72b175691f Mon Sep 17 00:00:00 2001 From: kwolekr Date: Sun, 17 Mar 2013 23:07:51 -0400 Subject: Add jungle grass to jungles --- src/mapgen.cpp | 4 ++-- src/mapgen.h | 4 ++-- src/mapgen_v6.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++-------- src/mapgen_v6.h | 2 +- 4 files changed, 53 insertions(+), 13 deletions(-) (limited to 'src/mapgen.h') diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 4316be6fe..dc6dab6bb 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -111,7 +111,7 @@ void Mapgen::lightSpread(VoxelArea &a, v3s16 p, u8 light) { } -void Mapgen::updateLighting(v3s16 nmin, v3s16 nmax) { +void Mapgen::calcLighting(v3s16 nmin, v3s16 nmax) { VoxelArea a(nmin - v3s16(1,0,1) * MAP_BLOCKSIZE, nmax + v3s16(1,0,1) * MAP_BLOCKSIZE); bool block_is_underground = (water_level >= nmax.Y); @@ -174,7 +174,7 @@ void Mapgen::updateLighting(v3s16 nmin, v3s16 nmax) { } -void Mapgen::updateLightingOld(v3s16 nmin, v3s16 nmax) { +void Mapgen::calcLightingOld(v3s16 nmin, v3s16 nmax) { enum LightBank banks[2] = {LIGHTBANK_DAY, LIGHTBANK_NIGHT}; VoxelArea a(nmin - v3s16(1,0,1) * MAP_BLOCKSIZE, diff --git a/src/mapgen.h b/src/mapgen.h index 3f3cd424d..f4bd659fb 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -79,8 +79,8 @@ public: void updateLiquid(UniqueQueue *trans_liquid, v3s16 nmin, v3s16 nmax); void setLighting(v3s16 nmin, v3s16 nmax, u8 light); void lightSpread(VoxelArea &a, v3s16 p, u8 light); - void updateLighting(v3s16 nmin, v3s16 nmax); - void updateLightingOld(v3s16 nmin, v3s16 nmax); + void calcLighting(v3s16 nmin, v3s16 nmax); + void calcLightingOld(v3s16 nmin, v3s16 nmax); virtual void makeChunk(BlockMakeData *data) {}; virtual int getGroundLevelAtPoint(v2s16 p) = 0; diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp index 5f428bb8f..59a4d49fc 100644 --- a/src/mapgen_v6.cpp +++ b/src/mapgen_v6.cpp @@ -457,12 +457,12 @@ void MapgenV6::makeChunk(BlockMakeData *data) { // Grow grass growGrass(); - // Generate some trees + // Generate some trees, and add grass, if a jungle if (flags & MG_TREES) - placeTrees(); + placeTreesAndJungleGrass(); // Calculate lighting - updateLighting(node_min, node_max); + calcLighting(node_min, node_max); this->generating = false; } @@ -783,14 +783,26 @@ void MapgenV6::addDirtGravelBlobs() { } -void MapgenV6::placeTrees() { +void MapgenV6::placeTreesAndJungleGrass() { //TimeTaker t("placeTrees"); + if (node_max.Y < water_level) + return; + + PseudoRandom grassrandom(blockseed + 53); + content_t c_junglegrass = ndef->getId("mapgen_junglegrass"); + // if we don't have junglegrass, don't place cignore... that's bad + if (c_junglegrass == CONTENT_IGNORE) + c_junglegrass = CONTENT_AIR; + MapNode n_junglegrass(c_junglegrass); + v3s16 em = vm->m_area.getExtent(); // Divide area into parts s16 div = 8; s16 sidelen = central_area_size.X / div; double area = sidelen * sidelen; + // N.B. We must add jungle grass first, since tree leaves will + // obstruct the ground, giving us a false ground level for (s16 z0 = 0; z0 < div; z0++) for (s16 x0 = 0; x0 < div; x0++) { // Center position of part of division @@ -811,9 +823,36 @@ void MapgenV6::placeTrees() { // Amount of trees, jungle area u32 tree_count = area * getTreeAmount(p2d_center); - bool is_jungle = (flags & MGV6_JUNGLES) && (getHumidity(p2d_center) > 0.75); - if (is_jungle) - tree_count *= 4; + + float humidity; + bool is_jungle = false; + if (flags & MGV6_JUNGLES) { + humidity = getHumidity(p2d_center); + if (humidity > 0.75) { + is_jungle = true; + tree_count *= 4; + } + } + + // Add jungle grass + if (is_jungle) { + u32 grass_count = 5 * humidity * tree_count; + for (u32 i = 0; i < grass_count; i++) { + s16 x = grassrandom.range(p2d_min.X, p2d_max.X); + s16 z = grassrandom.range(p2d_min.Y, p2d_max.Y); + + s16 y = find_ground_level(v2s16(x, z)); ////////////////optimize this! + if (y < water_level || y < node_min.Y || y > node_max.Y) + continue; + + u32 vi = vm->m_area.index(x, y, z); + // place on dirt_with_grass, since we know it is exposed to sunlight + if (vm->m_data[vi].getContent() == c_dirt_with_grass) { + vm->m_area.add_y(em, vi, 1); + vm->m_data[vi] = n_junglegrass; + } + } + } // Put trees in random places on part of division for (u32 i = 0; i < tree_count; i++) { @@ -846,7 +885,7 @@ void MapgenV6::placeTrees() { } } } - //printf("placeTrees: %dms\n", t.stop()); + //printf("placeTreesAndJungleGrass: %dms\n", t.stop()); } @@ -878,6 +917,7 @@ void MapgenV6::growGrass() { } } + void MapgenV6::defineCave(Cave &cave, PseudoRandom ps, v3s16 node_min, bool large_cave) { cave.min_tunnel_diameter = 2; diff --git a/src/mapgen_v6.h b/src/mapgen_v6.h index 662aed2ce..5b3ea9d27 100644 --- a/src/mapgen_v6.h +++ b/src/mapgen_v6.h @@ -163,7 +163,7 @@ public: void flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos); void addDirtGravelBlobs(); void growGrass(); - void placeTrees(); + void placeTreesAndJungleGrass(); virtual void defineCave(Cave &cave, PseudoRandom ps, v3s16 node_min, bool large_cave); void generateCaves(int max_stone_y); -- cgit v1.2.3 From ca7043e52d6a5d0ee1b91f287371fbe7f216697e Mon Sep 17 00:00:00 2001 From: Mukul Sati Date: Sat, 23 Mar 2013 02:24:31 -0400 Subject: Set of changes to build mineTest using Visual Studio 11.0. These affect the following: 1. String concatenation in guiMainMenu.cpp - it is required for all individual strings to be of the same type ; adding explicit L qualifier before the other strings. 2. Correcting type of BlockMakeData to struct in place of class forward declarations. This information is used for name decoration by Visual Studio, leading to linker errors in case of mismatches. 3. Windows headers define max as a macro somewhere, leading to a compile time error in profiler.h; using () around function to prevent macro match from occurring. --- src/guiMainMenu.cpp | 4 +++- src/map.h | 2 +- src/mapgen.h | 2 +- src/profiler.h | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/mapgen.h') diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp index 9e6b01dd6..5dc73cd96 100644 --- a/src/guiMainMenu.cpp +++ b/src/guiMainMenu.cpp @@ -43,6 +43,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "subgame.h" #define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0])) +#define LSTRING(x) LSTRING_(x) +#define LSTRING_(x) L##x const wchar_t *contrib_core_strs[] = { L"Perttu Ahola (celeron55) ", @@ -760,7 +762,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize) core::rect rect(0, 0, 130, 70); rect += m_topleft_client + v2s32(35, 160); Environment->addStaticText( - L"Minetest " VERSION_STRING "\nhttp://minetest.net/", + L"Minetest " LSTRING(VERSION_STRING) L"\nhttp://minetest.net/", rect, false, true, this, -1); } { diff --git a/src/map.h b/src/map.h index 3833cceb4..31001e4c3 100644 --- a/src/map.h +++ b/src/map.h @@ -50,7 +50,7 @@ class NodeMetadata; class IGameDef; class IRollbackReportSink; class EmergeManager; -class BlockMakeData; +struct BlockMakeData; /* diff --git a/src/mapgen.h b/src/mapgen.h index f4bd659fb..2e917a3aa 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -45,7 +45,7 @@ class MapBlock; class ManualMapVoxelManipulator; class VoxelManipulator; class INodeDefManager; -class BlockMakeData; +struct BlockMakeData; class VoxelArea; struct MapgenParams { diff --git a/src/profiler.h b/src/profiler.h index 56b026880..271ad70c1 100644 --- a/src/profiler.h +++ b/src/profiler.h @@ -73,7 +73,7 @@ public: else{ /* No add shall have been used */ assert(n->second != -2); - n->second = std::max(n->second, 0) + 1; + n->second = (std::max)(n->second, 0) + 1; } } { -- cgit v1.2.3 From 57cbb8bfd8daaa1b8b1aa876723ff6355d21f7fc Mon Sep 17 00:00:00 2001 From: kwolekr Date: Sun, 24 Mar 2013 01:43:38 -0400 Subject: Add Ore infrastructure and l_register_ore() --- src/emerge.h | 3 +- src/mapgen.cpp | 134 ++++++++++++++++++++++++++++++++++++++++++++++++ src/mapgen.h | 43 ++++++++++++++++ src/mapgen_indev.cpp | 4 +- src/mapgen_indev.h | 4 +- src/mapgen_v6.cpp | 14 +++-- src/mapgen_v6.h | 6 ++- src/scriptapi.cpp | 46 ++++++++++++++++- src/scriptapi_noise.cpp | 2 + src/server.cpp | 9 ++-- 10 files changed, 248 insertions(+), 17 deletions(-) (limited to 'src/mapgen.h') diff --git a/src/emerge.h b/src/emerge.h index 70b67e731..3d717bce3 100644 --- a/src/emerge.h +++ b/src/emerge.h @@ -63,8 +63,9 @@ public: std::map blocks_enqueued; std::map peer_queue_count; - //biome manager + //Mapgen-related structures BiomeDefManager *biomedef; + std::vector ores; EmergeManager(IGameDef *gamedef, BiomeDefManager *bdef); ~EmergeManager(); diff --git a/src/mapgen.cpp b/src/mapgen.cpp index dc6dab6bb..53b5d6867 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -49,6 +49,140 @@ FlagDesc flagdesc_mapgen[] = { /////////////////////////////////////////////////////////////////////////////// +Ore *createOre(OreType type) { + switch (type) { + case ORE_SCATTER: + return new OreScatter; + case ORE_SHEET: + return new OreSheet; + //case ORE_CLAYLIKE: //TODO: implement this! + // return new OreClaylike; + default: + return NULL; + } +} + + +void Ore::resolveNodeNames(INodeDefManager *ndef) { + if (ore == CONTENT_IGNORE) { + ore = ndef->getId(ore_name); + if (ore == CONTENT_IGNORE) { + errorstream << "Ore::resolveNodeNames: ore node '" + << ore_name << "' not defined"; + ore = CONTENT_AIR; + wherein = CONTENT_AIR; + } + } + + if (wherein == CONTENT_IGNORE) { + wherein = ndef->getId(wherein_name); + if (wherein == CONTENT_IGNORE) { + errorstream << "Ore::resolveNodeNames: wherein node '" + << wherein_name << "' not defined"; + ore = CONTENT_AIR; + wherein = CONTENT_AIR; + } + } +} + + +void OreScatter::generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) { + if (nmin.Y > height_max || nmax.Y < height_min) + return; + + resolveNodeNames(mg->ndef); + + MapNode n_ore(ore); + ManualMapVoxelManipulator *vm = mg->vm; + PseudoRandom pr(blockseed); + + int ymin = MYMAX(nmin.Y, height_min); + int ymax = MYMIN(nmax.Y, height_max); + if (clust_size >= ymax - ymin + 1) + return; + + int volume = (nmax.X - nmin.X + 1) * + (nmax.Y - nmin.Y + 1) * + (nmax.Z - nmin.Z + 1); + int csize = clust_size; + int orechance = (csize * csize * csize) / clust_num_ores; + int nclusters = volume / clust_scarcity; + + for (int i = 0; i != nclusters; i++) { + int x0 = pr.range(nmin.X, nmax.X - csize + 1); + int y0 = pr.range(ymin, ymax - csize + 1); + int z0 = pr.range(nmin.Z, nmax.Z - csize + 1); + + if (np && (NoisePerlin3D(np, x0, y0, z0, mg->seed) < nthresh)) + continue; + + for (int z1 = 0; z1 != csize; z1++) + for (int y1 = 0; y1 != csize; y1++) + for (int x1 = 0; x1 != csize; x1++) { + if (pr.range(1, orechance) != 1) + continue; + + u32 i = vm->m_area.index(x0 + x1, y0 + y1, z0 + z1); + if (vm->m_data[i].getContent() == wherein) + vm->m_data[i] = n_ore; + } + } +} + + +void OreSheet::generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) { + if (nmin.Y > height_max || nmax.Y < height_min) + return; + + resolveNodeNames(mg->ndef); + + MapNode n_ore(ore); + ManualMapVoxelManipulator *vm = mg->vm; + PseudoRandom pr(blockseed + 4234); + + int ymin = MYMAX(nmin.Y, height_min); + int ymax = MYMIN(nmax.Y, height_max); + + int x0 = nmin.X; + int z0 = nmin.Z; + + int x1 = nmax.X; + int z1 = nmax.Z; + + int max_height = clust_size; + + int y_start = pr.range(ymin, ymax - max_height); + + if (!noise) { + int sx = nmax.X - nmin.X + 1; + int sz = nmax.Z - nmin.Z + 1; + noise = new Noise(np, 0, sx, sz); + } + noise->seed = mg->seed + y_start; + noise->perlinMap2D(x0, z0); + + int index = 0; + for (int z = z0; z != z1; z++) + for (int x = x0; x != x1; x++) { + + if (noise->result[index++] < nthresh) + continue; + + int height = max_height * (1. / pr.range(1, 3)); + int y0 = y_start + pr.range(1, 3) - 1; + int y1 = y0 + height; + for (int y = y0; y != y1; y++) { + u32 i = vm->m_area.index(x, y, z); + if (!vm->m_area.contains(i)) + continue; + + if (vm->m_data[i].getContent() == wherein) + vm->m_data[i] = n_ore; + } + } +} + + void Mapgen::updateLiquid(UniqueQueue *trans_liquid, v3s16 nmin, v3s16 nmax) { bool isliquid, wasliquid; v3s16 em = vm->m_area.getExtent(); diff --git a/src/mapgen.h b/src/mapgen.h index 2e917a3aa..a900985da 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -97,5 +97,48 @@ struct MapgenFactory { virtual MapgenParams *createMapgenParams() = 0; }; +enum OreType { + ORE_SCATTER, + ORE_SHEET, + ORE_CLAYLIKE +}; + +class Ore { +public: + std::string ore_name; + std::string wherein_name; + + content_t ore; + content_t wherein; // the node to be replaced + s16 clust_scarcity; // + s16 clust_num_ores; // how many ore nodes are in a chunk + s16 clust_size; // how large (in nodes) a chunk of ore is + s16 height_min; + s16 height_max; + float nthresh; // threshhold for noise at which an ore is placed + NoiseParams *np; // noise for distribution of clusters (NULL for uniform scattering) + Noise *noise; + + Ore() { + ore = CONTENT_IGNORE; + wherein = CONTENT_IGNORE; + np = NULL; + noise = NULL; + } + + void resolveNodeNames(INodeDefManager *ndef); + virtual void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) = 0; +}; + +class OreScatter : public Ore { + void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax); +}; + +class OreSheet : public Ore { + void generate(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax); +}; + +Ore *createOre(OreType type); + #endif diff --git a/src/mapgen_indev.cpp b/src/mapgen_indev.cpp index 6956fc63f..5d455827a 100644 --- a/src/mapgen_indev.cpp +++ b/src/mapgen_indev.cpp @@ -80,7 +80,9 @@ void NoiseIndev::transformNoiseMapFarScale(float xx, float yy, float zz) { } } -MapgenIndev::MapgenIndev(int mapgenid, MapgenIndevParams *params) : MapgenV6(mapgenid, params) { +MapgenIndev::MapgenIndev(int mapgenid, MapgenIndevParams *params, EmergeManager *emerge) + : MapgenV6(mapgenid, params, emerge) +{ noiseindev_terrain_base = new NoiseIndev(params->npindev_terrain_base, seed, csize.X, csize.Z); noiseindev_terrain_higher = new NoiseIndev(params->npindev_terrain_higher, seed, csize.X, csize.Z); noiseindev_steepness = new NoiseIndev(params->npindev_steepness, seed, csize.X, csize.Z); diff --git a/src/mapgen_indev.h b/src/mapgen_indev.h index 7ce65dfe3..fdac1ba20 100644 --- a/src/mapgen_indev.h +++ b/src/mapgen_indev.h @@ -126,7 +126,7 @@ class MapgenIndev : public MapgenV6 { NoiseIndev *noiseindev_float_islands2; NoiseIndev *noiseindev_float_islands3; - MapgenIndev(int mapgenid, MapgenIndevParams *params); + MapgenIndev(int mapgenid, MapgenIndevParams *params, EmergeManager *emerge); ~MapgenIndev(); void calculateNoise(); @@ -141,7 +141,7 @@ class MapgenIndev : public MapgenV6 { struct MapgenFactoryIndev : public MapgenFactoryV6 { Mapgen *createMapgen(int mgid, MapgenParams *params, EmergeManager *emerge) { - return new MapgenIndev(mgid, (MapgenIndevParams *)params); + return new MapgenIndev(mgid, (MapgenIndevParams *)params, emerge); }; MapgenParams *createMapgenParams() { diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp index 1efa3ad74..0b419617d 100644 --- a/src/mapgen_v6.cpp +++ b/src/mapgen_v6.cpp @@ -64,9 +64,10 @@ NoiseParams nparams_v6_def_apple_trees = /////////////////////////////////////////////////////////////////////////////// -MapgenV6::MapgenV6(int mapgenid, MapgenV6Params *params) { +MapgenV6::MapgenV6(int mapgenid, MapgenV6Params *params, EmergeManager *emerge) { this->generating = false; this->id = mapgenid; + this->emerge = emerge; this->seed = (int)params->seed; this->water_level = params->water_level; @@ -463,6 +464,12 @@ void MapgenV6::makeChunk(BlockMakeData *data) { if (flags & MG_TREES) placeTreesAndJungleGrass(); + // Generate the registered ores + for (unsigned int i = 0; i != emerge->ores.size(); i++) { + Ore *ore = emerge->ores[i]; + ore->generate(this, blockseed + i, node_min, node_max); + } + // Calculate lighting calcLighting(node_min, node_max); @@ -494,14 +501,13 @@ void MapgenV6::calculateNoise() { noise_height_select->perlinMap2D( x + 0.5 * noise_height_select->np->spread.X, z + 0.5 * noise_height_select->np->spread.Z); - } - - if (!(flags & MG_FLAT)) { + noise_mud->perlinMap2D( x + 0.5 * noise_mud->np->spread.X, z + 0.5 * noise_mud->np->spread.Z); noise_mud->transformNoiseMap(); } + noise_beach->perlinMap2D( x + 0.2 * noise_beach->np->spread.X, z + 0.7 * noise_beach->np->spread.Z); diff --git a/src/mapgen_v6.h b/src/mapgen_v6.h index 89a3324cd..d37e406cb 100644 --- a/src/mapgen_v6.h +++ b/src/mapgen_v6.h @@ -91,6 +91,8 @@ struct MapgenV6Params : public MapgenParams { class MapgenV6 : public Mapgen { public: + EmergeManager *emerge; + int ystride; v3s16 csize; u32 flags; @@ -128,7 +130,7 @@ public: content_t c_desert_sand; content_t c_desert_stone; - MapgenV6(int mapgenid, MapgenV6Params *params); + MapgenV6(int mapgenid, MapgenV6Params *params, EmergeManager *emerge); ~MapgenV6(); void makeChunk(BlockMakeData *data); @@ -172,7 +174,7 @@ public: struct MapgenFactoryV6 : public MapgenFactory { Mapgen *createMapgen(int mgid, MapgenParams *params, EmergeManager *emerge) { - return new MapgenV6(mgid, (MapgenV6Params *)params); + return new MapgenV6(mgid, (MapgenV6Params *)params, emerge); }; MapgenParams *createMapgenParams() { diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 29494ff69..ddffbb0b7 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -30,6 +30,7 @@ extern "C" { #include "settings.h" // For accessing g_settings #include "main.h" // For g_settings #include "biome.h" +#include "emerge.h" #include "script.h" #include "rollback.h" @@ -242,6 +243,14 @@ struct EnumString es_BiomeTerrainType[] = {0, NULL}, }; +struct EnumString es_OreType[] = +{ + {ORE_SCATTER, "scatter"}, + {ORE_SHEET, "sheet"}, + {ORE_CLAYLIKE, "claylike"}, + {0, NULL}, +}; + /*****************************************************************************/ /* Parameters */ /*****************************************************************************/ @@ -612,8 +621,6 @@ static int l_register_biome_groups(lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); int index = 1; - if (!lua_istable(L, index)) - throw LuaError(L, "register_biome_groups: parameter is not a table"); BiomeDefManager *bmgr = get_server(L)->getBiomeDef(); if (!bmgr) { @@ -686,6 +693,40 @@ static int l_register_biome(lua_State *L) } +static int l_register_ore(lua_State *L) +{ + int index = 1; + luaL_checktype(L, index, LUA_TTABLE); + + IWritableNodeDefManager *ndef = get_server(L)->getWritableNodeDefManager(); + EmergeManager *emerge = get_server(L)->getEmergeManager(); + + enum OreType oretype = (OreType)getenumfield(L, index, + "ore_type", es_OreType, ORE_SCATTER); + Ore *ore = createOre(oretype); + + ore->ore_name = getstringfield_default(L, index, "ore", ""); + ore->wherein_name = getstringfield_default(L, index, "wherein", ""); + ore->clust_scarcity = getintfield_default(L, index, "clust_scarcity", 0); + ore->clust_num_ores = getintfield_default(L, index, "clust_num_ores", 0); + ore->clust_size = getintfield_default(L, index, "clust_size", 0); + ore->height_min = getintfield_default(L, index, "height_min", 0); + ore->height_max = getintfield_default(L, index, "height_max", 0); + ore->nthresh = getfloatfield_default(L, index, "noise_threshhold", 0.); + + lua_getfield(L, index, "noise_params"); + ore->np = read_noiseparams(L, -1); + lua_pop(L, 1); + + ore->noise = NULL; + + emerge->ores.push_back(ore); + + verbosestream << "register_ore: ore '" << ore->ore_name + << "' registered" << std::endl; + return 0; +} + // setting_set(name, value) static int l_setting_set(lua_State *L) @@ -1060,6 +1101,7 @@ static const struct luaL_Reg minetest_f [] = { {"register_craft", l_register_craft}, {"register_biome", l_register_biome}, {"register_biome_groups", l_register_biome_groups}, + {"register_ore", l_register_ore}, {"setting_set", l_setting_set}, {"setting_get", l_setting_get}, {"setting_getbool", l_setting_getbool}, diff --git a/src/scriptapi_noise.cpp b/src/scriptapi_noise.cpp index 1dd6ef8e0..2c1a83c4c 100644 --- a/src/scriptapi_noise.cpp +++ b/src/scriptapi_noise.cpp @@ -269,6 +269,7 @@ NoiseParams *read_noiseparams(lua_State *L, int index) np->scale = getfloatfield_default(L, index, "scale", 0.0); lua_getfield(L, index, "spread"); np->spread = read_v3f(L, -1); + lua_pop(L, 1); np->seed = getintfield_default(L, index, "seed", 0); np->octaves = getintfield_default(L, index, "octaves", 0); np->persist = getfloatfield_default(L, index, "persist", 0.0); @@ -276,6 +277,7 @@ NoiseParams *read_noiseparams(lua_State *L, int index) return np; } + /* LuaPseudoRandom */ diff --git a/src/server.cpp b/src/server.cpp index 644f89349..db05b95cc 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -653,7 +653,6 @@ Server::Server( m_craftdef(createCraftDefManager()), m_event(new EventManager()), m_thread(this), - //m_emergethread(this), m_time_of_day_send_timer(0), m_uptime(0), m_shutdown_requested(false), @@ -698,7 +697,10 @@ Server::Server( // Create biome definition manager m_biomedef = new BiomeDefManager(this); - + + // Create emerge manager + m_emerge = new EmergeManager(this, m_biomedef); + // Create rollback manager std::string rollback_path = m_path_world+DIR_DELIM+"rollback.txt"; m_rollback = createRollbackManager(rollback_path, this); @@ -814,9 +816,6 @@ Server::Server( // Add default biomes after nodedef had its aliases added m_biomedef->addDefaultBiomes(); - // Create emerge manager - m_emerge = new EmergeManager(this, m_biomedef); - // Initialize Environment ServerMap *servermap = new ServerMap(path_world, this, m_emerge); m_env = new ServerEnvironment(servermap, m_lua, this, this); -- cgit v1.2.3