]> git.mxchange.org Git - simgear.git/commitdiff
Be more conservative and reuse SSG objects.
authordavid <david>
Wed, 5 Jun 2002 19:12:50 +0000 (19:12 +0000)
committerdavid <david>
Wed, 5 Jun 2002 19:12:50 +0000 (19:12 +0000)
simgear/sky/cloud.cxx

index cae48fdbbd49bcf088611da7741b9b1d5f69a504..4f9b5a15d05a92802fb1b25c9b2eb33e5b16e0a1 100644 (file)
@@ -38,21 +38,23 @@ SGCloudLayer::layer_states[SGCloudLayer::SG_MAX_CLOUD_TYPES];
 
 // Constructor
 SGCloudLayer::SGCloudLayer( const string &tex_path )
-  : layer_root(0),
-    layer_transform(0),
+  : layer_root(new ssgRoot),
+    layer_transform(new ssgTransform),
+    layer(0),
     texture_path(tex_path),
     layer_asl(0),
     layer_thickness(0),
     layer_transition(0),
     layer_type(SG_CLOUD_CLEAR)
 {
+    layer_root->addKid(layer_transform);
     rebuild();
 }
 
 // Destructor
 SGCloudLayer::~SGCloudLayer()
 {
-    delete layer_root;
+    delete layer_root;         // deletes layer_transform and layer as well
 }
 
 float
@@ -150,12 +152,6 @@ SGCloudLayer::rebuild()
       layer_states[SG_CLOUD_CLEAR] = 0;
     }
 
-                               // This should automatically delete
-                               // layer_transform as well.
-    delete layer_root;
-    layer_root = 0;
-    layer_transform = 0;
-
     scale = 4000.0;
 
     last_lon = last_lat = -999.0f;
@@ -196,23 +192,17 @@ SGCloudLayer::rebuild()
     vl->add( vertex );
     tl->add( tc );
 
-    ssgLeaf *layer = 
-       new ssgVtxTable ( GL_TRIANGLE_STRIP, vl, NULL, tl, cl );
+    if (layer != 0)
+      layer_transform->removeKid(layer); // automatic delete
+    layer = new ssgVtxTable ( GL_TRIANGLE_STRIP, vl, NULL, tl, cl );
     if (layer_states[layer_type] != 0)
       layer->setState( layer_states[layer_type] );
 
     // force a repaint of the moon colors with arbitrary defaults
     repaint( color );
 
-    // build the ssg scene graph sub tree for the sky and connected
-    // into the provide scene graph branch
-    layer_transform = new ssgTransform;
-
     // moon_transform->addKid( halo );
     layer_transform->addKid( layer );
-
-    layer_root = new ssgRoot;
-    layer_root->addKid( layer_transform );
 }