/* =========================================================================== Copyright (C) 1997-2006 Id Software, Inc. This file is part of Quake 2 Tools source code. Quake 2 Tools source code is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Quake 2 Tools source code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Quake 2 Tools source code; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA =========================================================================== */ #include "qe3.h" #include "mru.h" int screen_width; int screen_height; qboolean have_quit; int update_bits; HANDLE bsp_process; //=========================================== void Sys_SetTitle (char *text) { SetWindowText (g_qeglobals.d_hwndMain, text); } HCURSOR waitcursor; void Sys_BeginWait (void) { waitcursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); } void Sys_EndWait (void) { if (waitcursor) { SetCursor (waitcursor); waitcursor = NULL; } } void Sys_GetCursorPos (int *x, int *y) { POINT lpPoint; GetCursorPos (&lpPoint); *x = lpPoint.x; *y = lpPoint.y; } void Sys_SetCursorPos (int x, int y) { SetCursorPos (x, y); } void Sys_UpdateWindows (int bits) { // Sys_Printf("updating 0x%X\n", bits); update_bits |= bits; //update_bits = -1; } void Sys_Beep (void) { MessageBeep (MB_ICONASTERISK); } char *TranslateString (char *buf) { static char buf2[32768]; int i, l; char *out; l = strlen(buf); out = buf2; for (i=0 ; iepairs ; ep ; ep=ep->next) { if (ep->key[0] == 'b' && ep->key[1] == 's' && ep->key[2] == 'p') { bsp_commands[i] = ep->key; AppendMenu (hmenu, MF_ENABLED|MF_STRING, CMD_BSPCOMMAND+i, (LPCTSTR)ep->key); i++; } } count = i; } //============================================== /* =============== CheckBspProcess See if the BSP is done yet =============== */ void CheckBspProcess (void) { char outputpath[1024]; char temppath[512]; DWORD exitcode; char *out; BOOL ret; if (!bsp_process) return; ret = GetExitCodeProcess (bsp_process, &exitcode); if (!ret) Error ("GetExitCodeProcess failed"); if (exitcode == STILL_ACTIVE) return; bsp_process = 0; GetTempPath(512, temppath); sprintf (outputpath, "%sjunk.txt", temppath); LoadFile (outputpath, (void *)&out); Sys_Printf ("%s", out); Sys_Printf ("\ncompleted.\n"); free (out); Sys_Beep (); Pointfile_Check (); } extern int cambuttonstate; /* ================== WinMain ================== */ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance ,LPSTR lpCmdLine, int nCmdShow) { MSG msg; double time, oldtime, delta; HACCEL accelerators; g_qeglobals.d_hInstance = hInstance; InitCommonControls (); screen_width = GetSystemMetrics (SM_CXFULLSCREEN); screen_height = GetSystemMetrics (SM_CYFULLSCREEN); // hack for broken NT 4.0 dual screen if (screen_width > 2*screen_height) screen_width /= 2; accelerators = LoadAccelerators (hInstance , MAKEINTRESOURCE(IDR_ACCELERATOR1)); if (!accelerators) Error ("LoadAccelerators failed"); Main_Create (hInstance); WCam_Create (hInstance); WXY_Create (hInstance); WZ_Create (hInstance); CreateEntityWindow(hInstance); // the project file can be specified on the command line, // or implicitly found in the scripts directory if (lpCmdLine && strlen(lpCmdLine)) { ParseCommandLine (lpCmdLine); if (!QE_LoadProject(argv[1])) Error ("Couldn't load %s project file", argv[1]); } else if (!QE_LoadProject("scripts/quake.qe4")) Error ("Couldn't load scripts/quake.qe4 project file"); QE_Init (); Sys_Printf ("Entering message loop\n"); oldtime = Sys_DoubleTime (); while (!have_quit) { Sys_EndWait (); // remove wait cursor if active while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { if (!TranslateAccelerator(g_qeglobals.d_hwndMain, accelerators, &msg) ) { TranslateMessage (&msg); DispatchMessage (&msg); } if (msg.message == WM_QUIT) have_quit = true; } CheckBspProcess (); time = Sys_DoubleTime (); delta = time - oldtime; oldtime = time; if (delta > 0.2) delta = 0.2; // run time dependant behavior Cam_MouseControl (delta); // update any windows now if (update_bits & W_CAMERA) { InvalidateRect(g_qeglobals.d_hwndCamera, NULL, false); UpdateWindow (g_qeglobals.d_hwndCamera); } if (update_bits & (W_Z | W_Z_OVERLAY) ) { InvalidateRect(g_qeglobals.d_hwndZ, NULL, false); UpdateWindow (g_qeglobals.d_hwndZ); } if ( update_bits & W_TEXTURE ) { InvalidateRect(g_qeglobals.d_hwndTexture, NULL, false); UpdateWindow (g_qeglobals.d_hwndEntity); } if (update_bits & (W_XY | W_XY_OVERLAY)) { InvalidateRect(g_qeglobals.d_hwndXY, NULL, false); UpdateWindow (g_qeglobals.d_hwndXY); } update_bits = 0; if (!cambuttonstate && !have_quit) { // if not driving in the camera view, block WaitMessage (); } } /* return success of application */ return TRUE; }