Hello,
Attached is a patch for flightgear and simgear that removes the
model_panel kludge and fixes a potential memory leak.
Thoughts/comments?
Simon
Index: src/Main/renderer.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Main/renderer.cxx,v
retrieving revision 1.31
diff -u -r1.31 renderer.cxx
--- src/Main/renderer.cxx 8 Nov 2005 10:00:24 -0000 1.31
+++ src/Main/renderer.cxx 30 Nov 2005 00:12:17 -0000
@@ -750,7 +750,7 @@
if ( globals->get_current_panel() != NULL ) {
globals->get_current_panel()->update(delta_time_sec);
}
- fgUpdate3DPanels();
+ globals->get_aircraft_model()->update3dPanels();
// We can do translucent menus, so why not. :-)
menus->apply();
Index: src/Input/input.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Input/input.cxx,v
retrieving revision 1.72
diff -u -r1.72 input.cxx
--- src/Input/input.cxx 23 Nov 2005 12:48:09 -0000 1.72
+++ src/Input/input.cxx 30 Nov 2005 00:12:19 -0000
@@ -49,7 +49,7 @@
#include <Cockpit/panel.hxx>
#include <Cockpit/panel_io.hxx>
#include <GUI/gui.h>
-#include <Model/panelnode.hxx>
+#include <Model/acmodel.hxx>
#include <Scripting/NasalSys.hxx>
#include <Main/globals.hxx>
@@ -306,7 +306,7 @@
globals->get_current_panel()->getVisibility() &&
globals->get_current_panel()->doMouseAction(b, updown, x, y))
return;
- else if (fgHandle3DPanelMouseEvent(b, updown, x, y))
+ else if (globals->get_aircraft_model()->handle3dPanelMouseEvent(b, updown, x, y))
return;
}
Index: src/Model/Makefile.am
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Model/Makefile.am,v
retrieving revision 1.5
diff -u -r1.5 Makefile.am
--- src/Model/Makefile.am 9 May 2003 20:41:02 -0000 1.5
+++ src/Model/Makefile.am 30 Nov 2005 00:12:19 -0000
@@ -2,7 +2,6 @@
libModel_a_SOURCES = \
acmodel.cxx acmodel.hxx \
- model_panel.cxx model_panel.hxx \
modelmgr.cxx modelmgr.hxx \
panelnode.cxx panelnode.hxx
Index: src/Model/acmodel.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Model/acmodel.cxx,v
retrieving revision 1.15
diff -u -r1.15 acmodel.cxx
--- src/Model/acmodel.cxx 27 Oct 2005 08:40:12 -0000 1.15
+++ src/Model/acmodel.cxx 30 Nov 2005 00:12:19 -0000
@@ -17,6 +17,7 @@
#include <simgear/structure/exception.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/scene/model/placement.hxx>
+#include <simgear/scene/model/model.hxx>
#include <simgear/scene/model/shadowvolume.hxx>
#include <Main/globals.hxx>
@@ -26,7 +27,8 @@
#include <Main/viewer.hxx>
#include <Scenery/scenery.hxx>
-#include "model_panel.hxx"
+#include "panelnode.hxx"
+#include <Cockpit/panel.hxx>
#include "acmodel.hxx"
@@ -84,8 +86,12 @@
delete _aircraft;
delete _scene;
- // SSG will delete it
+
+ // SSG will delete it
globals->get_scenery()->get_aircraft_branch()->removeKid(_selector);
+
+ // SSG deletes the ssgLeaf panel nodes
+ _panel_nodes.clear();
}
void
@@ -107,18 +113,30 @@
_fgLoaderOptions.livery_path = texture_path;
}
try {
- ssgBranch *model = fgLoad3DModelPanel( globals->get_fg_root(),
- path,
- globals->get_props(),
- globals->get_sim_time_sec() );
+ vector<SGPropertyNode_ptr> panel_nodes;
+ ssgBranch *model = sgLoad3DModel( globals->get_fg_root(),
+ path,
+ globals->get_props(),
+ globals->get_sim_time_sec(),
+ &panel_nodes );
+
+ for (int i = 0; i < panel_nodes.size(); i++) {
+ SG_LOG(SG_INPUT, SG_DEBUG, "Loading a panel");
+ FGPanelNode * panel = new FGPanelNode(panel_nodes[i]);
+ if (panel_nodes[i]->hasValue("name"))
+ panel->setName((char *)panel_nodes[i]->getStringValue("name"));
+ addPanelNode(panel);
+ model->addKid(panel);
+ }
+
_aircraft->init( model );
} catch (const sg_exception &ex) {
SG_LOG(SG_GENERAL, SG_ALERT, "Failed to load aircraft from " << path);
SG_LOG(SG_GENERAL, SG_ALERT, "(Falling back to glider.ac.)");
- ssgBranch *model = fgLoad3DModelPanel( globals->get_fg_root(),
- "Models/Geometry/glider.ac",
- globals->get_props(),
- globals->get_sim_time_sec() );
+ ssgBranch *model = sgLoad3DModel( globals->get_fg_root(),
+ "Models/Geometry/glider.ac",
+ globals->get_props(),
+ globals->get_sim_time_sec() );
_aircraft->init( model );
}
_scene->addKid(_aircraft->getSceneGraph());
@@ -186,4 +204,25 @@
}
+void FGAircraftModel::addPanelNode(FGPanelNode * n)
+{
+ _panel_nodes.push_back(n);
+}
+
+void FGAircraftModel::update3dPanels()
+{
+ for (unsigned int i = 0; i < _panel_nodes.size(); i++) {
+ _panel_nodes[i]->getPanel()->updateMouseDelay();
+ }
+
+}
+
+bool FGAircraftModel::handle3dPanelMouseEvent(int button, int updown, int x, int y)
+{
+ for (unsigned int i = 0; i < _panel_nodes.size(); i++) {
+ if ( _panel_nodes[i]->doMouseAction(button, updown, x, y) )
+ return true;
+ }
+ return false;
+}
// end of model.cxx
Index: src/Model/acmodel.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Model/acmodel.hxx,v
retrieving revision 1.7
diff -u -r1.7 acmodel.hxx
--- src/Model/acmodel.hxx 29 Apr 2005 14:38:24 -0000 1.7
+++ src/Model/acmodel.hxx 30 Nov 2005 00:12:19 -0000
@@ -23,6 +23,7 @@
class ssgRoot;
class ssgSelector;
class SGModelPlacement;
+class FGPanelNode;
class FGAircraftModel : public SGSubsystem
@@ -39,6 +40,9 @@
virtual void draw ();
virtual SGModelPlacement * get3DModel() { return _aircraft; }
void select( bool s ) { _selector->select( s ? 0xffffffff : 0 ); }
+ void addPanelNode(FGPanelNode *n);
+ void update3dPanels();
+ bool handle3dPanelMouseEvent(int button, int updown, int x, int y);
private:
@@ -47,6 +51,7 @@
ssgRoot * _scene;
float _nearplane;
float _farplane;
+ vector<FGPanelNode*> _panel_nodes;
};
Index: src/Model/panelnode.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Model/panelnode.cxx,v
retrieving revision 1.10
diff -u -r1.10 panelnode.cxx
--- src/Model/panelnode.cxx 22 Aug 2005 17:49:50 -0000 1.10
+++ src/Model/panelnode.cxx 30 Nov 2005 00:12:19 -0000
@@ -13,27 +13,6 @@
SG_USING_STD(vector);
-
-// Static (!) handling for all 3D panels in the program. Very
-// clumsy. Replace with per-aircraft handling.
-vector<FGPanelNode*> all_3d_panels;
-bool fgHandle3DPanelMouseEvent( int button, int updown, int x, int y )
-{
- for ( unsigned int i = 0; i < all_3d_panels.size(); i++ ) {
- if ( all_3d_panels[i]->doMouseAction(button, updown, x, y) ) {
- return true;
- }
- }
- return false;
-}
-
-void fgUpdate3DPanels()
-{
- for ( unsigned int i = 0; i < all_3d_panels.size(); i++ ) {
- all_3d_panels[i]->getPanel()->updateMouseDelay();
- }
-}
-
FGPanelNode::FGPanelNode(SGPropertyNode* props)
{
int i;
@@ -115,9 +94,6 @@
(cz-a[2])*(cz-a[2]));
bsphere.setCenter(cx, cy, cz);
bsphere.setRadius(r);
-
- // All done. Add us to the list
- all_3d_panels.push_back(this);
}
FGPanelNode::~FGPanelNode()
Index: src/Model/panelnode.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Model/panelnode.hxx,v
retrieving revision 1.4
diff -u -r1.4 panelnode.hxx
--- src/Model/panelnode.hxx 26 Jun 2005 17:21:18 -0000 1.4
+++ src/Model/panelnode.hxx 30 Nov 2005 00:12:19 -0000
@@ -12,12 +12,6 @@
// many methods, mostly involved with modelling and runtime
// inspection, are unimplemented.
-// Static mouse handler for all FGPanelNodes. Very clumsy; this
-// should really be done through our container (an aircraft model,
-// typically).
-bool fgHandle3DPanelMouseEvent(int button, int updown, int x, int y);
-void fgUpdate3DPanels();
-
class FGPanelNode : public ssgLeaf
{
protected:Index: simgear/scene/model/model.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/SimGear/simgear/scene/model/model.cxx,v
retrieving revision 1.35
diff -u -r1.35 model.cxx
--- simgear/scene/model/model.cxx 25 Sep 2005 07:44:50 -0000 1.35
+++ simgear/scene/model/model.cxx 29 Nov 2005 22:47:25 -0000
@@ -245,7 +245,8 @@
ssgBranch *
sgLoad3DModel( const string &fg_root, const string &path,
SGPropertyNode *prop_root,
- double sim_time_sec, ssgEntity *(*load_panel)(SGPropertyNode *) )
+ double sim_time_sec,
+ vector<SGPropertyNode_ptr> *panel_nodes )
{
ssgBranch * model = 0;
SGPropertyNode props;
@@ -287,7 +288,8 @@
}
// Set up the alignment node
ssgTransform * alignmainmodel = new ssgTransform;
- if ( load_panel == 0 )
+
+ if (!panel_nodes)
alignmainmodel->setTravCallback( SSG_CALLBACK_PRETRAV, model_filter_callback );
alignmainmodel->addKid(model);
sgMat4 res_matrix;
@@ -318,23 +320,19 @@
align->setTransform(res_matrix);
ssgBranch * kid = sgLoad3DModel( fg_root, node->getStringValue("path"),
- prop_root, sim_time_sec, load_panel );
+ prop_root, sim_time_sec, panel_nodes );
align->addKid(kid);
align->setName(node->getStringValue("name", ""));
model->addKid(align);
}
- if ( load_panel ) {
- // Load panels
- vector<SGPropertyNode_ptr> panel_nodes = props.getChildren("panel");
- for (i = 0; i < panel_nodes.size(); i++) {
- SG_LOG(SG_INPUT, SG_DEBUG, "Loading a panel");
- ssgEntity * panel = load_panel(panel_nodes[i]);
- if (panel_nodes[i]->hasValue("name"))
- panel->setName((char *)panel_nodes[i]->getStringValue("name"));
- model->addKid(panel);
+ if (panel_nodes) {
+ vector<SGPropertyNode_ptr> pn = props.getChildren("panel");
+ for (i = 0; i < pn.size(); i++) {
+ (*panel_nodes).push_back(pn[i]);
}
}
+
// Load animations
set<ssgBranch *> ignore_branches;
vector<SGPropertyNode_ptr> animation_nodes = props.getChildren("animation");
@@ -352,7 +350,6 @@
}
#endif
-
return alignmainmodel;
}
Index: simgear/scene/model/model.hxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/SimGear/simgear/scene/model/model.hxx,v
retrieving revision 1.8
diff -u -r1.8 model.hxx
--- simgear/scene/model/model.hxx 5 Jul 2005 17:08:27 -0000 1.8
+++ simgear/scene/model/model.hxx 29 Nov 2005 22:47:25 -0000
@@ -47,8 +47,7 @@
ssgBranch *
sgLoad3DModel( const string& fg_root, const string &path,
SGPropertyNode *prop_root, double sim_time_sec,
- ssgEntity *(*load_panel)(SGPropertyNode *) = 0 );
-
+ vector<SGPropertyNode_ptr> *panel_nodes = 0 );
/**
* Make an offset matrix from rotations and position offset.
Index: simgear/scene/model/placement.cxx
===================================================================
RCS file: /var/cvs/SimGear-0.3/SimGear/simgear/scene/model/placement.cxx,v
retrieving revision 1.6
diff -u -r1.6 placement.cxx
--- simgear/scene/model/placement.cxx 5 Sep 2005 13:23:55 -0000 1.6
+++ simgear/scene/model/placement.cxx 29 Nov 2005 22:47:25 -0000
@@ -41,6 +41,7 @@
SGModelPlacement::~SGModelPlacement ()
{
+ delete _location;
}
void_______________________________________________
Flightgear-devel mailing list
[email protected]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d