2 ===========================================================================
3 Copyright (C) 1997-2006 Id Software, Inc.
5 This file is part of Quake 2 Tools source code.
7 Quake 2 Tools source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
12 Quake 2 Tools source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Quake 2 Tools source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
25 QEGlobals_t g_qeglobals;
27 void QE_CheckOpenGLForErrors(void)
31 while ( ( i = glGetError() ) != GL_NO_ERROR )
35 sprintf( buffer, "OpenGL Error: %s", gluErrorString( i ) );
37 MessageBox( g_qeglobals.d_hwndMain, buffer , "QuakeEd Error", MB_OK | MB_ICONEXCLAMATION );
43 char *ExpandReletivePath (char *p)
45 static char temp[1024];
50 if (p[0] == '/' || p[0] == '\\')
53 base = ValueForKey(g_qeglobals.d_project_entity, "basepath");
54 sprintf (temp, "%s/%s", base, p);
60 void *qmalloc (int size)
68 char *copystring (char *s)
71 b = malloc(strlen(s)+1);
80 If five minutes have passed since making a change
81 and the map hasn't been saved, save it out.
84 void QE_CheckAutoSave( void )
86 static clock_t s_start;
91 if ( modified != 1 || !s_start)
97 if ( now - s_start > ( CLOCKS_PER_SEC * 60 * QE_AUTOSAVE_INTERVAL ) )
99 Sys_Printf ("Autosaving...\n");
100 Sys_Status ("Autosaving...", 0 );
102 Map_SaveFile (ValueForKey(g_qeglobals.d_project_entity, "autosave"), false);
104 Sys_Status ("Autosaving...Saved.", 0 );
117 qboolean QE_LoadProject (char *projectfile)
121 Sys_Printf ("QE_LoadProject (%s)\n", projectfile);
123 if ( LoadFileNoCrash (projectfile, (void *)&data) == -1)
125 StartTokenParsing (data);
126 g_qeglobals.d_project_entity = Entity_Parse (true);
127 if (!g_qeglobals.d_project_entity)
128 Error ("Couldn't parse %s", projectfile);
131 Eclass_InitForSourceDirectory (ValueForKey (g_qeglobals.d_project_entity, "entitypath"));
133 FillClassList (); // list in entity window
148 #define SPEED_MOVE 32
149 #define SPEED_TURN 22.5
151 qboolean QE_KeyDown (int key)
156 PostMessage( g_qeglobals.d_hwndMain, WM_COMMAND, ID_MISC_SELECTENTITYCOLOR, 0 );
160 VectorMA (camera.origin, SPEED_MOVE, camera.forward, camera.origin);
161 Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
164 VectorMA (camera.origin, -SPEED_MOVE, camera.forward, camera.origin);
165 Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
168 camera.angles[1] += SPEED_TURN;
169 Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
172 camera.angles[1] -= SPEED_TURN;
173 Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
176 camera.origin[2] += SPEED_MOVE;
177 Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY|W_Z_OVERLAY);
180 camera.origin[2] -= SPEED_MOVE;
181 Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY|W_Z_OVERLAY);
184 camera.angles[0] += SPEED_TURN;
185 if (camera.angles[0] > 85)
186 camera.angles[0] = 85;
187 Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
190 camera.angles[0] -= SPEED_TURN;
191 if (camera.angles[0] < -85)
192 camera.angles[0] = -85;
193 Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
196 VectorMA (camera.origin, -SPEED_MOVE, camera.right, camera.origin);
197 Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
200 VectorMA (camera.origin, SPEED_MOVE, camera.right, camera.origin);
201 Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
205 g_qeglobals.d_showgrid = !g_qeglobals.d_showgrid;
206 PostMessage( g_qeglobals.d_hwndXY, WM_PAINT, 0, 0 );
209 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_GRID_1, 0);
212 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_GRID_2, 0);
215 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_GRID_4, 0);
218 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_GRID_8, 0);
221 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_GRID_16, 0);
224 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_GRID_32, 0);
227 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_GRID_64, 0);
231 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_SELECTION_DRAGEDGES, 0);
234 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_SELECTION_DRAGVERTECIES, 0);
238 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_ENTITY, 0);
241 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_CONSOLE, 0);
244 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_TEXTURE, 0);
247 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_TEXTURES_INSPECTOR, 0);
251 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_SELECTION_CLONE, 0);
255 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_SELECTION_DELETE, 0);
258 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_SELECTION_DESELECT, 0);
261 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_CENTER, 0);
265 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_ZOOMIN, 0);
268 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_ZOOMOUT, 0);
272 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_DOWNFLOOR, 0);
275 PostMessage (g_qeglobals.d_hwndMain, WM_COMMAND, ID_VIEW_UPFLOOR, 0);
290 Sets target / targetname on the two entities selected
291 from the first selected to the secon
294 void ConnectEntities (void)
296 entity_t *e1, *e2, *e;
298 int maxtarg, targetnum;
301 if (g_qeglobals.d_select_count != 2)
303 Sys_Status ("Must have two brushes selected.", 0);
308 e1 = g_qeglobals.d_select_order[0]->owner;
309 e2 = g_qeglobals.d_select_order[1]->owner;
311 if (e1 == world_entity || e2 == world_entity)
313 Sys_Status ("Can't connect to the world.", 0);
320 Sys_Status ("Brushes are from same entity.", 0);
325 target = ValueForKey (e1, "target");
326 if (target && target[0])
327 strcpy (newtarg, target);
330 target = ValueForKey (e2, "targetname");
331 if (target && target[0])
332 strcpy (newtarg, target);
335 // make a unique target value
337 for (e=entities.next ; e != &entities ; e=e->next)
339 tn = ValueForKey (e, "targetname");
342 targetnum = atoi(tn+1);
343 if (targetnum > maxtarg)
347 sprintf (newtarg, "t%i", maxtarg+1);
351 SetKeyValue (e1, "target", newtarg);
352 SetKeyValue (e2, "targetname", newtarg);
353 Sys_UpdateWindows (W_XY | W_CAMERA);
356 Select_Brush (g_qeglobals.d_select_order[1]);
359 qboolean QE_SingleBrush (void)
361 if ( (selected_brushes.next == &selected_brushes)
362 || (selected_brushes.next->next != &selected_brushes) )
364 Sys_Printf ("Error: you must have a single brush selected\n");
367 if (selected_brushes.next->owner->eclass->fixedsize)
369 Sys_Printf ("Error: you cannot manipulate fixed size entities\n");
379 ** initialize variables
381 g_qeglobals.d_gridsize = 8;
382 g_qeglobals.d_showgrid = true;
393 void QE_ConvertDOSToUnixName( char *dst, const char *src )
406 int g_numbrushes, g_numentities;
408 void QE_CountBrushesAndUpdateStatusBar( void )
410 static int s_lastbrushcount, s_lastentitycount;
411 static qboolean s_didonce;
419 if ( active_brushes.next != NULL )
421 for ( b = active_brushes.next ; b != NULL && b != &active_brushes ; b=next)
426 if ( !b->owner->eclass->fixedsize)
434 if ( entities.next != NULL )
436 for ( e = entities.next ; e != &entities && g_numentities != MAX_MAP_ENTITIES ; e = e->next)
442 if ( ( ( g_numbrushes != s_lastbrushcount ) || ( g_numentities != s_lastentitycount ) ) || ( !s_didonce ) )
444 Sys_UpdateStatusBar();
446 s_lastbrushcount = g_numbrushes;
447 s_lastentitycount = g_numentities;