From 83494a171723c5cb86eb43f13bf5cc1e43d386b3 Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 5 Oct 2011 13:18:45 +0300 Subject: Modify generation pipeline: add "make_coasts" and "emit_coasts" options to generate and get coastlines from different sources. --- generator/feature_generator.cpp | 67 ++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 14 deletions(-) (limited to 'generator/feature_generator.cpp') diff --git a/generator/feature_generator.cpp b/generator/feature_generator.cpp index af4b1379d5..95e89d19cd 100644 --- a/generator/feature_generator.cpp +++ b/generator/feature_generator.cpp @@ -251,30 +251,58 @@ public: class MainFeaturesEmitter { - Polygonizer m_countries; - + scoped_ptr > m_countries; scoped_ptr > m_world; scoped_ptr m_coasts; scoped_ptr m_coastsHolder; + string m_srcCoastsFile; uint32_t m_coastType; + template class CombinedEmitter + { + T1 * m_p1; + T2 * m_p2; + public: + CombinedEmitter(T1 * p1, T2 * p2) : m_p1(p1), m_p2(p2) {} + void operator() (FeatureBuilder1 const & fb, uint64_t) + { + if (m_p1) (*m_p1)(fb); + if (m_p2) (*m_p2)(fb); + } + }; + public: MainFeaturesEmitter(GenerateInfo const & info) - : m_countries(info) { { - static char const * path[] = {"natural", "coastline"}; + static char const * path[] = { "natural", "coastline" }; m_coastType = classif().GetTypeByPath(vector(path, path + 2)); } - if (info.m_createWorld) + m_srcCoastsFile = info.m_tmpDir + WORLD_COASTS_FILE_NAME + info.m_datFileSuffix; + + if (!info.m_makeCoasts) + { + m_countries.reset(new Polygonizer(info)); + + if (info.m_emitCoasts) + { + m_coastsHolder.reset(new FeaturesCollector( + info.m_datFilePrefix + WORLD_COASTS_FILE_NAME + info.m_datFileSuffix)); + } + } + else { - m_world.reset(new WorldMapGenerator(info)); // 6 - is cell level for oceans covering m_coasts.reset(new CoastlineFeaturesGenerator(m_coastType, 6)); - m_coastsHolder.reset(new FeaturesCollector( - info.m_datFilePrefix + WORLD_COASTS_FILE_NAME + info.m_datFileSuffix)); + + m_coastsHolder.reset(new FeaturesCollector(m_srcCoastsFile)); + } + + if (info.m_createWorld) + { + m_world.reset(new WorldMapGenerator(info)); } } @@ -296,7 +324,8 @@ public: if (m_world) (*m_world)(fb); - m_countries(fb); + if (m_countries) + (*m_countries)(fb); } } @@ -315,15 +344,25 @@ public: { FeatureBuilder1 fb; if (m_coasts->GetFeature(i, fb)) - { (*m_coastsHolder)(fb); - m_countries(fb); - } } } + else if (m_coastsHolder) + { + CombinedEmitter< + FeaturesCollector, + Polygonizer > emitter(m_coastsHolder.get(), m_countries.get()); + feature::ForEachFromDatRawFormat(m_srcCoastsFile, emitter); + } } - inline vector const & GetNames() const { return m_countries.Names(); } + inline void GetNames(vector & names) const + { + if (m_countries) + names = m_countries->Names(); + else + names.clear(); + } }; } @@ -344,7 +383,7 @@ bool GenerateImpl(GenerateInfo & info) ParseXMLFromStdIn(parser); bucketer.Finish(); - info.m_bucketNames = bucketer.GetNames(); + bucketer.GetNames(info.m_bucketNames); } catch (Reader::Exception const & e) { -- cgit v1.2.3