Finish and clean up mapgen configuration
parent
45cf32afc5
commit
631a835e07
|
@ -78,7 +78,7 @@ BiomeDefManager::BiomeDefManager(IGameDef *gamedef) {
|
||||||
|
|
||||||
|
|
||||||
BiomeDefManager::~BiomeDefManager() {
|
BiomeDefManager::~BiomeDefManager() {
|
||||||
for (int i = 0; i != bgroups.size(); i++)
|
for (unsigned int i = 0; i != bgroups.size(); i++)
|
||||||
delete bgroups[i];
|
delete bgroups[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +96,7 @@ Biome *BiomeDefManager::createBiome(BiomeTerrainType btt) {
|
||||||
case BIOME_TERRAIN_FLAT:
|
case BIOME_TERRAIN_FLAT:
|
||||||
return new BiomeSuperflat;
|
return new BiomeSuperflat;
|
||||||
}
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,7 +117,7 @@ void BiomeDefManager::addBiomeGroup(float freq) {
|
||||||
void BiomeDefManager::addBiome(Biome *b) {
|
void BiomeDefManager::addBiome(Biome *b) {
|
||||||
std::vector<Biome *> *bgroup;
|
std::vector<Biome *> *bgroup;
|
||||||
|
|
||||||
if (b->groupid >= bgroups.size()) {
|
if ((unsigned int)b->groupid >= bgroups.size()) {
|
||||||
errorstream << "BiomeDefManager: attempted to add biome '" << b->name
|
errorstream << "BiomeDefManager: attempted to add biome '" << b->name
|
||||||
<< "' to nonexistent biome group " << b->groupid << std::endl;
|
<< "' to nonexistent biome group " << b->groupid << std::endl;
|
||||||
return;
|
return;
|
||||||
|
@ -131,7 +132,6 @@ void BiomeDefManager::addBiome(Biome *b) {
|
||||||
|
|
||||||
|
|
||||||
void BiomeDefManager::addDefaultBiomes() {
|
void BiomeDefManager::addDefaultBiomes() {
|
||||||
std::vector<Biome *> *bgroup;
|
|
||||||
Biome *b;
|
Biome *b;
|
||||||
|
|
||||||
b = new Biome;
|
b = new Biome;
|
||||||
|
|
|
@ -153,7 +153,6 @@ void set_default_settings(Settings *settings)
|
||||||
|
|
||||||
settings->setDefault("profiler_print_interval", "0");
|
settings->setDefault("profiler_print_interval", "0");
|
||||||
settings->setDefault("enable_mapgen_debug_info", "false");
|
settings->setDefault("enable_mapgen_debug_info", "false");
|
||||||
settings->setDefault("use_mapgen_version", "6");
|
|
||||||
settings->setDefault("active_object_send_range_blocks", "3");
|
settings->setDefault("active_object_send_range_blocks", "3");
|
||||||
settings->setDefault("active_block_range", "2");
|
settings->setDefault("active_block_range", "2");
|
||||||
//settings->setDefault("max_simultaneous_block_sends_per_client", "1");
|
//settings->setDefault("max_simultaneous_block_sends_per_client", "1");
|
||||||
|
@ -164,16 +163,37 @@ void set_default_settings(Settings *settings)
|
||||||
settings->setDefault("max_block_generate_distance", "7");
|
settings->setDefault("max_block_generate_distance", "7");
|
||||||
settings->setDefault("time_send_interval", "5");
|
settings->setDefault("time_send_interval", "5");
|
||||||
settings->setDefault("time_speed", "72");
|
settings->setDefault("time_speed", "72");
|
||||||
settings->setDefault("default_water_level", "1");
|
|
||||||
settings->setDefault("server_unload_unused_data_timeout", "29");
|
settings->setDefault("server_unload_unused_data_timeout", "29");
|
||||||
settings->setDefault("server_map_save_interval", "5.3");
|
settings->setDefault("server_map_save_interval", "5.3");
|
||||||
settings->setDefault("full_block_send_enable_min_time_from_building", "2.0");
|
settings->setDefault("full_block_send_enable_min_time_from_building", "2.0");
|
||||||
settings->setDefault("dedicated_server_step", "0.1");
|
settings->setDefault("dedicated_server_step", "0.1");
|
||||||
settings->setDefault("ignore_world_load_errors", "false");
|
settings->setDefault("ignore_world_load_errors", "false");
|
||||||
settings->setDefault("mgv6_use_smooth_biome_trans", "true"); //temporary
|
|
||||||
settings->setDefault("congestion_control_aim_rtt", "0.2");
|
settings->setDefault("congestion_control_aim_rtt", "0.2");
|
||||||
settings->setDefault("congestion_control_max_rate", "400");
|
settings->setDefault("congestion_control_max_rate", "400");
|
||||||
settings->setDefault("congestion_control_min_rate", "10");
|
settings->setDefault("congestion_control_min_rate", "10");
|
||||||
settings->setDefault("remote_media", "");
|
settings->setDefault("remote_media", "");
|
||||||
|
|
||||||
|
//mapgen related things
|
||||||
|
settings->setDefault("mg_version", "6");
|
||||||
|
settings->setDefault("water_level", "1");
|
||||||
|
settings->setDefault("chunksize", "5");
|
||||||
|
settings->setDefault("mg_flags", "19");
|
||||||
|
settings->setDefault("mgv6_freq_desert", "0.45");
|
||||||
|
settings->setDefault("mgv6_freq_beach", "0.15");
|
||||||
|
|
||||||
|
settings->setDefault("mgv6_np_terrain_base", "-4, 20, (250.0, 250, 250), 82341, 5, 0.6");
|
||||||
|
settings->setDefault("mgv6_np_terrain_higher", "20, 16, (500, 500, 500), 85039, 5, 0.6");
|
||||||
|
settings->setDefault("mgv6_np_steepness", "0.85, 0.5, (125, 125, 125), -932, 5, 0.7");
|
||||||
|
settings->setDefault("mgv6_np_height_select", "0.5, 1, (250, 250, 250), 4213, 5, 0.69");
|
||||||
|
settings->setDefault("mgv6_np_trees", "0, 1, (125, 125, 125), 2, 4, 0.66");
|
||||||
|
settings->setDefault("mgv6_np_mud", "4, 2, (200, 200, 200), 91013, 3, 0.55");
|
||||||
|
settings->setDefault("mgv6_np_beach", "0, 1, (250, 250, 250), 59420, 3, 0.50");
|
||||||
|
settings->setDefault("mgv6_np_biome", "0, 1, (250, 250, 250), 9130, 3, 0.50");
|
||||||
|
settings->setDefault("mgv6_np_cave", "6, 6, (250, 250, 250), 34329, 3, 0.50");
|
||||||
|
|
||||||
|
settings->setDefault("mgv7_np_terrain", "10, 12, (350, 350, 350), 82341, 5, 0.6");
|
||||||
|
settings->setDefault("mgv7_np_bgroup", "0.5, 0.3125, (350, 350, 350), 5923, 2, 0.6");
|
||||||
|
settings->setDefault("mgv7_np_heat", "25, 50, (500, 500, 500), 35293, 1, 0");
|
||||||
|
settings->setDefault("mgv7_np_humidity", "50, 31.25, (750, 750, 750), 12094, 2, 0.6");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
93
src/map.cpp
93
src/map.cpp
|
@ -1993,10 +1993,10 @@ void Map::removeNodeTimer(v3s16 p)
|
||||||
/*
|
/*
|
||||||
ServerMap
|
ServerMap
|
||||||
*/
|
*/
|
||||||
|
ServerMap::ServerMap(std::string savedir, IGameDef *gamedef):
|
||||||
ServerMap::ServerMap(std::string savedir, IGameDef *gamedef, EmergeManager *emerge):
|
|
||||||
Map(dout_server, gamedef),
|
Map(dout_server, gamedef),
|
||||||
m_seed(0),
|
m_seed(0),
|
||||||
|
m_emerge(NULL),
|
||||||
m_map_metadata_changed(true),
|
m_map_metadata_changed(true),
|
||||||
m_database(NULL),
|
m_database(NULL),
|
||||||
m_database_read(NULL),
|
m_database_read(NULL),
|
||||||
|
@ -2004,26 +2004,22 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef, EmergeManager *emer
|
||||||
{
|
{
|
||||||
verbosestream<<__FUNCTION_NAME<<std::endl;
|
verbosestream<<__FUNCTION_NAME<<std::endl;
|
||||||
|
|
||||||
m_emerge = emerge;
|
|
||||||
|
|
||||||
//m_chunksize = 8; // Takes a few seconds
|
//m_chunksize = 8; // Takes a few seconds
|
||||||
|
|
||||||
|
m_mgparams = MapgenParams::getParamsFromSettings(g_settings);
|
||||||
|
if (!m_mgparams)
|
||||||
|
m_mgparams = new MapgenV6Params();
|
||||||
|
|
||||||
|
m_seed = m_mgparams->seed;
|
||||||
|
|
||||||
if (g_settings->get("fixed_map_seed").empty())
|
if (g_settings->get("fixed_map_seed").empty())
|
||||||
{
|
{
|
||||||
m_seed = (((u64)(myrand()%0xffff)<<0)
|
m_seed = (((u64)(myrand()%0xffff)<<0)
|
||||||
+ ((u64)(myrand()%0xffff)<<16)
|
+ ((u64)(myrand()%0xffff)<<16)
|
||||||
+ ((u64)(myrand()%0xffff)<<32)
|
+ ((u64)(myrand()%0xffff)<<32)
|
||||||
+ ((u64)(myrand()&0xffff)<<48));
|
+ ((u64)(myrand()&0xffff)<<48));
|
||||||
|
m_mgparams->seed = m_seed;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
m_seed = g_settings->getU64("fixed_map_seed");
|
|
||||||
}
|
|
||||||
//emerge->params.seed = m_seed;
|
|
||||||
//emerge->params.water_level = g_settings->getS16("default_water_level");
|
|
||||||
//mapgen version
|
|
||||||
//chunksize
|
|
||||||
//noiseparams
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Experimental and debug stuff
|
Experimental and debug stuff
|
||||||
|
@ -2057,6 +2053,10 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef, EmergeManager *emer
|
||||||
// Load map metadata (seed, chunksize)
|
// Load map metadata (seed, chunksize)
|
||||||
loadMapMeta();
|
loadMapMeta();
|
||||||
}
|
}
|
||||||
|
catch(SettingNotFoundException &e){
|
||||||
|
infostream<<"ServerMap: Some metadata not found."
|
||||||
|
<<" Using default settings."<<std::endl;
|
||||||
|
}
|
||||||
catch(FileNotGoodException &e){
|
catch(FileNotGoodException &e){
|
||||||
infostream<<"WARNING: Could not load map metadata"
|
infostream<<"WARNING: Could not load map metadata"
|
||||||
//<<" Disabling chunk-based generator."
|
//<<" Disabling chunk-based generator."
|
||||||
|
@ -3079,25 +3079,38 @@ void ServerMap::saveMapMeta()
|
||||||
|
|
||||||
Settings params;
|
Settings params;
|
||||||
|
|
||||||
params.setS16("mg_version", m_emerge->mg_version);
|
params.setS16("mg_version", m_emerge->params->mg_version);
|
||||||
|
|
||||||
params.setU64("seed", m_emerge->params->seed);
|
params.setU64("seed", m_emerge->params->seed);
|
||||||
params.setS16("water_level", m_emerge->params->water_level);
|
params.setS16("water_level", m_emerge->params->water_level);
|
||||||
params.setS16("chunksize", m_emerge->params->chunksize);
|
params.setS16("chunksize", m_emerge->params->chunksize);
|
||||||
params.setS32("flags", m_emerge->params->flags);
|
params.setS32("mg_flags", m_emerge->params->flags);
|
||||||
switch (m_emerge->mg_version) {
|
switch (m_emerge->params->mg_version) {
|
||||||
case 6:
|
case 6:
|
||||||
{
|
{
|
||||||
MapgenV6Params *v6params = m_emerge->params;
|
MapgenV6Params *v6params = (MapgenV6Params *)m_emerge->params;
|
||||||
|
|
||||||
params.setFloat("freq_desert", v6params->freq_desert);
|
|
||||||
params.setFloat("freq_beach", v6params->freq_beach);
|
|
||||||
|
|
||||||
|
params.setFloat("mgv6_freq_desert", v6params->freq_desert);
|
||||||
|
params.setFloat("mgv6_freq_beach", v6params->freq_beach);
|
||||||
|
params.setNoiseParams("mgv6_np_terrain_base", v6params->np_terrain_base);
|
||||||
|
params.setNoiseParams("mgv6_np_terrain_higher", v6params->np_terrain_higher);
|
||||||
|
params.setNoiseParams("mgv6_np_steepness", v6params->np_steepness);
|
||||||
|
params.setNoiseParams("mgv6_np_height_select", v6params->np_height_select);
|
||||||
|
params.setNoiseParams("mgv6_np_trees", v6params->np_trees);
|
||||||
|
params.setNoiseParams("mgv6_np_mud", v6params->np_mud);
|
||||||
|
params.setNoiseParams("mgv6_np_beach", v6params->np_beach);
|
||||||
|
params.setNoiseParams("mgv6_np_biome", v6params->np_biome);
|
||||||
|
params.setNoiseParams("mgv6_np_cave", v6params->np_cave);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 7:
|
case 7:
|
||||||
{
|
{
|
||||||
MapgenV7Params *v7params = m_emerge->params;
|
MapgenV7Params *v7params = (MapgenV7Params *)m_emerge->params;
|
||||||
|
|
||||||
|
params.setNoiseParams("mgv7_np_terrain", v7params->np_terrain);
|
||||||
|
params.setNoiseParams("mgv7_np_bgroup", v7params->np_bgroup);
|
||||||
|
params.setNoiseParams("mgv7_np_heat", v7params->np_heat);
|
||||||
|
params.setNoiseParams("mgv7_np_humidity", v7params->np_humidity);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -3142,36 +3155,18 @@ void ServerMap::loadMapMeta()
|
||||||
params.parseConfigLine(line);
|
params.parseConfigLine(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_emerge->mg_version = params.getS16("mg_version");
|
MapgenParams *mgparams = MapgenParams::getParamsFromSettings(¶ms);
|
||||||
m_emerge->setMapgenParams();
|
if (mgparams) {
|
||||||
|
if (m_mgparams)
|
||||||
m_emerge->params->seed = params.getU64("seed");
|
delete m_mgparams;
|
||||||
m_emerge->params->water_level = params.getS16("water_level");
|
m_mgparams = mgparams;
|
||||||
m_emerge->params->chunksize = params.getS16("chunksize");
|
m_seed = mgparams->seed;
|
||||||
m_emerge->params->flags = params.getS32("flags");
|
} else {
|
||||||
|
if (params.exists("seed")) {
|
||||||
m_seed = m_emerge->params->seed;
|
m_seed = params.getU64("seed");
|
||||||
|
m_mgparams->seed = m_seed;
|
||||||
switch (m_emerge->mg_version) {
|
|
||||||
case 6:
|
|
||||||
{
|
|
||||||
MapgenV6Params *v6params = m_emerge->params;
|
|
||||||
|
|
||||||
v6params->freq_desert = params.getFloat("freq_desert");
|
|
||||||
v6params->freq_beach = params.getFloat("freq_beach");
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case 7:
|
|
||||||
{
|
|
||||||
MapgenV7Params *v6params = m_emerge->params;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
; //complain here
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
verbosestream<<"ServerMap::loadMapMeta(): "<<"seed="<<m_seed<<std::endl;
|
verbosestream<<"ServerMap::loadMapMeta(): "<<"seed="<<m_seed<<std::endl;
|
||||||
}
|
}
|
||||||
|
|
14
src/map.h
14
src/map.h
|
@ -358,7 +358,7 @@ public:
|
||||||
/*
|
/*
|
||||||
savedir: directory to which map data should be saved
|
savedir: directory to which map data should be saved
|
||||||
*/
|
*/
|
||||||
ServerMap(std::string savedir, IGameDef *gamedef, EmergeManager *emerge);
|
ServerMap(std::string savedir, IGameDef *gamedef);
|
||||||
~ServerMap();
|
~ServerMap();
|
||||||
|
|
||||||
s32 mapType() const
|
s32 mapType() const
|
||||||
|
@ -478,11 +478,21 @@ public:
|
||||||
|
|
||||||
u64 getSeed(){ return m_seed; }
|
u64 getSeed(){ return m_seed; }
|
||||||
|
|
||||||
EmergeManager *m_emerge;
|
MapgenParams *getMapgenParams(){ return m_mgparams; }
|
||||||
|
|
||||||
|
void setEmerge(EmergeManager *emerge){ m_emerge = emerge; }
|
||||||
|
|
||||||
|
// Parameters fed to the Mapgen
|
||||||
|
MapgenParams *m_mgparams;
|
||||||
private:
|
private:
|
||||||
// Seed used for all kinds of randomness in generation
|
// Seed used for all kinds of randomness in generation
|
||||||
u64 m_seed;
|
u64 m_seed;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Emerge manager
|
||||||
|
EmergeManager *m_emerge;
|
||||||
|
|
||||||
std::string m_savedir;
|
std::string m_savedir;
|
||||||
bool m_map_saving_enabled;
|
bool m_map_saving_enabled;
|
||||||
|
|
||||||
|
|
211
src/mapgen.cpp
211
src/mapgen.cpp
|
@ -34,19 +34,35 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#include "main.h" // For g_profiler
|
#include "main.h" // For g_profiler
|
||||||
#include "treegen.h"
|
#include "treegen.h"
|
||||||
|
|
||||||
|
/////////////////// Mapgen V6 perlin noise default values
|
||||||
|
NoiseParams nparams_v6_def_terrain_base =
|
||||||
|
{-AVERAGE_MUD_AMOUNT, 20.0, v3f(250.0, 250.0, 250.0), 82341, 5, 0.6};
|
||||||
|
NoiseParams nparams_v6_def_terrain_higher =
|
||||||
|
{20.0, 16.0, v3f(500.0, 500.0, 500.0), 85039, 5, 0.6};
|
||||||
|
NoiseParams nparams_v6_def_steepness =
|
||||||
|
{0.85, 0.5, v3f(125.0, 125.0, 125.0), -932, 5, 0.7};
|
||||||
|
NoiseParams nparams_v6_def_height_select =
|
||||||
|
{0.5, 1.0, v3f(250.0, 250.0, 250.0), 4213, 5, 0.69};
|
||||||
|
NoiseParams nparams_v6_def_trees =
|
||||||
|
{0.0, 1.0, v3f(125.0, 125.0, 125.0), 2, 4, 0.66};
|
||||||
|
NoiseParams nparams_v6_def_mud =
|
||||||
|
{AVERAGE_MUD_AMOUNT, 2.0, v3f(200.0, 200.0, 200.0), 91013, 3, 0.55};
|
||||||
|
NoiseParams nparams_v6_def_beach =
|
||||||
|
{0.0, 1.0, v3f(250.0, 250.0, 250.0), 59420, 3, 0.50};
|
||||||
|
NoiseParams nparams_v6_def_biome =
|
||||||
|
{0.0, 1.0, v3f(250.0, 250.0, 250.0), 9130, 3, 0.50};
|
||||||
|
NoiseParams nparams_v6_def_cave =
|
||||||
|
{6.0, 6.0, v3f(250.0, 250.0, 250.0), 34329, 3, 0.50};
|
||||||
|
|
||||||
|
/////////////////// Mapgen V7 perlin noise default values
|
||||||
/*
|
NoiseParams nparams_v7_def_terrain =
|
||||||
MapgenV7Params mg_def_params_v7 = {
|
{10.0, 12.0, v3f(350., 350., 350.), 82341, 5, 0.6}; //terrain
|
||||||
0,
|
NoiseParams nparams_v7_def_bgroup =
|
||||||
1,
|
{0.5, 1/(2*1.6), v3f(350., 350., 350.), 5923, 2, 0.60}; //0 to 1
|
||||||
5,
|
NoiseParams nparams_v7_def_heat =
|
||||||
MG_TREES | MG_CAVES | MG_DUNGEONS,
|
{25.0, 50.0, v3f(500., 500., 500.), 35293, 1, 0.00}; //-25 to 75
|
||||||
&nparams_v7_def_terrain,
|
NoiseParams nparams_v7_def_humidity =
|
||||||
&nparams_v7_def_bgroup,
|
{50, 100/(2*1.6), v3f(750., 750., 750.), 12094, 2, 0.60}; //0 to 100
|
||||||
&nparams_v7_def_heat,
|
|
||||||
&nparams_v7_def_humidity
|
|
||||||
};*/
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -56,25 +72,18 @@ MapgenV7::MapgenV7(BiomeDefManager *biomedef, int mapgenid, MapgenV7Params *para
|
||||||
this->generating = false;
|
this->generating = false;
|
||||||
this->id = mapgenid;
|
this->id = mapgenid;
|
||||||
this->biomedef = biomedef;
|
this->biomedef = biomedef;
|
||||||
|
this->ndef = biomedef->ndef;
|
||||||
|
|
||||||
this->seed = params->seed;
|
this->seed = (int)params->seed;
|
||||||
this->csize = v3s16(1, 1, 1) * params->chunksize * MAP_BLOCKSIZE; /////////////////get this from config!
|
this->csize = v3s16(1, 1, 1) * params->chunksize * MAP_BLOCKSIZE;
|
||||||
this->water_level = params->water_level;
|
this->water_level = params->water_level;
|
||||||
|
|
||||||
//g_settings->getS16("default_water_level");
|
|
||||||
|
|
||||||
/*
|
|
||||||
this->np_terrain = np_terrain;
|
|
||||||
this->np_bgroup = np_bgroup;
|
|
||||||
this->np_heat = np_heat;
|
|
||||||
this->np_humidity = np_humidity;
|
|
||||||
*/
|
|
||||||
noise_terrain = new Noise(params->np_terrain, seed, csize.X, csize.Y);
|
noise_terrain = new Noise(params->np_terrain, seed, csize.X, csize.Y);
|
||||||
noise_bgroup = new Noise(params->np_bgroup, seed, csize.X, csize.Y);
|
noise_bgroup = new Noise(params->np_bgroup, seed, csize.X, csize.Y);
|
||||||
noise_heat = new Noise(params->np_heat, seed, csize.X, csize.Y);
|
noise_heat = new Noise(params->np_heat, seed, csize.X, csize.Y);
|
||||||
noise_humidity = new Noise(params->np_humidity, seed, csize.X, csize.Y);
|
noise_humidity = new Noise(params->np_humidity, seed, csize.X, csize.Y);
|
||||||
|
|
||||||
this->ndef = biomedef->ndef;
|
|
||||||
n_air = MapNode(ndef->getId("mapgen_air"));
|
n_air = MapNode(ndef->getId("mapgen_air"));
|
||||||
n_water = MapNode(ndef->getId("mapgen_water_source"));
|
n_water = MapNode(ndef->getId("mapgen_water_source"));
|
||||||
n_lava = MapNode(ndef->getId("mapgen_lava_source"));
|
n_lava = MapNode(ndef->getId("mapgen_lava_source"));
|
||||||
|
@ -200,12 +209,33 @@ void MapgenV7::updateLighting(v3s16 nmin, v3s16 nmax) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EmergeManager::EmergeManager(IGameDef *gamedef, int mg_version) {
|
Biome *MapgenV7::getBiomeAtPoint(v3s16 p) {
|
||||||
this->mg_version = mg_version;
|
float bgroup = NoisePerlin2D(noise_bgroup->np, p.X, p.Y, seed);
|
||||||
this->biomedef = new BiomeDefManager(gamedef);
|
float heat = NoisePerlin2D(noise_heat->np, p.X, p.Y, seed);
|
||||||
|
float humidity = NoisePerlin2D(noise_humidity->np, p.X, p.Y, seed);
|
||||||
|
return biomedef->getBiome(bgroup, heat, humidity);
|
||||||
|
}
|
||||||
|
|
||||||
this->params = NULL;
|
|
||||||
setMapgenParams();
|
//FIXME: This assumes y == 0, that is, always in a non-hell/non-sky biome
|
||||||
|
int MapgenV7::getGroundLevelAtPoint(v2s16 p) {
|
||||||
|
float terrain = NoisePerlin2D(noise_terrain->np, p.X, p.Y, seed);
|
||||||
|
Biome *biome = getBiomeAtPoint(v3s16(p.X, p.Y, 0));
|
||||||
|
return biome->getSurfaceHeight(terrain);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////// Emerge Manager ////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
EmergeManager::EmergeManager(IGameDef *gamedef, BiomeDefManager *bdef,
|
||||||
|
MapgenParams *mgparams) {
|
||||||
|
//the order of these assignments is pretty important
|
||||||
|
this->biomedef = bdef ? bdef : new BiomeDefManager(gamedef);
|
||||||
|
this->params = mgparams;
|
||||||
|
this->mapgen = NULL;
|
||||||
|
this->mapgen = getMapgen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -217,59 +247,33 @@ EmergeManager::~EmergeManager() {
|
||||||
|
|
||||||
Mapgen *EmergeManager::getMapgen() {
|
Mapgen *EmergeManager::getMapgen() {
|
||||||
if (!mapgen) {
|
if (!mapgen) {
|
||||||
switch (mg_version) {
|
switch (params->mg_version) {
|
||||||
case 6:
|
case 6:
|
||||||
mapgen = new MapgenV6(0, params);
|
mapgen = new MapgenV6(0, (MapgenV6Params *)params);
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
mapgen = new MapgenV7(biomedef, 0, params);
|
mapgen = new MapgenV7(biomedef, 0, (MapgenV7Params *)params);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
errorstream << "EmergeManager: Unsupported mapgen version "
|
errorstream << "EmergeManager: Unsupported mapgen version "
|
||||||
<< mg_version << ", falling back to V6" << std::endl;
|
<< params->mg_version << ", falling back to V6" << std::endl;
|
||||||
mg_version = 6;
|
params->mg_version = 6;
|
||||||
mapgen = new MapgenV6(0, mgv6params);
|
mapgen = new MapgenV6(0, (MapgenV6Params *)params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mapgen;
|
return mapgen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void EmergeManager::setMapgenParams() {
|
|
||||||
if (params)
|
|
||||||
delete params;
|
|
||||||
|
|
||||||
switch (mg_version) {
|
|
||||||
case 6:
|
|
||||||
params = new MapgenV6Params();
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
params = new MapgenV7Params();
|
|
||||||
break;
|
|
||||||
default: //////do something here!
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void EmergeManager::addBlockToQueue() {
|
void EmergeManager::addBlockToQueue() {
|
||||||
|
//STUB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Biome *EmergeManager::getBiomeAtPoint(v3s16 p) {
|
|
||||||
float bgroup = NoisePerlin2D(np_bgroup, p.X, p.Y, seed);
|
|
||||||
float heat = NoisePerlin2D(np_heat, p.X, p.Y, seed);
|
|
||||||
float humidity = NoisePerlin2D(np_humidity, p.X, p.Y, seed);
|
|
||||||
return biomedef->getBiome(bgroup, heat, humidity);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//FIXME: This assumes y == 0, that is, always in a non-hell/non-sky biome
|
|
||||||
int EmergeManager::getGroundLevelAtPoint(v2s16 p) {
|
int EmergeManager::getGroundLevelAtPoint(v2s16 p) {
|
||||||
float terrain = NoisePerlin2D(np_terrain, p.X, p.Y, seed);
|
if (!mapgen)
|
||||||
Biome *biome = getBiomeAtPoint(v3s16(p.X, p.Y, 0));
|
return 0;
|
||||||
return biome->getSurfaceHeight(terrain);
|
return mapgen->getGroundLevelAtPoint(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -283,18 +287,93 @@ bool EmergeManager::isBlockUnderground(v3s16 blockpos) {
|
||||||
|
|
||||||
//yuck, but then again, should i bother being accurate?
|
//yuck, but then again, should i bother being accurate?
|
||||||
//the height of the nodes in a single block is quite variable
|
//the height of the nodes in a single block is quite variable
|
||||||
return blockpos.Y * (MAP_BLOCKSIZE + 1) <= water_level;
|
return blockpos.Y * (MAP_BLOCKSIZE + 1) <= params->water_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
u32 EmergeManager::getBlockSeed(v3s16 p) {
|
u32 EmergeManager::getBlockSeed(v3s16 p) {
|
||||||
return (u32)(seed & 0xFFFFFFFF) +
|
return (u32)(params->seed & 0xFFFFFFFF) +
|
||||||
p.Z * 38134234 +
|
p.Z * 38134234 +
|
||||||
p.Y * 42123 +
|
p.Y * 42123 +
|
||||||
p.Y * 23;
|
p.Y * 23;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MapgenParams *MapgenParams::createMapgenParams(int mgver) {
|
||||||
|
switch (mgver) {
|
||||||
|
case 6:
|
||||||
|
return new MapgenV6Params();
|
||||||
|
case 7:
|
||||||
|
return new MapgenV7Params();
|
||||||
|
default: //instead of complaining, default to 6
|
||||||
|
return new MapgenV6Params();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MapgenParams *MapgenParams::getParamsFromSettings(Settings *settings) {
|
||||||
|
int mg_version = settings->getS16("mg_version");
|
||||||
|
MapgenParams *mgparams = MapgenParams::createMapgenParams(mg_version);
|
||||||
|
mgparams->mg_version = mg_version;
|
||||||
|
mgparams->seed = settings->getU64(settings == g_settings ? "fixed_map_seed" : "seed");
|
||||||
|
mgparams->water_level = settings->getS16("water_level");
|
||||||
|
mgparams->chunksize = settings->getS16("chunksize");
|
||||||
|
mgparams->flags = settings->getS32("mg_flags");
|
||||||
|
|
||||||
|
switch (mg_version) {
|
||||||
|
case 6:
|
||||||
|
{
|
||||||
|
MapgenV6Params *v6params = (MapgenV6Params *)mgparams;
|
||||||
|
|
||||||
|
v6params->freq_desert = settings->getFloat("mgv6_freq_desert");
|
||||||
|
v6params->freq_beach = settings->getFloat("mgv6_freq_beach");
|
||||||
|
v6params->np_terrain_base = settings->getNoiseParams("mgv6_np_terrain_base");
|
||||||
|
v6params->np_terrain_higher = settings->getNoiseParams("mgv6_np_terrain_higher");
|
||||||
|
v6params->np_steepness = settings->getNoiseParams("mgv6_np_steepness");
|
||||||
|
v6params->np_height_select = settings->getNoiseParams("mgv6_np_height_select");
|
||||||
|
v6params->np_trees = settings->getNoiseParams("mgv6_np_trees");
|
||||||
|
v6params->np_mud = settings->getNoiseParams("mgv6_np_mud");
|
||||||
|
v6params->np_beach = settings->getNoiseParams("mgv6_np_beach");
|
||||||
|
v6params->np_biome = settings->getNoiseParams("mgv6_np_biome");
|
||||||
|
v6params->np_cave = settings->getNoiseParams("mgv6_np_cave");
|
||||||
|
|
||||||
|
if (!v6params->np_terrain_base || !v6params->np_terrain_higher ||
|
||||||
|
!v6params->np_steepness || !v6params->np_height_select ||
|
||||||
|
!v6params->np_trees || !v6params->np_mud ||
|
||||||
|
!v6params->np_beach || !v6params->np_biome || !v6params->np_cave) {
|
||||||
|
delete mgparams;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 7:
|
||||||
|
{
|
||||||
|
MapgenV7Params *v7params = (MapgenV7Params *)mgparams;
|
||||||
|
|
||||||
|
v7params->np_terrain = settings->getNoiseParams("mgv7_np_terrain");
|
||||||
|
v7params->np_bgroup = settings->getNoiseParams("mgv7_np_bgroup");
|
||||||
|
v7params->np_heat = settings->getNoiseParams("mgv7_np_heat");
|
||||||
|
v7params->np_humidity = settings->getNoiseParams("mgv7_np_humidity");
|
||||||
|
|
||||||
|
if (!v7params->np_terrain || !v7params->np_bgroup ||
|
||||||
|
!v7params->np_heat || !v7params->np_humidity) {
|
||||||
|
delete mgparams;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
delete mgparams;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mgparams;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////// legacy static functions for farmesh
|
/////////////////////////////////// legacy static functions for farmesh
|
||||||
|
|
||||||
|
|
||||||
|
|
129
src/mapgen.h
129
src/mapgen.h
|
@ -25,6 +25,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#include "gamedef.h"
|
#include "gamedef.h"
|
||||||
#include "mapnode.h"
|
#include "mapnode.h"
|
||||||
#include "noise.h"
|
#include "noise.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
|
/////////////////// Mapgen flags
|
||||||
|
#define MG_TREES 0x01
|
||||||
|
#define MG_CAVES 0x02
|
||||||
|
#define MG_DUNGEONS 0x04
|
||||||
|
#define MGV6_FORESTS 0x08
|
||||||
|
#define MGV6_BIOME_BLEND 0x10
|
||||||
|
|
||||||
|
#define AVERAGE_MUD_AMOUNT 4
|
||||||
|
|
||||||
class BiomeDefManager;
|
class BiomeDefManager;
|
||||||
class Biome;
|
class Biome;
|
||||||
|
@ -35,6 +45,20 @@ class ManualMapVoxelManipulator;
|
||||||
class VoxelManipulator;
|
class VoxelManipulator;
|
||||||
class INodeDefManager;
|
class INodeDefManager;
|
||||||
|
|
||||||
|
extern NoiseParams nparams_v6_def_terrain_base;
|
||||||
|
extern NoiseParams nparams_v6_def_terrain_higher;
|
||||||
|
extern NoiseParams nparams_v6_def_steepness;
|
||||||
|
extern NoiseParams nparams_v6_def_height_select;
|
||||||
|
extern NoiseParams nparams_v6_def_trees;
|
||||||
|
extern NoiseParams nparams_v6_def_mud;
|
||||||
|
extern NoiseParams nparams_v6_def_beach;
|
||||||
|
extern NoiseParams nparams_v6_def_biome;
|
||||||
|
extern NoiseParams nparams_v6_def_cave;
|
||||||
|
|
||||||
|
extern NoiseParams nparams_v7_def_terrain;
|
||||||
|
extern NoiseParams nparams_v7_def_bgroup;
|
||||||
|
extern NoiseParams nparams_v7_def_heat;
|
||||||
|
extern NoiseParams nparams_v7_def_humidity;
|
||||||
|
|
||||||
enum BiomeType
|
enum BiomeType
|
||||||
{
|
{
|
||||||
|
@ -58,58 +82,24 @@ struct BlockMakeData {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/////////////////// Mapgen flags
|
|
||||||
#define MG_TREES 0x01
|
|
||||||
#define MG_CAVES 0x02
|
|
||||||
#define MG_DUNGEONS 0x04
|
|
||||||
#define MGV6_FORESTS 0x08
|
|
||||||
#define MGV6_BIOME_BLEND 0x10
|
|
||||||
|
|
||||||
#define AVERAGE_MUD_AMOUNT 4
|
|
||||||
|
|
||||||
/////////////////// Mapgen V6 perlin noise default values
|
|
||||||
NoiseParams nparams_v6_def_terrain_base =
|
|
||||||
{-AVERAGE_MUD_AMOUNT, 20.0, v3f(250.0, 250.0, 250.0), 82341, 5, 0.6};
|
|
||||||
NoiseParams nparams_v6_def_terrain_higher =
|
|
||||||
{20.0, 16.0, v3f(500.0, 500.0, 500.0), 85309, 5, 0.6};
|
|
||||||
NoiseParams nparams_v6_def_steepness =
|
|
||||||
{0.85, 0.5, v3f(125.0, 125.0, 125.0), -932, 5, 0.7};
|
|
||||||
NoiseParams nparams_v6_def_height_select =
|
|
||||||
{0.5, 1.0, v3f(250.0, 250.0, 250.0), 4213, 5, 0.69};
|
|
||||||
NoiseParams nparams_v6_def_trees =
|
|
||||||
{0.0, 1.0, v3f(125.0, 125.0, 125.0), 2, 4, 0.66};
|
|
||||||
NoiseParams nparams_v6_def_mud =
|
|
||||||
{AVERAGE_MUD_AMOUNT, 2.0, v3f(200.0, 200.0, 200.0), 91013, 3, 0.55};
|
|
||||||
NoiseParams nparams_v6_def_beach =
|
|
||||||
{0.0, 1.0, v3f(250.0, 250.0, 250.0), 59420, 3, 0.50};
|
|
||||||
NoiseParams nparams_v6_def_biome =
|
|
||||||
{0.0, 1.0, v3f(250.0, 250.0, 250.0), 9130, 3, 0.50};
|
|
||||||
NoiseParams nparams_v6_def_cave =
|
|
||||||
{6.0, 6.0, v3f(250.0, 250.0, 250.0), 34329, 3, 0.50};
|
|
||||||
|
|
||||||
/////////////////// Mapgen V7 perlin noise default values
|
|
||||||
NoiseParams nparams_v7_def_terrain =
|
|
||||||
{10.0, 12.0, v3f(350., 350., 350.), 82341, 5, 0.6}; //terrain
|
|
||||||
NoiseParams nparams_v7_def_bgroup =
|
|
||||||
{0.5, 1/(2*1.6), v3f(350., 350., 350.), 5923, 2, 0.60}; //0 to 1
|
|
||||||
NoiseParams nparams_v7_def_heat =
|
|
||||||
{25.0, 50.0, v3f(500., 500., 500.), 35293, 1, 0.00}; //-25 to 75
|
|
||||||
NoiseParams nparams_v7_def_humidity =
|
|
||||||
{50, 100/(2*1.6), v3f(750., 750., 750.), 12094, 2, 0.60}; //0 to 100
|
|
||||||
|
|
||||||
struct MapgenParams {
|
struct MapgenParams {
|
||||||
int seed;
|
int mg_version;
|
||||||
int water_level;
|
|
||||||
int chunksize;
|
int chunksize;
|
||||||
|
u64 seed;
|
||||||
|
int water_level;
|
||||||
u32 flags;
|
u32 flags;
|
||||||
|
|
||||||
MapgenParams() {
|
MapgenParams() {
|
||||||
|
mg_version = 6;
|
||||||
seed = 0;
|
seed = 0;
|
||||||
water_level = 1;
|
water_level = 1;
|
||||||
chunksize = 5;
|
chunksize = 5;
|
||||||
flags = MG_TREES | MG_CAVES | MGV6_BIOME_BLEND;
|
flags = MG_TREES | MG_CAVES | MGV6_BIOME_BLEND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static MapgenParams *createMapgenParams(int mgver);
|
||||||
|
static MapgenParams *getParamsFromSettings(Settings *settings);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MapgenV6Params : public MapgenParams {
|
struct MapgenV6Params : public MapgenParams {
|
||||||
|
@ -163,6 +153,7 @@ public:
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
virtual void makeChunk(BlockMakeData *data) {};
|
virtual void makeChunk(BlockMakeData *data) {};
|
||||||
|
virtual int getGroundLevelAtPoint(v2s16 p) = 0;
|
||||||
|
|
||||||
//Legacy functions for Farmesh (pending removal)
|
//Legacy functions for Farmesh (pending removal)
|
||||||
static bool get_have_beach(u64 seed, v2s16 p2d);
|
static bool get_have_beach(u64 seed, v2s16 p2d);
|
||||||
|
@ -189,7 +180,6 @@ public:
|
||||||
Noise *noise_mud;
|
Noise *noise_mud;
|
||||||
Noise *noise_beach;
|
Noise *noise_beach;
|
||||||
Noise *noise_biome;
|
Noise *noise_biome;
|
||||||
Noise *noise_cave;
|
|
||||||
|
|
||||||
float *map_terrain_base;
|
float *map_terrain_base;
|
||||||
float *map_terrain_higher;
|
float *map_terrain_higher;
|
||||||
|
@ -199,7 +189,8 @@ public:
|
||||||
float *map_mud;
|
float *map_mud;
|
||||||
float *map_beach;
|
float *map_beach;
|
||||||
float *map_biome;
|
float *map_biome;
|
||||||
float *map_cave;
|
|
||||||
|
NoiseParams *np_cave;
|
||||||
|
|
||||||
u32 flags;
|
u32 flags;
|
||||||
float freq_desert;
|
float freq_desert;
|
||||||
|
@ -209,6 +200,7 @@ public:
|
||||||
~MapgenV6();
|
~MapgenV6();
|
||||||
|
|
||||||
void makeChunk(BlockMakeData *data);
|
void makeChunk(BlockMakeData *data);
|
||||||
|
int getGroundLevelAtPoint(v2s16 p);
|
||||||
|
|
||||||
|
|
||||||
static s16 find_ground_level(VoxelManipulator &vmanip, v2s16 p2d, INodeDefManager *ndef);
|
static s16 find_ground_level(VoxelManipulator &vmanip, v2s16 p2d, INodeDefManager *ndef);
|
||||||
|
@ -254,12 +246,6 @@ public:
|
||||||
int id;
|
int id;
|
||||||
u32 flags;
|
u32 flags;
|
||||||
|
|
||||||
/*
|
|
||||||
NoiseParams *np_terrain;
|
|
||||||
NoiseParams *np_bgroup;
|
|
||||||
NoiseParams *np_heat;
|
|
||||||
NoiseParams *np_humidity;*/
|
|
||||||
|
|
||||||
//should these be broken off into a "commonly used nodes" class?
|
//should these be broken off into a "commonly used nodes" class?
|
||||||
MapNode n_air;
|
MapNode n_air;
|
||||||
MapNode n_water;
|
MapNode n_water;
|
||||||
|
@ -269,6 +255,9 @@ public:
|
||||||
~MapgenV7();
|
~MapgenV7();
|
||||||
|
|
||||||
void makeChunk(BlockMakeData *data);
|
void makeChunk(BlockMakeData *data);
|
||||||
|
int getGroundLevelAtPoint(v2s16 p);
|
||||||
|
|
||||||
|
Biome *getBiomeAtPoint(v3s16 p);
|
||||||
void updateLiquid(v3s16 node_min, v3s16 node_max);
|
void updateLiquid(v3s16 node_min, v3s16 node_max);
|
||||||
void updateLighting(v3s16 node_min, v3s16 node_max);
|
void updateLighting(v3s16 node_min, v3s16 node_max);
|
||||||
|
|
||||||
|
@ -281,7 +270,6 @@ public:
|
||||||
class EmergeManager {
|
class EmergeManager {
|
||||||
public:
|
public:
|
||||||
//settings
|
//settings
|
||||||
int mg_version;
|
|
||||||
MapgenParams *params;
|
MapgenParams *params;
|
||||||
|
|
||||||
//mapgen objects here
|
//mapgen objects here
|
||||||
|
@ -290,11 +278,10 @@ public:
|
||||||
//biome manager
|
//biome manager
|
||||||
BiomeDefManager *biomedef;
|
BiomeDefManager *biomedef;
|
||||||
|
|
||||||
EmergeManager(IGameDef *gamedef, int mg_version=6);
|
EmergeManager(IGameDef *gamedef, BiomeDefManager *bdef, MapgenParams *mgparams);
|
||||||
~EmergeManager();
|
~EmergeManager();
|
||||||
|
|
||||||
Mapgen *getMapgen();
|
Mapgen *getMapgen();
|
||||||
void setMapgenParams();
|
|
||||||
void addBlockToQueue();
|
void addBlockToQueue();
|
||||||
|
|
||||||
//mapgen helper methods
|
//mapgen helper methods
|
||||||
|
@ -304,43 +291,5 @@ public:
|
||||||
u32 getBlockSeed(v3s16 p);
|
u32 getBlockSeed(v3s16 p);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
namespace mapgen
|
|
||||||
{
|
|
||||||
// Finds precise ground level at any position
|
|
||||||
s16 find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision);
|
|
||||||
|
|
||||||
// Find out if block is completely underground
|
|
||||||
bool block_is_underground(u64 seed, v3s16 blockpos);
|
|
||||||
|
|
||||||
// Get a pseudorandom seed for a position on the map
|
|
||||||
u32 get_blockseed(u64 seed, v3s16 p);
|
|
||||||
|
|
||||||
// Main map generation routine
|
|
||||||
void make_block(BlockMakeData *data);
|
|
||||||
|
|
||||||
|
|
||||||
//These are used by FarMesh
|
|
||||||
bool get_have_beach(u64 seed, v2s16 p2d);
|
|
||||||
double tree_amount_2d(u64 seed, v2s16 p);
|
|
||||||
|
|
||||||
struct BlockMakeData
|
|
||||||
{
|
|
||||||
bool no_op;
|
|
||||||
ManualMapVoxelManipulator *vmanip; // Destructor deletes
|
|
||||||
u64 seed;
|
|
||||||
v3s16 blockpos_min;
|
|
||||||
v3s16 blockpos_max;
|
|
||||||
v3s16 blockpos_requested;
|
|
||||||
UniqueQueue<v3s16> transforming_liquid;
|
|
||||||
INodeDefManager *nodedef;
|
|
||||||
|
|
||||||
BlockMakeData();
|
|
||||||
~BlockMakeData();
|
|
||||||
};
|
|
||||||
|
|
||||||
}; // namespace mapgen
|
|
||||||
*/
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -32,47 +32,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
#include "settings.h" // For g_settings
|
#include "settings.h" // For g_settings
|
||||||
#include "main.h" // For g_profiler
|
#include "main.h" // For g_profiler
|
||||||
|
|
||||||
/*
|
|
||||||
#define AVERAGE_MUD_AMOUNT 4
|
|
||||||
|
|
||||||
NoiseParams nparams_v6_def_terrain_base =
|
|
||||||
{-AVERAGE_MUD_AMOUNT, 20.0, v3f(250.0, 250.0, 250.0), 82341, 5, 0.6};
|
|
||||||
NoiseParams nparams_v6_def_terrain_higher =
|
|
||||||
{20.0, 16.0, v3f(500.0, 500.0, 500.0), 85309, 5, 0.6};
|
|
||||||
NoiseParams nparams_v6_def_steepness =
|
|
||||||
{0.85, 0.5, v3f(125.0, 125.0, 125.0), -932, 5, 0.7};
|
|
||||||
NoiseParams nparams_v6_def_height_select =
|
|
||||||
{0.5, 1.0, v3f(250.0, 250.0, 250.0), 4213, 5, 0.69};
|
|
||||||
NoiseParams nparams_v6_def_trees =
|
|
||||||
{0.0, 1.0, v3f(125.0, 125.0, 125.0), 2, 4, 0.66};
|
|
||||||
NoiseParams nparams_v6_def_mud =
|
|
||||||
{AVERAGE_MUD_AMOUNT, 2.0, v3f(200.0, 200.0, 200.0), 91013, 3, 0.55};
|
|
||||||
NoiseParams nparams_v6_def_beach =
|
|
||||||
{0.0, 1.0, v3f(250.0, 250.0, 250.0), 59420, 3, 0.50};
|
|
||||||
NoiseParams nparams_v6_def_biome =
|
|
||||||
{0.0, 1.0, v3f(250.0, 250.0, 250.0), 9130, 3, 0.50};
|
|
||||||
NoiseParams nparams_v6_def_cave =
|
|
||||||
{6.0, 6.0, v3f(250.0, 250.0, 250.0), 34329, 3, 0.50};
|
|
||||||
|
|
||||||
|
|
||||||
MapgenV6Params mg_def_params_v6 = {
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
5,
|
|
||||||
MG_TREES | MG_CAVES | MGV6_BIOME_BLEND,
|
|
||||||
0.45,
|
|
||||||
0.15,
|
|
||||||
&nparams_v6_def_terrain_base,
|
|
||||||
&nparams_v6_def_terrain_higher,
|
|
||||||
&nparams_v6_def_steepness,
|
|
||||||
&nparams_v6_def_height_select,
|
|
||||||
&nparams_v6_def_trees,
|
|
||||||
&nparams_v6_def_mud,
|
|
||||||
&nparams_v6_def_beach,
|
|
||||||
&nparams_v6_def_biome,
|
|
||||||
&nparams_v6_def_cave
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -81,9 +40,9 @@ MapgenV6::MapgenV6(int mapgenid, MapgenV6Params *params) {
|
||||||
this->generating = false;
|
this->generating = false;
|
||||||
this->id = mapgenid;
|
this->id = mapgenid;
|
||||||
|
|
||||||
this->seed = params->seed;
|
this->seed = (int)params->seed;
|
||||||
this->water_level = params->water_level;
|
this->water_level = params->water_level;
|
||||||
this->flags = flags;
|
this->flags = params->flags;
|
||||||
this->csize = v3s16(1, 1, 1) * params->chunksize * MAP_BLOCKSIZE;
|
this->csize = v3s16(1, 1, 1) * params->chunksize * MAP_BLOCKSIZE;
|
||||||
|
|
||||||
this->freq_desert = params->freq_desert;
|
this->freq_desert = params->freq_desert;
|
||||||
|
@ -91,6 +50,8 @@ MapgenV6::MapgenV6(int mapgenid, MapgenV6Params *params) {
|
||||||
|
|
||||||
this->ystride = csize.X; //////fix this
|
this->ystride = csize.X; //////fix this
|
||||||
|
|
||||||
|
np_cave = params->np_cave;
|
||||||
|
|
||||||
noise_terrain_base = new Noise(params->np_terrain_base, seed, csize.X, csize.Y);
|
noise_terrain_base = new Noise(params->np_terrain_base, seed, csize.X, csize.Y);
|
||||||
noise_terrain_higher = new Noise(params->np_terrain_higher, seed, csize.X, csize.Y);
|
noise_terrain_higher = new Noise(params->np_terrain_higher, seed, csize.X, csize.Y);
|
||||||
noise_steepness = new Noise(params->np_steepness, seed, csize.X, csize.Y);
|
noise_steepness = new Noise(params->np_steepness, seed, csize.X, csize.Y);
|
||||||
|
@ -120,7 +81,6 @@ MapgenV6::~MapgenV6() {
|
||||||
delete noise_mud;
|
delete noise_mud;
|
||||||
delete noise_beach;
|
delete noise_beach;
|
||||||
delete noise_biome;
|
delete noise_biome;
|
||||||
delete noise_cave;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -401,6 +361,12 @@ u32 MapgenV6::get_blockseed(u64 seed, v3s16 p)
|
||||||
return (u32)(seed%0x100000000ULL) + z*38134234 + y*42123 + x*23;
|
return (u32)(seed%0x100000000ULL) + z*38134234 + y*42123 + x*23;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int MapgenV6::getGroundLevelAtPoint(v2s16 p) {
|
||||||
|
return base_rock_level_2d(seed, p) + AVERAGE_MUD_AMOUNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1
|
#define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1
|
||||||
|
|
||||||
void MapgenV6::makeChunk(BlockMakeData *data)
|
void MapgenV6::makeChunk(BlockMakeData *data)
|
||||||
|
@ -636,10 +602,7 @@ void MapgenV6::makeChunk(BlockMakeData *data)
|
||||||
0.5+(double)node_min.X/250, 0.5+(double)node_min.Y/250,
|
0.5+(double)node_min.X/250, 0.5+(double)node_min.Y/250,
|
||||||
data->seed+34329, 3, 0.50);*/
|
data->seed+34329, 3, 0.50);*/
|
||||||
|
|
||||||
double cave_amount = np_cave->offset + np_cave->scale * noise2d_perlin(
|
double cave_amount = NoisePerlin2D(np_cave, node_min.X, node_min.Y, data->seed);
|
||||||
0.5 + (double)node_min.X / np_cave->spread.X,
|
|
||||||
0.5 + (double)node_min.Y / np_cave->spread.Y,
|
|
||||||
data->seed + np_cave->seed, np_cave->octaves, np_cave->persist);
|
|
||||||
|
|
||||||
const u32 age_loops = 2;
|
const u32 age_loops = 2;
|
||||||
for(u32 i_age=0; i_age<age_loops; i_age++)
|
for(u32 i_age=0; i_age<age_loops; i_age++)
|
||||||
|
@ -669,11 +632,15 @@ void MapgenV6::makeChunk(BlockMakeData *data)
|
||||||
}
|
}
|
||||||
for(u32 jj=0; jj<caves_count+bruises_count; jj++)
|
for(u32 jj=0; jj<caves_count+bruises_count; jj++)
|
||||||
{
|
{
|
||||||
int avg_height = (int)
|
if (!(flags & MG_CAVES))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/*int avg_height = (int)
|
||||||
((base_rock_level_2d(data->seed, v2s16(node_min.X, node_min.Z)) +
|
((base_rock_level_2d(data->seed, v2s16(node_min.X, node_min.Z)) +
|
||||||
base_rock_level_2d(data->seed, v2s16(node_max.X, node_max.Z))) / 2);
|
base_rock_level_2d(data->seed, v2s16(node_max.X, node_max.Z))) / 2);
|
||||||
if ((node_max.Y + node_min.Y) / 2 > avg_height)
|
if ((node_max.Y + node_min.Y) / 2 > avg_height)
|
||||||
break;
|
break;*/
|
||||||
|
|
||||||
bool large_cave = (jj >= caves_count);
|
bool large_cave = (jj >= caves_count);
|
||||||
s16 min_tunnel_diameter = 2;
|
s16 min_tunnel_diameter = 2;
|
||||||
s16 max_tunnel_diameter = ps.range(2,6);
|
s16 max_tunnel_diameter = ps.range(2,6);
|
||||||
|
@ -1316,7 +1283,7 @@ void MapgenV6::makeChunk(BlockMakeData *data)
|
||||||
Generate some trees
|
Generate some trees
|
||||||
*/
|
*/
|
||||||
assert(central_area_size.X == central_area_size.Z);
|
assert(central_area_size.X == central_area_size.Z);
|
||||||
{
|
if (flags & MG_TREES) {
|
||||||
// Divide area into parts
|
// Divide area into parts
|
||||||
s16 div = 8;
|
s16 div = 8;
|
||||||
s16 sidelen = central_area_size.X / div;
|
s16 sidelen = central_area_size.X / div;
|
||||||
|
|
10
src/noise.h
10
src/noise.h
|
@ -70,6 +70,10 @@ struct NoiseParams {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Convenience macros for getting/setting NoiseParams in Settings
|
||||||
|
#define getNoiseParams(x) getStruct<NoiseParams>((x), "f,f,v3,s32,s32,f")
|
||||||
|
#define setNoiseParams(x, y) setStruct((x), "f,f,v3,s32,s32,f", (y))
|
||||||
|
|
||||||
class Noise {
|
class Noise {
|
||||||
public:
|
public:
|
||||||
NoiseParams *np;
|
NoiseParams *np;
|
||||||
|
@ -129,8 +133,12 @@ inline float easeCurve(float t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NoisePerlin2D(np, x, y, s) ((np)->offset + (np)->scale * \
|
#define NoisePerlin2D(np, x, y, s) ((np)->offset + (np)->scale * \
|
||||||
noise2d_perlin((float)(x) * (np)->spread.X, (float)(y) * (np)->spread.Y, \
|
noise2d_perlin((float)(x) / (np)->spread.X, (float)(y) / (np)->spread.Y, \
|
||||||
(s) + (np)->seed, (np)->octaves, (np)->persist))
|
(s) + (np)->seed, (np)->octaves, (np)->persist))
|
||||||
|
|
||||||
|
#define NoisePerlin3D(np, x, y, z, s) ((np)->offset + (np)->scale * \
|
||||||
|
noise2d_perlin((float)(x) / (np)->spread.X, (float)(y) / (np)->spread.Y, \
|
||||||
|
(float)(z) / (np)->spread.Z, (s) + (np)->seed, (np)->octaves, (np)->persist))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -4463,7 +4463,7 @@ static int l_register_biome_groups(lua_State *L)
|
||||||
if (!lua_istable(L, index))
|
if (!lua_istable(L, index))
|
||||||
throw LuaError(L, "register_biome_groups: parameter is not a table");
|
throw LuaError(L, "register_biome_groups: parameter is not a table");
|
||||||
|
|
||||||
BiomeDefManager *bmgr = get_server(L)->getEmergeManager()->biomedef;
|
BiomeDefManager *bmgr = get_server(L)->getBiomeDef();
|
||||||
if (!bmgr) {
|
if (!bmgr) {
|
||||||
verbosestream << "register_biome_groups: BiomeDefManager not active" << std::endl;
|
verbosestream << "register_biome_groups: BiomeDefManager not active" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -4487,7 +4487,7 @@ static int l_register_biome(lua_State *L)
|
||||||
std::string nodename;
|
std::string nodename;
|
||||||
|
|
||||||
IWritableNodeDefManager *ndef = get_server(L)->getWritableNodeDefManager();
|
IWritableNodeDefManager *ndef = get_server(L)->getWritableNodeDefManager();
|
||||||
BiomeDefManager *bmgr = get_server(L)->getEmergeManager()->biomedef;
|
BiomeDefManager *bmgr = get_server(L)->getBiomeDef();
|
||||||
if (!bmgr) {
|
if (!bmgr) {
|
||||||
verbosestream << "register_biome: BiomeDefManager not active" << std::endl;
|
verbosestream << "register_biome: BiomeDefManager not active" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -945,6 +945,7 @@ Server::Server(
|
||||||
m_rollback_sink_enabled(true),
|
m_rollback_sink_enabled(true),
|
||||||
m_enable_rollback_recording(false),
|
m_enable_rollback_recording(false),
|
||||||
m_emerge(NULL),
|
m_emerge(NULL),
|
||||||
|
m_biomedef(NULL),
|
||||||
m_lua(NULL),
|
m_lua(NULL),
|
||||||
m_itemdef(createItemDefManager()),
|
m_itemdef(createItemDefManager()),
|
||||||
m_nodedef(createNodeDefManager()),
|
m_nodedef(createNodeDefManager()),
|
||||||
|
@ -984,8 +985,8 @@ Server::Server(
|
||||||
infostream<<"- config: "<<m_path_config<<std::endl;
|
infostream<<"- config: "<<m_path_config<<std::endl;
|
||||||
infostream<<"- game: "<<m_gamespec.path<<std::endl;
|
infostream<<"- game: "<<m_gamespec.path<<std::endl;
|
||||||
|
|
||||||
// Create emerge manager
|
// Create biome definition manager
|
||||||
m_emerge = new EmergeManager(this, g_settings->getS16("use_mapgen_version"));
|
m_biomedef = new BiomeDefManager(this);
|
||||||
|
|
||||||
// Create rollback manager
|
// Create rollback manager
|
||||||
std::string rollback_path = m_path_world+DIR_DELIM+"rollback.txt";
|
std::string rollback_path = m_path_world+DIR_DELIM+"rollback.txt";
|
||||||
|
@ -1094,19 +1095,23 @@ Server::Server(
|
||||||
m_nodedef->updateAliases(m_itemdef);
|
m_nodedef->updateAliases(m_itemdef);
|
||||||
|
|
||||||
// Add default biomes after nodedef had its aliases added
|
// Add default biomes after nodedef had its aliases added
|
||||||
if (m_emerge->biomedef)
|
m_biomedef->addDefaultBiomes();
|
||||||
m_emerge->biomedef->addDefaultBiomes();
|
|
||||||
|
|
||||||
// Initialize Environment
|
// Initialize Environment
|
||||||
|
ServerMap *servermap = new ServerMap(path_world, this);
|
||||||
|
m_env = new ServerEnvironment(servermap, m_lua, this, this);
|
||||||
|
|
||||||
m_env = new ServerEnvironment(new ServerMap(path_world, this, m_emerge), m_lua,
|
// Create emerge manager
|
||||||
this, this);
|
m_emerge = new EmergeManager(this, m_biomedef, servermap->getMapgenParams());
|
||||||
|
|
||||||
|
// Give map pointer to the emerge manager
|
||||||
|
servermap->setEmerge(m_emerge);
|
||||||
|
|
||||||
// Give environment reference to scripting api
|
// Give environment reference to scripting api
|
||||||
scriptapi_add_environment(m_lua, m_env);
|
scriptapi_add_environment(m_lua, m_env);
|
||||||
|
|
||||||
// Register us to receive map edit events
|
// Register us to receive map edit events
|
||||||
m_env->getMap().addEventReceiver(this);
|
servermap->addEventReceiver(this);
|
||||||
|
|
||||||
// If file exists, load environment metadata
|
// If file exists, load environment metadata
|
||||||
if(fs::PathExists(m_path_world+DIR_DELIM+"env_meta.txt"))
|
if(fs::PathExists(m_path_world+DIR_DELIM+"env_meta.txt"))
|
||||||
|
@ -4849,7 +4854,7 @@ v3f findSpawnPos(ServerMap &map)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
s16 water_level = map.m_emerge->water_level; //g_settings->getS16("default_water_level");
|
s16 water_level = map.m_mgparams->water_level;
|
||||||
|
|
||||||
// Try to find a good place a few times
|
// Try to find a good place a few times
|
||||||
for(s32 i=0; i<1000; i++)
|
for(s32 i=0; i<1000; i++)
|
||||||
|
@ -4874,7 +4879,7 @@ v3f findSpawnPos(ServerMap &map)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
nodepos = v3s16(nodepos2d.X, groundheight-2, nodepos2d.Y);
|
nodepos = v3s16(nodepos2d.X, groundheight+1, nodepos2d.Y);
|
||||||
bool is_good = false;
|
bool is_good = false;
|
||||||
s32 air_count = 0;
|
s32 air_count = 0;
|
||||||
for(s32 i=0; i<10; i++){
|
for(s32 i=0; i<10; i++){
|
||||||
|
|
|
@ -553,6 +553,8 @@ public:
|
||||||
//TODO: determine what should be locked when accessing the emerge manager
|
//TODO: determine what should be locked when accessing the emerge manager
|
||||||
EmergeManager *getEmergeManager(){ return m_emerge; }
|
EmergeManager *getEmergeManager(){ return m_emerge; }
|
||||||
|
|
||||||
|
BiomeDefManager *getBiomeDef(){ return m_biomedef; }
|
||||||
|
|
||||||
// actions: time-reversed list
|
// actions: time-reversed list
|
||||||
// Return value: success/failure
|
// Return value: success/failure
|
||||||
bool rollbackRevertActions(const std::list<RollbackAction> &actions,
|
bool rollbackRevertActions(const std::list<RollbackAction> &actions,
|
||||||
|
@ -746,6 +748,9 @@ private:
|
||||||
// Emerge manager
|
// Emerge manager
|
||||||
EmergeManager *m_emerge;
|
EmergeManager *m_emerge;
|
||||||
|
|
||||||
|
// Biome Definition Manager
|
||||||
|
BiomeDefManager *m_biomedef;
|
||||||
|
|
||||||
// Scripting
|
// Scripting
|
||||||
// Envlock and conlock should be locked when using Lua
|
// Envlock and conlock should be locked when using Lua
|
||||||
lua_State *m_lua;
|
lua_State *m_lua;
|
||||||
|
|
|
@ -566,23 +566,39 @@ public:
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> struct alignment_trick { char c; T member; };
|
//template<typename T> struct alignment_trick { char c; T member; };
|
||||||
#define ALIGNOF(type) offsetof (alignment_trick<type>, member)
|
//#define ALIGNOF(type) offsetof (alignment_trick<type>, member)
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define ALIGNOF(x) __alignof(x)
|
||||||
|
#else
|
||||||
|
#define ALIGNOF(x) __alignof__(x)
|
||||||
|
#endif
|
||||||
#define PADDING(x, y) ((ALIGNOF(y) - ((uintptr_t)(x) & (ALIGNOF(y) - 1))) & (ALIGNOF(y) - 1))
|
#define PADDING(x, y) ((ALIGNOF(y) - ((uintptr_t)(x) & (ALIGNOF(y) - 1))) & (ALIGNOF(y) - 1))
|
||||||
typedef int64_t s64;
|
#ifdef _WIN32
|
||||||
|
#define strtok_r(x, y, z) strtok_s(x, y, z)
|
||||||
|
#define strtof(x, y) (float)strtod(x, y)
|
||||||
|
#define strtoll(x, y, z) _strtoi64(x, y, z)
|
||||||
|
#define strtoull(x, y, z) _strtoui64(x, y, z)
|
||||||
|
#endif
|
||||||
|
|
||||||
void *getStruct(std::string &name, std::string format, size_t len)
|
typedef long long int s64; //to be added to src/irrlichttypes.h later
|
||||||
|
|
||||||
|
template <class T> T *getStruct(std::string name, std::string format)
|
||||||
{
|
{
|
||||||
|
size_t len = sizeof(T);
|
||||||
std::vector<std::string *> strs_alloced;
|
std::vector<std::string *> strs_alloced;
|
||||||
std::string *str;
|
std::string *str;
|
||||||
char *s = &(get(name))[0];
|
std::string valstr = get(name);
|
||||||
char *buf = new char[len];
|
char *s = &valstr[0];
|
||||||
char *bufpos = buf;
|
T *buf = new T;
|
||||||
|
char *bufpos = (char *)buf;
|
||||||
char *f, *snext;
|
char *f, *snext;
|
||||||
size_t pos;
|
size_t pos;
|
||||||
|
|
||||||
char *fmt = &format[0];
|
char *fmtpos, *fmt = &format[0];
|
||||||
while ((f = strsep(&fmt, ",")) && s) {
|
while ((f = strtok_r(fmt, ",", &fmtpos)) && s) {
|
||||||
|
fmt = NULL;
|
||||||
|
|
||||||
bool is_unsigned = false;
|
bool is_unsigned = false;
|
||||||
int width = 0;
|
int width = 0;
|
||||||
char valtype = *f;
|
char valtype = *f;
|
||||||
|
@ -591,14 +607,14 @@ typedef int64_t s64;
|
||||||
if (width && valtype == 's')
|
if (width && valtype == 's')
|
||||||
valtype = 'i';
|
valtype = 'i';
|
||||||
|
|
||||||
switch (*f) {
|
switch (valtype) {
|
||||||
case 'u':
|
case 'u':
|
||||||
is_unsigned = true;
|
is_unsigned = true;
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
case 'i':
|
case 'i':
|
||||||
if (width == 16) {
|
if (width == 16) {
|
||||||
bufpos += PADDING(bufpos, u16);
|
bufpos += PADDING(bufpos, u16);
|
||||||
if ((bufpos - buf) + sizeof(u16) <= len) {
|
if ((bufpos - (char *)buf) + sizeof(u16) <= len) {
|
||||||
if (is_unsigned)
|
if (is_unsigned)
|
||||||
*(u16 *)bufpos = (u16)strtoul(s, &s, 10);
|
*(u16 *)bufpos = (u16)strtoul(s, &s, 10);
|
||||||
else
|
else
|
||||||
|
@ -607,7 +623,7 @@ typedef int64_t s64;
|
||||||
bufpos += sizeof(u16);
|
bufpos += sizeof(u16);
|
||||||
} else if (width == 32) {
|
} else if (width == 32) {
|
||||||
bufpos += PADDING(bufpos, u32);
|
bufpos += PADDING(bufpos, u32);
|
||||||
if ((bufpos - buf) + sizeof(u32) <= len) {
|
if ((bufpos - (char *)buf) + sizeof(u32) <= len) {
|
||||||
if (is_unsigned)
|
if (is_unsigned)
|
||||||
*(u32 *)bufpos = (u32)strtoul(s, &s, 10);
|
*(u32 *)bufpos = (u32)strtoul(s, &s, 10);
|
||||||
else
|
else
|
||||||
|
@ -616,7 +632,7 @@ typedef int64_t s64;
|
||||||
bufpos += sizeof(u32);
|
bufpos += sizeof(u32);
|
||||||
} else if (width == 64) {
|
} else if (width == 64) {
|
||||||
bufpos += PADDING(bufpos, u64);
|
bufpos += PADDING(bufpos, u64);
|
||||||
if ((bufpos - buf) + sizeof(u64) <= len) {
|
if ((bufpos - (char *)buf) + sizeof(u64) <= len) {
|
||||||
if (is_unsigned)
|
if (is_unsigned)
|
||||||
*(u64 *)bufpos = (u64)strtoull(s, &s, 10);
|
*(u64 *)bufpos = (u64)strtoull(s, &s, 10);
|
||||||
else
|
else
|
||||||
|
@ -632,7 +648,7 @@ typedef int64_t s64;
|
||||||
*snext++ = 0;
|
*snext++ = 0;
|
||||||
|
|
||||||
bufpos += PADDING(bufpos, bool);
|
bufpos += PADDING(bufpos, bool);
|
||||||
if ((bufpos - buf) + sizeof(bool) <= len)
|
if ((bufpos - (char *)buf) + sizeof(bool) <= len)
|
||||||
*(bool *)bufpos = is_yes(std::string(s));
|
*(bool *)bufpos = is_yes(std::string(s));
|
||||||
bufpos += sizeof(bool);
|
bufpos += sizeof(bool);
|
||||||
|
|
||||||
|
@ -640,7 +656,7 @@ typedef int64_t s64;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
bufpos += PADDING(bufpos, float);
|
bufpos += PADDING(bufpos, float);
|
||||||
if ((bufpos - buf) + sizeof(float) <= len)
|
if ((bufpos - (char *)buf) + sizeof(float) <= len)
|
||||||
*(float *)bufpos = strtof(s, &s);
|
*(float *)bufpos = strtof(s, &s);
|
||||||
bufpos += sizeof(float);
|
bufpos += sizeof(float);
|
||||||
|
|
||||||
|
@ -664,7 +680,7 @@ typedef int64_t s64;
|
||||||
while ((pos = str->find("\\\"", pos)) != std::string::npos)
|
while ((pos = str->find("\\\"", pos)) != std::string::npos)
|
||||||
str->erase(pos, 1);
|
str->erase(pos, 1);
|
||||||
|
|
||||||
if ((bufpos - buf) + sizeof(std::string *) <= len)
|
if ((bufpos - (char *)buf) + sizeof(std::string *) <= len)
|
||||||
*(std::string **)bufpos = str;
|
*(std::string **)bufpos = str;
|
||||||
bufpos += sizeof(std::string *);
|
bufpos += sizeof(std::string *);
|
||||||
strs_alloced.push_back(str);
|
strs_alloced.push_back(str);
|
||||||
|
@ -680,7 +696,7 @@ typedef int64_t s64;
|
||||||
if (width == 2) {
|
if (width == 2) {
|
||||||
bufpos += PADDING(bufpos, v2f);
|
bufpos += PADDING(bufpos, v2f);
|
||||||
|
|
||||||
if ((bufpos - buf) + sizeof(v2f) <= len) {
|
if ((bufpos - (char *)buf) + sizeof(v2f) <= len) {
|
||||||
v2f *v = (v2f *)bufpos;
|
v2f *v = (v2f *)bufpos;
|
||||||
v->X = strtof(s, &s);
|
v->X = strtof(s, &s);
|
||||||
s++;
|
s++;
|
||||||
|
@ -690,7 +706,7 @@ typedef int64_t s64;
|
||||||
bufpos += sizeof(v2f);
|
bufpos += sizeof(v2f);
|
||||||
} else if (width == 3) {
|
} else if (width == 3) {
|
||||||
bufpos += PADDING(bufpos, v3f);
|
bufpos += PADDING(bufpos, v3f);
|
||||||
if ((bufpos - buf) + sizeof(v3f) <= len) {
|
if ((bufpos - (char *)buf) + sizeof(v3f) <= len) {
|
||||||
v3f *v = (v3f *)bufpos;
|
v3f *v = (v3f *)bufpos;
|
||||||
v->X = strtof(s, &s);
|
v->X = strtof(s, &s);
|
||||||
s++;
|
s++;
|
||||||
|
@ -710,15 +726,16 @@ typedef int64_t s64;
|
||||||
if (s && *s == ',')
|
if (s && *s == ',')
|
||||||
s++;
|
s++;
|
||||||
|
|
||||||
if ((bufpos - buf) > len) //error, buffer too small
|
if ((size_t)(bufpos - (char *)buf) > len) //error, buffer too small
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f && *f) { //error, mismatched number of fields and values
|
if (f && *f) { //error, mismatched number of fields and values
|
||||||
fail:
|
fail:
|
||||||
for (int i = 0; i != strs_alloced.size(); i++)
|
for (unsigned int i = 0; i != strs_alloced.size(); i++)
|
||||||
delete strs_alloced[i];
|
delete strs_alloced[i];
|
||||||
delete[] buf;
|
delete buf;
|
||||||
|
//delete[] buf;
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -735,13 +752,12 @@ fail:
|
||||||
size_t fpos;
|
size_t fpos;
|
||||||
char *f;
|
char *f;
|
||||||
|
|
||||||
int nprinted;
|
|
||||||
char *bufpos = (char *)value;
|
char *bufpos = (char *)value;
|
||||||
char *fmt = &format[0];
|
char *fmtpos, *fmt = &format[0];
|
||||||
|
while ((f = strtok_r(fmt, ",", &fmtpos))) {
|
||||||
while ((f = strsep(&fmt, ","))) {
|
fmt = NULL;
|
||||||
bool is_unsigned = false;
|
bool is_unsigned = false;
|
||||||
int width = 0;
|
int width = 0, nprinted = 0;
|
||||||
char valtype = *f;
|
char valtype = *f;
|
||||||
|
|
||||||
width = (int)strtol(f + 1, &f, 10);
|
width = (int)strtol(f + 1, &f, 10);
|
||||||
|
@ -769,7 +785,7 @@ fail:
|
||||||
bufpos += PADDING(bufpos, u64);
|
bufpos += PADDING(bufpos, u64);
|
||||||
nprinted = snprintf(sbuf + pos, sbuflen,
|
nprinted = snprintf(sbuf + pos, sbuflen,
|
||||||
is_unsigned ? "%llu, " : "%lli, ",
|
is_unsigned ? "%llu, " : "%lli, ",
|
||||||
*((u64 *)bufpos));
|
(unsigned long long)*((u64 *)bufpos));
|
||||||
bufpos += sizeof(u64);
|
bufpos += sizeof(u64);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue