W3DView.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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. // W3DView.cpp : Defines the class behaviors for the application.
  19. //
  20. #include "stdafx.h"
  21. #include "w3dview.h"
  22. #include "mainfrm.h"
  23. #include "w3dviewdoc.h"
  24. #include "w3dviewview.h"
  25. #include "utils.h"
  26. #include "colorutils.h"
  27. #include "verchk.h"
  28. #include "wwmath.h"
  29. #include "wwaudio.h"
  30. #include "viewerassetmgr.h"
  31. #include "globals.h"
  32. #include "animatedsoundoptionsdialog.h"
  33. #include "animatedsoundmgr.h"
  34. #undef STRICT
  35. #include "ww3d.h"
  36. #include "AssetMgr.H"
  37. #ifdef _DEBUG
  38. #define new DEBUG_NEW
  39. #undef THIS_FILE
  40. static char THIS_FILE[] = __FILE__;
  41. #endif
  42. /////////////////////////////////////////////////////////////////////////////
  43. //
  44. // Local prototypes
  45. //
  46. BOOL CALLBACK fnTopLevelWindowSearch (HWND hwnd, LPARAM lParam);
  47. /////////////////////////////////////////////////////////////////////////////
  48. //
  49. // CW3DViewApp
  50. //
  51. BEGIN_MESSAGE_MAP(CW3DViewApp, CWinApp)
  52. //{{AFX_MSG_MAP(CW3DViewApp)
  53. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  54. // NOTE - the ClassWizard will add and remove mapping macros here.
  55. // DO NOT EDIT what you see in these blocks of generated code!
  56. //}}AFX_MSG_MAP
  57. // Standard file based document commands
  58. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  59. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  60. END_MESSAGE_MAP()
  61. /////////////////////////////////////////////////////////////////////////////
  62. //
  63. // CW3DViewApp construction
  64. //
  65. CW3DViewApp::CW3DViewApp (void)
  66. : m_bInitialized (false)
  67. {
  68. // TODO: add construction code here,
  69. // Place all significant initialization in InitInstance
  70. }
  71. /////////////////////////////////////////////////////////////////////////////
  72. // The one and only CW3DViewApp object
  73. CW3DViewApp theApp;
  74. extern int AFXAPI AfxWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow);
  75. int WINAPI
  76. WinMain
  77. (
  78. HINSTANCE hInstance,
  79. HINSTANCE hPrevInstance,
  80. LPTSTR lpCmdLine,
  81. int nCmdShow
  82. )
  83. {
  84. int retcode = 0;
  85. #ifndef _DEBUG
  86. try
  87. {
  88. #endif //_DEBUG
  89. //::AfxWinInit (hInstance, hPrevInstance, lpCmdLine, nCmdShow);
  90. //::AfxInitialize (FALSE, _MFC_VER);
  91. AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
  92. pModuleState->m_bDLL = (BYTE)FALSE;
  93. #ifdef _MBCS
  94. // set correct multi-byte code-page for Win32 apps
  95. _setmbcp(_MB_CP_ANSI);
  96. #endif //_MBCS
  97. retcode = ::AfxWinMain (hInstance, hPrevInstance, lpCmdLine, nCmdShow);
  98. #ifndef _DEBUG
  99. }
  100. catch (...)
  101. {
  102. ::MessageBox (NULL, "Internal Application Error", "Unrecoverable Error", MB_ICONERROR | MB_OK);
  103. }
  104. #endif //_DEBUG
  105. return retcode;
  106. }
  107. ///////////////////////////////////////////////////////////////
  108. //
  109. // Do_Version_Check
  110. //
  111. ////////////////////////////////////////////////////////////
  112. void
  113. Do_Version_Check (void)
  114. {
  115. char curr_filename[MAX_PATH];
  116. ::GetModuleFileName (NULL, curr_filename, MAX_PATH);
  117. CString filename = "\\\\cabal\\mis\\r&d\\w3d\\w3dview\\";
  118. filename += ::Get_Filename_From_Path (curr_filename);
  119. //
  120. // Check the version of the viewer that is out on the network
  121. // against the version we are running.
  122. //
  123. if (Compare_EXE_Version ((int)::AfxGetInstanceHandle (), filename) < 0) {
  124. ::MessageBox (NULL, "There is a newer version of the W3DViewer, please run W3DUpdate to upgrade your local copy.", "Version Info", MB_ICONEXCLAMATION | MB_OK | MB_SETFOREGROUND | MB_SYSTEMMODAL);
  125. }
  126. return ;
  127. }
  128. /////////////////////////////////////////////////////////////////////////////
  129. //
  130. // InitInstance
  131. //
  132. BOOL CW3DViewApp::InitInstance (void)
  133. {
  134. // Standard initialization
  135. // If you are not using these features and wish to reduce the size
  136. // of your final executable, you should remove from the following
  137. // the specific initialization routines you do not need.
  138. #ifdef _AFXDLL
  139. Enable3dControls(); // Call this when using MFC in a shared DLL
  140. #else
  141. Enable3dControlsStatic(); // Call this when linking to MFC statically
  142. #endif
  143. Do_Version_Check ();
  144. RegisterColorPicker (::AfxGetInstanceHandle ());
  145. RegisterColorBar (::AfxGetInstanceHandle ());
  146. // Is there already an instance of the viewer running?
  147. HWND hprev_instance = NULL;
  148. ::EnumWindows (fnTopLevelWindowSearch, (LPARAM)&hprev_instance);
  149. if (hprev_instance == NULL) {
  150. // Change the registry key under which our settings are stored.
  151. // You should modify this string to be something appropriate
  152. // such as the name of your company or organization.
  153. SetRegistryKey(_T("Westwood Studios"));
  154. //
  155. // Load standard INI file options (including MRU)
  156. //
  157. LoadStdProfileSettings (9);
  158. //
  159. // Initialize the libraries
  160. //
  161. WWMath::Init ();
  162. AnimatedSoundOptionsDialogClass::Load_Animated_Sound_Settings ();
  163. //
  164. // Disable the 3DFX logo
  165. //
  166. _putenv ("FX_GLIDE_NO_SPLASH=1");
  167. // Register the application's document templates. Document templates
  168. // serve as the connection between documents, frame windows and views.
  169. CSingleDocTemplate* pDocTemplate;
  170. pDocTemplate = new CSingleDocTemplate(
  171. IDR_MAINFRAME,
  172. RUNTIME_CLASS(CW3DViewDoc),
  173. RUNTIME_CLASS(CMainFrame), // main SDI frame window
  174. RUNTIME_CLASS(CW3DViewView));
  175. AddDocTemplate(pDocTemplate);
  176. // Enable DDE Execute open
  177. EnableShellOpen();
  178. RegisterShellFileTypes(TRUE);
  179. // Parse command line for standard shell commands, DDE, file open
  180. CCommandLineInfo cmdInfo;
  181. ParseCommandLine(cmdInfo);
  182. //
  183. // Allocate an asset manager
  184. //
  185. _TheAssetMgr = new ViewerAssetMgrClass;
  186. // Dispatch commands specified on the command line
  187. if (!ProcessShellCommand(cmdInfo))
  188. return FALSE;
  189. // The one and only window has been initialized, so show and update it.
  190. m_pMainWnd->ShowWindow(SW_SHOW);
  191. m_pMainWnd->UpdateWindow();
  192. ::SetProp (*m_pMainWnd, "WW3DVIEWER", (HANDLE)1);
  193. // Enable drag/drop open
  194. m_pMainWnd->DragAcceptFiles();
  195. m_bInitialized = true;
  196. } else {
  197. // Make the previous instance in the foreground
  198. ::ShowWindow (hprev_instance, SW_NORMAL);
  199. ::BringWindowToTop (hprev_instance);
  200. ::SetForegroundWindow (hprev_instance);
  201. }
  202. return (hprev_instance == NULL);
  203. }
  204. /////////////////////////////////////////////////////////////////////////////
  205. // CAboutDlg dialog used for App About
  206. class CAboutDlg : public CDialog
  207. {
  208. public:
  209. CAboutDlg();
  210. // Dialog Data
  211. //{{AFX_DATA(CAboutDlg)
  212. enum { IDD = IDD_ABOUTBOX };
  213. //}}AFX_DATA
  214. // ClassWizard generated virtual function overrides
  215. //{{AFX_VIRTUAL(CAboutDlg)
  216. protected:
  217. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  218. //}}AFX_VIRTUAL
  219. // Implementation
  220. protected:
  221. //{{AFX_MSG(CAboutDlg)
  222. virtual BOOL OnInitDialog();
  223. //}}AFX_MSG
  224. DECLARE_MESSAGE_MAP()
  225. };
  226. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  227. {
  228. //{{AFX_DATA_INIT(CAboutDlg)
  229. //}}AFX_DATA_INIT
  230. }
  231. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  232. {
  233. CDialog::DoDataExchange(pDX);
  234. //{{AFX_DATA_MAP(CAboutDlg)
  235. //}}AFX_DATA_MAP
  236. }
  237. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  238. //{{AFX_MSG_MAP(CAboutDlg)
  239. //}}AFX_MSG_MAP
  240. END_MESSAGE_MAP()
  241. // App command to run the dialog
  242. void CW3DViewApp::OnAppAbout()
  243. {
  244. CAboutDlg aboutDlg;
  245. aboutDlg.DoModal();
  246. }
  247. /*
  248. **
  249. */
  250. void Debug_Refs(void)
  251. {
  252. #ifndef NDEBUG
  253. TRACE("Detecting Active Refs...\r\n");
  254. //ODS("At time %s", cMiscUtil::Get_Text_Time());
  255. RefCountNodeClass * first = RefCountClass::ActiveRefList.First();
  256. RefCountNodeClass * node = first;
  257. while (node->Is_Valid())
  258. {
  259. RefCountClass * obj = node->Get();
  260. ActiveRefStruct * ref = &(obj->ActiveRefInfo);
  261. bool display = true;
  262. int count = 0;
  263. RefCountNodeClass * search = first;
  264. while (search->Is_Valid()) {
  265. if (search == node) { // if this is not the first one
  266. if (count != 0) {
  267. display = false;
  268. break;
  269. }
  270. }
  271. RefCountClass * search_obj = search->Get();
  272. ActiveRefStruct * search_ref = &(search_obj->ActiveRefInfo);
  273. if ( ref->File && search_ref->File &&
  274. !strcmp(search_ref->File, ref->File) &&
  275. (search_ref->Line == ref->Line) ) {
  276. count++;
  277. } else if ( (ref->File == NULL) && (search_ref->File == NULL) ) {
  278. count++;
  279. }
  280. search = search->Next();
  281. }
  282. if ( display ) {
  283. TRACE ( "%d Active Ref: %s %d %p\n", count, ref->File,ref->Line,obj);
  284. static int num_printed = 0;
  285. if (++num_printed > 20) {
  286. TRACE( "And Many More......\n");
  287. break;
  288. }
  289. }
  290. node = node->Next();
  291. }
  292. TRACE("Done.\r\n");
  293. //ODS("At time %s", cMiscUtil::Get_Text_Time());
  294. #endif
  295. }
  296. /////////////////////////////////////////////////////////////////////////////
  297. //
  298. // CW3DViewApp
  299. //
  300. int
  301. CW3DViewApp::ExitInstance()
  302. {
  303. //
  304. // Free any resources the WW3D engine allocated
  305. //
  306. if (m_bInitialized) {
  307. //
  308. // Shutdown the audio system
  309. //
  310. WWAudioClass::Get_Instance ()->Shutdown ();
  311. //
  312. // Shutdown W3D
  313. //
  314. WW3DAssetManager::Get_Instance()->Free_Assets ();
  315. WW3D::Shutdown ();
  316. //
  317. // Shutdown the libraries
  318. //
  319. WWMath::Shutdown ();
  320. AnimatedSoundMgrClass::Shutdown ();
  321. //
  322. // Free the asset manager
  323. //
  324. delete _TheAssetMgr;
  325. _TheAssetMgr = NULL;
  326. }
  327. Debug_Refs ();
  328. return CWinApp::ExitInstance ();
  329. }
  330. //////////////////////////////////////////////////////////////////////////////
  331. //
  332. // fnTopLevelWindowSearch
  333. //
  334. BOOL CALLBACK
  335. fnTopLevelWindowSearch
  336. (
  337. HWND hwnd,
  338. LPARAM lParam
  339. )
  340. {
  341. BOOL bcontinue = TRUE;
  342. // Is this a viewer window?
  343. if (::GetProp (hwnd, "WW3DVIEWER") != 0) {
  344. bcontinue = false;
  345. (*((HWND *)lParam)) = hwnd;
  346. }
  347. // Return the TRUE/FALSE result code
  348. return bcontinue;
  349. }
  350. //////////////////////////////////////////////////////////////////////////////
  351. //
  352. // OnInitDialog
  353. //
  354. BOOL
  355. CAboutDlg::OnInitDialog (void)
  356. {
  357. // Allow the base class to process this message
  358. CDialog::OnInitDialog ();
  359. // Version 1.0 by default
  360. DWORD version_major = 1;
  361. DWORD version_minor = 0;
  362. // Get the name and path of the currently executing application
  363. TCHAR filename[MAX_PATH];
  364. ::GetModuleFileName (NULL, filename, sizeof (filename));
  365. // Get the version information for this file
  366. DWORD dummy_var = 0;
  367. DWORD version_size = ::GetFileVersionInfoSize (filename, &dummy_var);
  368. if (version_size > 0) {
  369. // Get the file version block
  370. LPBYTE pblock = new BYTE[version_size];
  371. if (::GetFileVersionInfo (filename, 0L, version_size, pblock)) {
  372. // Query the block for the file version information
  373. UINT version_len = 0;
  374. VS_FIXEDFILEINFO *pversion_info = NULL;
  375. if (::VerQueryValue (pblock, "\\", (LPVOID *)&pversion_info, &version_len)) {
  376. version_major = pversion_info->dwFileVersionMS;
  377. version_minor = pversion_info->dwFileVersionLS;
  378. }
  379. }
  380. SAFE_DELETE (pblock);
  381. }
  382. // Put the version string into the dialog
  383. CString version_string;
  384. version_string.Format (IDS_VERSION, (version_major >> 16), (version_major & 0xFFFF));
  385. SetDlgItemText (IDC_VERSION, version_string);
  386. return TRUE;
  387. }