]> git.mxchange.org Git - flightgear.git/blob - src/Model/loader.cxx
Check point commit:
[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/misc/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 &path)
65 {
66                                 // FIXME: normalize path to
67                                 // avoid duplicates.
68     std::map<string, ssgBase *>::iterator it = _table.find(path);
69     if (it == _table.end()) {
70         _table[path] = fgLoad3DModel((char *)path.c_str());
71         it = _table.find(path);
72         it->second->ref();      // add one reference to keep it around
73     }
74     return (ssgEntity *)it->second;
75 }
76
77
78 \f
79 ////////////////////////////////////////////////////////////////////////
80 // Implementation of FGTextureLoader.
81 ////////////////////////////////////////////////////////////////////////
82
83 FGTextureLoader::FGTextureLoader ()
84 {
85 }
86
87 FGTextureLoader::~FGTextureLoader ()
88 {
89 }
90
91 ssgTexture *
92 FGTextureLoader::load_texture (const string &path)
93 {
94     std::map<string, ssgBase *>::iterator it = _table.find(path);
95     if (it == _table.end()) {
96         _table[path] = new ssgTexture((char *)path.c_str()); // FIXME wrapu/v
97         it = _table.find(path);
98         it->second->ref();      // add one reference to keep it around
99     }
100     return (ssgTexture *)it->second;
101 }
102
103
104 // end of loader.cxx