GenerateVisDialog.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. // GenerateVisDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "GenerateVisDialog.h"
  23. #include "GeneratingVisDialog.H"
  24. #include "Utils.H"
  25. #include "SceneEditor.H"
  26. #include "rendobj.h"
  27. #include "phys.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. /////////////////////////////////////////////////////////////////////////////
  34. // GenerateVisDialogClass dialog
  35. GenerateVisDialogClass::GenerateVisDialogClass(CWnd* pParent /*=NULL*/)
  36. : CDialog(GenerateVisDialogClass::IDD, pParent)
  37. {
  38. //{{AFX_DATA_INIT(GenerateVisDialogClass)
  39. //}}AFX_DATA_INIT
  40. }
  41. void GenerateVisDialogClass::DoDataExchange(CDataExchange* pDX)
  42. {
  43. CDialog::DoDataExchange(pDX);
  44. //{{AFX_DATA_MAP(GenerateVisDialogClass)
  45. DDX_Control(pDX, IDC_SAMPLEHEIGHT_SLIDER, m_SampleHeightSlider);
  46. DDX_Control(pDX, IDC_GRANULARITY_SLIDER, m_GranularitySlider);
  47. //}}AFX_DATA_MAP
  48. }
  49. BEGIN_MESSAGE_MAP(GenerateVisDialogClass, CDialog)
  50. //{{AFX_MSG_MAP(GenerateVisDialogClass)
  51. ON_WM_HSCROLL()
  52. //}}AFX_MSG_MAP
  53. END_MESSAGE_MAP()
  54. //////////////////////////////////////////////////////////////////////////////
  55. //
  56. // OnInitDialog
  57. //
  58. //////////////////////////////////////////////////////////////////////////////
  59. BOOL
  60. GenerateVisDialogClass::OnInitDialog (void)
  61. {
  62. CDialog::OnInitDialog ();
  63. m_GranularitySlider.SetRange (1, 32);
  64. m_GranularitySlider.SetPos (16);
  65. SetDlgItemInt (IDC_GRANULARITY_EDIT, 16);
  66. m_SampleHeightSlider.SetRange (1, 20);
  67. m_SampleHeightSlider.SetPos (10);
  68. SetDlgItemInt (IDC_SAMPLEHEIGHT_EDIT, 10);
  69. bool bcheck = ::Get_Scene_Editor ()->Is_Vis_Quick_And_Dirty();
  70. SendDlgItemMessage (IDC_IGNORE_TRANSPARENCY_CHECK, BM_SETCHECK, (WPARAM)bcheck);
  71. return TRUE;
  72. }
  73. //////////////////////////////////////////////////////////////////////////////
  74. //
  75. // OnHScroll
  76. //
  77. //////////////////////////////////////////////////////////////////////////////
  78. void
  79. GenerateVisDialogClass::OnHScroll
  80. (
  81. UINT nSBCode,
  82. UINT nPos,
  83. CScrollBar* pScrollBar
  84. )
  85. {
  86. SetDlgItemInt (IDC_GRANULARITY_EDIT, m_GranularitySlider.GetPos ());
  87. SetDlgItemInt (IDC_SAMPLEHEIGHT_EDIT, m_SampleHeightSlider.GetPos ());
  88. CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
  89. return ;
  90. }
  91. //////////////////////////////////////////////////////////////////////////////
  92. //
  93. // OnOK
  94. //
  95. //////////////////////////////////////////////////////////////////////////////
  96. void
  97. GenerateVisDialogClass::OnOK (void)
  98. {
  99. SceneEditorClass *scene = ::Get_Scene_Editor ();
  100. //
  101. // Enable quick and dirty mode (if necessary)
  102. //
  103. BOOL is_quick_and_dirty = SendDlgItemMessage (IDC_IGNORE_TRANSPARENCY_CHECK, BM_GETCHECK);
  104. scene->Set_Vis_Quick_And_Dirty (is_quick_and_dirty == TRUE);
  105. //
  106. // Read the settings from the dialog
  107. //
  108. BOOL ignore_bias = SendDlgItemMessage (IDC_IGNORE_VIS_BIAS, BM_GETCHECK);
  109. BOOL selection_only = SendDlgItemMessage (IDC_SELECTION_ONLY, BM_GETCHECK);
  110. float granularity = (float)m_GranularitySlider.GetPos ();
  111. float sample_height = (float)m_SampleHeightSlider.GetPos ();
  112. //
  113. // Record the time when the vis preprocessing is started
  114. //
  115. DWORD start_time = ::GetTickCount();
  116. //
  117. // Reset the vis data (which also causes the culling systems to re-partition)
  118. //
  119. if (selection_only != TRUE) {
  120. scene->Reset_Vis(true);
  121. }
  122. //
  123. // Kick off the vis
  124. //
  125. if (SendDlgItemMessage (IDC_USE_EDGE_SAMPLING, BM_GETCHECK) != 0) {
  126. scene->Generate_Edge_Sampled_Vis (granularity, (ignore_bias == TRUE));
  127. } else {
  128. scene->Generate_Uniform_Sampled_Vis (granularity, sample_height, (ignore_bias == TRUE), (selection_only == TRUE));
  129. }
  130. if (selection_only != TRUE) {
  131. //
  132. // Now do the manual vis points ();
  133. //
  134. scene->Generate_Manual_Vis ();
  135. //
  136. // Now vis the light sources
  137. //
  138. scene->Generate_Light_Vis ();
  139. }
  140. //
  141. // Now make sure each dynamic object has updated visibility
  142. //
  143. scene->Reset_Dynamic_Object_Visibility_Status ();
  144. //
  145. // Display the total elapsed time to the user
  146. //
  147. DWORD elapsed_time = ::GetTickCount() - start_time;
  148. int hours = elapsed_time / (1000 * 60 * 60);
  149. elapsed_time -= hours * (1000 * 60 * 60);
  150. int minutes = elapsed_time / (1000 * 60);
  151. elapsed_time -= minutes * (1000 * 60);
  152. int seconds = elapsed_time / 1000;
  153. CString message;
  154. message.Format("Total Elapsed Time: %d hours, %d minutes, %d seconds.",hours,minutes,seconds);
  155. MessageBox (message, "Time", MB_OK | MB_ICONEXCLAMATION);
  156. CDialog::OnOK ();
  157. return ;
  158. }