Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
quadsquare.h
Go to the documentation of this file.
1 #ifndef QUADSQUARE_H
2 #define QUADSQUARE_H
3 
15 #include "vec.h"
16 #include "gfxlib.h"
17 #include <vector>
18 #include "resizable.h"
19 #include "nonlinear_transform.h"
20 
21 class Texture;
22 
24 {
27  unsigned int material;
28  bool reflect;
29  float scales;
30  float scalet;
31  unsigned char color;
32  union
33  {
34  char *filename;
36  }
37  tex;
39  {
40  scales = scalet = 1;
41  tex.filename = NULL;
42  material = 0;
43  reflect = false;
44  blendSrc = ONE;
45  blendDst = ZERO;
46  }
47 };
48 
49 typedef int (updateparity)( int );
54 
56 {
57  short *Data;
58  unsigned char *terrainmap;
60  unsigned long XSize, ZSize;
61  unsigned int RowWidth;
62  int Scale;
63  float Sample( int x, int z, float &texture ) const;
64 };
65 
72 {
75  void Clear()
76  {
77  q.clear();
78  c.clear();
79  }
80 };
81 
82 struct VertInfo
83 {
84  unsigned short Y;
85  unsigned char Tex;
86  unsigned char Rem;
87  unsigned int vertindex;
88  void SetTex( float );
89  unsigned short GetTex() const;
90 };
91 
92 class quadsquare;
93 
99 {
103  int Level;
104  int xorg, zorg;
105  VertInfo Verts[4]; //ne, nw, sw, se
106 };
107 
114 {
115 public:
117  VertInfo Vertex[5]; //center, e, n, w, s
118  unsigned short Error[6]; //e, s, children: ne, nw, sw, se
119  unsigned short MinY, MaxY; //Bounds for frustum culling and error testing.
120  unsigned char EnabledFlags; //bits 0-7: e, n, w, s, ne, nw, sw, se
121  unsigned char SubEnabledCount[2]; //e, s enabled reference counts.
122  bool Static;
123  bool Dirty; //Set when vertex data has changed, but error/enabled data has not been recalculated.
124  quadsquare( quadcornerdata *pcd );
125  ~quadsquare();
127  void AddHeightMap( const quadcornerdata &cd, const HeightMapInfo &hm );
128  void AddHeightMapAux( const quadcornerdata &cd, const HeightMapInfo &hm );
129  void StaticCullData( const quadcornerdata &cd, float ThresholdDetail );
130  float RecomputeErrorAndLighting( const quadcornerdata &cd );
131  int CountNodes() const;
133  void Update( const quadcornerdata &cd,
134  const Vector &ViewerLocation,
135  float Detail,
136  unsigned short numstages,
137  unsigned short whichstage,
138  updateparity *whichordertoupdate );
139  int Render( const quadcornerdata &cd, const Vector &camera );
140  float GetHeight( const quadcornerdata &cd, float x, float z, Vector &normal ); // const;
141  static Vector MakeLightness( float xslope, float zslope, const Vector &loc );
142  static void SetCurrentTerrain( unsigned int *VertexAllocated,
143  unsigned int *VertexCount,
144  GFXVertexList*vertices,
145  std::vector< unsigned int > *unusedvertices,
146  IdentityTransform*transform,
147  std::vector< TerrainTexture > *texturelist,
148  const Vector &NormalScale,
149  quadsquare*neighbor[4] );
150 private:
151  static void tri( unsigned int Aind,
152  unsigned short Atex,
153  unsigned int Bind,
154  unsigned short Btex,
155  unsigned int Cind,
156  unsigned short Ctex );
158  unsigned int SetVertices( GFXVertex *vertexs, const quadcornerdata &pcd );
159  void EnableEdgeVertex( int index, bool IncrementCount, const quadcornerdata &cd );
160  quadsquare*EnableDescendant( int count, int stack[], const quadcornerdata &cd );
161  void EnableChild( int index, const quadcornerdata &cd );
162  void NotifyChildDisable( const quadcornerdata &cd, int index );
163  void ResetTree();
164  void StaticCullAux( const quadcornerdata &cd, float ThresholdDetail, int TargetLevel );
165  quadsquare * GetNeighbor( int dir, const quadcornerdata &cd ) const;
166  quadsquare * GetFarNeighbor( int dir, const quadcornerdata &cd ) const;
167  void CreateChild( int index, const quadcornerdata &cd );
168  void SetupCornerData( quadcornerdata *q, const quadcornerdata &pd, int ChildIndex );
169  void UpdateAux( const quadcornerdata &cd, const Vector &ViewerLocation, float CenterError, unsigned int pipelinemask );
170  void RenderAux( const quadcornerdata &cd, CLIPSTATE vis );
171  void SetStatic( const quadcornerdata &cd );
172  static IdentityTransform *nonlinear_trans;
173  static unsigned int *VertexAllocated;
174  static unsigned int *VertexCount;
175  static GFXVertexList *vertices;
176  static GFXVertexList *blendVertices;
177  static std::vector< unsigned int > *unusedvertices;
178  static std::vector< TerrainTexture > *textures;
179  static std::vector< TextureIndex > indices;
180  static Vector normalscale;
181  static Vector camerapos;
182  static quadsquare *neighbor[4];
183 };
184 
185 #endif //QUADSQUARE_H
186