From cb7589cc959de769c1560efcdbd1c7211a8eea92 Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 15 May 2003 21:35:31 +0000 Subject: [PATCH] Various code massaging. --- simgear/scene/model/Makefile.am | 4 +- simgear/scene/model/loader.cxx | 77 ----------------- simgear/scene/model/location.cxx | 3 - simgear/scene/model/model.cxx | 3 +- simgear/scene/model/modellib.cxx | 85 +++++++++++++++++++ .../scene/model/{loader.hxx => modellib.hxx} | 34 +++----- simgear/scene/model/placement.cxx | 2 +- 7 files changed, 104 insertions(+), 104 deletions(-) delete mode 100644 simgear/scene/model/loader.cxx create mode 100644 simgear/scene/model/modellib.cxx rename simgear/scene/model/{loader.hxx => modellib.hxx} (61%) diff --git a/simgear/scene/model/Makefile.am b/simgear/scene/model/Makefile.am index 360d6c60..3734733b 100644 --- a/simgear/scene/model/Makefile.am +++ b/simgear/scene/model/Makefile.am @@ -6,16 +6,16 @@ noinst_HEADERS = include_HEADERS = \ animation.hxx \ - loader.hxx \ location.hxx \ model.hxx \ + modellib.hxx \ placement.hxx libsgmodel_a_SOURCES = \ animation.cxx \ - loader.cxx \ location.cxx \ model.cxx \ + modellib.cxx \ placement.cxx INCLUDES = -I$(top_srcdir) diff --git a/simgear/scene/model/loader.cxx b/simgear/scene/model/loader.cxx deleted file mode 100644 index bf833fc4..00000000 --- a/simgear/scene/model/loader.cxx +++ /dev/null @@ -1,77 +0,0 @@ -// loader.cxx - implement SSG model and texture loaders. - -#include -#include - -#include "loader.hxx" -#include "model.hxx" - - - -//////////////////////////////////////////////////////////////////////// -// Implementation of SGssgLoader. -//////////////////////////////////////////////////////////////////////// - -SGssgLoader::SGssgLoader () -{ - // no op -} - -SGssgLoader::~SGssgLoader () -{ - std::map::iterator it = _table.begin(); - while (it != _table.end()) { - it->second->deRef(); - _table.erase(it); - } -} - -void -SGssgLoader::flush () -{ - std::map::iterator it = _table.begin(); - while (it != _table.end()) { - ssgBase * item = it->second; - // If there is only one reference, it's - // ours; no one else is using the item. - if (item->getRef() == 1) { - item->deRef(); - _table.erase(it); - } - it++; - } -} - - - -//////////////////////////////////////////////////////////////////////// -// Implementation of SGModelLoader. -//////////////////////////////////////////////////////////////////////// - -SGModelLoader::SGModelLoader () -{ -} - -SGModelLoader::~SGModelLoader () -{ -} - -ssgEntity * -SGModelLoader::load_model( const string &fg_root, - const string &path, - SGPropertyNode *prop_root, - double sim_time_sec ) -{ - // FIXME: normalize path to - // avoid duplicates. - std::map::iterator it = _table.find(path); - if (it == _table.end()) { - _table[path] = sgLoad3DModel( fg_root, path, prop_root, sim_time_sec ); - it = _table.find(path); - it->second->ref(); // add one reference to keep it around - } - return (ssgEntity *)it->second; -} - - -// end of loader.cxx diff --git a/simgear/scene/model/location.cxx b/simgear/scene/model/location.cxx index 57c2975e..5ae03aed 100644 --- a/simgear/scene/model/location.cxx +++ b/simgear/scene/model/location.cxx @@ -35,9 +35,6 @@ #include #include -// #include -// #include "globals.hxx" - #include "location.hxx" diff --git a/simgear/scene/model/model.cxx b/simgear/scene/model/model.cxx index b6394fb7..425d558d 100644 --- a/simgear/scene/model/model.cxx +++ b/simgear/scene/model/model.cxx @@ -21,7 +21,8 @@ #include #include #include -#include + +#include "animation.hxx" #include "model.hxx" diff --git a/simgear/scene/model/modellib.cxx b/simgear/scene/model/modellib.cxx new file mode 100644 index 00000000..3d3edd1b --- /dev/null +++ b/simgear/scene/model/modellib.cxx @@ -0,0 +1,85 @@ +// modellib.cxx - implement an SSG model library. + +#include +#include + +#include "model.hxx" + +#include "modellib.hxx" + + + +//////////////////////////////////////////////////////////////////////// +// Implementation of SGModelLib. +//////////////////////////////////////////////////////////////////////// + +SGModelLib::SGModelLib () +{ +} + +SGModelLib::~SGModelLib () +{ + map::iterator it = _table.begin(); + while (it != _table.end()) { + it->second->deRef(); + _table.erase(it); + } +} + +void +SGModelLib::flush1() +{ + // This routine is disabled because I believe I see multiple + // problems with it. + // + // 1. It blindly deletes all managed models that aren't used + // elsewhere. Is this what we really want???? In the one + // FlightGear case that calls this method, this clearly is not the + // intention. I believe it makes more sense to simply leave items + // in the lbrary, even if they are not currently used, they will be + // there already when/if we want to use them later. + // + // 2. This routine only does a deRef() on the model. This doesn't actually + // delete the ssg tree so there is a memory leak. + + SG_LOG( SG_GENERAL, SG_ALERT, + "WARNGING: a disabled/broken routine has been called. This should be fixed!" ); + + return; + + map::iterator it = _table.begin(); + while (it != _table.end()) { + ssgBase *item = it->second; + // If there is only one reference, it's + // ours; no one else is using the item. + if (item->getRef() == 1) { + item->deRef(); + _table.erase(it); + } + it++; + } +} + + +ssgEntity * +SGModelLib::load_model( const string &fg_root, + const string &path, + SGPropertyNode *prop_root, + double sim_time_sec ) +{ + // FIXME: normalize path to + // avoid duplicates. + map::iterator it = _table.find(path); + if (it == _table.end()) { + ssgEntity *model = sgLoad3DModel( fg_root, path, prop_root, + sim_time_sec ); + model->ref(); + _table[path] = model; // add one reference to keep it around + return model; + } else { + return (ssgEntity *)it->second; + } +} + + +// end of modellib.cxx diff --git a/simgear/scene/model/loader.hxx b/simgear/scene/model/modellib.hxx similarity index 61% rename from simgear/scene/model/loader.hxx rename to simgear/scene/model/modellib.hxx index cd2da075..deed1e68 100644 --- a/simgear/scene/model/loader.hxx +++ b/simgear/scene/model/modellib.hxx @@ -1,5 +1,7 @@ -#ifndef __MODEL_LOADER_HXX -#define __MODEL_LOADER_HXX 1 +// modellib.cxx - implement an SSG model library. + +#ifndef _SG_MODEL_LIB_HXX +#define _SG_MODEL_LIB_HXX 1 #ifndef __cplusplus # error This library requires C++ @@ -18,34 +20,26 @@ SG_USING_STD(map); SG_USING_STD(string); -/** - * Base class for loading and managing SSG things. - */ -class SGssgLoader -{ -public: - SGssgLoader (); - virtual ~SGssgLoader (); - virtual void flush (); -protected: - std::map _table; -}; - - /** * Class for loading and managing models with XML wrappers. */ -class SGModelLoader : public SGssgLoader +class SGModelLib { + public: - SGModelLoader (); - virtual ~SGModelLoader (); + + SGModelLib (); + virtual ~SGModelLib (); + virtual void flush1(); virtual ssgEntity *load_model( const string &fg_root, const string &path, SGPropertyNode *prop_root, double sim_time_sec ); +protected: + + map _table; }; -#endif +#endif // _SG_MODEL_LIB_HXX diff --git a/simgear/scene/model/placement.cxx b/simgear/scene/model/placement.cxx index b408062b..cbee20f5 100644 --- a/simgear/scene/model/placement.cxx +++ b/simgear/scene/model/placement.cxx @@ -17,7 +17,7 @@ #include #include -#include +#include "location.hxx" #include "placement.hxx" -- 2.39.5