OptimizingVisDialog.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. // OptimizingVisDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "optimizingvisdialog.h"
  23. #include "utils.h"
  24. #include "sceneeditor.h"
  25. #include "rendobj.h"
  26. #include "phys.h"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. //////////////////////////////////////////////////////////////////////////
  33. // Local Prototypes
  34. //////////////////////////////////////////////////////////////////////////
  35. static UINT fnOptimizeVisDialogThread (DWORD dwparam1, DWORD dwparam2, DWORD, HRESULT *, HWND *);
  36. /////////////////////////////////////////////////////////////////////////////
  37. //
  38. // OptimizingVisDialogClass
  39. //
  40. /////////////////////////////////////////////////////////////////////////////
  41. OptimizingVisDialogClass::OptimizingVisDialogClass(CWnd *parent)
  42. : m_Cancelled (false),
  43. m_ProgressStats (NULL),
  44. CDialog(OptimizingVisDialogClass::IDD, parent)
  45. {
  46. //{{AFX_DATA_INIT(OptimizingVisDialogClass)
  47. // NOTE: the ClassWizard will add member initialization here
  48. //}}AFX_DATA_INIT
  49. Create (OptimizingVisDialogClass::IDD, parent);
  50. return ;
  51. }
  52. /////////////////////////////////////////////////////////////////////////////
  53. //
  54. // DoDataExchange
  55. //
  56. /////////////////////////////////////////////////////////////////////////////
  57. void
  58. OptimizingVisDialogClass::DoDataExchange (CDataExchange *pDX)
  59. {
  60. CDialog::DoDataExchange (pDX);
  61. //{{AFX_DATA_MAP(OptimizingVisDialogClass)
  62. DDX_Control(pDX, IDC_PROGRESS_BAR, m_ProgressBar);
  63. //}}AFX_DATA_MAP
  64. return ;
  65. }
  66. BEGIN_MESSAGE_MAP(OptimizingVisDialogClass, CDialog)
  67. //{{AFX_MSG_MAP(OptimizingVisDialogClass)
  68. //}}AFX_MSG_MAP
  69. END_MESSAGE_MAP()
  70. /////////////////////////////////////////////////////////////////////////////
  71. //
  72. // OnInitDialog
  73. //
  74. /////////////////////////////////////////////////////////////////////////////
  75. BOOL
  76. OptimizingVisDialogClass::OnInitDialog (void)
  77. {
  78. CDialog::OnInitDialog ();
  79. m_ProgressBar.SetRange (0, 100);
  80. SetTimer (777, 1000, NULL);
  81. return TRUE;
  82. }
  83. /////////////////////////////////////////////////////////////////////////////
  84. //
  85. // OnCancel
  86. //
  87. /////////////////////////////////////////////////////////////////////////////
  88. void
  89. OptimizingVisDialogClass::OnCancel (void)
  90. {
  91. KillTimer (777);
  92. ::DestroyWindow (m_hWnd);
  93. ::PostQuitMessage (0);
  94. return ;
  95. }
  96. /////////////////////////////////////////////////////////////////////////////
  97. //
  98. // WindowProc
  99. //
  100. /////////////////////////////////////////////////////////////////////////////
  101. LRESULT
  102. OptimizingVisDialogClass::WindowProc
  103. (
  104. UINT message,
  105. WPARAM wParam,
  106. LPARAM lParam
  107. )
  108. {
  109. if (message == WM_TIMER) {
  110. Update_Stats ();
  111. }
  112. return CDialog::WindowProc (message, wParam, lParam);
  113. }
  114. /////////////////////////////////////////////////////////////////////////////
  115. //
  116. // Update_Stats
  117. //
  118. /////////////////////////////////////////////////////////////////////////////
  119. void
  120. OptimizingVisDialogClass::Update_Stats (void)
  121. {
  122. if (m_ProgressStats == NULL) {
  123. return ;
  124. }
  125. //
  126. // Update each of the status fields
  127. //
  128. SetDlgItemInt (IDC_INITIAL_BIT_COUNT_TEXT, m_ProgressStats->Get_Initial_Bit_Count ());
  129. SetDlgItemInt (IDC_INITIAL_SECTOR_COUNT_TEXT, m_ProgressStats->Get_Initial_Sector_Count ());
  130. SetDlgItemInt (IDC_FINAL_BIT_COUNT_TEXT, m_ProgressStats->Get_Final_Bit_Count ());
  131. SetDlgItemInt (IDC_FINAL_SECTOR_COUNT_TEXT, m_ProgressStats->Get_Final_Sector_Count ());
  132. SetDlgItemInt (IDC_INITIAL_OBJECT_COUNT_TEXT, m_ProgressStats->Get_Initial_Object_Count ());
  133. SetDlgItemInt (IDC_FINAL_OBJECT_COUNT_TEXT, m_ProgressStats->Get_Final_Object_Count ());
  134. SetDlgItemInt (IDC_INITIAL_DYNAMIC_CELL_COUNT_TEXT, m_ProgressStats->Get_Initial_Dynamic_Cell_Count ());
  135. SetDlgItemInt (IDC_FINAL_DYNAMIC_CELL_COUNT_TEXT, m_ProgressStats->Get_Final_Dynamic_Cell_Count ());
  136. SetDlgItemInt (IDC_DYNAMIC_CELLS_REMOVED_COUNT_TEXT, m_ProgressStats->Get_Dynamic_Cells_Removed ());
  137. SetDlgItemInt (IDC_OBJECTS_MERGED_TEXT, m_ProgressStats->Get_Objects_Merged ());
  138. SetDlgItemInt (IDC_SECTORS_MERGED_TEXT, m_ProgressStats->Get_Sectors_Merged ());
  139. //
  140. // Update the status text
  141. //
  142. int total = m_ProgressStats->Get_Total_Operation_Count ();
  143. int current = m_ProgressStats->Get_Completed_Operation_Count ();
  144. CString status_text;
  145. status_text.Format ("%d of %d operations completed.", current, total);
  146. SetDlgItemText (IDC_STATUS_TEXT,status_text);
  147. //
  148. // Update the progress bar
  149. //
  150. if (total > 0) {
  151. m_ProgressBar.SetPos ((current * 100) / total);
  152. }
  153. return ;
  154. }
  155. /////////////////////////////////////////////////////////////////////////////
  156. //
  157. // Set_Finished
  158. //
  159. /////////////////////////////////////////////////////////////////////////////
  160. void
  161. OptimizingVisDialogClass::Set_Finished (void)
  162. {
  163. ::EnableWindow (::GetDlgItem (m_hWnd, IDCANCEL), TRUE);
  164. Update_Stats ();
  165. m_ProgressBar.SetPos (100);
  166. return ;
  167. }
  168. /////////////////////////////////////////////////////////////////////////////
  169. //
  170. // Optimize
  171. //
  172. /////////////////////////////////////////////////////////////////////////////
  173. void
  174. OptimizingVisDialogClass::Optimize (void)
  175. {
  176. OptimizingVisDialogClass *dialog = NULL;
  177. VisOptProgressClass stats;
  178. //
  179. // Create the dialog on a separate thread
  180. //
  181. ::Create_UI_Thread (fnOptimizeVisDialogThread, 0, (DWORD)&dialog, 0, NULL, NULL);
  182. dialog->Set_Status_Object (&stats);
  183. //
  184. // Kick off the optimization
  185. //
  186. ::Get_Scene_Editor ()->Optimize_Visibility_Data (stats);
  187. //
  188. // Now make sure each dynamic object has updated visibility
  189. //
  190. ::Get_Scene_Editor ()->Reset_Dynamic_Object_Visibility_Status ();
  191. //
  192. // Cleanup the dialog
  193. //
  194. dialog->Set_Finished ();
  195. dialog->Set_Status_Object (NULL);
  196. return ;
  197. }
  198. /////////////////////////////////////////////////////////////////////////////
  199. //
  200. // fnOptimizeVisDialogThread
  201. //
  202. ////////////////////////////////////////////////////////////////////////////
  203. UINT
  204. fnOptimizeVisDialogThread
  205. (
  206. DWORD dwparam1,
  207. DWORD dwparam2,
  208. DWORD /*dwparam3*/,
  209. HRESULT* /*presult*/,
  210. HWND* /*phmain_wnd*/
  211. )
  212. {
  213. OptimizingVisDialogClass *dialog = new OptimizingVisDialogClass (NULL); //::AfxGetMainWnd ());
  214. dialog->ShowWindow (SW_SHOW);
  215. //
  216. // Return the dialog object to the caller
  217. //
  218. OptimizingVisDialogClass **return_val = (OptimizingVisDialogClass **)dwparam2;
  219. if (return_val != NULL) {
  220. (*return_val) = dialog;
  221. }
  222. return 1;
  223. }
  224. /////////////////////////////////////////////////////////////////////////////
  225. //
  226. // OptimizingVisDialogClass::Set_Status_Object
  227. //
  228. ////////////////////////////////////////////////////////////////////////////
  229. void
  230. OptimizingVisDialogClass::Set_Status_Object (VisOptProgressClass *status_object)
  231. {
  232. m_ProgressStats = status_object;
  233. Update_Stats();
  234. return ;
  235. }