Remove no virtual dtor warnings, make MapgenParams contain actual NoiseParams

This commit is contained in:
kwolekr 2013-05-18 23:26:27 -04:00
parent f577facf79
commit 93474c4218
11 changed files with 182 additions and 177 deletions

@ -71,6 +71,12 @@ Ore *createOre(OreType type) {
} }
Ore::~Ore() {
delete np;
delete noise;
}
void Ore::resolveNodeNames(INodeDefManager *ndef) { void Ore::resolveNodeNames(INodeDefManager *ndef) {
if (ore == CONTENT_IGNORE) { if (ore == CONTENT_IGNORE) {
ore = ndef->getId(ore_name); ore = ndef->getId(ore_name);
@ -347,23 +353,18 @@ bool MapgenV6Params::readParams(Settings *settings) {
freq_desert = settings->getFloat("mgv6_freq_desert"); freq_desert = settings->getFloat("mgv6_freq_desert");
freq_beach = settings->getFloat("mgv6_freq_beach"); freq_beach = settings->getFloat("mgv6_freq_beach");
np_terrain_base = settings->getNoiseParams("mgv6_np_terrain_base");
np_terrain_higher = settings->getNoiseParams("mgv6_np_terrain_higher");
np_steepness = settings->getNoiseParams("mgv6_np_steepness");
np_height_select = settings->getNoiseParams("mgv6_np_height_select");
np_mud = settings->getNoiseParams("mgv6_np_mud");
np_beach = settings->getNoiseParams("mgv6_np_beach");
np_biome = settings->getNoiseParams("mgv6_np_biome");
np_cave = settings->getNoiseParams("mgv6_np_cave");
np_humidity = settings->getNoiseParams("mgv6_np_humidity");
np_trees = settings->getNoiseParams("mgv6_np_trees");
np_apple_trees = settings->getNoiseParams("mgv6_np_apple_trees");
bool success = bool success =
np_terrain_base && np_terrain_higher && np_steepness && settings->getNoiseParams("mgv6_np_terrain_base", np_terrain_base) &&
np_height_select && np_trees && np_mud && settings->getNoiseParams("mgv6_np_terrain_higher", np_terrain_higher) &&
np_beach && np_biome && np_cave && settings->getNoiseParams("mgv6_np_steepness", np_steepness) &&
np_humidity && np_apple_trees; settings->getNoiseParams("mgv6_np_height_select", np_height_select) &&
settings->getNoiseParams("mgv6_np_mud", np_mud) &&
settings->getNoiseParams("mgv6_np_beach", np_beach) &&
settings->getNoiseParams("mgv6_np_biome", np_biome) &&
settings->getNoiseParams("mgv6_np_cave", np_cave) &&
settings->getNoiseParams("mgv6_np_humidity", np_humidity) &&
settings->getNoiseParams("mgv6_np_trees", np_trees) &&
settings->getNoiseParams("mgv6_np_apple_trees", np_apple_trees);
return success; return success;
} }
@ -387,16 +388,13 @@ void MapgenV6Params::writeParams(Settings *settings) {
bool MapgenV7Params::readParams(Settings *settings) { bool MapgenV7Params::readParams(Settings *settings) {
np_terrain_base = settings->getNoiseParams("mgv7_np_terrain_base");
np_terrain_alt = settings->getNoiseParams("mgv7_np_terrain_alt");
np_terrain_mod = settings->getNoiseParams("mgv7_np_terrain_mod");
np_terrain_persist = settings->getNoiseParams("mgv7_np_terrain_persist");
np_height_select = settings->getNoiseParams("mgv7_np_height_select");
np_ridge = settings->getNoiseParams("mgv7_np_ridge");
bool success = bool success =
np_terrain_base && np_terrain_alt && np_terrain_mod && settings->getNoiseParams("mgv7_np_terrain_base", np_terrain_base) &&
np_terrain_persist && np_height_select && np_ridge; settings->getNoiseParams("mgv7_np_terrain_alt", np_terrain_alt) &&
settings->getNoiseParams("mgv7_np_terrain_mod", np_terrain_mod) &&
settings->getNoiseParams("mgv7_np_terrain_persist", np_terrain_persist) &&
settings->getNoiseParams("mgv7_np_height_select", np_height_select) &&
settings->getNoiseParams("mgv7_np_ridge", np_ridge);
return success; return success;
} }

@ -74,7 +74,8 @@ struct MapgenParams {
} }
virtual bool readParams(Settings *settings) = 0; virtual bool readParams(Settings *settings) = 0;
virtual void writeParams(Settings *settings) {}; virtual void writeParams(Settings *settings) = 0;
virtual ~MapgenParams() {}
}; };
class Mapgen { class Mapgen {
@ -86,6 +87,8 @@ public:
ManualMapVoxelManipulator *vm; ManualMapVoxelManipulator *vm;
INodeDefManager *ndef; INodeDefManager *ndef;
virtual ~Mapgen() {}
void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax); void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
void setLighting(v3s16 nmin, v3s16 nmax, u8 light); void setLighting(v3s16 nmin, v3s16 nmax, u8 light);
void lightSpread(VoxelArea &a, v3s16 p, u8 light); void lightSpread(VoxelArea &a, v3s16 p, u8 light);
@ -105,6 +108,7 @@ struct MapgenFactory {
virtual Mapgen *createMapgen(int mgid, MapgenParams *params, virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
EmergeManager *emerge) = 0; EmergeManager *emerge) = 0;
virtual MapgenParams *createMapgenParams() = 0; virtual MapgenParams *createMapgenParams() = 0;
virtual ~MapgenFactory() {}
}; };
enum OreType { enum OreType {
@ -140,6 +144,8 @@ public:
noise = NULL; noise = NULL;
} }
virtual ~Ore();
void resolveNodeNames(INodeDefManager *ndef); void resolveNodeNames(INodeDefManager *ndef);
void placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax); void placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
virtual void generate(ManualMapVoxelManipulator *vm, int seed, virtual void generate(ManualMapVoxelManipulator *vm, int seed,
@ -147,11 +153,13 @@ public:
}; };
class OreScatter : public Ore { class OreScatter : public Ore {
~OreScatter() {}
virtual void generate(ManualMapVoxelManipulator *vm, int seed, virtual void generate(ManualMapVoxelManipulator *vm, int seed,
u32 blockseed, v3s16 nmin, v3s16 nmax); u32 blockseed, v3s16 nmin, v3s16 nmax);
}; };
class OreSheet : public Ore { class OreSheet : public Ore {
~OreSheet() {}
virtual void generate(ManualMapVoxelManipulator *vm, int seed, virtual void generate(ManualMapVoxelManipulator *vm, int seed,
u32 blockseed, v3s16 nmin, v3s16 nmax); u32 blockseed, v3s16 nmin, v3s16 nmax);
}; };

