source: Revenant/terrain-generator/main.cpp@ dd8f5b4

Last change on this file since dd8f5b4 was dd8f5b4, checked in by Jonathan Neufeld <support@…>, 4 years ago

(WIP) GD Native module

  • Property mode set to 100755
File size: 6.7 KB
RevLine 
[dd8f5b4]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
13// Will have to replace these
14// #include <yamlogrecfgreader.h>
15
16using namespace geoworld;
17using namespace mars;
18using namespace std;
19
20template< typename T >
21ostream & operator << (ostream & print, const BBox< T > & bbox)
22{
23 print << "[" << bbox.left << "x" << bbox.top << ", " << bbox.right << "x" << bbox.bottom << "]";
24 return print;
25}
26
27class ConsoleListener : public geoworld::ISynthesisSessionListener
28{
29public:
30 virtual void onRaster( GeoWorld * const pWorld )
31 {
32 cout << "Rastering..." << std::endl;
33 }
34
35 virtual void onRejects( GeoWorld * const pWorld, const MorphList & rejects )
36 {
37 cout << "Rejects: " << std::endl;
38
39 for (MorphList::const_iterator i = rejects.begin(); i != rejects.end(); ++i)
40 cout << "\t- " << (*i)->getTypeName() << std::endl;
41
42 cout << std::endl;
43 }
44
45 virtual void onInitMorph( GeoWorld * const pWorld, const GeoMorph * pMorph )
46 {
47 cout << "Initialize Morph: " << pMorph->getTypeName();
48
49 const BoundedGeoMorph *pBGM = dynamic_cast< const BoundedGeoMorph * >(pMorph);
50 if (NULL != pBGM)
51 {
52 cout << ", bbox=" << pBGM->getBBox();
53 }
54 cout << std::endl;
55 }
56
57 virtual void onGenerate( GeoWorld * const pWorld )
58 {
59 cout << "Generating world at LOD " << pWorld->getLOD() << std::endl;
60 }
61
62 virtual void onDoMorph (GeoWorld * const pWorld, mars::ptr< GeoMorph > & pGM, const size_t i, const size_t nTotal)
63 {
64 cout << "Morph " << typeid(*pGM).name() << ", " << (i + 1) << " of " << nTotal << std::endl;
65 }
66
67 virtual void onCreateMiddleTier (GeoWorld * const pWorld, const std::string & sFileName)
68 {
69 cout << "Generating Pageable-World File \"" << sFileName << "\"" << std::endl;
70 }
71
72 virtual void onGenerateMiddleTier (GeoWorld * const pWorld, const PagedGeoWorld * const pPgWorld)
73 {
74 cout << "Dumping a sample" << std::endl;
75
76 const LockedGWSection * pSection = pPgWorld->lockro(-500, -500, 2000, 1000);
77
78 *pSection >> GLOBALDEM;
79 DUMP_GLOBALDEM();
80
81 pPgWorld->unlock(pSection);
82 }
83
84 virtual void onPrepareMorphs( GeoWorld * const pWorld, const MorphList & morphs )
85 {
86 cout << "Chosen morphs: " << std::endl;
87
88 for (MorphList::const_iterator i = morphs.begin(); i != morphs.end(); ++i)
89 cout << "\t- " << (*i)->getTypeName() << std::endl;
90
91 cout << std::endl;
92 }
93
94 virtual void onPrepareMorphs2( PagedGeoWorld * const pPgWorld, const unsigned short nPass, const MorphList & morphs )
95 {
96 cout << "P" << nPass << ": " << "Chosen morphs: " << std::endl;
97
98 for (MorphList::const_iterator i = morphs.begin(); i != morphs.end(); ++i)
99 cout << "\t- " << (*i)->getTypeName() << std::endl;
100
101 cout << std::endl;
102 }
103
104 virtual void onInitMorph2( PagedGeoWorld * const pPgWorld, const unsigned short nPass, const GeoMorph * pMorph )
105 {
106 cout << "P" << nPass << ": " << "Initialize Morph: " << pMorph->getTypeName();
107
108 const BoundedGeoMorph *pBGM = dynamic_cast< const BoundedGeoMorph * >(pMorph);
109 if (NULL != pBGM)
110 {
111 cout << ", bbox=" << pBGM->getBBox();
112 }
113 cout << std::endl;
114 }
115
116 virtual void onDoMorph2( PagedGeoWorld * const pPgWorld, const unsigned short nPass, mars::ptr< GeoMorph > & pGM, const size_t i, const size_t nTotal )
117 {
118 cout << "P" << nPass << ": " << "Morph " << typeid(*pGM).name() << ", " << (i + 1) << " of " << nTotal << std::endl;
119 }
120
121 virtual void onRaster2( PagedGeoWorld * const pPgWorld, const unsigned short nPass )
122 {
123 cout << "P" << nPass << ": " << "Rastering..." << std::endl;
124 }
125
126 virtual void onPass2( PagedGeoWorld * const pPgWorld, const unsigned short nPass )
127 {
128 cout << "Begin pass #" << nPass << std::endl;
129 }
130
131 virtual void onGenerate2( PagedGeoWorld * const pPgWorld )
132 {
133 cout << "Generating world at LOD " << pPgWorld->getLOD() << std::endl;
134 }
135
136 virtual void onRejects2( PagedGeoWorld * const pPgWorld, const unsigned short nPass, const MorphList & rejects )
137 {
138 cout << "P" << nPass << ": " << "Rejects: " << std::endl;
139
140 for (MorphList::const_iterator i = rejects.begin(); i != rejects.end(); ++i)
141 cout << "\t- " << (*i)->getTypeName() << std::endl;
142
143 cout << std::endl;
144 }
145
146 virtual void onGenerateGeoHostLayers (GeoWorld * const pWorld, DepositSynthesizer * const pDepSynth)
147 {
148 cout << "Generating Geology Host layers..." << std::endl;
149 }
150
151 virtual void onSpawnMinerals (GeoWorld * const pWorld, DepositSynthesizer * const pDepSynth)
152 {
153 cout << "Generating some minerals..." << std::endl;
154 }
155 virtual void onSpawnMinerals2 (PagedGeoWorld * const pPgWorld, const unsigned short nPass, DepositSynthesizer * const pDepSynth)
156 {
157 cout << "Generating some minerals..." << std::endl;
158 }
159};
160
161int main ()
162{
163 using namespace mars;
164 using namespace geoworld;
165 using namespace genesis;
166
167 Log::getSingleton().setLevel(Log::Debug);
168 Log::getSingleton().addSettings(Log_File | Log_Line);
169 std::ifstream in("../DB/gmfactories.yaml", std::ios_base::in);
170
171 if (!in)
172 return -1;
173
174 DefaultGMRegistry registry;
175 YAMLGeoMorphConfigReader cfgin(in);
176
177 /*time_t t;
178
179 time(&t);
180 srand(t);
181 const unsigned int nSeed = rand();
182 srand(nSeed);
183 LOGN << nSeed;*/
184
185 registry.configure(cfgin);
186 //registry.unregisterFactory("mountains");
187 //registry.unregisterFactory("outflowchannels");
188 //registry.unregisterFactory("volcano");
189 //registry.unregisterFactory("crater");
190 //registry.unregisterFactory("winderosion");
191
192 SynthesisSession sess;
193 ConsoleListener listener;
194 std::ifstream
195 incfg("../DB/genesis.yaml", std::ios::in),
196 indepsynthcfg("../DB/depsynth.yaml", std::ios::in);
197
198 auto minerals = MineralsYAMLReader("../DB/minerals.yaml", "../DB/classes.yaml", NULL);
199 auto deposits = YAMLDepositSynthCfgReader (indepsynthcfg);
200 auto cfg = YAMLSynthSessCfgReader(incfg);
201
202 if (
203 sess.init(
204 minerals,
205 deposits,
206 cfg
207 )
208 )
209 {
210 sess.setTileDim(128);
211 sess.addListener(&listener);
212 sess.generate("mytest.pgw", registry, 4000, 2000, 20000);
213 } else
214 cout << "Error during initialization" << std::endl;
215
216/*
217#ifdef _GWDEBUG
218 const PagedGeoWorld & world = sess.getWorld();
219 const unsigned int
220 nXI = world.getWorldWidth() >> 3,
221 nYI = world.getWorldHeight() >> 3;
222
223 for (unsigned int j = 0; j < world.getWorldHeight(); j += nYI)
224 for (unsigned int i = 0; i < world.getWorldWidth(); i += nXI)
225 {
226 const LockedGWSection * pSection = world.lockro(i, j, nXI, nYI, false);
227 *pSection >> GLOBALDEM;
228 DUMP_GLOBALDEM();
229 world.unlock(pSection);
230 }
231
232#endif*/
233
234 cout << "Finished." << std::endl;
235
236 std::cin.get();
237 return 0;
238}
Note: See TracBrowser for help on using the repository browser.