W3DDisplay.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: W3DDisplay.h /////////////////////////////////////////////////////////
  24. //
  25. // W3D Implementation for the W3D Display which is responsible for creating
  26. // and maintaning the entire visual display
  27. //
  28. // Author: Colin Day, April 2001
  29. //
  30. ///////////////////////////////////////////////////////////////////////////////
  31. #pragma once
  32. #ifndef __W3DDISPLAY_H_
  33. #define __W3DDISPLAY_H_
  34. #include "GameClient/Display.h"
  35. #include "WW3D2/lightenvironment.h"
  36. class VideoBuffer;
  37. class W3DDebugDisplay;
  38. class DisplayString;
  39. class W3DAssetManager;
  40. class LightClass;
  41. class Render2DClass;
  42. class RTS3DScene;
  43. class RTS2DScene;
  44. class RTS3DInterfaceScene;
  45. //=============================================================================
  46. /** W3D implementation of the game display which is responsible for creating
  47. * all interaction with the screen and updating the display
  48. */
  49. class W3DDisplay : public Display
  50. {
  51. public:
  52. W3DDisplay();
  53. ~W3DDisplay();
  54. virtual void init( void ); ///< initialize or re-initialize the sytsem
  55. virtual void reset( void ) ; ///< Reset system
  56. virtual void setWidth( UnsignedInt width );
  57. virtual void setHeight( UnsignedInt height );
  58. virtual Bool setDisplayMode( UnsignedInt xres, UnsignedInt yres, UnsignedInt bitdepth, Bool windowed );
  59. virtual Int getDisplayModeCount(void); ///<return number of display modes/resolutions supported by video card.
  60. virtual void getDisplayModeDescription(Int modeIndex, Int *xres, Int *yres, Int *bitDepth); ///<return description of mode
  61. virtual void setGamma(Real gamma, Real bright, Real contrast, Bool calibrate);
  62. virtual void doSmartAssetPurgeAndPreload(const char* usageFileName);
  63. #if defined(_DEBUG) || defined(_INTERNAL)
  64. virtual void dumpAssetUsage(const char* mapname);
  65. #endif
  66. //---------------------------------------------------------------------------
  67. // Drawing management
  68. virtual void setClipRegion( IRegion2D *region ); ///< Set clip rectangle for 2D draw operations.
  69. virtual Bool isClippingEnabled( void ) { return m_isClippedEnabled; }
  70. virtual void enableClipping( Bool onoff ) { m_isClippedEnabled = onoff; }
  71. virtual void draw( void ); ///< redraw the entire display
  72. /// @todo Replace these light management routines with a LightManager singleton
  73. virtual void createLightPulse( const Coord3D *pos, const RGBColor *color, Real innerRadius,Real outerRadius,
  74. UnsignedInt increaseFrameTime, UnsignedInt decayFrameTime//, Bool donut = FALSE
  75. );
  76. virtual void setTimeOfDay ( TimeOfDay tod );
  77. /// draw a line on the display in screen coordinates
  78. virtual void drawLine( Int startX, Int startY, Int endX, Int endY,
  79. Real lineWidth, UnsignedInt lineColor );
  80. /// draw a line on the display in screen coordinates
  81. virtual void drawLine( Int startX, Int startY, Int endX, Int endY,
  82. Real lineWidth, UnsignedInt lineColor1, UnsignedInt lineColor2 );
  83. /// draw a rect border on the display in pixel coordinates with the specified color
  84. virtual void drawOpenRect( Int startX, Int startY, Int width, Int height,
  85. Real lineWidth, UnsignedInt lineColor );
  86. /// draw a filled rect on the display in pixel coords with the specified color
  87. virtual void drawFillRect( Int startX, Int startY, Int width, Int height,
  88. UnsignedInt color );
  89. /// Draw a percentage of a rectangle, much like a clock (0 to x%)
  90. virtual void drawRectClock(Int startX, Int startY, Int width, Int height, Int percent, UnsignedInt color);
  91. /// Draw's the remaining percentage of a rectangle (x% to 100)
  92. virtual void drawRemainingRectClock(Int startX, Int startY, Int width, Int height, Int percent, UnsignedInt color);
  93. /// draw an image fit within the screen coordinates
  94. virtual void drawImage( const Image *image, Int startX, Int startY,
  95. Int endX, Int endY, Color color = 0xFFFFFFFF, DrawImageMode mode=DRAW_IMAGE_ALPHA);
  96. /// draw a video buffer fit within the screen coordinates
  97. virtual void drawVideoBuffer( VideoBuffer *buffer, Int startX, Int startY,
  98. Int endX, Int endY );
  99. virtual VideoBuffer* createVideoBuffer( void ) ; ///< Create a video buffer that can be used for this display
  100. virtual void takeScreenShot(void); //save screenshot to file
  101. virtual void toggleMovieCapture(void); //enable AVI or frame capture mode.
  102. virtual void toggleLetterBox(void); ///<enabled letter-boxed display
  103. virtual void enableLetterBox(Bool enable); ///<forces letter-boxed display on/off
  104. virtual Bool isLetterBoxFading(void); ///<returns true while letterbox fades in/out
  105. virtual Bool isLetterBoxed(void);
  106. virtual void clearShroud();
  107. virtual void setShroudLevel(Int x, Int y, CellShroudStatus setting);
  108. virtual void setBorderShroudLevel(UnsignedByte level); ///<color that will appear in unused border terrain.
  109. #if defined(_DEBUG) || defined(_INTERNAL)
  110. virtual void dumpModelAssets(const char *path); ///< dump all used models/textures to a file.
  111. #endif
  112. virtual void preloadModelAssets( AsciiString model ); ///< preload model asset
  113. virtual void preloadTextureAssets( AsciiString texture ); ///< preload texture asset
  114. /// @todo Need a scene abstraction
  115. static RTS3DScene *m_3DScene; ///< our 3d scene representation
  116. static RTS2DScene *m_2DScene; ///< our 2d scene representation
  117. static RTS3DInterfaceScene *m_3DInterfaceScene; ///< our 3d interface scene that draws last (for 3d mouse cursor, etc)
  118. static W3DAssetManager *m_assetManager; ///< W3D asset manager
  119. void drawFPSStats( void ); ///< draw the fps on the screen
  120. virtual Real getAverageFPS( void ); ///< return the average FPS.
  121. virtual Int getLastFrameDrawCalls( void ); ///< returns the number of draw calls issued in the previous frame
  122. protected:
  123. void initAssets( void ); ///< init assets for WW3D
  124. void init3DScene( void ); ///< init 3D scene for WW3D
  125. void init2DScene( void ); ///< init 2D scene for WW3D
  126. void gatherDebugStats( void ); ///< compute debug stats
  127. void drawDebugStats( void ); ///< display debug stats
  128. void drawCurrentDebugDisplay( void ); ///< draws current debug display
  129. void calculateTerrainLOD(void); ///< Calculate terrain LOD.
  130. void renderLetterBox(UnsignedInt time); ///< draw letter box border
  131. void updateAverageFPS(void); ///< figure out the average fps over the last 30 frames.
  132. Byte m_initialized; ///< TRUE when system is initialized
  133. LightClass *m_myLight[LightEnvironmentClass::MAX_LIGHTS]; ///< light hack for now
  134. Render2DClass *m_2DRender; ///< interface for common 2D functions
  135. IRegion2D m_clipRegion; ///< the clipping region for images
  136. Bool m_isClippedEnabled; ///<used by 2D drawing operations to define clip re
  137. Real m_averageFPS; ///<average fps over the last 30 frames.
  138. #if defined(_DEBUG) || defined(_INTERNAL)
  139. Int64 m_timerAtCumuFPSStart;
  140. #endif
  141. enum
  142. {
  143. FPS, ///< debug display frames per second
  144. Frame, ///< debug display current frame
  145. Polygons, ///< debug display polygons
  146. Vertices, ///< debug display vertices
  147. VideoRam, ///< debug display for video ram used
  148. DebugInfo, ///< miscellaneous debug info string
  149. KEY_MOUSE_STATES, ///< keyboard modifier and mouse button states.
  150. MousePosition, ///< debug display mouse position
  151. Particles, ///< debug display particles
  152. Objects, ///< debug display total number of objects
  153. NetIncoming, ///< debug display network incoming stats
  154. NetOutgoing, ///< debug display network outgoing stats
  155. NetStats, ///< debug display network performance stats.
  156. NetFPSAverages, ///< debug display all players' average fps.
  157. SelectedInfo, ///< debug display for the selected object in the UI
  158. TerrainStats, ///< debug display for the terrain renderer
  159. DisplayStringCount
  160. };
  161. DisplayString *m_displayStrings[DisplayStringCount];
  162. DisplayString *m_benchmarkDisplayString;
  163. W3DDebugDisplay *m_nativeDebugDisplay; ///< W3D specific debug display interface
  164. }; // end W3DDisplay
  165. #endif // end __W3DDISPLAY_H_