Dungeongen: Remove dependency on Mapgen

This commit is contained in:
kwolekr 2016-05-22 16:50:43 -04:00
parent fd0efb21c3
commit c8fd232678
4 changed files with 45 additions and 24 deletions

View File

@ -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)

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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