1 | #ifndef __GEOWORLD_CONFIGURATION_INTERFACES_H__
|
---|
2 | #define __GEOWORLD_CONFIGURATION_INTERFACES_H__
|
---|
3 |
|
---|
4 | #include <mars_util.h>
|
---|
5 | #include <string>
|
---|
6 |
|
---|
7 | #include "linalgadapt.h"
|
---|
8 | #include "gwtypes.h"
|
---|
9 | #include "mindbtypes.h"
|
---|
10 |
|
---|
11 | namespace geoworld
|
---|
12 | {
|
---|
13 | struct MetaConfig
|
---|
14 | {
|
---|
15 | struct
|
---|
16 | {
|
---|
17 | std::string genesis, gmfactories, depsynth, minerals, classes;
|
---|
18 | } resources;
|
---|
19 | };
|
---|
20 |
|
---|
21 | class IMetaConfigReader
|
---|
22 | {
|
---|
23 | public:
|
---|
24 | virtual bool load (MetaConfig & cfg) = 0;
|
---|
25 | };
|
---|
26 |
|
---|
27 | struct SynthesisSessionConfig
|
---|
28 | {
|
---|
29 | struct
|
---|
30 | {
|
---|
31 | unsigned short count;
|
---|
32 | mars::RangeX< unsigned short > morphcount;
|
---|
33 | } passes;
|
---|
34 | struct
|
---|
35 | {
|
---|
36 | unsigned short layercount;
|
---|
37 | mars::RangeX< unsigned short > classcount;
|
---|
38 | } geohost;
|
---|
39 | struct
|
---|
40 | {
|
---|
41 | unsigned short morphcount;
|
---|
42 | unsigned short lod;
|
---|
43 | float coarseness;
|
---|
44 | } macro;
|
---|
45 | unsigned short tiledim;
|
---|
46 | };
|
---|
47 |
|
---|
48 | class ISynthesisSessionConfigReader
|
---|
49 | {
|
---|
50 | public:
|
---|
51 | virtual bool load (SynthesisSessionConfig & cfg) = 0;
|
---|
52 | };
|
---|
53 |
|
---|
54 | struct DepositSynthesizerSettings
|
---|
55 | {
|
---|
56 | struct
|
---|
57 | {
|
---|
58 | size_t count; // Number of layers in the strata
|
---|
59 | mars::RangeX< size_t > classes; // Range of how many different mineral classes to synthesize in the world
|
---|
60 | mars::Range< unsigned char > silica; // Range of how much silica mineral classifications should have
|
---|
61 | float coarseness; // Midpoint displacement noise level for generating strata
|
---|
62 | struct
|
---|
63 | {
|
---|
64 | GeoHeightMap::Precision base; // The base thickness of each layer of strata (in plaxels)
|
---|
65 | float curve; // Value between (0, 1] that determines how quickly strata thickness grows from layer to layer deep
|
---|
66 | float scale; // A scaling factor for layer thickness over and above the base
|
---|
67 | } thickness;
|
---|
68 | } layers;
|
---|
69 | struct
|
---|
70 | {
|
---|
71 | float frequency; // Approximate number of minerals per 1000 pixels cubed per pass, actual synthesis may be more due to nested/hosted minerals
|
---|
72 | mars::RangeX< unsigned long > neighborhood; // Minimum/maximum radius that a neighborhood of rock is sampled for determining appropriate minerals to synthesize at that location.
|
---|
73 | struct
|
---|
74 | {
|
---|
75 | float curve; // Value between (0, 1] that determines how quickly mineral abundance increases
|
---|
76 | } abundance;
|
---|
77 | struct
|
---|
78 | {
|
---|
79 | float curve, // Value between (0, 1] that determines how quickly deposit size grows from the minimum
|
---|
80 | base; // The minimum deposit size
|
---|
81 |
|
---|
82 | struct
|
---|
83 | {
|
---|
84 | mars::RangeX< float > deviation; // Amount of sphere-pack deviation along the vein
|
---|
85 | mars::RangeX< unsigned short > detail; // Min/max of sphere-pack sub-division iterations, larger means very crooked veins
|
---|
86 | float erratic; // Degree of erratic angular placement of spheres
|
---|
87 | } vein;
|
---|
88 | struct
|
---|
89 | {
|
---|
90 | mars::RangeX< float > orthogonality; // RangeX between 0.0 and 1.0 determining the degree of alignment with the vertical axis
|
---|
91 | mars::RangeX< float > deviation; // Amount of sphere-pack deviation along the dike
|
---|
92 | } dike;
|
---|
93 | struct
|
---|
94 | {
|
---|
95 | mars::RangeX< float > tail; // Minimum/maximum size of the laccolith's tail (like the tail of an upside down teardrop) relative to deposit size
|
---|
96 | } laccolith;
|
---|
97 |
|
---|
98 | mars::RangeX< size_t > nesting; // Minimum/maximum number of nested hosted minerals to allow
|
---|
99 | } deposit;
|
---|
100 |
|
---|
101 | struct
|
---|
102 | {
|
---|
103 | WorldUnit
|
---|
104 | limit,
|
---|
105 | minimum,
|
---|
106 | maxtier;
|
---|
107 | mars::RangeX< float >
|
---|
108 | sizeflux;
|
---|
109 | mars::RangeX< unsigned short >
|
---|
110 | kidflux;
|
---|
111 | } spherepack;
|
---|
112 | } minerals;
|
---|
113 | };
|
---|
114 |
|
---|
115 | class IDepositSynthConfigReader
|
---|
116 | {
|
---|
117 | public:
|
---|
118 | virtual bool load (DepositSynthesizerSettings & settings) = 0;
|
---|
119 | };
|
---|
120 |
|
---|
121 | // TODO: Support more detail
|
---|
122 | class GMRegistryException : public std::exception
|
---|
123 | {
|
---|
124 | private:
|
---|
125 | std::string _msg;
|
---|
126 |
|
---|
127 | public:
|
---|
128 | GMRegistryException(const std::string & sMsg)
|
---|
129 | : _msg(sMsg) {}
|
---|
130 |
|
---|
131 | virtual const char * what() const noexcept { return _msg.c_str(); }
|
---|
132 | };
|
---|
133 | class GMMalformedConfigEx : public GMRegistryException
|
---|
134 | {
|
---|
135 | public:
|
---|
136 | GMMalformedConfigEx(const std::string & sMsg)
|
---|
137 | : GMRegistryException(sMsg) {}
|
---|
138 | };
|
---|
139 | class GMInvalidFactoryConfigEx : public GMRegistryException
|
---|
140 | {
|
---|
141 | public:
|
---|
142 | GMInvalidFactoryConfigEx (const std::string & sMsg = "Invalid factory configuration")
|
---|
143 | : GMRegistryException(sMsg) {}
|
---|
144 | };
|
---|
145 | class GMInvalidPropertyEx : public GMInvalidFactoryConfigEx
|
---|
146 | {
|
---|
147 | public:
|
---|
148 | std::string key;
|
---|
149 |
|
---|
150 | GMInvalidPropertyEx (const std::string & sKeyProp, const std::string & sMsg = "Invalid property")
|
---|
151 | : key(sKeyProp), GMInvalidFactoryConfigEx(sKeyProp + ": " + sMsg) {}
|
---|
152 | };
|
---|
153 | class GMIndexOutOfBoundsEx : public GMInvalidFactoryConfigEx
|
---|
154 | {
|
---|
155 | public:
|
---|
156 | size_t index;
|
---|
157 |
|
---|
158 | GMIndexOutOfBoundsEx (const size_t & nIdx, const std::string & sMsg = "Index out of bounds")
|
---|
159 | : index(nIdx), GMInvalidFactoryConfigEx(sMsg) {}
|
---|
160 | };
|
---|
161 |
|
---|
162 | class IConfigSection;
|
---|
163 | class IConfigSequence;
|
---|
164 |
|
---|
165 | class IConfigValue
|
---|
166 | {
|
---|
167 | protected:
|
---|
168 | template< typename T, typename M >
|
---|
169 | inline mars::RangeX< T > convertRange (const mars::RangeX< M > & rngFrom) const
|
---|
170 | {
|
---|
171 | return mars::RangeX< T > (
|
---|
172 | static_cast< T > (rngFrom.minimum),
|
---|
173 | static_cast< T > (rngFrom.maximum),
|
---|
174 | static_cast< T > (rngFrom.step)
|
---|
175 | );
|
---|
176 | }
|
---|
177 |
|
---|
178 | virtual mars::RangeX< double > toDoubleRange () const {
|
---|
179 | auto dummy = mars::RangeX< double >();
|
---|
180 | return toRange(dummy);
|
---|
181 | }
|
---|
182 | virtual mars::RangeX< long > toLongRange () const {
|
---|
183 | auto dummy = mars::RangeX< long >();
|
---|
184 | return toRange(dummy);
|
---|
185 | }
|
---|
186 |
|
---|
187 | virtual mars::RangeX< double > & toRange (mars::RangeX< double > & out) const = 0;
|
---|
188 | virtual mars::RangeX< long > & toRange (mars::RangeX< long > & out) const = 0;
|
---|
189 |
|
---|
190 | public:
|
---|
191 | virtual IConfigSection * operator >> (IConfigSection * & pSection) const = 0;
|
---|
192 | virtual IConfigSequence * operator >> (IConfigSequence * & pSequence) const = 0;
|
---|
193 | virtual std::string & operator >> (std::string & out) const = 0;
|
---|
194 | virtual float & operator >> (float & out) const = 0;
|
---|
195 | virtual bool & operator >> (bool & out) const = 0;
|
---|
196 | virtual unsigned int & operator >> (unsigned int & out) const = 0;
|
---|
197 | virtual unsigned short & operator >> (unsigned short & out) const = 0;
|
---|
198 |
|
---|
199 | virtual VectorTag< GeoHeightMap::Precision >::V2 & operator >> (VectorTag< GeoHeightMap::Precision >::V2 & out) const = 0;
|
---|
200 | virtual VectorTag< GeoHeightMap::Precision >::V3 & operator >> (VectorTag< GeoHeightMap::Precision >::V3 & out) const = 0;
|
---|
201 |
|
---|
202 | mars::RangeX< long > & operator >> (mars::RangeX< long > & out) const
|
---|
203 | { return out = toRange(out); }
|
---|
204 | mars::RangeX< double > & operator >> (mars::RangeX< double > & out) const
|
---|
205 | { return out = toRange(out); }
|
---|
206 | mars::RangeX< float > & operator >> (mars::RangeX< float > & out) const
|
---|
207 | { return out = convertRange< float > (toDoubleRange()); }
|
---|
208 |
|
---|
209 | mars::RangeX< int > & operator >> (mars::RangeX< int > & out) const
|
---|
210 | { return out = convertRange< int > (toLongRange()); }
|
---|
211 | mars::RangeX< short > & operator >> (mars::RangeX< short > & out) const
|
---|
212 | { return out = convertRange< short > (toLongRange()); }
|
---|
213 | mars::RangeX< unsigned int > & operator >> (mars::RangeX< unsigned int > & out) const
|
---|
214 | { return out = convertRange< unsigned int > (toLongRange()); }
|
---|
215 | mars::RangeX< unsigned short > & operator >> (mars::RangeX< unsigned short > & out) const
|
---|
216 | { return out = convertRange< unsigned short > (toLongRange()); }
|
---|
217 | };
|
---|
218 |
|
---|
219 | template< typename K >
|
---|
220 | class TemplConfigAggregate
|
---|
221 | {
|
---|
222 | private:
|
---|
223 | template< typename T, typename M >
|
---|
224 | mars::RangeX< T > getrng(const K & key, const T, const M)
|
---|
225 | {
|
---|
226 | mars::RangeX< M > rng;
|
---|
227 |
|
---|
228 | *operator [] (key) >> rng;
|
---|
229 | return mars::RangeX< T > (static_cast< T > (rng.minimum), static_cast< T > (rng.maximum));
|
---|
230 | }
|
---|
231 |
|
---|
232 | public:
|
---|
233 | virtual const IConfigValue * operator [] (const K & key) const = 0;
|
---|
234 |
|
---|
235 | template< typename T >
|
---|
236 | T get(const K & key, T * = NULL)
|
---|
237 | {
|
---|
238 | T val;
|
---|
239 |
|
---|
240 | return *operator [] (key) >> val;
|
---|
241 | }
|
---|
242 | std::string getstr(const K & key)
|
---|
243 | {
|
---|
244 | std::string str;
|
---|
245 | return *operator [] (key) >> str;
|
---|
246 | }
|
---|
247 | IConfigSection * getmap(const K & key)
|
---|
248 | {
|
---|
249 | IConfigSection * pSection;
|
---|
250 | return *operator [] (key) >> pSection;
|
---|
251 | }
|
---|
252 | IConfigSequence * getseq(const K & key)
|
---|
253 | {
|
---|
254 | IConfigSequence * pSequence;
|
---|
255 | return *operator [] (key) >> pSequence;
|
---|
256 | }
|
---|
257 |
|
---|
258 | inline mars::RangeX< float > getrngf(const K & key)
|
---|
259 | { return getrng(key, 0.0f, 0.0); }
|
---|
260 | inline mars::RangeX< double > getrngd(const K & key)
|
---|
261 | { return getrng(key, 0.0, 0.0); }
|
---|
262 | inline mars::RangeX< short > getrngs(const K & key)
|
---|
263 | { return getrng(key, static_cast <short> (0), 0L); }
|
---|
264 | inline mars::RangeX< int > getrngi(const K & key)
|
---|
265 | { return getrng(key, 0, 0L); }
|
---|
266 | inline mars::RangeX< long > getrngl(const K & key)
|
---|
267 | { return getrng(key, 0L, 0L); }
|
---|
268 | };
|
---|
269 |
|
---|
270 | class IConfigSection : public TemplConfigAggregate< std::string > {};
|
---|
271 | class IConfigSequence : public TemplConfigAggregate< size_t > {};
|
---|
272 |
|
---|
273 | class IConfigFactoryBase
|
---|
274 | {
|
---|
275 | public:
|
---|
276 | const std::string factory, nom;
|
---|
277 |
|
---|
278 | IConfigFactoryBase(const std::string & factory)
|
---|
279 | : factory(factory), nom(factory) {}
|
---|
280 | IConfigFactoryBase(const std::string & factory, const std::string & name)
|
---|
281 | : factory(factory), nom(name) {}
|
---|
282 |
|
---|
283 | virtual IConfigSection * getSection() = 0;
|
---|
284 | virtual ~IConfigFactoryBase() = 0;
|
---|
285 | };
|
---|
286 |
|
---|
287 | enum GeoTemplatePhase
|
---|
288 | { GTP_Pre = 0, GTP_Post = 1, CountGTP = 2 };
|
---|
289 |
|
---|
290 | class IConfigGMFactory : public IConfigFactoryBase
|
---|
291 | {
|
---|
292 | public:
|
---|
293 | const struct Settings
|
---|
294 | {
|
---|
295 | float frequency;
|
---|
296 | } settings;
|
---|
297 |
|
---|
298 | IConfigGMFactory(const std::string & factory, const Settings & settings)
|
---|
299 | : IConfigFactoryBase(factory), settings(settings) {}
|
---|
300 | IConfigGMFactory(const std::string & factory, const std::string & name, const Settings & settings)
|
---|
301 | : IConfigFactoryBase(factory, name), settings(settings) {}
|
---|
302 | };
|
---|
303 |
|
---|
304 | class IConfigGTFactory : public IConfigFactoryBase
|
---|
305 | {
|
---|
306 | public:
|
---|
307 | const struct Settings
|
---|
308 | {
|
---|
309 | GeoTemplatePhase phase;
|
---|
310 | } settings;
|
---|
311 |
|
---|
312 | IConfigGTFactory(const std::string & factory, const Settings & settings)
|
---|
313 | : IConfigFactoryBase(factory), settings(settings) {}
|
---|
314 | IConfigGTFactory(const std::string & factory, const std::string & name, const Settings & settings)
|
---|
315 | : IConfigFactoryBase(factory, name), settings(settings) {}
|
---|
316 | };
|
---|
317 |
|
---|
318 | class IFactoryConfigReader
|
---|
319 | {
|
---|
320 | public:
|
---|
321 | virtual IConfigFactoryBase * readNext () = 0;
|
---|
322 | };
|
---|
323 |
|
---|
324 | }
|
---|
325 |
|
---|
326 | #endif
|
---|