1
0
Fork 0

Mathias Frhlich:

Make use of the automatic reference counting class for ssg* data in flightgear.
This commit is contained in:
ehofman 2006-02-08 10:25:56 +00:00
parent ae77c7d75a
commit a47725e92f
18 changed files with 59 additions and 124 deletions

View file

@ -51,7 +51,6 @@ const double FGAIBase::lbs_to_slugs = 0.031080950172; //conversion factor
FGAIBase::FGAIBase()
: fp( NULL ),
model( NULL ),
props( NULL ),
manager( NULL ),
_refID( _newAIModelID() )
@ -82,8 +81,6 @@ FGAIBase::~FGAIBase() {
root->removeChild(_type_str.c_str(), index);
delete fp;
fp = NULL;
ssgDeRefDelete(model);
model = 0;
}
void FGAIBase::update(double dt) {
@ -151,7 +148,6 @@ ssgBranch * FGAIBase::load3DModel(const string& fg_root,
// 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))
{
@ -161,17 +157,7 @@ ssgBranch * FGAIBase::load3DModel(const string& fg_root,
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;
}

View file

@ -27,6 +27,7 @@
#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>
@ -180,7 +181,7 @@ protected:
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;

View file

@ -59,12 +59,6 @@ FGAIManager::~FGAIManager() {
++ai_list_itr;
}
ai_list.clear();
ModelVecIterator i = loadedModels.begin();
while (i != loadedModels.end())
{
ssgDeRefDelete(i->getModelId());
++i;
}
}
@ -445,8 +439,6 @@ ssgBranch * FGAIManager::getModel(const string& path) const
void FGAIManager::setModel(const string& path, ssgBranch *model)
{
if (model)
model->ref();
loadedModels.push_back(FGModelID(path,model));
}

View file

@ -26,6 +26,7 @@
#include <list>
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/structure/ssgSharedPtr.hxx>
#include <Main/fg_props.hxx>
@ -42,7 +43,7 @@ SG_USING_STD(vector);
class FGModelID
{
private:
ssgBranch * model;
ssgSharedPtr<ssgBranch> model;
string path;
public:
FGModelID(const string& pth, ssgBranch * mdl) { path =pth; model=mdl;};

View file

@ -45,7 +45,6 @@ FGAIEntity::FGAIEntity() {
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
@ -56,7 +55,6 @@ FGAIEntity::~FGAIEntity() {
void FGAIEntity::SetModel(ssgBranch* model) {
_model = model;
_model->ref();
_aip.init(_model);
_aip.setVisible(false);
globals->get_scenery()->get_scene_graph()->addKid(_aip.getSceneGraph());

View file

@ -24,8 +24,10 @@
#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;
/*****************************************************************
@ -65,7 +67,7 @@ protected:
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();

View file

@ -61,7 +61,6 @@ FGAILocalTraffic::FGAILocalTraffic() {
globals->get_sim_time_sec() );
*//*
_model = model;
_model->ref();
_aip.init(_model);
*/
//SetModel(model);
@ -125,7 +124,6 @@ FGAILocalTraffic::FGAILocalTraffic() {
}
FGAILocalTraffic::~FGAILocalTraffic() {
//_model->deRef();
}
void FGAILocalTraffic::GetAirportDetails(const string& id) {

View file

@ -56,8 +56,6 @@ FGAIMgr::FGAIMgr() {
}
FGAIMgr::~FGAIMgr() {
ssgDeRefDelete(_defaultModel);
if(_havePiperModel) ssgDeRefDelete(_piperModel);
}
void FGAIMgr::init() {
@ -105,10 +103,6 @@ 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/");

View file

@ -23,6 +23,7 @@
#define _FG_AIMGR_HXX
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/structure/ssgSharedPtr.hxx>
#include <Main/fg_props.hxx>
@ -109,8 +110,8 @@ public:
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

View file

@ -70,8 +70,6 @@ wxRadarBg::wxRadarBg ()
wxRadarBg::~wxRadarBg ()
{
ssgDeRefDelete(resultTexture);
ssgDeRefDelete(wxEcho);
}
void
@ -83,12 +81,10 @@ wxRadarBg::init ()
_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);

View file

@ -26,6 +26,7 @@
#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;
@ -49,8 +50,8 @@ private:
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;

View file

@ -116,10 +116,10 @@ sgMat4 copy_of_ssgOpenGLAxisSwapMatrix =
{ 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;
@ -141,7 +141,6 @@ FGRenderer::~FGRenderer()
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 );
@ -153,7 +152,6 @@ FGRenderer::build_states( void ) {
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 );
@ -167,14 +165,12 @@ FGRenderer::build_states( void ) {
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 );

View file

@ -17,6 +17,7 @@ SG_USING_STD(string);
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.
@ -43,8 +44,8 @@ public:
private:
SGModelPlacement * _aircraft;
ssgSelector * _selector;
ssgRoot * _scene;
ssgSharedPtr<ssgSelector> _selector;
ssgSharedPtr<ssgRoot> _scene;
float _nearplane;
float _farplane;

View file

@ -90,7 +90,7 @@ private:
vector<Instance *> _instances;
ssgSelector * _selector;
ssgSharedPtr<ssgSelector> _selector;
};

View file

@ -112,7 +112,6 @@ void FGScenery::set_center( const Point3D& p ) {
}
void FGScenery::register_placement_transform(ssgPlacementTransform *trans) {
trans->ref();
_placement_list.push_back(trans);
sgdVec3 c;
sgdSetVec3(c, center.x(), center.y(), center.z());
@ -124,7 +123,6 @@ void FGScenery::unregister_placement_transform(ssgPlacementTransform *trans) {
while (it != _placement_list.end()) {
if ((*it) == trans) {
it = _placement_list.erase(it);
ssgDeRefDelete(trans);
} else
++it;
}
@ -155,7 +153,7 @@ FGScenery::get_cart_elevation_m(const sgdVec3& pos, double max_altoff,
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;
}
}

View file

@ -36,12 +36,13 @@
#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
@ -57,17 +58,17 @@ class FGScenery : public SGSubsystem {
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:

View file

@ -201,16 +201,6 @@ static void my_remove_branch( ssgBranch * branch ) {
// 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 ) {
@ -264,7 +254,7 @@ bool FGTileEntry::free_tile() {
// 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 ) {
@ -272,7 +262,7 @@ bool FGTileEntry::free_tile() {
// 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 ) {
@ -280,7 +270,7 @@ bool FGTileEntry::free_tile() {
// 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 ) {
@ -288,7 +278,7 @@ bool FGTileEntry::free_tile() {
// 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 ) {
@ -296,7 +286,7 @@ bool FGTileEntry::free_tile() {
// 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) ) {
@ -798,21 +788,19 @@ FGTileEntry::load( const string_list &path_list, bool is_base )
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,
@ -821,7 +809,6 @@ FGTileEntry::load( const string_list &path_list, bool is_base )
bounding_radius = br;
new_tile -> addKid( geometry );
} else {
delete geometry;
SG_LOG( SG_TERRAIN, SG_ALERT,
"Warning: failed to generate ocean tile!" );
}
@ -836,10 +823,10 @@ FGTileEntry::load( const string_list &path_list, bool is_base )
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,
@ -850,30 +837,16 @@ FGTileEntry::load( const string_list &path_list, bool is_base )
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;
}
@ -1017,7 +990,6 @@ FGTileEntry::add_ssg_nodes( ssgBranch *terrain_branch,
}
#endif
terra_transform->ref();
terrain_branch->addKid( terra_transform );
globals->get_scenery()->register_placement_transform(terra_transform);
@ -1030,7 +1002,6 @@ FGTileEntry::add_ssg_nodes( ssgBranch *terrain_branch,
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);
}
@ -1038,7 +1009,6 @@ FGTileEntry::add_ssg_nodes( ssgBranch *terrain_branch,
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 );
@ -1047,7 +1017,6 @@ FGTileEntry::add_ssg_nodes( ssgBranch *terrain_branch,
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 );
@ -1056,7 +1025,6 @@ FGTileEntry::add_ssg_nodes( ssgBranch *terrain_branch,
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 );

View file

@ -41,6 +41,8 @@
#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>
@ -58,7 +60,6 @@ typedef point_list::const_iterator const_point_list_iterator;
class ssgLeaf;
class ssgBranch;
class ssgTransform;
class ssgPlacementTransform;
class ssgSelector;
class ssgRangeSelector;
class ssgVertexArray;
@ -75,7 +76,7 @@ private:
string model_path;
string texture_path;
FGTileEntry *tile;
ssgTransform *obj_trans;
ssgSharedPtr<ssgTransform> obj_trans;
SGBucket bucket;
@ -128,27 +129,27 @@ private:
// - 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