示例#1
0
/*
 =======================================================================================================================
    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 bool inAutoSave = false;
	static bool autoToggle = false;
	if (inAutoSave) {
		Sys_Status("Did not autosave due recursive entry into autosave routine\n");
		return;
	}

	if ( !mapModified ) {
		return;
	}

	inAutoSave = true;

	if ( g_PrefsDlg.m_bAutoSave ) {
		CString strMsg = g_PrefsDlg.m_bSnapShots ? "Autosaving snapshot..." : "Autosaving...";
		Sys_Status(strMsg.GetBuffer(0), 0);

		if (g_PrefsDlg.m_bSnapShots && stricmp(currentmap, "unnamed.map") != 0) {
			Map_Snapshot();
		} else {
			Map_SaveFile(ValueForKey(g_qeglobals.d_project_entity, (autoToggle == 0) ? "autosave1" : "autosave2" ), false, true);
			autoToggle ^= 1;
		}
		Sys_Status("Autosaving...Saved.", 0);
		mapModified = 0;		// DHM - _D3XP
	} else {
		common->Printf("Autosave skipped...\n");
		Sys_Status("Autosave skipped...", 0);
	}

	inAutoSave = false;
}
示例#2
0
void Map_Snapshot(){
	CString strMsg;

	// I hope the modified flag is kept correctly up to date
	if ( !modified ) {
		return;
	}

	// we need to do the following
	// 1. make sure the snapshot directory exists (create it if it doesn't)
	// 2. find out what the lastest save is based on number
	// 3. inc that and save the map
	CString strOrgPath, strOrgFile;
	ExtractPath_and_Filename( currentmap, strOrgPath, strOrgFile );
	AddSlash( strOrgPath );
	strOrgPath += "snapshots";
	bool bGo = true;
	struct stat Stat;
	if ( stat( strOrgPath, &Stat ) == -1 ) {
#ifdef _WIN32
		bGo = ( _mkdir( strOrgPath ) != -1 );
#endif

#if defined ( __linux__ ) || defined ( __APPLE__ )
		bGo = ( mkdir( strOrgPath,0755 ) != -1 );
#endif
	}
	AddSlash( strOrgPath );
	if ( bGo ) {
		int nCount = 0;
		long lSize = 0;
		CString strNewPath;
		strNewPath = strOrgPath;
		strNewPath += strOrgFile;
		CString strFile;
		while ( bGo )
		{
			char buf[PATH_MAX];
			sprintf( buf, "%s.%i", strNewPath.GetBuffer(), nCount );
			strFile = buf;
			bGo = DoesFileExist( strFile, lSize );
			nCount++;
		}
		// strFile has the next available slot
		Map_SaveFile( strFile, false );
		// it is still a modified map (we enter this only if this is a modified map)
		Sys_SetTitle( currentmap );
		Sys_MarkMapModified();
		if ( lSize > 12 * 1024 * 1024 ) { // total size of saves > 4 mb
			Sys_Printf( "The snapshot files in %s total more than 4 megabytes. You might consider cleaning up.", strOrgPath.GetBuffer() );
		}
	}
	else
	{
		strMsg.Format( "Snapshot save failed.. unabled to create directory\n%s", strOrgPath.GetBuffer() );
		gtk_MessageBox( g_pParentWnd->m_pWidget, strMsg );
	}
	strOrgPath = "";
	strOrgFile = "";
}
示例#3
0
/*
 =======================================================================================================================
 =======================================================================================================================
 */
void Map_Snapshot() {
	CString strMsg;

	//
	// we need to do the following 1. make sure the snapshot directory exists (create
	// it if it doesn't) 2. find out what the lastest save is based on number 3. inc
	// that and save the map
	//
	CString strOrgPath, strOrgFile;
	ExtractPath_and_Filename(currentmap, strOrgPath, strOrgFile);
	AddSlash(strOrgPath);
	strOrgPath += "snapshots";

	bool			bGo = true;
	struct _stat	Stat;
	if (_stat(strOrgPath, &Stat) == -1) {
		bGo = (_mkdir(strOrgPath) != -1);
	}

	AddSlash(strOrgPath);
	if (bGo) {
		int		nCount = 0;
		long	lSize = 0;
		CString strNewPath = strOrgPath;
		strNewPath += strOrgFile;

		CString strFile;
		while (bGo) {
			strFile.Format("%s.%i", strNewPath, nCount);
			bGo = DoesFileExist(strFile, lSize);
			nCount++;
		}

		// strFile has the next available slot
		Map_SaveFile(strFile.GetBuffer(0), false);
		Sys_SetTitle(currentmap);
		if (lSize > 12 * 1024 * 1024) { // total size of saves > 4 mb
			common->Printf
			(
				"The snapshot files in the [%s] directory total more than 4 megabytes. You might consider cleaning the directory up.",
				strOrgPath
			);
		}
	}
	else {
		strMsg.Format("Snapshot save failed.. unabled to create directory\n%s", strOrgPath);
		g_pParentWnd->MessageBox(strMsg);
	}
}
示例#4
0
文件: qe3.cpp 项目: GSIO01/GtkRadiant
void WINAPI QE_CheckOpenGLForErrors( void ){
	char strMsg[1024];
	int i = qglGetError();
	if ( i != GL_NO_ERROR ) {
		if ( i == GL_OUT_OF_MEMORY ) {
			sprintf( strMsg, "OpenGL out of memory error %s\nDo you wish to save before exiting?", qgluErrorString( (GLenum)i ) );
			if ( gtk_MessageBox( g_pParentWnd->m_pWidget, strMsg, "Radiant Error", MB_YESNO ) == IDYES ) {
				Map_SaveFile( NULL, false );
			}
			_exit( 1 );
		}
		else
		{
			Sys_Printf( "Warning: OpenGL Error %s\n", qgluErrorString( (GLenum)i ) );
		}
	}
}
示例#5
0
/*
 =======================================================================================================================
 =======================================================================================================================
 */
