1 // modellib.cxx - implement an SSG model library.
3 #include <simgear/compiler.h>
4 #include <simgear/props/props.hxx>
8 #include "modellib.hxx"
12 ////////////////////////////////////////////////////////////////////////
13 // Implementation of SGModelLib.
14 ////////////////////////////////////////////////////////////////////////
16 SGModelLib::SGModelLib ()
20 SGModelLib::~SGModelLib ()
22 map<string, ssgBase *>::iterator it = _table.begin();
23 while (it != _table.end()) {
32 // This routine is disabled because I believe I see multiple
35 // 1. It blindly deletes all managed models that aren't used
36 // elsewhere. Is this what we really want???? In the one
37 // FlightGear case that calls this method, this clearly is not the
38 // intention. I believe it makes more sense to simply leave items
39 // in the lbrary, even if they are not currently used, they will be
40 // there already when/if we want to use them later.
42 // 2. This routine only does a deRef() on the model. This doesn't actually
43 // delete the ssg tree so there is a memory leak.
45 SG_LOG( SG_GENERAL, SG_ALERT,
46 "WARNGING: a disabled/broken routine has been called. This should be fixed!" );
50 map<string, ssgBase *>::iterator it = _table.begin();
51 while (it != _table.end()) {
52 ssgBase *item = it->second;
53 // If there is only one reference, it's
54 // ours; no one else is using the item.
55 if (item->getRef() == 1) {
65 SGModelLib::load_model( const string &fg_root,
67 SGPropertyNode *prop_root,
70 // FIXME: normalize path to
72 map<string, ssgBase *>::iterator it = _table.find(path);
73 if (it == _table.end()) {
74 ssgEntity *model = sgLoad3DModel( fg_root, path, prop_root,
77 _table[path] = model; // add one reference to keep it around
80 return (ssgEntity *)it->second;
85 // end of modellib.cxx