Various code massaging.

This commit is contained in:
curt
2003-05-15 21:35:31 +00:00
parent 2ca4b30553
commit cb7589cc95
7 changed files with 104 additions and 104 deletions

View File

@@ -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)

View File

@@ -1,77 +0,0 @@
// loader.cxx - implement SSG model and texture loaders.
#include <simgear/compiler.h>
#include <simgear/props/props.hxx>
#include "loader.hxx"
#include "model.hxx"
////////////////////////////////////////////////////////////////////////
// Implementation of SGssgLoader.
////////////////////////////////////////////////////////////////////////
SGssgLoader::SGssgLoader ()
{
// no op
}
SGssgLoader::~SGssgLoader ()
{
std::map<string, ssgBase *>::iterator it = _table.begin();
while (it != _table.end()) {
it->second->deRef();
_table.erase(it);
}
}
void
SGssgLoader::flush ()
{
std::map<string, ssgBase *>::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<string, ssgBase *>::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

View File

@@ -35,9 +35,6 @@
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/math/vector.hxx>
// #include <Scenery/scenery.hxx>
// #include "globals.hxx"
#include "location.hxx"

View File

@@ -21,7 +21,8 @@
#include <simgear/misc/sg_path.hxx>
#include <simgear/props/props.hxx>
#include <simgear/props/props_io.hxx>
#include <simgear/scene/model/animation.hxx>
#include "animation.hxx"
#include "model.hxx"

View File

@@ -0,0 +1,85 @@
// modellib.cxx - implement an SSG model library.
#include <simgear/compiler.h>
#include <simgear/props/props.hxx>
#include "model.hxx"
#include "modellib.hxx"
////////////////////////////////////////////////////////////////////////
// Implementation of SGModelLib.
////////////////////////////////////////////////////////////////////////
SGModelLib::SGModelLib ()
{
}
SGModelLib::~SGModelLib ()
{
map<string, ssgBase *>::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<string, ssgBase *>::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<string, ssgBase *>::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

View File

@@ -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<string,ssgBase *> _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<string,ssgBase *> _table;
};
#endif
#endif // _SG_MODEL_LIB_HXX

View File

@@ -17,7 +17,7 @@
#include <plib/ssg.h>
#include <plib/ul.h>
#include <simgear/scene/model/location.hxx>
#include "location.hxx"
#include "placement.hxx"