LightSolveProgressDialog.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. // LightSolveProgressDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "LightSolveProgressDialog.h"
  23. #include "utils.h"
  24. #include "sceneeditor.h"
  25. #include "lightsolvecontext.h"
  26. #include "lightsolveprogress.h"
  27. #include "phys.h"
  28. #include "rendobj.h"
  29. #include "lightsolve.h"
  30. #ifdef _DEBUG
  31. #define new DEBUG_NEW
  32. #undef THIS_FILE
  33. static char THIS_FILE[] = __FILE__;
  34. #endif
  35. //////////////////////////////////////////////////////////////////////////
  36. // Progress Callback Object
  37. //////////////////////////////////////////////////////////////////////////
  38. class LSProgressCallbackClass : public LightSolveObserverClass
  39. {
  40. public:
  41. LSProgressCallbackClass(void) { }
  42. ~LSProgressCallbackClass(void) { }
  43. virtual void Progress_Callback(LightSolveContextClass & context)
  44. {
  45. General_Pump_Messages();
  46. };
  47. };
  48. /////////////////////////////////////////////////////////////////////////////
  49. // LightSolveProgressDialog dialog
  50. LightSolveProgressDialog::LightSolveProgressDialog(LightSolveContextClass & context,CWnd* pParent /*=NULL*/)
  51. : m_Cancelled(false),
  52. m_SolveContext(context),
  53. CDialog(LightSolveProgressDialog::IDD, pParent)
  54. {
  55. //{{AFX_DATA_INIT(LightSolveProgressDialog)
  56. // NOTE: the ClassWizard will add member initialization here
  57. //}}AFX_DATA_INIT
  58. return ;
  59. }
  60. void LightSolveProgressDialog::DoDataExchange(CDataExchange* pDX)
  61. {
  62. CDialog::DoDataExchange(pDX);
  63. //{{AFX_DATA_MAP(LightSolveProgressDialog)
  64. DDX_Control(pDX, IDC_PROGRESS_BAR, m_ProgressBar);
  65. //}}AFX_DATA_MAP
  66. }
  67. BEGIN_MESSAGE_MAP(LightSolveProgressDialog, CDialog)
  68. //{{AFX_MSG_MAP(LightSolveProgressDialog)
  69. //}}AFX_MSG_MAP
  70. END_MESSAGE_MAP()
  71. /////////////////////////////////////////////////////////////////////////////
  72. // LightSolveProgressDialog message handlers
  73. /////////////////////////////////////////////////////////////////////////////
  74. //
  75. // OnInitDialog
  76. //
  77. /////////////////////////////////////////////////////////////////////////////
  78. BOOL
  79. LightSolveProgressDialog::OnInitDialog()
  80. {
  81. CDialog::OnInitDialog();
  82. m_ProgressBar.SetRange (0, 100);
  83. SetTimer (777, 250, NULL);
  84. ShowWindow (SW_SHOW);
  85. PostMessage (WM_USER+101);
  86. return TRUE;
  87. }
  88. /////////////////////////////////////////////////////////////////////////////
  89. //
  90. // OnCancel
  91. //
  92. /////////////////////////////////////////////////////////////////////////////
  93. void
  94. LightSolveProgressDialog::OnCancel (void)
  95. {
  96. m_Cancelled = true;
  97. m_SolveContext.Get_Progress().Request_Cancel();
  98. return ;
  99. }
  100. /////////////////////////////////////////////////////////////////////////////
  101. //
  102. // WindowProc
  103. //
  104. /////////////////////////////////////////////////////////////////////////////
  105. LRESULT
  106. LightSolveProgressDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  107. {
  108. if (message == WM_USER+101) {
  109. //
  110. // Kick off the lighting solveoptimization
  111. //
  112. LightSolveClass::Generate_Static_Light_Solve(m_SolveContext);
  113. //
  114. // Cleanup the dialog
  115. //
  116. Set_Finished ();
  117. }
  118. if (message == WM_TIMER) {
  119. Update_Stats ();
  120. }
  121. return CDialog::WindowProc(message, wParam, lParam);
  122. }
  123. /////////////////////////////////////////////////////////////////////////////
  124. //
  125. // Set_Finished
  126. //
  127. /////////////////////////////////////////////////////////////////////////////
  128. void
  129. LightSolveProgressDialog::Set_Finished (void)
  130. {
  131. Update_Stats ();
  132. m_ProgressBar.SetPos (100);
  133. EndDialog (IDOK);
  134. return ;
  135. }
  136. /////////////////////////////////////////////////////////////////////////////
  137. //
  138. // Update_Stats
  139. //
  140. /////////////////////////////////////////////////////////////////////////////
  141. void
  142. LightSolveProgressDialog::Update_Stats (void)
  143. {
  144. ::General_Pump_Messages();
  145. LightSolveProgressClass * progress = &(m_SolveContext.Get_Progress());
  146. //
  147. // Update each of the status fields
  148. //
  149. SetDlgItemInt (IDC_TOTAL_OBJECT_COUNT, progress->Get_Object_Count());
  150. SetDlgItemInt (IDC_CURRENT_OBJECT, progress->Get_Processed_Object_Count());
  151. SetDlgItemText (IDC_CURRENT_MESH_NAME, progress->Get_Current_Mesh_Name());
  152. SetDlgItemInt (IDC_VERTEX_COUNT, progress->Get_Current_Mesh_Vertex_Count());
  153. SetDlgItemInt (IDC_CURRENT_VERTEX, progress->Get_Current_Vertex());
  154. //
  155. // Update the status text
  156. //
  157. int total = progress->Get_Object_Count ();
  158. int current = progress->Get_Processed_Object_Count ();
  159. CString status_text;
  160. status_text.Format ("%d of %d objects solved.", current, total);
  161. SetDlgItemText (IDC_STATUS_TEXT,status_text);
  162. //
  163. // Update the progress bar
  164. //
  165. if (total > 0) {
  166. m_ProgressBar.SetPos ((current * 100) / total);
  167. }
  168. return ;
  169. }
  170. /////////////////////////////////////////////////////////////////////////////
  171. //
  172. // Solve
  173. //
  174. ////////////////////////////////////////////////////////////////////////////
  175. void
  176. LightSolveProgressDialog::Solve (LightSolveContextClass & context,CWnd * parent)
  177. {
  178. //
  179. // Create the callback object
  180. LSProgressCallbackClass callback;
  181. context.Set_Observer(&callback);
  182. //
  183. // Create the dialog
  184. //
  185. LightSolveProgressDialog dialog(context,parent);
  186. dialog.DoModal();
  187. }