]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/modellib.cxx
Move FGEventMgr and FGSubsystemMgr over to SimGear, add SGEventMgr to FlightGear...
[simgear.git] / simgear / scene / model / modellib.cxx
1 // modellib.cxx - implement an SSG model library.
2
3 #include <simgear/compiler.h>
4 #include <simgear/props/props.hxx>
5
6 #include "model.hxx"
7
8 #include "modellib.hxx"
9
10
11 \f
12 ////////////////////////////////////////////////////////////////////////
13 // Implementation of SGModelLib.
14 ////////////////////////////////////////////////////////////////////////
15
16 SGModelLib::SGModelLib ()
17 {
18 }
19
20 SGModelLib::~SGModelLib ()
21 {
22     map<string, ssgBase *>::iterator it = _table.begin();
23     while (it != _table.end()) {
24         it->second->deRef();
25         _table.erase(it);
26     }
27 }
28
29 void
30 SGModelLib::flush1()
31 {
32     // This routine is disabled because I believe I see multiple
33     // problems with it.
34     //
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.
41     //
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.
44
45     SG_LOG( SG_GENERAL, SG_ALERT,
46             "WARNGING: a disabled/broken routine has been called.  This should be fixed!" );
47
48     return;
49
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) {
56             item->deRef();
57             _table.erase(it);
58         }
59         it++;
60     }
61 }
62
63
64 ssgEntity *
65 SGModelLib::load_model( const string &fg_root,
66                            const string &path,
67                            SGPropertyNode *prop_root,
68                            double sim_time_sec )
69 {
70                                 // FIXME: normalize path to
71                                 // avoid duplicates.
72     map<string, ssgBase *>::iterator it = _table.find(path);
73     if (it == _table.end()) {
74         ssgEntity *model = sgLoad3DModel( fg_root, path, prop_root,
75                                           sim_time_sec );
76         model->ref();
77         _table[path] = model;      // add one reference to keep it around
78         return model;
79     } else {
80         return (ssgEntity *)it->second;
81     }
82 }
83
84
85 // end of modellib.cxx