]> git.mxchange.org Git - flightgear.git/blobdiff - src/Objects/newmat.hxx
Added static port system and a new altimeter model connected to it.
[flightgear.git] / src / Objects / newmat.hxx
index 57a9e9df94a898055d656165de76e9ddf2c8769f..eac328576f7851077926287f830c8cc502b6e682 100644 (file)
@@ -64,6 +64,156 @@ class FGNewMat {
 
 public:
 
+\f
+  //////////////////////////////////////////////////////////////////////
+  // Inner classes.
+  //////////////////////////////////////////////////////////////////////
+
+  class ObjectGroup;
+
+  /**
+   * A randomly-placeable object.
+   *
+   * FGNewMat uses this class to keep track of the model(s) and
+   * parameters for a single instance of a randomly-placeable object.
+   * The object can have more than one variant model (i.e. slightly
+   * different shapes of trees), but they are considered equivalent
+   * and interchangeable.
+   */
+  class Object
+  {
+  public:
+
+    /**
+     * The heading type for a randomly-placed object.
+     */
+    enum HeadingType {
+      HEADING_FIXED,
+      HEADING_BILLBOARD,
+      HEADING_RANDOM
+    };
+
+
+    /**
+     * Get the number of variant models available for the object.
+     *
+     * @return The number of variant models.
+     */
+    int get_model_count () const;
+
+
+    /**
+     * Get a specific variant model for the object.
+     *
+     * @param index The index of the model.
+     * @return The model.
+     */
+    ssgEntity * get_model (int index) const;
+
+
+    /**
+     * Get a randomly-selected variant model for the object.
+     *
+     * @return A randomly select model from the variants.
+     */
+    ssgEntity * get_random_model () const;
+
+
+    /**
+     * Get the average number of meters^2 occupied by each instance.
+     *
+     * @return The coverage in meters^2.
+     */
+    double get_coverage_m2 () const;
+
+
+    /**
+     * Get the heading type for the object.
+     *
+     * @return The heading type.
+     */
+    HeadingType get_heading_type () const;
+
+  protected:
+
+    friend class ObjectGroup;
+
+    Object (const SGPropertyNode * node, double range_m);
+
+    virtual ~Object ();
+
+  private:
+
+    /**
+     * Actually load the models.
+     *
+     * This class uses lazy loading so that models won't be held
+     * in memory for materials that are never referenced.
+     */
+    void load_models () const;
+
+    vector<string> _paths;
+    mutable vector<ssgEntity *> _models;
+    mutable bool _models_loaded;
+    double _coverage_m2;
+    double _range_m;
+    HeadingType _heading_type;
+  };
+
+
+  /**
+   * A collection of related objects with the same visual range.
+   *
+   * Grouping objects with the same range together significantly
+   * reduces the memory requirements of randomly-placed objects.
+   * Each FGNewMat instance keeps a (possibly-empty) list of
+   * object groups for placing randomly on the scenery.
+   */
+  class ObjectGroup
+  {
+  public:
+    virtual ~ObjectGroup ();
+
+
+    /**
+     * Get the visual range of the object in meters.
+     *
+     * @return The visual range.
+     */
+    double get_range_m () const;
+
+
+    /**
+     * Get the number of objects in the group.
+     *
+     * @return The number of objects.
+     */
+    int get_object_count () const;
+
+
+    /**
+     * Get a specific object.
+     *
+     * @param index The object's index, zero-based.
+     * @return The object selected.
+     */
+    Object * get_object (int index) const;
+
+  protected:
+
+    friend class FGNewMat;
+
+    ObjectGroup (SGPropertyNode * node);
+
+  private:
+
+    double _range_m;
+    vector<Object *> _objects;
+
+  };
+
+
+
 \f
   ////////////////////////////////////////////////////////////////////
   // Public Constructors.
@@ -148,30 +298,16 @@ public:
 
 
   /**
-   * Get the number of dynamic objects defined for this material.
+   * Get the number of randomly-placed objects defined for this material.
    */
-  virtual int get_object_count () const { return objects.size(); }
+  virtual int get_object_group_count () const { return object_groups.size(); }
 
 
   /**
-   * Get a dynamic object for this material.
+   * Get a randomly-placed object for this material.
    */
-  virtual ssgEntity * get_object (int i) const { return objects[i].model; }
-
-
-  /**
-   * Get the average space for a dynamic object for this material.
-   */
-  virtual double get_object_coverage (int i) const {
-    return objects[i].coverage;
-  }
-
-
-  /**
-   * Get the group LOD range for a dynamic object for this material.
-   */
-  virtual double get_object_group_lod (int i) const {
-    return objects[i].group_lod;
+  virtual ObjectGroup * get_object_group (int index) const {
+    return object_groups[index];
   }
 
 
@@ -245,18 +381,12 @@ private:
 
   // material properties
   sgVec4 ambient, diffuse, specular, emission;
+  double shininess;
 
   // true if texture loading deferred, and not yet loaded
   bool texture_loaded;
 
-  struct Object
-  {
-    ssgEntity * model;
-    double coverage;
-    double group_lod;
-  };
-
-  vector<Object> objects;
+  vector<ObjectGroup *> object_groups;
 
   // ref count so we can properly delete if we have multiple
   // pointers to this record
@@ -274,6 +404,7 @@ private:
   void build_ssg_state(bool defer_tex_load = false);
   void set_ssg_state( ssgSimpleState *s );
 
+
 };
 
 #endif // _NEWMAT_HXX