forked from Mirrorlandia_minetest/minetest
EmergeManager: Fix Lua mapgen override param handling
This commit is contained in:
parent
bbae8eb751
commit
83cc882335
@ -181,8 +181,15 @@ void EmergeManager::initMapgens(MapgenParams *mgparams) {
|
|||||||
|
|
||||||
// Apply mapgen parameter overrides from Lua
|
// Apply mapgen parameter overrides from Lua
|
||||||
if (luaoverride_params) {
|
if (luaoverride_params) {
|
||||||
if (luaoverride_params_modified & MGPARAMS_SET_MGNAME)
|
if (luaoverride_params_modified & MGPARAMS_SET_MGNAME) {
|
||||||
mgparams->mg_name = luaoverride_params->mg_name;
|
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)
|
if (luaoverride_params_modified & MGPARAMS_SET_SEED)
|
||||||
mgparams->seed = luaoverride_params->seed;
|
mgparams->seed = luaoverride_params->seed;
|
||||||
@ -202,18 +209,47 @@ void EmergeManager::initMapgens(MapgenParams *mgparams) {
|
|||||||
// Create the mapgens
|
// Create the mapgens
|
||||||
this->params = mgparams;
|
this->params = mgparams;
|
||||||
for (size_t i = 0; i != emergethread.size(); i++) {
|
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) {
|
if (!mg) {
|
||||||
infostream << "EmergeManager: falling back to mapgen v6" << std::endl;
|
infostream << "EmergeManager: Falling back to Mapgen V6" << std::endl;
|
||||||
delete params;
|
|
||||||
params = createMapgenParams("v6");
|
params = setMapgenType(params, "v6");
|
||||||
mg = createMapgen("v6", 0, params);
|
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);
|
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() {
|
Mapgen *EmergeManager::getCurrentMapgen() {
|
||||||
for (unsigned int i = 0; i != emergethread.size(); i++) {
|
for (unsigned int i = 0; i != emergethread.size(); i++) {
|
||||||
if (emergethread[i]->IsSameThread())
|
if (emergethread[i]->IsSameThread())
|
||||||
@ -229,6 +265,7 @@ void EmergeManager::triggerAllThreads() {
|
|||||||
emergethread[i]->trigger();
|
emergethread[i]->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool EmergeManager::enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate) {
|
bool EmergeManager::enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate) {
|
||||||
std::map<v3s16, BlockEmergeData *>::const_iterator iter;
|
std::map<v3s16, BlockEmergeData *>::const_iterator iter;
|
||||||
BlockEmergeData *bedata;
|
BlockEmergeData *bedata;
|
||||||
@ -286,7 +323,7 @@ bool EmergeManager::enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate
|
|||||||
int EmergeManager::getGroundLevelAtPoint(v2s16 p) {
|
int EmergeManager::getGroundLevelAtPoint(v2s16 p) {
|
||||||
if (mapgen.size() == 0 || !mapgen[0]) {
|
if (mapgen.size() == 0 || !mapgen[0]) {
|
||||||
errorstream << "EmergeManager: getGroundLevelAtPoint() called"
|
errorstream << "EmergeManager: getGroundLevelAtPoint() called"
|
||||||
" before mapgen initialized" << std::endl;
|
" before mapgen initialized" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -483,7 +520,7 @@ void *EmergeThread::Thread() {
|
|||||||
MapBlock *block = NULL;
|
MapBlock *block = NULL;
|
||||||
std::map<v3s16, MapBlock *> modified_blocks;
|
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);
|
ScopeProfiler sp(g_profiler, "EmergeThread: Mapgen::makeChunk", SPT_AVG);
|
||||||
TimeTaker t("mapgen::make_block()");
|
TimeTaker t("mapgen::make_block()");
|
||||||
|
@ -112,6 +112,7 @@ public:
|
|||||||
~EmergeManager();
|
~EmergeManager();
|
||||||
|
|
||||||
void initMapgens(MapgenParams *mgparams);
|
void initMapgens(MapgenParams *mgparams);
|
||||||
|
MapgenParams *setMapgenType(MapgenParams *mgparams, std::string newname);
|
||||||
Mapgen *getCurrentMapgen();
|
Mapgen *getCurrentMapgen();
|
||||||
Mapgen *createMapgen(std::string mgname, int mgid,
|
Mapgen *createMapgen(std::string mgname, int mgid,
|
||||||
MapgenParams *mgparams);
|
MapgenParams *mgparams);
|
||||||
|
Loading…
Reference in New Issue
Block a user