source: Revenant/terrain-generator/main.cpp@ 25c4774

port/mars-tycoon
Last change on this file since 25c4774 was 25c4774, checked in by Jonathan Neufeld <support@…>, 3 years ago

(TEST) Corrected bug using wrong z-base (still not sure what this is)

  • Property mode set to 100755
File size: 7.9 KB
Line 
1#include <geoworld.h>
2#include <iostream>
3#include <fstream>
4#include <gmregistry.h>
5#include <gwmorphs/gmdefault.h>
6#include <yamlgmcfgrd.h>
7#include <yamlminreader.h>
8#include <yamlsessreader.h>
9#include <yamldepositsynthreader.h>
10#include <synthsession.h>
11#include <PNGDEM.h>
12#include <boost/program_options.hpp>
13
14#include <iostream>
15#include <string>
16#include <filesystem>
17#include <unistd.h>
18
19// Will have to replace these
20// #include <yamlogrecfgreader.h>
21
22using namespace geoworld;
23using namespace mars;
24using namespace std;
25using namespace genesis;
26namespace po = boost::program_options;
27
28template< typename T >
29ostream & operator << (ostream & print, const BBox< T > & bbox)
30{
31 print << "[" << bbox.left << "x" << bbox.top << ", " << bbox.right << "x" << bbox.bottom << "]";
32 return print;
33}
34
35class ConsoleListener : public geoworld::ISynthesisSessionListener
36{
37public:
38 virtual void onRaster( GeoWorld * const pWorld )
39 {
40 cout << "Rastering..." << std::endl;
41 }
42
43 virtual void onRejects( GeoWorld * const pWorld, const MorphList & rejects )
44 {
45 cout << "Rejects: " << std::endl;
46
47 for (MorphList::const_iterator i = rejects.begin(); i != rejects.end(); ++i)
48 cout << "\t- " << (*i)->getTypeName() << std::endl;
49
50 cout << std::endl;
51 }
52
53 virtual void onInitMorph( GeoWorld * const pWorld, const GeoMorph * pMorph )
54 {
55 cout << "Initialize Morph: " << pMorph->getTypeName();
56
57 const BoundedGeoMorph *pBGM = dynamic_cast< const BoundedGeoMorph * >(pMorph);
58 if (NULL != pBGM)
59 {
60 cout << ", bbox=" << pBGM->getBBox();
61 }
62 cout << std::endl;
63 }
64
65 virtual void onGenerate( GeoWorld * const pWorld )
66 {
67 cout << "Generating world at LOD " << pWorld->getLOD() << std::endl;
68 }
69
70 virtual void onDoMorph (GeoWorld * const pWorld, mars::ptr< GeoMorph > & pGM, const size_t i, const size_t nTotal)
71 {
72 cout << "Morph " << typeid(*pGM).name() << ", " << (i + 1) << " of " << nTotal << std::endl;
73 }
74
75 virtual void onCreateMiddleTier (GeoWorld * const pWorld, const std::string & sFileName)
76 {
77 cout << "Generating Pageable-World File \"" << sFileName << "\"" << std::endl;
78 }
79
80 virtual void onGenerateMiddleTier (GeoWorld * const pWorld, const PagedGeoWorld * const pPgWorld)
81 {
82 cout << "Dumping a sample" << std::endl;
83
84 const LockedGWSection * pSection = pPgWorld->lockro(-500, -500, 2000, 1000);
85
86 *pSection >> GLOBALDEM;
87 DUMP_GLOBALDEM();
88
89 pPgWorld->unlock(pSection);
90 }
91
92 virtual void onPrepareMorphs( GeoWorld * const pWorld, const MorphList & morphs )
93 {
94 cout << "Chosen morphs: " << std::endl;
95
96 for (MorphList::const_iterator i = morphs.begin(); i != morphs.end(); ++i)
97 cout << "\t- " << (*i)->getTypeName() << std::endl;
98
99 cout << std::endl;
100 }
101
102 virtual void onPrepareMorphs2( PagedGeoWorld * const pPgWorld, const unsigned short nPass, const MorphList & morphs )
103 {
104 cout << "P" << nPass << ": " << "Chosen morphs: " << std::endl;
105
106 for (MorphList::const_iterator i = morphs.begin(); i != morphs.end(); ++i)
107 cout << "\t- " << (*i)->getTypeName() << std::endl;
108
109 cout << std::endl;
110 }
111
112 virtual void onInitMorph2( PagedGeoWorld * const pPgWorld, const unsigned short nPass, const GeoMorph * pMorph )
113 {
114 cout << "P" << nPass << ": " << "Initialize Morph: " << pMorph->getTypeName();
115
116 const BoundedGeoMorph *pBGM = dynamic_cast< const BoundedGeoMorph * >(pMorph);
117 if (NULL != pBGM)
118 {
119 cout << ", bbox=" << pBGM->getBBox();
120 }
121 cout << std::endl;
122 }
123
124 virtual void onDoMorph2( PagedGeoWorld * const pPgWorld, const unsigned short nPass, mars::ptr< GeoMorph > & pGM, const size_t i, const size_t nTotal )
125 {
126 cout << "P" << nPass << ": " << "Morph " << typeid(*pGM).name() << ", " << (i + 1) << " of " << nTotal << std::endl;
127 }
128
129 virtual void onRaster2( PagedGeoWorld * const pPgWorld, const unsigned short nPass )
130 {
131 cout << "P" << nPass << ": " << "Rastering..." << std::endl;
132 }
133
134 virtual void onPass2( PagedGeoWorld * const pPgWorld, const unsigned short nPass )
135 {
136 cout << "Begin pass #" << nPass << std::endl;
137 }
138
139 virtual void onGenerate2( PagedGeoWorld * const pPgWorld )
140 {
141 cout << "Generating world at LOD " << pPgWorld->getLOD() << std::endl;
142 }
143
144 virtual void onRejects2( PagedGeoWorld * const pPgWorld, const unsigned short nPass, const MorphList & rejects )
145 {
146 cout << "P" << nPass << ": " << "Rejects: " << std::endl;
147
148 for (MorphList::const_iterator i = rejects.begin(); i != rejects.end(); ++i)
149 cout << "\t- " << (*i)->getTypeName() << std::endl;
150
151 cout << std::endl;
152 }
153
154 virtual void onGenerateGeoHostLayers (GeoWorld * const pWorld, DepositSynthesizer * const pDepSynth)
155 {
156 cout << "Generating Geology Host layers..." << std::endl;
157 }
158
159 virtual void onSpawnMinerals (GeoWorld * const pWorld, DepositSynthesizer * const pDepSynth)
160 {
161 cout << "Generating some minerals..." << std::endl;
162 }
163 virtual void onSpawnMinerals2 (PagedGeoWorld * const pPgWorld, const unsigned short nPass, DepositSynthesizer * const pDepSynth)
164 {
165 cout << "Generating some minerals..." << std::endl;
166 }
167};
168
169int main (int argc, char * argv[])
170{
171 po::options_description desc("Available options");
172 desc.add_options()
173 ("help", "How to use this utility")
174 ("cf", po::value<string>(), "Configuration files directory")
175 ("output-file", po::value< string >(), "output file");
176
177 po::positional_options_description positionals;
178 positionals.add("output-file", -1);
179
180 po::variables_map args;
181 po::store(
182 po::command_line_parser(argc, argv)
183 .options(desc)
184 .positional(positionals)
185 .run(),
186 args
187 );
188 po::notify(args);
189
190 if (args.count("help")) {
191 cout << desc << std::endl;
192 return 1;
193 }
194
195 std::string
196 cf = ".",
197 outputFile = "mytest.pgw";
198
199 if (args.count("cf"))
200 cf = args["cf"].as<std::string>();
201
202 if (args.count("output-file"))
203 outputFile = args["output-file"].as<std::string>();
204
205
206 Log::getSingleton().setLevel(Log::Debug);
207 Log::getSingleton().addSettings(Log_File | Log_Line);
208 std::ifstream in(cf + "/gmfactories.yaml", std::ios_base::in);
209
210 if (!in) {
211 cerr << "Missing factories yaml" << std::endl;
212 return -1;
213 }
214
215 DefaultGMRegistry registry;
216 YAMLGeoMorphConfigReader cfgin(in);
217
218 /*time_t t;
219
220 time(&t);
221 srand(t);
222 const unsigned int nSeed = rand();
223 srand(nSeed);
224 LOGN << nSeed;*/
225
226 registry.configure(cfgin);
227 //registry.unregisterFactory("mountains");
228 //registry.unregisterFactory("outflowchannels");
229 //registry.unregisterFactory("volcano");
230 //registry.unregisterFactory("crater");
231 //registry.unregisterFactory("winderosion");
232
233 SynthesisSession sess;
234 ConsoleListener listener;
235 std::ifstream
236 incfg(cf + "/genesis.yaml", std::ios::in),
237 indepsynthcfg(cf + "/depsynth.yaml", std::ios::in);
238
239 const std::string
240 mineralsYaml = cf + "/minerals.yaml",
241 classesYaml = cf + "/classes.yaml";
242
243 auto minerals = MineralsYAMLReader(mineralsYaml.c_str(), classesYaml.c_str(), NULL);
244 auto deposits = YAMLDepositSynthCfgReader (indepsynthcfg);
245 auto cfg = YAMLSynthSessCfgReader(incfg);
246
247 if (
248 sess.init(
249 minerals,
250 deposits,
251 cfg
252 )
253 )
254 {
255 sess.setTileDim(128);
256 sess.addListener(&listener);
257 sess.generate(outputFile, registry, 4000, 2000, 20000);
258 } else {
259 cerr << "Error during initialization" << std::endl;
260 return 42;
261 }
262
263/*
264#ifdef _GWDEBUG
265 const PagedGeoWorld & world = sess.getWorld();
266 const unsigned int
267 nXI = world.getWorldWidth() >> 3,
268 nYI = world.getWorldHeight() >> 3;
269
270 for (unsigned int j = 0; j < world.getWorldHeight(); j += nYI)
271 for (unsigned int i = 0; i < world.getWorldWidth(); i += nXI)
272 {
273 const LockedGWSection * pSection = world.lockro(i, j, nXI, nYI, false);
274 *pSection >> GLOBALDEM;
275 DUMP_GLOBALDEM();
276 world.unlock(pSection);
277 }
278
279#endif*/
280
281 cout << "Finished." << std::endl;
282
283 return 0;
284}
Note: See TracBrowser for help on using the repository browser.