}
+Ore::~Ore() {
+ delete np;
+ delete noise;
+}
+
+
void Ore::resolveNodeNames(INodeDefManager *ndef) {
if (ore == CONTENT_IGNORE) {
ore = ndef->getId(ore_name);
freq_desert = settings->getFloat("mgv6_freq_desert");
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 =
- np_terrain_base && np_terrain_higher && np_steepness &&
- np_height_select && np_trees && np_mud &&
- np_beach && np_biome && np_cave &&
- np_humidity && np_apple_trees;
+ bool success =
+ settings->getNoiseParams("mgv6_np_terrain_base", np_terrain_base) &&
+ settings->getNoiseParams("mgv6_np_terrain_higher", np_terrain_higher) &&
+ settings->getNoiseParams("mgv6_np_steepness", np_steepness) &&
+ 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;
}
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 =
- np_terrain_base && np_terrain_alt && np_terrain_mod &&
- np_terrain_persist && np_height_select && np_ridge;
+ bool success =
+ settings->getNoiseParams("mgv7_np_terrain_base", np_terrain_base) &&
+ settings->getNoiseParams("mgv7_np_terrain_alt", np_terrain_alt) &&
+ settings->getNoiseParams("mgv7_np_terrain_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;
}
}
virtual bool readParams(Settings *settings) = 0;
- virtual void writeParams(Settings *settings) {};
+ virtual void writeParams(Settings *settings) = 0;
+ virtual ~MapgenParams() {}
};
class Mapgen {
ManualMapVoxelManipulator *vm;
INodeDefManager *ndef;
+ virtual ~Mapgen() {}
+
void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
void setLighting(v3s16 nmin, v3s16 nmax, u8 light);
void lightSpread(VoxelArea &a, v3s16 p, u8 light);
virtual Mapgen *createMapgen(int mgid, MapgenParams *params,
EmergeManager *emerge) = 0;
virtual MapgenParams *createMapgenParams() = 0;
+ virtual ~MapgenFactory() {}
};
enum OreType {
noise = NULL;
}
+ virtual ~Ore();
+
void resolveNodeNames(INodeDefManager *ndef);
void placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
virtual void generate(ManualMapVoxelManipulator *vm, int seed,
};
class OreScatter : public Ore {
+ ~OreScatter() {}
virtual void generate(ManualMapVoxelManipulator *vm, int seed,
u32 blockseed, v3s16 nmin, v3s16 nmax);
};
class OreSheet : public Ore {
+ ~OreSheet() {}
virtual void generate(ManualMapVoxelManipulator *vm, int seed,
u32 blockseed, v3s16 nmin, v3s16 nmax);
};
MapgenIndev::MapgenIndev(int mapgenid, MapgenIndevParams *params, EmergeManager *emerge)
: MapgenV6(mapgenid, params, emerge)
{
- 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_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);
-// noise_trees = new Noise(params->np_trees, seed, csize.X, csize.Y);
- noiseindev_mud = new NoiseIndev(params->npindev_mud, seed, csize.X, csize.Z);
-// noise_beach = new Noise(params->np_beach, seed, csize.X, csize.Y);
- noiseindev_float_islands1 = new NoiseIndev(params->npindev_float_islands1, seed, csize.X, csize.Y, 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);
+ noiseindev_terrain_base = new NoiseIndev(¶ms->npindev_terrain_base, seed, csize.X, csize.Z);
+ noiseindev_terrain_higher = new NoiseIndev(¶ms->npindev_terrain_higher, seed, csize.X, csize.Z);
+ noiseindev_steepness = new NoiseIndev(¶ms->npindev_steepness, seed, csize.X, csize.Z);
+ noiseindev_mud = new NoiseIndev(¶ms->npindev_mud, seed, csize.X, csize.Z);
+ noiseindev_float_islands1 = new NoiseIndev(¶ms->npindev_float_islands1, seed, csize.X, csize.Y, csize.Z);
+ noiseindev_float_islands2 = new NoiseIndev(¶ms->npindev_float_islands2, seed, csize.X, csize.Y, csize.Z);
+ noiseindev_float_islands3 = new NoiseIndev(¶ms->npindev_float_islands3, seed, csize.X, csize.Z);
+ noiseindev_biome = new NoiseIndev(¶ms->npindev_biome, seed, csize.X, csize.Z);
}
MapgenIndev::~MapgenIndev() {
}
bool MapgenIndevParams::readParams(Settings *settings) {
- freq_desert = settings->getFloat("mgv6_freq_desert");
- 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 =
- npindev_terrain_base && npindev_terrain_higher && npindev_steepness &&
- np_height_select && np_trees && npindev_mud &&
- np_beach && np_biome && np_cave &&
- npindev_float_islands1 && npindev_float_islands2 && npindev_float_islands3;
- return success;
+ freq_desert = settings->getFloat("mgv6_freq_desert");
+ freq_beach = settings->getFloat("mgv6_freq_beach");
+
+ bool success =
+ settings->getNoiseIndevParams("mgindev_np_terrain_base", npindev_terrain_base) &&
+ settings->getNoiseIndevParams("mgindev_np_terrain_higher", npindev_terrain_higher) &&
+ settings->getNoiseIndevParams("mgindev_np_steepness", npindev_steepness) &&
+ 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;
}
void MapgenIndevParams::writeParams(Settings *settings) {
- settings->setFloat("mgv6_freq_desert", freq_desert);
- settings->setFloat("mgv6_freq_beach", freq_beach);
-
- settings->setNoiseIndevParams("mgindev_np_terrain_base", npindev_terrain_base);
- settings->setNoiseIndevParams("mgindev_np_terrain_higher", npindev_terrain_higher);
- settings->setNoiseIndevParams("mgindev_np_steepness", npindev_steepness);
- settings->setNoiseParams("mgv6_np_height_select", np_height_select);
- settings->setNoiseParams("mgv6_np_trees", np_trees);
- settings->setNoiseIndevParams("mgindev_np_mud", npindev_mud);
- settings->setNoiseParams("mgv6_np_beach", np_beach);
- settings->setNoiseIndevParams("mgindev_np_biome", npindev_biome);
- settings->setNoiseParams("mgv6_np_cave", np_cave);
- settings->setNoiseIndevParams("mgindev_np_float_islands1", npindev_float_islands1);
- settings->setNoiseIndevParams("mgindev_np_float_islands2", npindev_float_islands2);
- settings->setNoiseIndevParams("mgindev_np_float_islands3", npindev_float_islands3);
+ settings->setFloat("mgv6_freq_desert", freq_desert);
+ settings->setFloat("mgv6_freq_beach", freq_beach);
+
+ settings->setNoiseIndevParams("mgindev_np_terrain_base", npindev_terrain_base);
+ settings->setNoiseIndevParams("mgindev_np_terrain_higher", npindev_terrain_higher);
+ settings->setNoiseIndevParams("mgindev_np_steepness", npindev_steepness);
+ settings->setNoiseParams("mgv6_np_height_select", np_height_select);
+ settings->setNoiseParams("mgv6_np_trees", np_trees);
+ settings->setNoiseIndevParams("mgindev_np_mud", npindev_mud);
+ settings->setNoiseParams("mgv6_np_beach", np_beach);
+ settings->setNoiseIndevParams("mgindev_np_biome", npindev_biome);
+ settings->setNoiseParams("mgv6_np_cave", np_cave);
+ settings->setNoiseIndevParams("mgindev_np_float_islands1", npindev_float_islands1);
+ settings->setNoiseIndevParams("mgindev_np_float_islands2", npindev_float_islands2);
+ settings->setNoiseIndevParams("mgindev_np_float_islands3", npindev_float_islands3);
}
float farscale;
float farspread;
- NoiseIndevParams(){}
- NoiseIndevParams(float offset_, float scale_, v3f spread_, int seed_, int octaves_, float persist_, float farscale_ = 1, float farspread_ = 1)
+ NoiseIndevParams() {}
+ NoiseIndevParams(float offset_, float scale_, v3f spread_,
+ int seed_, int octaves_, float persist_,
+ float farscale_ = 1, float farspread_ = 1)
{
- offset = offset_;
- scale = scale_;
- spread = spread_;
- seed = seed_;
+ offset = offset_;
+ scale = scale_;
+ spread = spread_;
+ seed = seed_;
octaves = octaves_;
persist = persist_;
- farscale = farscale_;
+ farscale = farscale_;
farspread = farspread_;
}
-
+
+ ~NoiseIndevParams() {}
};
-#define getNoiseIndevParams(x) getStruct<NoiseIndevParams>((x), "f,f,v3,s32,s32,f,f,f")
-#define setNoiseIndevParams(x, y) setStruct((x), "f,f,v3,s32,s32,f,f,f", (y))
+#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))
class NoiseIndev : public Noise {
- public:
+public:
NoiseIndevParams *npindev;
- //NoiseIndev() {};
+ virtual ~NoiseIndev() {};
NoiseIndev(NoiseIndevParams *np, int seed, int sx, int sy);
NoiseIndev(NoiseIndevParams *np, int seed, int sx, int sy, int sz);
void init(NoiseIndevParams *np, int seed, int sx, int sy, int sz);
*/
struct MapgenIndevParams : public MapgenV6Params {
- NoiseIndevParams *npindev_terrain_base;
- NoiseIndevParams *npindev_terrain_higher;
- NoiseIndevParams *npindev_steepness;
+ NoiseIndevParams npindev_terrain_base;
+ NoiseIndevParams npindev_terrain_higher;
+ NoiseIndevParams npindev_steepness;
//NoiseParams *np_height_select;
//NoiseParams *np_trees;
- NoiseIndevParams *npindev_mud;
+ NoiseIndevParams npindev_mud;
//NoiseParams *np_beach;
- NoiseIndevParams *npindev_biome;
+ NoiseIndevParams npindev_biome;
//NoiseParams *np_cave;
- NoiseIndevParams *npindev_float_islands1;
- NoiseIndevParams *npindev_float_islands2;
- NoiseIndevParams *npindev_float_islands3;
+ NoiseIndevParams npindev_float_islands1;
+ NoiseIndevParams npindev_float_islands2;
+ NoiseIndevParams npindev_float_islands3;
MapgenIndevParams() {
//freq_desert = 0.45;
//freq_beach = 0.15;
- npindev_terrain_base = &nparams_indev_def; //&nparams_indev_def_terrain_base;
- npindev_terrain_higher = &nparams_indev_def; //&nparams_indev_def_terrain_higher;
- npindev_steepness = &nparams_indev_def; //&nparams_indev_def_steepness;
+ npindev_terrain_base = nparams_indev_def; //&nparams_indev_def_terrain_base;
+ npindev_terrain_higher = nparams_indev_def; //&nparams_indev_def_terrain_higher;
+ npindev_steepness = nparams_indev_def; //&nparams_indev_def_steepness;
//np_height_select = &nparams_v6_def_height_select;
//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;
- npindev_biome = &nparams_indev_def; //&nparams_indev_def_biome;
+ npindev_biome = nparams_indev_def; //&nparams_indev_def_biome;
//np_cave = &nparams_v6_def_cave;
- npindev_float_islands1 = &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_islands1 = 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;
}
struct MapgenSinglenodeParams : public MapgenParams {
- MapgenSinglenodeParams() {
- }
+ MapgenSinglenodeParams() {}
+ ~MapgenSinglenodeParams() {}
bool readParams(Settings *settings);
void writeParams(Settings *settings);
this->ystride = csize.X; //////fix this
- np_cave = params->np_cave;
- np_humidity = params->np_humidity;
- np_trees = params->np_trees;
- np_apple_trees = params->np_apple_trees;
-
- 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_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_mud = new Noise(params->np_mud, 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);
+ np_cave = ¶ms->np_cave;
+ np_humidity = ¶ms->np_humidity;
+ np_trees = ¶ms->np_trees;
+ np_apple_trees = ¶ms->np_apple_trees;
+
+ noise_terrain_base = new Noise(¶ms->np_terrain_base, seed, csize.X, csize.Y);
+ noise_terrain_higher = new Noise(¶ms->np_terrain_higher, seed, csize.X, csize.Y);
+ noise_steepness = new Noise(¶ms->np_steepness, seed, csize.X, csize.Y);
+ noise_height_select = new Noise(¶ms->np_height_select, seed, csize.X, csize.Y);
+ noise_mud = new Noise(¶ms->np_mud, seed, csize.X, csize.Y);
+ noise_beach = new Noise(¶ms->np_beach, seed, csize.X, csize.Y);
+ noise_biome = new Noise(¶ms->np_biome, seed, csize.X, csize.Y);
}
struct MapgenV6Params : public MapgenParams {
float freq_desert;
float freq_beach;
- NoiseParams *np_terrain_base;
- NoiseParams *np_terrain_higher;
- NoiseParams *np_steepness;
- NoiseParams *np_height_select;
- NoiseParams *np_mud;
- NoiseParams *np_beach;
- NoiseParams *np_biome;
- NoiseParams *np_cave;
- NoiseParams *np_humidity;
- NoiseParams *np_trees;
- NoiseParams *np_apple_trees;
+ NoiseParams np_terrain_base;
+ NoiseParams np_terrain_higher;
+ NoiseParams np_steepness;
+ NoiseParams np_height_select;
+ NoiseParams np_mud;
+ NoiseParams np_beach;
+ NoiseParams np_biome;
+ NoiseParams np_cave;
+ NoiseParams np_humidity;
+ NoiseParams np_trees;
+ NoiseParams np_apple_trees;
MapgenV6Params() {
freq_desert = 0.45;
freq_beach = 0.15;
- np_terrain_base = &nparams_v6_def_terrain_base;
- np_terrain_higher = &nparams_v6_def_terrain_higher;
- np_steepness = &nparams_v6_def_steepness;
- np_height_select = &nparams_v6_def_height_select;
- np_mud = &nparams_v6_def_mud;
- np_beach = &nparams_v6_def_beach;
- np_biome = &nparams_v6_def_biome;
- np_cave = &nparams_v6_def_cave;
- np_humidity = &nparams_v6_def_humidity;
- np_trees = &nparams_v6_def_trees;
- np_apple_trees = &nparams_v6_def_apple_trees;
-
+ np_terrain_base = nparams_v6_def_terrain_base;
+ np_terrain_higher = nparams_v6_def_terrain_higher;
+ np_steepness = nparams_v6_def_steepness;
+ np_height_select = nparams_v6_def_height_select;
+ np_mud = nparams_v6_def_mud;
+ np_beach = nparams_v6_def_beach;
+ np_biome = nparams_v6_def_biome;
+ np_cave = nparams_v6_def_cave;
+ np_humidity = nparams_v6_def_humidity;
+ np_trees = nparams_v6_def_trees;
+ np_apple_trees = nparams_v6_def_apple_trees;
}
+ ~MapgenV6Params() {}
+
bool readParams(Settings *settings);
void writeParams(Settings *settings);
};
this->ridge_heightmap = new s16[csize.X * csize.Z];
// Terrain noise
- 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_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_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_terrain_base = new Noise(¶ms->np_terrain_base, seed, csize.X, csize.Z);
+ noise_terrain_alt = new Noise(¶ms->np_terrain_alt, seed, csize.X, csize.Z);
+ noise_terrain_mod = new Noise(¶ms->np_terrain_mod, seed, csize.X, csize.Z);
+ noise_terrain_persist = new Noise(¶ms->np_terrain_persist, seed, csize.X, csize.Z);
+ noise_height_select = new Noise(¶ms->np_height_select, seed, csize.X, csize.Z);
+ noise_ridge = new Noise(¶ms->np_ridge, seed, csize.X, csize.Y, csize.Z);
// Biome noise
noise_heat = new Noise(bmgr->np_heat, seed, csize.X, csize.Z);
extern NoiseParams nparams_v7_def_ridge;
struct MapgenV7Params : public MapgenParams {
- NoiseParams *np_terrain_base;
- NoiseParams *np_terrain_alt;
- NoiseParams *np_terrain_mod;
- NoiseParams *np_terrain_persist;
- NoiseParams *np_height_select;
- NoiseParams *np_ridge;
+ NoiseParams np_terrain_base;
+ NoiseParams np_terrain_alt;
+ NoiseParams np_terrain_mod;
+ NoiseParams np_terrain_persist;
+ NoiseParams np_height_select;
+ NoiseParams np_ridge;
MapgenV7Params() {
- np_terrain_base = &nparams_v7_def_terrain_base;
- np_terrain_alt = &nparams_v7_def_terrain_alt;
- np_terrain_mod = &nparams_v7_def_terrain_mod;
- np_terrain_persist = &nparams_v7_def_terrain_persist;
- np_height_select = &nparams_v7_def_height_select;
- np_ridge = &nparams_v7_def_ridge;
+ np_terrain_base = nparams_v7_def_terrain_base;
+ np_terrain_alt = nparams_v7_def_terrain_alt;
+ np_terrain_mod = nparams_v7_def_terrain_mod;
+ np_terrain_persist = nparams_v7_def_terrain_persist;
+ np_height_select = nparams_v7_def_height_select;
+ np_ridge = nparams_v7_def_ridge;
}
+ ~MapgenV7Params() {}
+
bool readParams(Settings *settings);
void writeParams(Settings *settings);
};
// 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))
+#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))
class Noise {
public:
Noise(NoiseParams *np, int seed, int sx, int sy);
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);
void setSize(int sx, int sy);
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::string *str;
std::string valstr = get(name);
char *s = &valstr[0];
- T *buf = new T;
- char *bufpos = (char *)buf;
+ char *buf = new char[len];
+ char *bufpos = buf;
char *f, *snext;
size_t pos;
case 'i':
if (width == 16) {
bufpos += PADDING(bufpos, u16);
- if ((bufpos - (char *)buf) + sizeof(u16) <= len) {
+ if ((bufpos - buf) + sizeof(u16) <= len) {
if (is_unsigned)
*(u16 *)bufpos = (u16)strtoul(s, &s, 10);
else
bufpos += sizeof(u16);
} else if (width == 32) {
bufpos += PADDING(bufpos, u32);
- if ((bufpos - (char *)buf) + sizeof(u32) <= len) {
+ if ((bufpos - buf) + sizeof(u32) <= len) {
if (is_unsigned)
*(u32 *)bufpos = (u32)strtoul(s, &s, 10);
else
bufpos += sizeof(u32);
} else if (width == 64) {
bufpos += PADDING(bufpos, u64);
- if ((bufpos - (char *)buf) + sizeof(u64) <= len) {
+ if ((bufpos - buf) + sizeof(u64) <= len) {
if (is_unsigned)
*(u64 *)bufpos = (u64)strtoull(s, &s, 10);
else
*snext++ = 0;
bufpos += PADDING(bufpos, bool);
- if ((bufpos - (char *)buf) + sizeof(bool) <= len)
+ if ((bufpos - buf) + sizeof(bool) <= len)
*(bool *)bufpos = is_yes(std::string(s));
bufpos += sizeof(bool);
break;
case 'f':
bufpos += PADDING(bufpos, float);
- if ((bufpos - (char *)buf) + sizeof(float) <= len)
+ if ((bufpos - buf) + sizeof(float) <= len)
*(float *)bufpos = strtof(s, &s);
bufpos += sizeof(float);
while ((pos = str->find("\\\"", pos)) != std::string::npos)
str->erase(pos, 1);
- if ((bufpos - (char *)buf) + sizeof(std::string *) <= len)
+ if ((bufpos - buf) + sizeof(std::string *) <= len)
*(std::string **)bufpos = str;
bufpos += sizeof(std::string *);
strs_alloced.push_back(str);
if (width == 2) {
bufpos += PADDING(bufpos, v2f);
- if ((bufpos - (char *)buf) + sizeof(v2f) <= len) {
+ if ((bufpos - buf) + sizeof(v2f) <= len) {
v2f *v = (v2f *)bufpos;
v->X = strtof(s, &s);
s++;
bufpos += sizeof(v2f);
} else if (width == 3) {
bufpos += PADDING(bufpos, v3f);
- if ((bufpos - (char *)buf) + sizeof(v3f) <= len) {
+ if ((bufpos - buf) + sizeof(v3f) <= len) {
v3f *v = (v3f *)bufpos;
v->X = strtof(s, &s);
s++;
if (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;
}
if (f && *f) { //error, mismatched number of fields and values
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 buf;
- //delete[] buf;
- buf = NULL;
+ delete[] buf;
+ return false;
}
- return buf;
+ memcpy(out, buf, olen);
+ delete[] buf;
+ return true;
}
bool setStruct(std::string name, std::string format, void *value)