]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/loader.cxx
Cygwin build fixes
[simgear.git] / simgear / scene / model / loader.cxx
1 // loader.cxx - implement SSG model and texture loaders.
2
3 #include <simgear/compiler.h>
4 #include <simgear/props/props.hxx>
5
6 #include "loader.hxx"
7 #include "model.hxx"
8
9
10 \f
11 ////////////////////////////////////////////////////////////////////////
12 // Implementation of FGSSGLoader.
13 ////////////////////////////////////////////////////////////////////////
14
15 FGSSGLoader::FGSSGLoader ()
16 {
17     // no op
18 }
19
20 FGSSGLoader::~FGSSGLoader ()
21 {
22     std::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 FGSSGLoader::flush ()
31 {
32     std::map<string, ssgBase *>::iterator it = _table.begin();
33     while (it != _table.end()) {
34         ssgBase * item = it->second;
35                                 // If there is only one reference, it's
36                                 // ours; no one else is using the item.
37         if (item->getRef() == 1) {
38             item->deRef();
39             _table.erase(it);
40         }
41         it++;
42     }
43 }
44
45
46 \f
47 ////////////////////////////////////////////////////////////////////////
48 // Implementation of FGModelLoader.
49 ////////////////////////////////////////////////////////////////////////
50
51 FGModelLoader::FGModelLoader ()
52 {
53 }
54
55 FGModelLoader::~FGModelLoader ()
56 {
57 }
58
59 ssgEntity *
60 FGModelLoader::load_model( const string &fg_root,
61                            const string &path,
62                            SGPropertyNode *prop_root,
63                            double sim_time_sec )
64 {
65                                 // FIXME: normalize path to
66                                 // avoid duplicates.
67     std::map<string, ssgBase *>::iterator it = _table.find(path);
68     if (it == _table.end()) {
69         _table[path] = fgLoad3DModel( fg_root, path, prop_root, sim_time_sec );
70         it = _table.find(path);
71         it->second->ref();      // add one reference to keep it around
72     }
73     return (ssgEntity *)it->second;
74 }
75
76
77 // end of loader.cxx