-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqe3.c
485 lines (410 loc) · 11.3 KB
/
qe3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
#include "qe3.h"
QEGlobals_t g_qeglobals;
void QE_CheckOpenGLForErrors(void)
{
int i;
while ( ( i = glGetError() ) != GL_NO_ERROR )
{
char buffer[100];
sprintf( buffer, "OpenGL Error: %s", gluErrorString( i ) );
MessageBox( g_qeglobals.d_hwndMain, buffer , "QuakeEd Error", MB_OK | MB_ICONEXCLAMATION );
exit( 1 );
}
}
char *ExpandReletivePath (char *p)
{
static char temp[1024];
char *base;
if (!p || !p[0])
return NULL;
if (p[0] == '/' || p[0] == '\\')
return p;
base = ValueForKey(g_qeglobals.d_project_entity, "basepath");
sprintf (temp, "%s/%s", base, p);
return temp;
}
void *qmalloc (int size)
{
void *b;
b = malloc(size);
memset (b, 0, size);
return b;
}
char *copystring (char *s)
{
char *b;
b = malloc(strlen(s)+1);
strcpy (b,s);
return b;
}
/*
===============
QE_CheckAutoSave
If five minutes have passed since making a change
and the map hasn't been saved, save it out.
===============
*/
void QE_CheckAutoSave( void )
{
static clock_t s_start;
clock_t now;
now = clock();
if ( modified != 1 || !s_start)
{
s_start = now;
return;
}
if ( now - s_start > ( CLOCKS_PER_SEC * 60 * QE_AUTOSAVE_INTERVAL ) )
{
Sys_Printf ("Autosaving...\n");
Sys_Status ("Autosaving...", 0);
Map_SaveFile (ValueForKey(g_qeglobals.d_project_entity, "autosave"), false);
Sys_Printf ("Autosaving successfull.\n");
Sys_Status ("Autosaving successfull.", 0);
modified = 2;
s_start = now;
}
}
/*
===========
QE_LoadProject
===========
*/
qboolean QE_LoadProject (char *projectfile)
{
char *data;
Sys_Printf ("QE_LoadProject (%s)\n", projectfile);
if ( LoadFileNoCrash (projectfile, (void *)&data) == -1)
return false;
StartTokenParsing (data);
g_qeglobals.d_project_entity = Entity_Parse (true);
if (!g_qeglobals.d_project_entity)
Error ("Couldn't parse %s", projectfile);
free (data);
// usefull for the log file and debuggin fucked up configurations from users:
// output the basic information of the .qe3 project file
Sys_Printf("basepath: %s\n", ValueForKey( g_qeglobals.d_project_entity, "basepath") );
Sys_Printf("mapspath: %s\n", ValueForKey( g_qeglobals.d_project_entity, "mapspath") );
Sys_Printf("rshcmd: %s\n", ValueForKey( g_qeglobals.d_project_entity, "rshcmd" ) );
Sys_Printf("remotebasepath: %s\n", ValueForKey( g_qeglobals.d_project_entity, "remotebasepath" ) );
Sys_Printf("entitypath: %s\n", ValueForKey( g_qeglobals.d_project_entity, "entitypath" ) );
Sys_Printf("texturepath: %s\n", ValueForKey( g_qeglobals.d_project_entity, "texturepath" ) );
Eclass_InitForSourceDirectory (ValueForKey (g_qeglobals.d_project_entity, "entitypath"));
FillClassList (); // list in entity window
FillTextureMenu ();
FillBSPMenu ();
Map_New ();
return true;
}
/*
===========
QE_KeyDown
===========
*/
#define SPEED_MOVE 32
#define SPEED_TURN 22.5
qboolean QE_KeyDown (int key)
{
switch (key)
{
case 'K':
PostMessage( g_qeglobals.d_hwndMain, WM_COMMAND, ID_MISC_SELECTENTITYCOLOR, 0 );
break;
case VK_TAB:
PostMessage( g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_NEXTVIEW, 0 );
break;
case VK_UP:
VectorMA (g_qeglobals.d_camera.origin, SPEED_MOVE, g_qeglobals.d_camera.forward, g_qeglobals.d_camera.origin);
Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
break;
case VK_DOWN:
VectorMA (g_qeglobals.d_camera.origin, -SPEED_MOVE, g_qeglobals.d_camera.forward, g_qeglobals.d_camera.origin);
Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
break;
case VK_LEFT:
g_qeglobals.d_camera.angles[1] += SPEED_TURN;
Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
break;
case VK_RIGHT:
g_qeglobals.d_camera.angles[1] -= SPEED_TURN;
Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
break;
case 'D':
g_qeglobals.d_camera.origin[2] += SPEED_MOVE;
Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY|W_Z_OVERLAY);
break;
case 'C':
g_qeglobals.d_camera.origin[2] -= SPEED_MOVE;
Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY|W_Z_OVERLAY);
break;
case 'A':
g_qeglobals.d_camera.angles[0] += SPEED_TURN;
if (g_qeglobals.d_camera.angles[0] > 85)
g_qeglobals.d_camera.angles[0] = 85;
Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
break;
case 'Z':
g_qeglobals.d_camera.angles[0] -= SPEED_TURN;
if (g_qeglobals.d_camera.angles[0] < -85)
g_qeglobals.d_camera.angles[0] = -85;
Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
break;
case VK_COMMA:
VectorMA (g_qeglobals.d_camera.origin, -SPEED_MOVE, g_qeglobals.d_camera.right, g_qeglobals.d_camera.origin);
Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
break;
case VK_PERIOD:
VectorMA (g_qeglobals.d_camera.origin, SPEED_MOVE, g_qeglobals.d_camera.right, g_qeglobals.d_camera.origin);
Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
break;
case '0':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_SHOWGRID, 0);
break;
case '1':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_GRID_1, 0);
break;
case '2':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_GRID_2, 0);
break;
case '3':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_GRID_4, 0);
break;
case '4':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_GRID_8, 0);
break;
case '5':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_GRID_16, 0);
break;
case '6':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_GRID_32, 0);
break;
case '7':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_GRID_64, 0);
break;
case '8':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_GRID_128, 0);
break;
case '9':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_GRID_256, 0);
break;
case 'E':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_SELECTION_DRAGEDGES, 0);
break;
case 'V':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_SELECTION_DRAGVERTECIES, 0);
break;
case 'X':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_CLIPPER, 0);
break;
case 'Q':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_SELECT_GROUPNEXTBRUSH, 0);
break;
case 'N':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_ENTITY, 0);
break;
case 'O':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_CONSOLE, 0);
break;
case 'T':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_TEXTURE, 0);
break;
case 'S':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_TEXTURES_INSPECTOR, 0);
break;
case ' ':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_SELECTION_CLONE, 0);
break;
case 'I':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_SELECTION_INVERT, 0);
break;
case VK_BACK:
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_SELECTION_DELETE, 0);
break;
case VK_ESCAPE:
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_SELECTION_DESELECT, 0);
break;
case VK_RETURN:
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_CLIP_SELECTED, 0);
break;
case 'H':
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_HIDESHOW_HIDESELECTED, 0);
break;
case VK_END:
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_CENTER, 0);
break;
case VK_DELETE:
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_ZOOMIN, 0);
break;
case VK_INSERT:
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_ZOOMOUT, 0);
break;
case VK_NEXT:
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_DOWNFLOOR, 0);
break;
case VK_PRIOR:
PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_UPFLOOR, 0);
break;
default:
return false;
}
return true;
}
/*
===============
ConnectEntities
Sets target / targetname on the two entities selected
from the first selected to the secon
===============
*/
void ConnectEntities (void)
{
entity_t *e1, *e2, *e;
char *target, *tn;
int maxtarg, targetnum;
char newtarg[32];
if (g_qeglobals.d_select_count != 2)
{
Sys_Printf ("Must have two brushes selected.\n");
Sys_Beep ();
return;
}
e1 = g_qeglobals.d_select_order[0]->owner;
e2 = g_qeglobals.d_select_order[1]->owner;
if (e1 == world_entity || e2 == world_entity)
{
Sys_Printf ("Can't connect to the world.\n");
Sys_Beep ();
return;
}
if (e1 == e2)
{
Sys_Printf ("Brushes are from same entity.\n");
Sys_Beep ();
return;
}
target = ValueForKey (e1, "target");
if (target && target[0])
strcpy (newtarg, target);
else
{
target = ValueForKey (e2, "targetname");
if (target && target[0])
strcpy (newtarg, target);
else
{
// make a unique target value
maxtarg = 0;
for (e=entities.next ; e != &entities ; e=e->next)
{
tn = ValueForKey (e, "targetname");
if (tn && tn[0])
{
targetnum = atoi(tn+1);
if (targetnum > maxtarg)
maxtarg = targetnum;
}
}
sprintf (newtarg, "t%i", maxtarg+1);
}
}
SetKeyValue (e1, "target", newtarg);
SetKeyValue (e2, "targetname", newtarg);
Sys_UpdateWindows (W_XY | W_CAMERA);
Select_Deselect(true);
Select_Brush (g_qeglobals.d_select_order[1], true);
}
qboolean QE_SingleBrush (void)
{
if ( (selected_brushes.next == &selected_brushes)
|| (selected_brushes.next->next != &selected_brushes) )
{
Sys_Printf ("Must have a single brush selected\n");
return false;
}
if (selected_brushes.next->owner->eclass->fixedsize)
{
Sys_Printf ("Cannot manipulate fixed size entities\n");
return false;
}
return true;
}
void QE_Init (void)
{
/*
** initialize variables
*/
g_qeglobals.d_gridsize = 8;
g_qeglobals.d_showgrid = true;
g_qeglobals.d_viewtype = XY;
g_qeglobals.d_camera.viewdistance = 256;
Sys_UpdateGridStatusBar ();
/*
** other stuff
*/
Texture_Init ();
Cam_Init ();
XY_Init ();
Z_Init ();
}
void QE_ConvertDOSToUnixName( char *dst, const char *src )
{
while ( *src )
{
if ( *src == '\\' )
*dst = '/';
else
*dst = *src;
dst++; src++;
}
*dst = 0;
}
int g_numbrushes, g_numentities, g_numtextures;
void QE_CountBrushesAndUpdateStatusBar( void )
{
static int s_lastbrushcount, s_lastentitycount, s_lasttexturecount;
static qboolean s_didonce;
// entity_t *e;
brush_t *b, *next;
qtexture_t *q;
g_numbrushes = 0;
g_numentities = 0;
g_numtextures = 0;
if ( active_brushes.next != NULL )
{
for ( b = active_brushes.next ; b != NULL && b != &active_brushes ; b=next)
{
next = b->next;
if (b->brush_faces )
{
if ( !b->owner->eclass->fixedsize)
g_numbrushes++;
else
g_numentities++;
}
}
}
/*
if ( entities.next != NULL )
{
for ( e = entities.next ; e != &entities && g_numentities != MAX_MAP_ENTITIES ; e = e->next)
{
g_numentities++;
}
}
*/
for (q=g_qeglobals.d_qtextures ; q ; q=q->next)
{
if (q->name[0] == '(')
continue; // don't count entity textures
if (q->inuse)
g_numtextures++;
}
if ( ( ( g_numbrushes != s_lastbrushcount ) || ( g_numentities != s_lastentitycount ) || ( g_numtextures != s_lasttexturecount ) ) || ( !s_didonce ) )
{
Sys_UpdateBrushStatusBar();
s_lastbrushcount = g_numbrushes;
s_lastentitycount = g_numentities;
s_lasttexturecount = g_numtextures;
s_didonce = true;
}
}