From 3464eef7112c69b73424314e2b0c876072293497 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 22 Oct 2010 19:11:24 +0100 Subject: [PATCH] Make the v2 HUD support reinit(), so HUDs can be reloaded at runtime. --- src/Instrumentation/HUD/HUD.cxx | 34 +++++++++++++++++++++++---------- src/Instrumentation/HUD/HUD.hxx | 4 ++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/Instrumentation/HUD/HUD.cxx b/src/Instrumentation/HUD/HUD.cxx index 4ea539db3..4a7d6a542 100644 --- a/src/Instrumentation/HUD/HUD.cxx +++ b/src/Instrumentation/HUD/HUD.cxx @@ -115,14 +115,8 @@ HUD::~HUD() _scr_heightN->removeChangeListener(this); _unitsN->removeChangeListener(this); delete _font_renderer; - delete _clip_box; - - deque::const_iterator it, end = _items.end(); - for (it = _items.begin(); it != end; ++it) - delete *it; - end = _ladders.end(); - for (it = _ladders.begin(); it != end; ++it) - delete *it; + + deinit(); } @@ -146,6 +140,27 @@ void HUD::init() _path->fireValueChanged(); } +void HUD::deinit() +{ + deque::const_iterator it, end = _items.end(); + for (it = _items.begin(); it != end; ++it) + delete *it; + end = _ladders.end(); + for (it = _ladders.begin(); it != end; ++it) + delete *it; + + _items.clear(); + _ladders.clear(); + + delete _clip_box; + _clip_box = NULL; +} + +void HUD::reinit() +{ + deinit(); + _path->fireValueChanged(); +} void HUD::update(double dt) { @@ -328,8 +343,7 @@ int HUD::load(const char *file, float x, float y, int level, const string& inden const sgDebugPriority TREE = SG_INFO; const int MAXNEST = 10; - SGPath path(globals->get_fg_root()); - path.append(file); + SGPath path(globals->resolve_maybe_aircraft_path(file)); if (!level) { SG_LOG(SG_INPUT, TREE, endl << "load " << file); diff --git a/src/Instrumentation/HUD/HUD.hxx b/src/Instrumentation/HUD/HUD.hxx index 6776495f2..3ef9d7ee7 100644 --- a/src/Instrumentation/HUD/HUD.hxx +++ b/src/Instrumentation/HUD/HUD.hxx @@ -153,6 +153,8 @@ public: void init(); void update(double); + void reinit(); + // called from Main/renderer.cxx to draw 2D and 3D HUD void draw(osg::State&); @@ -195,6 +197,8 @@ protected: int level = 0, const std::string& indent = ""); private: + void deinit(); + void draw3D(); void draw2D(GLfloat, GLfloat, GLfloat, GLfloat); -- 2.39.5