]> git.mxchange.org Git - flightgear.git/blobdiff - Scenery/tile.hxx
Tweaks for building with native SGI compilers.
[flightgear.git] / Scenery / tile.hxx
index 535b9ff7c53fd06be967d4a643df90a8598650f3..46240a9106232222a017481079d46075c58ada39 100644 (file)
 #include <GL/glut.h>
 #include <XGL/xgl.h>
 
-#ifdef __sun__
-extern "C" void *memmove(void *, const void *, size_t);
-extern "C" void *memset(void *, int, size_t);
-#endif
+#include <Include/compiler.h>
 
-#include <list>         // STL list
-#ifdef NEEDNAMESPACESTD
-using namespace std;
-#endif
+#include <vector>
+#include STL_STRING
 
 #include <Bucket/bucketutils.h>
-#include <Include/fg_types.h>
 #include <Math/mat3.h>
+#include <Math/point3d.hxx>
+#include <Objects/fragment.hxx>
 
+FG_USING_STD(string);
+FG_USING_STD(vector);
 
-// Maximum nodes per tile
-#define MAX_NODES 1000
-
-
-typedef struct {
-    int n1, n2, n3;
-} fgFACE;
-
-
-// Object fragment data class
-class fgFRAGMENT {
-
-public:
-    // culling data for this object fragment (fine grain culling)
-    fgPoint3d center;
-    double bounding_radius;
-
-    // variable offset data for this object fragment for this frame
-    // fgCartesianPoint3d tile_offset;
-
-    // saved transformation matrix for this fragment (used by renderer)
-    // GLfloat matrix[16];
-    
-    // tile_ptr & material_ptr are set so that when we traverse the
-    // list of fragments we can quickly reference back the tile or
-    // material property this fragment is assigned to.
-
-    // material property pointer
-    void *material_ptr;
-
-    // tile pointer
-    void *tile_ptr;
-
-    // OpenGL display list for fragment data
-    GLint display_list;
-
-    // face list (this indexes into the master tile vertex list)
-    list < fgFACE > faces;
-
-    // Constructor
-    fgFRAGMENT ( void );
-
-    // Add a face to the face list
-    void add_face(int n1, int n2, int n3);
-
-    // test if line intesects with this fragment.  p0 and p1 are the
-    // two line end points of the line.  If side_flag is true, check
-    // to see that end points are on opposite sides of face.  Returns
-    // 1 if it does, 0 otherwise.  If it intesects, result is the
-    // point of intersection
-    int intersect( fgPoint3d *end0, fgPoint3d *end1, int side_flag,
-                  fgPoint3d *result);
-
-    // Destructor
-    ~fgFRAGMENT ( void );
-};
-
+#ifdef FG_HAVE_NATIVE_SGI_COMPILERS
+#include <strings.h>
+#endif
 
 // Scenery tile class
 class fgTILE {
 
 public:
 
+    typedef vector < fgFRAGMENT > container;
+    typedef container::iterator FragmentIterator;
+    typedef container::const_iterator FragmentConstIterator;
+
+public:
     // node list (the per fragment face lists reference this node list)
     double (*nodes)[3];
     int ncount;
 
     // culling data for whole tile (course grain culling)
-    fgPoint3d center;
+    Point3D center;
     double bounding_radius;
-    fgPoint3d offset;
+    Point3D offset;
     GLdouble model_view[16];
 
     // this tile's official location in the world
     fgBUCKET tile_bucket;
 
     // the tile cache will mark here if the tile is being used
-    int used;
+    bool used;
+
+    container fragment_list;
+
+public:
 
-    list < fgFRAGMENT > fragment_list;
+    FragmentIterator begin() { return fragment_list.begin(); }
+    FragmentConstIterator begin() const { return fragment_list.begin(); }
+
+    FragmentIterator end() { return fragment_list.end(); }
+    FragmentConstIterator end() const { return fragment_list.end(); }
+
+    void add_fragment( fgFRAGMENT& frag ) {
+       frag.tile_ptr = this;
+       fragment_list.push_back( frag );
+    }
+
+    //
+    size_t num_fragments() const {
+       return fragment_list.size();
+    }
+
+    // Step through the fragment list, deleting the display list, then
+    // the fragment, until the list is empty.
+    void release_fragments();
+
+//     int ObjLoad( const string& path, const fgBUCKET& p );
 
     // Constructor
     fgTILE ( void );
 
     // Destructor
     ~fgTILE ( void );
+
+    // Calculate this tile's offset
+    void SetOffset( const Point3D& off)
+    {
+       offset = center - off;
+    }
+
+
+    // Calculate the model_view transformation matrix for this tile
+    inline void
+    UpdateViewMatrix(GLdouble *MODEL_VIEW)
+    {
+
+#if defined( USE_MEM ) || defined( WIN32 )
+       memcpy( model_view, MODEL_VIEW, 16*sizeof(GLdouble) );
+#else 
+       bcopy( MODEL_VIEW, model_view, 16*sizeof(GLdouble) );
+#endif
+       
+       // This is equivalent to doing a glTranslatef(x, y, z);
+       model_view[12] += (model_view[0]*offset.x() +
+                          model_view[4]*offset.y() +
+                          model_view[8]*offset.z());
+       model_view[13] += (model_view[1]*offset.x() +
+                          model_view[5]*offset.y() +
+                          model_view[9]*offset.z());
+       model_view[14] += (model_view[2]*offset.x() +
+                          model_view[6]*offset.y() +
+                          model_view[10]*offset.z() );
+       // m[15] += (m[3]*x + m[7]*y + m[11]*z);
+       // m[3] m7[] m[11] are 0.0 see LookAt() in views.cxx
+       // so m[15] is unchanged
+    }
+
+private:
+
+    // not defined
+    fgTILE( const fgTILE& );
+    fgTILE& operator = ( const fgTILE& );
 };
 
 
