]> git.mxchange.org Git - flightgear.git/blob - src/Model/modelmgr.hxx
Code cleanups, code updates and fix at least on (possible) devide-by-zero
[flightgear.git] / src / Model / modelmgr.hxx
1 // model-mgr.hxx - manage user-specified 3D models.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain, and comes with no warranty.
5
6 #ifndef __MODELMGR_HXX
7 #define __MODELMGR_HXX 1
8
9 #include <vector>
10 #include <memory>
11
12 #include <simgear/compiler.h>   // for SG_USING_STD
13 #include <simgear/structure/subsystem_mgr.hxx>
14
15 // Don't pull in headers, since we don't need them here.
16 class SGPropertyNode;
17 class SGModelPlacement;
18
19
20 /**
21  * Manage a list of user-specified models.
22  */
23 class FGModelMgr : public SGSubsystem
24 {
25 public:
26
27   /**
28    * A dynamically-placed model using properties.
29    *
30    * The model manager uses the property nodes to update the model's
31    * position and orientation; any of the property node pointers may
32    * be set to zero to avoid update.  Normally, a caller should
33    * load the model by instantiating SGModelPlacement with the path
34    * to the model or its XML wrapper, then assign any relevant
35    * property node pointers.
36    *
37    * @see SGModelPlacement
38    * @see FGModelMgr#add_instance
39    */
40   struct Instance
41   {
42     Instance ();
43     virtual ~Instance ();
44     SGModelPlacement * model;
45     SGPropertyNode_ptr node;
46     SGPropertyNode_ptr lon_deg_node;
47     SGPropertyNode_ptr lat_deg_node;
48     SGPropertyNode_ptr elev_ft_node;
49     SGPropertyNode_ptr roll_deg_node;
50     SGPropertyNode_ptr pitch_deg_node;
51     SGPropertyNode_ptr heading_deg_node;
52     bool shadow;
53   };
54
55   FGModelMgr ();
56   virtual ~FGModelMgr ();
57
58   virtual void init ();
59   virtual void shutdown ();
60
61   virtual void bind ();
62   virtual void unbind ();
63   virtual void update (double dt);
64
65   virtual void add_model (SGPropertyNode * node);
66
67   /**
68    * Add an instance of a dynamic model to the manager.
69    *
70    * NOTE: pointer ownership is transferred to the model manager!
71    *
72    * The caller is responsible for setting up the Instance structure
73    * as required.  The model manager will continuously update the
74    * location and orientation of the model based on the current
75    * values of the properties.
76    */
77   virtual void add_instance (Instance * instance);
78
79
80   /**
81    * Remove an instance of a dynamic model from the manager.
82    *
83    * NOTE: the manager will delete the instance as well.
84    */
85   virtual void remove_instance (Instance * instance);
86
87     static const char* subsystemName() { return "model-manager"; }
88 private:
89   /**
90    * Listener class that adds models at runtime.
91    */
92   class Listener : public SGPropertyChangeListener
93   {
94   public:
95     Listener(FGModelMgr *mgr) : _mgr(mgr) {}
96     virtual void childAdded (SGPropertyNode * parent, SGPropertyNode * child);
97     virtual void childRemoved (SGPropertyNode * parent, SGPropertyNode * child);
98
99   private:
100     FGModelMgr * _mgr;
101   };
102
103   SGPropertyNode_ptr _models;
104   std::auto_ptr<Listener> _listener;
105
106     std::vector<Instance *> _instances;
107
108 };
109
110 #endif // __MODELMGR_HXX