wbview3d.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. // WbView3d.h
  19. // Class to encapsulate height map.
  20. // Author: Steven Johnson, Aug 2001
  21. #if !defined(AFX_WBVIEW3D_H__832D8241_87F6_11D5_8CE0_00010297BBAC__INCLUDED_)
  22. #define AFX_WBVIEW3D_H__832D8241_87F6_11D5_8CE0_00010297BBAC__INCLUDED_
  23. #if _MSC_VER > 1000
  24. #pragma once
  25. #endif // _MSC_VER > 1000
  26. // wbview3d.h : header file
  27. //
  28. #include "Lib/BaseType.h"
  29. #include "rendobj.h"
  30. #include "robjlist.h"
  31. #include "WbView.h"
  32. #include "common/gameType.h"
  33. #include "common/GlobalData.h"
  34. #include "common/ModelState.h"
  35. #include "dx8wrapper.h"
  36. //#include "GameLogic/Module/BodyModule.h" -- Yikes... not necessary to include this! (KM)
  37. enum BodyDamageType; //Ahhhh much better!
  38. class WorldHeightMap;
  39. class LayerClass;
  40. class IntersectionClass;
  41. class W3DAssetManager;
  42. class SkeletonSceneClass;
  43. class CameraClass;
  44. class WBHeightMap;
  45. class LightClass;
  46. class MapObject;
  47. class DrawObject;
  48. class CWorldBuilderView;
  49. class BuildListInfo;
  50. class TransRenderObj;
  51. struct ID3DXFont;
  52. /////////////////////////////////////////////////////////////////////////////
  53. // WbView3d view
  54. class WbView3d : public WbView, public DX8_CleanupHook
  55. {
  56. protected:
  57. WbView3d(); // protected constructor used by dynamic creation
  58. DECLARE_DYNCREATE(WbView3d)
  59. // Attributes
  60. public:
  61. // DX8_CleanupHook methods
  62. virtual void ReleaseResources(void); ///< Release all dx8 resources so the device can be reset.
  63. virtual void ReAcquireResources(void); ///< Reacquire all resources after device reset.
  64. // Operations
  65. public:
  66. // Overrides
  67. // ClassWizard generated virtual function overrides
  68. //{{AFX_VIRTUAL(WbView3d)
  69. protected:
  70. virtual void OnDraw(CDC* pDC); // overridden to draw this view
  71. //}}AFX_VIRTUAL
  72. // Implementation
  73. protected:
  74. virtual ~WbView3d();
  75. #ifdef _DEBUG
  76. virtual void AssertValid() const;
  77. virtual void Dump(CDumpContext& dc) const;
  78. #endif
  79. // Generated message map functions
  80. protected:
  81. //{{AFX_MSG(WbView3d)
  82. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  83. afx_msg void OnPaint();
  84. afx_msg void OnSize(UINT nType, int cx, int cy);
  85. afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
  86. afx_msg void OnTimer(UINT nIDEvent);
  87. afx_msg void OnDestroy();
  88. afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
  89. afx_msg void OnViewShowwireframe();
  90. afx_msg void OnUpdateViewShowwireframe(CCmdUI* pCmdUI);
  91. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  92. afx_msg void OnViewShowentire3dmap();
  93. afx_msg void OnUpdateViewShowentire3dmap(CCmdUI* pCmdUI);
  94. afx_msg void OnViewShowtopdownview();
  95. afx_msg void OnUpdateViewShowtopdownview(CCmdUI* pCmdUI);
  96. afx_msg void OnViewShowclouds();
  97. afx_msg void OnUpdateViewShowclouds(CCmdUI* pCmdUI);
  98. afx_msg void OnViewShowmacrotexture();
  99. afx_msg void OnUpdateViewShowmacrotexture(CCmdUI* pCmdUI);
  100. afx_msg void OnEditSelectmacrotexture();
  101. afx_msg void OnViewShowshadows();
  102. afx_msg void OnUpdateViewShowshadows(CCmdUI* pCmdUI);
  103. afx_msg void OnViewShowSoftWater();
  104. afx_msg void OnUpdateViewShowSoftWater(CCmdUI* pCmdUI);
  105. afx_msg void OnViewExtraBlends();
  106. afx_msg void OnUpdateViewShowExtraBlends(CCmdUI* pCmdUI);
  107. afx_msg void OnEditShadows();
  108. afx_msg void OnEditMapSettings();
  109. afx_msg void OnViewShowimpassableareas();
  110. afx_msg void OnUpdateViewShowimpassableareas(CCmdUI* pCmdUI);
  111. afx_msg void OnImpassableAreaOptions();
  112. afx_msg void OnViewPartialmapsize96x96();
  113. afx_msg void OnUpdateViewPartialmapsize96x96(CCmdUI* pCmdUI);
  114. afx_msg void OnViewPartialmapsize192x192();
  115. afx_msg void OnUpdateViewPartialmapsize192x192(CCmdUI* pCmdUI);
  116. afx_msg void OnViewPartialmapsize160x160();
  117. afx_msg void OnUpdateViewPartialmapsize160x160(CCmdUI* pCmdUI);
  118. afx_msg void OnViewPartialmapsize128x128();
  119. afx_msg void OnUpdateViewPartialmapsize128x128(CCmdUI* pCmdUI);
  120. afx_msg void OnViewShowModels();
  121. afx_msg void OnUpdateViewShowModels(CCmdUI* pCmdUI);
  122. afx_msg void OnViewBoundingBoxes();
  123. afx_msg void OnUpdateViewBoundingBoxes(CCmdUI* pCmdUI);
  124. afx_msg void OnViewSightRanges();
  125. afx_msg void OnUpdateViewSightRanges(CCmdUI* pCmdUI);
  126. afx_msg void OnViewWeaponRanges();
  127. afx_msg void OnUpdateViewWeaponRanges(CCmdUI* pCmdUI);
  128. afx_msg void OnHighlightTestArt();
  129. afx_msg void OnUpdateHighlightTestArt(CCmdUI* pCmdUI);
  130. afx_msg void OnShowLetterbox();
  131. afx_msg void OnUpdateShowLetterbox(CCmdUI* pCmdUI);
  132. afx_msg void OnViewLayersList();
  133. afx_msg void OnUpdateViewLayersList(CCmdUI* pCmdUI);
  134. afx_msg void OnViewGarrisoned();
  135. afx_msg void OnUpdateViewGarrisoned(CCmdUI* pCmdUI);
  136. afx_msg void OnViewShowMapBoundaries();
  137. afx_msg void OnUpdateViewShowMapBoundaries(CCmdUI* pCmdUI);
  138. afx_msg void OnViewShowAmbientSounds();
  139. afx_msg void OnUpdateViewShowAmbientSounds(CCmdUI* pCmdUI);
  140. afx_msg void OnViewShowSoundCircles();
  141. afx_msg void OnUpdateViewShowSoundCircles(CCmdUI* pCmdUI);
  142. //}}AFX_MSG
  143. DECLARE_MESSAGE_MAP()
  144. private:
  145. HINSTANCE m_hInst;
  146. W3DAssetManager *m_assetManager;
  147. SkeletonSceneClass *m_scene;
  148. SkeletonSceneClass *m_overlayScene;
  149. SkeletonSceneClass *m_baseBuildScene;
  150. SkeletonSceneClass *m_transparentObjectsScene;
  151. CameraClass *m_camera;
  152. WBHeightMap *m_heightMapRenderObj;
  153. RenderObjClass *m_objectToolTrackingObj;
  154. Bool m_showObjToolTrackingObj;
  155. AsciiString m_objectToolTrackingModelName;
  156. Real m_mouseWheelOffset;
  157. Real m_groundLevel;
  158. Coord3D m_cameraOffset;
  159. CPoint m_actualWinSize;
  160. Real m_theta;
  161. Real m_cameraAngle;
  162. Real m_FXPitch;
  163. Bool m_doPitch;
  164. Real m_actualHeightAboveGround; // for camera tool display only
  165. Vector3 m_cameraSource; // for camera tool display only
  166. Vector3 m_cameraTarget; // for camera tool display only
  167. Int m_time;
  168. Int m_updateCount;
  169. UINT m_timer;
  170. DrawObject *m_drawObject;
  171. RefRenderObjListClass m_lightList;
  172. LayerClass *m_layer;
  173. LayerClass *m_buildLayer;
  174. IntersectionClass *m_intersector;
  175. Bool m_showWireframe;
  176. Bool m_ww3dInited;
  177. Bool m_needToLoadRoads;
  178. LightClass *m_globalLight[MAX_GLOBAL_LIGHTS];
  179. RenderObjClass *m_lightFeedbackMesh[MAX_GLOBAL_LIGHTS];
  180. Real m_buildRedMultiplier;
  181. Real m_curTrackingZ;
  182. Bool m_projection; ///< True if top down projection instead of "isometric" perspective.
  183. Bool m_showEntireMap; ///< True if drawing entire map instead of cached fast subset.
  184. Bool m_showShadows; ///< True if drawing shadows.
  185. Bool m_firstPaint; ///< True if we haven't painted yet.
  186. Bool m_showLayersList; ///< Flag whether the layers list is visible or not.
  187. Bool m_showMapBoundaries; ///< Flag whether to show all the map boundaries or not
  188. Bool m_showAmbientSounds; ///< Flag whether to show all the ambient sounds or not
  189. Bool m_showSoundCircles; ///< Flag whether to show the minimum and maximum radii of the ambient sounds attached to the selected object
  190. Bool m_showBoundingBoxes;
  191. Bool m_showSightRanges;
  192. Bool m_showWeaponRanges;
  193. Bool m_highlightTestArt;
  194. Bool m_showLetterbox;
  195. ID3DXFont* m3DFont;
  196. Int m_pickPixels;
  197. Int m_partialMapSize;
  198. protected:
  199. UINT getLastDrawTime();
  200. void init3dScene();
  201. void initAssets();
  202. void initWW3D();
  203. void drawCircle( HDC hdc, const Coord3D & centerPoint, Real radius, COLORREF color );
  204. void drawLabels(HDC hdc);
  205. void drawLabels(void);
  206. void shutdownWW3D();
  207. void killTheTimer();
  208. void render();
  209. void setupCamera();
  210. void updateHysteresis(void);
  211. void updateLights();
  212. void updateScorches();
  213. void updateTrees();
  214. public:
  215. virtual Bool viewToDocCoords(CPoint curPt, Coord3D *newPt, Bool constrain=true);
  216. virtual Bool docToViewCoords(Coord3D curPt, CPoint* newPt);
  217. virtual void updateHeightMapInView(WorldHeightMap *htMap, Bool partial, const IRegion2D &partialRange);
  218. /// Invalidates an object. Pass NULL to inval all objects.
  219. virtual void invalObjectInView(MapObject *pObj);
  220. // find the best model for an object
  221. AsciiString getBestModelName(const ThingTemplate* tt, const ModelConditionFlags& c);
  222. /// Invalidates an build list object.
  223. void invalBuildListItemInView(BuildListInfo *pBuild);
  224. /// Invalidates the area of one height map cell in the 2d view.
  225. virtual void invalidateCellInView(int xIndex, int yIndex);
  226. /// Scrolls the window by this amount.
  227. virtual void scrollInView(Real x, Real y, Bool end);
  228. virtual void setDefaultCamera();
  229. virtual void rotateCamera(Real delta);
  230. virtual void pitchCamera(Real delta);
  231. void setCameraPitch(Real absolutePitch);
  232. Real getCameraPitch(void);
  233. Real getCurrentZoom(void); //WST 10/17/2002
  234. Real getHeightAboveGround(void) { return m_actualHeightAboveGround; }
  235. Vector3 getCameraSource(void) { return m_cameraSource; }
  236. Vector3 getCameraTarget(void) { return m_cameraTarget; }
  237. Real getCameraAngle(void) { return m_cameraAngle; }
  238. CPoint getActualWinSize(void) {return m_actualWinSize;}
  239. virtual MapObject *picked3dObjectInView(CPoint viewPt);
  240. virtual BuildListInfo *pickedBuildObjectInView(CPoint viewPt);
  241. void removeFenceListObjects(MapObject *pObject);
  242. void updateFenceListObjects(MapObject *pObject);
  243. /// Removes all render objects. Call when swithing to a new map.
  244. void resetRenderObjects();
  245. void stepTimeOfDay(void);
  246. void reset3dEngineDisplaySize(Int width, Int height); ///< Closes & reinitializes w3d.
  247. void setLighting(const GlobalData::TerrainLighting *tl, Int whichLighting, Int whichLight=0);
  248. DrawObject *getDrawObject(void) {return m_drawObject;};
  249. AsciiString getModelNameAndScale(MapObject *pMapObj, Real *scale, BodyDamageType curDamageState);
  250. virtual Int getPickPixels(void) {return m_pickPixels;}
  251. virtual Bool viewToDocCoordZ(CPoint curPt, Coord3D *newPt, Real Z);
  252. public:
  253. // void init(CWorldBuilderView *pMainView, HINSTANCE hInstance, CWnd* parent);
  254. void redraw();
  255. virtual void setCenterInView(Real x, Real y);
  256. Bool getShowTerrain();
  257. Bool getShowWireframe();
  258. void setObjTracking(MapObject *pMapObj, Coord3D pos, Real angle, Bool show);
  259. void setViewLayersList(Bool showLayersList) { m_showLayersList = showLayersList; }
  260. Bool getShowMapBoundaryFeedback(void) const { return m_showMapBoundaries; }
  261. Bool getShowAmbientSoundsFeedback(void) const { return m_showAmbientSounds; }
  262. void togglePitchAndRotation( void ) { m_doPitch = !m_doPitch; }
  263. virtual Bool isDoingPitch( void ) { return m_doPitch; }
  264. void setShowBoundingBoxes(Bool toggle) {m_showBoundingBoxes = toggle;}
  265. Bool getShowBoundingBoxes(void) { return m_showBoundingBoxes;}
  266. void setShowSightRanges(Bool toggle) {m_showSightRanges = toggle;}
  267. Bool getShowSightRanges(void) { return m_showSightRanges;}
  268. void setShowWeaponRanges(Bool toggle) {m_showWeaponRanges = toggle;}
  269. Bool getShowWeaponRanges(void) { return m_showWeaponRanges;}
  270. void setHighlightTestArt(Bool toggle) {m_highlightTestArt = toggle;}
  271. Bool getHighlightTestArt(void) { return m_highlightTestArt;}
  272. void setShowLetterbox(Bool toggle) {m_showLetterbox = toggle;}
  273. Bool getShowLetterbox(void) { return m_showLetterbox;}
  274. };
  275. inline UINT WbView3d::getLastDrawTime() { return m_time; }
  276. inline Bool WbView3d::getShowWireframe() { return m_showWireframe; }
  277. /////////////////////////////////////////////////////////////////////////////
  278. //{{AFX_INSERT_LOCATION}}
  279. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  280. #endif // !defined(AFX_WBVIEW3D_H__832D8241_87F6_11D5_8CE0_00010297BBAC__INCLUDED_)