@@ -149,6 +161,101 @@ public:
 
 
 // $Log$
+// Revision 1.25  1999/03/02 01:03:30  curt
+// Tweaks for building with native SGI compilers.
+//
+// Revision 1.24  1999/02/26 22:10:02  curt
+// Added initial support for native SGI compilers.
+//
+// Revision 1.23  1999/02/02 20:13:41  curt
+// MSVC++ portability changes by Bernie Bright:
+//
+// Lib/Serial/serial.[ch]xx: Initial Windows support - incomplete.
+// Simulator/Astro/stars.cxx: typo? included <stdio> instead of <cstdio>
+// Simulator/Cockpit/hud.cxx: Added Standard headers
+// Simulator/Cockpit/panel.cxx: Redefinition of default parameter
+// Simulator/Flight/flight.cxx: Replaced cout with FG_LOG.  Deleted <stdio.h>
+// Simulator/Main/fg_init.cxx:
+// Simulator/Main/GLUTmain.cxx:
+// Simulator/Main/options.hxx: Shuffled <fg_serial.hxx> dependency
+// Simulator/Objects/material.hxx:
+// Simulator/Time/timestamp.hxx: VC++ friend kludge
+// Simulator/Scenery/tile.[ch]xx: Fixed using std::X declarations
+// Simulator/Main/views.hxx: Added a constant
+//
+// Revision 1.22  1998/12/03 01:18:16  curt
+// Converted fgFLIGHT to a class.
+// Tweaks for Sun Portability.
+// Tweaked current terrain elevation code as per NHV.
+//
+// Revision 1.21  1998/11/09 23:40:47  curt
+// Bernie Bright <bbright@c031.aone.net.au> writes:
+// I've made some changes to the Scenery handling.  Basically just tidy ups.
+// The main difference is in tile.[ch]xx where I've changed list<fgFRAGMENT> to
+// vector<fgFRAGMENT>.  Studying our usage patterns this seems reasonable.
+// Lists are good if you need to insert/delete elements randomly but we
+// don't do that.  All access seems to be sequential.  Two additional
+// benefits are smaller memory usage - each list element requires pointers
+// to the next and previous elements, and faster access - vector iterators
+// are smaller and faster than list iterators.  This should also help
+// Charlie Hotchkiss' problem when compiling with Borland and STLport.
+//
+// ./Lib/Bucket/bucketutils.hxx
+//   Convenience functions for fgBUCKET.
+//
+// ./Simulator/Scenery/tile.cxx
+// ./Simulator/Scenery/tile.hxx
+//   Changed fragment list to a vector.
+//   Added some convenience member functions.
+//
+// ./Simulator/Scenery/tilecache.cxx
+// ./Simulator/Scenery/tilecache.hxx
+//   use const fgBUCKET& instead of fgBUCKET* where appropriate.
+//
+// ./Simulator/Scenery/tilemgr.cxx
+// ./Simulator/Scenery/tilemgr.hxx
+//   uses all the new convenience functions.
+//
+// Revision 1.20  1998/10/16 00:55:46  curt
+// Converted to Point3D class.
+//
+// Revision 1.19  1998/09/17 18:36:17  curt
+// Tweaks and optimizations by Norman Vine.
+//
+// Revision 1.18  1998/08/25 16:52:42  curt
+// material.cxx material.hxx obj.cxx obj.hxx texload.c texload.h moved to
+//   ../Objects
+//
+// Revision 1.17  1998/08/22  14:49:58  curt
+// Attempting to iron out seg faults and crashes.
+// Did some shuffling to fix a initialization order problem between view
+// position, scenery elevation.
+//
+// Revision 1.16  1998/08/22 02:01:34  curt
+// increased fragment list size.
+//
+// Revision 1.15  1998/08/20 15:12:06  curt
+// Used a forward declaration of classes fgTILE and fgMATERIAL to eliminate
+// the need for "void" pointers and casts.
+// Quick hack to count the number of scenery polygons that are being drawn.
+//
+// Revision 1.14  1998/08/12 21:13:06  curt
+// material.cxx: don't load textures if they are disabled
+// obj.cxx: optimizations from Norman Vine
+// tile.cxx: minor tweaks
+// tile.hxx: addition of num_faces
+// tilemgr.cxx: minor tweaks
+//
+// Revision 1.13  1998/07/24 21:42:08  curt
+// material.cxx: whups, double method declaration with no definition.
+// obj.cxx: tweaks to avoid errors in SGI's CC.
+// tile.cxx: optimizations by Norman Vine.
+// tilemgr.cxx: optimizations by Norman Vine.
+//
+// Revision 1.12  1998/07/22 21:41:42  curt
+// Add basic fgFACE methods contributed by Charlie Hotchkiss.
+// intersect optimization from Norman Vine.
+//
 // Revision 1.11  1998/07/12 03:18:28  curt
 // Added ground collision detection.  This involved:
 // - saving the entire vertex list for each tile with the tile records.