Skip to content

Commit

Permalink
Write common mapgen params to map_meta.txt on world initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
kwolekr committed Jan 28, 2015
1 parent 80a7408 commit ad690c4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/emerge.cpp
Expand Up @@ -380,8 +380,11 @@ void EmergeManager::loadParamsFromSettings(Settings *settings)

delete params.sparams;
params.sparams = createMapgenParams(params.mg_name);
if (params.sparams)

if (params.sparams) {
params.sparams->readParams(g_settings);
params.sparams->readParams(settings);
}
}


Expand Down
37 changes: 30 additions & 7 deletions src/subgame.cpp
Expand Up @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "porting.h"
#include "filesys.h"
#include "settings.h"
#include "main.h"
#include "log.h"
#include "strfnd.h"
#ifndef SERVER
Expand Down Expand Up @@ -265,15 +266,37 @@ std::vector<WorldSpec> getAvailableWorlds()

bool initializeWorld(const std::string &path, const std::string &gameid)
{
infostream<<"Initializing world at "<<path<<std::endl;
infostream << "Initializing world at " << path << std::endl;

fs::CreateAllDirs(path);

// Create world.mt if does not already exist
std::string worldmt_path = path + DIR_DELIM + "world.mt";
if(!fs::PathExists(worldmt_path)){
infostream<<"Creating world.mt ("<<worldmt_path<<")"<<std::endl;
fs::CreateAllDirs(path);
std::string worldmt_path = path + DIR_DELIM "world.mt";
if (!fs::PathExists(worldmt_path)) {
std::ostringstream ss(std::ios_base::binary);
ss << "gameid = " << gameid << "\nbackend = sqlite3\n";
if (!fs::safeWriteToFile(worldmt_path, ss.str()))
return false;

infostream << "Wrote world.mt (" << worldmt_path << ")" << std::endl;
}

// Create map_meta.txt if does not already exist
std::string mapmeta_path = path + DIR_DELIM "map_meta.txt";
if (!fs::PathExists(mapmeta_path)) {
std::ostringstream ss(std::ios_base::binary);
ss<<"gameid = "<<gameid<< "\nbackend = sqlite3\n";
fs::safeWriteToFile(worldmt_path, ss.str());
ss
<< "mg_name = " << g_settings->get("mg_name")
<< "\nseed = " << g_settings->get("fixed_map_seed")
<< "\nchunksize = " << g_settings->get("chunksize")
<< "\nwater_level = " << g_settings->get("water_level")
<< "\nmg_flags = " << g_settings->get("mg_flags")
<< "\n[end_of_params]\n";
if (!fs::safeWriteToFile(mapmeta_path, ss.str()))
return false;

infostream << "Wrote map_meta.txt (" << mapmeta_path << ")" << std::endl;
}

return true;
}

2 comments on commit ad690c4

@ShadowNinja
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are only a few chosen parameters written? You miss things like mgv6_freq_beach and mg_biome_np_heat. Also, any new parameters have to be added in two places now. You should use writeParamsToSettings or similar.

@kwolekr
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to include a ton of additional dependencies.
Not having these parameters written doesn't matter much until you're able to edit those settings from within the user interface. Mapgen-specific parameters are a bit too out-of-scope here IMO

Please sign in to comment.