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 ===========================================================================
34 //===========================================
36 void Sys_SetTitle (char *text)
38 SetWindowText (g_qeglobals.d_hwndMain, text);
43 void Sys_BeginWait (void)
45 waitcursor = SetCursor (LoadCursor (NULL, IDC_WAIT));
48 void Sys_EndWait (void)
52 SetCursor (waitcursor);
58 void Sys_GetCursorPos (int *x, int *y)
62 GetCursorPos (&lpPoint);
67 void Sys_SetCursorPos (int x, int y)
72 void Sys_UpdateWindows (int bits)
74 // Sys_Printf("updating 0x%X\n", bits);
82 MessageBeep (MB_ICONASTERISK);
85 char *TranslateString (char *buf)
87 static char buf2[32768];
108 void Sys_ClearPrintf (void)
114 SendMessage (g_qeglobals.d_hwndEdit,
120 void Sys_Printf (char *text, ...)
126 va_start (argptr,text);
127 vsprintf (buf, text,argptr);
130 out = TranslateString (buf);
135 SendMessage (g_qeglobals.d_hwndEdit,
143 double Sys_DoubleTime (void)
145 return clock()/ 1000.0;
148 void PrintPixels (HDC hDC)
151 PIXELFORMATDESCRIPTOR p[64];
153 printf ("### flags color layer\n");
154 for (i=1 ; i<64 ; i++)
156 if (!DescribePixelFormat ( hDC, i, sizeof(p[0]), &p[i]))
158 printf ("%3i %5i %5i %5i\n", i,
163 printf ("%i modes\n", i-1);
168 //==========================================================================
170 void QEW_StopGL( HWND hWnd, HGLRC hGLRC, HDC hDC )
172 wglMakeCurrent( NULL, NULL );
173 wglDeleteContext( hGLRC );
174 ReleaseDC( hWnd, hDC );
177 int QEW_SetupPixelFormat(HDC hDC, qboolean zbuffer )
179 static PIXELFORMATDESCRIPTOR pfd = {
180 sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
182 PFD_DRAW_TO_WINDOW | // support window
183 PFD_SUPPORT_OPENGL | // support OpenGL
184 PFD_DOUBLEBUFFER, // double buffered
185 PFD_TYPE_RGBA, // RGBA type
186 24, // 24-bit color depth
187 0, 0, 0, 0, 0, 0, // color bits ignored
188 0, // no alpha buffer
189 0, // shift bit ignored
190 0, // no accumulation buffer
191 0, 0, 0, 0, // accum bits ignored
193 0, // no stencil buffer
194 0, // no auxiliary buffer
195 PFD_MAIN_PLANE, // main layer
197 0, 0, 0 // layer masks ignored
205 if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 )
207 printf("%d",GetLastError());
208 Error ("ChoosePixelFormat failed");
211 if (!SetPixelFormat(hDC, pixelformat, &pfd))
212 Error ("SetPixelFormat failed");
221 For abnormal program terminations
224 void Error (char *error, ...)
231 err = GetLastError ();
233 va_start (argptr,error);
234 vsprintf (text, error,argptr);
237 sprintf (text2, "%s\nGetLastError() = %i", text, err);
238 MessageBox(g_qeglobals.d_hwndMain, text2, "Error", 0 /* MB_OK */ );
244 ======================================================================
248 ======================================================================
251 qboolean ConfirmModified (void)
256 if (MessageBox (g_qeglobals.d_hwndMain, "This will lose changes to the map"
257 , "warning", MB_OKCANCEL) == IDCANCEL)
262 static OPENFILENAME ofn; /* common dialog box structure */
263 static char szDirName[MAX_PATH]; /* directory string */
264 static char szFile[260]; /* filename string */
265 static char szFileTitle[260]; /* file title string */
266 static char szFilter[260] = /* filter string */
267 "QuakeEd file (*.map)\0*.map\0\0";
268 static char szProjectFilter[260] = /* filter string */
269 "QuakeEd project (*.qe4)\0*.qe4\0\0";
270 static char chReplace; /* string separator for szFilter */
271 static int i, cbString; /* integer count variables */
272 static HANDLE hf; /* file handle */
274 void OpenDialog (void)
277 * Obtain the system directory name and
278 * store it in szDirName.
281 strcpy (szDirName, ValueForKey (g_qeglobals.d_project_entity, "basepath") );
282 strcat (szDirName, "\\maps");
284 /* Place the terminating null character in the szFile. */
288 /* Set the members of the OPENFILENAME structure. */
290 ofn.lStructSize = sizeof(OPENFILENAME);
291 ofn.hwndOwner = g_qeglobals.d_hwndCamera;
292 ofn.lpstrFilter = szFilter;
293 ofn.nFilterIndex = 1;
294 ofn.lpstrFile = szFile;
295 ofn.nMaxFile = sizeof(szFile);
296 ofn.lpstrFileTitle = szFileTitle;
297 ofn.nMaxFileTitle = sizeof(szFileTitle);
298 ofn.lpstrInitialDir = szDirName;
299 ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST |
302 /* Display the Open dialog box. */
304 if (!GetOpenFileName(&ofn))
307 // Add the file in MRU.
308 AddNewItem( g_qeglobals.d_lpMruMenu, ofn.lpstrFile);
310 // Refresh the File menu.
311 PlaceMenuMRUItem(g_qeglobals.d_lpMruMenu,GetSubMenu(GetMenu(g_qeglobals.d_hwndMain),0),
316 Map_LoadFile (ofn.lpstrFile);
319 void ProjectDialog (void)
322 * Obtain the system directory name and
323 * store it in szDirName.
326 strcpy (szDirName, ValueForKey(g_qeglobals.d_project_entity, "basepath") );
327 strcat (szDirName, "\\scripts");
329 /* Place the terminating null character in the szFile. */
333 /* Set the members of the OPENFILENAME structure. */
335 ofn.lStructSize = sizeof(OPENFILENAME);
336 ofn.hwndOwner = g_qeglobals.d_hwndCamera;
337 ofn.lpstrFilter = szProjectFilter;
338 ofn.nFilterIndex = 1;
339 ofn.lpstrFile = szFile;
340 ofn.nMaxFile = sizeof(szFile);
341 ofn.lpstrFileTitle = szFileTitle;
342 ofn.nMaxFileTitle = sizeof(szFileTitle);
343 ofn.lpstrInitialDir = szDirName;
344 ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST |
347 /* Display the Open dialog box. */
349 if (!GetOpenFileName(&ofn))
352 // Refresh the File menu.
353 PlaceMenuMRUItem(g_qeglobals.d_lpMruMenu,GetSubMenu(GetMenu(g_qeglobals.d_hwndMain),0),
357 if (!QE_LoadProject(ofn.lpstrFile))
358 Error ("Couldn't load project file");
362 void SaveAsDialog (void)
364 strcpy (szDirName, ValueForKey (g_qeglobals.d_project_entity, "basepath") );
365 strcat (szDirName, "\\maps");
367 /* Place the terminating null character in the szFile. */
371 /* Set the members of the OPENFILENAME structure. */
373 ofn.lStructSize = sizeof(OPENFILENAME);
374 ofn.hwndOwner = g_qeglobals.d_hwndCamera;
375 ofn.lpstrFilter = szFilter;
376 ofn.nFilterIndex = 1;
377 ofn.lpstrFile = szFile;
378 ofn.nMaxFile = sizeof(szFile);
379 ofn.lpstrFileTitle = szFileTitle;
380 ofn.nMaxFileTitle = sizeof(szFileTitle);
381 ofn.lpstrInitialDir = szDirName;
382 ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST |
383 OFN_FILEMUSTEXIST | OFN_OVERWRITEPROMPT;
385 /* Display the Open dialog box. */
387 if (!GetSaveFileName(&ofn))
390 DefaultExtension (ofn.lpstrFile, ".map");
391 strcpy (currentmap, ofn.lpstrFile);
393 // Add the file in MRU.
394 AddNewItem(g_qeglobals.d_lpMruMenu, ofn.lpstrFile);
396 // Refresh the File menu.
397 PlaceMenuMRUItem(g_qeglobals.d_lpMruMenu,GetSubMenu(GetMenu(g_qeglobals.d_hwndMain),0),
400 Map_SaveFile (ofn.lpstrFile, false); // ignore region
404 =======================================================
408 =======================================================
417 char *bsp_commands[256];
419 void FillBSPMenu (void)
426 hmenu = GetSubMenu (GetMenu(g_qeglobals.d_hwndMain), MENU_BSP);
428 for (i=0 ; i<count ; i++)
429 DeleteMenu (hmenu, CMD_BSPCOMMAND+i, MF_BYCOMMAND);
433 for (ep = g_qeglobals.d_project_entity->epairs ; ep ; ep=ep->next)
435 if (ep->key[0] == 'b' && ep->key[1] == 's' && ep->key[2] == 'p')
437 bsp_commands[i] = ep->key;
438 AppendMenu (hmenu, MF_ENABLED|MF_STRING,
439 CMD_BSPCOMMAND+i, (LPCTSTR)ep->key);
446 //==============================================
452 See if the BSP is done yet
455 void CheckBspProcess (void)
457 char outputpath[1024];
466 ret = GetExitCodeProcess (bsp_process, &exitcode);
468 Error ("GetExitCodeProcess failed");
469 if (exitcode == STILL_ACTIVE)
474 GetTempPath(512, temppath);
475 sprintf (outputpath, "%sjunk.txt", temppath);
477 LoadFile (outputpath, (void *)&out);
478 Sys_Printf ("%s", out);
479 Sys_Printf ("\ncompleted.\n");
486 extern int cambuttonstate;
494 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance
495 ,LPSTR lpCmdLine, int nCmdShow)
498 double time, oldtime, delta;
501 g_qeglobals.d_hInstance = hInstance;
503 InitCommonControls ();
505 screen_width = GetSystemMetrics (SM_CXFULLSCREEN);
506 screen_height = GetSystemMetrics (SM_CYFULLSCREEN);
508 // hack for broken NT 4.0 dual screen
509 if (screen_width > 2*screen_height)
512 accelerators = LoadAccelerators (hInstance
513 , MAKEINTRESOURCE(IDR_ACCELERATOR1));
515 Error ("LoadAccelerators failed");
517 Main_Create (hInstance);
519 WCam_Create (hInstance);
520 WXY_Create (hInstance);
521 WZ_Create (hInstance);
522 CreateEntityWindow(hInstance);
524 // the project file can be specified on the command line,
525 // or implicitly found in the scripts directory
526 if (lpCmdLine && strlen(lpCmdLine))
528 ParseCommandLine (lpCmdLine);
529 if (!QE_LoadProject(argv[1]))
530 Error ("Couldn't load %s project file", argv[1]);
532 else if (!QE_LoadProject("scripts/quake.qe4"))
533 Error ("Couldn't load scripts/quake.qe4 project file");
537 Sys_Printf ("Entering message loop\n");
539 oldtime = Sys_DoubleTime ();
543 Sys_EndWait (); // remove wait cursor if active
545 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
547 if (!TranslateAccelerator(g_qeglobals.d_hwndMain, accelerators, &msg) )
549 TranslateMessage (&msg);
550 DispatchMessage (&msg);
552 if (msg.message == WM_QUIT)
559 time = Sys_DoubleTime ();
560 delta = time - oldtime;
565 // run time dependant behavior
566 Cam_MouseControl (delta);
568 // update any windows now
569 if (update_bits & W_CAMERA)
571 InvalidateRect(g_qeglobals.d_hwndCamera, NULL, false);
572 UpdateWindow (g_qeglobals.d_hwndCamera);
574 if (update_bits & (W_Z | W_Z_OVERLAY) )
576 InvalidateRect(g_qeglobals.d_hwndZ, NULL, false);
577 UpdateWindow (g_qeglobals.d_hwndZ);
580 if ( update_bits & W_TEXTURE )
582 InvalidateRect(g_qeglobals.d_hwndTexture, NULL, false);
583 UpdateWindow (g_qeglobals.d_hwndEntity);
586 if (update_bits & (W_XY | W_XY_OVERLAY))
588 InvalidateRect(g_qeglobals.d_hwndXY, NULL, false);
589 UpdateWindow (g_qeglobals.d_hwndXY);
594 if (!cambuttonstate && !have_quit)
595 { // if not driving in the camera view, block
601 /* return success of application */