From df467b9dba3cda5f537eabb236a6e0ad19b26063 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Fri, 27 Aug 2010 18:20:09 +0200 Subject: [PATCH] Let SGCloudLayer handle coverage strings This is currently handled in various places in FlightGear. --- simgear/scene/sky/cloud.cxx | 57 +++++++++++++++++++++++++++++++++++++ simgear/scene/sky/cloud.hxx | 19 +++++++++++++ 2 files changed, 76 insertions(+) diff --git a/simgear/scene/sky/cloud.cxx b/simgear/scene/sky/cloud.cxx index d7b7e2f3..5d8b09ff 100644 --- a/simgear/scene/sky/cloud.cxx +++ b/simgear/scene/sky/cloud.cxx @@ -83,6 +83,13 @@ static bool bump_mapping = false; bool SGCloudLayer::enable_bump_mapping = false; +const std::string SGCloudLayer::SG_CLOUD_OVERCAST_STRING = "overcast"; +const std::string SGCloudLayer::SG_CLOUD_BROKEN_STRING = "broken"; +const std::string SGCloudLayer::SG_CLOUD_SCATTERED_STRING = "scattered"; +const std::string SGCloudLayer::SG_CLOUD_FEW_STRING = "few"; +const std::string SGCloudLayer::SG_CLOUD_CIRRUS_STRING = "cirrus"; +const std::string SGCloudLayer::SG_CLOUD_CLEAR_STRING = "clear"; + // make an StateSet for a cloud layer given the named texture static osg::StateSet* SGMakeState(const SGPath &path, const char* colorTexture, @@ -293,6 +300,56 @@ SGCloudLayer::setCoverage (Coverage coverage) } } +const std::string & +SGCloudLayer::getCoverageString( Coverage coverage ) +{ + switch( coverage ) { + case SG_CLOUD_OVERCAST: + return SG_CLOUD_OVERCAST_STRING; + case SG_CLOUD_BROKEN: + return SG_CLOUD_BROKEN_STRING; + case SG_CLOUD_SCATTERED: + return SG_CLOUD_SCATTERED_STRING; + case SG_CLOUD_FEW: + return SG_CLOUD_FEW_STRING; + case SG_CLOUD_CIRRUS: + return SG_CLOUD_CIRRUS_STRING; + case SG_CLOUD_CLEAR: + default: + return SG_CLOUD_CLEAR_STRING; + } +} + +SGCloudLayer::Coverage +SGCloudLayer::getCoverageType( const std::string & coverage ) +{ + if( SG_CLOUD_OVERCAST_STRING == coverage ) { + return SG_CLOUD_OVERCAST; + } else if( SG_CLOUD_BROKEN_STRING == coverage ) { + return SG_CLOUD_BROKEN; + } else if( SG_CLOUD_SCATTERED_STRING == coverage ) { + return SG_CLOUD_SCATTERED; + } else if( SG_CLOUD_FEW_STRING == coverage ) { + return SG_CLOUD_FEW; + } else if( SG_CLOUD_CIRRUS_STRING == coverage ) { + return SG_CLOUD_CIRRUS; + } else { + return SG_CLOUD_CLEAR; + } +} + +const std::string & +SGCloudLayer::getCoverageString() const +{ + return getCoverageString(layer_coverage); +} + +void +SGCloudLayer::setCoverageString( const std::string & coverage ) +{ + setCoverage( getCoverageType(coverage) ); +} + void SGCloudLayer::setTextureOffset(const osg::Vec2& offset) { diff --git a/simgear/scene/sky/cloud.hxx b/simgear/scene/sky/cloud.hxx index 91a977b0..9b490fa9 100644 --- a/simgear/scene/sky/cloud.hxx +++ b/simgear/scene/sky/cloud.hxx @@ -63,6 +63,13 @@ public: SG_MAX_CLOUD_COVERAGES }; + static const std::string SG_CLOUD_OVERCAST_STRING; // "overcast" + static const std::string SG_CLOUD_BROKEN_STRING; // "broken" + static const std::string SG_CLOUD_SCATTERED_STRING; // "scattered" + static const std::string SG_CLOUD_FEW_STRING; // "few" + static const std::string SG_CLOUD_CIRRUS_STRING; // "cirrus" + static const std::string SG_CLOUD_CLEAR_STRING; // "clear" + /** * Constructor * @param tex_path the path to the set of cloud textures @@ -123,6 +130,18 @@ public: */ void setCoverage (Coverage coverage); + /** get coverage as string */ + const string & getCoverageString() const; + + /** get coverage as string */ + static const string & getCoverageString( Coverage coverage ); + + /** get coverage type from string */ + static Coverage getCoverageType( const std::string & coverage ); + + /** set coverage as string */ + void setCoverageString( const string & coverage ); + /** * set the cloud movement direction * @param dir the cloud movement direction -- 2.39.2