@ -84,17 +84,14 @@ void NoiseIndev::transformNoiseMapFarScale(float xx, float yy, float zz) {
MapgenIndev::MapgenIndev(int mapgenid, MapgenIndevParams *params, EmergeManager *emerge) MapgenIndev::MapgenIndev(int mapgenid, MapgenIndevParams *params, EmergeManager *emerge)
: MapgenV6(mapgenid, params, emerge) : MapgenV6(mapgenid, params, emerge)
{ {
noiseindev_terrain_base = new NoiseIndev(params->npindev_terrain_base, seed, csize.X, csize.Z); noiseindev_terrain_base = new NoiseIndev(&params->npindev_terrain_base, seed, csize.X, csize.Z);
noiseindev_terrain_higher = new NoiseIndev(params->npindev_terrain_higher, seed, csize.X, csize.Z); noiseindev_terrain_higher = new NoiseIndev(&params->npindev_terrain_higher, seed, csize.X, csize.Z);
noiseindev_steepness = new NoiseIndev(params->npindev_steepness, seed, csize.X, csize.Z); noiseindev_steepness = new NoiseIndev(&params->npindev_steepness, seed, csize.X, csize.Z);
// noise_height_select = new Noise(params->np_height_select, seed, csize.X, csize.Y); noiseindev_mud = new NoiseIndev(&params->npindev_mud, seed, csize.X, csize.Z);
// noise_trees = new Noise(params->np_trees, seed, csize.X, csize.Y); noiseindev_float_islands1 = new NoiseIndev(&params->npindev_float_islands1, seed, csize.X, csize.Y, csize.Z);
noiseindev_mud = new NoiseIndev(params->npindev_mud, seed, csize.X, csize.Z); noiseindev_float_islands2 = new NoiseIndev(&params->npindev_float_islands2, seed, csize.X, csize.Y, csize.Z);
// noise_beach = new Noise(params->np_beach, seed, csize.X, csize.Y); noiseindev_float_islands3 = new NoiseIndev(&params->npindev_float_islands3, seed, csize.X, csize.Z);
noiseindev_float_islands1 = new NoiseIndev(params->npindev_float_islands1, seed, csize.X, csize.Y, csize.Z); noiseindev_biome = new NoiseIndev(&params->npindev_biome, seed, csize.X, csize.Z);
noiseindev_float_islands2 = new NoiseIndev(params->npindev_float_islands2, seed, csize.X, csize.Y, csize.Z);
noiseindev_float_islands3 = new NoiseIndev(params->npindev_float_islands3, seed, csize.X, csize.Z);
noiseindev_biome = new NoiseIndev(params->npindev_biome, seed, csize.X, csize.Z);
} }
MapgenIndev::~MapgenIndev() { MapgenIndev::~MapgenIndev() {
@ -173,24 +170,19 @@ bool MapgenIndevParams::readParams(Settings *settings) {
freq_desert = settings->getFloat("mgv6_freq_desert"); freq_desert = settings->getFloat("mgv6_freq_desert");
freq_beach = settings->getFloat("mgv6_freq_beach"); freq_beach = settings->getFloat("mgv6_freq_beach");
npindev_terrain_base = settings->getNoiseIndevParams("mgindev_np_terrain_base");
npindev_terrain_higher = settings->getNoiseIndevParams("mgindev_np_terrain_higher");
npindev_steepness = settings->getNoiseIndevParams("mgindev_np_steepness");
np_height_select = settings->getNoiseParams("mgv6_np_height_select");
np_trees = settings->getNoiseParams("mgv6_np_trees");
npindev_mud = settings->getNoiseIndevParams("mgindev_np_mud");
np_beach = settings->getNoiseParams("mgv6_np_beach");
npindev_biome = settings->getNoiseIndevParams("mgindev_np_biome");
np_cave = settings->getNoiseParams("mgv6_np_cave");
npindev_float_islands1 = settings->getNoiseIndevParams("mgindev_np_float_islands1");
npindev_float_islands2 = settings->getNoiseIndevParams("mgindev_np_float_islands2");
npindev_float_islands3 = settings->getNoiseIndevParams("mgindev_np_float_islands3");
bool success = bool success =
npindev_terrain_base && npindev_terrain_higher && npindev_steepness && settings->getNoiseIndevParams("mgindev_np_terrain_base", npindev_terrain_base) &&
np_height_select && np_trees && npindev_mud && settings->getNoiseIndevParams("mgindev_np_terrain_higher", npindev_terrain_higher) &&
np_beach && np_biome && np_cave && settings->getNoiseIndevParams("mgindev_np_steepness", npindev_steepness) &&
npindev_float_islands1 && npindev_float_islands2 && npindev_float_islands3; settings->getNoiseParams("mgv6_np_height_select", np_height_select) &&
settings->getNoiseParams("mgv6_np_trees", np_trees) &&
settings->getNoiseIndevParams("mgindev_np_mud", npindev_mud) &&
settings->getNoiseParams("mgv6_np_beach", np_beach) &&
settings->getNoiseIndevParams("mgindev_np_biome", npindev_biome) &&
settings->getNoiseParams("mgv6_np_cave", np_cave) &&
settings->getNoiseIndevParams("mgindev_np_float_islands1", npindev_float_islands1) &&
settings->getNoiseIndevParams("mgindev_np_float_islands2", npindev_float_islands2) &&
settings->getNoiseIndevParams("mgindev_np_float_islands3", npindev_float_islands3);
return success; return success;
} }

@ -33,7 +33,9 @@ struct NoiseIndevParams : public NoiseParams {
float farspread; float farspread;
NoiseIndevParams() {} NoiseIndevParams() {}
NoiseIndevParams(float offset_, float scale_, v3f spread_, int seed_, int octaves_, float persist_, float farscale_ = 1, float farspread_ = 1) NoiseIndevParams(float offset_, float scale_, v3f spread_,
int seed_, int octaves_, float persist_,
float farscale_ = 1, float farspread_ = 1)
{ {
offset = offset_; offset = offset_;
scale = scale_; scale = scale_;
@ -46,16 +48,17 @@ struct NoiseIndevParams : public NoiseParams {
farspread = farspread_; farspread = farspread_;
} }
~NoiseIndevParams() {}
}; };
#define getNoiseIndevParams(x) getStruct<NoiseIndevParams>((x), "f,f,v3,s32,s32,f,f,f") #define getNoiseIndevParams(x, y) getStruct((x), "f,f,v3,s32,s32,f,f,f", &(y), sizeof(y))
#define setNoiseIndevParams(x, y) setStruct((x), "f,f,v3,s32,s32,f,f,f", (y)) #define setNoiseIndevParams(x, y) setStruct((x), "f,f,v3,s32,s32,f,f,f", &(y))
class NoiseIndev : public Noise { class NoiseIndev : public Noise {
public: public:
NoiseIndevParams *npindev; NoiseIndevParams *npindev;
//NoiseIndev() {}; virtual ~NoiseIndev() {};
NoiseIndev(NoiseIndevParams *np, int seed, int sx, int sy); NoiseIndev(NoiseIndevParams *np, int seed, int sx, int sy);
NoiseIndev(NoiseIndevParams *np, int seed, int sx, int sy, int sz); NoiseIndev(NoiseIndevParams *np, int seed, int sx, int sy, int sz);
void init(NoiseIndevParams *np, int seed, int sx, int sy, int sz); void init(NoiseIndevParams *np, int seed, int sx, int sy, int sz);
@ -77,34 +80,34 @@ extern NoiseIndevParams nparams_indev_def_float_islands;
*/ */
struct MapgenIndevParams : public MapgenV6Params { struct MapgenIndevParams : public MapgenV6Params {
NoiseIndevParams *npindev_terrain_base; NoiseIndevParams npindev_terrain_base;
NoiseIndevParams *npindev_terrain_higher; NoiseIndevParams npindev_terrain_higher;
NoiseIndevParams *npindev_steepness; NoiseIndevParams npindev_steepness;
//NoiseParams *np_height_select; //NoiseParams *np_height_select;
//NoiseParams *np_trees; //NoiseParams *np_trees;
NoiseIndevParams *npindev_mud; NoiseIndevParams npindev_mud;
//NoiseParams *np_beach; //NoiseParams *np_beach;
NoiseIndevParams *npindev_biome; NoiseIndevParams npindev_biome;
//NoiseParams *np_cave; //NoiseParams *np_cave;
NoiseIndevParams *npindev_float_islands1; NoiseIndevParams npindev_float_islands1;
NoiseIndevParams *npindev_float_islands2; NoiseIndevParams npindev_float_islands2;
NoiseIndevParams *npindev_float_islands3; NoiseIndevParams npindev_float_islands3;
MapgenIndevParams() { MapgenIndevParams() {
//freq_desert = 0.45; //freq_desert = 0.45;
//freq_beach = 0.15; //freq_beach = 0.15;
npindev_terrain_base = &nparams_indev_def; //&nparams_indev_def_terrain_base; npindev_terrain_base = nparams_indev_def; //&nparams_indev_def_terrain_base;
npindev_terrain_higher = &nparams_indev_def; //&nparams_indev_def_terrain_higher; npindev_terrain_higher = nparams_indev_def; //&nparams_indev_def_terrain_higher;
npindev_steepness = &nparams_indev_def; //&nparams_indev_def_steepness; npindev_steepness = nparams_indev_def; //&nparams_indev_def_steepness;
//np_height_select = &nparams_v6_def_height_select; //np_height_select = &nparams_v6_def_height_select;
//np_trees = &nparams_v6_def_trees; //np_trees = &nparams_v6_def_trees;
npindev_mud = &nparams_indev_def; //&nparams_indev_def_mud; npindev_mud = nparams_indev_def; //&nparams_indev_def_mud;
//np_beach = &nparams_v6_def_beach; //np_beach = &nparams_v6_def_beach;
npindev_biome = &nparams_indev_def; //&nparams_indev_def_biome; npindev_biome = nparams_indev_def; //&nparams_indev_def_biome;
//np_cave = &nparams_v6_def_cave; //np_cave = &nparams_v6_def_cave;
npindev_float_islands1 = &nparams_indev_def; //&nparams_indev_def_float_islands; npindev_float_islands1 = nparams_indev_def; //&nparams_indev_def_float_islands;
npindev_float_islands2 = &nparams_indev_def; //&nparams_indev_def_float_islands; npindev_float_islands2 = nparams_indev_def; //&nparams_indev_def_float_islands;
npindev_float_islands3 = &nparams_indev_def; //&nparams_indev_def_float_islands; npindev_float_islands3 = nparams_indev_def; //&nparams_indev_def_float_islands;
} }

@ -24,8 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
struct MapgenSinglenodeParams : public MapgenParams { struct MapgenSinglenodeParams : public MapgenParams {
MapgenSinglenodeParams() { MapgenSinglenodeParams() {}
} ~MapgenSinglenodeParams() {}
bool readParams(Settings *settings); bool readParams(Settings *settings);
void writeParams(Settings *settings); void writeParams(Settings *settings);

@ -80,18 +80,18 @@ MapgenV6::MapgenV6(int mapgenid, MapgenV6Params *params, EmergeManager *emerge)
this->ystride = csize.X; //////fix this this->ystride = csize.X; //////fix this
np_cave = params->np_cave; np_cave = &params->np_cave;
np_humidity = params->np_humidity; np_humidity = &params->np_humidity;
np_trees = params->np_trees; np_trees = &params->np_trees;
np_apple_trees = params->np_apple_trees; np_apple_trees = &params->np_apple_trees;
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);
noise_height_select = new Noise(params->np_height_select, seed, csize.X, csize.Y); noise_height_select = new Noise(&params->np_height_select, seed, csize.X, csize.Y);
noise_mud = new Noise(params->np_mud, seed, csize.X, csize.Y); noise_mud = new Noise(&params->np_mud, seed, csize.X, csize.Y);
noise_beach = new Noise(params->np_beach, seed, csize.X, csize.Y); noise_beach = new Noise(&params->np_beach, seed, csize.X, csize.Y);
noise_biome = new Noise(params->np_biome, seed, csize.X, csize.Y); noise_biome = new Noise(&params->np_biome, seed, csize.X, csize.Y);
} }

@ -45,35 +45,36 @@ extern NoiseParams nparams_v6_def_apple_trees;
struct MapgenV6Params : public MapgenParams { struct MapgenV6Params : public MapgenParams {
float freq_desert; float freq_desert;
float freq_beach; float freq_beach;
NoiseParams *np_terrain_base; NoiseParams np_terrain_base;
NoiseParams *np_terrain_higher; NoiseParams np_terrain_higher;
NoiseParams *np_steepness; NoiseParams np_steepness;
NoiseParams *np_height_select; NoiseParams np_height_select;
NoiseParams *np_mud; NoiseParams np_mud;
NoiseParams *np_beach; NoiseParams np_beach;
NoiseParams *np_biome; NoiseParams np_biome;
NoiseParams *np_cave; NoiseParams np_cave;
NoiseParams *np_humidity; NoiseParams np_humidity;
NoiseParams *np_trees; NoiseParams np_trees;
NoiseParams *np_apple_trees; NoiseParams np_apple_trees;
MapgenV6Params() { MapgenV6Params() {
freq_desert = 0.45; freq_desert = 0.45;
freq_beach = 0.15; freq_beach = 0.15;
np_terrain_base = &nparams_v6_def_terrain_base; np_terrain_base = nparams_v6_def_terrain_base;
np_terrain_higher = &nparams_v6_def_terrain_higher; np_terrain_higher = nparams_v6_def_terrain_higher;
np_steepness = &nparams_v6_def_steepness; np_steepness = nparams_v6_def_steepness;
np_height_select = &nparams_v6_def_height_select; np_height_select = nparams_v6_def_height_select;
np_mud = &nparams_v6_def_mud; np_mud = nparams_v6_def_mud;
np_beach = &nparams_v6_def_beach; np_beach = nparams_v6_def_beach;
np_biome = &nparams_v6_def_biome; np_biome = nparams_v6_def_biome;
np_cave = &nparams_v6_def_cave; np_cave = nparams_v6_def_cave;
np_humidity = &nparams_v6_def_humidity; np_humidity = nparams_v6_def_humidity;
np_trees = &nparams_v6_def_trees; np_trees = nparams_v6_def_trees;
np_apple_trees = &nparams_v6_def_apple_trees; np_apple_trees = nparams_v6_def_apple_trees;
} }
~MapgenV6Params() {}
bool readParams(Settings *settings); bool readParams(Settings *settings);
void writeParams(Settings *settings); void writeParams(Settings *settings);
}; };

@ -85,12 +85,12 @@ MapgenV7::MapgenV7(int mapgenid, MapgenV7Params *params, EmergeManager *emerge)
this->ridge_heightmap = new s16[csize.X * csize.Z]; this->ridge_heightmap = new s16[csize.X * csize.Z];
// Terrain noise // Terrain noise
noise_terrain_base = new Noise(params->np_terrain_base, seed, csize.X, csize.Z); noise_terrain_base = new Noise(&params->np_terrain_base, seed, csize.X, csize.Z);
noise_terrain_alt = new Noise(params->np_terrain_alt, seed, csize.X, csize.Z); noise_terrain_alt = new Noise(&params->np_terrain_alt, seed, csize.X, csize.Z);
noise_terrain_mod = new Noise(params->np_terrain_mod, seed, csize.X, csize.Z); noise_terrain_mod = new Noise(&params->np_terrain_mod, seed, csize.X, csize.Z);
noise_terrain_persist = new Noise(params->np_terrain_persist, seed, csize.X, csize.Z); noise_terrain_persist = new Noise(&params->np_terrain_persist, seed, csize.X, csize.Z);
noise_height_select = new Noise(params->np_height_select, seed, csize.X, csize.Z); noise_height_select = new Noise(&params->np_height_select, seed, csize.X, csize.Z);
noise_ridge = new Noise(params->np_ridge, seed, csize.X, csize.Y, csize.Z); noise_ridge = new Noise(&params->np_ridge, seed, csize.X, csize.Y, csize.Z);
// Biome noise // Biome noise
noise_heat = new Noise(bmgr->np_heat, seed, csize.X, csize.Z); noise_heat = new Noise(bmgr->np_heat, seed, csize.X, csize.Z);

@ -30,22 +30,24 @@ extern NoiseParams nparams_v7_def_height_select;
extern NoiseParams nparams_v7_def_ridge; extern NoiseParams nparams_v7_def_ridge;
struct MapgenV7Params : public MapgenParams { struct MapgenV7Params : public MapgenParams {
NoiseParams *np_terrain_base; NoiseParams np_terrain_base;
NoiseParams *np_terrain_alt; NoiseParams np_terrain_alt;
NoiseParams *np_terrain_mod; NoiseParams np_terrain_mod;
NoiseParams *np_terrain_persist; NoiseParams np_terrain_persist;
NoiseParams *np_height_select; NoiseParams np_height_select;
NoiseParams *np_ridge; NoiseParams np_ridge;
MapgenV7Params() { MapgenV7Params() {
np_terrain_base = &nparams_v7_def_terrain_base; np_terrain_base = nparams_v7_def_terrain_base;
np_terrain_alt = &nparams_v7_def_terrain_alt; np_terrain_alt = nparams_v7_def_terrain_alt;
np_terrain_mod = &nparams_v7_def_terrain_mod; np_terrain_mod = nparams_v7_def_terrain_mod;
np_terrain_persist = &nparams_v7_def_terrain_persist; np_terrain_persist = nparams_v7_def_terrain_persist;
np_height_select = &nparams_v7_def_height_select; np_height_select = nparams_v7_def_height_select;
np_ridge = &nparams_v7_def_ridge; np_ridge = nparams_v7_def_ridge;
} }
~MapgenV7Params() {}
bool readParams(Settings *settings); bool readParams(Settings *settings);
void writeParams(Settings *settings); void writeParams(Settings *settings);
}; };

@ -72,8 +72,8 @@ struct NoiseParams {
// Convenience macros for getting/setting NoiseParams in Settings // Convenience macros for getting/setting NoiseParams in Settings
#define getNoiseParams(x) getStruct<NoiseParams>((x), "f,f,v3,s32,s32,f") #define getNoiseParams(x, y) getStruct((x), "f,f,v3,s32,s32,f", &(y), sizeof(y))
#define setNoiseParams(x, y) setStruct((x), "f,f,v3,s32,s32,f", (y)) #define setNoiseParams(x, y) setStruct((x), "f,f,v3,s32,s32,f", &(y))
class Noise { class Noise {
public: public:
@ -88,7 +88,7 @@ public:
Noise(NoiseParams *np, int seed, int sx, int sy); Noise(NoiseParams *np, int seed, int sx, int sy);
Noise(NoiseParams *np, int seed, int sx, int sy, int sz); Noise(NoiseParams *np, int seed, int sx, int sy, int sz);
~Noise(); virtual ~Noise();
virtual void init(NoiseParams *np, int seed, int sx, int sy, int sz); virtual void init(NoiseParams *np, int seed, int sx, int sy, int sz);
void setSize(int sx, int sy); void setSize(int sx, int sy);

@ -577,15 +577,15 @@ public:
return (isdigit(val[0])) ? stoi(val) : readFlagString(val, flagdesc); return (isdigit(val[0])) ? stoi(val) : readFlagString(val, flagdesc);
} }
template <class T> T *getStruct(std::string name, std::string format) bool getStruct(std::string name, std::string format, void *out, size_t olen)
{ {
size_t len = sizeof(T); size_t len = olen;
std::vector<std::string *> strs_alloced; std::vector<std::string *> strs_alloced;
std::string *str; std::string *str;
std::string valstr = get(name); std::string valstr = get(name);
char *s = &valstr[0]; char *s = &valstr[0];
T *buf = new T; char *buf = new char[len];
char *bufpos = (char *)buf; char *bufpos = buf;
char *f, *snext; char *f, *snext;
size_t pos; size_t pos;
@ -608,7 +608,7 @@ public:
case 'i': case 'i':
if (width == 16) { if (width == 16) {
bufpos += PADDING(bufpos, u16); bufpos += PADDING(bufpos, u16);
if ((bufpos - (char *)buf) + sizeof(u16) <= len) { if ((bufpos - 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
@ -617,7 +617,7 @@ public:
bufpos += sizeof(u16); bufpos += sizeof(u16);
} else if (width == 32) { } else if (width == 32) {
bufpos += PADDING(bufpos, u32); bufpos += PADDING(bufpos, u32);
if ((bufpos - (char *)buf) + sizeof(u32) <= len) { if ((bufpos - 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
@ -626,7 +626,7 @@ public:
bufpos += sizeof(u32); bufpos += sizeof(u32);
} else if (width == 64) { } else if (width == 64) {
bufpos += PADDING(bufpos, u64); bufpos += PADDING(bufpos, u64);
if ((bufpos - (char *)buf) + sizeof(u64) <= len) { if ((bufpos - 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
@ -642,7 +642,7 @@ public:
*snext++ = 0; *snext++ = 0;
bufpos += PADDING(bufpos, bool); bufpos += PADDING(bufpos, bool);
if ((bufpos - (char *)buf) + sizeof(bool) <= len) if ((bufpos - buf) + sizeof(bool) <= len)
*(bool *)bufpos = is_yes(std::string(s)); *(bool *)bufpos = is_yes(std::string(s));
bufpos += sizeof(bool); bufpos += sizeof(bool);
@ -650,7 +650,7 @@ public:
break; break;
case 'f': case 'f':
bufpos += PADDING(bufpos, float); bufpos += PADDING(bufpos, float);
if ((bufpos - (char *)buf) + sizeof(float) <= len) if ((bufpos - buf) + sizeof(float) <= len)
*(float *)bufpos = strtof(s, &s); *(float *)bufpos = strtof(s, &s);
bufpos += sizeof(float); bufpos += sizeof(float);
@ -674,7 +674,7 @@ public:
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 - (char *)buf) + sizeof(std::string *) <= len) if ((bufpos - 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);
@ -690,7 +690,7 @@ public:
if (width == 2) { if (width == 2) {
bufpos += PADDING(bufpos, v2f); bufpos += PADDING(bufpos, v2f);
if ((bufpos - (char *)buf) + sizeof(v2f) <= len) { if ((bufpos - buf) + sizeof(v2f) <= len) {
v2f *v = (v2f *)bufpos; v2f *v = (v2f *)bufpos;
v->X = strtof(s, &s); v->X = strtof(s, &s);
s++; s++;
@ -700,7 +700,7 @@ public:
bufpos += sizeof(v2f); bufpos += sizeof(v2f);
} else if (width == 3) { } else if (width == 3) {
bufpos += PADDING(bufpos, v3f); bufpos += PADDING(bufpos, v3f);
if ((bufpos - (char *)buf) + sizeof(v3f) <= len) { if ((bufpos - buf) + sizeof(v3f) <= len) {
v3f *v = (v3f *)bufpos; v3f *v = (v3f *)bufpos;
v->X = strtof(s, &s); v->X = strtof(s, &s);
s++; s++;
@ -720,20 +720,21 @@ public:
if (s && *s == ',') if (s && *s == ',')
s++; s++;
if ((size_t)(bufpos - (char *)buf) > len) //error, buffer too small if ((size_t)(bufpos - 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 (unsigned int i = 0; i != strs_alloced.size(); i++) for (size_t i = 0; i != strs_alloced.size(); i++)
delete strs_alloced[i]; delete strs_alloced[i];
delete buf; delete[] buf;
//delete[] buf; return false;
buf = NULL;
} }
return buf; memcpy(out, buf, olen);
delete[] buf;
return true;
} }
bool setStruct(std::string name, std::string format, void *value) bool setStruct(std::string name, std::string format, void *value)