Utils.cpp 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /////////////////////////////////////////////////////////////////////////////
  19. //
  20. // Utils.CPP
  21. //
  22. // Module containing usefull misc. utility functions
  23. //
  24. #include "stdafx.h"
  25. #include "mainfrm.h"
  26. #include "leveleditdoc.h"
  27. #include "leveleditview.h"
  28. #include "leveledit.h"
  29. #include "utils.h"
  30. #include "outputform.h"
  31. #include "sceneeditor.h"
  32. #include "nodemgr.h"
  33. #include "node.h"
  34. #include "groupmgr.h"
  35. #include "updatingdbdialog.h"
  36. #include "icons.h"
  37. #include "regkeys.h"
  38. #include "presetmgr.h"
  39. #include "HLod.h"
  40. #include "AABox.h"
  41. #include "definition.h"
  42. #include "verchk.h"
  43. #include "editorsaveload.h"
  44. #include "generatingvisdialog.h"
  45. #include "boxrobj.h"
  46. #include "definitionfactory.h"
  47. #include "definitionfactorymgr.h"
  48. #include "nodecategories.h"
  49. #include "conversationpage.h"
  50. ////////////////////////////////////////////////////////////////////////////
  51. //
  52. // Get_Current_Document
  53. //
  54. ////////////////////////////////////////////////////////////////////////////
  55. CLevelEditDoc *
  56. Get_Current_Document (void)
  57. {
  58. // Assume failure
  59. CLevelEditDoc *pdoc = NULL;
  60. // Get a pointer to the main window
  61. CMainFrame *pmainwnd = (CMainFrame *)theApp.GetMainWnd ();
  62. // Did we successfully get a pointer to the main window?
  63. if (pmainwnd != NULL) {
  64. // Use the main window pointer to get a pointer
  65. // to the current doc.
  66. //pdoc = (CLevelEditDoc *)pmainwnd->GetActiveDocument ();
  67. pdoc = pmainwnd->Get_Current_Document ();
  68. ASSERT (pdoc);
  69. }
  70. // Return the doc pointer
  71. return pdoc;
  72. }
  73. ////////////////////////////////////////////////////////////////////////////
  74. //
  75. // Get_Node_Mgr
  76. //
  77. ////////////////////////////////////////////////////////////////////////////
  78. NodeMgrClass &
  79. Get_Node_Mgr (void)
  80. {
  81. // Return the node manager pointer
  82. return _TheNodeMgr;
  83. }
  84. ////////////////////////////////////////////////////////////////////////////
  85. //
  86. // Get_Scene_Editor
  87. //
  88. ////////////////////////////////////////////////////////////////////////////
  89. SceneEditorClass *
  90. Get_Scene_Editor (void)
  91. {
  92. SceneEditorClass *peditor = NULL;
  93. CLevelEditDoc *pdoc = ::Get_Current_Document ();
  94. // Were we successful in getting the document pointer?
  95. ASSERT (pdoc != NULL);
  96. if (pdoc != NULL) {
  97. // Get a pointer to the editor
  98. peditor = pdoc->Get_Scene ();
  99. }
  100. // Return the editor pointer
  101. return peditor;
  102. }
  103. ////////////////////////////////////////////////////////////////////////////
  104. //
  105. // Get_Camera_Mgr
  106. //
  107. ////////////////////////////////////////////////////////////////////////////
  108. CameraMgr *
  109. Get_Camera_Mgr (void)
  110. {
  111. CameraMgr *pcameramgr = NULL;
  112. // Get a pointer to the current view
  113. CLevelEditView *pview = ::Get_Main_View ();
  114. // Were we successful in getting the view pointer?
  115. ASSERT (pview != NULL);
  116. if (pview != NULL) {
  117. // Get a pointer to the camera maanager
  118. pcameramgr = pview->Get_Camera_Mgr ();
  119. }
  120. // Return the camera manager pointer
  121. return pcameramgr;
  122. }
  123. ////////////////////////////////////////////////////////////////////////////
  124. //
  125. // Get_Mouse_Mgr
  126. //
  127. ////////////////////////////////////////////////////////////////////////////
  128. MouseMgrClass *
  129. Get_Mouse_Mgr (void)
  130. {
  131. MouseMgrClass *pmousemgr = NULL;
  132. // Get a pointer to the current view
  133. CLevelEditView *pview = ::Get_Main_View ();
  134. // Were we successful in getting the view pointer?
  135. ASSERT (pview != NULL);
  136. if (pview != NULL) {
  137. // Get a pointer to the mouse maanager
  138. pmousemgr = pview->Get_Mouse_Mgr ();
  139. }
  140. // Return the mouse manager pointer
  141. return pmousemgr;
  142. }
  143. ////////////////////////////////////////////////////////////////////////////
  144. //
  145. // Get_Selection_Mgr
  146. //
  147. ////////////////////////////////////////////////////////////////////////////
  148. SelectionMgrClass &
  149. Get_Selection_Mgr (void)
  150. {
  151. // Return the selction manager pointer
  152. return ::Get_Scene_Editor ()->Get_Selection_Mgr ();
  153. }
  154. ////////////////////////////////////////////////////////////////////////////
  155. //
  156. // Get_Main_View
  157. //
  158. ////////////////////////////////////////////////////////////////////////////
  159. CLevelEditView *
  160. Get_Main_View (void)
  161. {
  162. // Assume failure
  163. CLevelEditView *pview = NULL;
  164. // Get a pointer to the main window
  165. CMainFrame *pmainwnd = (CMainFrame *)theApp.GetMainWnd ();
  166. // Did we successfully get a pointer to the main window?
  167. ASSERT (pmainwnd != NULL);
  168. if (pmainwnd != NULL) {
  169. // Use the main window pointer to get a pointer
  170. // to the current view.
  171. pview = (CLevelEditView *)pmainwnd->GetActiveView ();
  172. ASSERT (pview != NULL);
  173. }
  174. // Return the view pointer
  175. return pview;
  176. }
  177. ////////////////////////////////////////////////////////////////////////////
  178. //
  179. // Get_File_Mgr
  180. //
  181. ////////////////////////////////////////////////////////////////////////////
  182. FileMgrClass *
  183. Get_File_Mgr (void)
  184. {
  185. FileMgrClass *pfilemgr = NULL;
  186. // Get a pointer to the current document
  187. CLevelEditDoc *pdoc = ::Get_Current_Document ();
  188. // Were we successful in getting the document pointer?
  189. ASSERT (pdoc != NULL);
  190. if (pdoc != NULL) {
  191. // Get a pointer to the file maanager
  192. pfilemgr = pdoc->Get_File_Mgr ();
  193. }
  194. // Return the file manager pointer
  195. return pfilemgr;
  196. }
  197. ////////////////////////////////////////////////////////////////////////////
  198. //
  199. // Refresh_Main_View
  200. //
  201. ////////////////////////////////////////////////////////////////////////////
  202. void
  203. Refresh_Main_View (void)
  204. {
  205. // Force the view to repaint itself,
  206. // but only if auto updating is turned off
  207. CLevelEditView *pview = Get_Main_View ();
  208. if ((pview != NULL) &&
  209. (pview->Is_Updating () == false) &&
  210. ::IsWindow (pview->m_hWnd)) {
  211. pview->Repaint_View ();
  212. pview->Repaint_View ();
  213. }
  214. return ;
  215. }
  216. /////////////////////////////////////////////////////////////
  217. //
  218. // Paint_Gradient
  219. //
  220. ////////////////////////////////////////////////////////////////////////////
  221. void
  222. Paint_Gradient
  223. (
  224. HWND hwnd,
  225. BYTE base_red,
  226. BYTE base_green,
  227. BYTE base_blue
  228. )
  229. {
  230. // Get the bounding rectangle so we know how much to paint
  231. RECT rect;
  232. ::GetClientRect (hwnd, &rect);
  233. // Determine the width, height, and width per each shade
  234. int width = rect.right-rect.left;
  235. int height = rect.bottom-rect.top;
  236. float width_per_shade = ((float)width) / 256.00F;
  237. // Pull a hack to get the CDC for the window
  238. HDC hdc = ::GetDC (hwnd);
  239. CDC cdc;
  240. cdc.Attach (hdc);
  241. // Loop through each shade and paint its sliver
  242. float posx = 0.00F;
  243. for (int shade = 0; shade < 256; shade ++) {
  244. // Paint this sliver
  245. cdc.FillSolidRect ((int)posx,
  246. 0,
  247. (width_per_shade >= 1.00F) ? (int)width_per_shade : 1,
  248. height,
  249. RGB (shade*base_red, shade*base_green, shade*base_blue));
  250. // Increment the current position
  251. posx += width_per_shade;
  252. }
  253. // Release the DC
  254. cdc.Detach ();
  255. ::ReleaseDC (hwnd, hdc);
  256. // Validate the contents of the window so the control won't paint itself
  257. ::ValidateRect (hwnd, NULL);
  258. return ;
  259. }
  260. ////////////////////////////////////////////////////////////////////////////
  261. //
  262. // Get_Startup_Directory
  263. //
  264. ////////////////////////////////////////////////////////////////////////////
  265. CString
  266. Get_Startup_Directory (void)
  267. {
  268. TCHAR path[MAX_PATH];
  269. ::GetModuleFileName (NULL, path, sizeof (path));
  270. LPTSTR filename = ::strrchr (path, '\\');
  271. if (filename)
  272. {
  273. // Strip ff the filename
  274. filename[0] = 0;
  275. }
  276. // Return the path to the caller
  277. return CString (path);
  278. }
  279. ////////////////////////////////////////////////////////////////////////////
  280. //
  281. // Get_Data_Directory
  282. //
  283. ////////////////////////////////////////////////////////////////////////////
  284. CString
  285. Get_Data_Directory (void)
  286. {
  287. // Get the path we were run from
  288. CString path = ::Get_Startup_Directory ();
  289. // Concat the 'data' subdir onto that path
  290. path += "\\Data";
  291. // Return the path to the caller
  292. return path;
  293. }
  294. ////////////////////////////////////////////////////////////////////////////
  295. //
  296. // Get_Filename_From_Path
  297. //
  298. ////////////////////////////////////////////////////////////////////////////
  299. CString
  300. Get_Filename_From_Path (LPCTSTR path)
  301. {
  302. // Find the last occurance of the directory deliminator
  303. LPCTSTR filename = ::strrchr (path, '\\');
  304. if (filename != NULL) {
  305. // Increment past the directory deliminator
  306. filename ++;
  307. } else {
  308. filename = path;
  309. }
  310. // Return the filename part of the path
  311. return CString (filename);
  312. }
  313. ////////////////////////////////////////////////////////////////////////////
  314. //
  315. // Strip_Filename_From_Path
  316. //
  317. ////////////////////////////////////////////////////////////////////////////
  318. CString
  319. Strip_Filename_From_Path (LPCTSTR path)
  320. {
  321. // Copy the path to a buffer we can modify
  322. TCHAR temp_path[MAX_PATH];
  323. ::lstrcpy (temp_path, path);
  324. // Find the last occurance of the directory deliminator
  325. LPTSTR filename = ::strrchr (temp_path, '\\');
  326. if (filename != NULL) {
  327. // Strip off the filename
  328. filename[0] = 0;
  329. } else if ((temp_path[1] != ':') && (temp_path[1] != '\\')) {
  330. temp_path[0] = 0;
  331. }
  332. // Return the path only
  333. return CString (temp_path);
  334. }
  335. ////////////////////////////////////////////////////////////////////////////
  336. //
  337. // Get_Subdir_From_Full_Path
  338. //
  339. ////////////////////////////////////////////////////////////////////////////
  340. CString
  341. Get_Subdir_From_Full_Path (LPCTSTR path)
  342. {
  343. int last_delim = 0;
  344. int prev_delim = 0;
  345. for (int index = 0; path[index] != 0; index++) {
  346. if (path[index] == '\\') {
  347. prev_delim = last_delim;
  348. last_delim = index + 1;
  349. }
  350. }
  351. // Return the sub-dir name
  352. CString sub_dir = &path[prev_delim];
  353. sub_dir = sub_dir.Left ((last_delim-prev_delim)-1);
  354. return sub_dir;
  355. }
  356. ////////////////////////////////////////////////////////////////////////////
  357. //
  358. // Get_Subdir_And_Filename_From_Path
  359. //
  360. ////////////////////////////////////////////////////////////////////////////
  361. CString
  362. Get_Subdir_And_Filename_From_Path (LPCTSTR path)
  363. {
  364. int last_delim = 0;
  365. int prev_delim = 0;
  366. for (int index = 0; path[index] != 0; index++) {
  367. if (path[index] == '\\') {
  368. prev_delim = last_delim;
  369. last_delim = index + 1;
  370. }
  371. }
  372. // Return the sub-dir and filename
  373. CString sub_dir = &path[prev_delim];
  374. return sub_dir;
  375. }
  376. ////////////////////////////////////////////////////////////////////////////
  377. //
  378. // Up_One_Directory
  379. //
  380. ////////////////////////////////////////////////////////////////////////////
  381. CString
  382. Up_One_Directory (LPCTSTR path)
  383. {
  384. // Copy the path to a buffer we can modify
  385. TCHAR local_copy[MAX_PATH];
  386. ::lstrcpy (local_copy, path);
  387. // Strip off the last subdir in the path
  388. LPTSTR plast_dir = ::strrchr (local_copy, '\\');
  389. if (plast_dir != NULL) {
  390. plast_dir[0] = 0;
  391. }
  392. // Return the new path
  393. return CString (local_copy);
  394. }
  395. ////////////////////////////////////////////////////////////////////////////
  396. //
  397. // Get_File_Size
  398. //
  399. ////////////////////////////////////////////////////////////////////////////
  400. DWORD
  401. Get_File_Size (LPCTSTR path)
  402. {
  403. DWORD file_size = 0L;
  404. ASSERT (path != NULL);
  405. if (path != NULL) {
  406. // Attempt to open the file
  407. HANDLE hfile = ::CreateFile (path,
  408. 0,
  409. 0,
  410. NULL,
  411. OPEN_EXISTING,
  412. 0L,
  413. NULL);
  414. ASSERT (hfile != INVALID_HANDLE_VALUE);
  415. if (hfile != INVALID_HANDLE_VALUE) {
  416. // Get the size in bytes of the file and return it
  417. // to the caller.
  418. file_size = ::GetFileSize (hfile, NULL);
  419. // Close the file
  420. ::CloseHandle (hfile);
  421. hfile = INVALID_HANDLE_VALUE;
  422. }
  423. }
  424. // Return the size in bytes of the file to the caller.
  425. return file_size;
  426. }
  427. ////////////////////////////////////////////////////////////////////////////
  428. //
  429. // Output_Message
  430. //
  431. ////////////////////////////////////////////////////////////////////////////
  432. void
  433. Output_Message (LPCTSTR message)
  434. {
  435. // Get a pointer to the main window
  436. CMainFrame *pmainwnd = (CMainFrame *)theApp.GetMainWnd ();
  437. // Did we successfully get a pointer to the main window?
  438. ASSERT (pmainwnd != NULL);
  439. if (pmainwnd != NULL) {
  440. FormToolbarClass &toolbar = pmainwnd->Get_Output_Toolbar ();
  441. // Get a pointer to the output window
  442. OutputFormClass *form = (OutputFormClass *)toolbar.Get_Form ();
  443. // Print the message to the window
  444. if ((form != NULL) && IsWindow (form->m_hWnd)) {
  445. form->Output_Message (message);
  446. }
  447. }
  448. TRACE (message);
  449. return ;
  450. }
  451. ////////////////////////////////////////////////////////////////////////////
  452. //
  453. // Is_Path_Relative
  454. //
  455. ////////////////////////////////////////////////////////////////////////////
  456. bool
  457. Is_Path_Relative (LPCTSTR path)
  458. {
  459. bool relative = false;
  460. // Param valid?
  461. ASSERT (path != NULL);
  462. if (path != NULL && path[0] != 0) {
  463. // Check for drive designation
  464. relative = bool(path[1] != ':');
  465. // Check for network path
  466. relative &= bool((path[0] != '\\') && (path[1] != '\\'));
  467. }
  468. // Return the true/false result code
  469. return relative;
  470. }
  471. ////////////////////////////////////////////////////////////////////////////
  472. //
  473. // Find_File
  474. //
  475. ////////////////////////////////////////////////////////////////////////////
  476. bool
  477. Find_File
  478. (
  479. LPCTSTR filename,
  480. LPCTSTR start_dir,
  481. CString &full_path
  482. )
  483. {
  484. bool bfound = false;
  485. // Params valid?
  486. ASSERT (filename != NULL);
  487. ASSERT (start_dir != NULL);
  488. if ((filename != NULL) && (start_dir != NULL)) {
  489. // Make sure the current directory name doesn't end in a
  490. // directory delimiter.
  491. CString current_dir = start_dir;
  492. if (current_dir[::lstrlen (current_dir)-1] == '\\') {
  493. current_dir = current_dir.Left (::lstrlen (current_dir)-1);
  494. }
  495. // Is the file in this directory?
  496. CString dir_test = current_dir + CString ("\\") + filename;
  497. if (::GetFileAttributes (dir_test) != 0xFFFFFFFF) {
  498. // Found it!
  499. bfound = true;
  500. full_path = dir_test;
  501. } else {
  502. WIN32_FIND_DATA find_info = { 0 };
  503. BOOL bcontinue = true;
  504. CString search_mask = current_dir + "\\*.*";
  505. // Loop through all the files in the current directory
  506. for (HANDLE hfilefind = ::FindFirstFile (search_mask, &find_info);
  507. (hfilefind != INVALID_HANDLE_VALUE) && bcontinue && !bfound;
  508. bcontinue = ::FindNextFile (hfilefind, &find_info)) {
  509. // Is this 'file' a subdir of the current directory?
  510. if ((find_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
  511. (find_info.cFileName[0] != '.')) {
  512. // Build the full path of this sub-dir name
  513. CString sub_dir_path = current_dir + CString ("\\") + find_info.cFileName;
  514. // Recursively call this find function for that subdir
  515. bfound = Find_File (filename, sub_dir_path, full_path);
  516. }
  517. }
  518. // Close the handle we needed for the file find routines
  519. if (hfilefind != INVALID_HANDLE_VALUE) {
  520. ::FindClose (hfilefind);
  521. }
  522. }
  523. }
  524. // Return the true/false result code
  525. return bfound;
  526. }
  527. ////////////////////////////////////////////////////////////////////////////
  528. //
  529. // Quick_Compare_Files
  530. //
  531. ////////////////////////////////////////////////////////////////////////////
  532. int
  533. Quick_Compare_Files
  534. (
  535. LPCTSTR file1,
  536. LPCTSTR file2
  537. )
  538. {
  539. // Assume they are the same
  540. int icompare = 0;
  541. // Params OK?
  542. ASSERT (file1 != NULL);
  543. ASSERT (file2 != NULL);
  544. if ((file1 != NULL) && (file2 != NULL)) {
  545. // Attempt to open file1
  546. HANDLE hfile1 = ::CreateFile (file1,
  547. 0,
  548. 0,
  549. NULL,
  550. OPEN_EXISTING,
  551. 0L,
  552. NULL);
  553. // Attempt to open file2
  554. HANDLE hfile2 = ::CreateFile (file2,
  555. 0,
  556. 0,
  557. NULL,
  558. OPEN_EXISTING,
  559. 0L,
  560. NULL);
  561. if ((hfile1 != INVALID_HANDLE_VALUE) && (hfile2 != INVALID_HANDLE_VALUE)) {
  562. // Get information about these 2 files.
  563. BY_HANDLE_FILE_INFORMATION file1_info = { 0 };
  564. BY_HANDLE_FILE_INFORMATION file2_info = { 0 };
  565. ::GetFileInformationByHandle (hfile1, &file1_info);
  566. ::GetFileInformationByHandle (hfile2, &file2_info);
  567. // Compare the time these files were last written to
  568. icompare = ::CompareFileTime (&file1_info.ftLastWriteTime, &file2_info.ftLastWriteTime);
  569. } else if ((hfile1 == INVALID_HANDLE_VALUE) && (hfile2 != INVALID_HANDLE_VALUE)) {
  570. icompare = -1;
  571. } else if ((hfile1 != INVALID_HANDLE_VALUE) && (hfile2 == INVALID_HANDLE_VALUE)) {
  572. icompare = 1;
  573. }
  574. if (hfile1 != INVALID_HANDLE_VALUE) {
  575. ::CloseHandle (hfile1);
  576. }
  577. if (hfile2 != INVALID_HANDLE_VALUE) {
  578. ::CloseHandle (hfile2);
  579. }
  580. }
  581. // Same as strcmp, -1 if file1 is older than file2, 0 if equal, 1 if file1 is newer than file2
  582. return icompare;
  583. }
  584. ////////////////////////////////////////////////////////////////////////////
  585. //
  586. // Build_List_From_String
  587. //
  588. ////////////////////////////////////////////////////////////////////////////
  589. int
  590. Build_List_From_String
  591. (
  592. LPCTSTR buffer,
  593. LPCTSTR delimiter,
  594. CString **pstring_list
  595. )
  596. {
  597. // Start with zero list entries
  598. int count = 0;
  599. ASSERT (buffer != NULL);
  600. ASSERT (delimiter != NULL);
  601. ASSERT (pstring_list != NULL);
  602. if ((buffer != NULL) &&
  603. (delimiter != NULL) &&
  604. (pstring_list != NULL)) {
  605. int delim_len = ::strlen (delimiter);
  606. // Determine how many entries there will be in the list
  607. for (LPCTSTR entry = buffer;
  608. (entry != NULL) && (entry[1] != 0);
  609. entry = ::strstr (entry, delimiter)) {
  610. // Move past the current delimiter (if necessary)
  611. if ((::strnicmp (entry, delimiter, delim_len) == 0) && (count > 0)) {
  612. entry += delim_len;
  613. }
  614. // Increment the count of entries
  615. count ++;
  616. }
  617. if (count > 0) {
  618. // Allocate enough CString objects to hold all the strings in the list
  619. (*pstring_list) = new CString[count];
  620. // Parse the string and pull out its entries.
  621. count = 0;
  622. for (entry = buffer;
  623. (entry != NULL) && (entry[1] != 0);
  624. entry = ::strstr (entry, delimiter)) {
  625. // Move past the current delimiter (if necessary)
  626. if ((::strnicmp (entry, delimiter, delim_len) == 0) && (count > 0)) {
  627. entry += delim_len;
  628. }
  629. // Copy this entry into its own string
  630. CString entry_string = entry;
  631. int delim_index = entry_string.Find (delimiter);
  632. entry_string = (delim_index >= 0) ? entry_string.Left (delim_index) : entry_string;
  633. //
  634. // Add this entry to our list (even if its an empty string)
  635. //
  636. (*pstring_list)[count++] = entry_string;
  637. }
  638. } else if (delim_len > 0) {
  639. count = 1;
  640. (*pstring_list) = new CString[count];
  641. (*pstring_list)[0] = buffer;
  642. }
  643. }
  644. // Return the number of entries in our list
  645. return count;
  646. }
  647. ////////////////////////////////////////////////////////////////////////////
  648. //
  649. // Build_String_From_List
  650. //
  651. ////////////////////////////////////////////////////////////////////////////
  652. CString
  653. Build_String_From_List
  654. (
  655. const CString *pstring_list,
  656. int count,
  657. LPCTSTR delimiter
  658. )
  659. {
  660. // Start an empty string
  661. CString composite_string;
  662. ASSERT (delimiter != NULL);
  663. ASSERT (pstring_list != NULL);
  664. if ((delimiter != NULL) &&
  665. (pstring_list != NULL)) {
  666. // Loop through all the entries in our list and add them
  667. // to the composite string
  668. for (int entry_index = 0; entry_index < count; entry_index ++) {
  669. composite_string += pstring_list[entry_index] + CString (delimiter);
  670. }
  671. }
  672. // Return the composite string
  673. return composite_string;
  674. }
  675. ////////////////////////////////////////////////////////////////////////////
  676. //
  677. // Constrain_Point_To_Aspect_Ratio
  678. //
  679. ////////////////////////////////////////////////////////////////////////////
  680. void
  681. Constrain_Point_To_Aspect_Ratio
  682. (
  683. float &xpos,
  684. float &ypos
  685. )
  686. {
  687. // Get the aspect ratios for the x and y axis
  688. float xaspect = ::Get_Main_View ()->Get_Cursor_Aspect_RatioX ();
  689. float yaspect = ::Get_Main_View ()->Get_Cursor_Aspect_RatioY ();
  690. // Convert the 'window' point to a full screen point.
  691. xpos *= xaspect;
  692. ypos *= yaspect;
  693. return ;
  694. }
  695. ////////////////////////////////////////////////////////////////////////////
  696. //
  697. // Asset_Name_From_Filename
  698. //
  699. ////////////////////////////////////////////////////////////////////////////
  700. CString
  701. Asset_Name_From_Filename (LPCTSTR filename)
  702. {
  703. // Get the filename from this path
  704. CString asset_name = ::Get_Filename_From_Path (filename);
  705. // Find the index of the extension (if exists)
  706. int extension = asset_name.ReverseFind ('.');
  707. // Strip off the extension
  708. if (extension != -1) {
  709. asset_name = asset_name.Left (extension);
  710. }
  711. // Return the name of the asset
  712. return asset_name;
  713. }
  714. ////////////////////////////////////////////////////////////////////////////
  715. //
  716. // Filename_From_Asset_Name
  717. //
  718. CString
  719. Filename_From_Asset_Name (LPCTSTR asset_name)
  720. {
  721. // The filename is simply the asset name plus the .w3d extension
  722. CString filename = asset_name + CString (".w3d");
  723. // Return the filename
  724. return filename;
  725. }
  726. ////////////////////////////////////////////////////////////////////////////
  727. //
  728. // Message_Box
  729. //
  730. ////////////////////////////////////////////////////////////////////////////
  731. UINT
  732. Message_Box
  733. (
  734. HWND hparentwnd,
  735. UINT message_id,
  736. UINT title_id,
  737. UINT style
  738. )
  739. {
  740. UINT ret_code = IDOK;
  741. if (Is_Silent_Mode () == false) {
  742. // Load the message from the strings table
  743. CString message;
  744. CString title;
  745. message.LoadString (message_id);
  746. title.LoadString (title_id);
  747. // Show the message box to the user and return the user's response
  748. ret_code = ::MessageBox (hparentwnd, message, title, style);
  749. }
  750. return ret_code;
  751. }
  752. ////////////////////////////////////////////////////////////////////////////
  753. //
  754. // Rotate_Matrix
  755. //
  756. ////////////////////////////////////////////////////////////////////////////
  757. void
  758. Rotate_Matrix
  759. (
  760. const Matrix3D &input_mat,
  761. const Matrix3D &rotation_mat,
  762. const Matrix3D &coord_system,
  763. Matrix3D *poutput_mat
  764. )
  765. {
  766. /*
  767. ** Translate this node in the specified coordinate system
  768. */
  769. Matrix3D coord_inv; // inverse of coordinate transform
  770. Matrix3D coord_to_obj; // transform from coord to object
  771. coord_system.Get_Orthogonal_Inverse (coord_inv);
  772. Matrix3D::Multiply (coord_inv, input_mat, &coord_to_obj);
  773. Matrix3D::Multiply (coord_system, rotation_mat, poutput_mat);
  774. Matrix3D::Multiply (*poutput_mat, coord_to_obj, poutput_mat);
  775. if (!poutput_mat->Is_Orthogonal ()) {
  776. poutput_mat->Re_Orthogonalize ();
  777. TRACE ("Matrix wasn't orthogonal.\n");
  778. }
  779. return ;
  780. }
  781. ////////////////////////////////////////////////////////////////////////////
  782. //
  783. // Get_LOD_File_Count
  784. //
  785. ////////////////////////////////////////////////////////////////////////////
  786. int
  787. Get_LOD_File_Count
  788. (
  789. LPCTSTR first_lod_filename,
  790. CString *pbase_filename
  791. )
  792. {
  793. CString base_filename = first_lod_filename;
  794. int lod_count = 0;
  795. if ((base_filename.GetLength () > 6) &&
  796. ::strcmpi (&first_lod_filename[::lstrlen (first_lod_filename)-6], "L1.W3D") == 0) {
  797. base_filename = base_filename.Left (base_filename.GetLength () - 6);
  798. // Loop through the files in the directory and count up the ones that
  799. // match our LOD-syntax for this object
  800. bool bfound = true;
  801. int lod_index = 1;
  802. while (bfound) {
  803. CString lod_filename;
  804. lod_filename.Format ("%sL%d.w3d", (LPCTSTR)base_filename, lod_index);
  805. lod_index ++;
  806. bfound = (::GetFileAttributes (lod_filename) != 0xFFFFFFFF);
  807. if (bfound) {
  808. lod_count ++;
  809. }
  810. }
  811. }
  812. if (pbase_filename != NULL) {
  813. *pbase_filename = base_filename;
  814. }
  815. // Return the count of LODs we found
  816. return lod_count;
  817. }
  818. ////////////////////////////////////////////////////////////////////////////
  819. //
  820. // Browse_For_Folder
  821. //
  822. ////////////////////////////////////////////////////////////////////////////
  823. bool
  824. Browse_For_Folder
  825. (
  826. CString &folder,
  827. HWND hparentwnd,
  828. LPCTSTR default_path,
  829. LPCTSTR title,
  830. UINT flags
  831. )
  832. {
  833. bool retval = false;
  834. // Browse for the folder
  835. BROWSEINFO browse_info = { 0 };
  836. browse_info.hwndOwner = hparentwnd;
  837. browse_info.lpszTitle = title;
  838. browse_info.ulFlags = flags;
  839. LPITEMIDLIST pidl = ::SHBrowseForFolder (&browse_info);
  840. if (pidl != NULL) {
  841. // Convert the 'PIDL' into a string
  842. char path[MAX_PATH];
  843. retval = (::SHGetPathFromIDList (pidl, path) == TRUE);
  844. if (retval) {
  845. folder = path;
  846. }
  847. // Fre the 'PIDL'
  848. LPMALLOC pmalloc = NULL;
  849. if (SUCCEEDED (::SHGetMalloc (&pmalloc))) {
  850. pmalloc->Free (pidl);
  851. COM_RELEASE (pmalloc);
  852. }
  853. }
  854. // Return the true/false result code
  855. return retval;
  856. }
  857. ////////////////////////////////////////////////////////////////////////////
  858. //
  859. // General_Pump_Messages
  860. //
  861. ////////////////////////////////////////////////////////////////////////////
  862. void
  863. General_Pump_Messages (void)
  864. {
  865. // Process any paint messages currently pending in the queue
  866. MSG msg = { 0 };
  867. while (::PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) {
  868. ::DispatchMessage (&msg);
  869. }
  870. return ;
  871. }
  872. ////////////////////////////////////////////////////////////////////////////
  873. //
  874. // Pump_Messages
  875. //
  876. ////////////////////////////////////////////////////////////////////////////
  877. void
  878. Pump_Messages (void)
  879. {
  880. // Process any paint messages currently pending in the queue
  881. MSG msg = { 0 };
  882. while (::PeekMessage (&msg, NULL, WM_PAINT, WM_PAINT, PM_REMOVE) ||
  883. ::PeekMessage (&msg, NULL, WM_NCPAINT, WM_NCPAINT, PM_REMOVE) ||
  884. ::PeekMessage (&msg, NULL, WM_ERASEBKGND, WM_ERASEBKGND, PM_REMOVE) ||
  885. ::PeekMessage (&msg, NULL, WM_SYNCPAINT, WM_SYNCPAINT, PM_REMOVE)) {
  886. ::DispatchMessage (&msg);
  887. }
  888. return ;
  889. }
  890. typedef struct
  891. {
  892. LPVOID ThreadProc;
  893. DWORD dwparam1;
  894. DWORD dwparam2;
  895. DWORD dwparam3;
  896. HRESULT *presult;
  897. HWND *phmain_wnd;
  898. HANDLE hevent;
  899. } THREAD_PARAMS;
  900. ////////////////////////////////////////////////////////////////////////////
  901. //
  902. // fnWorkerThread
  903. //
  904. ////////////////////////////////////////////////////////////////////////////
  905. UINT
  906. fnWorkerThread (LPVOID pParam)
  907. {
  908. THREAD_PARAMS *pthread_params = (THREAD_PARAMS *)pParam;
  909. if (pthread_params != NULL) {
  910. // Call the user function
  911. MY_THREADPROC thread_proc = (MY_THREADPROC)pthread_params->ThreadProc;
  912. (thread_proc) (pthread_params->dwparam1,
  913. pthread_params->dwparam2,
  914. pthread_params->dwparam3,
  915. pthread_params->presult);
  916. // Free the thread params
  917. SAFE_DELETE (pthread_params);
  918. }
  919. return 1;
  920. }
  921. ////////////////////////////////////////////////////////////////////////////
  922. //
  923. // Create_Worker_Thread
  924. //
  925. ////////////////////////////////////////////////////////////////////////////
  926. void
  927. Create_Worker_Thread
  928. (
  929. MY_THREADPROC fnthread_proc,
  930. DWORD dwparam1,
  931. DWORD dwparam2,
  932. DWORD dwparam3,
  933. HRESULT *presult
  934. )
  935. {
  936. // Create a structure we can pass to the thread proc
  937. THREAD_PARAMS *pthread_params = new THREAD_PARAMS;
  938. pthread_params->ThreadProc = (LPVOID)fnthread_proc;
  939. pthread_params->dwparam1 = dwparam1;
  940. pthread_params->dwparam2 = dwparam2;
  941. pthread_params->dwparam3 = dwparam3;
  942. pthread_params->presult = presult;
  943. pthread_params->phmain_wnd = NULL;
  944. pthread_params->hevent = NULL;
  945. // Kick off our own thread proc
  946. ::AfxBeginThread (fnWorkerThread, (LPVOID)pthread_params);
  947. return ;
  948. }
  949. ////////////////////////////////////////////////////////////////////////////
  950. //
  951. // fnUIThread
  952. //
  953. ////////////////////////////////////////////////////////////////////////////
  954. UINT
  955. fnUIThread (LPVOID pParam)
  956. {
  957. THREAD_PARAMS *pthread_params = (THREAD_PARAMS *)pParam;
  958. if (pthread_params != NULL) {
  959. // Call the user function
  960. MY_UITHREADPROC thread_proc = (MY_UITHREADPROC)pthread_params->ThreadProc;
  961. (thread_proc) (pthread_params->dwparam1,
  962. pthread_params->dwparam2,
  963. pthread_params->dwparam3,
  964. pthread_params->presult,
  965. pthread_params->phmain_wnd);
  966. // Let the calling thread return
  967. ::SetEvent (pthread_params->hevent);
  968. // Now pump messages until its time to quit the thread
  969. MSG msg = { 0 };
  970. while (::GetMessage (&msg, NULL, 0, 0) > 0) {
  971. ::TranslateMessage (&msg);
  972. ::DispatchMessage (&msg);
  973. }
  974. // Free the thread params
  975. SAFE_DELETE (pthread_params);
  976. }
  977. return 1;
  978. }
  979. ////////////////////////////////////////////////////////////////////////////
  980. //
  981. // Create_UI_Thread
  982. //
  983. ////////////////////////////////////////////////////////////////////////////
  984. void
  985. Create_UI_Thread
  986. (
  987. MY_UITHREADPROC fnthread_proc,
  988. DWORD dwparam1,
  989. DWORD dwparam2,
  990. DWORD dwparam3,
  991. HRESULT *presult,
  992. HWND *phmain_wnd
  993. )
  994. {
  995. // Create a structure we can pass to the thread proc
  996. THREAD_PARAMS *pthread_params = new THREAD_PARAMS;
  997. pthread_params->ThreadProc = (LPVOID)fnthread_proc;
  998. pthread_params->dwparam1 = dwparam1;
  999. pthread_params->dwparam2 = dwparam2;
  1000. pthread_params->dwparam3 = dwparam3;
  1001. pthread_params->presult = presult;
  1002. pthread_params->phmain_wnd = phmain_wnd;;
  1003. pthread_params->hevent = ::CreateEvent (NULL, FALSE, FALSE, NULL);
  1004. // Kick off our own thread proc
  1005. ::AfxBeginThread (fnUIThread, (LPVOID)pthread_params);
  1006. // Now pump messages until the thread has initialized
  1007. while (::MsgWaitForMultipleObjects (1,
  1008. &(pthread_params->hevent),
  1009. FALSE,
  1010. INFINITE,
  1011. QS_ALLINPUT | QS_ALLEVENTS | QS_ALLPOSTMESSAGE) != WAIT_OBJECT_0) {
  1012. // Dispatch all messages in the queue
  1013. MSG msg = { 0 };
  1014. while (::PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) {
  1015. ::TranslateMessage (&msg);
  1016. ::DispatchMessage (&msg);
  1017. }
  1018. }
  1019. // Make sure we close the event handle
  1020. ::CloseHandle (pthread_params->hevent);
  1021. return ;
  1022. }
  1023. ////////////////////////////////////////////////////////////////////////////
  1024. //
  1025. // Update_Frame_Count
  1026. //
  1027. ////////////////////////////////////////////////////////////////////////////
  1028. void
  1029. Update_Frame_Count
  1030. (
  1031. int frame,
  1032. int max_frames
  1033. )
  1034. {
  1035. // Get a pointer to the main window
  1036. CMainFrame *pmainwnd = (CMainFrame *)theApp.GetMainWnd ();
  1037. // Did we successfully get a pointer to the main window?
  1038. ASSERT (pmainwnd != NULL);
  1039. if (pmainwnd != NULL) {
  1040. pmainwnd->Update_Ani_Frame (frame, max_frames);
  1041. }
  1042. return ;
  1043. }
  1044. ////////////////////////////////////////////////////////////////////////////
  1045. //
  1046. // SetDlgItemFloat
  1047. //
  1048. ////////////////////////////////////////////////////////////////////////////
  1049. void
  1050. SetDlgItemFloat
  1051. (
  1052. HWND hdlg,
  1053. UINT child_id,
  1054. float value
  1055. )
  1056. {
  1057. // Convert the float to a string
  1058. CString text;
  1059. text.Format ("%.3f", value);
  1060. // Pass the string onto the dialog control
  1061. ::SetDlgItemText (hdlg, child_id, text);
  1062. return ;
  1063. }
  1064. ////////////////////////////////////////////////////////////////////////////
  1065. //
  1066. // SetWindowFloat
  1067. //
  1068. ////////////////////////////////////////////////////////////////////////////
  1069. void
  1070. SetWindowFloat (HWND hwnd, float value)
  1071. {
  1072. // Convert the float to a string
  1073. CString text;
  1074. text.Format ("%.3f", value);
  1075. // Pass the string onto the window
  1076. ::SetWindowText (hwnd, text);
  1077. return ;
  1078. }
  1079. ////////////////////////////////////////////////////////////////////////////
  1080. //
  1081. // GetWindowFloat
  1082. //
  1083. ////////////////////////////////////////////////////////////////////////////
  1084. float
  1085. GetWindowFloat (HWND hwnd, bool interpret)
  1086. {
  1087. // Get the string from the window
  1088. TCHAR string_value[20];
  1089. ::GetWindowText (hwnd, string_value, sizeof (string_value));
  1090. //
  1091. // Convert the string to a float and return the value
  1092. //
  1093. float value = 0;
  1094. if (interpret) {
  1095. value = ((float)::atol (string_value)) / 100.0F;
  1096. } else {
  1097. value = ::atof (string_value);
  1098. }
  1099. return value;
  1100. }
  1101. ////////////////////////////////////////////////////////////////////////////
  1102. //
  1103. // GetDlgItemFloat
  1104. //
  1105. ////////////////////////////////////////////////////////////////////////////
  1106. float
  1107. GetDlgItemFloat
  1108. (
  1109. HWND hdlg,
  1110. UINT child_id,
  1111. bool interpret
  1112. )
  1113. {
  1114. // Get the string from the window
  1115. TCHAR string_value[20];
  1116. ::GetDlgItemText (hdlg, child_id, string_value, sizeof (string_value));
  1117. //
  1118. // Convert the string to a float and return the value
  1119. //
  1120. float value = 0;
  1121. if (interpret) {
  1122. value = ((float)::atol (string_value)) / 100.0F;
  1123. } else {
  1124. value = ::atof (string_value);
  1125. }
  1126. return value;
  1127. }
  1128. ////////////////////////////////////////////////////////////////////////////
  1129. //
  1130. // Get_Conversation_Form
  1131. //
  1132. ////////////////////////////////////////////////////////////////////////////
  1133. ConversationPageClass *
  1134. Get_Conversation_Form (void)
  1135. {
  1136. //
  1137. // Return the form pointer
  1138. //
  1139. return ConversationPageClass::Get_Instance ();
  1140. }
  1141. ////////////////////////////////////////////////////////////////////////////
  1142. //
  1143. // Get_Overlap_Form
  1144. //
  1145. ////////////////////////////////////////////////////////////////////////////
  1146. OverlapPageClass *
  1147. Get_Overlap_Form (void)
  1148. {
  1149. OverlapPageClass *form = NULL;
  1150. //
  1151. // Attempt to get a pointer to the form from the dialog bar
  1152. //
  1153. CMainFrame *main_wnd = (CMainFrame *)::AfxGetMainWnd ();
  1154. if (main_wnd != NULL) {
  1155. MainDialogBarClass &toolbar = main_wnd->Get_Main_Dialog_Bar ();
  1156. form = toolbar.Get_Overlap_Form ();
  1157. }
  1158. // Return the form pointer
  1159. return form;
  1160. }
  1161. ////////////////////////////////////////////////////////////////////////////
  1162. //
  1163. // Get_Instances_Form
  1164. //
  1165. ////////////////////////////////////////////////////////////////////////////
  1166. InstancesPageClass *
  1167. Get_Instances_Form (void)
  1168. {
  1169. InstancesPageClass *form = NULL;
  1170. //
  1171. // Attempt to get a pointer to the form from the dialog bar
  1172. //
  1173. CMainFrame *main_wnd = (CMainFrame *)::AfxGetMainWnd ();
  1174. if (main_wnd != NULL) {
  1175. MainDialogBarClass &toolbar = main_wnd->Get_Main_Dialog_Bar ();
  1176. form = toolbar.Get_Instances_Form ();
  1177. }
  1178. // Return the form pointer
  1179. return form;
  1180. }
  1181. ////////////////////////////////////////////////////////////////////////////
  1182. //
  1183. // Get_Global_Presets_Form
  1184. //
  1185. ////////////////////////////////////////////////////////////////////////////
  1186. PresetsFormClass *
  1187. Get_Presets_Form (void)
  1188. {
  1189. //
  1190. // Attempt to get a pointer to the form from the dialog bar
  1191. //
  1192. MainDialogBarClass &toolbar = ((CMainFrame *)::AfxGetMainWnd ())->Get_Main_Dialog_Bar ();
  1193. PresetsFormClass *form = toolbar.Get_Presets_Form ();
  1194. // Return the form pointer
  1195. return form;
  1196. }
  1197. ////////////////////////////////////////////////////////////////////////////
  1198. //
  1199. // Get_Global_Group_List
  1200. //
  1201. ////////////////////////////////////////////////////////////////////////////
  1202. GROUP_LIST &
  1203. Get_Global_Group_List (void)
  1204. {
  1205. // Return the list pointer
  1206. return ::Get_Scene_Editor ()->Get_Group_List ();
  1207. }
  1208. ////////////////////////////////////////////////////////////////////////////
  1209. //
  1210. // Fill_Node_Instance_Combo
  1211. //
  1212. ////////////////////////////////////////////////////////////////////////////
  1213. void
  1214. Fill_Node_Instance_Combo
  1215. (
  1216. HWND hcombobox,
  1217. NodeClass * default_node
  1218. )
  1219. {
  1220. // Loop through all the nodes in the level, and add them to the combobox
  1221. NodeMgrClass &node_mgr = ::Get_Node_Mgr ();
  1222. for (NodeClass *node = node_mgr.Get_First ();
  1223. node != NULL;
  1224. node = node_mgr.Get_Next (node)) {
  1225. // Add this node to the combobox
  1226. int index = ::SendMessage (hcombobox, CB_ADDSTRING, (WPARAM)0, (LPARAM)node->Get_Name ());
  1227. if (index != CB_ERR) {
  1228. ::SendMessage (hcombobox, CB_SETITEMDATA, (WPARAM)index, (LPARAM)node);
  1229. // If this is the default node, then select it...
  1230. if (node == default_node) {
  1231. ::SendMessage (hcombobox, CB_SETCURSEL, (WPARAM)index, 0L);
  1232. }
  1233. }
  1234. }
  1235. return ;
  1236. }
  1237. ////////////////////////////////////////////////////////////////////////////
  1238. //
  1239. // Fill_Group_Combo
  1240. //
  1241. ////////////////////////////////////////////////////////////////////////////
  1242. void
  1243. Fill_Group_Combo
  1244. (
  1245. HWND hcombobox,
  1246. GroupMgrClass *pdefault
  1247. )
  1248. {
  1249. // Loop through all the groups in the level, and add them to the combobox
  1250. GROUP_LIST &group_list = ::Get_Global_Group_List ();
  1251. for (int index = 0; index < group_list.Count (); index ++) {
  1252. GroupMgrClass *pgroup = group_list[index];
  1253. if (pgroup != NULL) {
  1254. // Add this group to the combobox
  1255. int index = ::SendMessage (hcombobox, CB_ADDSTRING, (WPARAM)0, (LPARAM)(LPCTSTR)pgroup->Get_Name ());
  1256. if (index != CB_ERR) {
  1257. ::SendMessage (hcombobox, CB_SETITEMDATA, (WPARAM)index, (LPARAM)pgroup);
  1258. // If this is the default group, then select it...
  1259. if (pgroup == pdefault) {
  1260. ::SendMessage (hcombobox, CB_SETCURSEL, (WPARAM)index, 0L);
  1261. }
  1262. }
  1263. }
  1264. }
  1265. return ;
  1266. }
  1267. ////////////////////////////////////////////////////////////////////////////
  1268. //
  1269. // Get_Ambient_Light_Form
  1270. //
  1271. ////////////////////////////////////////////////////////////////////////////
  1272. LightAmbientFormClass *
  1273. Get_Ambient_Light_Form (void)
  1274. {
  1275. // Attempt to get a pointer to the form from the library object
  1276. FormToolbarClass &toolbar = ((CMainFrame *)::AfxGetMainWnd ())->Get_Ambient_Light_Toolbar ();
  1277. LightAmbientFormClass *pform = (LightAmbientFormClass *)toolbar.Get_Form ();
  1278. // Return the form pointer
  1279. return pform;
  1280. }
  1281. ////////////////////////////////////////////////////////////////////////////
  1282. //
  1283. // Get_Global_Image_List
  1284. //
  1285. ////////////////////////////////////////////////////////////////////////////
  1286. CImageList *
  1287. Get_Global_Image_List (void)
  1288. {
  1289. // Return the imagelist pointer
  1290. return ((CMainFrame *)::AfxGetMainWnd ())->Get_Image_List ();
  1291. }
  1292. ////////////////////////////////////////////////////////////////////////////
  1293. //
  1294. // Copy_File
  1295. //
  1296. ////////////////////////////////////////////////////////////////////////////
  1297. bool
  1298. Copy_File
  1299. (
  1300. LPCTSTR existing_filename,
  1301. LPCTSTR new_filename,
  1302. bool bforce_copy
  1303. )
  1304. {
  1305. // Assume failure
  1306. bool retval = false;
  1307. ASSERT (existing_filename != NULL);
  1308. ASSERT (new_filename != NULL);
  1309. if ((existing_filename != NULL) &&
  1310. (new_filename != NULL)) {
  1311. // Make sure we aren't copying over ourselves
  1312. bool allow_copy = (::lstrcmpi (existing_filename, new_filename) != 0);
  1313. // Strip the readonly bit off if necessary
  1314. DWORD attributes = ::GetFileAttributes (new_filename);
  1315. if (allow_copy &&
  1316. (attributes != 0xFFFFFFFF) &&
  1317. ((attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY)) {
  1318. if (bforce_copy) {
  1319. ::SetFileAttributes (new_filename, attributes & (~FILE_ATTRIBUTE_READONLY));
  1320. } else {
  1321. allow_copy = false;
  1322. }
  1323. }
  1324. // Perform the copy operation!
  1325. if (allow_copy) {
  1326. retval = (::CopyFile (existing_filename, new_filename, FALSE) == TRUE);
  1327. }
  1328. }
  1329. // Return the true/false result code
  1330. return retval;
  1331. }
  1332. /////////////////////////////////////////////////////////////////////////////
  1333. //
  1334. // fnUpdatingVSSThread
  1335. //
  1336. ////////////////////////////////////////////////////////////////////////////
  1337. UINT
  1338. fnUpdatingVSSThread
  1339. (
  1340. DWORD dwparam1,
  1341. DWORD /*dwparam2*/,
  1342. DWORD /*dwparam3*/,
  1343. HRESULT* /*presult*/,
  1344. HWND* phmain_wnd
  1345. )
  1346. {
  1347. // Create a new instance of the 'updating' dialog
  1348. UpdatingDBDialogClass *pdialog = new UpdatingDBDialogClass ((HWND)dwparam1);
  1349. pdialog->ShowWindow (SW_SHOW);
  1350. // Return the window handle of the main wnd to the calling thread
  1351. if (phmain_wnd != NULL) {
  1352. (*phmain_wnd) = pdialog->m_hWnd;
  1353. }
  1354. return 1;
  1355. }
  1356. ////////////////////////////////////////////////////////////////////////////
  1357. //
  1358. // Show_VSS_Update_Dialog
  1359. //
  1360. ////////////////////////////////////////////////////////////////////////////
  1361. HWND
  1362. Show_VSS_Update_Dialog (HWND hparent_wnd)
  1363. {
  1364. // Kick off a UI thread that will display the 'updating' dialog and animation for us
  1365. HWND hthread_wnd = NULL;
  1366. ::Create_UI_Thread (fnUpdatingVSSThread, (DWORD)hparent_wnd, 0, 0, NULL, &hthread_wnd);
  1367. return hthread_wnd;
  1368. }
  1369. ////////////////////////////////////////////////////////////////////////////
  1370. //
  1371. // Kill_VSS_Update_Dialog
  1372. //
  1373. ////////////////////////////////////////////////////////////////////////////
  1374. void
  1375. Kill_VSS_Update_Dialog (HWND hdlg)
  1376. {
  1377. // Close out the window
  1378. if (::IsWindow (hdlg)) {
  1379. ::PostMessage (hdlg, WM_USER+101, 0, 0L);
  1380. }
  1381. return ;
  1382. }
  1383. ////////////////////////////////////////////////////////////////////////////
  1384. //
  1385. // Get_File_Time
  1386. //
  1387. ////////////////////////////////////////////////////////////////////////////
  1388. bool
  1389. Get_File_Time
  1390. (
  1391. LPCTSTR path,
  1392. LPFILETIME pcreation_time,
  1393. LPFILETIME paccess_time,
  1394. LPFILETIME pwrite_time
  1395. )
  1396. {
  1397. // Assume failure
  1398. bool retval = false;
  1399. // Attempt to open the file
  1400. HANDLE hfile = ::CreateFile (path,
  1401. 0,
  1402. 0,
  1403. NULL,
  1404. OPEN_EXISTING,
  1405. 0L,
  1406. NULL);
  1407. if (hfile != INVALID_HANDLE_VALUE) {
  1408. // Get the mod times for this file
  1409. retval = (::GetFileTime (hfile, pcreation_time, paccess_time, pwrite_time) == TRUE);
  1410. // Close the file
  1411. SAFE_CLOSE (hfile);
  1412. }
  1413. // Return the true/false result code
  1414. return retval;
  1415. }
  1416. ////////////////////////////////////////////////////////////////////////////
  1417. //
  1418. // Type_To_Icon
  1419. //
  1420. ////////////////////////////////////////////////////////////////////////////
  1421. int
  1422. Type_To_Icon
  1423. (
  1424. NODE_TYPE type,
  1425. bool btemp
  1426. )
  1427. {
  1428. int index = TEMP_ICON;
  1429. // If we aren't looking for a temp icon, then determine
  1430. // which icon to use based on the type
  1431. if (btemp == false) {
  1432. switch (type)
  1433. {
  1434. case NODE_TYPE_OBJECT:
  1435. index = OBJECT_ICON;
  1436. break;
  1437. case NODE_TYPE_TERRAIN_SECTION:
  1438. case NODE_TYPE_TERRAIN:
  1439. index = TERRAIN_ICON;
  1440. break;
  1441. case NODE_TYPE_TILE:
  1442. index = TILE_ICON;
  1443. break;
  1444. case NODE_TYPE_ZONE:
  1445. case NODE_TYPE_DAMAGE_ZONE:
  1446. index = ZONE_ICON;
  1447. break;
  1448. case NODE_TYPE_COVER_SPOT:
  1449. index = OBJECT_ICON;
  1450. break;
  1451. case NODE_TYPE_WAYPATH:
  1452. case NODE_TYPE_WAYPOINT:
  1453. index = WAYPATH_ICON;
  1454. break;
  1455. case NODE_TYPE_LIGHT:
  1456. index = LIGHT_ICON;
  1457. break;
  1458. case NODE_TYPE_SOUND:
  1459. index = SOUND_ICON;
  1460. break;
  1461. case NODE_TYPE_TRANSITION:
  1462. case NODE_TYPE_TRANSITION_CHARACTER:
  1463. index = TRANSITION_ICON;
  1464. break;
  1465. case NODE_TYPE_BUILDING:
  1466. index = BUILDING_ICON;
  1467. break;
  1468. }
  1469. }
  1470. // Return the icon's index
  1471. return index;
  1472. }
  1473. /////////////////////////////////////////////////////////////////////////////
  1474. //
  1475. // FileAccessRightsClass
  1476. //
  1477. /////////////////////////////////////////////////////////////////////////////
  1478. FileAccessRightsClass::FileAccessRightsClass
  1479. (
  1480. LPCTSTR filename,
  1481. ACCESS_TYPE type,
  1482. bool should_restore
  1483. )
  1484. : m_Filename (filename),
  1485. m_FileAttrs (0xFFFFFFFF),
  1486. m_bNeedsRestoring (false)
  1487. {
  1488. // Does the file exist?
  1489. m_FileAttrs = ::GetFileAttributes (m_Filename);
  1490. if (m_FileAttrs != 0xFFFFFFFF) {
  1491. if ((type == WANTS_READONLY) &&
  1492. (m_FileAttrs & FILE_ATTRIBUTE_READONLY) != FILE_ATTRIBUTE_READONLY) {
  1493. // Assign the readonly bit to the file
  1494. ::SetFileAttributes (m_Filename, m_FileAttrs | FILE_ATTRIBUTE_READONLY);
  1495. m_bNeedsRestoring = should_restore;
  1496. } else if ((type == WANTS_WRITEABLE) &&
  1497. (m_FileAttrs & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY) {
  1498. // Strip the readonly bit from the file
  1499. ::SetFileAttributes (m_Filename, m_FileAttrs & (~FILE_ATTRIBUTE_READONLY));
  1500. m_bNeedsRestoring = should_restore;
  1501. }
  1502. }
  1503. return ;
  1504. }
  1505. /////////////////////////////////////////////////////////////////////////////
  1506. //
  1507. // ~FileAccessRightsClass
  1508. //
  1509. /////////////////////////////////////////////////////////////////////////////
  1510. FileAccessRightsClass::~FileAccessRightsClass (void)
  1511. {
  1512. // Restore the file's attributes if necessary
  1513. if (m_bNeedsRestoring) {
  1514. ::SetFileAttributes (m_Filename, m_FileAttrs);
  1515. }
  1516. return ;
  1517. }
  1518. /////////////////////////////////////////////////////////////////////////////
  1519. //
  1520. // fnEditToFloatProc
  1521. //
  1522. /////////////////////////////////////////////////////////////////////////////
  1523. LRESULT CALLBACK
  1524. fnEditToFloatProc
  1525. (
  1526. HWND hwnd,
  1527. UINT message,
  1528. WPARAM wparam,
  1529. LPARAM lparam
  1530. )
  1531. {
  1532. WNDPROC old_proc = (WNDPROC)::GetProp (hwnd, "OLD_WND_PROC");
  1533. LRESULT result = 0L;
  1534. if (message == WM_SETTEXT) {
  1535. //
  1536. // Convert the textual value to a long, convert
  1537. // the long to a float, and conver the float to
  1538. // a string.
  1539. //
  1540. LPCTSTR string = (LPCTSTR)lparam;
  1541. if (::strchr (string, '.') != 0) {
  1542. result = ::CallWindowProc (old_proc, hwnd, message, wparam, lparam);
  1543. } else {
  1544. long value = ::atol ((LPCTSTR)lparam);
  1545. float float_value = value / 100.0F;
  1546. CString new_text;
  1547. new_text.Format ("%.3f", float_value);
  1548. result = ::CallWindowProc (old_proc, hwnd, message, wparam, (LPARAM)(LPCTSTR)new_text);
  1549. }
  1550. } else if (message == WM_GETTEXT) {
  1551. //
  1552. // Get the value (as text) from the control,
  1553. // convert it to a float, convert the float
  1554. // to a long, then convert the long back to
  1555. // a string.
  1556. //
  1557. result = ::CallWindowProc (old_proc, hwnd, message, wparam, lparam);
  1558. LPCTSTR string = (LPCTSTR)lparam;
  1559. if (::strchr (string, '.') != 0) {
  1560. float float_value = ::atof (string);
  1561. long int_value = long(float_value * 100);
  1562. ::itoa (int_value, (LPTSTR)lparam, 10);
  1563. } else {
  1564. long int_value = ::atol (string) * 100;
  1565. ::itoa (int_value, (LPTSTR)lparam, 10);
  1566. }
  1567. result = ::lstrlen ((LPTSTR)lparam);
  1568. } else if (message == WM_CHAR) {
  1569. //
  1570. // Check to see if this is one of the characters we allow
  1571. // the user to type
  1572. //
  1573. if ( (wparam >= '0' && wparam <= '9') ||
  1574. wparam == '.' ||
  1575. wparam == VK_BACK ||
  1576. wparam == '-')
  1577. {
  1578. result = ::CallWindowProc (old_proc, hwnd, message, wparam, lparam);
  1579. }
  1580. } else if (old_proc != NULL) {
  1581. result = ::CallWindowProc (old_proc, hwnd, message, wparam, lparam);
  1582. }
  1583. return result;
  1584. }
  1585. /////////////////////////////////////////////////////////////////////////////
  1586. //
  1587. // Restore_Edit_Ctrl
  1588. //
  1589. /////////////////////////////////////////////////////////////////////////////
  1590. void
  1591. Restore_Edit_Ctrl (HWND edit_wnd)
  1592. {
  1593. LONG orig_proc = (LONG)::GetProp (edit_wnd, "OLD_WND_PROC");
  1594. if (orig_proc != 0) {
  1595. ::SetWindowLong (edit_wnd, GWL_WNDPROC, orig_proc);
  1596. ::RemoveProp (edit_wnd, "OLD_WND_PROC");
  1597. }
  1598. return ;
  1599. }
  1600. /////////////////////////////////////////////////////////////////////////////
  1601. //
  1602. // Make_Edit_Float_Ctrl
  1603. //
  1604. /////////////////////////////////////////////////////////////////////////////
  1605. void
  1606. Make_Edit_Float_Ctrl (HWND edit_wnd)
  1607. {
  1608. Restore_Edit_Ctrl (edit_wnd);
  1609. LONG old_proc = ::SetWindowLong (edit_wnd, GWL_WNDPROC, (LONG)fnEditToFloatProc);
  1610. SetProp (edit_wnd, "OLD_WND_PROC", (HANDLE)old_proc);
  1611. return ;
  1612. }
  1613. /////////////////////////////////////////////////////////////////////////////
  1614. //
  1615. // fnEditToIntProc
  1616. //
  1617. /////////////////////////////////////////////////////////////////////////////
  1618. LRESULT CALLBACK
  1619. fnEditToIntProc
  1620. (
  1621. HWND hwnd,
  1622. UINT message,
  1623. WPARAM wparam,
  1624. LPARAM lparam
  1625. )
  1626. {
  1627. WNDPROC old_proc = (WNDPROC)::GetProp (hwnd, "OLD_WND_PROC");
  1628. LRESULT result = 0L;
  1629. if (message == WM_CHAR) {
  1630. //
  1631. // Check to see if this is one of the characters we allow
  1632. // the user to type
  1633. //
  1634. if ( (wparam >= '0' && wparam <= '9') ||
  1635. wparam == VK_BACK ||
  1636. wparam == '-')
  1637. {
  1638. result = ::CallWindowProc (old_proc, hwnd, message, wparam, lparam);
  1639. }
  1640. } else if (old_proc != NULL) {
  1641. result = ::CallWindowProc (old_proc, hwnd, message, wparam, lparam);
  1642. }
  1643. return result;
  1644. }
  1645. /////////////////////////////////////////////////////////////////////////////
  1646. //
  1647. // Make_Edit_Int_Ctrl
  1648. //
  1649. /////////////////////////////////////////////////////////////////////////////
  1650. void
  1651. Make_Edit_Int_Ctrl (HWND edit_wnd)
  1652. {
  1653. Restore_Edit_Ctrl (edit_wnd);
  1654. LONG old_proc = ::SetWindowLong (edit_wnd, GWL_WNDPROC, (LONG)fnEditToIntProc);
  1655. SetProp (edit_wnd, "OLD_WND_PROC", (HANDLE)old_proc);
  1656. return ;
  1657. }
  1658. //////////////////////////////////////////////////////////////////////////////
  1659. //
  1660. // Set_Modified
  1661. //
  1662. /////////////////////////////////////////////////////////////////////////////
  1663. void
  1664. Set_Modified (bool modified)
  1665. {
  1666. ::Get_Current_Document ()->SetModifiedFlag (modified);
  1667. return ;
  1668. }
  1669. bool _IsSilent = false;
  1670. //////////////////////////////////////////////////////////////////////////////
  1671. //
  1672. // Is_Silent_Mode
  1673. //
  1674. /////////////////////////////////////////////////////////////////////////////
  1675. bool
  1676. Is_Silent_Mode (void)
  1677. {
  1678. return _IsSilent;
  1679. }
  1680. //////////////////////////////////////////////////////////////////////////////
  1681. //
  1682. // Set_Silent_Mode
  1683. //
  1684. /////////////////////////////////////////////////////////////////////////////
  1685. void
  1686. Set_Silent_Mode (bool is_silent)
  1687. {
  1688. _IsSilent = is_silent;
  1689. return ;
  1690. }
  1691. //////////////////////////////////////////////////////////////////////////////
  1692. //
  1693. // Get_Next_Temp_ID
  1694. //
  1695. /////////////////////////////////////////////////////////////////////////////
  1696. int
  1697. Get_Next_Temp_ID (void)
  1698. {
  1699. //
  1700. // Read the next temporary preset ID from the registry
  1701. //
  1702. int temp_id = theApp.GetProfileInt (CONFIG_KEY, TEMP_ID_VALUE, TEMP_DEF_ID_START);
  1703. //
  1704. // Make sure the temp ID is in the right range
  1705. //
  1706. if (temp_id < TEMP_DEF_ID_START) {
  1707. temp_id = TEMP_DEF_ID_START;
  1708. }
  1709. //
  1710. // Store the next temp ID value in the registry
  1711. //
  1712. theApp.WriteProfileInt (CONFIG_KEY, TEMP_ID_VALUE, temp_id+1);
  1713. return temp_id;
  1714. }
  1715. //////////////////////////////////////////////////////////////////////////////
  1716. //
  1717. // Get_Collision_Box
  1718. //
  1719. /////////////////////////////////////////////////////////////////////////////
  1720. bool
  1721. Get_Collision_Box (const RenderObjClass *model, AABoxClass &box)
  1722. {
  1723. bool retval = false;
  1724. if (model != NULL) {
  1725. //
  1726. // Get the collision box for this render obj
  1727. //
  1728. RenderObjClass *world_box = model->Get_Sub_Object_By_Name ("WORLDBOX");
  1729. // If we didn't finde WorldBox, try to find the LOD named "WorldBox"
  1730. // The LOD code generates a unique name for the mesh by appending A,B,C, etc to the name.
  1731. // A is the lowest LOD, B is the next, and so on. Our worldbox is specified in the highest
  1732. // LOD so we have to construct the name by appending 'A'+LodCount to the name... icky
  1733. if ((world_box == NULL) && (model->Class_ID() == RenderObjClass::CLASSID_HLOD))
  1734. {
  1735. char namebuffer[64];
  1736. sprintf(namebuffer,"WorldBox%c",'A' + ((HLodClass *)model)->Get_Lod_Count() - 1);
  1737. world_box = model->Get_Sub_Object_By_Name(namebuffer);
  1738. /*if (box_obj && box_obj->Class_ID() == RenderObjClass::CLASSID_OBBOX) {
  1739. world_box = box_obj;
  1740. }*/
  1741. }
  1742. if (world_box != NULL) {
  1743. box = world_box->Get_Bounding_Box ();
  1744. world_box->Release_Ref ();
  1745. retval = true;
  1746. }
  1747. }
  1748. return retval;
  1749. }
  1750. //////////////////////////////////////////////////////////////////
  1751. //
  1752. // Get_Collision_Box
  1753. //
  1754. // Note: This function returns true if it returns an AABox or
  1755. // false if it returns an OBBox
  1756. //
  1757. //////////////////////////////////////////////////////////////////
  1758. bool
  1759. Get_Collision_Box (RenderObjClass *render_obj, AABoxClass &aabox, OBBoxClass &obbox)
  1760. {
  1761. bool is_aabox = true;
  1762. aabox.Center.Set (0, 0, 0);
  1763. aabox.Extent.Set (0, 0, 0);
  1764. obbox.Center.Set (0, 0, 0);
  1765. obbox.Extent.Set (0, 0, 0);
  1766. if (render_obj != NULL) {
  1767. //
  1768. // Try to get the "WorldBox" from the model
  1769. //
  1770. RenderObjClass *world_box = render_obj->Get_Sub_Object_By_Name ("WorldBox");
  1771. //
  1772. // If we didn't finde WorldBox, try to find the LOD named "WorldBox"
  1773. // The LOD code generates a unique name for the mesh by appending A,B,C, etc to the name.
  1774. // A is the lowest LOD, B is the next, and so on. Our worldbox is specified in the highest
  1775. // LOD so we have to construct the name by appending 'A'+LodCount to the name... icky
  1776. //
  1777. if ((world_box == NULL) && (render_obj->Class_ID () == RenderObjClass::CLASSID_HLOD)) {
  1778. char namebuffer[64];
  1779. sprintf(namebuffer,"WorldBox%c",'A' + ((HLodClass *)render_obj)->Get_Lod_Count() - 1);
  1780. world_box = render_obj->Get_Sub_Object_By_Name (namebuffer);
  1781. }
  1782. if (world_box != NULL) {
  1783. //
  1784. // Determine which type of bounding box to return and OBBox or an AABox
  1785. //
  1786. if (world_box->Class_ID() == RenderObjClass::CLASSID_OBBOX) {
  1787. obbox = ((OBBoxRenderObjClass *)world_box)->Get_Box ();
  1788. is_aabox = false;
  1789. } else {
  1790. aabox = world_box->Get_Bounding_Box ();
  1791. is_aabox = true;
  1792. }
  1793. }
  1794. REF_PTR_RELEASE (world_box);
  1795. }
  1796. return is_aabox;
  1797. }
  1798. //////////////////////////////////////////////////////////////////////////////
  1799. //
  1800. // Instance_Definition
  1801. //
  1802. /////////////////////////////////////////////////////////////////////////////
  1803. PersistClass *
  1804. Instance_Definition (DefinitionClass *definition)
  1805. {
  1806. PersistClass *new_object = NULL;
  1807. //
  1808. // Create the new object
  1809. //
  1810. if (definition != NULL) {
  1811. new_object = definition->Create ();
  1812. }
  1813. if (new_object == NULL) {
  1814. LPCTSTR name = definition->Get_Name ();
  1815. CString message;
  1816. message.Format ("Unable to create an instance of %s.\nCheck to make sure the preset is properly configured with a model and/or physics object.", name);
  1817. //
  1818. // Warn the user that we were unable to create the object
  1819. //
  1820. HWND parent_wnd = ::AfxGetMainWnd ()->m_hWnd;
  1821. ::MessageBox (parent_wnd, message, "Preset Error", MB_ICONERROR | MB_OK);
  1822. }
  1823. return new_object;
  1824. }
  1825. //////////////////////////////////////////////////////////////////////////////
  1826. //
  1827. // Check_Editor_Version
  1828. //
  1829. /////////////////////////////////////////////////////////////////////////////
  1830. bool
  1831. Check_Editor_Version (void)
  1832. {
  1833. #ifndef PUBLIC_EDITOR_VER
  1834. char curr_filename[MAX_PATH];
  1835. ::GetModuleFileName (NULL, curr_filename, MAX_PATH);
  1836. CString filename = "\\\\mobius\\project7\\projects\\renegade\\programming\\tools\\level edit\\";
  1837. filename += ::Get_Filename_From_Path (curr_filename);
  1838. //
  1839. // Check the version of the level editor that is out on the network
  1840. // against the version we are running. We don't want people making modifications
  1841. // with and older version
  1842. //
  1843. return (::Compare_EXE_Version ((int)::AfxGetInstanceHandle (), filename) >= 0);
  1844. #else
  1845. return true;
  1846. #endif
  1847. }
  1848. /////////////////////////////////////////////////////////////////////////////
  1849. //
  1850. // Perform_Job
  1851. //
  1852. /////////////////////////////////////////////////////////////////////////////
  1853. void
  1854. Perform_Job (LPCTSTR filename, bool delete_on_completion)
  1855. {
  1856. int total = ::GetPrivateProfileInt ("Job Description", "Total", 1, filename);
  1857. int index = ::GetPrivateProfileInt ("Job Description", "Index", 0, filename);
  1858. CString granularity_string;
  1859. ::GetPrivateProfileString ("Job Description", "Granularity", "1", granularity_string.GetBufferSetLength (20), 20, filename);
  1860. float granularity = ::atof (granularity_string);
  1861. CString level_file;
  1862. ::GetPrivateProfileString ("Job Description", "LVL", "", level_file.GetBufferSetLength (MAX_PATH), MAX_PATH, filename);
  1863. CString output_file;
  1864. ::GetPrivateProfileString ("Job Description", "Output", "", output_file.GetBufferSetLength (MAX_PATH), MAX_PATH, filename);
  1865. if (level_file.GetLength () > 0) {
  1866. //
  1867. // Load the requested level
  1868. //
  1869. ::Get_Main_View ()->Allow_Repaint (false);
  1870. EditorSaveLoadClass::Load_Level (level_file);
  1871. ::Get_Main_View ()->Allow_Repaint (true);
  1872. //
  1873. // Start VIS
  1874. //
  1875. #if (1)
  1876. ::Get_Scene_Editor ()->Generate_Uniform_Sampled_Vis (granularity,false,false,true,index,total);
  1877. #else
  1878. ::Get_Scene_Editor ()->Generate_Edge_Sampled_Vis (granularity,false,true,index,total);
  1879. #endif
  1880. ::Get_Scene_Editor ()->Generate_Manual_Vis (true,index,total);
  1881. ::Get_Scene_Editor ()->Generate_Light_Vis (true,index,total);
  1882. //
  1883. // Export VIS to the given file
  1884. //
  1885. ::Get_Scene_Editor ()->Export_VIS (output_file);
  1886. }
  1887. //
  1888. // Delete the job file if necessary
  1889. //
  1890. if (delete_on_completion) {
  1891. ::DeleteFile (filename);
  1892. }
  1893. return ;
  1894. }
  1895. /////////////////////////////////////////////////////////////////////////////
  1896. //
  1897. // Get_Factory_Name
  1898. //
  1899. /////////////////////////////////////////////////////////////////////////////
  1900. LPCTSTR
  1901. Get_Factory_Name (uint32 class_id)
  1902. {
  1903. LPCTSTR name = NULL;
  1904. //
  1905. // Can we find the requested factory?
  1906. //
  1907. DefinitionFactoryClass *factory = DefinitionFactoryMgrClass::Find_Factory (class_id);
  1908. if (factory == NULL) {
  1909. //
  1910. // Check to see if this is an abstract factory
  1911. //
  1912. for (int index = 0; index < PRESET_CATEGORY_COUNT; index ++) {
  1913. if (PRESET_CATEGORIES[index].clsid == (int)class_id) {
  1914. name = PRESET_CATEGORIES[index].name;
  1915. break;
  1916. }
  1917. }
  1918. } else {
  1919. name = factory->Get_Name ();
  1920. }
  1921. return name;
  1922. }
  1923. /////////////////////////////////////////////////////////////////////////////
  1924. //
  1925. // Convert_Newline_To_Chars
  1926. //
  1927. /////////////////////////////////////////////////////////////////////////////
  1928. void
  1929. Convert_Newline_To_Chars (CString &string)
  1930. {
  1931. CString retval;
  1932. //
  1933. // Take a guess as to how large to make the final string
  1934. //
  1935. int count = string.GetLength ();
  1936. //
  1937. // Copy characters between the strings
  1938. //
  1939. for (int index = 0; index < count; index ++) {
  1940. if (string[index] == '\n') {
  1941. retval += "\\n";
  1942. } else {
  1943. retval += string[index];
  1944. }
  1945. }
  1946. string = retval;
  1947. return ;
  1948. }
  1949. /////////////////////////////////////////////////////////////////////////////
  1950. //
  1951. // Convert_Chars_To_Newline
  1952. //
  1953. /////////////////////////////////////////////////////////////////////////////
  1954. void
  1955. Convert_Chars_To_Newline (CString &string)
  1956. {
  1957. CString retval;
  1958. //
  1959. // Take a guess as to how large to make the final string
  1960. //
  1961. int count = string.GetLength ();
  1962. //
  1963. // Copy characters between the strings
  1964. //
  1965. for (int index = 0; index < count; index ++) {
  1966. if (index + 1 < count && string[index] == '\\' && string[index + 1] == 'n') {
  1967. retval += '\n';
  1968. index ++;
  1969. } else {
  1970. retval += string[index];
  1971. }
  1972. }
  1973. string = retval;
  1974. return ;
  1975. }