]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/gtkgensurf/gensurf.h
Centralise compile checks
[xonotic/netradiant.git] / contrib / gtkgensurf / gensurf.h
1 /*
2    GenSurf plugin for GtkRadiant
3    Copyright (C) 2001 David Hyde, Loki software and qeradiant.com
4
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with this library; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #ifndef _GENSURF_H_
21 #define _GENSURF_H_
22
23 #include "globaldefs.h"
24 #include <string.h>
25 #include "qertypes.h"
26 #include <stdio.h>
27
28 #include "mathlib.h"
29 #include "iscenegraph.h"
30 #define USE_QERTABLE_DEFINE
31 #include "qerplugin.h"
32 extern _QERFuncTable_1 g_FuncTable;
33
34 #include "irender.h"
35 #include "iselection.h"
36
37 #define USE_ENTITYTABLE_DEFINE
38 #include "ientity.h"
39 extern _QEREntityTable __ENTITYTABLENAME;
40
41 #define USE_PATCHTABLE_DEFINE
42 #include "ipatch.h"
43 extern _QERPatchTable __PATCHTABLENAME;
44
45 #define USE_BRUSHTABLE_DEFINE
46 #include "ibrush.h"
47 extern _QERBrushTable __BRUSHTABLENAME;
48
49 #include "igl.h"
50 #include "ientity.h"
51
52 #include "iui_gtk.h"
53
54 #include "gendlgs.h"
55
56
57 #define PLUGIN
58 #define Q3RADIANT
59
60 //#if GDEF_OS_LINUX || GDEF_OS_MACOS
61 #if 1
62 #include <algorithm>
63 #else
64 template <class T>
65 inline T min( T x, T y ) { return ( x < y ) ? x : y; }
66 template <class T>
67 inline T max( T x, T y ) { return ( x > y ) ? x : y; }
68 #endif
69
70 typedef struct { long x, y; } Point;
71 typedef struct { long left, top, right, bottom; } Rect;
72
73 #define NAME_MAX 255
74
75 typedef void* LPVOID;
76 typedef char* LPSTR;
77
78 //#endif
79 inline bool PtInRect( Rect *rc, Point pt ){
80         if ( pt.x < rc->left ) {
81                 return false;
82         }
83         if ( pt.x > rc->right ) {
84                 return false;
85         }
86         if ( pt.y < rc->bottom ) {
87                 return false;
88         }
89         if ( pt.y > rc->top ) {
90                 return false;
91         }
92         return true;
93 }
94
95 #define NUMGAMES 7
96
97 #define CONTENTS_SOLID  0x00000001
98 #define CONTENTS_DETAIL 0x08000000  // brushes to be added after vis leafs
99 #define CONTENTS_LADDER 0x20000000
100 #define SURF_HINT       0x100   // make a primary bsp splitter
101 #define SURF_SKIP       0x200   // completely ignore, allowing non-closed brushes
102 #define HINT_OFFSET 96
103
104 #define PI 3.14159265358979224
105 #define RadiansToDegrees( a ) ( floor( a * 57.2957795 - 0.5 ) + 1. )
106 #define DegreesToRadians( a ) ( a / 57.2957795 )
107
108 #define BOGUS_RANGE 65536
109 /*
110    #define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
111    #define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
112    #define VectorClear(x) {x[0] = x[1] = x[2] = 0;}
113    #define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
114    #define VectorScale(a,b,c) {c[0]=b*a[0];c[1]=b*a[1];c[2]=b*a[2];}
115    #define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
116  */
117 #define XYZVectorSubtract( a,b,c ) {c[0] = (float)a[0] - (float)b[0]; c[1] = (float)a[1] - (float)b[1]; c[2] = (float)a[2] - (float)b[2]; }
118 #define side( u1,v1,u2,v2,u3,v3 ) ( v3 - v1 ) * ( u2 - u1 ) - ( u3 - u1 ) * ( v2 - v1 )
119
120 #define QUAKE2    0
121 #define HALFLIFE  1
122 #define SIN       2
123 #define HERETIC2  3
124 #define KINGPIN   4
125 #define GENESIS3D 5
126 #define QUAKE3    6
127
128 #define MAX_FACES_PER_BRUSH 6
129 #define SLIVER_ANGLE DegreesToRadians( 20 )
130 #define MAX_NODES ( MAX_ROWS + 1 ) * ( MAX_ROWS + 1 )
131 #define MAX_TRIS  (MAX_ROWS)*( MAX_ROWS )
132
133 typedef float vec;
134 typedef vec vec3[3];
135 typedef vec vec2[2];
136
137 typedef struct
138 {
139         vec3 v[3];
140         char texture[64];
141         float Shift[2];
142         float Rotate;
143         float Scale[2];
144         int Contents;
145         int Surface;
146         int Value;
147 } FACE;
148
149 typedef struct
150 {
151         vec3 normal;
152         vec dist;
153 } PLANE;
154
155 typedef struct
156 {
157         int numpoints;
158         vec3 p[4];          // variable sized
159 } MY_WINDING;
160
161 typedef struct
162 {
163         int Number;
164         int NumFaces;
165         FACE face[MAX_FACES_PER_BRUSH];
166 } BRUSH;
167
168 typedef struct tagXYZ
169 {
170         int fixed;
171         int done;
172         double p[3];
173         double pp[3];    // these used only for general 3D projection (not isometric)
174         double fixed_value;
175         double range;
176         double rate;
177 } XYZ;
178
179 // Q2 PAK file structures
180 typedef struct
181 {
182         char id[4]; // Should be 'PACK'
183         int dstart; // Offest in the file to the directory
184         int dsize;  // Size in bytes of the directory, same as num_items*64
185 } pak_header_t;
186
187 typedef struct
188 {
189         char name[56]; // The name of the item, normal C string
190         int start; // Offset in .pak file to start of item
191         int size; // Size of item in bytes
192 } pak_item_t;
193
194 // SiN .SIN structures
195 #define SINPAKHEADER        ( ( 'K' << 24 ) + ( 'A' << 16 ) + ( 'P' << 8 ) + 'S' )
196 #define MAX_PAK_FILENAME_LENGTH 120
197
198 typedef struct
199 {
200         char name[MAX_PAK_FILENAME_LENGTH];
201         int filepos, filelen;
202 } dpackfile_t;
203
204 typedef struct
205 {
206         int ident;          // == IDPAKHEADER
207         int dirofs;
208         int dirlen;
209 } dpackheader_t;
210
211 // Half-Life WAD file structures
212 typedef struct
213 {
214         char identification[4];             // should be WAD2 or 2DAW
215         int numlumps;
216         int infotableofs;
217 } wadinfo_t;
218
219 typedef struct
220 {
221         int filepos;
222         int disksize;
223         int size;                           // uncompressed
224         char type;
225         char compression;
226         char pad1, pad2;
227         char name[16];                      // must be null terminated
228 } lumpinfo_t;
229
230 typedef struct
231 {
232         int signature;
233         short version;
234         short bitflag;
235         short compression_method;
236         short modfiletime;
237         short modfiledate;
238         int crc;
239         int compressed_size;
240         int uncompressed_size;
241         short filename_size;
242         short extra_size;
243 } zipheader_t;
244
245 typedef struct
246 {
247         double x[2];
248         double y[2];
249         double z[2];
250 } bounding_box;
251
252 typedef struct
253 {
254         float p[3];
255         int used;
256         int tri;
257         float error;
258         int fixed;
259 } NODE;
260
261 typedef struct
262 {
263         int v[3];
264         int n[3];      // indices of neighboring triangles
265         PLANE plane;
266         int flag;
267         float min[3];
268         float max[3];
269 } TRI;
270
271 //--------------- bitmap.c -----------------------------
272 bool OpenBitmap();
273 double CalculateSnapValue( double value );
274 void GenerateBitmapMapping();
275 //--------------- face.c -------------------------------
276 void PlaneFromPoints( float *, float *, float *, PLANE * );
277 //void CrossProduct (vec3 v1, vec3 v2, vec3 cross);
278 //vec VectorNormalize (vec3 in, vec3 out);
279 //--------------- gendlg.c -----------------------------
280 GtkWidget* create_main_dialog();
281 void About( GtkWidget *parent );
282 //--------------- genmap.c -----------------------------
283 double AtLeast( double,double );
284 bool CanEdit( int, int );
285 void CloseFuncGroup();
286 bool FixedPoint( int,int );
287 void GenerateMap();
288 void GenerateXYZ();
289 double LessThan( double,double );
290 void MakeBrush( BRUSH * );
291 double MoreThan( double,double );
292 double Nearest( double,double );
293 double NoMoreThan( double,double );
294 void OpenFuncGroup();
295 void PlasmaCloud();
296 int PlayerStartZ( double,double );
297 void SubdividePlasma( int,int,int,int );
298 bool ValidSurface();
299 void XYZtoV( XYZ *, vec3 * );
300 scene::Node* MakePatch( void );
301
302 //---------------- gensurf.c ---------------------------
303 bool GenSurfInit();
304 void ReadIniFile( const char * );
305 void WriteIniFile( const char * );
306 void OpenSetup( GtkWidget*,int );
307 void SaveSetup( GtkWidget* );
308 //---------------- heretic.c ---------------------------
309 int GetDefSurfaceProps( char * );
310 //---------------- view.c ------------------------------
311 void CreateViewWindow();
312 void DrawGrid( Rect );
313 void DrawPreview( Rect );
314 void evaluate();
315 void GetScaleFactor( Rect );
316 void project( XYZ * );
317 void Scale( Rect,XYZ,Point * );
318 void ShowPreview();
319 void UpdatePreview( bool );
320
321 //---------------- plugin.c -----------------------------
322 void UseFaceBounds();
323
324 extern _QERFuncTable_1 g_FuncTable;
325 extern _QERQglTable g_GLTable;
326 extern _QERUIGtkTable g_UIGtkTable;
327 extern _QEREntityTable g_EntityTable;
328 //#define MAX_ROWS 64
329 #define MAX_ROWS 128
330
331 #define PLANE_XY0 0
332 #define PLANE_XY1 1
333 #define PLANE_YZ0 2
334 #define PLANE_XZ0 3
335 #define PLANE_YZ1 4
336 #define PLANE_XZ1 5
337
338 #define WAVE_COS_SIN    0
339 #define WAVE_HCYLINDER  1
340 #define WAVE_VCYLINDER  2
341 #define WAVE_BITMAP     3
342 #define WAVE_ROUGH_ONLY 4
343 #define WAVE_FORMULA    5
344 #define WAVE_FIRST      WAVE_COS_SIN
345 #define WAVE_LAST       WAVE_FORMULA
346 #define DLG_WAVE_LAST   DLG_WAVE_01 + WAVE_LAST - WAVE_FIRST
347
348 #define MSG_VERTEX_SELECTED WM_USER + 1
349
350 typedef struct tagMYBITMAP
351 {
352         char name[NAME_MAX];
353         char defpath[NAME_MAX];
354         double black_value;
355         double white_value;
356         int width, height;
357         unsigned char* colors;
358 } MYBITMAP;
359
360 typedef struct tagELEMENT {
361         int i;
362         int j;
363 } ELEMENT;
364
365 extern char gszAppDir[NAME_MAX];
366 extern char gszCaption[64];
367 extern char gszHelpFile[NAME_MAX];
368 extern char gszIni[NAME_MAX];
369 extern char gszMapFile[NAME_MAX];
370 extern char gszVersion[64];
371 extern double Amplitude;
372 extern double Roughness;
373 extern double TexOffset[2];
374 extern double TexScale[2];
375 extern double WaveLength;
376 extern double Hll, Hur, Vll, Vur;
377 extern double Z00, Z01, Z10, Z11;
378 extern double yaw, pitch, roll;
379 extern ELEMENT Vertex[( MAX_ROWS + 1 ) * ( MAX_ROWS + 1 )];
380 extern int AddHints;
381 extern int ArghRad2;
382 extern int AutoOverwrite;
383 extern int Decimate;
384 extern int FileAppend;
385 extern int FixBorders;
386 extern int HideBackFaces;
387 extern int NH, NV;
388 extern int NumVerticesSelected;
389 extern int Plane;
390 extern int Preview;
391 extern int RandomSeed;
392 extern int Skybox;
393 extern int UseDetail;
394 extern int UseLadder;
395 extern int VertexMode;
396 extern int vid_x, vid_y;
397 extern int WaveType;
398 extern int gNumNodes;
399 extern int gNumTris;
400 extern int view_x, view_y;
401 extern int view_cx, view_cy;
402 extern int UsePatches;
403 extern int SlantAngle;
404 extern int GimpHints;
405 extern int Antialiasing;           // ^Fishman - Antializing for the preview window.
406 extern int AddTerrainKey;           // ^Fishman - Add terrain key to func_group.
407 extern int SnapToGrid;           // Hydra : snap to grid
408 extern int SP;       // ^Fishman - Snap to grid.
409
410
411 /*extern HCURSOR   ghCursorCurrent;
412    extern HCURSOR   ghCursorDefault;
413    extern HCURSOR   ghCursorVertex;
414    extern HINSTANCE ghInst;*/
415 extern GtkWidget *g_pRadiantWnd;
416 extern ui::Window g_pWnd;
417 /*extern HWND      ghwndAngles;
418    extern HWND      ghwndFix;
419  */extern GtkWidget     *g_pWndPreview;
420 extern GtkWidget *g_pPreviewWidget;
421 extern MYBITMAP gbmp;
422 extern NODE      *gNode;
423 extern TRI       *gTri;
424 extern XYZ xyz[MAX_ROWS + 1][MAX_ROWS + 1];
425
426 extern int Game;
427 extern bounding_box PlayerBox[NUMGAMES];
428 //extern char      gszOutputDir[NUMGAMES][NAME_MAX];
429 extern char Texture[NUMGAMES][3][64];
430 //extern char      gszTextureDir[NUMGAMES][NAME_MAX];
431 extern char GameName[NUMGAMES][16];
432 //extern char      pakfile[NUMGAMES][NAME_MAX];
433 //extern char      lastpakfile[NUMGAMES][NAME_MAX];
434 //extern int       UsePak[NUMGAMES];
435 //extern char      GameDir[NUMGAMES][NAME_MAX];
436 //extern char      ExcelFunc[1024];
437
438 #endif // _GENSURF_H_