Make use of the automatic reference counting class for ssg* data in flightgear.
FGAIBase::FGAIBase()
: fp( NULL ),
- model( NULL ),
props( NULL ),
manager( NULL ),
_refID( _newAIModelID() )
root->removeChild(_type_str.c_str(), index);
delete fp;
fp = NULL;
- ssgDeRefDelete(model);
- model = 0;
}
void FGAIBase::update(double dt) {
// some more code here to check whether a model with this name has already been loaded
// if not load it, otherwise, get the memory pointer and do something like
// SetModel as in ATC/AIEntity.cxx
- //SSGBranch *model;
model = manager->getModel(path);
if (!(model))
{
sim_time_sec);
manager->setModel(path, model);
}
- //else
- // {
- // model->ref();
- // aip.init(model);
- // aip.setVisible(false);
- // globals->get_scenery()->get_scene_graph()->addKid(aip.getSceneGraph());
- // do some setModel stuff.
- if (model)
- model->ref();
-
return model;
}
#include <simgear/math/point3d.hxx>
#include <simgear/scene/model/placement.hxx>
#include <simgear/misc/sg_path.hxx>
+#include <simgear/structure/ssgSharedPtr.hxx>
#include <Main/fg_props.hxx>
string model_path; //Path to the 3D model
- ssgBranch * model; //The 3D model object
+ ssgSharedPtr<ssgBranch> model; //The 3D model object
SGModelPlacement aip;
bool delete_me;
bool invisible;
++ai_list_itr;
}
ai_list.clear();
- ModelVecIterator i = loadedModels.begin();
- while (i != loadedModels.end())
- {
- ssgDeRefDelete(i->getModelId());
- ++i;
- }
}
void FGAIManager::setModel(const string& path, ssgBranch *model)
{
- if (model)
- model->ref();
loadedModels.push_back(FGModelID(path,model));
}
#include <list>
#include <simgear/structure/subsystem_mgr.hxx>
+#include <simgear/structure/ssgSharedPtr.hxx>
#include <Main/fg_props.hxx>
class FGModelID
{
private:
- ssgBranch * model;
+ ssgSharedPtr<ssgBranch> model;
string path;
public:
FGModelID(const string& pth, ssgBranch * mdl) { path =pth; model=mdl;};
FGAIEntity::~FGAIEntity() {
//cout << "FGAIEntity dtor called..." << endl;
- ssgDeRefDelete(_model); // Ought to check valid?
//cout << "Removing model from scene graph..." << endl;
globals->get_scenery()->get_scene_graph()->removeKid(_aip.getSceneGraph());
// Unregister that one at the scenery manager
void FGAIEntity::SetModel(ssgBranch* model) {
_model = model;
- _model->ref();
_aip.init(_model);
_aip.setVisible(false);
globals->get_scenery()->get_scene_graph()->addKid(_aip.getSceneGraph());
#include <simgear/math/point3d.hxx>
#include <simgear/scene/model/model.hxx>
#include <simgear/scene/model/placement.hxx>
+#include <simgear/structure/ssgSharedPtr.hxx>
-class ssgBranch;
+
+class ssgBase;
/*****************************************************************
double _pitch; //degrees
char* _model_path; //Path to the 3D model
- ssgBranch* _model; // Pointer to the model
+ ssgSharedPtr<ssgBranch> _model; // Pointer to the model
SGModelPlacement _aip;
void Transform();
globals->get_sim_time_sec() );
*//*
_model = model;
- _model->ref();
_aip.init(_model);
*/
//SetModel(model);
}
FGAILocalTraffic::~FGAILocalTraffic() {
- //_model->deRef();
}
void FGAILocalTraffic::GetAirportDetails(const string& id) {
}
FGAIMgr::~FGAIMgr() {
- ssgDeRefDelete(_defaultModel);
- if(_havePiperModel) ssgDeRefDelete(_piperModel);
}
void FGAIMgr::init() {
_havePiperModel = false;
}
- // We need to keep one ref of the models open to stop ssg deleting them behind our back!
- _defaultModel->ref();
- if(_havePiperModel) _piperModel->ref();
-
// go through the $FG_ROOT/ATC directory and find all *.taxi files
SGPath path(globals->get_fg_root());
path.append("ATC/");
#define _FG_AIMGR_HXX
#include <simgear/structure/subsystem_mgr.hxx>
+#include <simgear/structure/ssgSharedPtr.hxx>
#include <Main/fg_props.hxx>
private:
- ssgBranch* _defaultModel; // Cessna 172!
- ssgBranch* _piperModel; // pa28-161
+ ssgSharedPtr<ssgBranch> _defaultModel; // Cessna 172!
+ ssgSharedPtr<ssgBranch> _piperModel; // pa28-161
bool initDone; // Hack - guard against update getting called before init
wxRadarBg::~wxRadarBg ()
{
- ssgDeRefDelete(resultTexture);
- ssgDeRefDelete(wxEcho);
}
void
_Instrument = fgGetNode(branch.c_str(), num, true );
_serviceable_node = _Instrument->getChild("serviceable", 0, true);
resultTexture = FGTextureManager::createTexture( odgauge_name );
- resultTexture->ref();
SGPath tpath(globals->get_fg_root());
tpath.append("Aircraft/Instruments/Textures/wxecho.rgb");
// no mipmap or else alpha will mix with pixels on the border of shapes, ruining the effect
wxEcho = new ssgTexture( tpath.c_str(), false, false, false);
- wxEcho->ref();
_Instrument->setFloatValue("trk", 0.0);
_Instrument->setFloatValue("tilt", 0.0);
#include <simgear/props/props.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/environment/visual_enviro.hxx>
+#include <simgear/structure/ssgSharedPtr.hxx>
class ssgTexture;
class FGODGauge;
SGPropertyNode_ptr _serviceable_node;
SGPropertyNode_ptr _Instrument;
- ssgTexture *resultTexture;
- ssgTexture *wxEcho;
+ ssgSharedPtr<ssgTexture> resultTexture;
+ ssgSharedPtr<ssgTexture> wxEcho;
string last_switchKnob;
bool sim_init_done;
FGODGauge *odg;
{ 0.0f, 0.0f, 0.0f, 1.0f }
};
-ssgSimpleState *cloud3d_imposter_state;
-ssgSimpleState *default_state;
-ssgSimpleState *hud_and_panel;
-ssgSimpleState *menus;
+ssgSharedPtr<ssgSimpleState> cloud3d_imposter_state;
+ssgSharedPtr<ssgSimpleState> default_state;
+ssgSharedPtr<ssgSimpleState> hud_and_panel;
+ssgSharedPtr<ssgSimpleState> menus;
SGShadowVolume *shadows;
void
FGRenderer::build_states( void ) {
default_state = new ssgSimpleState;
- default_state->ref();
default_state->disable( GL_TEXTURE_2D );
default_state->enable( GL_CULL_FACE );
default_state->enable( GL_COLOR_MATERIAL );
default_state->disable( GL_LIGHTING );
cloud3d_imposter_state = new ssgSimpleState;
- cloud3d_imposter_state->ref();
cloud3d_imposter_state->enable( GL_TEXTURE_2D );
cloud3d_imposter_state->enable( GL_CULL_FACE );
cloud3d_imposter_state->enable( GL_COLOR_MATERIAL );
cloud3d_imposter_state->disable( GL_LIGHTING );
hud_and_panel = new ssgSimpleState;
- hud_and_panel->ref();
hud_and_panel->disable( GL_CULL_FACE );
hud_and_panel->disable( GL_TEXTURE_2D );
hud_and_panel->disable( GL_LIGHTING );
hud_and_panel->enable( GL_BLEND );
menus = new ssgSimpleState;
- menus->ref();
menus->disable( GL_CULL_FACE );
menus->disable( GL_TEXTURE_2D );
menus->enable( GL_BLEND );
SG_USING_STD(vector);
#include <simgear/structure/subsystem_mgr.hxx> // for SGSubsystem
+#include <simgear/structure/ssgSharedPtr.hxx>
// Don't pull in the headers, since we don't need them here.
private:
SGModelPlacement * _aircraft;
- ssgSelector * _selector;
- ssgRoot * _scene;
+ ssgSharedPtr<ssgSelector> _selector;
+ ssgSharedPtr<ssgRoot> _scene;
float _nearplane;
float _farplane;
vector<Instance *> _instances;
- ssgSelector * _selector;
+ ssgSharedPtr<ssgSelector> _selector;
};
}
void FGScenery::register_placement_transform(ssgPlacementTransform *trans) {
- trans->ref();
_placement_list.push_back(trans);
sgdVec3 c;
sgdSetVec3(c, center.x(), center.y(), center.z());
while (it != _placement_list.end()) {
if ((*it) == trans) {
it = _placement_list.erase(it);
- ssgDeRefDelete(trans);
} else
++it;
}
Point3D ppos(pos[0], pos[1], pos[2]);
if (30.0*30.0 < ppos.distance3Dsquared(center)) {
set_center( ppos );
- replaced_center = false;
+ replaced_center = true;
}
}
#include <simgear/compiler.h>
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/math/point3d.hxx>
+#include <simgear/scene/model/placementtrans.hxx>
+#include <simgear/structure/ssgSharedPtr.hxx>
SG_USING_STD(list);
class ssgRoot;
class ssgBranch;
-class ssgPlacementTransform;
// Define a structure containing global scenery parameters
double sun_angle;
// SSG scene graph
- ssgRoot *scene_graph;
- ssgBranch *terrain_branch;
- ssgRoot *gnd_lights_root;
- ssgRoot *vasi_lights_root;
- ssgRoot *rwy_lights_root;
- ssgRoot *taxi_lights_root;
- ssgBranch *models_branch;
- ssgBranch *aircraft_branch;
+ ssgSharedPtr<ssgRoot> scene_graph;
+ ssgSharedPtr<ssgBranch> terrain_branch;
+ ssgSharedPtr<ssgRoot> gnd_lights_root;
+ ssgSharedPtr<ssgRoot> vasi_lights_root;
+ ssgSharedPtr<ssgRoot> rwy_lights_root;
+ ssgSharedPtr<ssgRoot> taxi_lights_root;
+ ssgSharedPtr<ssgBranch> models_branch;
+ ssgSharedPtr<ssgBranch> aircraft_branch;
// list of all placement transform, used to move the scenery center on the fly.
- typedef list<ssgPlacementTransform*> placement_list_type;
+ typedef list<ssgSharedPtr<ssgPlacementTransform> > placement_list_type;
placement_list_type _placement_list;
public:
// is intended to spread the load of freeing a complex tile out over
// several frames.
static int fgPartialFreeSSGtree( ssgBranch *b, int n ) {
-
-#if 0
- // for testing: we could call the following two lines and replace
- // the functionality of this entire function and everything will
- // get properly freed, but it will happen all at once and could
- // cause a huge frame rate hit.
- ssgDeRefDelete( b );
- return 0;
-#endif
-
int num_deletes = 0;
if ( n > 0 ) {
// disconnected from the scene graph)
SG_LOG( SG_TERRAIN, SG_DEBUG, "FREEING terra_transform" );
if ( fgPartialFreeSSGtree( terra_transform, delete_size ) == 0 ) {
- ssgDeRefDelete( terra_transform );
+ terra_transform = 0;
free_tracker |= TERRA_NODE;
}
} else if ( !(free_tracker & GROUND_LIGHTS) && gnd_lights_transform ) {
// disconnected from the scene graph)
SG_LOG( SG_TERRAIN, SG_DEBUG, "FREEING gnd_lights_transform" );
if ( fgPartialFreeSSGtree( gnd_lights_transform, delete_size ) == 0 ) {
- ssgDeRefDelete( gnd_lights_transform );
+ gnd_lights_transform = 0;
free_tracker |= GROUND_LIGHTS;
}
} else if ( !(free_tracker & VASI_LIGHTS) && vasi_lights_selector ) {
// been disconnected from the scene graph)
SG_LOG( SG_TERRAIN, SG_DEBUG, "FREEING vasi_lights_selector" );
if ( fgPartialFreeSSGtree( vasi_lights_selector, delete_size ) == 0 ) {
- ssgDeRefDelete( vasi_lights_selector );
+ vasi_lights_selector = 0;
free_tracker |= VASI_LIGHTS;
}
} else if ( !(free_tracker & RWY_LIGHTS) && rwy_lights_selector ) {
// been disconnected from the scene graph)
SG_LOG( SG_TERRAIN, SG_DEBUG, "FREEING rwy_lights_selector" );
if ( fgPartialFreeSSGtree( rwy_lights_selector, delete_size ) == 0 ) {
- ssgDeRefDelete( rwy_lights_selector );
+ rwy_lights_selector = 0;
free_tracker |= RWY_LIGHTS;
}
} else if ( !(free_tracker & TAXI_LIGHTS) && taxi_lights_selector ) {
// disconnected from the scene graph)
SG_LOG( SG_TERRAIN, SG_DEBUG, "FREEING taxi_lights_selector" );
if ( fgPartialFreeSSGtree( taxi_lights_selector, delete_size ) == 0 ) {
- ssgDeRefDelete( taxi_lights_selector );
+ taxi_lights_selector = 0;
free_tracker |= TAXI_LIGHTS;
}
} else if ( !(free_tracker & LIGHTMAPS) ) {
if (found_tile_base) {
// load tile if found ...
- ssgBranch *geometry = new ssgBranch;
+ ssgSharedPtr<ssgBranch> geometry = new ssgBranch;
if ( obj_load( object_base.str(), geometry,
NULL, NULL, NULL, light_pts, true ) ) {
geometry->getKid( 0 )->setTravCallback(SSG_CALLBACK_PRETRAV,
&FGTileMgr::tile_filter_cb);
new_tile -> addKid( geometry );
- } else {
- delete geometry;
}
} else {
// ... or generate an ocean tile on the fly
SG_LOG(SG_TERRAIN, SG_INFO, " Generating ocean tile");
- ssgBranch *geometry = new ssgBranch;
+ ssgSharedPtr<ssgBranch> geometry = new ssgBranch;
Point3D c;
double br;
if ( sgGenTile( path_list[0], tile_bucket, &c, &br,
bounding_radius = br;
new_tile -> addKid( geometry );
} else {
- delete geometry;
SG_LOG( SG_TERRAIN, SG_ALERT,
"Warning: failed to generate ocean tile!" );
}
SGPath custom_path = obj->path;
custom_path.append( obj->name );
- ssgBranch *geometry = new ssgBranch;
- ssgBranch *vasi_lights = new ssgBranch;
- ssgBranch *rwy_lights = new ssgBranch;
- ssgBranch *taxi_lights = new ssgBranch;
+ ssgSharedPtr<ssgBranch> geometry = new ssgBranch;
+ ssgSharedPtr<ssgBranch> vasi_lights = new ssgBranch;
+ ssgSharedPtr<ssgBranch> rwy_lights = new ssgBranch;
+ ssgSharedPtr<ssgBranch> taxi_lights = new ssgBranch;
if ( obj_load( custom_path.str(),
geometry, vasi_lights, rwy_lights,
SSG_CALLBACK_PRETRAV,
&FGTileMgr::tile_filter_cb );
new_tile -> addKid( geometry );
- } else {
- delete geometry;
}
if ( vasi_lights -> getNumKids() > 0 )
vasi_lights_transform -> addKid( vasi_lights );
- else
- delete vasi_lights;
if ( rwy_lights -> getNumKids() > 0 )
rwy_lights_transform -> addKid( rwy_lights );
- else
- delete rwy_lights;
if ( taxi_lights -> getNumKids() > 0 )
taxi_lights_transform -> addKid( taxi_lights );
- else
- delete taxi_lights;
-
- } else {
- delete geometry;
- delete vasi_lights;
- delete rwy_lights;
- delete taxi_lights;
}
}
#endif
- terra_transform->ref();
terrain_branch->addKid( terra_transform );
globals->get_scenery()->register_placement_transform(terra_transform);
if ( gnd_lights_transform != NULL ) {
// bump up the ref count so we can remove this later without
// having ssg try to free the memory.
- gnd_lights_transform->ref();
gnd_lights_branch->addKid( gnd_lights_transform );
globals->get_scenery()->register_placement_transform(gnd_lights_transform);
}
if ( vasi_lights_transform != NULL ) {
// bump up the ref count so we can remove this later without
// having ssg try to free the memory.
- vasi_lights_selector->ref();
vasi_lights_selector->addKid( vasi_lights_transform );
globals->get_scenery()->register_placement_transform(vasi_lights_transform);
vasi_lights_branch->addKid( vasi_lights_selector );
if ( rwy_lights_transform != NULL ) {
// bump up the ref count so we can remove this later without
// having ssg try to free the memory.
- rwy_lights_selector->ref();
rwy_lights_selector->addKid( rwy_lights_transform );
globals->get_scenery()->register_placement_transform(rwy_lights_transform);
rwy_lights_branch->addKid( rwy_lights_selector );
if ( taxi_lights_transform != NULL ) {
// bump up the ref count so we can remove this later without
// having ssg try to free the memory.
- taxi_lights_selector->ref();
taxi_lights_selector->addKid( taxi_lights_transform );
globals->get_scenery()->register_placement_transform(taxi_lights_transform);
taxi_lights_branch->addKid( taxi_lights_selector );
#include <simgear/bucket/newbucket.hxx>
#include <simgear/math/point3d.hxx>
#include <simgear/misc/sg_path.hxx>
+#include <simgear/scene/model/placementtrans.hxx>
+#include <simgear/structure/ssgSharedPtr.hxx>
#if defined( sgi )
#include <strings.h>
class ssgLeaf;
class ssgBranch;
class ssgTransform;
-class ssgPlacementTransform;
class ssgSelector;
class ssgRangeSelector;
class ssgVertexArray;
string model_path;
string texture_path;
FGTileEntry *tile;
- ssgTransform *obj_trans;
+ ssgSharedPtr<ssgTransform> obj_trans;
SGBucket bucket;
// - kidn(fan)
// pointer to ssg transform for this tile
- ssgPlacementTransform *terra_transform;
- ssgPlacementTransform *vasi_lights_transform;
- ssgPlacementTransform *rwy_lights_transform;
- ssgPlacementTransform *taxi_lights_transform;
- ssgPlacementTransform *gnd_lights_transform;
+ ssgSharedPtr<ssgPlacementTransform> terra_transform;
+ ssgSharedPtr<ssgPlacementTransform> vasi_lights_transform;
+ ssgSharedPtr<ssgPlacementTransform> rwy_lights_transform;
+ ssgSharedPtr<ssgPlacementTransform> taxi_lights_transform;
+ ssgSharedPtr<ssgPlacementTransform> gnd_lights_transform;
// pointer to ssg range selector for this tile
- ssgRangeSelector *terra_range;
- ssgRangeSelector *gnd_lights_range;
+ ssgSharedPtr<ssgRangeSelector> terra_range;
+ ssgSharedPtr<ssgRangeSelector> gnd_lights_range;
// we create several preset brightness and can choose which one we
// want based on lighting conditions.
- ssgSelector *gnd_lights_brightness;
+ ssgSharedPtr<ssgSelector> gnd_lights_brightness;
// we need to be able to turn runway lights on or off (doing this
// via a call back would be nifty, but then the call back needs to
// know about the higher level application's global state which is
// a problem if we move the code into simgear.)
- ssgSelector *vasi_lights_selector;
- ssgSelector *rwy_lights_selector;
- ssgSelector *taxi_lights_selector;
+ ssgSharedPtr<ssgSelector> vasi_lights_selector;
+ ssgSharedPtr<ssgSelector> rwy_lights_selector;
+ ssgSharedPtr<ssgSelector> taxi_lights_selector;
/**
* Indicates this tile has been loaded from a file and connected