]> git.mxchange.org Git - simgear.git/commitdiff
Mathias Fröhlich:
authorehofman <ehofman>
Tue, 24 Jan 2006 14:44:35 +0000 (14:44 +0000)
committerehofman <ehofman>
Tue, 24 Jan 2006 14:44:35 +0000 (14:44 +0000)
Incorporating the shared ptr code:
- All scenegraph references from SimGear
- SGMaterial which already had a reference counter uses now that common
  infrastructure.
- SGMatModel is now counted.
- SGSoundSample from SimGear
- And the corresponding change for the sound samples in flightgear which fixes
  a latent crash if FGBeacon would evern be deleted.

15 files changed:
simgear/environment/visual_enviro.cxx
simgear/scene/material/mat.cxx
simgear/scene/material/mat.hxx
simgear/scene/material/matlib.cxx
simgear/scene/material/matlib.hxx
simgear/scene/material/matmodel.cxx
simgear/scene/material/matmodel.hxx
simgear/scene/model/placement.hxx
simgear/scene/sky/cloud.cxx
simgear/scene/sky/newcloud.cxx
simgear/sound/sample_openal.hxx
simgear/sound/soundmgr_openal.cxx
simgear/sound/soundmgr_openal.hxx
simgear/sound/xmlsound.cxx
simgear/sound/xmlsound.hxx

index 8daab27c86318cd33523fcfedf73296a5d76c995..41df969bea9977b73a2e11969a53dc00117b69e2 100644 (file)
@@ -26,6 +26,8 @@
 
 #include <plib/sg.h>
 #include <simgear/constants.h>
