wbview3d.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*
  2. ** Command & Conquer Generals(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 OnLookEast();
  102. afx_msg void OnUpdateLookEast(CCmdUI* pCmdUI);
  103. afx_msg void OnLookNorth();
  104. afx_msg void OnUpdateLookNorth(CCmdUI* pCmdUI);
  105. afx_msg void OnLookSouth();
  106. afx_msg void OnUpdateLookSouth(CCmdUI* pCmdUI);
  107. afx_msg void OnLookWest();
  108. afx_msg void OnUpdateLookWest(CCmdUI* pCmdUI);
  109. afx_msg void OnViewShowshadows();
  110. afx_msg void OnUpdateViewShowshadows(CCmdUI* pCmdUI);
  111. afx_msg void OnViewShowSoftWater();
  112. afx_msg void OnUpdateViewShowSoftWater(CCmdUI* pCmdUI);
  113. afx_msg void OnViewExtraBlends();
  114. afx_msg void OnUpdateViewShowExtraBlends(CCmdUI* pCmdUI);
  115. afx_msg void OnEditShadows();
  116. afx_msg void OnEditMapSettings();
  117. afx_msg void OnViewShowimpassableareas();
  118. afx_msg void OnUpdateViewShowimpassableareas(CCmdUI* pCmdUI);
  119. afx_msg void OnImpassableAreaOptions();
  120. afx_msg void OnViewPartialmapsize96x96();
  121. afx_msg void OnUpdateViewPartialmapsize96x96(CCmdUI* pCmdUI);
  122. afx_msg void OnViewPartialmapsize192x192();
  123. afx_msg void OnUpdateViewPartialmapsize192x192(CCmdUI* pCmdUI);
  124. afx_msg void OnViewPartialmapsize160x160();
  125. afx_msg void OnUpdateViewPartialmapsize160x160(CCmdUI* pCmdUI);
  126. afx_msg void OnViewPartialmapsize128x128();
  127. afx_msg void OnUpdateViewPartialmapsize128x128(CCmdUI* pCmdUI);
  128. afx_msg void OnViewShowModels();
  129. afx_msg void OnUpdateViewShowModels(CCmdUI* pCmdUI);
  130. afx_msg void OnViewLayersList();
  131. afx_msg void OnUpdateViewLayersList(CCmdUI* pCmdUI);
  132. afx_msg void OnViewGarrisoned();
  133. afx_msg void OnUpdateViewGarrisoned(CCmdUI* pCmdUI);
  134. afx_msg void OnViewShowMapBoundaries();
  135. afx_msg void OnUpdateViewShowMapBoundaries(CCmdUI* pCmdUI);
  136. afx_msg void OnViewShowAmbientSounds();
  137. afx_msg void OnUpdateViewShowAmbientSounds(CCmdUI* pCmdUI);
  138. //}}AFX_MSG
  139. DECLARE_MESSAGE_MAP()
  140. private:
  141. HINSTANCE m_hInst;
  142. W3DAssetManager *m_assetManager;
  143. SkeletonSceneClass *m_scene;
  144. SkeletonSceneClass *m_overlayScene;
  145. SkeletonSceneClass *m_baseBuildScene;
  146. SkeletonSceneClass *m_transparentObjectsScene;
  147. CameraClass *m_camera;
  148. WBHeightMap *m_heightMapRenderObj;
  149. RenderObjClass *m_objectToolTrackingObj;
  150. Bool m_showObjToolTrackingObj;
  151. AsciiString m_objectToolTrackingModelName;
  152. Real m_mouseWheelOffset;
  153. Real m_groundLevel;
  154. Coord3D m_cameraOffset;
  155. CPoint m_actualWinSize;
  156. Real m_theta;
  157. Real m_cameraAngle;
  158. Real m_FXPitch;
  159. Bool m_doPitch;
  160. Real m_actualHeightAboveGround; // for camera tool display only
  161. Vector3 m_cameraSource; // for camera tool display only
  162. Vector3 m_cameraTarget; // for camera tool display only
  163. Int m_time;
  164. Int m_updateCount;
  165. UINT m_timer;
  166. DrawObject *m_drawObject;
  167. RefRenderObjListClass m_lightList;
  168. LayerClass *m_layer;
  169. LayerClass *m_buildLayer;
  170. IntersectionClass *m_intersector;
  171. Bool m_showWireframe;
  172. Bool m_ww3dInited;
  173. Bool m_needToLoadRoads;
  174. LightClass *m_globalLight[MAX_GLOBAL_LIGHTS];
  175. RenderObjClass *m_lightFeedbackMesh[MAX_GLOBAL_LIGHTS];
  176. Real m_buildRedMultiplier;
  177. Real m_curTrackingZ;
  178. Bool m_projection; ///< True if top down projection instead of "isometric" perspective.
  179. Bool m_showEntireMap; ///< True if drawing entire map instead of cached fast subset.
  180. Bool m_showShadows; ///< True if drawing shadows.
  181. Bool m_firstPaint; ///< True if we haven't painted yet.
  182. Bool m_showLayersList; ///< Flag whether the layers list is visible or not.
  183. Bool m_showMapBoundaries; ///< Flag whether to show all the map boundaries or not
  184. Bool m_showAmbientSounds; ///< Flag whether to show all the ambient sounds or not
  185. ID3DXFont* m3DFont;
  186. Int m_pickPixels;
  187. Int m_partialMapSize;
  188. protected:
  189. UINT getLastDrawTime();
  190. void init3dScene();
  191. void initAssets();
  192. void initWW3D();
  193. void drawLabels(HDC hdc);
  194. void drawLabels(void);
  195. void shutdownWW3D();
  196. void killTheTimer();
  197. void render();
  198. void setupCamera();
  199. void updateHysteresis(void);
  200. void updateLights();
  201. void updateScorches();
  202. public:
  203. virtual Bool viewToDocCoords(CPoint curPt, Coord3D *newPt, Bool constrain=true);
  204. virtual Bool docToViewCoords(Coord3D curPt, CPoint* newPt);
  205. virtual void updateHeightMapInView(WorldHeightMap *htMap, Bool partial, const IRegion2D &partialRange);
  206. /// Invalidates an object. Pass NULL to inval all objects.
  207. virtual void invalObjectInView(MapObject *pObj);
  208. // find the best model for an object
  209. AsciiString getBestModelName(const ThingTemplate* tt, const ModelConditionFlags& c);
  210. /// Invalidates an build list object.
  211. void invalBuildListItemInView(BuildListInfo *pBuild);
  212. /// Invalidates the area of one height map cell in the 2d view.
  213. virtual void invalidateCellInView(int xIndex, int yIndex);
  214. /// Scrolls the window by this amount.
  215. virtual void scrollInView(Real x, Real y, Bool end);
  216. virtual void setDefaultCamera();
  217. virtual void rotateCamera(Real delta);
  218. virtual void pitchCamera(Real delta);
  219. void setCameraPitch(Real absolutePitch);
  220. Real getCameraPitch(void);
  221. Real getHeightAboveGround(void) { return m_actualHeightAboveGround; }
  222. Vector3 getCameraSource(void) { return m_cameraSource; }
  223. Vector3 getCameraTarget(void) { return m_cameraTarget; }
  224. Real getCameraAngle(void) { return m_cameraAngle; }
  225. virtual MapObject *picked3dObjectInView(CPoint viewPt);
  226. virtual BuildListInfo *pickedBuildObjectInView(CPoint viewPt);
  227. void removeFenceListObjects(MapObject *pObject);
  228. void updateFenceListObjects(MapObject *pObject);
  229. /// Removes all render objects. Call when swithing to a new map.
  230. void resetRenderObjects();
  231. void stepTimeOfDay(void);
  232. void reset3dEngineDisplaySize(Int width, Int height); ///< Closes & reinitializes w3d.
  233. void setLighting(const GlobalData::TerrainLighting *tl, Int whichLighting, Int whichLight=0);
  234. DrawObject *getDrawObject(void) {return m_drawObject;};
  235. AsciiString getModelNameAndScale(MapObject *pMapObj, Real *scale, BodyDamageType curDamageState);
  236. virtual Int getPickPixels(void) {return m_pickPixels;}
  237. virtual Bool viewToDocCoordZ(CPoint curPt, Coord3D *newPt, Real Z);
  238. public:
  239. // void init(CWorldBuilderView *pMainView, HINSTANCE hInstance, CWnd* parent);
  240. void redraw();
  241. virtual void setCenterInView(Real x, Real y);
  242. Bool getShowTerrain();
  243. Bool getShowWireframe();
  244. void setObjTracking(MapObject *pMapObj, Coord3D pos, Real angle, Bool show);
  245. void setViewLayersList(Bool showLayersList) { m_showLayersList = showLayersList; }
  246. Bool getShowMapBoundaryFeedback(void) const { return m_showMapBoundaries; }
  247. Bool getShowAmbientSoundsFeedback(void) const { return m_showAmbientSounds; }
  248. void togglePitchAndRotation( void ) { m_doPitch = !m_doPitch; }
  249. virtual Bool isDoingPitch( void ) { return m_doPitch; }
  250. };
  251. inline UINT WbView3d::getLastDrawTime() { return m_time; }
  252. inline Bool WbView3d::getShowWireframe() { return m_showWireframe; }
  253. /////////////////////////////////////////////////////////////////////////////
  254. //{{AFX_INSERT_LOCATION}}
  255. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  256. #endif // !defined(AFX_WBVIEW3D_H__832D8241_87F6_11D5_8CE0_00010297BBAC__INCLUDED_)