]> git.mxchange.org Git - flightgear.git/blob - src/Model/loader.cxx
This is step "1" of probably "many" in the process of separating out the
[flightgear.git] / src / Model / loader.cxx
1 // loader.cxx - implement SSG model and texture loaders.
2
3 #ifdef HAVE_CONFIG_H
4 #  include <config.h>
5 #endif
6
7 #include <simgear/compiler.h>
8 #include <simgear/props/props.hxx>
9
10 #include "loader.hxx"
11 #include "model.hxx"
12
13
14 \f
15 ////////////////////////////////////////////////////////////////////////
16 // Implementation of FGSSGLoader.
17 ////////////////////////////////////////////////////////////////////////
18
19 FGSSGLoader::FGSSGLoader ()
20 {
21     // no op
22 }
23
24 FGSSGLoader::~FGSSGLoader ()
25 {
26     std::map<string, ssgBase *>::iterator it = _table.begin();
27     while (it != _table.end()) {
28         it->second->deRef();
29         _table.erase(it);
30     }
31 }
32
33 void
34 FGSSGLoader::flush ()
35 {
36     std::map<string, ssgBase *>::iterator it = _table.begin();
37     while (it != _table.end()) {
38         ssgBase * item = it->second;
39                                 // If there is only one reference, it's
40                                 // ours; no one else is using the item.
41         if (item->getRef() == 1) {
42             item->deRef();
43             _table.erase(it);
44         }
45         it++;
46     }
47 }
48
49
50 \f
51 ////////////////////////////////////////////////////////////////////////
52 // Implementation of FGModelLoader.
53 ////////////////////////////////////////////////////////////////////////
54
55 FGModelLoader::FGModelLoader ()
56 {
57 }
58
59 FGModelLoader::~FGModelLoader ()
60 {
61 }
62
63 ssgEntity *
64 FGModelLoader::load_model( const string &fg_root,
65                            const string &path,
66                            SGPropertyNode *prop_root,
67                            double sim_time_sec )
68 {
69                                 // FIXME: normalize path to
70                                 // avoid duplicates.
71     std::map<string, ssgBase *>::iterator it = _table.find(path);
72     if (it == _table.end()) {
73         _table[path] = fgLoad3DModel( fg_root, path, prop_root, sim_time_sec );
74         it = _table.find(path);
75         it->second->ref();      // add one reference to keep it around
76     }
77     return (ssgEntity *)it->second;
78 }
79
80
81 \f
82 ////////////////////////////////////////////////////////////////////////
83 // Implementation of FGTextureLoader.
84 ////////////////////////////////////////////////////////////////////////
85
86 FGTextureLoader::FGTextureLoader ()
87 {
88 }
89
90 FGTextureLoader::~FGTextureLoader ()
91 {
92 }
93
94 ssgTexture *
95 FGTextureLoader::load_texture( const string &fg_root, const string &path )
96 {
97     std::map<string, ssgBase *>::iterator it = _table.find(path);
98     if (it == _table.end()) {
99         _table[path] = new ssgTexture((char *)path.c_str()); // FIXME wrapu/v
100         it = _table.find(path);
101         it->second->ref();      // add one reference to keep it around
102     }
103     return (ssgTexture *)it->second;
104 }
105
106
107 // end of loader.cxx