+#include <simgear/structure/SGReferenced.hxx>
+#include <simgear/structure/SGSharedPtr.hxx>
 #include <simgear/math/sg_random.h>
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/math/point3d.hxx>
@@ -655,7 +657,7 @@ void SGEnviro::drawLightning(void) {
                                double ax = 0.0, ay = 0.0;
                                ax = cos(course) * dist;
                                ay = sin(course) * dist;
-                               SGSoundSample *snd = soundMgr->find("thunder");
+                               SGSharedPtr<SGSoundSample> snd = soundMgr->find("thunder");
                                if( snd ) {
                                        ALfloat pos[3]={ax, ay, -sgEnviro.last_alt };
                                        snd->set_source_pos(pos);
index 1c1258d9597a8c9672106cac228e398cd85abdb3..ce5e78a9def381e159d6698c5df6b3d668d4843c 100644 (file)
@@ -74,10 +74,6 @@ SGMaterial::SGMaterial( ssgSimpleState *s )
 
 SGMaterial::~SGMaterial (void)
 {
-  for (unsigned int i = 0; i < object_groups.size(); i++) {
-    delete object_groups[i];
-    object_groups[i] = 0;
-  }
 }
 
 
@@ -182,7 +178,6 @@ SGMaterial::init ()
     wrapv = true;
     mipmap = true;
     light_coverage = 0.0;
-    refcount = 0;
     shininess = 1.0;
     for (int i = 0; i < 4; i++) {
         ambient[i]  = (i < 3) ? 0.2 : 1.0;
@@ -238,7 +233,6 @@ SGMaterial::build_ssg_state( bool defer_tex_load )
     for (unsigned int i = 0; i < _status.size(); i++)
     {
         ssgSimpleState *state = new ssgSimpleState();
-        state->ref();
 
         // Set up the textured state
         state->setShadeModel( shade_model );
@@ -279,9 +273,7 @@ SGMaterial::build_ssg_state( bool defer_tex_load )
 
 void SGMaterial::set_ssg_state( ssgSimpleState *s )
 {
-    _internal_state st( s, "", true );
-    st.state->ref();
-    _status.push_back( st );
+    _status.push_back( _internal_state( s, "", true ) );
 }
 
 // end of mat.cxx
index b980a0069aca80a7fd3578e3c30449236e4f026f..106b0e39915cf2a64bfa5cd571e1c91dda517371 100644 (file)
@@ -39,6 +39,8 @@
 #include <plib/ssg.h>
 
 #include <simgear/props/props.hxx>
+#include <simgear/structure/ssgSharedPtr.hxx>
+#include <simgear/structure/SGSharedPtr.hxx>
 
 #include "matmodel.hxx"
 
@@ -55,7 +57,7 @@ SG_USING_STD(vector);
  * defined in the $FG_ROOT/materials.xml file, and can be changed
  * at runtime.
  */
-class SGMaterial {
+class SGMaterial : public SGReferenced {
 
 public:
 
@@ -161,29 +163,6 @@ public:
     return object_groups[index];
   }
 
-
-  /**
-   * Increment the reference count for this material.
-   *
-   * A material with 0 references may be deleted by the
-   * material library.
-   */
-  virtual inline void ref () { refcount++; }
-
-
-  /**
-   * Decrement the reference count for this material.
-   */
-  virtual inline void deRef () { refcount--; }
-
-
-  /**
-   * Get the reference count for this material.
-   *
-   * @return The number of references (0 if none).
-   */
-  virtual inline int getRef () const { return refcount; }
-
 protected:
 
 \f
@@ -201,7 +180,7 @@ protected:
   struct _internal_state {
      _internal_state( ssgSimpleState *s, const string &t, bool l )
                   : state(s), texture_path(t), texture_loaded(l) {}
-      ssgSimpleState *state;
+      ssgSharedPtr<ssgSimpleState> state;
       string texture_path;
       bool texture_loaded;
   };
@@ -235,12 +214,7 @@ private:
   sgVec4 ambient, diffuse, specular, emission;
   double shininess;
 
-  vector<SGMatModelGroup *> object_groups;
-
-  // ref count so we can properly delete if we have multiple
-  // pointers to this record
-  int refcount;
-
+  vector<SGSharedPtr<SGMatModelGroup> > object_groups;
 
 \f
   ////////////////////////////////////////////////////////////////////
index 7264022d9353832d3ee87c9f796e684825d21014..15406eaac0ab0f4a018f2cb9e2b11491700953e9 100644 (file)
@@ -192,12 +192,11 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char
     for (int i = 0; i < nMaterials; i++) {
         const SGPropertyNode * node = materials.getChild(i);
         if (!strcmp(node->getName(), "material")) {
-            SGMaterial *m = new SGMaterial( fg_root, node, season );
+            SGSharedPtr<SGMaterial> m = new SGMaterial( fg_root, node, season );
 
             vector<SGPropertyNode_ptr>names = node->getChildren("name");
             for ( unsigned int j = 0; j < names.size(); j++ ) {
                 string name = names[j]->getStringValue();
-                m->ref();
                 // cerr << "Material " << name << endl;
                 matlib[name] = m;
                 SG_LOG( SG_TERRAIN, SG_INFO, "  Loading material "
@@ -211,7 +210,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char
 
     // hard coded ground light state
     ssgSimpleState *gnd_lights = new ssgSimpleState;
-    gnd_lights->ref();
     gnd_lights->disable( GL_TEXTURE_2D );
     gnd_lights->enable( GL_CULL_FACE );
     gnd_lights->enable( GL_COLOR_MATERIAL );
@@ -228,7 +226,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char
     // hard coded runway white light state
     tex_name = gen_standard_dir_light_map( 235, 235, 195, 255 );
     ssgSimpleState *rwy_white_lights = new ssgSimpleState();
-    rwy_white_lights->ref();
     rwy_white_lights->disable( GL_LIGHTING );
     rwy_white_lights->enable ( GL_CULL_FACE ) ;
     rwy_white_lights->enable( GL_TEXTURE_2D );
@@ -249,7 +246,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char
     // hard coded runway medium intensity white light state
     tex_name = gen_standard_dir_light_map( 235, 235, 195, 205 );
     ssgSimpleState *rwy_white_medium_lights = new ssgSimpleState();
-    rwy_white_medium_lights->ref();
     rwy_white_medium_lights->disable( GL_LIGHTING );
     rwy_white_medium_lights->enable ( GL_CULL_FACE ) ;
     rwy_white_medium_lights->enable( GL_TEXTURE_2D );
@@ -267,7 +263,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char
     // hard coded runway low intensity white light state
     tex_name = gen_standard_dir_light_map( 235, 235, 195, 155 );
     ssgSimpleState *rwy_white_low_lights = new ssgSimpleState();
-    rwy_white_low_lights->ref();
     rwy_white_low_lights->disable( GL_LIGHTING );
     rwy_white_low_lights->enable ( GL_CULL_FACE ) ;
     rwy_white_low_lights->enable( GL_TEXTURE_2D );
@@ -285,7 +280,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char
     // hard coded runway yellow light state
     tex_name = gen_standard_dir_light_map( 235, 215, 20, 255 );
     ssgSimpleState *rwy_yellow_lights = new ssgSimpleState();
-    rwy_yellow_lights->ref();
     rwy_yellow_lights->disable( GL_LIGHTING );
     rwy_yellow_lights->enable ( GL_CULL_FACE ) ;
     rwy_yellow_lights->enable( GL_TEXTURE_2D );
@@ -302,7 +296,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char
     // hard coded runway medium intensity yellow light state
     tex_name = gen_standard_dir_light_map( 235, 215, 20, 205 );
     ssgSimpleState *rwy_yellow_medium_lights = new ssgSimpleState();
-    rwy_yellow_medium_lights->ref();
     rwy_yellow_medium_lights->disable( GL_LIGHTING );
     rwy_yellow_medium_lights->enable ( GL_CULL_FACE ) ;
     rwy_yellow_medium_lights->enable( GL_TEXTURE_2D );
@@ -320,7 +313,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char
     // hard coded runway low intensity yellow light state
     tex_name = gen_standard_dir_light_map( 235, 215, 20, 155 );
     ssgSimpleState *rwy_yellow_low_lights = new ssgSimpleState();
-    rwy_yellow_low_lights->ref();
     rwy_yellow_low_lights->disable( GL_LIGHTING );
     rwy_yellow_low_lights->enable ( GL_CULL_FACE ) ;
     rwy_yellow_low_lights->enable( GL_TEXTURE_2D );
@@ -338,7 +330,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char
     // hard coded runway red light state
     tex_name = gen_standard_dir_light_map( 235, 90, 90, 255 );
     ssgSimpleState *rwy_red_lights = new ssgSimpleState();
-    rwy_red_lights->ref();
     rwy_red_lights->disable( GL_LIGHTING );
     rwy_red_lights->enable ( GL_CULL_FACE ) ;
     rwy_red_lights->enable( GL_TEXTURE_2D );
@@ -356,7 +347,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char
     // hard coded medium intensity runway red light state
     tex_name = gen_standard_dir_light_map( 235, 90, 90, 205 );
     ssgSimpleState *rwy_red_medium_lights = new ssgSimpleState();
-    rwy_red_medium_lights->ref();
     rwy_red_medium_lights->disable( GL_LIGHTING );
     rwy_red_medium_lights->enable ( GL_CULL_FACE ) ;
     rwy_red_medium_lights->enable( GL_TEXTURE_2D );
@@ -374,7 +364,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char
     // hard coded low intensity runway red light state
     tex_name = gen_standard_dir_light_map( 235, 90, 90, 155 );
     ssgSimpleState *rwy_red_low_lights = new ssgSimpleState();
-    rwy_red_low_lights->ref();
     rwy_red_low_lights->disable( GL_LIGHTING );
     rwy_red_low_lights->enable ( GL_CULL_FACE ) ;
     rwy_red_low_lights->enable( GL_TEXTURE_2D );
@@ -392,7 +381,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char
     // hard coded runway green light state
     tex_name = gen_standard_dir_light_map( 20, 235, 20, 255 );
     ssgSimpleState *rwy_green_lights = new ssgSimpleState();
-    rwy_green_lights->ref();
     rwy_green_lights->disable( GL_LIGHTING );
     rwy_green_lights->enable ( GL_CULL_FACE ) ;
     rwy_green_lights->enable( GL_TEXTURE_2D );
@@ -410,7 +398,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char
     // hard coded medium intensity runway green light state
     tex_name = gen_standard_dir_light_map( 20, 235, 20, 205 );
     ssgSimpleState *rwy_green_medium_lights = new ssgSimpleState();
-    rwy_green_medium_lights->ref();
     rwy_green_medium_lights->disable( GL_LIGHTING );
     rwy_green_medium_lights->enable ( GL_CULL_FACE ) ;
     rwy_green_medium_lights->enable( GL_TEXTURE_2D );
@@ -428,7 +415,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char
     // hard coded low intensity runway green light state
     tex_name = gen_standard_dir_light_map( 20, 235, 20, 155 );
     ssgSimpleState *rwy_green_low_lights = new ssgSimpleState();
-    rwy_green_low_lights->ref();
     rwy_green_low_lights->disable( GL_LIGHTING );
     rwy_green_low_lights->enable ( GL_CULL_FACE ) ;
     rwy_green_low_lights->enable( GL_TEXTURE_2D );
@@ -448,7 +434,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char
     // hard coded low intensity taxiway blue light state
     tex_name = gen_taxiway_dir_light_map( 90, 90, 235, 205 );
     ssgSimpleState *taxiway_blue_low_lights = new ssgSimpleState();
-    taxiway_blue_low_lights->ref();
     taxiway_blue_low_lights->disable( GL_LIGHTING );
     taxiway_blue_low_lights->enable ( GL_CULL_FACE ) ;
     taxiway_blue_low_lights->enable( GL_TEXTURE_2D );
@@ -466,7 +451,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char
     // hard coded runway vasi light state
     tex_name = gen_standard_dir_light_map( 235, 235, 195, 255 );
     ssgSimpleState *rwy_vasi_lights = new ssgSimpleState();
-    rwy_vasi_lights->ref();
     rwy_vasi_lights->disable( GL_LIGHTING );
     rwy_vasi_lights->enable ( GL_CULL_FACE ) ;
     rwy_vasi_lights->enable( GL_TEXTURE_2D );
@@ -515,13 +499,11 @@ bool SGMaterialLib::add_item ( const string &mat_name, const string &full_path )
 // Load a library of material properties
 bool SGMaterialLib::add_item ( const string &mat_name, ssgSimpleState *state )
 {
-    SGMaterial *m = new SGMaterial( state );
+    matlib[mat_name] = new SGMaterial( state );
 
     SG_LOG( SG_TERRAIN, SG_INFO, "  Loading material given a premade "
            << "ssgSimpleState = " << mat_name );
 
-    matlib[mat_name] = m;
-
     return true;
 }
 
@@ -541,14 +523,6 @@ SGMaterial *SGMaterialLib::find( const string& material ) {
 
 // Destructor
 SGMaterialLib::~SGMaterialLib ( void ) {
-    // Free up all the material entries first
-    for ( material_map_iterator it = begin(); it != end(); it++ ) {
-       SGMaterial *slot = it->second;
-       slot->deRef();
-       if ( slot->getRef() <= 0 ) {
-            delete slot;
-        }
-    }
 }
 
 
index f457d2760bbec1ce07a3ce7520d3dd58e55e8676..44a12ff7c679d944d88e73b436b4d3a35828ba8a 100644 (file)
@@ -31,6 +31,8 @@
 
 #include <simgear/compiler.h>
 
+#include <simgear/structure/SGSharedPtr.hxx>
+
 #include STL_STRING            // Standard C++ string library
 #include <map>                 // STL associative "array"
 #include <vector>              // STL "array"
@@ -52,7 +54,7 @@ class SGMaterialLib {
 private:
 
     // associative array of materials
-    typedef map < string, SGMaterial *, less<string> > material_map;
+    typedef map < string, SGSharedPtr<SGMaterial>, less<string> > material_map;
     typedef material_map::iterator material_map_iterator;
     typedef material_map::const_iterator const_material_map_iterator;
 
index 259789d4c52396aeda893e4c3a8526cd98090b2b..177f5ec4855b969b24d5a3a6d16d006d4ab9d41a 100644 (file)
@@ -108,12 +108,6 @@ SGMatModel::SGMatModel (const SGPropertyNode * node, double range_m)
 
 SGMatModel::~SGMatModel ()
 {
-  for (unsigned int i = 0; i < _models.size(); i++) {
-    if (_models[i] != 0) {
-      ssgDeRefDelete(_models[i]);
-      _models[i] = 0;
-    }
-  }
 }
 
 int
@@ -160,7 +154,6 @@ SGMatModel::load_models ( SGModelLib *modellib,
                                 // there).
        float ranges[] = {0, _range_m};
        ssgRangeSelector * lod = new ssgRangeSelector;
-        lod->ref();
         lod->setRanges(ranges, 2);
        if (_heading_type == HEADING_BILLBOARD) {
           // if the model is a billboard, it is likely :
@@ -246,10 +239,6 @@ SGMatModelGroup::SGMatModelGroup (SGPropertyNode * node)
 
 SGMatModelGroup::~SGMatModelGroup ()
 {
-  for (unsigned int i = 0; i < _objects.size(); i++) {
-    delete _objects[i];
-    _objects[i] = 0;
-  }
 }
 
 double
index 145f3affb441ab7cb4bedf0784c02e4b495e4c8a..b303ef9e0069a004417e7f45fe3ae2d08acd2244 100644 (file)
@@ -35,6 +35,9 @@
 #include <plib/sg.h>
 #include <plib/ssg.h>
 
+#include <simgear/structure/SGReferenced.hxx>
+#include <simgear/structure/SGSharedPtr.hxx>
+#include <simgear/structure/ssgSharedPtr.hxx>
 #include <simgear/props/props.hxx>
 
 SG_USING_STD(string);
@@ -53,7 +56,7 @@ class SGModelLib;
  * different shapes of trees), but they are considered equivalent
  * and interchangeable.
  */
-class SGMatModel {
+class SGMatModel : public SGReferenced {
 
 public:
 
@@ -116,14 +119,14 @@ public:
      */
     HeadingType get_heading_type () const;
 
+    virtual ~SGMatModel ();
+
 protected:
 
     friend class SGMatModelGroup;
 
     SGMatModel (const SGPropertyNode * node, double range_m);
 
-    virtual ~SGMatModel ();
-
 private:
 
     /**
@@ -138,7 +141,7 @@ private:
                       double sim_time_sec );
 
     vector<string> _paths;
-    mutable vector<ssgEntity *> _models;
+    mutable vector<ssgSharedPtr<ssgEntity> > _models;
     mutable bool _models_loaded;
     double _coverage_m2;
     double _range_m;
@@ -154,7 +157,7 @@ private:
  * Each SGMaterial instance keeps a (possibly-empty) list of
  * object groups for placing randomly on the scenery.
  */
-class SGMatModelGroup {
+class SGMatModelGroup : public SGReferenced {
 
 public:
 
@@ -194,7 +197,7 @@ protected:
 private:
 
     double _range_m;
-    vector<SGMatModel *> _objects;
+    vector<SGSharedPtr<SGMatModel> > _objects;
 
 };
 
index 1b7a4c264ac6b3d402ef2fb4be13eff33ef469d8..1b6654feb9bd8656d651de13d8765dd0d1f449e8 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <simgear/math/point3d.hxx>
 #include <simgear/props/props.hxx>
+#include <simgear/structure/ssgSharedPtr.hxx>
 
 
 // Don't pull in the headers, since we don't need them here.
@@ -91,8 +92,8 @@ private:
   double _pitch_deg;
   double _heading_deg;
 
-  ssgSelector * _selector;
-  ssgPlacementTransform * _position;
+  ssgSharedPtr<ssgSelector> _selector;
+  ssgSharedPtr<ssgPlacementTransform> _position;
 
                                 // Location
   SGLocation * _location;
index f4b3de253d5b5afc2c0ad635c7a60f5ad0916575..4652474e41cee7e35b6929db422db3b6b792bfbb 100644 (file)
@@ -31,6 +31,7 @@
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/screen/extensions.hxx>
 #include <simgear/screen/texture.hxx>
+#include <simgear/structure/ssgSharedPtr.hxx>
 
 #include "newcloud.hxx"
 #include "cloudfield.hxx"
 #endif
 
 
-static ssgStateSelector *layer_states[SGCloudLayer::SG_MAX_CLOUD_COVERAGES];
+static ssgSharedPtr<ssgStateSelector> layer_states[SGCloudLayer::SG_MAX_CLOUD_COVERAGES];
 static bool state_initialized = false;
 static bool bump_mapping = false;
 static GLint nb_texture_unit = 0;
-static ssgTexture *normal_map[SGCloudLayer::SG_MAX_CLOUD_COVERAGES][2] = { 0 };
-static ssgTexture *color_map[SGCloudLayer::SG_MAX_CLOUD_COVERAGES][2] = { 0 };
+static ssgSharedPtr<ssgTexture> normal_map[SGCloudLayer::SG_MAX_CLOUD_COVERAGES][2];
+static ssgSharedPtr<ssgTexture> color_map[SGCloudLayer::SG_MAX_CLOUD_COVERAGES][2];
 static GLuint normalization_cube_map;
 
 static glActiveTextureProc glActiveTexturePtr = 0;
@@ -345,56 +346,44 @@ SGCloudLayer::rebuild()
             cloud_path.set(texture_path.str());
             cloud_path.append("overcast.rgb");
             color_map[ SG_CLOUD_OVERCAST ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
-            color_map[ SG_CLOUD_OVERCAST ][ 0 ]->ref();
             cloud_path.set(texture_path.str());
             cloud_path.append("overcast_n.rgb");
             normal_map[ SG_CLOUD_OVERCAST ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
-            normal_map[ SG_CLOUD_OVERCAST ][ 0 ]->ref();
 
             cloud_path.set(texture_path.str());
             cloud_path.append("overcast_top.rgb");
             color_map[ SG_CLOUD_OVERCAST ][ 1 ] = new ssgTexture( cloud_path.str().c_str() );
-            color_map[ SG_CLOUD_OVERCAST ][ 1 ]->ref();
             cloud_path.set(texture_path.str());
             cloud_path.append("overcast_top_n.rgb");
             normal_map[ SG_CLOUD_OVERCAST ][ 1 ] = new ssgTexture( cloud_path.str().c_str() );
-            normal_map[ SG_CLOUD_OVERCAST ][ 1 ]->ref();
 
             cloud_path.set(texture_path.str());
             cloud_path.append("broken.rgba");
             color_map[ SG_CLOUD_BROKEN ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
-            color_map[ SG_CLOUD_BROKEN ][ 0 ]->ref();
             cloud_path.set(texture_path.str());
             cloud_path.append("broken_n.rgb");
             normal_map[ SG_CLOUD_BROKEN ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
-            normal_map[ SG_CLOUD_BROKEN ][ 0 ]->ref();
 
             cloud_path.set(texture_path.str());
             cloud_path.append("scattered.rgba");
             color_map[ SG_CLOUD_SCATTERED ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
-            color_map[ SG_CLOUD_SCATTERED ][ 0 ]->ref();
             cloud_path.set(texture_path.str());
             cloud_path.append("scattered_n.rgb");
             normal_map[ SG_CLOUD_SCATTERED ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
-            normal_map[ SG_CLOUD_SCATTERED ][ 0 ]->ref();
 
             cloud_path.set(texture_path.str());
             cloud_path.append("few.rgba");
             color_map[ SG_CLOUD_FEW ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
-            color_map[ SG_CLOUD_FEW ][ 0 ]->ref();
             cloud_path.set(texture_path.str());
             cloud_path.append("few_n.rgb");
             normal_map[ SG_CLOUD_FEW ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
-            normal_map[ SG_CLOUD_FEW ][ 0 ]->ref();
 
             cloud_path.set(texture_path.str());
             cloud_path.append("cirrus.rgba");
             color_map[ SG_CLOUD_CIRRUS ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
-            color_map[ SG_CLOUD_CIRRUS ][ 0 ]->ref();
             cloud_path.set(texture_path.str());
             cloud_path.append("cirrus_n.rgb");
             normal_map[ SG_CLOUD_CIRRUS ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
-            normal_map[ SG_CLOUD_CIRRUS ][ 0 ]->ref();
 
             glGenTextures( 1, &normalization_cube_map );
             glBindTexture( GL_TEXTURE_CUBE_MAP_ARB, normalization_cube_map );
@@ -410,7 +399,6 @@ SGCloudLayer::rebuild()
             ssgSimpleState *state;
 
             state_sel = new ssgStateSelector( 2 );
-            state_sel->ref();
             cloud_path.set(texture_path.str());
             cloud_path.append("overcast.rgb");
             state_sel->setStep( 0, sgCloudMakeState(cloud_path.str()) );
@@ -420,7 +408,6 @@ SGCloudLayer::rebuild()
             layer_states[SG_CLOUD_OVERCAST] = state_sel;
 
             state_sel = new ssgStateSelector( 2 );
-            state_sel->ref();
             cloud_path.set(texture_path.str());
             cloud_path.append("broken.rgba");
             state = sgCloudMakeState(cloud_path.str());
@@ -429,7 +416,6 @@ SGCloudLayer::rebuild()
             layer_states[SG_CLOUD_BROKEN] = state_sel;
 
             state_sel = new ssgStateSelector( 2 );
-            state_sel->ref();
             cloud_path.set(texture_path.str());
             cloud_path.append("scattered.rgba");
             state = sgCloudMakeState(cloud_path.str());
@@ -438,7 +424,6 @@ SGCloudLayer::rebuild()
             layer_states[SG_CLOUD_SCATTERED] = state_sel;
 
             state_sel = new ssgStateSelector( 2 );
-            state_sel->ref();
             cloud_path.set(texture_path.str());
             cloud_path.append("few.rgba");
             state = sgCloudMakeState(cloud_path.str());
@@ -447,7 +432,6 @@ SGCloudLayer::rebuild()
             layer_states[SG_CLOUD_FEW] = state_sel;
 
             state_sel = new ssgStateSelector( 2 );
-            state_sel->ref();
             cloud_path.set(texture_path.str());
             cloud_path.append("cirrus.rgba");
             state = sgCloudMakeState(cloud_path.str());
index a527b792efcd288883aa139aabec858f5a1b8ece..f8453683a90e134c9d501ef62eee9ecaba3f6bb9 100644 (file)
@@ -30,6 +30,7 @@
 #include <plib/ssg.h>
 #include <simgear/math/sg_random.h>
 #include <simgear/misc/sg_path.hxx>
+#include <simgear/structure/ssgSharedPtr.hxx>
 
 #include STL_ALGORITHM
 #include SG_GLU_H
@@ -41,7 +42,7 @@
 /*
 */
 
-static ssgTexture *cloudTextures[SGNewCloud::CLTexture_max];
+static ssgSharedPtr<ssgTexture> cloudTextures[SGNewCloud::CLTexture_max];
 
 
 bool SGNewCloud::useAnisotropic = true;
@@ -129,12 +130,10 @@ void SGNewCloud::loadTextures(const string &tex_path) {
     cloud_path.set(tex_path);
     cloud_path.append("cl_cumulus.rgb");
     cloudTextures[ CLTexture_cumulus ] = new ssgTexture( cloud_path.str().c_str(), false, false, false );
-    cloudTextures[ CLTexture_cumulus ]->ref();
 
     cloud_path.set(tex_path);
     cloud_path.append("cl_stratus.rgb");
     cloudTextures[ CLTexture_stratus ] = new ssgTexture( cloud_path.str().c_str(), false, false, false );
-    cloudTextures[ CLTexture_stratus ]->ref();
 
 }
 
index 381164b4b22029f75024c638fd04ee4143636251..10625ad6f4062c281b92240ba725ae1339e43ad8 100644 (file)
@@ -37,6 +37,8 @@
 #include STL_STRING
 
 #include <simgear/debug/logstream.hxx>
+#include <simgear/structure/SGReferenced.hxx>
+#include <simgear/structure/SGSharedPtr.hxx>
 
 #include <plib/sg.h>
 
@@ -56,7 +58,7 @@ SG_USING_STD(string);
  * manages everything we need to know for an individual sound sample
  */
 
-class SGSoundSample {
+class SGSoundSample : public SGReferenced {
 
 private:
 
index 534c4430e4cb348c68866c15fcc6a0c0d1e71ab2..971bea6d2c4d1582ce2f20d5c955c40da8d8977d 100644 (file)
@@ -141,15 +141,6 @@ SGSoundMgr::~SGSoundMgr() {
     if (context)
         alcDestroyContext( context );
 #endif
-    //
-    // Remove the samples from the sample manager.
-    //
-    sample_map_iterator sample_current = samples.begin();
-    sample_map_iterator sample_end = samples.end();
-    for ( ; sample_current != sample_end; ++sample_current ) {
-       SGSoundSample *sample = sample_current->second;
-       delete sample;
-    }
 }
 
 
@@ -158,12 +149,6 @@ void SGSoundMgr::init() {
     //
     // Remove the samples from the sample manager.
     //
-    sample_map_iterator sample_current = samples.begin();
-    sample_map_iterator sample_end = samples.end();
-    for ( ; sample_current != sample_end; ++sample_current ) {
-        SGSoundSample *sample = sample_current->second;
-        delete sample;
-    }
     samples.clear();
 }
 
index 6c0d18429526257403ca2fccb1f75eaee7d4fc63..dd4d3913144872add74c5602946e286e5a4be0c2 100644 (file)
@@ -56,7 +56,7 @@ SG_USING_STD(map);
 SG_USING_STD(string);
 
 
-typedef map < string, SGSoundSample * > sample_map;
+typedef map < string, SGSharedPtr<SGSoundSample> > sample_map;
 typedef sample_map::iterator sample_map_iterator;
 typedef sample_map::const_iterator const_sample_map_iterator;
 
index 3e27b82b4933b57e4d60d7d7186241c9bd78913e..3bd9bd89f14458108e74d2c1d76a2a04af88398a 100644 (file)
@@ -65,7 +65,6 @@ static const struct {
 SGXmlSound::SGXmlSound()
   : _sample(NULL),
     _condition(NULL),
-    _property(NULL),
     _active(false),
     _name(""),
     _mode(SGXmlSound::ONCE),
@@ -80,12 +79,10 @@ SGXmlSound::~SGXmlSound()
 {
     _sample->stop();
 
-    delete _property;
     delete _condition;
 
     _volume.clear();
     _pitch.clear();
-    delete _sample;
 }
 
 void
index e290b3939d20332d0d08c74abde54e3462579055..ced1e046d3d629d2608a929bb4018a40404ca31f 100644 (file)
@@ -120,7 +120,7 @@ protected:
 
   // SGXmlSound properties
   typedef struct {
-        SGPropertyNode * prop;
+        SGPropertyNode_ptr prop;
         double (*fn)(double);
         double *intern;
         double factor;
@@ -133,10 +133,10 @@ protected:
 private:
 
   SGSoundMgr * _mgr;
-  SGSoundSample * _sample;
+  SGSharedPtr<SGSoundSample> _sample;
 
   SGCondition * _condition;
-  SGPropertyNode * _property;
+  SGPropertyNode_ptr _property;
 
   bool _active;
   string _name;