]> git.mxchange.org Git - flightgear.git/commitdiff
Tweak ODGauge usage, fix multiple instances of NavDisplay or wxRadar.
authorJames Turner <zakalawe@mac.com>
Sun, 15 Apr 2012 11:03:21 +0000 (12:03 +0100)
committerJames Turner <zakalawe@mac.com>
Sun, 15 Apr 2012 11:03:21 +0000 (12:03 +0100)
13 files changed:
src/Instrumentation/NavDisplay.cxx
src/Instrumentation/NavDisplay.hxx
src/Instrumentation/agradar.cxx
src/Instrumentation/agradar.hxx
src/Instrumentation/groundradar.cxx
src/Instrumentation/groundradar.hxx
src/Instrumentation/instrument_mgr.cxx
src/Instrumentation/od_gauge.cxx
src/Instrumentation/od_gauge.hxx
src/Instrumentation/wxradar.cxx
src/Instrumentation/wxradar.hxx
src/Main/renderer.cxx
src/Main/renderer.hxx

index b33311d07fb2e976c502519a9614e040bf40212c..c45a705efe5eadf624b0fc851895b6c783bd9885 100644 (file)
@@ -418,7 +418,6 @@ NavDisplay::NavDisplay(SGPropertyNode *node) :
     _odg(0),
     _scale(0),
     _view_heading(0),
-    _resultTexture(0),
     _font_size(0),
     _font_spacing(0),
     _rangeNm(0)
@@ -485,9 +484,9 @@ NavDisplay::NavDisplay(SGPropertyNode *node) :
 
 NavDisplay::~NavDisplay()
 {
+  delete _odg;
 }
 
