forked from Mirrorlandia_minetest/minetest
EmergeManager: Fix Lua mapgen override param handling
This commit is contained in:
parent
bbae8eb751
commit
83cc882335
145
src/emerge.cpp
145
src/emerge.cpp
@ -56,10 +56,10 @@ public:
|
||||
Mapgen *mapgen;
|
||||
bool enable_mapgen_debug_info;
|
||||
int id;
|
||||
|
||||
|
||||
Event qevent;
|
||||
std::queue<v3s16> blockqueue;
|
||||
|
||||
|
||||
EmergeThread(Server *server, int ethreadid):
|
||||
SimpleThread(),
|
||||
m_server(server),
|
||||
@ -100,14 +100,14 @@ EmergeManager::EmergeManager(IGameDef *gamedef) {
|
||||
this->ndef = gamedef->getNodeDefManager();
|
||||
this->biomedef = new BiomeDefManager();
|
||||
this->params = NULL;
|
||||
|
||||
|
||||
this->luaoverride_params = NULL;
|
||||
this->luaoverride_params_modified = 0;
|
||||
this->luaoverride_flagmask = 0;
|
||||
|
||||
|
||||
mapgen_debug_info = g_settings->getBool("enable_mapgen_debug_info");
|
||||
|
||||
|
||||
|
||||
int nthreads;
|
||||
if (g_settings->get("num_emerge_threads").empty()) {
|
||||
int nprocs = porting::getNumberOfProcessors();
|
||||
@ -118,7 +118,7 @@ EmergeManager::EmergeManager(IGameDef *gamedef) {
|
||||
}
|
||||
if (nthreads < 1)
|
||||
nthreads = 1;
|
||||
|
||||
|
||||
qlimit_total = g_settings->getU16("emergequeue_limit_total");
|
||||
qlimit_diskonly = g_settings->get("emergequeue_limit_diskonly").empty() ?
|
||||
nthreads * 5 + 1 :
|
||||
@ -126,10 +126,10 @@ EmergeManager::EmergeManager(IGameDef *gamedef) {
|
||||
qlimit_generate = g_settings->get("emergequeue_limit_generate").empty() ?
|
||||
nthreads + 1 :
|
||||
g_settings->getU16("emergequeue_limit_generate");
|
||||
|
||||
|
||||
for (int i = 0; i != nthreads; i++)
|
||||
emergethread.push_back(new EmergeThread((Server *)gamedef, i));
|
||||
|
||||
|
||||
infostream << "EmergeManager: using " << nthreads << " threads" << std::endl;
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ EmergeManager::~EmergeManager() {
|
||||
for (unsigned int i = 0; i < decorations.size(); i++)
|
||||
delete decorations[i];
|
||||
decorations.clear();
|
||||
|
||||
|
||||
for (std::map<std::string, MapgenFactory *>::iterator iter = mglist.begin();
|
||||
iter != mglist.end(); iter ++) {
|
||||
delete iter->second;
|
||||
@ -165,61 +165,97 @@ EmergeManager::~EmergeManager() {
|
||||
|
||||
void EmergeManager::initMapgens(MapgenParams *mgparams) {
|
||||
Mapgen *mg;
|
||||
|
||||
|
||||
if (mapgen.size())
|
||||
return;
|
||||
|
||||
|
||||
// Resolve names of nodes for things that were registered
|
||||
// (at this point, the registration period is over)
|
||||
biomedef->resolveNodeNames(ndef);
|
||||
|
||||
|
||||
for (size_t i = 0; i != ores.size(); i++)
|
||||
ores[i]->resolveNodeNames(ndef);
|
||||
|
||||
|
||||
for (size_t i = 0; i != decorations.size(); i++)
|
||||
decorations[i]->resolveNodeNames(ndef);
|
||||
|
||||
|
||||
// Apply mapgen parameter overrides from Lua
|
||||
if (luaoverride_params) {
|
||||
if (luaoverride_params_modified & MGPARAMS_SET_MGNAME)
|
||||
mgparams->mg_name = luaoverride_params->mg_name;
|
||||
|
||||
if (luaoverride_params_modified & MGPARAMS_SET_MGNAME) {
|
||||
MapgenParams *mgp = setMapgenType(mgparams, luaoverride_params->mg_name);
|
||||
if (!mgp) {
|
||||
errorstream << "EmergeManager: Failed to set new mapgen name"
|
||||
<< std::endl;
|
||||
} else {
|
||||
mgparams = mgp;
|
||||
}
|
||||
}
|
||||
|
||||
if (luaoverride_params_modified & MGPARAMS_SET_SEED)
|
||||
mgparams->seed = luaoverride_params->seed;
|
||||
|
||||
|
||||
if (luaoverride_params_modified & MGPARAMS_SET_WATER_LEVEL)
|
||||
mgparams->water_level = luaoverride_params->water_level;
|
||||
|
||||
|
||||
if (luaoverride_params_modified & MGPARAMS_SET_FLAGS) {
|
||||
mgparams->flags &= ~luaoverride_flagmask;
|
||||
mgparams->flags |= luaoverride_params->flags;
|
||||
}
|
||||
|
||||
|
||||
delete luaoverride_params;
|
||||
luaoverride_params = NULL;
|
||||
}
|
||||
|
||||
|
||||
// Create the mapgens
|
||||
this->params = mgparams;
|
||||
for (size_t i = 0; i != emergethread.size(); i++) {
|
||||
mg = createMapgen(params->mg_name, 0, params);
|
||||
mg = createMapgen(params->mg_name, i, params);
|
||||
if (!mg) {
|
||||
infostream << "EmergeManager: falling back to mapgen v6" << std::endl;
|
||||
delete params;
|
||||
params = createMapgenParams("v6");
|
||||
mg = createMapgen("v6", 0, params);
|
||||
infostream << "EmergeManager: Falling back to Mapgen V6" << std::endl;
|
||||
|
||||
params = setMapgenType(params, "v6");
|
||||
mg = createMapgen(params->mg_name, i, params);
|
||||
if (!mg) {
|
||||
errorstream << "EmergeManager: CRITICAL ERROR: Failed to fall"
|
||||
"back to Mapgen V6, not generating map" << std::endl;
|
||||
}
|
||||
}
|
||||
mapgen.push_back(mg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MapgenParams *EmergeManager::setMapgenType(MapgenParams *mgparams,
|
||||
std::string newname) {
|
||||
MapgenParams *newparams = createMapgenParams(newname);
|
||||
if (!newparams) {
|
||||
errorstream << "EmergeManager: Mapgen override failed" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
newparams->mg_name = newname;
|
||||
newparams->seed = mgparams->seed;
|
||||
newparams->water_level = mgparams->water_level;
|
||||
newparams->chunksize = mgparams->chunksize;
|
||||
newparams->flags = mgparams->flags;
|
||||
|
||||
if (!newparams->readParams(g_settings)) {
|
||||
errorstream << "EmergeManager: Mapgen override failed" << std::endl;
|
||||
delete newparams;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
delete mgparams;
|
||||
return newparams;
|
||||
}
|
||||
|
||||
|
||||
Mapgen *EmergeManager::getCurrentMapgen() {
|
||||
for (unsigned int i = 0; i != emergethread.size(); i++) {
|
||||
if (emergethread[i]->IsSameThread())
|
||||
return emergethread[i]->mapgen;
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -229,19 +265,20 @@ void EmergeManager::triggerAllThreads() {
|
||||
emergethread[i]->trigger();
|
||||
}
|
||||
|
||||
|
||||
bool EmergeManager::enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate) {
|
||||
std::map<v3s16, BlockEmergeData *>::const_iterator iter;
|
||||
BlockEmergeData *bedata;
|
||||
u16 count;
|
||||
u8 flags = 0;
|
||||
int idx = 0;
|
||||
|
||||
|
||||
if (allow_generate)
|
||||
flags |= BLOCK_EMERGE_ALLOWGEN;
|
||||
|
||||
{
|
||||
JMutexAutoLock queuelock(queuemutex);
|
||||
|
||||
|
||||
count = blocks_enqueued.size();
|
||||
if (count >= qlimit_total)
|
||||
return false;
|
||||
@ -250,7 +287,7 @@ bool EmergeManager::enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate
|
||||
u16 qlimit_peer = allow_generate ? qlimit_generate : qlimit_diskonly;
|
||||
if (count >= qlimit_peer)
|
||||
return false;
|
||||
|
||||
|
||||
iter = blocks_enqueued.find(p);
|
||||
if (iter != blocks_enqueued.end()) {
|
||||
bedata = iter->second;
|
||||
@ -262,9 +299,9 @@ bool EmergeManager::enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate
|
||||
bedata->flags = flags;
|
||||
bedata->peer_requested = peer_id;
|
||||
blocks_enqueued.insert(std::make_pair(p, bedata));
|
||||
|
||||
|
||||
peer_queue_count[peer_id] = count + 1;
|
||||
|
||||
|
||||
// insert into the EmergeThread queue with the least items
|
||||
int lowestitems = emergethread[0]->blockqueue.size();
|
||||
for (unsigned int i = 1; i != emergethread.size(); i++) {
|
||||
@ -274,11 +311,11 @@ bool EmergeManager::enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate
|
||||
lowestitems = nitems;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
emergethread[idx]->blockqueue.push(p);
|
||||
}
|
||||
emergethread[idx]->qevent.signal();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -286,10 +323,10 @@ bool EmergeManager::enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate
|
||||
int EmergeManager::getGroundLevelAtPoint(v2s16 p) {
|
||||
if (mapgen.size() == 0 || !mapgen[0]) {
|
||||
errorstream << "EmergeManager: getGroundLevelAtPoint() called"
|
||||
" before mapgen initialized" << std::endl;
|
||||
" before mapgen initialized" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return mapgen[0]->getGroundLevelAtPoint(p);
|
||||
}
|
||||
|
||||
@ -325,7 +362,7 @@ Mapgen *EmergeManager::createMapgen(std::string mgname, int mgid,
|
||||
" not registered" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
MapgenFactory *mgfactory = iter->second;
|
||||
return mgfactory->createMapgen(mgid, mgparams, this);
|
||||
}
|
||||
@ -339,7 +376,7 @@ MapgenParams *EmergeManager::createMapgenParams(std::string mgname) {
|
||||
" not registered" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
MapgenFactory *mgfactory = iter->second;
|
||||
return mgfactory->createMapgenParams();
|
||||
}
|
||||
@ -350,10 +387,10 @@ MapgenParams *EmergeManager::getParamsFromSettings(Settings *settings) {
|
||||
MapgenParams *mgparams = createMapgenParams(mg_name);
|
||||
if (!mgparams)
|
||||
return NULL;
|
||||
|
||||
|
||||
std::string seedstr = settings->get(settings == g_settings ?
|
||||
"fixed_map_seed" : "seed");
|
||||
|
||||
|
||||
mgparams->mg_name = mg_name;
|
||||
mgparams->seed = read_seed(seedstr.c_str());
|
||||
mgparams->water_level = settings->getS16("water_level");
|
||||
@ -395,21 +432,21 @@ bool EmergeThread::popBlockEmerge(v3s16 *pos, u8 *flags) {
|
||||
return false;
|
||||
v3s16 p = blockqueue.front();
|
||||
blockqueue.pop();
|
||||
|
||||
|
||||
*pos = p;
|
||||
|
||||
|
||||
iter = emerge->blocks_enqueued.find(p);
|
||||
if (iter == emerge->blocks_enqueued.end())
|
||||
return false; //uh oh, queue and map out of sync!!
|
||||
|
||||
BlockEmergeData *bedata = iter->second;
|
||||
*flags = bedata->flags;
|
||||
|
||||
|
||||
emerge->peer_queue_count[bedata->peer_requested]--;
|
||||
|
||||
delete bedata;
|
||||
emerge->blocks_enqueued.erase(iter);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -419,7 +456,7 @@ bool EmergeThread::getBlockOrStartGen(v3s16 p, MapBlock **b,
|
||||
v2s16 p2d(p.X, p.Z);
|
||||
//envlock: usually takes <=1ms, sometimes 90ms or ~400ms to acquire
|
||||
JMutexAutoLock envlock(m_server->m_env_mutex);
|
||||
|
||||
|
||||
// Load sector if it isn't loaded
|
||||
if (map->getSectorNoGenerateNoEx(p2d) == NULL)
|
||||
map->loadSectorMeta(p2d);
|
||||
@ -440,7 +477,7 @@ bool EmergeThread::getBlockOrStartGen(v3s16 p, MapBlock **b,
|
||||
*b = block;
|
||||
return map->initBlockMake(data, p);
|
||||
}
|
||||
|
||||
|
||||
*b = block;
|
||||
return false;
|
||||
}
|
||||
@ -455,12 +492,12 @@ void *EmergeThread::Thread() {
|
||||
v3s16 last_tried_pos(-32768,-32768,-32768); // For error output
|
||||
v3s16 p;
|
||||
u8 flags;
|
||||
|
||||
|
||||
map = (ServerMap *)&(m_server->m_env->getMap());
|
||||
emerge = m_server->m_emerge;
|
||||
mapgen = emerge->mapgen[id];
|
||||
enable_mapgen_debug_info = emerge->mapgen_debug_info;
|
||||
|
||||
|
||||
while (getRun())
|
||||
try {
|
||||
if (!popBlockEmerge(&p, &flags)) {
|
||||
@ -474,7 +511,7 @@ void *EmergeThread::Thread() {
|
||||
|
||||
bool allow_generate = flags & BLOCK_EMERGE_ALLOWGEN;
|
||||
EMERGE_DBG_OUT("p=" PP(p) " allow_generate=" << allow_generate);
|
||||
|
||||
|
||||
/*
|
||||
Try to fetch block from memory or disk.
|
||||
If not found and asked to generate, initialize generator.
|
||||
@ -482,8 +519,8 @@ void *EmergeThread::Thread() {
|
||||
BlockMakeData data;
|
||||
MapBlock *block = NULL;
|
||||
std::map<v3s16, MapBlock *> modified_blocks;
|
||||
|
||||
if (getBlockOrStartGen(p, &block, &data, allow_generate)) {
|
||||
|
||||
if (getBlockOrStartGen(p, &block, &data, allow_generate) && mapgen) {
|
||||
{
|
||||
ScopeProfiler sp(g_profiler, "EmergeThread: Mapgen::makeChunk", SPT_AVG);
|
||||
TimeTaker t("mapgen::make_block()");
|
||||
@ -501,7 +538,7 @@ void *EmergeThread::Thread() {
|
||||
"Mapgen::makeChunk (envlock)", SPT_AVG);
|
||||
|
||||
map->finishBlockMake(&data, modified_blocks);
|
||||
|
||||
|
||||
block = map->getBlockNoCreateNoEx(p);
|
||||
if (block) {
|
||||
/*
|
||||
@ -522,7 +559,7 @@ void *EmergeThread::Thread() {
|
||||
}
|
||||
|
||||
EMERGE_DBG_OUT("ended up with: " << analyze_block(block));
|
||||
|
||||
|
||||
m_server->m_env->activateBlock(block, 0);
|
||||
}
|
||||
}
|
||||
@ -568,7 +605,7 @@ void *EmergeThread::Thread() {
|
||||
err << "You can ignore this using [ignore_world_load_errors = true]."<<std::endl;
|
||||
m_server->setAsyncFatalError(err.str());
|
||||
}
|
||||
|
||||
|
||||
END_DEBUG_EXCEPTION_HANDLER(errorstream)
|
||||
log_deregister_thread();
|
||||
return NULL;
|
||||
|
13
src/emerge.h
13
src/emerge.h
@ -83,21 +83,21 @@ public:
|
||||
INodeDefManager *ndef;
|
||||
|
||||
std::map<std::string, MapgenFactory *> mglist;
|
||||
|
||||
|
||||
std::vector<Mapgen *> mapgen;
|
||||
std::vector<EmergeThread *> emergethread;
|
||||
|
||||
|
||||
//settings
|
||||
MapgenParams *params;
|
||||
bool mapgen_debug_info;
|
||||
u16 qlimit_total;
|
||||
u16 qlimit_diskonly;
|
||||
u16 qlimit_generate;
|
||||
|
||||
|
||||
MapgenParams *luaoverride_params;
|
||||
u32 luaoverride_params_modified;
|
||||
u32 luaoverride_flagmask;
|
||||
|
||||
|
||||
//block emerge queue data structures
|
||||
JMutex queuemutex;
|
||||
std::map<v3s16, BlockEmergeData *> blocks_enqueued;
|
||||
@ -112,17 +112,18 @@ public:
|
||||
~EmergeManager();
|
||||
|
||||
void initMapgens(MapgenParams *mgparams);
|
||||
MapgenParams *setMapgenType(MapgenParams *mgparams, std::string newname);
|
||||
Mapgen *getCurrentMapgen();
|
||||
Mapgen *createMapgen(std::string mgname, int mgid,
|
||||
MapgenParams *mgparams);
|
||||
MapgenParams *createMapgenParams(std::string mgname);
|
||||
void triggerAllThreads();
|
||||
bool enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate);
|
||||
|
||||
|
||||
void registerMapgen(std::string name, MapgenFactory *mgfactory);
|
||||
MapgenParams *getParamsFromSettings(Settings *settings);
|
||||
void setParamsToSettings(Settings *settings);
|
||||
|
||||
|
||||
//mapgen helper methods
|
||||
Biome *getBiomeAtPoint(v3s16 p);
|
||||
int getGroundLevelAtPoint(v2s16 p);
|
||||
|
138
src/mapgen.cpp
138
src/mapgen.cpp
@ -151,7 +151,7 @@ void OreScatter::generate(ManualMapVoxelManipulator *vm, int seed,
|
||||
int x0 = pr.range(nmin.X, nmax.X - csize + 1);
|
||||
int y0 = pr.range(nmin.Y, nmax.Y - csize + 1);
|
||||
int z0 = pr.range(nmin.Z, nmax.Z - csize + 1);
|
||||
|
||||
|
||||
if (np && (NoisePerlin3D(np, x0, y0, z0, seed) < nthresh))
|
||||
continue;
|
||||
|
||||
@ -241,7 +241,7 @@ Decoration::~Decoration() {
|
||||
|
||||
void Decoration::resolveNodeNames(INodeDefManager *ndef) {
|
||||
this->ndef = ndef;
|
||||
|
||||
|
||||
if (c_place_on == CONTENT_IGNORE)
|
||||
c_place_on = ndef->getId(place_on_name);
|
||||
}
|
||||
@ -257,7 +257,7 @@ void Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
|
||||
"sidelen; setting sidelen to " << carea_size << std::endl;
|
||||
sidelen = carea_size;
|
||||
}
|
||||
|
||||
|
||||
s16 divlen = carea_size / sidelen;
|
||||
int area = sidelen * sidelen;
|
||||
|
||||
@ -287,11 +287,11 @@ void Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
|
||||
s16 z = ps.range(p2d_min.Y, p2d_max.Y);
|
||||
|
||||
int mapindex = carea_size * (z - nmin.Z) + (x - nmin.X);
|
||||
|
||||
s16 y = mg->heightmap ?
|
||||
|
||||
s16 y = mg->heightmap ?
|
||||
mg->heightmap[mapindex] :
|
||||
mg->findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y);
|
||||
|
||||
|
||||
if (y < nmin.Y || y > nmax.Y)
|
||||
continue;
|
||||
|
||||
@ -309,7 +309,7 @@ void Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
|
||||
|
||||
if (mg->biomemap) {
|
||||
std::set<u8>::iterator iter;
|
||||
|
||||
|
||||
if (biomes.size()) {
|
||||
iter = biomes.find(mg->biomemap[mapindex]);
|
||||
if (iter == biomes.end())
|
||||
@ -327,7 +327,7 @@ void Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
|
||||
void Decoration::placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
|
||||
PseudoRandom pr(blockseed + 53);
|
||||
std::vector<CutoffData> handled_cutoffs;
|
||||
|
||||
|
||||
// Copy over the cutoffs we're interested in so we don't needlessly hold a lock
|
||||
{
|
||||
JMutexAutoLock cutofflock(cutoff_mutex);
|
||||
@ -341,37 +341,37 @@ void Decoration::placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
|
||||
continue;
|
||||
if (p.Y + height < nmin.Y || p.Y > nmax.Y)
|
||||
continue;
|
||||
|
||||
|
||||
handled_cutoffs.push_back(cutoff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Generate the cutoffs
|
||||
for (size_t i = 0; i != handled_cutoffs.size(); i++) {
|
||||
v3s16 p = handled_cutoffs[i].p;
|
||||
s16 height = handled_cutoffs[i].height;
|
||||
|
||||
|
||||
if (p.Y + height > nmax.Y) {
|
||||
//printf("Decoration at (%d %d %d) cut off again!\n", p.X, p.Y, p.Z);
|
||||
cuttoffs.push_back(v3s16(p.X, p.Y, p.Z));
|
||||
}
|
||||
|
||||
|
||||
generate(mg, &pr, nmax.Y, nmin.Y - p.Y, v3s16(p.X, nmin.Y, p.Z));
|
||||
}
|
||||
|
||||
|
||||
// Remove cutoffs that were handled from the cutoff list
|
||||
{
|
||||
JMutexAutoLock cutofflock(cutoff_mutex);
|
||||
for (std::list<CutoffData>::iterator i = cutoffs.begin();
|
||||
i != cutoffs.end(); ++i) {
|
||||
|
||||
|
||||
for (size_t j = 0; j != handled_cutoffs.size(); j++) {
|
||||
CutoffData coff = *i;
|
||||
if (coff.p == handled_cutoffs[j].p)
|
||||
i = cutoffs.erase(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -381,7 +381,7 @@ void Decoration::placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
|
||||
|
||||
void DecoSimple::resolveNodeNames(INodeDefManager *ndef) {
|
||||
Decoration::resolveNodeNames(ndef);
|
||||
|
||||
|
||||
if (c_deco == CONTENT_IGNORE && !decolist_names.size()) {
|
||||
c_deco = ndef->getId(deco_name);
|
||||
if (c_deco == CONTENT_IGNORE) {
|
||||
@ -399,11 +399,11 @@ void DecoSimple::resolveNodeNames(INodeDefManager *ndef) {
|
||||
c_spawnby = CONTENT_AIR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (c_decolist.size())
|
||||
return;
|
||||
|
||||
for (size_t i = 0; i != decolist_names.size(); i++) {
|
||||
|
||||
for (size_t i = 0; i != decolist_names.size(); i++) {
|
||||
content_t c = ndef->getId(decolist_names[i]);
|
||||
if (c == CONTENT_IGNORE) {
|
||||
errorstream << "DecoSimple::resolveNodeNames: decolist node '"
|
||||
@ -422,7 +422,7 @@ void DecoSimple::generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) {
|
||||
if (vm->m_data[vi].getContent() != c_place_on &&
|
||||
c_place_on != CONTENT_IGNORE)
|
||||
return;
|
||||
|
||||
|
||||
if (nspawnby != -1) {
|
||||
int nneighs = 0;
|
||||
v3s16 dirs[8] = { // a Moore neighborhood
|
||||
@ -435,18 +435,18 @@ void DecoSimple::generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) {
|
||||
v3s16(-1, 0, -1),
|
||||
v3s16( 1, 0, -1)
|
||||
};
|
||||
|
||||
|
||||
for (int i = 0; i != 8; i++) {
|
||||
u32 index = vm->m_area.index(p + dirs[i]);
|
||||
if (vm->m_area.contains(index) &&
|
||||
vm->m_data[index].getContent() == c_spawnby)
|
||||
nneighs++;
|
||||
}
|
||||
|
||||
|
||||
if (nneighs < nspawnby)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
size_t ndecos = c_decolist.size();
|
||||
content_t c_place = ndecos ? c_decolist[pr->range(0, ndecos - 1)] : c_deco;
|
||||
|
||||
@ -454,15 +454,15 @@ void DecoSimple::generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) {
|
||||
pr->range(deco_height, deco_height_max) : deco_height;
|
||||
|
||||
height = MYMIN(height, max_y - p.Y);
|
||||
|
||||
|
||||
v3s16 em = vm->m_area.getExtent();
|
||||
for (int i = 0; i < height; i++) {
|
||||
vm->m_area.add_y(em, vi, 1);
|
||||
|
||||
|
||||
content_t c = vm->m_data[vi].getContent();
|
||||
if (c != CONTENT_AIR && c != CONTENT_IGNORE)
|
||||
break;
|
||||
|
||||
|
||||
vm->m_data[vi] = MapNode(c_place);
|
||||
}
|
||||
}
|
||||
@ -499,37 +499,37 @@ DecoSchematic::~DecoSchematic() {
|
||||
|
||||
void DecoSchematic::resolveNodeNames(INodeDefManager *ndef) {
|
||||
Decoration::resolveNodeNames(ndef);
|
||||
|
||||
|
||||
if (filename.empty())
|
||||
return;
|
||||
|
||||
|
||||
if (!node_names) {
|
||||
errorstream << "DecoSchematic::resolveNodeNames: node name list was "
|
||||
"not created" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (size_t i = 0; i != node_names->size(); i++) {
|
||||
std::string name = node_names->at(i);
|
||||
|
||||
|
||||
std::map<std::string, std::string>::iterator it;
|
||||
it = replacements.find(name);
|
||||
if (it != replacements.end())
|
||||
name = it->second;
|
||||
|
||||
|
||||
content_t c = ndef->getId(name);
|
||||
if (c == CONTENT_IGNORE) {
|
||||
errorstream << "DecoSchematic::resolveNodeNames: node '"
|
||||
<< name << "' not defined" << std::endl;
|
||||
c = CONTENT_AIR;
|
||||
}
|
||||
|
||||
|
||||
c_nodes.push_back(c);
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i != size.X * size.Y * size.Z; i++)
|
||||
schematic[i].setContent(c_nodes[schematic[i].getContent()]);
|
||||
|
||||
|
||||
delete node_names;
|
||||
node_names = NULL;
|
||||
}
|
||||
@ -544,15 +544,15 @@ void DecoSchematic::generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) {
|
||||
p.Y -= (size.Y + 1) / 2;
|
||||
if (flags & DECO_PLACE_CENTER_Z)
|
||||
p.Z -= (size.Z + 1) / 2;
|
||||
|
||||
|
||||
u32 vi = vm->m_area.index(p);
|
||||
if (vm->m_data[vi].getContent() != c_place_on &&
|
||||
c_place_on != CONTENT_IGNORE)
|
||||
return;
|
||||
|
||||
|
||||
Rotation rot = (rotation == ROTATE_RAND) ?
|
||||
(Rotation)pr->range(ROTATE_0, ROTATE_270) : rotation;
|
||||
|
||||
|
||||
blitToVManip(p, vm, rot, false);
|
||||
}
|
||||
|
||||
@ -649,7 +649,7 @@ void DecoSchematic::placeStructure(Map *map, v3s16 p) {
|
||||
|
||||
Rotation rot = (rotation == ROTATE_RAND) ?
|
||||
(Rotation)myrand_range(ROTATE_0, ROTATE_270) : rotation;
|
||||
|
||||
|
||||
v3s16 s = (rot == ROTATE_90 || rot == ROTATE_270) ?
|
||||
v3s16(size.Z, size.Y, size.X) : size;
|
||||
|
||||
@ -659,17 +659,17 @@ void DecoSchematic::placeStructure(Map *map, v3s16 p) {
|
||||
p.Y -= (s.Y + 1) / 2;
|
||||
if (flags & DECO_PLACE_CENTER_Z)
|
||||
p.Z -= (s.Z + 1) / 2;
|
||||
|
||||
|
||||
v3s16 bp1 = getNodeBlockPos(p);
|
||||
v3s16 bp2 = getNodeBlockPos(p + s - v3s16(1,1,1));
|
||||
vm->initialEmerge(bp1, bp2);
|
||||
|
||||
|
||||
blitToVManip(p, vm, rot, true);
|
||||
|
||||
|
||||
std::map<v3s16, MapBlock *> lighting_modified_blocks;
|
||||
std::map<v3s16, MapBlock *> modified_blocks;
|
||||
vm->blitBackAll(&modified_blocks);
|
||||
|
||||
|
||||
// TODO: Optimize this by using Mapgen::calcLighting() instead
|
||||
lighting_modified_blocks.insert(modified_blocks.begin(), modified_blocks.end());
|
||||
map->updateLighting(lighting_modified_blocks, modified_blocks);
|
||||
@ -680,7 +680,7 @@ void DecoSchematic::placeStructure(Map *map, v3s16 p) {
|
||||
it = modified_blocks.begin();
|
||||
it != modified_blocks.end(); ++it)
|
||||
event.modified_blocks.insert(it->first);
|
||||
|
||||
|
||||
map->dispatchEvent(&event);
|
||||
}
|
||||
|
||||
@ -688,7 +688,7 @@ void DecoSchematic::placeStructure(Map *map, v3s16 p) {
|
||||
bool DecoSchematic::loadSchematicFile() {
|
||||
content_t cignore = CONTENT_IGNORE;
|
||||
bool have_cignore = false;
|
||||
|
||||
|
||||
std::ifstream is(filename.c_str(), std::ios_base::binary);
|
||||
|
||||
u32 signature = readU32(is);
|
||||
@ -697,7 +697,7 @@ bool DecoSchematic::loadSchematicFile() {
|
||||
"file" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
u16 version = readU16(is);
|
||||
if (version > MTSCHEM_FILE_VER_HIGHEST_READ) {
|
||||
errorstream << "loadSchematicFile: unsupported schematic "
|
||||
@ -718,9 +718,9 @@ bool DecoSchematic::loadSchematicFile() {
|
||||
}
|
||||
|
||||
int nodecount = size.X * size.Y * size.Z;
|
||||
|
||||
|
||||
u16 nidmapcount = readU16(is);
|
||||
|
||||
|
||||
node_names = new std::vector<std::string>;
|
||||
for (int i = 0; i != nidmapcount; i++) {
|
||||
std::string name = deSerializeString(is);
|
||||
@ -736,7 +736,7 @@ bool DecoSchematic::loadSchematicFile() {
|
||||
schematic = new MapNode[nodecount];
|
||||
MapNode::deSerializeBulk(is, SER_FMT_VER_HIGHEST_READ, schematic,
|
||||
nodecount, 2, 2, true);
|
||||
|
||||
|
||||
if (version == 1) { // fix up the probability values
|
||||
for (int i = 0; i != nodecount; i++) {
|
||||
if (schematic[i].param1 == 0)
|
||||
@ -745,7 +745,7 @@ bool DecoSchematic::loadSchematicFile() {
|
||||
schematic[i].param1 = MTSCHEM_PROB_NEVER;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -774,7 +774,7 @@ bool DecoSchematic::loadSchematicFile() {
|
||||
For each node in schematic:
|
||||
[u8] param2
|
||||
}
|
||||
|
||||
|
||||
Version changes:
|
||||
1 - Initial version
|
||||
2 - Fixed messy never/always place; 0 probability is now never, 0xFF is always
|
||||
@ -792,12 +792,12 @@ void DecoSchematic::saveSchematicFile(INodeDefManager *ndef) {
|
||||
std::vector<content_t> usednodes;
|
||||
int nodecount = size.X * size.Y * size.Z;
|
||||
build_nnlist_and_update_ids(schematic, nodecount, &usednodes);
|
||||
|
||||
|
||||
u16 numids = usednodes.size();
|
||||
writeU16(ss, numids); // name count
|
||||
for (int i = 0; i != numids; i++)
|
||||
ss << serializeString(ndef->get(usednodes[i]).name); // node names
|
||||
|
||||
|
||||
// compressed bulk node data
|
||||
MapNode::serializeBulk(ss, SER_FMT_VER_HIGHEST_WRITE, schematic,
|
||||
nodecount, 2, 2, true);
|
||||
@ -810,7 +810,7 @@ void build_nnlist_and_update_ids(MapNode *nodes, u32 nodecount,
|
||||
std::vector<content_t> *usednodes) {
|
||||
std::map<content_t, content_t> nodeidmap;
|
||||
content_t numids = 0;
|
||||
|
||||
|
||||
for (u32 i = 0; i != nodecount; i++) {
|
||||
content_t id;
|
||||
content_t c = nodes[i].getContent();
|
||||
@ -836,7 +836,7 @@ bool DecoSchematic::getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2) {
|
||||
v3s16 bp1 = getNodeBlockPos(p1);
|
||||
v3s16 bp2 = getNodeBlockPos(p2);
|
||||
vm->initialEmerge(bp1, bp2);
|
||||
|
||||
|
||||
size = p2 - p1 + 1;
|
||||
|
||||
slice_probs = new u8[size.Y];
|
||||
@ -844,7 +844,7 @@ bool DecoSchematic::getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2) {
|
||||
slice_probs[y] = MTSCHEM_PROB_ALWAYS;
|
||||
|
||||
schematic = new MapNode[size.X * size.Y * size.Z];
|
||||
|
||||
|
||||
u32 i = 0;
|
||||
for (s16 z = p1.Z; z <= p2.Z; z++)
|
||||
for (s16 y = p1.Y; y <= p2.Y; y++) {
|
||||
@ -870,7 +870,7 @@ void DecoSchematic::applyProbabilities(v3s16 p0,
|
||||
if (index < size.Z * size.Y * size.X) {
|
||||
u8 prob = (*plist)[i].second;
|
||||
schematic[index].param1 = prob;
|
||||
|
||||
|
||||
// trim unnecessary node names from schematic
|
||||
if (prob == MTSCHEM_PROB_NEVER)
|
||||
schematic[index].setContent(CONTENT_AIR);
|
||||
@ -906,7 +906,7 @@ s16 Mapgen::findGroundLevelFull(v2s16 p2d) {
|
||||
s16 y_nodes_min = vm->m_area.MinEdge.Y;
|
||||
u32 i = vm->m_area.index(p2d.X, y_nodes_max, p2d.Y);
|
||||
s16 y;
|
||||
|
||||
|
||||
for (y = y_nodes_max; y >= y_nodes_min; y--) {
|
||||
MapNode &n = vm->m_data[i];
|
||||
if (ndef->get(n).walkable)
|
||||
@ -922,7 +922,7 @@ s16 Mapgen::findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax) {
|
||||
v3s16 em = vm->m_area.getExtent();
|
||||
u32 i = vm->m_area.index(p2d.X, ymax, p2d.Y);
|
||||
s16 y;
|
||||
|
||||
|
||||
for (y = ymax; y >= ymin; y--) {
|
||||
MapNode &n = vm->m_data[i];
|
||||
if (ndef->get(n).walkable)
|
||||
@ -937,7 +937,7 @@ s16 Mapgen::findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax) {
|
||||
void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax) {
|
||||
if (!heightmap)
|
||||
return;
|
||||
|
||||
|
||||
//TimeTaker t("Mapgen::updateHeightmap", NULL, PRECISION_MICRO);
|
||||
int index = 0;
|
||||
for (s16 z = nmin.Z; z <= nmax.Z; z++) {
|
||||
@ -949,7 +949,7 @@ void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax) {
|
||||
continue;
|
||||
if (y == nmin.Y - 1 && heightmap[index] < nmin.Y)
|
||||
continue;
|
||||
|
||||
|
||||
heightmap[index] = y;
|
||||
}
|
||||
}
|
||||
@ -1040,7 +1040,7 @@ void Mapgen::calcLighting(v3s16 nmin, v3s16 nmax) {
|
||||
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)
|
||||
@ -1103,15 +1103,15 @@ void Mapgen::calcLightingOld(v3s16 nmin, v3s16 nmax) {
|
||||
vm->spreadLight(bank, light_sources, ndef);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////// Mapgen V6 parameter read/write
|
||||
|
||||
|
||||
bool MapgenV6Params::readParams(Settings *settings) {
|
||||
freq_desert = settings->getFloat("mgv6_freq_desert");
|
||||
freq_beach = settings->getFloat("mgv6_freq_beach");
|
||||
|
||||
bool success =
|
||||
bool success =
|
||||
settings->getNoiseParams("mgv6_np_terrain_base", np_terrain_base) &&
|
||||
settings->getNoiseParams("mgv6_np_terrain_higher", np_terrain_higher) &&
|
||||
settings->getNoiseParams("mgv6_np_steepness", np_steepness) &&
|
||||
@ -1125,12 +1125,12 @@ bool MapgenV6Params::readParams(Settings *settings) {
|
||||
settings->getNoiseParams("mgv6_np_apple_trees", np_apple_trees);
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void MapgenV6Params::writeParams(Settings *settings) {
|
||||
settings->setFloat("mgv6_freq_desert", freq_desert);
|
||||
settings->setFloat("mgv6_freq_beach", freq_beach);
|
||||
|
||||
|
||||
settings->setNoiseParams("mgv6_np_terrain_base", np_terrain_base);
|
||||
settings->setNoiseParams("mgv6_np_terrain_higher", np_terrain_higher);
|
||||
settings->setNoiseParams("mgv6_np_steepness", np_steepness);
|
||||
@ -1146,7 +1146,7 @@ void MapgenV6Params::writeParams(Settings *settings) {
|
||||
|
||||
|
||||
bool MapgenV7Params::readParams(Settings *settings) {
|
||||
bool success =
|
||||
bool success =
|
||||
settings->getNoiseParams("mgv7_np_terrain_base", np_terrain_base) &&
|
||||
settings->getNoiseParams("mgv7_np_terrain_alt", np_terrain_alt) &&
|
||||
settings->getNoiseParams("mgv7_np_terrain_persist", np_terrain_persist) &&
|
||||
|
38
src/mapgen.h
38
src/mapgen.h
@ -41,7 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
|
||||
/////////////////// Ore generation flags
|
||||
// Use absolute value of height to determine ore placement
|
||||
#define OREFLAG_ABSHEIGHT 0x01
|
||||
#define OREFLAG_ABSHEIGHT 0x01
|
||||
// Use 3d noise to get density of ore placement, instead of just the position
|
||||
#define OREFLAG_DENSITY 0x02 // not yet implemented
|
||||
// For claylike ore types, place ore if the number of surrounding
|
||||
@ -81,7 +81,7 @@ struct MapgenParams {
|
||||
chunksize = 5;
|
||||
flags = MG_TREES | MG_CAVES | MGV6_BIOME_BLEND;
|
||||
}
|
||||
|
||||
|
||||
virtual bool readParams(Settings *settings) { return true; }
|
||||
virtual void writeParams(Settings *settings) {}
|
||||
virtual ~MapgenParams() {}
|
||||
@ -95,7 +95,7 @@ public:
|
||||
int id;
|
||||
ManualMapVoxelManipulator *vm;
|
||||
INodeDefManager *ndef;
|
||||
|
||||
|
||||
s16 *heightmap;
|
||||
u8 *biomemap;
|
||||
v3s16 csize;
|
||||
@ -153,18 +153,18 @@ public:
|
||||
s16 height_max;
|
||||
u8 ore_param2; // to set node-specific attributes
|
||||
u32 flags; // attributes for this ore
|
||||
float nthresh; // threshhold for noise at which an ore is placed
|
||||
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;
|
||||
np = NULL;
|
||||
noise = NULL;
|
||||
}
|
||||
|
||||
|
||||
virtual ~Ore();
|
||||
|
||||
|
||||
void resolveNodeNames(INodeDefManager *ndef);
|
||||
void placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
|
||||
virtual void generate(ManualMapVoxelManipulator *vm, int seed,
|
||||
@ -199,7 +199,7 @@ struct CutoffData {
|
||||
//v3s16 p;
|
||||
//v3s16 size;
|
||||
//s16 height;
|
||||
|
||||
|
||||
CutoffData(s16 x, s16 y, s16 z, s16 h) {
|
||||
p = v3s16(x, y, z);
|
||||
height = h;
|
||||
@ -210,25 +210,25 @@ struct CutoffData {
|
||||
class Decoration {
|
||||
public:
|
||||
INodeDefManager *ndef;
|
||||
|
||||
|
||||
int mapseed;
|
||||
std::string place_on_name;
|
||||
content_t c_place_on;
|
||||
s16 sidelen;
|
||||
float fill_ratio;
|
||||
NoiseParams *np;
|
||||
|
||||
|
||||
std::set<u8> biomes;
|
||||
//std::list<CutoffData> cutoffs;
|
||||
//JMutex cutoff_mutex;
|
||||
|
||||
Decoration();
|
||||
virtual ~Decoration();
|
||||
|
||||
|
||||
virtual void resolveNodeNames(INodeDefManager *ndef);
|
||||
void placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
|
||||
void placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
|
||||
|
||||
|
||||
virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) = 0;
|
||||
virtual int getHeight() = 0;
|
||||
virtual std::string getName() = 0;
|
||||
@ -243,12 +243,12 @@ public:
|
||||
s16 deco_height;
|
||||
s16 deco_height_max;
|
||||
s16 nspawnby;
|
||||
|
||||
|
||||
std::vector<std::string> decolist_names;
|
||||
std::vector<content_t> c_decolist;
|
||||
|
||||
~DecoSimple() {}
|
||||
|
||||
|
||||
void resolveNodeNames(INodeDefManager *ndef);
|
||||
virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
|
||||
virtual int getHeight();
|
||||
@ -265,7 +265,7 @@ public:
|
||||
class DecoSchematic : public Decoration {
|
||||
public:
|
||||
std::string filename;
|
||||
|
||||
|
||||
std::vector<std::string> *node_names;
|
||||
std::vector<content_t> c_nodes;
|
||||
std::map<std::string, std::string> replacements;
|
||||
@ -278,18 +278,18 @@ public:
|
||||
|
||||
DecoSchematic();
|
||||
~DecoSchematic();
|
||||
|
||||
|
||||
void resolveNodeNames(INodeDefManager *ndef);
|
||||
virtual void generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
|
||||
virtual int getHeight();
|
||||
virtual std::string getName();
|
||||
|
||||
|
||||
void blitToVManip(v3s16 p, ManualMapVoxelManipulator *vm,
|
||||
Rotation rot, bool force_placement);
|
||||
|
||||
|
||||
bool loadSchematicFile();
|
||||
void saveSchematicFile(INodeDefManager *ndef);
|
||||
|
||||
|
||||
bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
|
||||
void placeStructure(Map *map, v3s16 p);
|
||||
void applyProbabilities(v3s16 p0,
|
||||
|
Loading…
Reference in New Issue
Block a user