diff options
author | kwolekr <kwolekr@minetest.net> | 2016-05-22 16:50:43 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2016-05-27 23:23:58 -0400 |
commit | c8fd232678698b8be469b3792e7acc9418231a38 (patch) | |
tree | 95f1c68889a3a40b2efad1ed87beb8a80d54c133 | |
parent | fd0efb21c3d40a963a813d73a09bb80df625b247 (diff) | |
download | minetest-c8fd232678698b8be469b3792e7acc9418231a38.tar.gz minetest-c8fd232678698b8be469b3792e7acc9418231a38.tar.bz2 minetest-c8fd232678698b8be469b3792e7acc9418231a38.zip |
Dungeongen: Remove dependency on Mapgen
-rw-r--r-- | src/dungeongen.cpp | 37 | ||||
-rw-r--r-- | src/dungeongen.h | 19 | ||||
-rw-r--r-- | src/mapgen.cpp | 7 | ||||
-rw-r--r-- | src/mapgen_v6.cpp | 6 |
4 files changed, 45 insertions, 24 deletions
diff --git a/src/dungeongen.cpp b/src/dungeongen.cpp index f7f9b8b50..6be7e9086 100644 --- a/src/dungeongen.cpp +++ b/src/dungeongen.cpp @@ -38,22 +38,27 @@ NoiseParams nparams_dungeon_density(0.0, 1.0, v3f(2.5, 2.5, 2.5), 0, 2, 1.4, 2.0 /////////////////////////////////////////////////////////////////////////////// -DungeonGen::DungeonGen(Mapgen *mapgen, DungeonParams *dparams) +DungeonGen::DungeonGen(INodeDefManager *ndef, + GenerateNotifier *gennotify, DungeonParams *dparams) { - this->mg = mapgen; - this->vm = mapgen->vm; + assert(ndef); + + this->ndef = ndef; + this->gennotify = gennotify; #ifdef DGEN_USE_TORCHES - c_torch = mg->ndef->getId("default:torch"); + c_torch = ndef->getId("default:torch"); #endif if (dparams) { memcpy(&dp, dparams, sizeof(dp)); } else { - dp.c_water = mg->ndef->getId("mapgen_water_source"); - dp.c_cobble = mg->ndef->getId("mapgen_cobble"); - dp.c_moss = mg->ndef->getId("mapgen_mossycobble"); - dp.c_stair = mg->ndef->getId("mapgen_stair_cobble"); + dp.seed = 0; + + dp.c_water = ndef->getId("mapgen_water_source"); + dp.c_cobble = ndef->getId("mapgen_cobble"); + dp.c_moss = ndef->getId("mapgen_mossycobble"); + dp.c_stair = ndef->getId("mapgen_stair_cobble"); dp.diagonal_dirs = false; dp.mossratio = 3.0; @@ -67,18 +72,21 @@ DungeonGen::DungeonGen(Mapgen *mapgen, DungeonParams *dparams) } // For mapgens using river water - dp.c_river_water = mg->ndef->getId("mapgen_river_water_source"); + dp.c_river_water = ndef->getId("mapgen_river_water_source"); if (dp.c_river_water == CONTENT_IGNORE) - dp.c_river_water = mg->ndef->getId("mapgen_water_source"); + dp.c_river_water = ndef->getId("mapgen_water_source"); } -void DungeonGen::generate(u32 bseed, v3s16 nmin, v3s16 nmax) +void DungeonGen::generate(MMVManip *vm, u32 bseed, v3s16 nmin, v3s16 nmax) { + assert(vm); + //TimeTaker t("gen dungeons"); - if (NoisePerlin3D(&dp.np_rarity, nmin.X, nmin.Y, nmin.Z, mg->seed) < 0.2) + if (NoisePerlin3D(&dp.np_rarity, nmin.X, nmin.Y, nmin.Z, dp.seed) < 0.2) return; + this->vm = vm; this->blockseed = bseed; random.seed(bseed + 2); @@ -109,7 +117,7 @@ void DungeonGen::generate(u32 bseed, v3s16 nmin, v3s16 nmax) u32 i = vm->m_area.index(nmin.X, y, z); for (s16 x = nmin.X; x <= nmax.X; x++) { if (vm->m_data[i].getContent() == dp.c_cobble) { - float wetness = NoisePerlin3D(&dp.np_wetness, x, y, z, mg->seed); + float wetness = NoisePerlin3D(&dp.np_wetness, x, y, z, dp.seed); float density = NoisePerlin3D(&dp.np_density, x, y, z, blockseed); if (density < wetness / dp.mossratio) vm->m_data[i].setContent(dp.c_moss); @@ -187,7 +195,8 @@ void DungeonGen::makeDungeon(v3s16 start_padding) makeRoom(roomsize, roomplace); v3s16 room_center = roomplace + v3s16(roomsize.X / 2, 1, roomsize.Z / 2); - mg->gennotify.addEvent(dp.notifytype, room_center); + if (gennotify) + gennotify->addEvent(dp.notifytype, room_center); #ifdef DGEN_USE_TORCHES // Place torch at room center (for testing) diff --git a/src/dungeongen.h b/src/dungeongen.h index d209dd4bf..f0a5e5ba8 100644 --- a/src/dungeongen.h +++ b/src/dungeongen.h @@ -39,6 +39,8 @@ int dir_to_facedir(v3s16 d); struct DungeonParams { + int seed; + content_t c_water; content_t c_river_water; content_t c_cobble; @@ -59,7 +61,9 @@ struct DungeonParams { class DungeonGen { public: MMVManip *vm; - Mapgen *mg; + INodeDefManager *ndef; + GenerateNotifier *gennotify; + u32 blockseed; PseudoRandom random; v3s16 csize; @@ -67,17 +71,20 @@ public: content_t c_torch; DungeonParams dp; - //RoomWalker + // RoomWalker v3s16 m_pos; v3s16 m_dir; - DungeonGen(Mapgen *mg, DungeonParams *dparams); - void generate(u32 bseed, v3s16 full_node_min, v3s16 full_node_max); + DungeonGen(INodeDefManager *ndef, + GenerateNotifier *gennotify, DungeonParams *dparams); + + void generate(MMVManip *vm, u32 bseed, + v3s16 full_node_min, v3s16 full_node_max); void makeDungeon(v3s16 start_padding); void makeRoom(v3s16 roomsize, v3s16 roomplace); void makeCorridor(v3s16 doorplace, v3s16 doordir, - v3s16 &result_place, v3s16 &result_dir); + v3s16 &result_place, v3s16 &result_dir); void makeDoor(v3s16 doorplace, v3s16 doordir); void makeFill(v3s16 place, v3s16 size, u8 avoid_flags, MapNode n, u8 or_flags); void makeHole(v3s16 place); @@ -86,7 +93,7 @@ public: bool findPlaceForRoomDoor(v3s16 roomsize, v3s16 &result_doorplace, v3s16 &result_doordir, v3s16 &result_roomplace); - void randomizeDir() + inline void randomizeDir() { m_dir = rand_ortho_dir(random, dp.diagonal_dirs); } diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 56fe34e16..041356e3d 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -639,10 +639,13 @@ void MapgenBasic::generateDungeons(s16 max_stone_y, MgStoneType stone_type) DungeonParams dp; + dp.seed = seed; + dp.np_rarity = nparams_dungeon_rarity; dp.np_density = nparams_dungeon_density; dp.np_wetness = nparams_dungeon_wetness; dp.c_water = c_water_source; + switch (stone_type) { default: case MGSTONE_STONE: @@ -680,8 +683,8 @@ void MapgenBasic::generateDungeons(s16 max_stone_y, MgStoneType stone_type) break; } - DungeonGen dgen(this, &dp); - dgen.generate(blockseed, full_node_min, full_node_max); + DungeonGen dgen(ndef, &gennotify, &dp); + dgen.generate(vm, blockseed, full_node_min, full_node_max); } diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp index 65acfaf93..103120b6a 100644 --- a/src/mapgen_v6.cpp +++ b/src/mapgen_v6.cpp @@ -559,6 +559,8 @@ void MapgenV6::makeChunk(BlockMakeData *data) if ((flags & MG_DUNGEONS) && (stone_surface_max_y >= node_min.Y)) { DungeonParams dp; + dp.seed = seed; + dp.np_rarity = nparams_dungeon_rarity; dp.np_density = nparams_dungeon_density; dp.np_wetness = nparams_dungeon_wetness; @@ -585,8 +587,8 @@ void MapgenV6::makeChunk(BlockMakeData *data) dp.notifytype = GENNOTIFY_DUNGEON; } - DungeonGen dgen(this, &dp); - dgen.generate(blockseed, full_node_min, full_node_max); + DungeonGen dgen(ndef, &gennotify, &dp); + dgen.generate(vm, blockseed, full_node_min, full_node_max); } // Add top and bottom side of water to transforming_liquid queue |