void SaveAsDialog(bool bRegion) {
	strcpy(szDirName, ValueForKey(g_qeglobals.d_project_entity, "basepath"));

	CString strPath = szDirName;
	AddSlash(strPath);
	strPath += "maps";
	if (g_PrefsDlg.m_strMaps.GetLength() > 0) {
		strPath += va("\\%s", g_PrefsDlg.m_strMaps);
	}

	/* Place the terminating null character in the szFile. */
	szFile[0] = '\0';

	/* Set the members of the OPENFILENAME structure. */
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = g_pParentWnd->GetSafeHwnd();
	ofn.lpstrFilter = szFilter;
	ofn.nFilterIndex = 1;
	ofn.lpstrFile = szFile;
	ofn.nMaxFile = sizeof(szFile);
	ofn.lpstrFileTitle = szFileTitle;
	ofn.nMaxFileTitle = sizeof(szFileTitle);
	ofn.lpstrInitialDir = strPath;
	ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_OVERWRITEPROMPT;

	/* Display the Open dialog box. */
	if (!GetSaveFileName(&ofn)) {
		return; // canceled
	}

	if (bRegion) {
		DefaultExtension(ofn.lpstrFile, ".reg");
	}
	else {
		DefaultExtension(ofn.lpstrFile, ".map");
	}

	if (!bRegion) {
		strcpy(currentmap, ofn.lpstrFile);
		AddNewItem(g_qeglobals.d_lpMruMenu, ofn.lpstrFile);
		PlaceMenuMRUItem(g_qeglobals.d_lpMruMenu, GetSubMenu(GetMenu(g_pParentWnd->GetSafeHwnd()), 0), ID_FILE_EXIT);
	}

	Map_SaveFile(ofn.lpstrFile, bRegion);	// ignore region
}
示例#6
0
文件: qe3.cpp 项目: FS-NulL/Q3Radiant
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 * g_PrefsDlg.m_nAutoSave))
	{

    if (g_PrefsDlg.m_bAutoSave)
    {
      CString strMsg = g_PrefsDlg.m_bSnapShots ? "Autosaving snapshot..." : "Autosaving...";
		  Sys_Printf(strMsg.GetBuffer(0));
      Sys_Printf("\n");
		  Sys_Status (strMsg.GetBuffer(0),0);

      // only snapshot if not working on a default map
      if (g_PrefsDlg.m_bSnapShots && stricmp(currentmap, "unnamed.map") != 0)
      {
        Map_Snapshot();
      }
      else
      {
		    Map_SaveFile (ValueForKey(g_qeglobals.d_project_entity, "autosave"), false);
      }

		  Sys_Status ("Autosaving...Saved.", 0 );
		  modified = 2;
    }
    else
    {
		  Sys_Printf ("Autosave skipped...\n");
		  Sys_Status ("Autosave skipped...", 0 );
    }
		s_start = now;
	}
}
示例#7
0
/*
 =======================================================================================================================
 =======================================================================================================================
 */
