X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2Fmodelmgr.hxx;h=0b1cf53435248d91511b2181c75682fd5962b229;hb=68c71d5787f2a0309e35c3e05939950113618cb7;hp=84e25839c9d5bc2eb7fb7d8382ced2bcb3df867f;hpb=17cfbd2a7cc386e4910ac4f713fabfc0978c52bc;p=flightgear.git diff --git a/src/Model/modelmgr.hxx b/src/Model/modelmgr.hxx index 84e25839c..0b1cf5343 100644 --- a/src/Model/modelmgr.hxx +++ b/src/Model/modelmgr.hxx @@ -13,51 +13,100 @@ #include #include // for SG_USING_STD +#include -#include
// for FGSubsystem - -SG_USING_STD(vector); +using std::vector; // Don't pull in headers, since we don't need them here. -class ssgSelector; class SGPropertyNode; -class FG3DModel; +class SGModelPlacement; /** * Manage a list of user-specified models. */ -class FGModelMgr : public FGSubsystem +class FGModelMgr : public SGSubsystem { public: + + /** + * A dynamically-placed model using properties. + * + * The model manager uses the property nodes to update the model's + * position and orientation; any of the property node pointers may + * be set to zero to avoid update. Normally, a caller should + * load the model by instantiating SGModelPlacement with the path + * to the model or its XML wrapper, then assign any relevant + * property node pointers. + * + * @see SGModelPlacement + * @see FGModelMgr#add_instance + */ + struct Instance + { + Instance (); + virtual ~Instance (); + SGModelPlacement * model; + SGPropertyNode_ptr node; + SGPropertyNode_ptr lon_deg_node; + SGPropertyNode_ptr lat_deg_node; + SGPropertyNode_ptr elev_ft_node; + SGPropertyNode_ptr roll_deg_node; + SGPropertyNode_ptr pitch_deg_node; + SGPropertyNode_ptr heading_deg_node; + bool shadow; + }; + FGModelMgr (); virtual ~FGModelMgr (); virtual void init (); virtual void bind (); virtual void unbind (); - virtual void update (int dt); + virtual void update (double dt); - virtual void draw (); + virtual void add_model (SGPropertyNode * node); -private: + /** + * Add an instance of a dynamic model to the manager. + * + * NOTE: pointer ownership is transferred to the model manager! + * + * The caller is responsible for setting up the Instance structure + * as required. The model manager will continuously update the + * location and orientation of the model based on the current + * values of the properties. + */ + virtual void add_instance (Instance * instance); - struct Instance + + /** + * Remove an instance of a dynamic model from the manager. + * + * NOTE: the manager will delete the instance as well. + */ + virtual void remove_instance (Instance * instance); + + +private: + /** + * Listener class that adds models at runtime. + */ + class Listener : public SGPropertyChangeListener { - Instance (); - virtual ~Instance (); - FG3DModel * model; - SGPropertyNode * lon_deg_node; - SGPropertyNode * lat_deg_node; - SGPropertyNode * elev_ft_node; - SGPropertyNode * roll_deg_node; - SGPropertyNode * pitch_deg_node; - SGPropertyNode * heading_deg_node; + public: + Listener(FGModelMgr *mgr) : _mgr(mgr) {} + virtual void childAdded (SGPropertyNode * parent, SGPropertyNode * child); + virtual void childRemoved (SGPropertyNode * parent, SGPropertyNode * child); + + private: + FGModelMgr * _mgr; }; - vector _instances; + SGPropertyNode_ptr _models; + Listener * _listener; - ssgSelector * _selector; + vector _instances; };