]> git.mxchange.org Git - flightgear.git/blob - src/Scripting/NasalModelData.hxx
ea472451b9de71bce4691df9666b3affb0426239
[flightgear.git] / src / Scripting / NasalModelData.hxx
1 // Copyright (C) 2013  James Turner
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License as
5 // published by the Free Software Foundation; either version 2 of the
6 // License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16
17 #ifndef NASAL_MODEL_DATA_HXX
18 #define NASAL_MODEL_DATA_HXX
19
20 #include <simgear/nasal/nasal.h>
21 #include <simgear/scene/model/modellib.hxx>
22
23 using std::string;
24
25 /** Nasal model data container.
26  * load and unload methods must be run in main thread (not thread-safe). */
27 class FGNasalModelData : public SGReferenced
28 {
29 public:
30     /** Constructor to be run in an arbitrary thread. */
31     FGNasalModelData(SGPropertyNode *root, const string& path, SGPropertyNode *prop,
32                      SGPropertyNode* load, SGPropertyNode* unload) :
33     _path(path),
34     _root(root), _prop(prop),
35     _load(load), _unload(unload)
36     {
37     }
38     
39     /** Load hook. Always call from inside the main loop. */
40     void load();
41     
42     /** Unload hook. Always call from inside the main loop. */
43     void unload();
44     
45 private:
46     static unsigned int _module_id;
47     
48     string _module, _path;
49     SGPropertyNode_ptr _root, _prop;
50     SGConstPropertyNode_ptr _load, _unload;
51 };
52
53 /** Thread-safe proxy for FGNasalModelData.
54  * modelLoaded/destroy methods only register the requested
55  * operation. Actual (un)loading of Nasal module is deferred
56  * and done in the main loop. */
57 class FGNasalModelDataProxy : public simgear::SGModelData
58 {
59 public:
60     FGNasalModelDataProxy(SGPropertyNode *root = 0) :
61     _root(root), _data(0)
62     {
63     }
64     
65     ~FGNasalModelDataProxy();
66     
67     void modelLoaded(const string& path, SGPropertyNode *prop, osg::Node *);
68     
69 protected:
70     SGPropertyNode_ptr _root;
71     SGSharedPtr<FGNasalModelData> _data;
72 };
73
74 #endif // of NASAL_MODEL_DATA_HXX