SurrenderWnd.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. // SurrenderWnd.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "vidinit.h"
  22. #include "SurrenderWnd.h"
  23. #include <camera.h>
  24. #include <scene.h>
  25. #include <ww3d.h>
  26. #include <assetmgr.h>
  27. #include <rawfile.h>
  28. #include <rendobj.h>
  29. #include <hanim.h>
  30. #include <txt2d.h>
  31. #include "convert.h"
  32. #include "defpal.h"
  33. #include "deffont.h"
  34. #include <bsurface.h>
  35. #ifdef _DEBUG
  36. #define new DEBUG_NEW
  37. #undef THIS_FILE
  38. static char THIS_FILE[] = __FILE__;
  39. #endif
  40. static WW3DAssetManager AssetManager;
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CSurrenderWnd
  43. CSurrenderWnd::CSurrenderWnd(CWnd *cwnd, int driver, int width, int height, int bitdepth, bool run_in_window) :
  44. m_CWnd(cwnd),
  45. m_Motion(0),
  46. m_Camera(0),
  47. m_Scene(0),
  48. m_RObj(0),
  49. m_FrameRate(60)
  50. {
  51. LPCTSTR str = AfxRegisterWndClass(CS_NOCLOSE, NULL, NULL, NULL);
  52. if (run_in_window) {
  53. CreateEx(0, str, "Card Test Window", WS_SYSMENU | WS_MINIMIZEBOX | WS_CAPTION|WS_VISIBLE, 0,0,640,480, NULL, NULL, NULL);
  54. } else {
  55. CreateEx(0, str, "Card Test Window", WS_SYSMENU | WS_MINIMIZEBOX | WS_CAPTION|WS_VISIBLE, 0,0,640,480, NULL, NULL, NULL);
  56. }
  57. WW3D::Set_Window(GetSafeHwnd());
  58. m_SubClass = GetWindowLong(GetSafeHwnd(), GWL_WNDPROC);
  59. WW3D::Set_Render_Device(driver, width, height, bitdepth, run_in_window, true);
  60. AssetManager.Set_WW3D_Load_On_Demand(true);
  61. // WW3D::Set_Ext_Swap_Interval(1);
  62. m_Scene = new SimpleSceneClass();
  63. m_TextScene = new SimpleSceneClass();
  64. m_Camera = new CameraClass();
  65. m_Camera->Set_Transform(Matrix3D(1));
  66. m_Camera->Set_Clip_Planes(1.0f, 1000000.0f);
  67. m_Camera->Set_View_Plane(DEG_TO_RAD(45.0f), DEG_TO_RAD(33.0f));
  68. m_TextCamera = NEW_REF(CameraClass, ());
  69. m_TextCamera->Set_View_Plane(Vector2(-1,-1), Vector2(1,1));
  70. m_TextCamera->Set_Position(Vector3(0,0,1));
  71. m_TextCamera->Set_Clip_Planes(0.1, 10.0);
  72. m_RObj = AssetManager.Create_Render_Obj("vidtest");
  73. m_RObj->Set_Transform(Matrix3D(1));
  74. m_Motion = AssetManager.Get_HAnim("vidtest1.vidtest1");
  75. m_MotionTime = GetTickCount();
  76. // m_RObj->Set_Animation(m_Motion, 0.0f, RenderObjClass::ANIM_MODE_MANUAL);
  77. m_RObj->Add(m_Scene);
  78. m_Text = new Text2DObjClass(DefaultFont, "Frame rate = %d", 0, 0, 15, 0, DefaultConvert, false, false, m_FrameRate);
  79. m_Text->Add(m_TextScene);
  80. }
  81. CSurrenderWnd::~CSurrenderWnd()
  82. {
  83. if (m_RObj) {
  84. m_RObj->Set_Animation();
  85. m_RObj->Release_Ref();
  86. }
  87. if (m_Camera) m_Camera->Release_Ref();
  88. if (m_Motion) m_Motion->Release_Ref();
  89. if (m_Text) m_Text->Release_Ref();
  90. if (m_TextCamera) m_TextCamera->Release_Ref();
  91. if (m_Scene) m_Scene->Release_Ref();
  92. if (m_TextScene) m_TextScene->Release_Ref();
  93. AssetManager.Free_Assets();
  94. }
  95. BEGIN_MESSAGE_MAP(CSurrenderWnd, CWnd)
  96. //{{AFX_MSG_MAP(CSurrenderWnd)
  97. ON_WM_PAINT()
  98. ON_WM_CLOSE()
  99. ON_WM_KEYDOWN()
  100. ON_WM_ACTIVATEAPP()
  101. //}}AFX_MSG_MAP
  102. END_MESSAGE_MAP()
  103. /////////////////////////////////////////////////////////////////////////////
  104. // CSurrenderWnd message handlers
  105. void CSurrenderWnd::OnPaint()
  106. {
  107. // CPaintDC dc(this); // device context for painting
  108. WW3D::Sync(GetTickCount());
  109. if (m_Motion && m_RObj) {
  110. float rate = m_Motion->Get_Frame_Rate();
  111. // figure out what the current frame is
  112. float currentframe = (GetTickCount() - m_MotionTime) / (1000 / rate);
  113. float numframes = m_Motion->Get_Num_Frames() - 1;
  114. currentframe = fmod(currentframe, numframes);
  115. float frame_rate = 1.0f / (WW3D::Get_Frame_Time() * 0.001f);
  116. m_FrameRate = (0.9f * m_FrameRate) + (0.1f * frame_rate);
  117. m_Text->Set_Text(DefaultFont, "Frame rate = %d", 0, 0, 15, 0, DefaultConvert, false, false, m_FrameRate);
  118. m_RObj->Set_Animation(m_Motion, currentframe);
  119. Matrix3D m = m_RObj->Get_Bone_Transform("camera");
  120. m.Rotate_Y(DEG_TO_RAD(-90.0f));
  121. m.Rotate_Z(DEG_TO_RAD(-90.0f));
  122. m_Camera->Set_Transform(m);
  123. }
  124. // Do not call CWnd::OnPaint() for painting messages
  125. if (!IsIconic()) {
  126. WW3D::Begin_Render(true, true, Vector3(0.0f,0,0));
  127. WW3D::Render(m_Scene, m_Camera, false, false, Vector3(0,0,0));
  128. WW3D::Render(m_TextScene, m_TextCamera, false, false, Vector3(0,0,0));
  129. WW3D::End_Render();
  130. }
  131. }
  132. void CSurrenderWnd::RemoveSubclass()
  133. {
  134. ::SetWindowLong(GetSafeHwnd(), GWL_WNDPROC, m_SubClass);
  135. }
  136. void CSurrenderWnd::OnClose()
  137. {
  138. // TODO: Add your message handler code here and/or call default
  139. CWnd::OnClose();
  140. delete this;
  141. }
  142. void CSurrenderWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  143. {
  144. // TODO: Add your message handler code here and/or call default
  145. if (nChar == VK_ESCAPE) {
  146. m_CWnd->PostMessage(WM_USER + 1, 0xDEADBEEF, 0xDEADBEEF);
  147. } else {
  148. CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
  149. }
  150. }