From: James Turner Date: Sun, 15 Apr 2012 11:03:21 +0000 (+0100) Subject: Tweak ODGauge usage, fix multiple instances of NavDisplay or wxRadar. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=96ee2b1577d16564cd43ac0ddf50ac784f807d29;p=flightgear.git Tweak ODGauge usage, fix multiple instances of NavDisplay or wxRadar. --- diff --git a/src/Instrumentation/NavDisplay.cxx b/src/Instrumentation/NavDisplay.cxx index b33311d07..c45a705ef 100644 --- a/src/Instrumentation/NavDisplay.cxx +++ b/src/Instrumentation/NavDisplay.cxx @@ -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(globals->get_subsystem("route-manager")); diff --git a/src/Instrumentation/NavDisplay.hxx b/src/Instrumentation/NavDisplay.hxx index 8db2dce7e..3e7adc7fa 100644 --- a/src/Instrumentation/NavDisplay.hxx +++ b/src/Instrumentation/NavDisplay.hxx @@ -147,7 +147,6 @@ private: SGPropertyNode_ptr _navRadio2Node; SGPropertyNode_ptr _xCenterNode, _yCenterNode; - osg::ref_ptr _resultTexture; osg::ref_ptr _symbolTexture; osg::ref_ptr _radarGeode; osg::ref_ptr _textGeode; diff --git a/src/Instrumentation/agradar.cxx b/src/Instrumentation/agradar.cxx index b5cd064f2..e5be21b86 100644 --- a/src/Instrumentation/agradar.cxx +++ b/src/Instrumentation/agradar.cxx @@ -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& names = _material->get_names(); + const std::vector& names = _material->get_names(); _solid = _material->get_solid(); _load_resistance = _material->get_load_resistance(); diff --git a/src/Instrumentation/agradar.hxx b/src/Instrumentation/agradar.hxx index f5ad02d73..609f54f41 100644 --- a/src/Instrumentation/agradar.hxx +++ b/src/Instrumentation/agradar.hxx @@ -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; diff --git a/src/Instrumentation/groundradar.cxx b/src/Instrumentation/groundradar.cxx index c604cc43c..2669d2ab1 100644 --- a/src/Instrumentation/groundradar.cxx +++ b/src/Instrumentation/groundradar.cxx @@ -77,6 +77,11 @@ GroundRadar::~GroundRadar() _range_node->removeChangeListener(this); } +void GroundRadar::update (double /* dt */) +{ + +} + void GroundRadar::valueChanged(SGPropertyNode*) { updateTexture(); diff --git a/src/Instrumentation/groundradar.hxx b/src/Instrumentation/groundradar.hxx index dc653f2c4..fb603be19 100644 --- a/src/Instrumentation/groundradar.hxx +++ b/src/Instrumentation/groundradar.hxx @@ -24,6 +24,7 @@ #include #include #include "od_gauge.hxx" +#include // 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); diff --git a/src/Instrumentation/instrument_mgr.cxx b/src/Instrumentation/instrument_mgr.cxx index c6694173f..9d034800a 100644 --- a/src/Instrumentation/instrument_mgr.cxx +++ b/src/Instrumentation/instrument_mgr.cxx @@ -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 ); diff --git a/src/Instrumentation/od_gauge.cxx b/src/Instrumentation/od_gauge.cxx index 349d7fdbf..ad79f021a 100644 --- a/src/Instrumentation/od_gauge.cxx +++ b/src/Instrumentation/od_gauge.cxx @@ -26,6 +26,7 @@ # include "config.h" #endif +#include #include #include #include @@ -46,12 +47,12 @@ #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; } diff --git a/src/Instrumentation/od_gauge.hxx b/src/Instrumentation/od_gauge.hxx index 932b4847d..b867d22d4 100644 --- a/src/Instrumentation/od_gauge.hxx +++ b/src/Instrumentation/od_gauge.hxx @@ -25,23 +25,24 @@ #ifndef _OD_GAUGE_HXX #define _OD_GAUGE_HXX -#include -#include -#include +#include + +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; } diff --git a/src/Instrumentation/wxradar.cxx b/src/Instrumentation/wxradar.cxx index 81e35c812..b1f81be65 100644 --- a/src/Instrumentation/wxradar.cxx +++ b/src/Instrumentation/wxradar.cxx @@ -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); diff --git a/src/Instrumentation/wxradar.hxx b/src/Instrumentation/wxradar.hxx index 9caa58673..7aff77717 100644 --- a/src/Instrumentation/wxradar.hxx +++ b/src/Instrumentation/wxradar.hxx @@ -34,9 +34,6 @@ #include #include -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_vector_type; + typedef std::vector ground_echo_vector_type; typedef ground_echo_vector_type::iterator ground_echo_vector_iterator; ground_echo_vector_type ground_echoes; diff --git a/src/Main/renderer.cxx b/src/Main/renderer.cxx index 36b0a1dbd..679220201 100644 --- a/src/Main/renderer.cxx +++ b/src/Main/renderer.cxx @@ -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 ) { diff --git a/src/Main/renderer.hxx b/src/Main/renderer.hxx index 664d6c32a..1093080b6 100644 --- a/src/Main/renderer.hxx +++ b/src/Main/renderer.hxx @@ -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