Display.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: Display.h ////////////////////////////////////////////////////////////
  24. // The graphics display singleton
  25. // Author: Michael S. Booth, March 2001
  26. #pragma once
  27. #ifndef _GAME_DISPLAY_H_
  28. #define _GAME_DISPLAY_H_
  29. #include <stdio.h>
  30. #include "Common/SubsystemInterface.h"
  31. #include "View.h"
  32. #include "GameClient/Color.h"
  33. #include "GameClient/GameFont.h"
  34. class View;
  35. struct ShroudLevel
  36. {
  37. Short m_currentShroud; ///< A Value of 1 means shrouded. 0 is not. Negative is the count of people looking.
  38. Short m_activeShroudLevel;///< A Value of 0 means passive shroud. Positive is the count of people shrouding.
  39. };
  40. class VideoBuffer;
  41. class VideoStreamInterface;
  42. class DebugDisplayInterface;
  43. class Radar;
  44. class Image;
  45. class DisplayString;
  46. enum StaticGameLODLevel;
  47. /**
  48. * The Display class implements the Display interface
  49. */
  50. class Display : public SubsystemInterface
  51. {
  52. public:
  53. enum DrawImageMode
  54. {
  55. DRAW_IMAGE_SOLID,
  56. DRAW_IMAGE_GRAYSCALE, //draw image without blending and ignoring alpha
  57. DRAW_IMAGE_ALPHA, //alpha blend the image into frame buffer
  58. DRAW_IMAGE_ADDITIVE //additive blend the image into frame buffer
  59. };
  60. typedef void (DebugDisplayCallback)( DebugDisplayInterface *debugDisplay, void *userData, FILE *fp = NULL );
  61. Display();
  62. virtual ~Display();
  63. virtual void init( void ) { }; ///< Initialize
  64. virtual void reset( void ); ///< Reset system
  65. virtual void update( void ); ///< Update system
  66. //---------------------------------------------------------------------------------------
  67. // Display attribute methods
  68. virtual void setWidth( UnsignedInt width ); ///< Sets the width of the display
  69. virtual void setHeight( UnsignedInt height ); ///< Sets the height of the display
  70. virtual UnsignedInt getWidth( void ) { return m_width; } ///< Returns the width of the display
  71. virtual UnsignedInt getHeight( void ) { return m_height; } ///< Returns the height of the display
  72. virtual void setBitDepth( UnsignedInt bitDepth ) { m_bitDepth = bitDepth; }
  73. virtual UnsignedInt getBitDepth( void ) { return m_bitDepth; }
  74. virtual void setWindowed( Bool windowed ) { m_windowed = windowed; } ///< set windowd/fullscreen flag
  75. virtual Bool getWindowed( void ) { return m_windowed; } ///< return widowed/fullscreen flag
  76. virtual Bool setDisplayMode( UnsignedInt xres, UnsignedInt yres, UnsignedInt bitdepth, Bool windowed ); ///<sets screen resolution/mode
  77. virtual Int getDisplayModeCount(void) {return 0;} ///<return number of display modes/resolutions supported by video card.
  78. virtual void getDisplayModeDescription(Int modeIndex, Int *xres, Int *yres, Int *bitDepth) {} ///<return description of mode
  79. virtual void setGamma(Real gamma, Real bright, Real contrast, Bool calibrate) {};
  80. virtual Bool testMinSpecRequirements(Bool *videoPassed, Bool *cpuPassed, Bool *memPassed,StaticGameLODLevel *idealVideoLevel=NULL, Real *cpuTime=NULL) {*videoPassed=*cpuPassed=*memPassed=true; return true;}
  81. virtual void doSmartAssetPurgeAndPreload(const char* usageFileName) = 0;
  82. #if defined(_DEBUG) || defined(_INTERNAL)
  83. virtual void dumpAssetUsage(const char* mapname) = 0;
  84. #endif
  85. //---------------------------------------------------------------------------------------
  86. // View management
  87. virtual void attachView( View *view ); ///< Attach the given view to the world
  88. virtual View *getFirstView( void ) { return m_viewList; } ///< Return the first view of the world
  89. virtual View *getNextView( View *view )
  90. {
  91. if( view )
  92. return view->getNextView();
  93. return NULL;
  94. }
  95. virtual void drawViews( void ); ///< Render all views of the world
  96. virtual void updateViews ( void ); ///< Updates state of world views
  97. virtual VideoBuffer* createVideoBuffer( void ) = 0; ///< Create a video buffer that can be used for this display
  98. //---------------------------------------------------------------------------------------
  99. // Drawing management
  100. virtual void setClipRegion( IRegion2D *region ) = 0; ///< Set clip rectangle for 2D draw operations.
  101. virtual Bool isClippingEnabled( void ) = 0;
  102. virtual void enableClipping( Bool onoff ) = 0;
  103. virtual void draw( void ); ///< Redraw the entire display
  104. virtual void setTimeOfDay( TimeOfDay tod ) = 0; ///< Set the time of day for this display
  105. virtual void createLightPulse( const Coord3D *pos, const RGBColor *color, Real innerRadius,Real attenuationWidth,
  106. UnsignedInt increaseFrameTime, UnsignedInt decayFrameTime//, Bool donut = FALSE
  107. ) = 0;
  108. /// draw a line on the display in pixel coordinates with the specified color
  109. virtual void drawLine( Int startX, Int startY, Int endX, Int endY,
  110. Real lineWidth, UnsignedInt lineColor ) = 0;
  111. /// draw a line on the display in pixel coordinates with the specified 2 colors
  112. virtual void drawLine( Int startX, Int startY, Int endX, Int endY,
  113. Real lineWidth, UnsignedInt lineColor1, UnsignedInt lineColor2 ) = 0;
  114. /// draw a rect border on the display in pixel coordinates with the specified color
  115. virtual void drawOpenRect( Int startX, Int startY, Int width, Int height,
  116. Real lineWidth, UnsignedInt lineColor ) = 0;
  117. /// draw a filled rect on the display in pixel coords with the specified color
  118. virtual void drawFillRect( Int startX, Int startY, Int width, Int height,
  119. UnsignedInt color ) = 0;
  120. /// Draw a percentage of a rectange, much like a clock
  121. virtual void drawRectClock(Int startX, Int startY, Int width, Int height, Int percent, UnsignedInt color) = 0;
  122. virtual void drawRemainingRectClock(Int startX, Int startY, Int width, Int height, Int percent, UnsignedInt color) = 0;
  123. /// draw an image fit within the screen coordinates
  124. virtual void drawImage( const Image *image, Int startX, Int startY,
  125. Int endX, Int endY, Color color = 0xFFFFFFFF, DrawImageMode mode=DRAW_IMAGE_ALPHA) = 0;
  126. /// draw a video buffer fit within the screen coordinates
  127. virtual void drawVideoBuffer( VideoBuffer *buffer, Int startX, Int startY,
  128. Int endX, Int endY ) = 0;
  129. /// FullScreen video playback
  130. virtual void playLogoMovie( AsciiString movieName, Int minMovieLength, Int minCopyrightLength );
  131. virtual void playMovie( AsciiString movieName );
  132. virtual void stopMovie( void );
  133. virtual Bool isMoviePlaying(void);
  134. /// Register debug display callback
  135. virtual void setDebugDisplayCallback( DebugDisplayCallback *callback, void *userData = NULL );
  136. virtual DebugDisplayCallback *getDebugDisplayCallback();
  137. virtual void setShroudLevel(Int x, Int y, CellShroudStatus setting ) = 0; ///< set shroud
  138. virtual void clearShroud() = 0; ///< empty the entire shroud
  139. virtual void setBorderShroudLevel(UnsignedByte level) = 0; ///<color that will appear in unused border terrain.
  140. #if defined(_DEBUG) || defined(_INTERNAL)
  141. virtual void dumpModelAssets(const char *path) = 0; ///< dump all used models/textures to a file.
  142. #endif
  143. virtual void preloadModelAssets( AsciiString model ) = 0; ///< preload model asset
  144. virtual void preloadTextureAssets( AsciiString texture ) = 0; ///< preload texture asset
  145. virtual void takeScreenShot(void) = 0; ///< saves screenshot to a file
  146. virtual void toggleMovieCapture(void) = 0; ///< starts saving frames to an avi or frame sequence
  147. virtual void toggleLetterBox(void) = 0; ///< enabled letter-boxed display
  148. virtual void enableLetterBox(Bool enable) = 0; ///< forces letter-boxed display on/off
  149. virtual Bool isLetterBoxFading( void ) { return FALSE; } ///< returns true while letterbox fades in/out
  150. virtual void setCinematicText( AsciiString string ) { m_cinematicText = string; }
  151. virtual void setCinematicFont( GameFont *font ) { m_cinematicFont = font; }
  152. virtual void setCinematicTextFrames( Int frames ) { m_cinematicTextFrames = frames; }
  153. virtual Real getAverageFPS( void ) = 0; ///< returns the average FPS.
  154. virtual Int getLastFrameDrawCalls( void ) = 0; ///< returns the number of draw calls issued in the previous frame
  155. protected:
  156. virtual void deleteViews( void ); ///< delete all views
  157. UnsignedInt m_width, m_height; ///< Dimensions of the display
  158. UnsignedInt m_bitDepth; ///< bit depth of the display
  159. Bool m_windowed; ///< TRUE when windowed, FALSE when fullscreen
  160. View *m_viewList; ///< All of the views into the world
  161. // Cinematic text data
  162. AsciiString m_cinematicText; ///< string of the cinematic text that should be displayed
  163. GameFont *m_cinematicFont; ///< font for cinematic text
  164. Int m_cinematicTextFrames; ///< count of how long the cinematic text should be displayed
  165. // Video playback data
  166. VideoBuffer *m_videoBuffer; ///< Video playback buffer
  167. VideoStreamInterface *m_videoStream; ///< Video stream;
  168. AsciiString m_currentlyPlayingMovie; ///< The currently playing video. Used to notify TheScriptEngine of completed videos.
  169. // Debug display data
  170. DebugDisplayInterface *m_debugDisplay; ///< Actual debug display
  171. DebugDisplayCallback *m_debugDisplayCallback; ///< Code to update the debug display
  172. void *m_debugDisplayUserData; ///< Data for debug display update handler
  173. Real m_letterBoxFadeLevel; ///<tracks the current alpha level for fading letter-boxed mode in/out.
  174. Bool m_letterBoxEnabled; ///<current state of letterbox
  175. UnsignedInt m_letterBoxFadeStartTime; ///< time of letterbox fade start
  176. Int m_movieHoldTime; ///< time that we hold on the last frame of the movie
  177. Int m_copyrightHoldTime; ///< time that the copyright must be on the screen
  178. UnsignedInt m_elapsedMovieTime; ///< used to make sure we show the stuff long enough
  179. UnsignedInt m_elapsedCopywriteTime; ///< Hold on the last frame until both have expired
  180. DisplayString *m_copyrightDisplayString;///< this'll hold the display string
  181. };
  182. // the singleton
  183. extern Display *TheDisplay;
  184. extern void StatDebugDisplay( DebugDisplayInterface *dd, void *, FILE *fp = NULL );
  185. //Added By Saad
  186. //Necessary for display resolution confirmation dialog box
  187. //Holds the previous and current display settings
  188. typedef struct _DisplaySettings
  189. {
  190. Int xRes; //Resolution width
  191. Int yRes; //Resolution height
  192. Int bitDepth; //Color Depth
  193. Bool windowed; //Window mode TRUE: we're windowed, FALSE: we're not windowed
  194. } DisplaySettings;
  195. #endif // _GAME_DISPLAY_H_