From: curt Date: Thu, 15 May 2003 21:35:31 +0000 (+0000) Subject: Various code massaging. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=cb7589cc959de769c1560efcdbd1c7211a8eea92;p=simgear.git Various code massaging. --- 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/loader.hxx b/simgear/scene/model/loader.hxx deleted file mode 100644 index cd2da075..00000000 --- a/simgear/scene/model/loader.hxx +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef __MODEL_LOADER_HXX -#define __MODEL_LOADER_HXX 1 - -#ifndef __cplusplus -# error This library requires C++ -#endif - -#include // for SG_USING_STD - -#include -#include STL_STRING - -#include - -#include - -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 -{ -public: - SGModelLoader (); - virtual ~SGModelLoader (); - - virtual ssgEntity *load_model( const string &fg_root, - const string &path, - SGPropertyNode *prop_root, - double sim_time_sec ); -}; - - -#endif 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/modellib.hxx b/simgear/scene/model/modellib.hxx new file mode 100644 index 00000000..deed1e68 --- /dev/null +++ b/simgear/scene/model/modellib.hxx @@ -0,0 +1,45 @@ +// 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++ +#endif + +#include // for SG_USING_STD + +#include +#include STL_STRING + +#include + +#include + +SG_USING_STD(map); +SG_USING_STD(string); + + +/** + * Class for loading and managing models with XML wrappers. + */ +class SGModelLib +{ + +public: + + 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 // _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"