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>
23 class FGNasalModelData;
24 typedef SGSharedPtr<FGNasalModelData> FGNasalModelDataRef;
25 typedef std::list<FGNasalModelData*> FGNasalModelDataList;
27 /** Nasal model data container.
28 * load and unload methods must be run in main thread (not thread-safe). */
29 class FGNasalModelData : public SGReferenced
32 /** Constructor to be run in an arbitrary thread. */
33 FGNasalModelData( SGPropertyNode *root,
34 const std::string& path,
37 SGPropertyNode* unload,
42 /** Load hook. Always call from inside the main loop. */
45 /** Unload hook. Always call from inside the main loop. */
49 * Get osg scenegraph node of model
54 * Get FGNasalModelData for model with the given module id. Every scenery
55 * model containing a nasal load or unload tag gets assigned a module id
59 * @return model data or NULL if does not exists
61 static FGNasalModelData* getByModuleId(unsigned int id);
64 static unsigned int _max_module_id;
65 static FGNasalModelDataList _loaded_models;
67 std::string _module, _path;
68 SGPropertyNode_ptr _root, _prop;
69 SGConstPropertyNode_ptr _load, _unload;
70 osg::ref_ptr<osg::Node> _branch;
71 unsigned int _module_id;
74 /** Thread-safe proxy for FGNasalModelData.
75 * modelLoaded/destroy methods only register the requested
76 * operation. Actual (un)loading of Nasal module is deferred
77 * and done in the main loop. */
78 class FGNasalModelDataProxy : public simgear::SGModelData
81 FGNasalModelDataProxy(SGPropertyNode *root = 0) :
86 ~FGNasalModelDataProxy();
88 void modelLoaded( const std::string& path,
92 virtual FGNasalModelDataProxy* clone() const { return new FGNasalModelDataProxy(_root); }
95 SGPropertyNode_ptr _root;
96 FGNasalModelDataRef _data;
99 #endif // of NASAL_MODEL_DATA_HXX