]> git.mxchange.org Git - flightgear.git/commitdiff
Choose a random splash texture
authoronox <denkpadje@gmail.com>
Sun, 31 May 2015 16:16:04 +0000 (18:16 +0200)
committeronox <denkpadje@gmail.com>
Sun, 31 May 2015 22:51:24 +0000 (00:51 +0200)
Signed-off-by: onox <denkpadje@gmail.com>
src/Viewer/splash.cxx

index 99539c7356ae2fbbbc3e5c2f9218489c24294338..1fc0555c594bfada8a41304edfe1149f6a5d3f60 100644 (file)
@@ -184,22 +184,36 @@ char *genNameString()
 
 static osg::Node* fgCreateSplashCamera()
 {
-  const char* splash_texture = fgGetString("/sim/startup/splash-texture");
-  SGSharedPtr<SGPropertyNode> style = fgGetNode("/sim/gui/style[0]", true);
-
   char *namestring = genNameString();
   fgSetString("/sim/startup/program-name", namestring);
   delete[] namestring;
 
-  SGPath tpath;
-  if (splash_texture  && strcmp(splash_texture, "")) {
-      tpath = globals->resolve_maybe_aircraft_path(splash_texture);
-      if (tpath.isNull())
-      {
-          SG_LOG( SG_VIEW, SG_ALERT, "Cannot find splash screen file '" << splash_texture
-                  << "'. Using default." );
-      }
-  }
+    simgear::PropertyList textures = fgGetNode("/sim/startup", true)->getChildren("splash-texture");
+    std::vector<SGPath> useable_textures;
+    SGPath tpath;
+
+    // Build a list of textures that are usable; those whose path can be resolved
+    for (simgear::PropertyList::iterator it = textures.begin(); it != textures.end(); it++) {
+        std::string value = (*it)->getStringValue();
+        if (!value.empty()) {
+            tpath = globals->resolve_maybe_aircraft_path(value);
+            if (!tpath.isNull()) {
+                useable_textures.push_back(tpath);
+            }
+            else {
+                SG_LOG(SG_VIEW, SG_ALERT, "Cannot find splash screen file '" << value << "'");
+            }
+        }
+    }
+
+    // Seed the RNG in order to get randomness
+    sg_srandom_time();
+
+    if (!useable_textures.empty()) {
+        // Select a random useable texture
+        const int index = (int)(sg_random() * useable_textures.size());
+        tpath = useable_textures[index];
+    }
 
   if (tpath.isNull()) {
     // no splash screen specified - select random image
@@ -214,6 +228,8 @@ static osg::Node* fgCreateSplashCamera()
     tpath.concat( ".png" );
   }
 
+  SGSharedPtr<SGPropertyNode> style = fgGetNode("/sim/gui/style[0]", true);
+
   osg::Texture2D* splashTexture = new osg::Texture2D;
   splashTexture->setImage(osgDB::readImageFile(tpath.c_str()));