2 GenSurf plugin for GtkRadiant
3 Copyright (C) 2001 David Hyde, Loki software and qeradiant.com
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.
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.
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
30 char gszAppDir[NAME_MAX];
32 char gszIni[NAME_MAX];
33 char gszHelpFile[NAME_MAX];
34 char gszMapFile[NAME_MAX];
41 double Hll, Hur, Vll, Vur;
42 double Z00, Z01, Z10, Z11;
43 ELEMENT Vertex[(MAX_ROWS+1)*(MAX_ROWS+1)];
48 int SnapToGrid=0; // 0, or the grid size to snap to. // Hydra : snap to grid
53 int NumVerticesSelected;
70 int Antialiasing; // ^Fishman - Antializing for the preview window.
71 int AddTerrainKey; // ^Fishman - Add terrain key to func_group.
72 int SP; // ^Fishman - Snap to grid.
74 GtkWidget *g_pWnd; // ghwnd;
75 GtkWidget *g_pRadiantWnd; // ghwnd_main;
77 */GtkWidget *g_pWndPreview;
78 GtkWidget *g_pPreviewWidget;
80 NODE *gNode=(NODE *)NULL;
81 TRI *gTri=(TRI *)NULL;
84 bounding_box PlayerBox[NUMGAMES] = { {{-16., 16.}, {-16., 16.}, {-24., 32.}}, // Quake2
85 {{-16., 16.}, {-16., 16.}, {-36., 36.}}, // Half-Life
86 {{-16., 16.}, {-16., 16.}, {-32., 32.}}, // SiN
87 {{-16., 16.}, {-16., 16.}, {-24., 32.}}, // Heretic2 (guess)
88 {{-16., 16.}, {-16., 16.}, {-24., 32.}}, // KingPin (guess)
89 {{-30., 30.}, {-30., 30.}, {-10.,160.}}, // Genesis3D (no idea)
90 {{-16., 16.}, {-16., 16.}, {-24., 32.}}}; // Quake3 (not sure)
91 //char gszOutputDir[NUMGAMES][NAME_MAX];
92 //char gszTextureDir[NUMGAMES][NAME_MAX];
93 char Texture[NUMGAMES][3][64];
94 //char pakfile[NUMGAMES][NAME_MAX];
95 //char lastpakfile[NUMGAMES][NAME_MAX];
96 //int UsePak[NUMGAMES];
97 //char GameDir[NUMGAMES][NAME_MAX];
99 char GameName[NUMGAMES][16] = {"Quake2", "Half-Life", "SiN", "Heretic2", "Kingpin", "Genesis3D", "Quake3" };
104 strcpy (gszVersion, "1.05");
105 strcpy (gszCaption, "GtkGenSurf");
106 if (strlen (gszVersion))
108 strcat (gszCaption, " v");
109 strcat (gszCaption, gszVersion);
112 strcpy (gszIni, g_FuncTable.m_pfnProfileGetDirectory ());
113 strcat (gszIni, "gensurf.ini");
115 /*if (g_FuncTable.m_pfnReadProjectKey != NULL)
119 basepath = g_FuncTable.m_pfnReadProjectKey("basepath");
122 g_strdown (basepath);
123 if (strstr(basepath,"baseq3"))
125 else if (strstr (basepath,"baseq2"))
127 else // Gotta have a game, might as well be Quake3
138 g_pWnd = create_main_dialog ();
140 ReadIniFile (gszIni);
145 // Reads default values
147 #define OPTS_SECTION "Options"
149 void ReadIniFile (const char *file)
155 Text = g_FuncTable.m_pfnProfileLoadString (file, OPTS_SECTION, "Amplitude", "");
157 Amplitude = atof (Text);
161 Text = g_FuncTable.m_pfnProfileLoadString (file, OPTS_SECTION, "Roughness", "");
163 Roughness = atof (Text);
167 Text = g_FuncTable.m_pfnProfileLoadString (file, OPTS_SECTION, "WaveLength", "");
169 WaveLength = atof (Text);
173 Text = g_FuncTable.m_pfnProfileLoadString (file, OPTS_SECTION, "Extents", "");
176 sscanf(Text,"%f,%f,%f,%f",&x1,&x2,&x3,&x4);
190 Text = g_FuncTable.m_pfnProfileLoadString (file, OPTS_SECTION, "CornerValues", "");
193 sscanf(Text,"%f,%f,%f,%f",&x1,&x2,&x3,&x4);
207 Text = g_FuncTable.m_pfnProfileLoadString (file, OPTS_SECTION, "TextureOffset", "");
210 sscanf(Text,"%f,%f",&x1,&x2);
220 Text = g_FuncTable.m_pfnProfileLoadString (file, OPTS_SECTION,"TextureScale","");
223 sscanf(Text,"%f,%f",&x1,&x2);
226 if(TexScale[0] == 0.) TexScale[0] = 1.0;
227 if(TexScale[1] == 0.) TexScale[1] = 1.0;
235 NH = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"NH",8);
236 NH = max(1,min(NH,MAX_ROWS));
237 NV = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"NV",8);
238 NV = max(1,min(NV,MAX_ROWS));
240 // Decimate = GetPrivateProfileInt(OPTS_SECTION,"Decimate",0,file);
241 // Decimate = max(0,min(Decimate,100));
243 AddHints = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"AddHints",0);
244 ArghRad2 = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"ArghRad2",0);
245 AutoOverwrite = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"AutoOverwrite",0);
246 FixBorders = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"FixBorders",1);
247 HideBackFaces = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"HideBackFaces",0);
248 Plane = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"Plane",0);
249 Preview = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"Preview", 0);
250 Antialiasing = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"Antialiasing",0); // ^Fishman - Antializing for the preview window.
251 RandomSeed = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"RandomSeed",1);
252 Skybox = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"Skybox",0);
253 UseDetail = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"UseDetail",0);
254 AddTerrainKey = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"AddTerrainKey",0); // ^Fishman - Add terrain key to func_group.
255 UseLadder = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"UseLadder",0);
256 WaveType = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"WaveType",0);
257 vid_x = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"vid_x", 0);
258 vid_y = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"vid_y", 0);
259 view_x = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"view_x",0);
260 view_y = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"view_y",0);
261 view_cx = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"view_cx",0);
262 view_cy = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"view_cy",0);
264 UsePatches = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"UsePatches",0);
266 SlantAngle = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"SlantAngle",60);
267 GimpHints = g_FuncTable.m_pfnProfileLoadInt (file, OPTS_SECTION,"GimpHints",0);
269 for(i=0; i<NUMGAMES; i++)
271 // strcpy (gszOutputDir[i], g_FuncTable.m_pfnProfileLoadString (file, GameName[i],"OutputDir",""));
272 strcpy (Texture[i][0], g_FuncTable.m_pfnProfileLoadString (file, GameName[i], "Texture", ""));
273 strcpy (Texture[i][1], g_FuncTable.m_pfnProfileLoadString (file, GameName[i], "Texture2", ""));
274 strcpy (Texture[i][2], g_FuncTable.m_pfnProfileLoadString (file, GameName[i], "Texture3", ""));
275 // strcpy (gszTextureDir[i], g_FuncTable.m_pfnProfileLoadString (file, GameName[i],"TextureDir",""));
276 // UsePak[i] = GetPrivateProfileInt(GameName[i],"UsePak",0);
277 // strcpy (pakfile[i], g_FuncTable.m_pfnProfileLoadString (file, GameName[i],"PakFile",""));
278 // strcpy (lastpakfile[i], g_FuncTable.m_pfnProfileLoadString (file, GameName[i],"LastPakFile",""));
279 // strcpy (GameDir[i], g_FuncTable.m_pfnProfileLoadString (file, GameName[i],"GameDir","\0"));
282 if(!strlen(gszTextureDir[QUAKE2]))
283 strcpy(gszTextureDir[QUAKE2],"c:\\quake2\\baseq2\\textures\\");
284 if(!strlen(gszTextureDir[KINGPIN]))
285 strcpy(gszTextureDir[KINGPIN],"c:\\kingpin\\main\\textures\\");
287 if(!strlen(Texture[QUAKE2][0])) strcpy(Texture[QUAKE2][0], "textures/e1u1/grass1_4");
288 if(!strlen(Texture[HALFLIFE][0])) strcpy(Texture[HALFLIFE][0], "textures/OUT_GRND1");
289 if(!strlen(Texture[SIN][0])) strcpy(Texture[SIN][0], "textures/generic/floor_organic/fl_grass");
290 if(!strlen(Texture[HERETIC2][0])) strcpy(Texture[HERETIC2][0], "textures/canyon/canyon05");
291 if(!strlen(Texture[KINGPIN][0])) strcpy(Texture[KINGPIN][0], "textures/bricks/s_sr_m3");
292 if(!strlen(Texture[GENESIS3D][0])) strcpy(Texture[GENESIS3D][0],"textures/rock13");
293 if(!strlen(Texture[QUAKE3][0])) strcpy(Texture[QUAKE3][0], "textures/organics/grass3");
294 if(!strlen(Texture[QUAKE3][1])) strcpy(Texture[QUAKE3][1], "textures/common/caulk");
295 strcpy (gbmp.name, g_FuncTable.m_pfnProfileLoadString (file, "Bitmap","Filename",""));
299 if (strlen(gbmp.name))
302 strcpy (gbmp.defpath, g_FuncTable.m_pfnProfileLoadString (file, "Bitmap","DefaultPath",""));
304 Text = g_FuncTable.m_pfnProfileLoadString (file, "Bitmap","BlackValue","");
306 gbmp.black_value = atof (Text);
308 gbmp.black_value = 0;
310 Text = g_FuncTable.m_pfnProfileLoadString (file, "Bitmap","WhiteValue","");
312 gbmp.white_value = atof (Text);
314 gbmp.white_value = 256.;
321 does a varargs printf into a temp buffer, so I don't need to have
322 varargs versions of all text functions.
323 FIXME: make this buffer size safe someday
326 char *va (const char *format, ...)
329 static char string[1024];
331 va_start (argptr, format);
332 vsprintf (string, format,argptr);
339 // Writes current values to INI file
340 void WriteIniFile(const char *file)
344 g_FuncTable.m_pfnProfileSaveString (file, OPTS_SECTION, "Amplitude", va("%g",Amplitude));
345 g_FuncTable.m_pfnProfileSaveString (file, OPTS_SECTION, "Roughness", va("%g",Roughness));
346 g_FuncTable.m_pfnProfileSaveString (file, OPTS_SECTION, "WaveLength", va("%g",WaveLength));
347 g_FuncTable.m_pfnProfileSaveString (file, OPTS_SECTION, "Extents", va("%g,%g,%g,%g",Hll,Vll,Hur,Vur));
348 g_FuncTable.m_pfnProfileSaveString (file, OPTS_SECTION, "CornerValues", va("%g,%g,%g,%g",Z00,Z01,Z10,Z11));
349 g_FuncTable.m_pfnProfileSaveString (file, OPTS_SECTION, "TextureOffset",va("%g,%g",TexOffset[0],TexOffset[1]));
350 g_FuncTable.m_pfnProfileSaveString (file, OPTS_SECTION, "TextureScale", va("%g,%g",TexScale[0],TexScale[1]));
351 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "NH", NH);
352 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "NV", NV);
353 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "AddHints", AddHints);
354 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "ArghRad2", ArghRad2);
355 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "AutoOverwrite", AutoOverwrite);
356 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "FixBorders", FixBorders);
357 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "Plane", Plane);
358 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "Preview", Preview);
359 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "Antialiasing", Antialiasing); // ^Fishman - Antializing for the preview window.
360 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "RandomSeed", RandomSeed);
361 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "Skybox", Skybox);
362 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "UseDetail", UseDetail);
363 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "AddTerrainKey", AddTerrainKey); // ^Fishman - Add terrain key to func_group.
364 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "UseLadder", UseLadder);
365 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "WaveType", WaveType);
366 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "vid_x", vid_x);
367 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "vid_y", vid_y);
368 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "view_x", view_x);
369 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "view_y", view_y);
370 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "view_cx", view_cx);
371 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "view_cy", view_cy);
372 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "UsePatches", UsePatches);
373 g_FuncTable.m_pfnProfileSaveInt (file, OPTS_SECTION, "SlantAngle", SlantAngle);
374 for(i=0; i<NUMGAMES; i++)
376 g_FuncTable.m_pfnProfileSaveString (file, GameName[i], "Texture", Texture[i][0] );
377 g_FuncTable.m_pfnProfileSaveString (file, GameName[i], "Texture2", Texture[i][1] );
378 g_FuncTable.m_pfnProfileSaveString (file, GameName[i], "Texture3", Texture[i][2] );
381 g_FuncTable.m_pfnProfileSaveString (file, "Bitmap", "Filename", gbmp.name );
382 g_FuncTable.m_pfnProfileSaveString (file, "Bitmap", "DefaultPath", gbmp.defpath );
383 g_FuncTable.m_pfnProfileSaveString (file, "Bitmap", "BlackValue", va("%g",gbmp.black_value));
384 g_FuncTable.m_pfnProfileSaveString (file, "Bitmap", "WhiteValue", va("%g",gbmp.white_value));
385 //g_FuncTable.m_pfnProfileSaveString (file, "Formula", "Formula", ExcelFunc );
388 void UpdatePreview (bool DataChange)
390 if (g_pWndPreview && GTK_WIDGET_VISIBLE (g_pWndPreview))
395 gtk_widget_draw (g_pPreviewWidget, NULL);
399 void SaveSetup (GtkWidget *parent)
401 const char *name = g_FuncTable.m_pfnFileDialog (parent, false, "Save GenSurf Settings",
402 g_FuncTable.m_pfnProfileGetDirectory ());
406 char key[32], text[32];
410 g_FuncTable.m_pfnProfileSaveString (name, OPTS_SECTION,"MapFile",gszMapFile);
411 sprintf(text,"0x%04x",FileAppend);
412 g_FuncTable.m_pfnProfileSaveString (name, OPTS_SECTION,"Append",text);
413 sprintf(text,"0x%04x",Decimate);
414 g_FuncTable.m_pfnProfileSaveString (name, OPTS_SECTION,"Decimate",text);
421 sprintf(key,"I%dJ%d",i,j);
422 sprintf(text,"%g %g %g", xyz[i][j].fixed_value, xyz[i][j].range, xyz[i][j].rate);
423 g_FuncTable.m_pfnProfileSaveString (name, "FixedPoints",key,text);
430 void OpenSetup (GtkWidget *parent, int UseDefaults)
434 float value,range,rate;
438 name = g_strdup ("plugins/defaults.srf"); // dummy string
440 name = g_FuncTable.m_pfnFileDialog (parent, true, "Open GenSurf Settings",
441 g_FuncTable.m_pfnProfileGetDirectory ());
446 Decimate = g_FuncTable.m_pfnProfileLoadInt (name, OPTS_SECTION,"Decimate",0);
447 Decimate = max(0,min(Decimate,100));
449 for (i=0; i<=NH; i++)
451 for (j=0; j<=NV; j++)
453 sprintf(key,"I%dJ%d",i,j);
454 text = g_FuncTable.m_pfnProfileLoadString (name, "FixedPoints", key, "");
459 sscanf(text,"%g %g %g",&value,&range,&rate);
460 xyz[i][j].fixed_value = value;
461 xyz[i][j].range = range;
462 xyz[i][j].rate = rate;