FlightGear next
NasalModelData.hxx
Go to the documentation of this file.
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
24typedef SGSharedPtr<FGNasalModelData> FGNasalModelDataRef;
25typedef std::list<FGNasalModelData*> FGNasalModelDataList;
26
29class FGNasalModelData : public SGReferenced
30{
31public:
33 FGNasalModelData( SGPropertyNode *root,
34 const std::string& path,
35 SGPropertyNode *prop,
36 SGPropertyNode* load,
37 SGPropertyNode* unload,
38 osg::Node* branch );
39
41
43 void load();
44
46 void unload();
47
51 osg::Node* getNode();
52
61 static FGNasalModelData* getByModuleId(unsigned int id);
62
63private:
64 inline static std::mutex _loaded_models_mutex; // mutex protecting the _loaded_models
65 inline static unsigned int _max_module_id = 0;
66 inline static FGNasalModelDataList _loaded_models;
67
68 std::string _module, _path;
69 SGPropertyNode_ptr _root, _prop;
70 SGConstPropertyNode_ptr _load, _unload;
71 osg::ref_ptr<osg::Node> _branch;
72 unsigned int _module_id;
73};
74
79class FGNasalModelDataProxy : public simgear::SGModelData
80{
81public:
82 FGNasalModelDataProxy(SGPropertyNode *root = 0) :
83 _root(root), _data(0)
84 {
85 }
86
88
89 void modelLoaded( const std::string& path,
90 SGPropertyNode *prop,
91 osg::Node *branch );
92
93 virtual FGNasalModelDataProxy* clone() const { return new FGNasalModelDataProxy(_root); }
94
95 ErrorContext getErrorContext() const override
96 {
97 return {}; // return nothing for now, not yet clear if this proxy needs it
98 }
99
100protected:
101 SGPropertyNode_ptr _root;
103};
104
105#endif // of NASAL_MODEL_DATA_HXX
SGSharedPtr< FGNasalModelData > FGNasalModelDataRef
std::list< FGNasalModelData * > FGNasalModelDataList
FGNasalModelDataProxy(SGPropertyNode *root=0)
void modelLoaded(const std::string &path, SGPropertyNode *prop, osg::Node *branch)
SGPropertyNode_ptr _root
FGNasalModelDataRef _data
ErrorContext getErrorContext() const override
virtual FGNasalModelDataProxy * clone() const
Nasal model data container.
static FGNasalModelData * getByModuleId(unsigned int id)
Get FGNasalModelData for model with the given module id.
void unload()
Unload hook.
void load()
Load hook.
FGNasalModelData(SGPropertyNode *root, const std::string &path, SGPropertyNode *prop, SGPropertyNode *load, SGPropertyNode *unload, osg::Node *branch)
Constructor to be run in an arbitrary thread.
osg::Node * getNode()
Get osg scenegraph node of model.