1 // Copyright (C) 2013 James Turner
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.
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.
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.
17 #ifndef NASAL_MODEL_DATA_HXX
18 #define NASAL_MODEL_DATA_HXX
20 #include <simgear/nasal/nasal.h>
21 #include <simgear/scene/model/modellib.hxx>
25 /** Nasal model data container.
26 * load and unload methods must be run in main thread (not thread-safe). */
27 class FGNasalModelData : public SGReferenced
30 /** Constructor to be run in an arbitrary thread. */
31 FGNasalModelData(SGPropertyNode *root, const string& path, SGPropertyNode *prop,
32 SGPropertyNode* load, SGPropertyNode* unload) :
34 _root(root), _prop(prop),
35 _load(load), _unload(unload)
39 /** Load hook. Always call from inside the main loop. */
42 /** Unload hook. Always call from inside the main loop. */
46 static unsigned int _module_id;
48 string _module, _path;
49 SGPropertyNode_ptr _root, _prop;
50 SGConstPropertyNode_ptr _load, _unload;
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
60 FGNasalModelDataProxy(SGPropertyNode *root = 0) :
65 ~FGNasalModelDataProxy();
67 void modelLoaded(const string& path, SGPropertyNode *prop, osg::Node *);
70 SGPropertyNode_ptr _root;
71 SGSharedPtr<FGNasalModelData> _data;
74 #endif // of NASAL_MODEL_DATA_HXX