win_qe3.cpp
来自「quake3工具源码。包括生成bsp文件」· C++ 代码 · 共 660 行 · 第 1/2 页
CPP
660 行
#include "stdafx.h"
#include "qe3.h"
#include "mru.h"
#include "PrefsDlg.h"
////////////////////////////////////////////////////////////////////////////
// BSP frontend plugin
// global flag for BSP frontend plugin is g_qeglobals.bBSPFrontendPlugin
_QERPlugBSPFrontendTable g_BSPFrontendTable;
CStringArray g_BSPFrontendCommands;
extern CEdit* g_pEdit;
int screen_width;
int screen_height;
qboolean have_quit;
int update_bits;
HANDLE bsp_process;
//===========================================
void Sys_MarkMapModified (void)
{
char title[1024];
if (modified != 1)
{
modified = true; // mark the map as changed
sprintf (title, "%s *", currentmap);
QE_ConvertDOSToUnixName( title, title );
Sys_SetTitle (title);
}
}
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_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 ; i<l ; i++)
{
if (buf[i] == '\n')
{
*out++ = '\r';
*out++ = '\n';
}
else
*out++ = buf[i];
}
*out++ = 0;
return buf2;
}
void Sys_ClearPrintf (void)
{
char text[4];
text[0] = 0;
SendMessage (g_qeglobals.d_hwndEdit, WM_SETTEXT, 0, (LPARAM)text);
}
#define SCROLLBACK_MAX_LINES 600
#define SCROLLBACK_DEL_CHARS 500
void Sys_Printf (char *text, ...)
{
va_list argptr;
char buf[32768];
char *out;
LRESULT result; // PGM
DWORD oldPosS, oldPosE; // PGM
va_start (argptr,text);
vsprintf (buf, text,argptr);
va_end (argptr);
out = TranslateString (buf);
#ifdef LATER
Sys_Status(out);
#else
//PGM
result = SendMessage (g_qeglobals.d_hwndEdit, EM_GETLINECOUNT, 0, 0);
if(result > SCROLLBACK_MAX_LINES)
{
char replaceText[5];
replaceText[0] = '\0';
SendMessage (g_qeglobals.d_hwndEdit, WM_SETREDRAW, (WPARAM)0, (LPARAM)0);
SendMessage (g_qeglobals.d_hwndEdit, EM_GETSEL, (WPARAM)&oldPosS, (LPARAM)&oldPosE);
SendMessage (g_qeglobals.d_hwndEdit, EM_SETSEL, 0, SCROLLBACK_DEL_CHARS);
SendMessage (g_qeglobals.d_hwndEdit, EM_REPLACESEL, (WPARAM)0, (LPARAM)replaceText);
SendMessage (g_qeglobals.d_hwndEdit, EM_SETSEL, oldPosS, oldPosE);
SendMessage (g_qeglobals.d_hwndEdit, WM_SETREDRAW, (WPARAM)1, (LPARAM)0);
}
//PGM
SendMessage (g_qeglobals.d_hwndEdit, EM_REPLACESEL, 0, (LPARAM)out);
#endif
}
double Sys_DoubleTime (void)
{
return clock()/ 1000.0;
}
void PrintPixels (HDC hDC)
{
int i;
PIXELFORMATDESCRIPTOR p[64];
printf ("### flags color layer\n");
for (i=1 ; i<64 ; i++)
{
if (!DescribePixelFormat ( hDC, i, sizeof(p[0]), &p[i]))
break;
printf ("%3i %5i %5i %5i\n", i,
p[i].dwFlags,
p[i].cColorBits,
p[i].bReserved);
}
printf ("%i modes\n", i-1);
}
//==========================================================================
void QEW_StopGL( HWND hWnd, HGLRC hGLRC, HDC hDC )
{
qwglMakeCurrent( NULL, NULL );
qwglDeleteContext( hGLRC );
ReleaseDC( hWnd, hDC );
}
int WINAPI QEW_SetupPixelFormat(HDC hDC, qboolean zbuffer )
{
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
32, // depth bits
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
}; //
int pixelformat = 0;
zbuffer = true;
if ( !zbuffer )
pfd.cDepthBits = 0;
if (g_PrefsDlg.m_bSGIOpenGL)
{
if ( (pixelformat = qwglChoosePixelFormat(hDC, &pfd)) == 0 )
{
printf("%d",GetLastError());
Error ("ChoosePixelFormat failed");
}
if (!qwglSetPixelFormat(hDC, pixelformat, &pfd))
Error ("SetPixelFormat failed");
}
else
{
if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 )
{
printf("%d",GetLastError());
Error ("ChoosePixelFormat failed");
}
if (!SetPixelFormat(hDC, pixelformat, &pfd))
Error ("SetPixelFormat failed");
}
return pixelformat;
}
/*
=================
Error
For abnormal program terminations
=================
*/
void Error (char *error, ...)
{
va_list argptr;
char text[1024];
char text2[1024];
int err;
err = GetLastError ();
int i = qglGetError();
va_start (argptr,error);
vsprintf (text, error,argptr);
va_end (argptr);
sprintf (text2, "%s\nGetLastError() = %i - %i\nAn unrecoverable error has occured. Would you like to edit Preferences before exiting Q3Radiant?", text, err, i);
if (MessageBox(g_qeglobals.d_hwndMain, text2, "Error", MB_YESNO) == IDYES)
{
g_PrefsDlg.LoadPrefs();
g_PrefsDlg.DoModal();
}
exit (1);
}
void Warning (char *error, ...)
{
va_list argptr;
char text[1024];
int err;
err = GetLastError ();
int i = qglGetError();
va_start (argptr,error);
vsprintf (text, error,argptr);
va_end (argptr);
Sys_Printf(text);
}
/*
======================================================================
FILE DIALOGS
======================================================================
*/
qboolean ConfirmModified (void)
{
if (!modified)
return true;
if (MessageBox (g_qeglobals.d_hwndMain, "This will lose changes to the map"
, "warning", MB_OKCANCEL) == IDCANCEL)
return false;
return true;
}
static OPENFILENAME ofn; /* common dialog box structure */
static char szDirName[MAX_PATH]; /* directory string */
static char szFile[260]; /* filename string */
static char szFileTitle[260]; /* file title string */
static char szFilter[260] = /* filter string */
"Map file (*.map, *.reg)\0*.map\0*.reg\0\0";
static char szProjectFilter[260] = /* filter string */
"Q3Radiant project (*.qe4, *.prj)\0*.qe4\0*.prj\0\0";
static char chReplace; /* string separator for szFilter */
static int i, cbString; /* integer count variables */
static HANDLE hf; /* file handle */
void OpenDialog (void)
{
/*
* Obtain the system directory name and
* store it in szDirName.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?