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