-
 void
 NavDisplay::init ()
 {
@@ -517,7 +516,6 @@ NavDisplay::init ()
     // texture name to use in 2D and 3D instruments
     _texture_path = _Instrument->getStringValue("radar-texture-path",
         "Aircraft/Instruments/Textures/od_wxradar.rgb");
-    _resultTexture = FGTextureManager::createTexture(_texture_path.c_str(), false);
 
     string path = _Instrument->getStringValue("symbol-texture-path",
         "Aircraft/Instruments/Textures/nd-symbols.png");
@@ -529,8 +527,7 @@ NavDisplay::init ()
     // no mipmap or else alpha will mix with pixels on the border of shapes, ruining the effect
     _symbolTexture = SGLoadTexture2D(tpath, NULL, false, false);
 
-    FGInstrumentMgr *imgr = (FGInstrumentMgr *)globals->get_subsystem("instrumentation");
-    _odg = (FGODGauge *)imgr->get_subsystem("od_gauge");
+    _odg = new FGODGauge;
     _odg->setSize(_Instrument->getIntValue("texture-size", 512));
 
     _route = static_cast<FGRouteMgr*>(globals->get_subsystem("route-manager"));
index 8db2dce7eee0076118e94a49480fb39381f0c6cd..3e7adc7fa6566aac1c4218af82a53fff4606c92b 100644 (file)
@@ -147,7 +147,6 @@ private:
     SGPropertyNode_ptr _navRadio2Node;
     SGPropertyNode_ptr _xCenterNode, _yCenterNode;
     
-    osg::ref_ptr<osg::Texture2D> _resultTexture;
     osg::ref_ptr<osg::Texture2D> _symbolTexture;
     osg::ref_ptr<osg::Geode> _radarGeode;
     osg::ref_ptr<osg::Geode> _textGeode;
index b5cd064f2a291c62c93151ec88b3cc3912f4333c..e5be21b86332a2066333b7ead655e29d6c31088b 100644 (file)
@@ -213,7 +213,7 @@ agRadar::getMaterial(){
     if (globals->get_scenery()->get_elevation_m(hitpos, _elevation_m, &_material)){
         //_ht_agl_ft = pos.getElevationFt() - _elevation_m * SG_METER_TO_FEET;
         if (_material) {
-            const vector<string>& names = _material->get_names();
+            const std::vector<std::string>& names = _material->get_names();
 
             _solid = _material->get_solid();
             _load_resistance = _material->get_load_resistance();
index f5ad02d73ae79a477c29aded63cdfccd43688c0f..609f54f41805507a4dbf0f800c583cda46d641e5 100644 (file)
@@ -55,7 +55,7 @@ public:
 
     const SGMaterial* _material;
 
-    string _mat_name; // ground material
+    std::string _mat_name; // ground material
 
     SGVec3d getCartUserPos() const;
     SGVec3d getCartAntennaPos()const;
index c604cc43c224121088d3f1ef53125fd5adc85c6e..2669d2ab1b151b3cf42c22dff4a4b208570b10b0 100644 (file)
@@ -77,6 +77,11 @@ GroundRadar::~GroundRadar()
     _range_node->removeChangeListener(this);
 }
 
+void GroundRadar::update (double /* dt */)
+{
+  
+}
+
 void GroundRadar::valueChanged(SGPropertyNode*)
 {
     updateTexture();
index dc653f2c4d3666b47ec88b9db375bf0d707b1de9..fb603be191dc650017dfeb4b494e09071bbd5b76 100644 (file)
@@ -24,6 +24,7 @@
 #include <osg/Geometry>
 #include <simgear/props/props.hxx>
 #include "od_gauge.hxx"
+#include <simgear/structure/subsystem_mgr.hxx>
 
 // forward decls
 class FGRunwayBase;
@@ -32,7 +33,7 @@ class FGRunwayBase;
 // Built-in layer for the atc radar.
 ////////////////////////////////////////////////////////////////////////
 
-class GroundRadar : public SGPropertyChangeListener, public FGODGauge
+class GroundRadar : public SGSubsystem, public SGPropertyChangeListener, private FGODGauge
 {
 public:
     static const int TextureHalfSize = 256;
@@ -40,7 +41,7 @@ public:
     virtual ~GroundRadar();
     void updateTexture();
     virtual void valueChanged(SGPropertyNode*);
-
+    virtual void update (double dt);
 protected:
     void createTexture(const char* texture_name);
     
index c6694173f77565a21e2a113230fdb6d48d7c10ec..9d034800a7ab08aa1783ff239aa9d9dab5eede9c 100644 (file)
@@ -43,7 +43,6 @@
 #include "turn_indicator.hxx"
 #include "vertical_speed_indicator.hxx"
 #include "inst_vertical_speed_indicator.hxx"
-#include "od_gauge.hxx"
 #include "wxradar.hxx"
 #include "tacan.hxx"
 #include "mk_viii.hxx"
@@ -56,9 +55,7 @@
 
 FGInstrumentMgr::FGInstrumentMgr () :
   _explicitGps(false)
-{
-    set_subsystem("od_gauge", new FGODGauge);
-    
+{    
     globals->add_subsystem("hud", new HUD, SGSubsystemMgr::DISPLAY);
 }
 
@@ -138,7 +135,7 @@ bool FGInstrumentMgr::build (SGPropertyNode* config_props)
             subsystemname << '['<< index << ']';
         string id = subsystemname.str();
         _instruments.push_back(id);
-
+      
         if ( name == "adf" ) {
             set_subsystem( id, new ADF( node ), 0.15 );
 
index 349d7fdbfd7538534e963e3436f1b7cb08ce5590..ad79f021ac5bbc8dfdf53d63d77a9c32bf2a7d44 100644 (file)
@@ -26,6 +26,7 @@
 #  include "config.h"
 #endif
 
+#include <osg/Texture2D>
 #include <osg/AlphaFunc>
 #include <osg/BlendFunc>
 #include <osg/Camera>
 #include "od_gauge.hxx"
 
 FGODGauge::FGODGauge() :
-    rtAvailable( false )// ,
-//     rt( 0 )
+  rtAvailable( false )
 {
 }
 
-void FGODGauge::allocRT () {
+void FGODGauge::allocRT ()
+{
     camera = new osg::Camera;
     // Only the far camera should trigger this texture to be rendered.
     camera->setNodeMask(simgear::BACKGROUND_BIT);
@@ -87,65 +88,25 @@ void FGODGauge::allocRT () {
     camera->attach(osg::Camera::COLOR_BUFFER, texture.get());
     globals->get_renderer()->addCamera(camera.get(), false);
     rtAvailable = true;
-
-    // GLint colorBits = 0;
-//     glGetIntegerv( GL_BLUE_BITS, &colorBits );
-//     rt = new RenderTexture();
-//     if( colorBits < 8 )
-//         rt->Reset("rgba=5,5,5,1 ctt");
-//     else
-//         rt->Reset("rgba ctt");
-
-//     if( rt->Initialize(256, 256, true) ) {
-//         SG_LOG(SG_INSTR, SG_INFO, "FGODGauge:Initialize sucessfull");
-//         if (rt->BeginCapture())
-//         {
-//             SG_LOG(SG_INSTR, SG_INFO, "FGODGauge:BeginCapture sucessfull, RTT available");
-//             rtAvailable = true;
-//             glViewport(0, 0, textureWH, textureWH);
-//             glMatrixMode(GL_PROJECTION);
-//             glLoadIdentity();
-//             gluOrtho2D( -256.0, 256.0, -256.0, 256.0 );
-//             glMatrixMode(GL_MODELVIEW);
-//             glLoadIdentity();
-//             glDisable(GL_LIGHTING);
-//             glEnable(GL_COLOR_MATERIAL);
-//             glDisable(GL_CULL_FACE);
-//             glDisable(GL_FOG);
-//             glDisable(GL_DEPTH_TEST);
-//             glClearColor(0.0, 0.0, 0.0, 0.0);
-//             glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-//             glBindTexture(GL_TEXTURE_2D, 0);
-//             glEnable(GL_TEXTURE_2D);
-//             glEnable(GL_ALPHA_TEST);
-//             glAlphaFunc(GL_GREATER, 0.0f);
-//             glDisable(GL_SMOOTH);
-//             glEnable(GL_BLEND);
-//             glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
-//             rt->EndCapture();
-//         } else
-//             SG_LOG(SG_INSTR, SG_WARN, "FGODGauge:BeginCapture failed, RTT not available, using backbuffer");
-//     } else
-//         SG_LOG(SG_INSTR, SG_WARN, "FGODGauge:Initialize failed, RTT not available, using backbuffer");
-}
-
-FGODGauge::~FGODGauge() {
-//     delete rt;
-}
-
-void FGODGauge::init () {
 }
 
-void FGODGauge::update (double dt) {
+FGODGauge::~FGODGauge()
+{
+    if (camera.valid()) {
+        globals->get_renderer()->removeCamera(camera.get());
+    }
 }
 
-
-void FGODGauge::setSize(int viewSize) {
+void FGODGauge::setSize(int viewSize)
+{
     textureWH = viewSize;
-//     glViewport(0, 0, textureWH, textureWH);
+    if (texture.valid()) {
+        texture->setTextureSize(textureWH, textureWH);
+    }
 }
 
-bool FGODGauge::serviceable(void) {
+bool FGODGauge::serviceable(void) 
+{
     return rtAvailable;
 }
 
index 932b4847d1773eb0324322a9b1e00233fd4f178c..b867d22d47c9d8a398ffb14a844ab3522aeeae4e 100644 (file)
 #ifndef _OD_GAUGE_HXX
 #define _OD_GAUGE_HXX
 
-#include <osg/Camera>
-#include <osg/Texture2D>
 
-#include <simgear/structure/subsystem_mgr.hxx>
+#include <osg/ref_ptr>
+
+namespace osg {
+  class Camera;
+  class Texture2D;
+}
 
 /**
  * Owner Drawn Gauge helper class.
  */
-class FGODGauge : public SGSubsystem {
-
+class FGODGauge
+{
 public:
-    FGODGauge ( SGPropertyNode *node );
     FGODGauge();
     virtual ~FGODGauge();
-    virtual void init ();
-    virtual void update (double dt);
 
+  
     void setSize(int viewSize);
     int size() const
         { return textureWH; }
index 81e35c8124525ed2d51c0cea758d58e381108397..b1f81be656ebf2e293ba902f662e6331943a4990 100644 (file)
@@ -119,6 +119,7 @@ wxRadarBg::wxRadarBg(SGPropertyNode *node) :
 wxRadarBg::~wxRadarBg ()
 {
     _font_node->removeChangeListener(this);
+    delete _odg;
 }
 
 
@@ -155,8 +156,7 @@ wxRadarBg::init ()
     // input range = n nm (20/40/80)
     // input display-mode = arc | rose | map | plan
 
-    FGInstrumentMgr *imgr = (FGInstrumentMgr *)globals->get_subsystem("instrumentation");
-    _odg = (FGODGauge *)imgr->get_subsystem("od_gauge");
+    _odg = new FGODGauge;
     _odg->setSize(512);
 
     _ai_enabled_node = fgGetNode("/sim/ai/enabled", true);
index 9caa586737f5ae5431805b49797a09c90931c9b2..7aff7771718b2be81c13b5b560f3de7d2b8a3223 100644 (file)
@@ -34,9 +34,6 @@
 #include <vector>
 #include <string>
 
-using std::vector;
-using std::string;
-
 class FGODGauge;
 
 class wxRadarBg : public SGSubsystem, public SGPropertyChangeListener {
@@ -78,7 +75,7 @@ protected:
         double elapsed_time;
     }ground_echo;
 
-    typedef vector <ground_echo*> ground_echo_vector_type;
+    typedef std::vector <ground_echo*> ground_echo_vector_type;
     typedef ground_echo_vector_type::iterator ground_echo_vector_iterator;
 
     ground_echo_vector_type       ground_echoes;
index 36b0a1dbd244d08a05cd6c22df8c12de7a72a233..679220201fd7de54cfa5636949536ed64bc2a5f2 100644 (file)
@@ -1838,6 +1838,12 @@ FGRenderer::addCamera(osg::Camera* camera, bool useSceneData)
     mRealRoot->addChild(camera);
 }
 
+void
+FGRenderer::removeCamera(osg::Camera* camera)
+{
+    mRealRoot->removeChild(camera);
+}
+                                    
 void
 FGRenderer::setPlanes( double zNear, double zFar )
 {
index 664d6c32ad66a41aee4966587a94db9bcd6f7114..1093080b607a6e7c92947dfff2cbfe56f9afe7e1 100644 (file)
@@ -77,6 +77,8 @@ public:
      */
     void addCamera(osg::Camera* camera, bool useSceneData);
 
+    void removeCamera(osg::Camera* camera);
+  
     /** Add a camera to the group. The camera is added to the viewer
      * as a slave. See osgViewer::Viewer::addSlave.
      * @param flags properties of the camera; see CameraGroup::Flags