LevelEditDoc.cpp 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  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. // LevelEditDoc.cpp : implementation of the CLevelEditDoc class
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "leveleditdoc.h"
  23. #include "utils.h"
  24. #include "physcoltest.h"
  25. #include "gridcull.h"
  26. #include "aabtreecull.h"
  27. #include "light.h"
  28. #include "ffactory.h"
  29. #include "leveleditview.h"
  30. #include "filemgr.h"
  31. #include "profilesection.h"
  32. #include "editorphys.h"
  33. #include "sceneeditor.h"
  34. #include "nodemgr.h"
  35. #include "node.h"
  36. #include "cameramgr.h"
  37. #include "regkeys.h"
  38. #include "editorassetmgr.h"
  39. #include "_assetmgr.h"
  40. #include "rcfile.h"
  41. #include "editorini.h"
  42. #include "updateassetsdialog.h"
  43. #include "filelocations.h"
  44. #include "ww3d.h"
  45. #include "editorsaveload.h"
  46. #include "presetslibform.h"
  47. #include "rawfile.h"
  48. #include "progressui.h"
  49. #include "verchk.h"
  50. #include "overlappage.h"
  51. #include "stringsmgr.h"
  52. #include "dazzle.h"
  53. #include "texture.h"
  54. #include "conversationpage.h"
  55. #include "conversationeditormgr.h"
  56. #include "dx8renderer.h"
  57. #include "presetmgr.h"
  58. #include "combatchunkid.h"
  59. #include "combat.h"
  60. #include "backgroundmgr.h"
  61. #include "weathermgr.h"
  62. #include "gameobjmanager.h"
  63. #include "scripts.h"
  64. #include "soundenvironment.h"
  65. #include "soldier.h"
  66. #include "editorbuild.h"
  67. #include "export.h"
  68. #ifdef _DEBUG
  69. #define new DEBUG_NEW
  70. #undef THIS_FILE
  71. static char THIS_FILE[] = __FILE__;
  72. #endif
  73. /////////////////////////////////////////////////////////////////////////////
  74. // Constants
  75. /////////////////////////////////////////////////////////////////////////////
  76. const Vector3 DEF_BACK_COLOR (0.2F, 0.4F, 0.6F);
  77. const Vector3 DEF_AMBIENT_COLOR (0.3F, 0.3F, 0.3F);
  78. /////////////////////////////////////////////////////////////////////////////
  79. // Static member initialization
  80. /////////////////////////////////////////////////////////////////////////////
  81. bool CLevelEditDoc::IsBatchExportMode = false;
  82. /////////////////////////////////////////////////////////////////////////////
  83. // CLevelEditDoc
  84. IMPLEMENT_DYNCREATE(CLevelEditDoc, CDocument)
  85. BEGIN_MESSAGE_MAP(CLevelEditDoc, CDocument)
  86. //{{AFX_MSG_MAP(CLevelEditDoc)
  87. ON_COMMAND(ID_FILE_SAVE, OnFileSave)
  88. ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
  89. //}}AFX_MSG_MAP
  90. END_MESSAGE_MAP()
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CLevelEditDoc construction/destruction
  93. ////////////////////////////////////////////////////////////
  94. //
  95. // CLevelEditDoc
  96. //
  97. CLevelEditDoc::CLevelEditDoc (void)
  98. : m_pScene (NULL),
  99. m_bPerformanceSampling (false),
  100. m_DisplayPathWeb (false),
  101. m_DisplayFullPaths (false),
  102. m_CoordSystem (COORD_WORLD),
  103. m_AxisRestriction (RESTRICT_NONE),
  104. m_ModeModifiers (0),
  105. m_bSnapPointsActive (true),
  106. m_bNeedRepartition (false),
  107. m_DebugScriptsMode (false)
  108. {
  109. // Allocate new managers
  110. m_pFileMgr = new FileMgrClass;
  111. //
  112. // Read the settings from the registry
  113. //
  114. m_DebugScriptsMode = (theApp.GetProfileInt (CONFIG_KEY, "ScriptDebugMode", 0) == 1);
  115. return;
  116. }
  117. ////////////////////////////////////////////////////////////
  118. //
  119. // ~CLevelEditDoc
  120. //
  121. CLevelEditDoc::~CLevelEditDoc (void)
  122. {
  123. // Used to ensure all dynamically allocated data is freed
  124. CleanupResources ();
  125. return ;
  126. }
  127. ///////////////////////////////////////////////////////////////
  128. //
  129. // Set_Debug_Script_Mode
  130. //
  131. ///////////////////////////////////////////////////////////////
  132. void
  133. CLevelEditDoc::Set_Debug_Script_Mode (bool onoff)
  134. {
  135. m_DebugScriptsMode = onoff;
  136. theApp.WriteProfileInt (CONFIG_KEY, "ScriptDebugMode", m_DebugScriptsMode);
  137. return ;
  138. }
  139. ///////////////////////////////////////////////////////////////
  140. //
  141. // Initialize_VSS
  142. //
  143. bool
  144. CLevelEditDoc::Initialize_VSS (void)
  145. {
  146. bool retval = false;
  147. ASSERT (m_pFileMgr != NULL);
  148. #ifdef PUBLIC_EDITOR_VER
  149. m_pFileMgr->Initialize_VSS ("");
  150. retval = true;
  151. #else
  152. // Get the default VSS database to open
  153. CString database_path = theApp.GetProfileString (CONFIG_KEY,
  154. VSSDB_VALUE,
  155. DEF_VSS_DB);
  156. // Look up the user's Source Safe logon name
  157. TCHAR user_name[256] = { 0 };
  158. bool blogon_success = false;
  159. if (::GetEnvironmentVariable ("SSUSER", user_name, sizeof (user_name)) == 0) {
  160. // Let the user know they need to setup this variable
  161. ::Message_Box (NULL,
  162. IDS_NOVSSUSER_MSG,
  163. IDS_NOVSS_TITLE,
  164. MB_ICONERROR | MB_OK | MB_SETFOREGROUND | MB_TOPMOST);
  165. } else {
  166. // Attempt to log onto the database using the correct username
  167. blogon_success = m_pFileMgr->Initialize_VSS (database_path, user_name);
  168. }
  169. // Were we successful in logging on with the username?
  170. if (blogon_success == false) {
  171. // Attempt to logon with read-only access
  172. blogon_success = m_pFileMgr->Initialize_VSS (database_path);
  173. if (!blogon_success) {
  174. // If we were unsuccessful, let the user know
  175. ::Message_Box (NULL,
  176. IDS_NOVSS_MSG,
  177. IDS_NOVSS_TITLE,
  178. MB_ICONERROR | MB_OK | MB_SETFOREGROUND | MB_TOPMOST);
  179. }
  180. // Ensure or is VSS interface read-only
  181. m_pFileMgr->Set_Read_Only_VSS (true);
  182. }
  183. if (m_pFileMgr->Is_VSS_Read_Only ()) {
  184. // Let the user know they are in read-only mode
  185. ::Message_Box (NULL,
  186. IDS_VSS_READONLY_MSG,
  187. IDS_NOVSS_TITLE,
  188. MB_ICONEXCLAMATION | MB_OK | MB_SETFOREGROUND | MB_TOPMOST);
  189. }
  190. // If at some point we were successful, then cache the database
  191. // path in the registry and return success
  192. if (blogon_success) {
  193. theApp.WriteProfileString (CONFIG_KEY, VSSDB_VALUE, database_path);
  194. retval = true;
  195. }
  196. #endif //PUBLIC_EDITOR_VER
  197. // Return the true/false result code
  198. return retval;
  199. }
  200. ///////////////////////////////////////////////////////////////
  201. //
  202. // Change_Base_Path
  203. //
  204. bool
  205. CLevelEditDoc::Change_Base_Path (void)
  206. {
  207. // Assume failure
  208. bool retval = false;
  209. // Ask the user to pick a base path
  210. CString base_path;
  211. if (::Browse_For_Folder (base_path,
  212. NULL,
  213. NULL,
  214. "Please select a location to keep your models. A subdir named Assets will be created automatically.")) {
  215. // Concat the Assets subdir onto the path
  216. if (base_path[::lstrlen (base_path)-1] != '\\') {
  217. base_path += "\\";
  218. }
  219. base_path += "Assets";
  220. // Let the file manager know what the new base path is
  221. m_pFileMgr->Set_Base_Path (base_path);
  222. retval = true;
  223. }
  224. // Return the true/false result code
  225. return retval;
  226. }
  227. ///////////////////////////////////////////////////////////////
  228. //
  229. // Update_Core_Files
  230. //
  231. ///////////////////////////////////////////////////////////////
  232. void
  233. CLevelEditDoc::Update_Core_Files (void)
  234. {
  235. // Ensure that VSS is initialized
  236. if (Initialize_VSS ()) {
  237. // Do we already have a base path?
  238. if (::lstrlen (m_pFileMgr->Get_Base_Path ()) == 0) {
  239. // Ask the user for a base path
  240. if (!Change_Base_Path ()) {
  241. // Pick a path for the user
  242. CString path = ::Get_Startup_Directory ().Left (3);
  243. path += DEF_ASSET_PATH;
  244. m_pFileMgr->Set_Base_Path (path);
  245. }
  246. }
  247. //
  248. // Add some search paths to the file factory
  249. //
  250. EditorFileFactoryClass::Add_Search_Path (m_pFileMgr->Make_Full_Path (SHATTER_DIR));
  251. EditorFileFactoryClass::Add_Search_Path (m_pFileMgr->Make_Full_Path (WEATHER_DIR));
  252. EditorFileFactoryClass::Add_Search_Path (m_pFileMgr->Make_Full_Path (SKY_DIR));
  253. EditorFileFactoryClass::Add_Search_Path (m_pFileMgr->Make_Full_Path ("always\\sound\\weather"));
  254. EditorFileFactoryClass::Add_Search_Path (m_pFileMgr->Make_Full_Path ("always\\effects"));
  255. ProgressUIMgrClass::Set_Status_Text ("Updating core asset files...");
  256. #ifdef PUBLIC_EDITOR_VER
  257. Update_Assets_For_Mod_Tree ();
  258. #else
  259. //
  260. // Make sure we have the latest versions of the core files
  261. //
  262. m_pFileMgr->Update_File (PRESETS_PATH);
  263. if (::Is_Silent_Mode () == false) {
  264. m_pFileMgr->Update_File (ALWAYS_INI_PATH);
  265. m_pFileMgr->Update_File (SERIAL_INI_PATH);
  266. m_pFileMgr->Update_File (UPDATE_INI_PATH);
  267. m_pFileMgr->Get_Subproject (ALWAYS_INI_DIR);
  268. m_pFileMgr->Update_File (HUMAN_SKEL_PATH);
  269. m_pFileMgr->Update_File (SKY_DIR);
  270. m_pFileMgr->Update_File (WEATHER_DIR);
  271. m_pFileMgr->Update_File (SHATTER_DIR);
  272. m_pFileMgr->Build_Global_Include_List ();
  273. if (m_DebugScriptsMode == false) {
  274. m_pFileMgr->Update_File (SCRIPTS_PATH);
  275. }
  276. //
  277. // Ensure the asset tree is updated
  278. //
  279. Update_Asset_Tree ();
  280. }
  281. #endif //PUBLIC_EDITOR_VER
  282. //
  283. // Update the strings database
  284. //
  285. StringsMgrClass::Create_Database_If_Necessary ();
  286. StringsMgrClass::Load_Translation_Database ();
  287. }
  288. return ;
  289. }
  290. ///////////////////////////////////////////////////////////////
  291. //
  292. // Update_Assets_For_Mod_Tree
  293. //
  294. ///////////////////////////////////////////////////////////////
  295. void
  296. CLevelEditDoc::Update_Assets_For_Mod_Tree (void)
  297. {
  298. //
  299. // Get all INI files to the always\INI directory
  300. //
  301. CString full_ini_path = ::Get_File_Mgr ()->Make_Full_Path (ALWAYS_INI_DIR);
  302. m_pFileMgr->Update_All_Files (full_ini_path, "*.ini");
  303. //
  304. // Make sure to get the human skeleton
  305. //
  306. m_pFileMgr->Update_File ("presets\\objects.ddb");
  307. //
  308. // Make sure to get the human skeleton
  309. //
  310. m_pFileMgr->Update_File (HUMAN_SKEL_PATH);
  311. return ;
  312. }
  313. ///////////////////////////////////////////////////////////////
  314. //
  315. // Update_Asset_Tree
  316. //
  317. ///////////////////////////////////////////////////////////////
  318. void
  319. CLevelEditDoc::Update_Asset_Tree (void)
  320. {
  321. // Get a pointer to the INI file from the asset manager
  322. CString path = ::Get_File_Mgr ()->Make_Full_Path (UPDATE_INI_PATH);
  323. EditorINIClass *pini = _pThe3DAssetManager->Get_INI (path);
  324. // Were we successful in getting a pointer to the INI file?
  325. ASSERT (pini != NULL);
  326. if (pini != NULL) {
  327. // Determine what the last time we updated was and when the
  328. // last time the database was modified
  329. int update_id = theApp.GetProfileInt (CONFIG_KEY, LAST_UPDATE_VALUE, 0);
  330. int curr_update_id = pini->Get_Int ("General", "ID");
  331. // Do we need to update?
  332. if (update_id < curr_update_id) {
  333. // Get the comments from the file
  334. TCHAR comments[512];
  335. pini->Get_TextBlock ("Comments", comments, sizeof (comments));
  336. for (LPSTR newline = ::strchr (comments, '|');
  337. newline != NULL;
  338. newline = ::strchr (newline, '|'))
  339. {
  340. newline[0] = '\r';
  341. newline[1] = '\n';
  342. }
  343. //
  344. // Build a list of directories that we need to update...
  345. //
  346. STRING_LIST directory_list;
  347. bool update_all = false;
  348. for (int index = update_id + 1; index <= curr_update_id; index ++) {
  349. //
  350. // Get the directory associated with this update-id
  351. //
  352. CString number_string;
  353. number_string.Format ("%d", index);
  354. StringClass filename;
  355. pini->Get_String (filename, "Details", number_string);
  356. //
  357. // If we couldn't get the directory, then update all files
  358. //
  359. if (filename.Get_Length () > 0) {
  360. directory_list.Add (::Get_File_Mgr ()->Make_Full_Path (filename));
  361. } else {
  362. update_all = true;
  363. }
  364. }
  365. //
  366. // Show a dialog to the user that will ask them
  367. // if they want to update now.
  368. //
  369. //if (::Is_Silent_Mode () == false) {
  370. UpdateAssetsDialogClass dialog (CString (comments), directory_list, update_all, NULL);
  371. if (dialog.DoModal () == IDOK) {
  372. // Remember that we've updated ourselves
  373. theApp.WriteProfileInt (CONFIG_KEY, LAST_UPDATE_VALUE, curr_update_id);
  374. }
  375. //}
  376. }
  377. // Free the INI object
  378. SAFE_DELETE (pini);
  379. }
  380. return ;
  381. }
  382. ///////////////////////////////////////////////////////////////
  383. //
  384. // CleanupResources
  385. //
  386. void
  387. CLevelEditDoc::CleanupResources (void)
  388. {
  389. //
  390. // Release our hold on the scene
  391. //
  392. MEMBER_RELEASE (m_pScene);
  393. SAFE_DELETE (m_pFileMgr);
  394. return ;
  395. }
  396. ////////////////////////////////////////////////////////////
  397. //
  398. // OnNewDocument
  399. //
  400. BOOL
  401. CLevelEditDoc::OnNewDocument (void)
  402. {
  403. // Allow the base class to process this message
  404. if (!CDocument::OnNewDocument())
  405. return FALSE;
  406. //
  407. // Keep the view from refreshing
  408. //
  409. ::Get_Main_View ()->Allow_Repaint (false);
  410. //
  411. // Instantiate a new scene
  412. //
  413. MEMBER_RELEASE (m_pScene);
  414. m_pScene = new SceneEditorClass;
  415. m_pScene->Set_Ambient_Light (DEF_AMBIENT_COLOR);
  416. m_pScene->Update_Lighting ();
  417. m_pScene->Enable_Collision_Detection (0, 0);
  418. m_pScene->Set_Sun_Light_Orientation (0, DEG_TO_RADF (50));
  419. m_pScene->Update_Lighting();
  420. // Reset sound environment, background and weather systems.
  421. CombatManager::Get_Sound_Environment()->Reset();
  422. BackgroundMgrClass::Reset();
  423. WeatherMgrClass::Reset();
  424. //
  425. // Reset the scene, camera, and file manager
  426. //
  427. m_pFileMgr->Initialize ();
  428. ::Get_Main_View ()->Reset_View ();
  429. ::Get_Scene_Editor ()->Re_Partition_Dynamic_Culling_System ();
  430. SetModifiedFlag (false);
  431. //
  432. // Force free the assets...
  433. //
  434. WW3DAssetManager::Get_Instance ()->Free_Assets ();
  435. TheDX8MeshRenderer.Invalidate ();
  436. Preload_Human_Data ();
  437. Preload_Tool_Assets ();
  438. //
  439. // Reset the overlap-sphere page
  440. //
  441. OverlapPageClass *form = ::Get_Overlap_Form ();
  442. if (form != NULL) {
  443. form->Reset_Tree ();
  444. }
  445. //
  446. // Reset the conversation page
  447. //
  448. ConversationPageClass *conversation_form = ::Get_Conversation_Form ();
  449. if (conversation_form != NULL) {
  450. conversation_form->Reload_Data ();
  451. }
  452. // Allow a refresh
  453. ::Get_Main_View ()->Allow_Repaint (true);
  454. ::Refresh_Main_View ();
  455. return true;
  456. }
  457. ////////////////////////////////////////////////////////////
  458. //
  459. // Serialize
  460. //
  461. ////////////////////////////////////////////////////////////
  462. void
  463. CLevelEditDoc::Serialize (CArchive& ar)
  464. {
  465. SetModifiedFlag (FALSE);
  466. return ;
  467. }
  468. /////////////////////////////////////////////////////////////////////////////
  469. // CLevelEditDoc diagnostics
  470. #ifdef _DEBUG
  471. void CLevelEditDoc::AssertValid() const
  472. {
  473. CDocument::AssertValid();
  474. }
  475. void CLevelEditDoc::Dump(CDumpContext& dc) const
  476. {
  477. CDocument::Dump(dc);
  478. }
  479. #endif //_DEBUG
  480. ///////////////////////////////////////////////////////////////
  481. //
  482. // Do_Version_Check
  483. //
  484. ////////////////////////////////////////////////////////////
  485. bool
  486. CLevelEditDoc::Do_Version_Check (void)
  487. {
  488. bool retval = true;
  489. #ifndef PUBLIC_EDITOR_VER
  490. //
  491. // Check the version of the level editor that is out on the network
  492. // against the version we are running. We don't want people making modifications
  493. // with and older version
  494. //
  495. if (Check_Editor_Version () == false) {
  496. if (Message_Box (NULL, IDS_VERSION_ERROR_MSG, IDS_VERSION_ERROR_TITLE, MB_ICONEXCLAMATION | MB_OKCANCEL | MB_SETFOREGROUND | MB_SYSTEMMODAL) == IDCANCEL) {
  497. //
  498. // Just for kicks, exit the process pretty violently
  499. //
  500. ExitProcess (1);
  501. retval = false;
  502. }
  503. m_pFileMgr->Set_Read_Only_VSS (true);
  504. }
  505. #endif //PUBLIC_EDITOR_VER
  506. return retval;
  507. }
  508. ///////////////////////////////////////////////////////////////
  509. //
  510. // Preload_Assets
  511. //
  512. ////////////////////////////////////////////////////////////
  513. void
  514. CLevelEditDoc::Preload_Assets (void)
  515. {
  516. Preload_Human_Data ();
  517. Preload_Tool_Assets ();
  518. //
  519. // Initialize the dazzle system
  520. //
  521. CString dazzle_ini_path = ::Get_File_Mgr ()->Make_Full_Path (DAZZLE_INI_PATH);
  522. FileClass * dazzle_ini_file = _TheFileFactory->Get_File (dazzle_ini_path);
  523. if (dazzle_ini_file) {
  524. INIClass dazzle_ini (*dazzle_ini_file);
  525. DazzleRenderObjClass::Init_From_INI (&dazzle_ini);
  526. _TheFileFactory->Return_File (dazzle_ini_file);
  527. }
  528. return ;
  529. }
  530. ///////////////////////////////////////////////////////////////
  531. //
  532. // Preload_Tool_Assets
  533. //
  534. ////////////////////////////////////////////////////////////
  535. void
  536. CLevelEditDoc::Preload_Tool_Assets (void)
  537. {
  538. //
  539. // Load the tool-art textures into the asset manager
  540. //
  541. _pThe3DAssetManager->Load_Resource_Texture ("METER.TGA");
  542. _pThe3DAssetManager->Load_Resource_Texture ("TA_CEMENT.TGA");
  543. _pThe3DAssetManager->Load_Resource_Texture ("TA_FRONT.TGA");
  544. _pThe3DAssetManager->Load_Resource_Texture ("TA_DUMMY.TGA");
  545. //
  546. // Load the tool-art models into the asset manager
  547. //
  548. ResourceFileClass way_start (NULL, "WayStart.w3d");
  549. ResourceFileClass way_mid (NULL, "WayMid.w3d");
  550. ResourceFileClass way_end (NULL, "WayStop.w3d");
  551. ResourceFileClass way_r (NULL, "Way_R.w3d");
  552. ResourceFileClass way_g (NULL, "Way_G.w3d");
  553. ResourceFileClass way_b (NULL, "Way_B.w3d");
  554. ResourceFileClass point_light (NULL, "PointLight.w3d");
  555. ResourceFileClass speaker1 (NULL, "Speaker.w3d");
  556. ResourceFileClass speaker2 (NULL, "Speaker2.w3d");
  557. ResourceFileClass body_box (NULL, "BODYBOX.W3D");
  558. ResourceFileClass camera_model (NULL, "CAMERA.W3D");
  559. ResourceFileClass grid_model (NULL, "GRID.W3D");
  560. ResourceFileClass trans_box_model (NULL, "TRANSBOX.W3D");
  561. ResourceFileClass dummy_model (NULL, "DUMMY.W3D");
  562. ResourceFileClass cover_spot_model (NULL, "COVERSPOT.W3D");
  563. ResourceFileClass building_model (NULL, "BUILDINGICON.W3D");
  564. ResourceFileClass carmarker_model (NULL, "CARMARKER.W3D");
  565. WW3DAssetManager::Get_Instance()->Load_3D_Assets (way_start);
  566. WW3DAssetManager::Get_Instance()->Load_3D_Assets (way_mid);
  567. WW3DAssetManager::Get_Instance()->Load_3D_Assets (way_end);
  568. WW3DAssetManager::Get_Instance()->Load_3D_Assets (way_r);
  569. WW3DAssetManager::Get_Instance()->Load_3D_Assets (way_g);
  570. WW3DAssetManager::Get_Instance()->Load_3D_Assets (way_b);
  571. WW3DAssetManager::Get_Instance()->Load_3D_Assets (point_light);
  572. WW3DAssetManager::Get_Instance()->Load_3D_Assets (speaker1);
  573. WW3DAssetManager::Get_Instance()->Load_3D_Assets (speaker2);
  574. WW3DAssetManager::Get_Instance()->Load_3D_Assets (body_box);
  575. WW3DAssetManager::Get_Instance()->Load_3D_Assets (camera_model);
  576. WW3DAssetManager::Get_Instance()->Load_3D_Assets (grid_model);
  577. WW3DAssetManager::Get_Instance()->Load_3D_Assets (trans_box_model);
  578. WW3DAssetManager::Get_Instance()->Load_3D_Assets (dummy_model);
  579. WW3DAssetManager::Get_Instance()->Load_3D_Assets (cover_spot_model);
  580. WW3DAssetManager::Get_Instance()->Load_3D_Assets (building_model);
  581. WW3DAssetManager::Get_Instance()->Load_3D_Assets (carmarker_model);
  582. //
  583. // Build a list of all the textures in the sky and weather directories
  584. //
  585. /*CString path1 = ::Get_File_Mgr()->Make_Full_Path (SKY_DIR);
  586. CString path2 = ::Get_File_Mgr()->Make_Full_Path (WEATHER_DIR);
  587. DynamicVectorClass<CString> file_list;
  588. ::Get_File_Mgr ()->Find_Files (path1, "*.tga", file_list, false);
  589. ::Get_File_Mgr ()->Find_Files (path2, "*.tga", file_list, false);
  590. //
  591. // Preload all of these textures
  592. //
  593. for (int index = 0; index < file_list.Count (); index ++) {
  594. CString &filename = file_list[index];
  595. TextureClass *texture = WW3DAssetManager::Get_Instance()->Get_Texture (filename);
  596. REF_PTR_RELEASE (texture);
  597. }*/
  598. return ;
  599. }
  600. ///////////////////////////////////////////////////////////////
  601. //
  602. // Preload_Human_Data
  603. //
  604. ////////////////////////////////////////////////////////////
  605. void
  606. CLevelEditDoc::Preload_Human_Data (void)
  607. {
  608. //
  609. // Make sure the human skeletons are loaded
  610. //
  611. _pThe3DAssetManager->Load_3D_Assets (HUMAN_SKEL_PATH);
  612. //
  613. // Force load the commando model
  614. //
  615. PresetClass *preset = PresetMgrClass::Find_Typed_Preset (CLASSID_GAME_OBJECT_DEF_SOLDIER, "Commando");
  616. if (preset != NULL) {
  617. preset->Load_All_Assets ();
  618. SoldierGameObj *soldier = (SoldierGameObj *)preset->Get_Definition ()->Create ();
  619. if (soldier != NULL) {
  620. soldier->Set_Delete_Pending ();
  621. }
  622. }
  623. return ;
  624. }
  625. ///////////////////////////////////////////////////////////////
  626. //
  627. // Init_Scene
  628. //
  629. ////////////////////////////////////////////////////////////
  630. void
  631. CLevelEditDoc::Init_Scene (void)
  632. {
  633. if (m_pScene == NULL) {
  634. // Ensure we have the latest core files
  635. Update_Core_Files ();
  636. //
  637. // Add the texture cache to the search path
  638. //
  639. EditorFileFactoryClass::Add_Search_Path (::Get_File_Mgr ()->Get_Texture_Cache_Path ());
  640. //
  641. // Load the global conversations
  642. //
  643. ConversationEditorMgrClass::Get_Latest_Version ();
  644. ConversationEditorMgrClass::Load_Global_Database ();
  645. //
  646. // Make sure we are using the right version of the editor
  647. //
  648. Do_Version_Check ();
  649. //
  650. // Make sure certain *required* assets are loaded into memory...
  651. //
  652. Preload_Assets ();
  653. //
  654. // Instantiate a new scene
  655. //
  656. m_pScene = new SceneEditorClass;
  657. m_pScene->Set_Ambient_Light (DEF_AMBIENT_COLOR);
  658. m_pScene->Update_Lighting ();
  659. m_pScene->Enable_Collision_Detection (0, 0);
  660. }
  661. return ;
  662. }
  663. ///////////////////////////////////////////////////////////////
  664. //
  665. // Get_Coord_System_Transform
  666. //
  667. ///////////////////////////////////////////////////////////////
  668. Matrix3D
  669. CLevelEditDoc::Get_Coord_System_Transform (NodeClass *node)
  670. {
  671. Matrix3D matrix (1);
  672. // What coordinate system are we working in?
  673. switch (m_CoordSystem) {
  674. case CLevelEditDoc::COORD_WORLD:
  675. matrix = Matrix3D (1);
  676. break;
  677. case CLevelEditDoc::COORD_OBJECT:
  678. matrix = node->Get_Transform ();
  679. break;
  680. case CLevelEditDoc::COORD_VIEW:
  681. matrix = ::Get_Camera_Mgr ()->Get_Camera()->Get_Transform ();
  682. break;
  683. }
  684. // Return the matrix
  685. return matrix;
  686. }
  687. ///////////////////////////////////////////////////////////////
  688. //
  689. // OnOpenDocument
  690. //
  691. ///////////////////////////////////////////////////////////////
  692. BOOL
  693. CLevelEditDoc::OnOpenDocument (LPCTSTR path)
  694. {
  695. ::Get_Main_View ()->Allow_Repaint (false);
  696. DWORD start_time = ::GetTickCount ();
  697. //
  698. // Start a new document
  699. //
  700. OnNewDocument ();
  701. //
  702. // Load the level
  703. //
  704. EditorSaveLoadClass::Load_Level (path);
  705. SetModifiedFlag (false);
  706. //
  707. // Reload the conversation page
  708. //
  709. ConversationPageClass *conversation_form = ::Get_Conversation_Form ();
  710. if (conversation_form != NULL) {
  711. conversation_form->Reload_Data ();
  712. }
  713. //
  714. // Load the level load time
  715. //
  716. CString load_time_message;
  717. load_time_message.Format ("Level load took %d seconds\r\n", int((::GetTickCount () - start_time) / 1000));
  718. ::Output_Message (load_time_message);
  719. ::Get_Main_View ()->Allow_Repaint (true);
  720. return TRUE;
  721. }
  722. ///////////////////////////////////////////////////////////////
  723. //
  724. // Set_Current_Path
  725. //
  726. ///////////////////////////////////////////////////////////////
  727. void
  728. CLevelEditDoc::Set_Current_Path (const char *path)
  729. {
  730. m_strPathName = path;
  731. return ;
  732. }
  733. ///////////////////////////////////////////////////////////////
  734. //
  735. // OnSaveDocument
  736. //
  737. ///////////////////////////////////////////////////////////////
  738. BOOL
  739. CLevelEditDoc::OnSaveDocument (LPCTSTR path)
  740. {
  741. theApp.WriteProfileString (CONFIG_KEY,
  742. LAST_SAVE_DIR_VALUE,
  743. ::Strip_Filename_From_Path (path));
  744. // Peform the save operation
  745. EditorSaveLoadClass::Save_Level (path);
  746. return TRUE;
  747. }
  748. ///////////////////////////////////////////////////////////////
  749. //
  750. // Repartition_If_Necessary
  751. //
  752. ///////////////////////////////////////////////////////////////
  753. void
  754. CLevelEditDoc::Repartition_If_Necessary (void)
  755. {
  756. if (m_bNeedRepartition) {
  757. // (gth) can't re-partition the object culling systems
  758. // or we'll lose hierarchical vis...
  759. m_pScene->Re_Partition_Static_Lights ();
  760. m_pScene->Re_Partition_Audio_System ();
  761. m_bNeedRepartition = false;
  762. }
  763. return ;
  764. }
  765. ///////////////////////////////////////////////////////////////
  766. //
  767. // PreCloseFrame
  768. //
  769. ///////////////////////////////////////////////////////////////
  770. void
  771. CLevelEditDoc::PreCloseFrame (CFrameWnd *pFrame)
  772. {
  773. //
  774. // Cleanup any dangling embedded objects
  775. //
  776. PresetMgrClass::Free_All_Embedded_Nodes ();
  777. NetworkObjectMgrClass::Delete_Pending ();
  778. GameObjObserverManager::Delete_Pending ();
  779. ScriptManager::Destroy_Pending ();
  780. return ;
  781. }
  782. //////////////////////////////////////////////////////////////////////////
  783. //
  784. // OnFileSave
  785. //
  786. //////////////////////////////////////////////////////////////////////////
  787. void
  788. CLevelEditDoc::OnFileSave (void)
  789. {
  790. #ifdef PUBLIC_EDITOR_VER
  791. if (m_strPathName.IsEmpty () || ::GetFileAttributes (m_strPathName) == 0xFFFFFFFF) {
  792. //
  793. // Pick a new path and save to it
  794. //
  795. CString full_path;
  796. if (Pick_Save_Path (full_path)) {
  797. Save_Level_File (full_path);
  798. }
  799. } else {
  800. //
  801. // Save to this path
  802. //
  803. Save_Level_File (m_strPathName);
  804. }
  805. #else
  806. CDocument::OnFileSave ();
  807. #endif //PUBLIC_EDITOR_VER
  808. return ;
  809. }
  810. //////////////////////////////////////////////////////////////////////////
  811. //
  812. // OnFileSaveAs
  813. //
  814. //////////////////////////////////////////////////////////////////////////
  815. void
  816. CLevelEditDoc::OnFileSaveAs (void)
  817. {
  818. #ifdef PUBLIC_EDITOR_VER
  819. //
  820. // Pick a new path and save to it
  821. //
  822. CString full_path;
  823. if (Pick_Save_Path (full_path)) {
  824. Save_Level_File (full_path);
  825. }
  826. #else
  827. CDocument::OnFileSaveAs ();
  828. #endif //PUBLIC_EDITOR_VER
  829. return ;
  830. }
  831. //////////////////////////////////////////////////////////////////////////
  832. //
  833. // Pick_Save_Path
  834. //
  835. //////////////////////////////////////////////////////////////////////////
  836. bool
  837. CLevelEditDoc::Pick_Save_Path (CString &save_path)
  838. {
  839. bool retval = false;
  840. //
  841. // Determine which directory we should save to
  842. //
  843. CString full_path = ::Get_File_Mgr ()->Make_Full_Path (LEVELS_ASSET_DIR);
  844. _pThe3DAssetManager->Set_Current_Directory (full_path);
  845. //
  846. // Make a default filename from the name of the document
  847. //
  848. CString default_name = GetTitle ();
  849. if (default_name.GetLength () > 0) {
  850. //default_name += ".lvl";
  851. }
  852. CFileDialog dialog ( FALSE,
  853. ".lvl",
  854. default_name,
  855. OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER,
  856. "Level Editor Files (*.lvl)|*.lvl||",
  857. ::AfxGetMainWnd ());
  858. //
  859. // Set the path, so it opens in the correct directory
  860. //
  861. dialog.m_ofn.lpstrInitialDir = full_path;
  862. //
  863. // Ask the user where they want to save this level
  864. //
  865. if (dialog.DoModal () == IDOK) {
  866. //
  867. // Return the path to the caller
  868. //
  869. retval = true;
  870. save_path = dialog.GetPathName ();
  871. }
  872. return retval;
  873. }
  874. //////////////////////////////////////////////////////////////////////////
  875. //
  876. // Save_Level_File
  877. //
  878. //////////////////////////////////////////////////////////////////////////
  879. void
  880. CLevelEditDoc::Save_Level_File (const char *full_path)
  881. {
  882. //
  883. // Reset the title and change the document name
  884. //
  885. SetPathName (full_path);
  886. //
  887. // Save in level editor format
  888. //
  889. OnSaveDocument (full_path);
  890. //
  891. // Save in game format
  892. //
  893. ExporterClass exporter;
  894. exporter.Export_Level_Only (full_path);
  895. return ;
  896. }