#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>
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);
SGMaterial::~SGMaterial (void)
{
- for (unsigned int i = 0; i < object_groups.size(); i++) {
- delete object_groups[i];
- object_groups[i] = 0;
- }
}
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;
for (unsigned int i = 0; i < _status.size(); i++)
{
ssgSimpleState *state = new ssgSimpleState();
- state->ref();
// Set up the textured state
state->setShadeModel( shade_model );
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
#include <plib/ssg.h>
#include <simgear/props/props.hxx>
+#include <simgear/structure/ssgSharedPtr.hxx>
+#include <simgear/structure/SGSharedPtr.hxx>
#include "matmodel.hxx"
* defined in the $FG_ROOT/materials.xml file, and can be changed
* at runtime.
*/
-class SGMaterial {
+class SGMaterial : public SGReferenced {
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
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;
};
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
////////////////////////////////////////////////////////////////////
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 "
// 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 );
// 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 );
// 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 );
// 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 );
// 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 );
// 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 );
// 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 );
// 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 );
// 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 );
// 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 );
// 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 );
// 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 );
// 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 );
// 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 );
// 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 );
// 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;
}
// 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;
- }
- }
}
#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"
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;
SGMatModel::~SGMatModel ()
{
- for (unsigned int i = 0; i < _models.size(); i++) {
- if (_models[i] != 0) {
- ssgDeRefDelete(_models[i]);
- _models[i] = 0;
- }
- }
}
int
// 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 :
SGMatModelGroup::~SGMatModelGroup ()
{
- for (unsigned int i = 0; i < _objects.size(); i++) {
- delete _objects[i];
- _objects[i] = 0;
- }
}
double
#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);
* different shapes of trees), but they are considered equivalent
* and interchangeable.
*/
-class SGMatModel {
+class SGMatModel : public SGReferenced {
public:
*/
HeadingType get_heading_type () const;
+ virtual ~SGMatModel ();
+
protected:
friend class SGMatModelGroup;
SGMatModel (const SGPropertyNode * node, double range_m);
- virtual ~SGMatModel ();
-
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;
* Each SGMaterial instance keeps a (possibly-empty) list of
* object groups for placing randomly on the scenery.
*/
-class SGMatModelGroup {
+class SGMatModelGroup : public SGReferenced {
public:
private:
double _range_m;
- vector<SGMatModel *> _objects;
+ vector<SGSharedPtr<SGMatModel> > _objects;
};
#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.
double _pitch_deg;
double _heading_deg;
- ssgSelector * _selector;
- ssgPlacementTransform * _position;
+ ssgSharedPtr<ssgSelector> _selector;
+ ssgSharedPtr<ssgPlacementTransform> _position;
// Location
SGLocation * _location;
#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;
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 );
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()) );
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());
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());
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());
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());
#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
/*
*/
-static ssgTexture *cloudTextures[SGNewCloud::CLTexture_max];
+static ssgSharedPtr<ssgTexture> cloudTextures[SGNewCloud::CLTexture_max];
bool SGNewCloud::useAnisotropic = true;
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();
}
#include STL_STRING
#include <simgear/debug/logstream.hxx>
+#include <simgear/structure/SGReferenced.hxx>
+#include <simgear/structure/SGSharedPtr.hxx>
#include <plib/sg.h>
* manages everything we need to know for an individual sound sample
*/
-class SGSoundSample {
+class SGSoundSample : public SGReferenced {
private:
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;
- }
}
//
// 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();
}
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;
SGXmlSound::SGXmlSound()
: _sample(NULL),
_condition(NULL),
- _property(NULL),
_active(false),
_name(""),
_mode(SGXmlSound::ONCE),
{
_sample->stop();
- delete _property;
delete _condition;
_volume.clear();
_pitch.clear();
- delete _sample;
}
void
// SGXmlSound properties
typedef struct {
- SGPropertyNode * prop;
+ SGPropertyNode_ptr prop;
double (*fn)(double);
double *intern;
double factor;
private:
SGSoundMgr * _mgr;
- SGSoundSample * _sample;
+ SGSharedPtr<SGSoundSample> _sample;
SGCondition * _condition;
- SGPropertyNode * _property;
+ SGPropertyNode_ptr _property;
bool _active;
string _name;