WIN_QE3.CPP 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. #include "stdafx.h"
  19. #include "qe3.h"
  20. #include "mru.h"
  21. #include "PrefsDlg.h"
  22. ////////////////////////////////////////////////////////////////////////////
  23. // BSP frontend plugin
  24. // global flag for BSP frontend plugin is g_qeglobals.bBSPFrontendPlugin
  25. _QERPlugBSPFrontendTable g_BSPFrontendTable;
  26. CStringArray g_BSPFrontendCommands;
  27. extern CEdit* g_pEdit;
  28. int screen_width;
  29. int screen_height;
  30. qboolean have_quit;
  31. int update_bits;
  32. HANDLE bsp_process;
  33. //===========================================
  34. void Sys_MarkMapModified (void)
  35. {
  36. char title[1024];
  37. if (modified != 1)
  38. {
  39. modified = true; // mark the map as changed
  40. sprintf (title, "%s *", currentmap);
  41. QE_ConvertDOSToUnixName( title, title );
  42. Sys_SetTitle (title);
  43. }
  44. }
  45. void Sys_SetTitle (char *text)
  46. {
  47. SetWindowText (g_qeglobals.d_hwndMain, text);
  48. }
  49. HCURSOR waitcursor;
  50. void Sys_BeginWait (void)
  51. {
  52. waitcursor = SetCursor (LoadCursor (NULL, IDC_WAIT));
  53. }
  54. void Sys_EndWait (void)
  55. {
  56. if (waitcursor)
  57. {
  58. SetCursor (waitcursor);
  59. waitcursor = NULL;
  60. }
  61. }
  62. void Sys_GetCursorPos (int *x, int *y)
  63. {
  64. POINT lpPoint;
  65. GetCursorPos (&lpPoint);
  66. *x = lpPoint.x;
  67. *y = lpPoint.y;
  68. }
  69. void Sys_SetCursorPos (int x, int y)
  70. {
  71. SetCursorPos (x, y);
  72. }
  73. void Sys_Beep (void)
  74. {
  75. MessageBeep (MB_ICONASTERISK);
  76. }
  77. char *TranslateString (char *buf)
  78. {
  79. static char buf2[32768];
  80. int i, l;
  81. char *out;
  82. l = strlen(buf);
  83. out = buf2;
  84. for (i=0 ; i<l ; i++)
  85. {
  86. if (buf[i] == '\n')
  87. {
  88. *out++ = '\r';
  89. *out++ = '\n';
  90. }
  91. else
  92. *out++ = buf[i];
  93. }
  94. *out++ = 0;
  95. return buf2;
  96. }
  97. void Sys_ClearPrintf (void)
  98. {
  99. char text[4];
  100. text[0] = 0;
  101. SendMessage (g_qeglobals.d_hwndEdit, WM_SETTEXT, 0, (LPARAM)text);
  102. }
  103. #define SCROLLBACK_MAX_LINES 600
  104. #define SCROLLBACK_DEL_CHARS 500
  105. void Sys_Printf (char *text, ...)
  106. {
  107. va_list argptr;
  108. char buf[32768];
  109. char *out;
  110. LRESULT result; // PGM
  111. DWORD oldPosS, oldPosE; // PGM
  112. va_start (argptr,text);
  113. vsprintf (buf, text,argptr);
  114. va_end (argptr);
  115. out = TranslateString (buf);
  116. #ifdef LATER
  117. Sys_Status(out);
  118. #else
  119. //PGM
  120. result = SendMessage (g_qeglobals.d_hwndEdit, EM_GETLINECOUNT, 0, 0);
  121. if(result > SCROLLBACK_MAX_LINES)
  122. {
  123. char replaceText[5];
  124. replaceText[0] = '\0';
  125. SendMessage (g_qeglobals.d_hwndEdit, WM_SETREDRAW, (WPARAM)0, (LPARAM)0);
  126. SendMessage (g_qeglobals.d_hwndEdit, EM_GETSEL, (WPARAM)&oldPosS, (LPARAM)&oldPosE);
  127. SendMessage (g_qeglobals.d_hwndEdit, EM_SETSEL, 0, SCROLLBACK_DEL_CHARS);
  128. SendMessage (g_qeglobals.d_hwndEdit, EM_REPLACESEL, (WPARAM)0, (LPARAM)replaceText);
  129. SendMessage (g_qeglobals.d_hwndEdit, EM_SETSEL, oldPosS, oldPosE);
  130. SendMessage (g_qeglobals.d_hwndEdit, WM_SETREDRAW, (WPARAM)1, (LPARAM)0);
  131. }
  132. //PGM
  133. SendMessage (g_qeglobals.d_hwndEdit, EM_REPLACESEL, 0, (LPARAM)out);
  134. #endif
  135. }
  136. double Sys_DoubleTime (void)
  137. {
  138. return clock()/ 1000.0;
  139. }
  140. void PrintPixels (HDC hDC)
  141. {
  142. int i;
  143. PIXELFORMATDESCRIPTOR p[64];
  144. printf ("### flags color layer\n");
  145. for (i=1 ; i<64 ; i++)
  146. {
  147. if (!DescribePixelFormat ( hDC, i, sizeof(p[0]), &p[i]))
  148. break;
  149. printf ("%3i %5i %5i %5i\n", i,
  150. p[i].dwFlags,
  151. p[i].cColorBits,
  152. p[i].bReserved);
  153. }
  154. printf ("%i modes\n", i-1);
  155. }
  156. //==========================================================================
  157. void QEW_StopGL( HWND hWnd, HGLRC hGLRC, HDC hDC )
  158. {
  159. qwglMakeCurrent( NULL, NULL );
  160. qwglDeleteContext( hGLRC );
  161. ReleaseDC( hWnd, hDC );
  162. }
  163. int WINAPI QEW_SetupPixelFormat(HDC hDC, qboolean zbuffer )
  164. {
  165. static PIXELFORMATDESCRIPTOR pfd = {
  166. sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
  167. 1, // version number
  168. PFD_DRAW_TO_WINDOW | // support window
  169. PFD_SUPPORT_OPENGL | // support OpenGL
  170. PFD_DOUBLEBUFFER, // double buffered
  171. PFD_TYPE_RGBA, // RGBA type
  172. 24, // 24-bit color depth
  173. 0, 0, 0, 0, 0, 0, // color bits ignored
  174. 0, // no alpha buffer
  175. 0, // shift bit ignored
  176. 0, // no accumulation buffer
  177. 0, 0, 0, 0, // accum bits ignored
  178. 32, // depth bits
  179. 0, // no stencil buffer
  180. 0, // no auxiliary buffer
  181. PFD_MAIN_PLANE, // main layer
  182. 0, // reserved
  183. 0, 0, 0 // layer masks ignored
  184. }; //
  185. int pixelformat = 0;
  186. zbuffer = true;
  187. if ( !zbuffer )
  188. pfd.cDepthBits = 0;
  189. if (g_PrefsDlg.m_bSGIOpenGL)
  190. {
  191. if ( (pixelformat = qwglChoosePixelFormat(hDC, &pfd)) == 0 )
  192. {
  193. printf("%d",GetLastError());
  194. Error ("ChoosePixelFormat failed");
  195. }
  196. if (!qwglSetPixelFormat(hDC, pixelformat, &pfd))
  197. Error ("SetPixelFormat failed");
  198. }
  199. else
  200. {
  201. if ( (pixelformat = ChoosePixelFormat(hDC, &pfd)) == 0 )
  202. {
  203. printf("%d",GetLastError());
  204. Error ("ChoosePixelFormat failed");
  205. }
  206. if (!SetPixelFormat(hDC, pixelformat, &pfd))
  207. Error ("SetPixelFormat failed");
  208. }
  209. return pixelformat;
  210. }
  211. /*
  212. =================
  213. Error
  214. For abnormal program terminations
  215. =================
  216. */
  217. void Error (char *error, ...)
  218. {
  219. va_list argptr;
  220. char text[1024];
  221. char text2[1024];
  222. int err;
  223. err = GetLastError ();
  224. int i = qglGetError();
  225. va_start (argptr,error);
  226. vsprintf (text, error,argptr);
  227. va_end (argptr);
  228. sprintf (text2, "%s\nGetLastError() = %i - %i\nAn unrecoverable error has occured. Would you like to edit Preferences before exiting Q3Radiant?", text, err, i);
  229. if (MessageBox(g_qeglobals.d_hwndMain, text2, "Error", MB_YESNO) == IDYES)
  230. {
  231. g_PrefsDlg.LoadPrefs();
  232. g_PrefsDlg.DoModal();
  233. }
  234. exit (1);
  235. }
  236. void Warning (char *error, ...)
  237. {
  238. va_list argptr;
  239. char text[1024];
  240. int err;
  241. err = GetLastError ();
  242. int i = qglGetError();
  243. va_start (argptr,error);
  244. vsprintf (text, error,argptr);
  245. va_end (argptr);
  246. Sys_Printf(text);
  247. }
  248. /*
  249. ======================================================================
  250. FILE DIALOGS
  251. ======================================================================
  252. */
  253. qboolean ConfirmModified (void)
  254. {
  255. if (!modified)
  256. return true;
  257. if (MessageBox (g_qeglobals.d_hwndMain, "This will lose changes to the map"
  258. , "warning", MB_OKCANCEL) == IDCANCEL)
  259. return false;
  260. return true;
  261. }
  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. "Map file (*.map, *.reg)\0*.map\0*.reg\0\0";
  268. static char szProjectFilter[260] = /* filter string */
  269. "Q3Radiant project (*.qe4, *.prj)\0*.qe4\0*.prj\0\0";
  270. static char chReplace; /* string separator for szFilter */
  271. static int i, cbString; /* integer count variables */
  272. static HANDLE hf; /* file handle */
  273. void OpenDialog (void)
  274. {
  275. /*
  276. * Obtain the system directory name and
  277. * store it in szDirName.
  278. */
  279. strcpy (szDirName, ValueForKey (g_qeglobals.d_project_entity, "mapspath") );
  280. if (strlen(szDirName) == 0)
  281. {
  282. strcpy (szDirName, ValueForKey (g_qeglobals.d_project_entity, "basepath") );
  283. strcat (szDirName, "\\maps");
  284. }
  285. /* Place the terminating null character in the szFile. */
  286. szFile[0] = '\0';
  287. /* Set the members of the OPENFILENAME structure. */
  288. ofn.lStructSize = sizeof(OPENFILENAME);
  289. ofn.hwndOwner = g_qeglobals.d_hwndCamera;
  290. ofn.lpstrFilter = szFilter;
  291. ofn.nFilterIndex = 1;
  292. ofn.lpstrFile = szFile;
  293. ofn.nMaxFile = sizeof(szFile);
  294. ofn.lpstrFileTitle = szFileTitle;
  295. ofn.nMaxFileTitle = sizeof(szFileTitle);
  296. ofn.lpstrInitialDir = szDirName;
  297. ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST |
  298. OFN_FILEMUSTEXIST;
  299. /* Display the Open dialog box. */
  300. if (!GetOpenFileName(&ofn))
  301. return; // canceled
  302. // Add the file in MRU.
  303. //FIXME
  304. AddNewItem( g_qeglobals.d_lpMruMenu, ofn.lpstrFile);
  305. // Refresh the File menu.
  306. //FIXME
  307. PlaceMenuMRUItem(g_qeglobals.d_lpMruMenu,GetSubMenu(GetMenu(g_qeglobals.d_hwndMain),0),
  308. ID_FILE_EXIT);
  309. /* Open the file. */
  310. Map_LoadFile (ofn.lpstrFile);
  311. }
  312. void ProjectDialog (void)
  313. {
  314. /*
  315. * Obtain the system directory name and
  316. * store it in szDirName.
  317. */
  318. strcpy (szDirName, ValueForKey(g_qeglobals.d_project_entity, "basepath") );
  319. strcat (szDirName, "\\scripts");
  320. /* Place the terminating null character in the szFile. */
  321. szFile[0] = '\0';
  322. /* Set the members of the OPENFILENAME structure. */
  323. ofn.lStructSize = sizeof(OPENFILENAME);
  324. ofn.hwndOwner = g_qeglobals.d_hwndCamera;
  325. ofn.lpstrFilter = szProjectFilter;
  326. ofn.nFilterIndex = 1;
  327. ofn.lpstrFile = szFile;
  328. ofn.nMaxFile = sizeof(szFile);
  329. ofn.lpstrFileTitle = szFileTitle;
  330. ofn.nMaxFileTitle = sizeof(szFileTitle);
  331. ofn.lpstrInitialDir = szDirName;
  332. ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST |
  333. OFN_FILEMUSTEXIST;
  334. /* Display the Open dialog box. */
  335. if (!GetOpenFileName(&ofn))
  336. return; // canceled
  337. // Refresh the File menu.
  338. PlaceMenuMRUItem(g_qeglobals.d_lpMruMenu,GetSubMenu(GetMenu(g_qeglobals.d_hwndMain),0),
  339. ID_FILE_EXIT);
  340. /* Open the file. */
  341. if (!QE_LoadProject(ofn.lpstrFile))
  342. Error ("Couldn't load project file");
  343. }
  344. extern void AddSlash(CString& strPath);
  345. void SaveAsDialog (bool bRegion)
  346. {
  347. strcpy (szDirName, ValueForKey (g_qeglobals.d_project_entity, "basepath") );
  348. CString strPath = szDirName;
  349. AddSlash(strPath);
  350. strPath += "maps";
  351. /* Place the terminating null character in the szFile. */
  352. szFile[0] = '\0';
  353. /* Set the members of the OPENFILENAME structure. */
  354. ofn.lStructSize = sizeof(OPENFILENAME);
  355. ofn.hwndOwner = g_qeglobals.d_hwndCamera;
  356. ofn.lpstrFilter = szFilter;
  357. ofn.nFilterIndex = 1;
  358. ofn.lpstrFile = szFile;
  359. ofn.nMaxFile = sizeof(szFile);
  360. ofn.lpstrFileTitle = szFileTitle;
  361. ofn.nMaxFileTitle = sizeof(szFileTitle);
  362. ofn.lpstrInitialDir = strPath;
  363. ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST |
  364. OFN_FILEMUSTEXIST | OFN_OVERWRITEPROMPT;
  365. /* Display the Open dialog box. */
  366. if (!GetSaveFileName(&ofn))
  367. return; // canceled
  368. if (bRegion)
  369. DefaultExtension (ofn.lpstrFile, ".reg");
  370. else
  371. DefaultExtension (ofn.lpstrFile, ".map");
  372. if (!bRegion)
  373. {
  374. strcpy (currentmap, ofn.lpstrFile);
  375. AddNewItem(g_qeglobals.d_lpMruMenu, ofn.lpstrFile);
  376. PlaceMenuMRUItem(g_qeglobals.d_lpMruMenu,GetSubMenu(GetMenu(g_qeglobals.d_hwndMain),0), ID_FILE_EXIT);
  377. }
  378. Map_SaveFile (ofn.lpstrFile, bRegion); // ignore region
  379. }
  380. /*
  381. =======================================================
  382. Menu modifications
  383. =======================================================
  384. */
  385. /*
  386. ==================
  387. FillBSPMenu
  388. ==================
  389. */
  390. char *bsp_commands[256];
  391. void FillBSPMenu (void)
  392. {
  393. HMENU hmenu;
  394. epair_t *ep;
  395. int i;
  396. static int count;
  397. hmenu = GetSubMenu (GetMenu(g_qeglobals.d_hwndMain), MENU_BSP);
  398. for (i=0 ; i<count ; i++)
  399. DeleteMenu (hmenu, CMD_BSPCOMMAND+i, MF_BYCOMMAND);
  400. count = 0;
  401. if ( g_qeglobals.bBSPFrontendPlugin )
  402. {
  403. CString str = g_BSPFrontendTable.m_pfnGetBSPMenu();
  404. char cTemp[1024];
  405. strcpy(cTemp, str);
  406. char* token = strtok(cTemp, ",;");
  407. if (token && *token == ' ')
  408. {
  409. while (*token == ' ')
  410. token++;
  411. }
  412. i = 0;
  413. // first token is menu name
  414. ModifyMenu( GetMenu(g_qeglobals.d_hwndMain), MENU_BSP, MF_BYPOSITION, MENU_BSP, (LPCTSTR)token );
  415. // redraw the menu bar
  416. DrawMenuBar( g_qeglobals.d_hwndMain );
  417. token = strtok(NULL, ",;");
  418. while (token != NULL)
  419. {
  420. g_BSPFrontendCommands.Add(token);
  421. AppendMenu (hmenu, MF_ENABLED|MF_STRING, CMD_BSPCOMMAND+i, (LPCTSTR)token );
  422. token = strtok(NULL, ",;");
  423. i++;
  424. }
  425. count = i;
  426. }
  427. else
  428. {
  429. i = 0;
  430. for (ep = g_qeglobals.d_project_entity->epairs ; ep ; ep=ep->next)
  431. {
  432. if (ep->key[0] == 'b' && ep->key[1] == 's' && ep->key[2] == 'p')
  433. {
  434. bsp_commands[i] = ep->key;
  435. AppendMenu (hmenu, MF_ENABLED|MF_STRING,
  436. CMD_BSPCOMMAND+i, (LPCTSTR)ep->key);
  437. i++;
  438. }
  439. }
  440. count = i;
  441. }
  442. }
  443. //==============================================
  444. void AddSlash(CString& strPath)
  445. {
  446. if (strPath.GetLength() > 0)
  447. {
  448. if (strPath.GetAt(strPath.GetLength()-1) != '\\')
  449. strPath += '\\';
  450. }
  451. }
  452. bool ExtractPath_and_Filename(const char* pPath, CString& strPath, CString& strFilename)
  453. {
  454. CString strPathName = pPath;
  455. int nSlash = strPathName.ReverseFind('\\');
  456. if (nSlash >= 0)
  457. {
  458. strPath = strPathName.Left(nSlash+1);
  459. strFilename = strPathName.Right(strPathName.GetLength() - nSlash - 1);
  460. }
  461. else strFilename = pPath;
  462. return true;
  463. }
  464. /*
  465. ===============
  466. CheckBspProcess
  467. See if the BSP is done yet
  468. ===============
  469. */
  470. extern void FindReplace(CString& strContents, const char* pTag, const char* pValue);
  471. extern CTime g_tBegin;
  472. void CheckBspProcess (void)
  473. {
  474. char outputpath[1024];
  475. char temppath[512];
  476. DWORD exitcode;
  477. char *out;
  478. BOOL ret;
  479. if (!bsp_process)
  480. return;
  481. ret = GetExitCodeProcess (bsp_process, &exitcode);
  482. if (!ret)
  483. Error ("GetExitCodeProcess failed");
  484. if (exitcode == STILL_ACTIVE)
  485. return;
  486. bsp_process = 0;
  487. GetTempPath(512, temppath);
  488. sprintf (outputpath, "%sjunk.txt", temppath);
  489. LoadFile (outputpath, (void **)&out);
  490. Sys_Printf ("%s", out);
  491. Sys_Printf ("\ncompleted.\n");
  492. free (out);
  493. CTime tEnd = CTime::GetCurrentTime();
  494. CTimeSpan tElapsed = tEnd - g_tBegin;
  495. CString strElapsed;
  496. strElapsed.Format("Run time was %i hours, %i minutes and %i seconds", tElapsed.GetHours(), tElapsed.GetMinutes(), tElapsed.GetSeconds());
  497. Sys_Printf(strElapsed.GetBuffer(0));
  498. Sys_Beep ();
  499. Pointfile_Check();
  500. // run game if no PointFile and pref is set
  501. //++timo needs to stop after BSP if leaked .. does run through vis and light instead ..
  502. if (g_PrefsDlg.m_bRunQuake == TRUE && !g_qeglobals.d_pointfile_display_list)
  503. {
  504. char cCurDir[1024];
  505. GetCurrentDirectory(1024, cCurDir);
  506. CString strExePath = g_PrefsDlg.m_strQuake2;
  507. CString strOrgPath;
  508. CString strOrgFile;
  509. ExtractPath_and_Filename(currentmap, strOrgPath, strOrgFile);
  510. if (g_PrefsDlg.m_bSetGame == TRUE) // run in place with set game.. don't copy map
  511. {
  512. CString strBasePath = ValueForKey(g_qeglobals.d_project_entity, "basepath");
  513. strExePath += " +set game ";
  514. strExePath += strBasePath;
  515. WinExec(strExePath, SW_SHOW);
  516. }
  517. else
  518. {
  519. CString strCopyPath = strExePath;
  520. char* pBuffer = strCopyPath.GetBufferSetLength(_MAX_PATH + 1);
  521. pBuffer[strCopyPath.ReverseFind('\\') + 1] = '\0';
  522. strCopyPath.ReleaseBuffer();
  523. SetCurrentDirectory(strCopyPath);
  524. CString strOrgPath;
  525. CString strOrgFile;
  526. ExtractPath_and_Filename(currentmap, strOrgPath, strOrgFile);
  527. AddSlash(strCopyPath);
  528. FindReplace(strOrgFile, ".map", ".bsp");
  529. //++timo modified for Quake3 !!
  530. strCopyPath += "baseq3\\maps\\";
  531. strCopyPath += strOrgFile;
  532. AddSlash(strOrgPath);
  533. strOrgPath += strOrgFile;
  534. bool bRun = (strOrgPath.CompareNoCase(strCopyPath) == 0);
  535. if (!bRun)
  536. bRun = (CopyFile(strOrgPath, strCopyPath, FALSE) == TRUE);
  537. if (bRun)
  538. {
  539. FindReplace(strOrgFile, ".bsp", "");
  540. strExePath += " +map ";
  541. strExePath += strOrgFile;
  542. WinExec(strExePath, SW_SHOW);
  543. }
  544. }
  545. SetCurrentDirectory(cCurDir);
  546. }
  547. }
  548. extern int cambuttonstate;
  549. extern "C" {
  550. void *Com_Allocate( int bytes ) {
  551. return malloc(bytes);
  552. }
  553. void Com_Dealloc( void *ptr ) {
  554. free(ptr);
  555. }
  556. void Com_Printf( const char *msg, ... ) {
  557. va_list argptr;
  558. char buf[32768];
  559. char *out;
  560. va_start (argptr,msg);
  561. vsprintf (buf, msg,argptr);
  562. va_end (argptr);
  563. out = TranslateString (buf);
  564. Sys_Printf(buf);
  565. }
  566. void Com_Error( int level, const char *error, ... ) {
  567. va_list argptr;
  568. char buf[32768];
  569. char *out;
  570. va_start (argptr,error);
  571. vsprintf (buf, error,argptr);
  572. va_end (argptr);
  573. out = TranslateString (buf);
  574. Sys_Printf(buf);
  575. }
  576. void Com_DPrintf( const char *msg, ... ) {
  577. return;
  578. }
  579. int FS_Write( const void *buffer, int len, fileHandle_t h ) {
  580. SafeWrite(reinterpret_cast<FILE*>(h), buffer, len);
  581. return len;
  582. }
  583. int FS_ReadFile( const char *qpath, void **buffer ) {
  584. CString strPath = ValueForKey(g_qeglobals.d_project_entity, "basepath");
  585. AddSlash(strPath);
  586. strPath += qpath;
  587. return LoadFile(strPath, buffer);
  588. }
  589. void FS_FreeFile( void *buffer ) {
  590. Com_Dealloc(buffer);
  591. }
  592. fileHandle_t FS_FOpenFileWrite( const char *filename ) {
  593. CString strPath = ValueForKey(g_qeglobals.d_project_entity, "basepath");
  594. AddSlash(strPath);
  595. strPath += filename;
  596. // bad casting ptr to int
  597. return reinterpret_cast<fileHandle_t>(SafeOpenWrite(strPath));
  598. }
  599. void FS_FCloseFile( fileHandle_t f ) {
  600. fclose(reinterpret_cast<FILE*>(f));
  601. }
  602. }