#ifndef __GEOWORLD_CONFIGURATION_INTERFACES_H__ #define __GEOWORLD_CONFIGURATION_INTERFACES_H__ #include #include #include "linalgadapt.h" #include "gwtypes.h" #include "mindbtypes.h" namespace geoworld { struct SynthesisSessionConfig { struct { unsigned short count; mars::RangeX< unsigned short > morphcount; } passes; struct { unsigned short layercount; mars::RangeX< unsigned short > classcount; } geohost; struct { unsigned short morphcount; unsigned short lod; float coarseness; } macro; unsigned short tiledim; }; class ISynthesisSessionConfigReader { public: virtual bool load (SynthesisSessionConfig & cfg) = 0; }; struct DepositSynthesizerSettings { struct { size_t count; // Number of layers in the strata mars::RangeX< size_t > classes; // Range of how many different mineral classes to synthesize in the world mars::Range< unsigned char > silica; // Range of how much silica mineral classifications should have float coarseness; // Midpoint displacement noise level for generating strata struct { GeoHeightMap::Precision base; // The base thickness of each layer of strata (in plaxels) float curve; // Value between (0, 1] that determines how quickly strata thickness grows from layer to layer deep float scale; // A scaling factor for layer thickness over and above the base } thickness; } layers; struct { float frequency; // Approximate number of minerals per 1000 pixels cubed per pass, actual synthesis may be more due to nested/hosted minerals mars::RangeX< unsigned long > neighborhood; // Minimum/maximum radius that a neighborhood of rock is sampled for determining appropriate minerals to synthesize at that location. struct { float curve; // Value between (0, 1] that determines how quickly mineral abundance increases } abundance; struct { float curve, // Value between (0, 1] that determines how quickly deposit size grows from the minimum base; // The minimum deposit size struct { mars::RangeX< float > deviation; // Amount of sphere-pack deviation along the vein mars::RangeX< unsigned short > detail; // Min/max of sphere-pack sub-division iterations, larger means very crooked veins float erratic; // Degree of erratic angular placement of spheres } vein; struct { mars::RangeX< float > orthogonality; // RangeX between 0.0 and 1.0 determining the degree of alignment with the vertical axis mars::RangeX< float > deviation; // Amount of sphere-pack deviation along the dike } dike; struct { mars::RangeX< float > tail; // Minimum/maximum size of the laccolith's tail (like the tail of an upside down teardrop) relative to deposit size } laccolith; mars::RangeX< size_t > nesting; // Minimum/maximum number of nested hosted minerals to allow } deposit; struct { WorldUnit limit, minimum, maxtier; mars::RangeX< float > sizeflux; mars::RangeX< unsigned short > kidflux; } spherepack; } minerals; }; class IDepositSynthConfigReader { public: virtual bool load (DepositSynthesizerSettings & settings) = 0; }; // TODO: Support more detail class GMRegistryException : public std::exception { private: std::string _msg; public: GMRegistryException(const std::string & sMsg) : _msg(sMsg) {} virtual const char * what() const noexcept { return _msg.c_str(); } }; class GMMalformedConfigEx : public GMRegistryException { public: GMMalformedConfigEx(const std::string & sMsg) : GMRegistryException(sMsg) {} }; class GMInvalidFactoryConfigEx : public GMRegistryException { public: GMInvalidFactoryConfigEx (const std::string & sMsg = "Invalid factory configuration") : GMRegistryException(sMsg) {} }; class GMInvalidPropertyEx : public GMInvalidFactoryConfigEx { public: std::string key; GMInvalidPropertyEx (const std::string & sKeyProp, const std::string & sMsg = "Invalid property") : key(sKeyProp), GMInvalidFactoryConfigEx(sKeyProp + ": " + sMsg) {} }; class GMIndexOutOfBoundsEx : public GMInvalidFactoryConfigEx { public: size_t index; GMIndexOutOfBoundsEx (const size_t & nIdx, const std::string & sMsg = "Index out of bounds") : index(nIdx), GMInvalidFactoryConfigEx(sMsg) {} }; class IConfigSection; class IConfigSequence; class IConfigValue { protected: template< typename T, typename M > inline mars::RangeX< T > convertRange (const mars::RangeX< M > & rngFrom) const { return mars::RangeX< T > ( static_cast< T > (rngFrom.minimum), static_cast< T > (rngFrom.maximum), static_cast< T > (rngFrom.step) ); } virtual mars::RangeX< double > toDoubleRange () const { auto dummy = mars::RangeX< double >(); return toRange(dummy); } virtual mars::RangeX< long > toLongRange () const { auto dummy = mars::RangeX< long >(); return toRange(dummy); } virtual mars::RangeX< double > & toRange (mars::RangeX< double > & out) const = 0; virtual mars::RangeX< long > & toRange (mars::RangeX< long > & out) const = 0; public: virtual IConfigSection * operator >> (IConfigSection * & pSection) const = 0; virtual IConfigSequence * operator >> (IConfigSequence * & pSequence) const = 0; virtual std::string & operator >> (std::string & out) const = 0; virtual float & operator >> (float & out) const = 0; virtual bool & operator >> (bool & out) const = 0; virtual unsigned int & operator >> (unsigned int & out) const = 0; virtual unsigned short & operator >> (unsigned short & out) const = 0; virtual VectorTag< GeoHeightMap::Precision >::V2 & operator >> (VectorTag< GeoHeightMap::Precision >::V2 & out) const = 0; virtual VectorTag< GeoHeightMap::Precision >::V3 & operator >> (VectorTag< GeoHeightMap::Precision >::V3 & out) const = 0; mars::RangeX< long > & operator >> (mars::RangeX< long > & out) const { return out = toRange(out); } mars::RangeX< double > & operator >> (mars::RangeX< double > & out) const { return out = toRange(out); } mars::RangeX< float > & operator >> (mars::RangeX< float > & out) const { return out = convertRange< float > (toDoubleRange()); } mars::RangeX< int > & operator >> (mars::RangeX< int > & out) const { return out = convertRange< int > (toLongRange()); } mars::RangeX< short > & operator >> (mars::RangeX< short > & out) const { return out = convertRange< short > (toLongRange()); } mars::RangeX< unsigned int > & operator >> (mars::RangeX< unsigned int > & out) const { return out = convertRange< unsigned int > (toLongRange()); } mars::RangeX< unsigned short > & operator >> (mars::RangeX< unsigned short > & out) const { return out = convertRange< unsigned short > (toLongRange()); } }; template< typename K > class TemplConfigAggregate { private: template< typename T, typename M > mars::RangeX< T > getrng(const K & key, const T, const M) { mars::RangeX< M > rng; *operator [] (key) >> rng; return mars::RangeX< T > (static_cast< T > (rng.minimum), static_cast< T > (rng.maximum)); } public: virtual const IConfigValue * operator [] (const K & key) const = 0; template< typename T > T get(const K & key, T * = NULL) { T val; return *operator [] (key) >> val; } std::string getstr(const K & key) { std::string str; return *operator [] (key) >> str; } IConfigSection * getmap(const K & key) { IConfigSection * pSection; return *operator [] (key) >> pSection; } IConfigSequence * getseq(const K & key) { IConfigSequence * pSequence; return *operator [] (key) >> pSequence; } inline mars::RangeX< float > getrngf(const K & key) { return getrng(key, 0.0f, 0.0); } inline mars::RangeX< double > getrngd(const K & key) { return getrng(key, 0.0, 0.0); } inline mars::RangeX< short > getrngs(const K & key) { return getrng(key, static_cast (0), 0L); } inline mars::RangeX< int > getrngi(const K & key) { return getrng(key, 0, 0L); } inline mars::RangeX< long > getrngl(const K & key) { return getrng(key, 0L, 0L); } }; class IConfigSection : public TemplConfigAggregate< std::string > {}; class IConfigSequence : public TemplConfigAggregate< size_t > {}; class IConfigFactoryBase { public: const std::string factory, nom; IConfigFactoryBase(const std::string & factory) : factory(factory), nom(factory) {} IConfigFactoryBase(const std::string & factory, const std::string & name) : factory(factory), nom(name) {} virtual IConfigSection * getSection() = 0; virtual ~IConfigFactoryBase() = 0; }; enum GeoTemplatePhase { GTP_Pre = 0, GTP_Post = 1, CountGTP = 2 }; class IConfigGMFactory : public IConfigFactoryBase { public: const struct Settings { float frequency; } settings; IConfigGMFactory(const std::string & factory, const Settings & settings) : IConfigFactoryBase(factory), settings(settings) {} IConfigGMFactory(const std::string & factory, const std::string & name, const Settings & settings) : IConfigFactoryBase(factory, name), settings(settings) {} }; class IConfigGTFactory : public IConfigFactoryBase { public: const struct Settings { GeoTemplatePhase phase; } settings; IConfigGTFactory(const std::string & factory, const Settings & settings) : IConfigFactoryBase(factory), settings(settings) {} IConfigGTFactory(const std::string & factory, const std::string & name, const Settings & settings) : IConfigFactoryBase(factory, name), settings(settings) {} }; class IFactoryConfigReader { public: virtual IConfigFactoryBase * readNext () = 0; }; } #endif