void WINAPI QE_CheckOpenGLForErrors(void) {
	CString strMsg;
	int		i = qglGetError();
	if (i != GL_NO_ERROR) {
		if (i == GL_OUT_OF_MEMORY) {
			//
			// strMsg.Format("OpenGL out of memory error %s\nDo you wish to save before
			// exiting?", gluErrorString((GLenum)i));
			//
			if (g_pParentWnd->MessageBox(strMsg, EDITOR_WINDOWTEXT " Error", MB_YESNO) == IDYES) {
				Map_SaveFile(NULL, false);
			}

			exit(1);
		}
		else {
			// strMsg.Format("Warning: OpenGL Error %s\n ", gluErrorString((GLenum)i));
			common->Printf(strMsg.GetBuffer(0));
		}
	}
}
示例#8
0
void SaveAsDialog (void)
{ 
	strcpy (szDirName, ValueForKey (g_qeglobals.d_project_entity, "basepath") );
	strcat (szDirName, "\\maps");

	/* Place the terminating null character in the szFile. */ 
 
	szFile[0] = '\0'; 
 
	/* Set the members of the OPENFILENAME structure. */ 
 
	ofn.lStructSize = sizeof(OPENFILENAME); 
	ofn.hwndOwner = g_qeglobals.d_hwndCamera;
	ofn.lpstrFilter = szFilter; 
	ofn.nFilterIndex = 1; 
	ofn.lpstrFile = szFile; 
	ofn.nMaxFile = sizeof(szFile); 
	ofn.lpstrFileTitle = szFileTitle; 
	ofn.nMaxFileTitle = sizeof(szFileTitle); 
	ofn.lpstrInitialDir = szDirName; 
	ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | 
		OFN_FILEMUSTEXIST | OFN_OVERWRITEPROMPT; 

	/* Display the Open dialog box. */ 
 
	if (!GetSaveFileName(&ofn))
		return;	// canceled
  
	DefaultExtension (ofn.lpstrFile, ".map");
	strcpy (currentmap, ofn.lpstrFile);

	// Add the file in MRU.
	AddNewItem(g_qeglobals.d_lpMruMenu, ofn.lpstrFile);

	// Refresh the File menu.
	PlaceMenuMRUItem(g_qeglobals.d_lpMruMenu,GetSubMenu(GetMenu(g_qeglobals.d_hwndMain),0),
			ID_FILE_EXIT);

	Map_SaveFile (ofn.lpstrFile, false);	// ignore region
}
示例#9
0
文件: qe3.cpp 项目: FS-NulL/Q3Radiant
void WINAPI QE_CheckOpenGLForErrors(void)
{
  int i = qglGetError();
  if (i != GL_NO_ERROR)
  {
    if (i == GL_OUT_OF_MEMORY)
    {
      if (MessageBox(g_qeglobals.d_hwndMain, "OpenGL out of memory error\nDo you wish to save before exiting?", "Q3Radiant Error", MB_YESNO) == IDYES)
      {
        Map_SaveFile(NULL, false);
      }
		  exit(1);
    }
    else
    {
      //++timo ignore stack overflows .. they are present in old versions as well .. would need to put quite a lot of
      // debug checks to track down ..
      if (i != GL_STACK_OVERFLOW)
  		  Sys_Printf ("Warning: OpenGL Error %s\n", qgluErrorString((GLenum)i));
    }
  }
}
示例#10
0
void RunBsp( char* command )
{
	char    sys[2048];
	char    batpath[2048];
	char    outputpath[2048];
	char    temppath[1024];
	char    name[2048];
	char    cWork[2048];
	FILE*   hFile;
	BOOL    ret;
	PROCESS_INFORMATION ProcessInformation;
	STARTUPINFO startupinfo;
	HWND hwndPClient = NULL;
	
	g_hWnd = g_pParentWnd->GetSafeHwnd();
	SetInspectorMode( W_CONSOLE );
	g_tBegin = CTime::GetCurrentTime();
	
	
	DWORD   dwExitcode;
	ret = GetExitCodeProcess( g_hToolThread, &dwExitcode );
	if ( dwExitcode != STILL_ACTIVE )
		g_hToolThread = NULL;
		
	if ( bsp_process || g_hToolThread )
	{
		Sys_Printf( "BSP is still going...\n" );
		return;
	}
	
	outputpath[0] = '\0';
	GetTempPath( 512, temppath );
	
	CString strOutFile = temppath;
	AddSlash( strOutFile );
	strOutFile += "junk.txt";
	
	sprintf( outputpath, " >>%s\r\n", strOutFile );
	
	strcpy( name, currentmap );
	if ( region_active )
	{
		Map_SaveFile( name, false );
		StripExtension( name );
		strcat( name, ".reg" );
	}
	
	Map_SaveFile( name, region_active );
	
	// FIXME: this code just gets worse and worse
	CString strPath, strFile;
	
	char* rsh = ValueForKey( g_qeglobals.d_project_entity, "rshcmd" );
	if ( rsh == NULL )
	{
		ExtractPath_and_Filename( name, strPath, strFile );
		AddSlash( strPath );
		BuildShortPathName( strPath, cWork, 1024 );
		strcat( cWork, strFile );
	}
	else
	{
		strcpy( cWork, name );
	}
	
	hwndPClient = FindWindow( NULL, "Q3Map Process Client" );
	if ( hwndPClient == NULL )
	{
		hwndPClient = FindAnyWindow( "Q3Map Process Client" );
	}
	
	Sys_Printf( "Window info for Process Client %i\n", reinterpret_cast<int>( hwndPClient ) );
	
	bool processServer = ( rsh && strlen( rsh ) > 0 && hwndPClient );
	
	QE_ExpandBspString( command, sys, cWork, processServer );
	
	// if we can find the q3map process server running
	// we will submit maps to it instead of via createprocess
	//
	if ( processServer )
	{
		CString str;
		char cBuff[2048];
		char* pStart = sys;
		char* pEnd = strstr( pStart, "&&" );
		while ( pEnd )
		{
			int nLen = pEnd - pStart - 1;
			strncpy( cBuff, pStart, nLen );
			cBuff[nLen] = 0;
			str = cBuff;
			FindReplace( str, rsh, "" );
			str.TrimLeft( ' ' );
			str.TrimRight( ' ' );
			ATOM a = GlobalAddAtom( str );
			PostMessage( hwndPClient, wm_AddCommand, 0, ( LPARAM )a );
			pStart = pEnd + 2;
			pEnd = strstr( pStart, "&&" );
		}
		str = pStart;
		FindReplace( str, rsh, "" );
		str.TrimLeft( ' ' );
		str.TrimRight( ' ' );
		ATOM a = GlobalAddAtom( str );
		PostMessage( hwndPClient, wm_AddCommand, 0, ( LPARAM )a );
		Sys_Printf( "Commands sent to Q3Map Process Client\n" );
		return;
	}
	
	CString strSys = sys;
	
	FindReplace( strSys, "&&", outputpath );
	strcpy( sys, strSys );
	strcat( sys, outputpath );
	
	
	Sys_ClearPrintf();
	Sys_Printf( "==================\nRunning bsp command...\n" );
	Sys_Printf( "\n%s\n", sys );
	
	//++timo removed the old way BSP commands .. dumping to junk.txt doesn't work on my win98 box
	// FIXME : will most likely break Quake2 BSP commands, is fitted to a one-lined sys command
	//
	// write qe3bsp.bat
	//
	//const char *basePath = ValueForKey(g_qeglobals.d_project_entity, "basepath");
	//if(basePath) {
	//const char *mapName =
	//sprintf(batpath,"%s/maps/%s.bat",basePath,mapName);
	strcpy( batpath, currentmap );
	char* dot = strchr( batpath, '.' );
	strcpy( dot, ".bat" );
	//} else {
	//  sprintf (batpath, "%sqe3bsp.bat", temppath);
	//}
	hFile = fopen( batpath, "w" );
	if ( !hFile )
		Error( "Can't write to %s", batpath );
	fprintf( hFile, sys );
	fclose( hFile );
	
	Pointfile_Delete();
	
	// delete junk.txt file
	remove( strOutFile );
	
	GetStartupInfo( &startupinfo );
	
	ret = CreateProcess(
			  batpath,
			  NULL,
			  NULL,
			  NULL,
			  FALSE,
			  0,
			  NULL,
			  NULL,
			  &startupinfo,
			  &ProcessInformation
		  );
		  
	if ( !ret )
		Error( "CreateProcess failed" );
		
	bsp_process = ProcessInformation.hProcess;
	
	Sleep( 100 );   // give the new process a chance to open it's window
	
	BringWindowToTop( g_qeglobals.d_hwndMain ); // pop us back on top
#if 0
	//
	// write qe3bsp.bat
	//
	sprintf( batpath, "%sqe3bsp.bat", temppath );
	hFile = fopen( batpath, "w" );
	if ( !hFile )
		Error( "Can't write to %s", batpath );
	fprintf( hFile, sys );
	fclose( hFile );
	
	//
	// write qe3bsp2.bat
	//
	sprintf( batpath, "%sqe3bsp2.bat", temppath );
	hFile = fopen( batpath, "w" );
	if ( !hFile )
		Error( "Can't write to %s", batpath );
	fprintf( hFile, "%sqe3bsp.bat > %s", temppath, outputpath );
	fclose( hFile );
	
	Pointfile_Delete();
	
	GetStartupInfo( &startupinfo );
	
	ret = CreateProcess(
			  batpath,      // pointer to name of executable module
			  NULL,         // pointer to command line string
			  NULL,         // pointer to process security attributes
			  NULL,         // pointer to thread security attributes
			  FALSE,            // handle inheritance flag
			  0 /*DETACHED_PROCESS*/,       // creation flags
			  NULL,         // pointer to new environment block
			  NULL,         // pointer to current directory name
			  &startupinfo, // pointer to STARTUPINFO
			  &ProcessInformation   // pointer to PROCESS_INFORMATION
		  );
		  
	if ( !ret )
		Error( "CreateProcess failed" );
		
	bsp_process = ProcessInformation.hProcess;
	
	Sleep( 100 );   // give the new process a chance to open it's window
	
	//BringWindowToTop( g_qeglobals.d_hwndMain );   // pop us back on top
	//SetFocus (g_qeglobals.d_hwndCamera);
#endif
	
}
示例#11
0
文件: qe3.cpp 项目: GSIO01/GtkRadiant
void Map_Snapshot(){
	CString strMsg;

	// I hope the modified flag is kept correctly up to date
	if ( !modified ) {
		return;
	}

	// we need to do the following
	// 1. make sure the snapshot directory exists (create it if it doesn't)
	// 2. find out what the lastest save is based on number
	// 3. inc that and save the map
	CString strOrgPath, strOrgFile;
	ExtractPath_and_Filename( currentmap, strOrgPath, strOrgFile );
	AddSlash( strOrgPath );
	strOrgPath += "snapshots";
	bool bGo = true;
	struct stat Stat;
	if ( stat( strOrgPath, &Stat ) == -1 ) {
#ifdef _WIN32
		bGo = ( _mkdir( strOrgPath ) != -1 );
#endif

#if defined ( __linux__ ) || defined ( __APPLE__ )
		bGo = ( mkdir( strOrgPath,0755 ) != -1 );
#endif
	}
	AddSlash( strOrgPath );
	if ( bGo ) {
		int nCount = 0;
		long lSize = 0;
		CString strNewPath;
		strNewPath = strOrgPath;
		strNewPath += strOrgFile;
		
		// QB - snapshots now follow the format: <mapname>.<snapnum>.<ext>
		//      **NOTE** atm snapshots must end with a .map (or .xmap) ext (this is why they were broken)
		CString strOldEXT = "map"; //default to .map
		const char* type = strrchr( strOrgFile.GetBuffer(),'.' );
		if ( type != NULL ) { strOldEXT = ++type; }; // get the ext for later.
		StripExtension(strNewPath); // then strip it from the new path
		//
		
		CString strFile;
		while ( bGo )
		{
			char buf[PATH_MAX];
			//sprintf( buf, "%s.%i", strNewPath.GetBuffer(), nCount );
			// snapshot will now end with a known ext.
			sprintf( buf, "%s.%i.%s", strNewPath.GetBuffer(), nCount, strOldEXT.GetBuffer() );
			strFile = buf;
			bGo = DoesFileExist( strFile, lSize );
			nCount++;
		}
		// strFile has the next available slot
		Map_SaveFile( strFile, false );
		// it is still a modified map (we enter this only if this is a modified map)
		Sys_SetTitle( currentmap );
		Sys_MarkMapModified();
		if ( lSize > 12 * 1024 * 1024 ) { // total size of saves > 4 mb
			Sys_Printf( "The snapshot files in %s total more than 4 megabytes. You might consider cleaning up.", strOrgPath.GetBuffer() );
		}
	}
	else
	{
		strMsg.Format( "Snapshot save failed.. unabled to create directory\n%s", strOrgPath.GetBuffer() );
		gtk_MessageBox( g_pParentWnd->m_pWidget, strMsg );
	}
	strOrgPath = "";
	strOrgFile = "";
}
示例#12
0
void RunBsp (char *command)
{
	char	sys[1024];
	char	batpath[1024];
	char	outputpath[1024];
	char	temppath[512];
	char	name[1024];
	FILE	*hFile;
	BOOL	ret;
	PROCESS_INFORMATION ProcessInformation;
	STARTUPINFO	startupinfo;

	SetInspectorMode (W_CONSOLE);

	if (bsp_process)
	{
		Sys_Printf ("BSP is still going...\n");
		return;
	}

	GetTempPath(512, temppath);
	sprintf (outputpath, "%sjunk.txt", temppath);

	strcpy (name, currentmap);
	if (region_active)
	{
		Map_SaveFile (name, false);
		StripExtension (name);
		strcat (name, ".reg");
	}

	Map_SaveFile (name, region_active);


	QE_ExpandBspString (command, sys, name);

	Sys_ClearPrintf ();
	Sys_Printf ("======================================\nRunning bsp command...\n");
	Sys_Printf ("\n%s\n", sys);

	//
	// write qe3bsp.bat
	//
	sprintf (batpath, "%sqe3bsp.bat", temppath);
	hFile = fopen(batpath, "w");
	if (!hFile)
		Error ("Can't write to %s", batpath);
	fprintf (hFile, sys);
	fclose (hFile);

	//
	// write qe3bsp2.bat
	//
	sprintf (batpath, "%sqe3bsp2.bat", temppath);
	hFile = fopen(batpath, "w");
	if (!hFile)
		Error ("Can't write to %s", batpath);
	fprintf (hFile, "%sqe3bsp.bat > %s", temppath, outputpath);
	fclose (hFile);

	Pointfile_Delete ();

	GetStartupInfo (&startupinfo);

	ret = CreateProcess(
    batpath,		// pointer to name of executable module 
    NULL,			// pointer to command line string
    NULL,			// pointer to process security attributes 
    NULL,			// pointer to thread security attributes 
    FALSE,			// handle inheritance flag 
    0 /*DETACHED_PROCESS*/,		// creation flags 
    NULL,			// pointer to new environment block 
    NULL,			// pointer to current directory name 
    &startupinfo,	// pointer to STARTUPINFO 
    &ProcessInformation 	// pointer to PROCESS_INFORMATION  
   );

	if (!ret)
		Error ("CreateProcess failed");

	bsp_process = ProcessInformation.hProcess;

	Sleep (100);	// give the new process a chance to open it's window

	BringWindowToTop( g_qeglobals.d_hwndMain );	// pop us back on top
	SetFocus (g_qeglobals.d_hwndCamera);
}
示例#13
0
/* handle all WM_COMMAND messages here */
LONG WINAPI CommandHandler (
    HWND    hWnd,
    WPARAM  wParam,
    LPARAM  lParam)
{
	HMENU hMenu;

    switch (LOWORD(wParam))
    {
//
// file menu
//
    	case ID_FILE_EXIT:
            /* exit application */
			if (!ConfirmModified())
				return TRUE;

            PostMessage (hWnd, WM_CLOSE, 0, 0L);
			break;

		case ID_FILE_OPEN:
			if (!ConfirmModified())
				return TRUE;
			OpenDialog ();
			break;

		case ID_FILE_NEW:
			if (!ConfirmModified())
				return TRUE;
			Map_New ();
			break;
		case ID_FILE_SAVE:
			if (!strcmp(currentmap, "unnamed.map"))
				SaveAsDialog ();
			else
				Map_SaveFile (currentmap, false);	// ignore region
			break;
		case ID_FILE_SAVEAS:
			SaveAsDialog ();
			break;

		case ID_FILE_LOADPROJECT:
			if (!ConfirmModified())
				return TRUE;
			ProjectDialog ();
			break;

		case ID_FILE_POINTFILE:
			if (g_qeglobals.d_pointfile_display_list)
				Pointfile_Clear ();
			else
				Pointfile_Check ();
			break;

//
// view menu
//
		case ID_VIEW_ENTITY:
			SetInspectorMode(W_ENTITY);
			break;
		case ID_VIEW_CONSOLE:
			SetInspectorMode(W_CONSOLE);
			break;
		case ID_VIEW_TEXTURE:
			SetInspectorMode(W_TEXTURE);
			break;

		case ID_VIEW_100:
			g_qeglobals.d_xy.scale = 1;
			Sys_UpdateWindows (W_XY|W_XY_OVERLAY);
			break;
		case ID_VIEW_ZOOMIN:
			g_qeglobals.d_xy.scale *= 5.0/4;
			if (g_qeglobals.d_xy.scale > 16)
				g_qeglobals.d_xy.scale = 16;
			Sys_UpdateWindows (W_XY|W_XY_OVERLAY);
			break;
		case ID_VIEW_ZOOMOUT:
			g_qeglobals.d_xy.scale *= 4.0/5;
			if (g_qeglobals.d_xy.scale < 0.1)
				g_qeglobals.d_xy.scale = 0.1;
			Sys_UpdateWindows (W_XY|W_XY_OVERLAY);
			break;

		case ID_VIEW_Z100:
			z.scale = 1;
			Sys_UpdateWindows (W_Z|W_Z_OVERLAY);
			break;
		case ID_VIEW_ZZOOMIN:
			z.scale *= 5.0/4;
			if (z.scale > 4)
				z.scale = 4;
			Sys_UpdateWindows (W_Z|W_Z_OVERLAY);
			break;
		case ID_VIEW_ZZOOMOUT:
			z.scale *= 4.0/5;
			if (z.scale < 0.125)
				z.scale = 0.125;
			Sys_UpdateWindows (W_Z|W_Z_OVERLAY);
			break;

		case ID_VIEW_CENTER:
			camera.angles[ROLL] = camera.angles[PITCH] = 0;
			camera.angles[YAW] = 22.5 * 
				floor( (camera.angles[YAW]+11)/22.5 );
			Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
			break;

		case ID_VIEW_UPFLOOR:
			Cam_ChangeFloor (true);
			break;
		case ID_VIEW_DOWNFLOOR:
			Cam_ChangeFloor (false);
			break;

		case ID_VIEW_SHOWNAMES:
			g_qeglobals.d_savedinfo.show_names = !g_qeglobals.d_savedinfo.show_names;
			CheckMenuItem ( GetMenu(g_qeglobals.d_hwndMain), ID_VIEW_SHOWNAMES, MF_BYCOMMAND | (g_qeglobals.d_savedinfo.show_names ? MF_CHECKED : MF_UNCHECKED)  );
			Map_BuildBrushData();
			Sys_UpdateWindows (W_XY);
			break;

		case ID_VIEW_SHOWCOORDINATES:
			g_qeglobals.d_savedinfo.show_coordinates ^= 1;
			CheckMenuItem ( GetMenu(g_qeglobals.d_hwndMain), ID_VIEW_SHOWCOORDINATES, MF_BYCOMMAND | (g_qeglobals.d_savedinfo.show_coordinates ? MF_CHECKED : MF_UNCHECKED)  );
			Sys_UpdateWindows (W_XY);
			break;

		case ID_VIEW_SHOWBLOCKS:
			g_qeglobals.show_blocks ^= 1;
			CheckMenuItem ( GetMenu(g_qeglobals.d_hwndMain), ID_VIEW_SHOWBLOCKS, MF_BYCOMMAND | (g_qeglobals.show_blocks ? MF_CHECKED : MF_UNCHECKED)  );
			Sys_UpdateWindows (W_XY);
			break;

		case ID_VIEW_SHOWLIGHTS:
			if ( ( g_qeglobals.d_savedinfo.exclude ^= EXCLUDE_LIGHTS ) & EXCLUDE_LIGHTS )
				CheckMenuItem ( GetMenu(g_qeglobals.d_hwndMain), ID_VIEW_SHOWLIGHTS, MF_BYCOMMAND | MF_UNCHECKED );
			else
				CheckMenuItem ( GetMenu(g_qeglobals.d_hwndMain), ID_VIEW_SHOWLIGHTS, MF_BYCOMMAND | MF_CHECKED );				
			Sys_UpdateWindows (W_XY|W_CAMERA);
			break;

		case ID_VIEW_SHOWPATH:
			if ( ( g_qeglobals.d_savedinfo.exclude ^= EXCLUDE_PATHS ) & EXCLUDE_PATHS )
				CheckMenuItem ( GetMenu(g_qeglobals.d_hwndMain), ID_VIEW_SHOWPATH, MF_BYCOMMAND | MF_UNCHECKED );
			else
				CheckMenuItem ( GetMenu(g_qeglobals.d_hwndMain), ID_VIEW_SHOWPATH, MF_BYCOMMAND | MF_CHECKED );
			Sys_UpdateWindows (W_XY|W_CAMERA);
			break;

		case ID_VIEW_SHOWENT:
			if ( ( g_qeglobals.d_savedinfo.exclude ^= EXCLUDE_ENT ) & EXCLUDE_ENT )
				CheckMenuItem( GetMenu(g_qeglobals.d_hwndMain), ID_VIEW_SHOWENT, MF_BYCOMMAND | MF_UNCHECKED);
			else
				CheckMenuItem( GetMenu(g_qeglobals.d_hwndMain), ID_VIEW_SHOWENT, MF_BYCOMMAND | MF_CHECKED);
			Sys_UpdateWindows (W_XY|W_CAMERA);
			break;

		case ID_VIEW_SHOWWATER:
			if ( ( g_qeglobals.d_savedinfo.exclude ^= EXCLUDE_WATER ) & EXCLUDE_WATER )
				CheckMenuItem ( GetMenu(g_qeglobals.d_hwndMain), ID_VIEW_SHOWWATER, MF_BYCOMMAND | MF_UNCHECKED );
			else
				CheckMenuItem ( GetMenu(g_qeglobals.d_hwndMain), ID_VIEW_SHOWWATER, MF_BYCOMMAND | MF_CHECKED );
			Sys_UpdateWindows (W_XY|W_CAMERA);
			break;

		case ID_VIEW_SHOWCLIP:
			if ( ( g_qeglobals.d_savedinfo.exclude ^= EXCLUDE_CLIP ) & EXCLUDE_CLIP )
				CheckMenuItem ( GetMenu(g_qeglobals.d_hwndMain), ID_VIEW_SHOWCLIP, MF_BYCOMMAND | MF_UNCHECKED );
			else
				CheckMenuItem ( GetMenu(g_qeglobals.d_hwndMain), ID_VIEW_SHOWCLIP, MF_BYCOMMAND | MF_CHECKED );
			Sys_UpdateWindows (W_XY|W_CAMERA);
			break;

		case ID_VIEW_SHOWDETAIL:
			if ( ( g_qeglobals.d_savedinfo.exclude ^= EXCLUDE_DETAIL ) & EXCLUDE_DETAIL )
			{
				CheckMenuItem ( GetMenu(g_qeglobals.d_hwndMain), ID_VIEW_SHOWDETAIL, MF_BYCOMMAND | MF_UNCHECKED );
				SetWindowText (g_qeglobals.d_hwndCamera, "Camera View (DETAIL EXCLUDED)");
			}
			else
			{
				CheckMenuItem ( GetMenu(g_qeglobals.d_hwndMain), ID_VIEW_SHOWDETAIL, MF_BYCOMMAND | MF_CHECKED );
				SetWindowText (g_qeglobals.d_hwndCamera, "Camera View");
			}
			Sys_UpdateWindows (W_XY|W_CAMERA);
			break;

		case ID_VIEW_SHOWWORLD:
			if ( ( g_qeglobals.d_savedinfo.exclude ^= EXCLUDE_WORLD ) & EXCLUDE_WORLD )
				CheckMenuItem ( GetMenu(g_qeglobals.d_hwndMain), ID_VIEW_SHOWWORLD, MF_BYCOMMAND | MF_UNCHECKED );
			else
				CheckMenuItem ( GetMenu(g_qeglobals.d_hwndMain), ID_VIEW_SHOWWORLD, MF_BYCOMMAND | MF_CHECKED );
			Sys_UpdateWindows (W_XY|W_CAMERA);
			break;


//
// grid menu
//
		case ID_GRID_1:
		case ID_GRID_2:
		case ID_GRID_4:
		case ID_GRID_8:
		case ID_GRID_16:
		case ID_GRID_32:
		case ID_GRID_64:
		{
			hMenu = GetMenu(hWnd);
			
			CheckMenuItem(hMenu, ID_GRID_1, MF_BYCOMMAND | MF_UNCHECKED);
			CheckMenuItem(hMenu, ID_GRID_2, MF_BYCOMMAND | MF_UNCHECKED);
			CheckMenuItem(hMenu, ID_GRID_4, MF_BYCOMMAND | MF_UNCHECKED);
			CheckMenuItem(hMenu, ID_GRID_8, MF_BYCOMMAND | MF_UNCHECKED);
			CheckMenuItem(hMenu, ID_GRID_16, MF_BYCOMMAND | MF_UNCHECKED);
			CheckMenuItem(hMenu, ID_GRID_32, MF_BYCOMMAND | MF_UNCHECKED);
			CheckMenuItem(hMenu, ID_GRID_64, MF_BYCOMMAND | MF_UNCHECKED);

			switch (LOWORD(wParam))
			{
				case ID_GRID_1: g_qeglobals.d_gridsize = 0; break;
				case ID_GRID_2: g_qeglobals.d_gridsize = 1; break;
				case ID_GRID_4: g_qeglobals.d_gridsize = 2; break;
				case ID_GRID_8: g_qeglobals.d_gridsize = 3; break;
				case ID_GRID_16: g_qeglobals.d_gridsize = 4; break;
				case ID_GRID_32: g_qeglobals.d_gridsize = 5; break;
				case ID_GRID_64: g_qeglobals.d_gridsize = 6; break;
			}
			g_qeglobals.d_gridsize = 1 << g_qeglobals.d_gridsize;

			CheckMenuItem(hMenu, LOWORD(wParam), MF_BYCOMMAND | MF_CHECKED);
			Sys_UpdateWindows (W_XY|W_Z);
			break;
		}

//
// texture menu
//
		case ID_VIEW_NEAREST:					
		case ID_VIEW_NEARESTMIPMAP:
		case ID_VIEW_LINEAR:
		case ID_VIEW_BILINEAR:
		case ID_VIEW_BILINEARMIPMAP:
		case ID_VIEW_TRILINEAR:
		case ID_TEXTURES_WIREFRAME:
		case ID_TEXTURES_FLATSHADE:
			Texture_SetMode (LOWORD(wParam));
			break;

		case ID_TEXTURES_SHOWINUSE:
			Sys_BeginWait ();
			Texture_ShowInuse ();
			SetInspectorMode(W_TEXTURE);
			break;

		case ID_TEXTURES_INSPECTOR:
			DoSurface ();
			break;

		case CMD_TEXTUREWAD:
		case CMD_TEXTUREWAD+1:
		case CMD_TEXTUREWAD+2:
		case CMD_TEXTUREWAD+3:
		case CMD_TEXTUREWAD+4:
		case CMD_TEXTUREWAD+5:
		case CMD_TEXTUREWAD+6:
		case CMD_TEXTUREWAD+7:
		case CMD_TEXTUREWAD+8:
		case CMD_TEXTUREWAD+9:
		case CMD_TEXTUREWAD+10:
		case CMD_TEXTUREWAD+11:
		case CMD_TEXTUREWAD+12:
		case CMD_TEXTUREWAD+13:
		case CMD_TEXTUREWAD+14:
		case CMD_TEXTUREWAD+15:
		case CMD_TEXTUREWAD+16:
		case CMD_TEXTUREWAD+17:
		case CMD_TEXTUREWAD+18:
		case CMD_TEXTUREWAD+19:
		case CMD_TEXTUREWAD+20:
		case CMD_TEXTUREWAD+21:
		case CMD_TEXTUREWAD+22:
		case CMD_TEXTUREWAD+23:
		case CMD_TEXTUREWAD+24:
		case CMD_TEXTUREWAD+25:
		case CMD_TEXTUREWAD+26:
		case CMD_TEXTUREWAD+27:
		case CMD_TEXTUREWAD+28:
		case CMD_TEXTUREWAD+29:
		case CMD_TEXTUREWAD+30:
		case CMD_TEXTUREWAD+31:
			Sys_BeginWait ();
			Texture_ShowDirectory (LOWORD(wParam));
			SetInspectorMode(W_TEXTURE);
			break;

//
// bsp menu
//
		case CMD_BSPCOMMAND:
		case CMD_BSPCOMMAND+1:
		case CMD_BSPCOMMAND+2:
		case CMD_BSPCOMMAND+3:
		case CMD_BSPCOMMAND+4:
		case CMD_BSPCOMMAND+5:
		case CMD_BSPCOMMAND+6:
		case CMD_BSPCOMMAND+7:
		case CMD_BSPCOMMAND+8:
		case CMD_BSPCOMMAND+9:
		case CMD_BSPCOMMAND+10:
		case CMD_BSPCOMMAND+11:
		case CMD_BSPCOMMAND+12:
		case CMD_BSPCOMMAND+13:
		case CMD_BSPCOMMAND+14:
		case CMD_BSPCOMMAND+15:
		case CMD_BSPCOMMAND+16:
		case CMD_BSPCOMMAND+17:
		case CMD_BSPCOMMAND+18:
		case CMD_BSPCOMMAND+19:
		case CMD_BSPCOMMAND+20:
		case CMD_BSPCOMMAND+21:
		case CMD_BSPCOMMAND+22:
		case CMD_BSPCOMMAND+23:
		case CMD_BSPCOMMAND+24:
		case CMD_BSPCOMMAND+25:
		case CMD_BSPCOMMAND+26:
		case CMD_BSPCOMMAND+27:
		case CMD_BSPCOMMAND+28:
		case CMD_BSPCOMMAND+29:
		case CMD_BSPCOMMAND+30:
		case CMD_BSPCOMMAND+31:
			{
				extern	char	*bsp_commands[256];

				RunBsp (bsp_commands[LOWORD(wParam-CMD_BSPCOMMAND)]);
			}
			break;

//
// misc menu
//
		case ID_MISC_BENCHMARK:
			SendMessage ( g_qeglobals.d_hwndCamera,
			WM_USER+267,	0, 0);
			break;

		case ID_TEXTUREBK:
			DoColor(COLOR_TEXTUREBACK);
			Sys_UpdateWindows (W_ALL);
			break;

		case ID_MISC_SELECTENTITYCOLOR:
			{
				extern int inspector_mode;
				
				if ( ( inspector_mode == W_ENTITY ) && DoColor(COLOR_ENTITY) == true )
				{
					extern void AddProp( void );
					
					char buffer[100];
					
					sprintf( buffer, "%f %f %f", g_qeglobals.d_savedinfo.colors[COLOR_ENTITY][0],
						g_qeglobals.d_savedinfo.colors[COLOR_ENTITY][1],
						g_qeglobals.d_savedinfo.colors[COLOR_ENTITY][2] );
					
					SetWindowText( hwndEnt[EntValueField], buffer );
					SetWindowText( hwndEnt[EntKeyField], "_color" );
					AddProp();
				}
				Sys_UpdateWindows( W_ALL );
			}
			break;

		case ID_MISC_PRINTXY:
			WXY_Print();
			break;

		case ID_COLORS_XYBK:
			DoColor(COLOR_GRIDBACK);
			Sys_UpdateWindows (W_ALL);
			break;

		case ID_COLORS_MAJOR:
			DoColor(COLOR_GRIDMAJOR);
			Sys_UpdateWindows (W_ALL);
			break;

		case ID_COLORS_MINOR:
			DoColor(COLOR_GRIDMINOR);
			Sys_UpdateWindows (W_ALL);
			break;

		case ID_MISC_GAMMA:
			DoGamma();
			break;

		case ID_MISC_FINDBRUSH:
			DoFind();
			break;

		case ID_MISC_NEXTLEAKSPOT:
			Pointfile_Next();
			break;
		case ID_MISC_PREVIOUSLEAKSPOT:
			Pointfile_Prev();
			break;

//
// brush menu
//
		case ID_BRUSH_3SIDED:
			Brush_MakeSided (3);
			break;
		case ID_BRUSH_4SIDED:
			Brush_MakeSided (4);
			break;
		case ID_BRUSH_5SIDED:
			Brush_MakeSided (5);
			break;
		case ID_BRUSH_6SIDED:
			Brush_MakeSided (6);
			break;
		case ID_BRUSH_7SIDED:
			Brush_MakeSided (7);
			break;
		case ID_BRUSH_8SIDED:
			Brush_MakeSided (8);
			break;
		case ID_BRUSH_9SIDED:
			Brush_MakeSided (9);
			break;
		case ID_BRUSH_ARBITRARYSIDED:
			DoSides ();
			break;

//
// select menu
//
		case ID_BRUSH_FLIPX:
			Select_FlipAxis (0);
			break;
		case ID_BRUSH_FLIPY:
			Select_FlipAxis (1);
			break;
		case ID_BRUSH_FLIPZ:
			Select_FlipAxis (2);
			break;
		case ID_BRUSH_ROTATEX:
			Select_RotateAxis (0, 90);
			break;
		case ID_BRUSH_ROTATEY:
			Select_RotateAxis (1, 90);
			break;
		case ID_BRUSH_ROTATEZ:
			Select_RotateAxis (2, 90);
			break;

		case ID_SELECTION_ARBITRARYROTATION:
			DoRotate ();
			break;

		case ID_SELECTION_UNGROUPENTITY:
			Select_Ungroup ();
			break;

		case ID_SELECTION_CONNECT:
			ConnectEntities ();
			break;

		case ID_SELECTION_DRAGVERTECIES:
			if (g_qeglobals.d_select_mode == sel_vertex)
			{
				g_qeglobals.d_select_mode = sel_brush;
				Sys_UpdateWindows (W_ALL);
			}
			else
			{
				SetupVertexSelection ();
				if (g_qeglobals.d_numpoints)
					g_qeglobals.d_select_mode = sel_vertex;
			}
			break;
		case ID_SELECTION_DRAGEDGES:
			if (g_qeglobals.d_select_mode == sel_edge)
			{
				g_qeglobals.d_select_mode = sel_brush;
				Sys_UpdateWindows (W_ALL);
			}
			else
			{
				SetupVertexSelection ();
				if (g_qeglobals.d_numpoints)
					g_qeglobals.d_select_mode = sel_edge;
			}
			break;

		case ID_SELECTION_SELECTPARTIALTALL:
			Select_PartialTall ();
			break;
		case ID_SELECTION_SELECTCOMPLETETALL:
			Select_CompleteTall ();
			break;
		case ID_SELECTION_SELECTTOUCHING:
			Select_Touching ();
			break;
		case ID_SELECTION_SELECTINSIDE:
			Select_Inside ();
			break;
		case ID_SELECTION_CSGSUBTRACT:
			CSG_Subtract ();
			break;
		case ID_SELECTION_MAKEHOLLOW:
			CSG_MakeHollow ();
			break;

		case ID_SELECTION_CLONE:
			Select_Clone ();
			break;
		case ID_SELECTION_DELETE:
			Select_Delete ();
			break;
		case ID_SELECTION_DESELECT:
			Select_Deselect ();
			break;

		case ID_SELECTION_MAKE_DETAIL:
			Select_MakeDetail ();
			break;
		case ID_SELECTION_MAKE_STRUCTURAL:
			Select_MakeStructural ();
			break;


//
// region menu
//
		case ID_REGION_OFF:
			Map_RegionOff ();
			break;
		case ID_REGION_SETXY:
			Map_RegionXY ();
			break;
		case ID_REGION_SETTALLBRUSH:
			Map_RegionTallBrush ();
			break;
		case ID_REGION_SETBRUSH:
			Map_RegionBrush ();
			break;
		case ID_REGION_SETSELECTION:
			Map_RegionSelectedBrushes ();
			break;

		case IDMRU+1:
		case IDMRU+2:
		case IDMRU+3:
		case IDMRU+4:
		case IDMRU+5:
		case IDMRU+6:
		case IDMRU+7:
		case IDMRU+8:
		case IDMRU+9:
			DoMru(hWnd,LOWORD(wParam));
			break;

//
// help menu
//

		case ID_HELP_ABOUT:
			DoAbout();
			break;

		default:
            return FALSE;
    }

    return TRUE;
}