Dungeongen: Remove dependency on Mapgen
parent
fd0efb21c3
commit
c8fd232678
|
@ -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;
|
assert(ndef);
|
||||||
this->vm = mapgen->vm;
|
|
||||||
|
this->ndef = ndef;
|
||||||
|
this->gennotify = gennotify;
|
||||||
|
|
||||||
#ifdef DGEN_USE_TORCHES
|
#ifdef DGEN_USE_TORCHES
|
||||||
c_torch = mg->ndef->getId("default:torch");
|
c_torch = ndef->getId("default:torch");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (dparams) {
|
if (dparams) {
|
||||||
memcpy(&dp, dparams, sizeof(dp));
|
memcpy(&dp, dparams, sizeof(dp));
|
||||||
} else {
|
} else {
|
||||||
dp.c_water = mg->ndef->getId("mapgen_water_source");
|
dp.seed = 0;
|
||||||
dp.c_cobble = mg->ndef->getId("mapgen_cobble");
|
|
||||||
dp.c_moss = mg->ndef->getId("mapgen_mossycobble");
|
dp.c_water = ndef->getId("mapgen_water_source");
|
||||||
dp.c_stair = mg->ndef->getId("mapgen_stair_cobble");
|
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.diagonal_dirs = false;
|
||||||
dp.mossratio = 3.0;
|
dp.mossratio = 3.0;
|
||||||
|
@ -67,18 +72,21 @@ DungeonGen::DungeonGen(Mapgen *mapgen, DungeonParams *dparams)
|
||||||
}
|
}
|
||||||
|
|
||||||
// For mapgens using river water
|
// 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)
|
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");
|
//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;
|
return;
|
||||||
|
|
||||||
|
this->vm = vm;
|
||||||
this->blockseed = bseed;
|
this->blockseed = bseed;
|
||||||
random.seed(bseed + 2);
|
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);
|
u32 i = vm->m_area.index(nmin.X, y, z);
|
||||||
for (s16 x = nmin.X; x <= nmax.X; x++) {
|
for (s16 x = nmin.X; x <= nmax.X; x++) {
|
||||||
if (vm->m_data[i].getContent() == dp.c_cobble) {
|
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);
|
float density = NoisePerlin3D(&dp.np_density, x, y, z, blockseed);
|
||||||
if (density < wetness / dp.mossratio)
|
if (density < wetness / dp.mossratio)
|
||||||
vm->m_data[i].setContent(dp.c_moss);
|
vm->m_data[i].setContent(dp.c_moss);
|
||||||
|
@ -187,7 +195,8 @@ void DungeonGen::makeDungeon(v3s16 start_padding)
|
||||||
makeRoom(roomsize, roomplace);
|
makeRoom(roomsize, roomplace);
|
||||||
|
|
||||||
v3s16 room_center = roomplace + v3s16(roomsize.X / 2, 1, roomsize.Z / 2);
|
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
|
#ifdef DGEN_USE_TORCHES
|
||||||
// Place torch at room center (for testing)
|
// Place torch at room center (for testing)
|
||||||
|
|
|
@ -39,6 +39,8 @@ int dir_to_facedir(v3s16 d);
|
||||||
|
|
||||||
|
|
||||||
struct DungeonParams {
|
struct DungeonParams {
|
||||||
|
int seed;
|
||||||
|
|
||||||
content_t c_water;
|
content_t c_water;
|
||||||
content_t c_river_water;
|
content_t c_river_water;
|
||||||
content_t c_cobble;
|
content_t c_cobble;
|
||||||
|
@ -59,7 +61,9 @@ struct DungeonParams {
|
||||||
class DungeonGen {
|
class DungeonGen {
|
||||||
public:
|
public:
|
||||||
MMVManip *vm;
|
MMVManip *vm;
|
||||||
Mapgen *mg;
|
INodeDefManager *ndef;
|
||||||
|
GenerateNotifier *gennotify;
|
||||||
|
|
||||||
u32 blockseed;
|
u32 blockseed;
|
||||||
PseudoRandom random;
|
PseudoRandom random;
|
||||||
v3s16 csize;
|
v3s16 csize;
|
||||||
|
@ -67,12 +71,15 @@ public:
|
||||||
content_t c_torch;
|
content_t c_torch;
|
||||||
DungeonParams dp;
|
DungeonParams dp;
|
||||||
|
|
||||||
//RoomWalker
|
// RoomWalker
|
||||||
v3s16 m_pos;
|
v3s16 m_pos;
|
||||||
v3s16 m_dir;
|
v3s16 m_dir;
|
||||||
|
|
||||||
DungeonGen(Mapgen *mg, DungeonParams *dparams);
|
DungeonGen(INodeDefManager *ndef,
|
||||||
void generate(u32 bseed, v3s16 full_node_min, v3s16 full_node_max);
|
GenerateNotifier *gennotify, DungeonParams *dparams);
|
||||||
|
|
||||||
|
void generate(MMVManip *vm, u32 bseed,
|
||||||
|
v3s16 full_node_min, v3s16 full_node_max);
|
||||||
|
|
||||||
void makeDungeon(v3s16 start_padding);
|
void makeDungeon(v3s16 start_padding);
|
||||||
void makeRoom(v3s16 roomsize, v3s16 roomplace);
|
void makeRoom(v3s16 roomsize, v3s16 roomplace);
|
||||||
|
@ -86,7 +93,7 @@ public:
|
||||||
bool findPlaceForRoomDoor(v3s16 roomsize, v3s16 &result_doorplace,
|
bool findPlaceForRoomDoor(v3s16 roomsize, v3s16 &result_doorplace,
|
||||||
v3s16 &result_doordir, v3s16 &result_roomplace);
|
v3s16 &result_doordir, v3s16 &result_roomplace);
|
||||||
|
|
||||||
void randomizeDir()
|
inline void randomizeDir()
|
||||||
{
|
{
|
||||||
m_dir = rand_ortho_dir(random, dp.diagonal_dirs);
|
m_dir = rand_ortho_dir(random, dp.diagonal_dirs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -639,10 +639,13 @@ void MapgenBasic::generateDungeons(s16 max_stone_y, MgStoneType stone_type)
|
||||||
|
|
||||||
DungeonParams dp;
|
DungeonParams dp;
|
||||||
|
|
||||||
|
dp.seed = seed;
|
||||||
|
|
||||||
dp.np_rarity = nparams_dungeon_rarity;
|
dp.np_rarity = nparams_dungeon_rarity;
|
||||||
dp.np_density = nparams_dungeon_density;
|
dp.np_density = nparams_dungeon_density;
|
||||||
dp.np_wetness = nparams_dungeon_wetness;
|
dp.np_wetness = nparams_dungeon_wetness;
|
||||||
dp.c_water = c_water_source;
|
dp.c_water = c_water_source;
|
||||||
|
|
||||||
switch (stone_type) {
|
switch (stone_type) {
|
||||||
default:
|
default:
|
||||||
case MGSTONE_STONE:
|
case MGSTONE_STONE:
|
||||||
|
@ -680,8 +683,8 @@ void MapgenBasic::generateDungeons(s16 max_stone_y, MgStoneType stone_type)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
DungeonGen dgen(this, &dp);
|
DungeonGen dgen(ndef, &gennotify, &dp);
|
||||||
dgen.generate(blockseed, full_node_min, full_node_max);
|
dgen.generate(vm, blockseed, full_node_min, full_node_max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -559,6 +559,8 @@ void MapgenV6::makeChunk(BlockMakeData *data)
|
||||||
if ((flags & MG_DUNGEONS) && (stone_surface_max_y >= node_min.Y)) {
|
if ((flags & MG_DUNGEONS) && (stone_surface_max_y >= node_min.Y)) {
|
||||||
DungeonParams dp;
|
DungeonParams dp;
|
||||||
|
|
||||||
|
dp.seed = seed;
|
||||||
|
|
||||||
dp.np_rarity = nparams_dungeon_rarity;
|
dp.np_rarity = nparams_dungeon_rarity;
|
||||||
dp.np_density = nparams_dungeon_density;
|
dp.np_density = nparams_dungeon_density;
|
||||||
dp.np_wetness = nparams_dungeon_wetness;
|
dp.np_wetness = nparams_dungeon_wetness;
|
||||||
|
@ -585,8 +587,8 @@ void MapgenV6::makeChunk(BlockMakeData *data)
|
||||||
dp.notifytype = GENNOTIFY_DUNGEON;
|
dp.notifytype = GENNOTIFY_DUNGEON;
|
||||||
}
|
}
|
||||||
|
|
||||||
DungeonGen dgen(this, &dp);
|
DungeonGen dgen(ndef, &gennotify, &dp);
|
||||||
dgen.generate(blockseed, full_node_min, full_node_max);
|
dgen.generate(vm, blockseed, full_node_min, full_node_max);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add top and bottom side of water to transforming_liquid queue
|
// Add top and bottom side of water to transforming_liquid queue
|
||||||
|
|
Loading…
Reference in New Issue