PageRenderTime 53ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Game/Subtitle.h

https://github.com/neuralshock/homeworld
C Header | 190 lines | 124 code | 32 blank | 34 comment | 0 complexity | e6b6c8ee8441329c17144e8f6654d6b4 MD5 | raw file
  1. /*=============================================================================
  2. Name : Subtitle.h
  3. Purpose : Definitions for subtitling
  4. Created 2/3/1999 by lmoloney
  5. Copyright Relic Entertainment, Inc. All rights reserved.
  6. =============================================================================*/
  7. #ifndef ___SUBTITLE_H
  8. #define ___SUBTITLE_H
  9. #include "Color.h"
  10. #include "font.h"
  11. #include "texreg.h"
  12. #include "Types.h"
  13. /*=============================================================================
  14. Switches:
  15. =============================================================================*/
  16. #define SUB_MODULE_TEST 0 //test this module
  17. #ifdef HW_BUILD_FOR_DEBUGGING
  18. #define SUB_ERROR_CHECKING 1 //general error checking
  19. #define SUB_VERBOSE_LEVEL 3 //control specific output code
  20. #define SUB_VISUALIZE_REGION 0 //draw the rectangle of the region
  21. #else
  22. #define SUB_ERROR_CHECKING 0 //general error checking
  23. #define SUB_VERBOSE_LEVEL 0 //control specific output code
  24. #define SUB_VISUALIZE_REGION 0 //draw the rectangle of the region
  25. #endif
  26. /*=============================================================================
  27. Definitions:
  28. =============================================================================*/
  29. //definitions for subtitle regions
  30. #define STR_NIS 0 //middle of screen, where NIS's normally play their text
  31. #define STR_LetterboxBar 1 //at the top of the screen, on top of the letterbox bar
  32. #define STR_CloseCaptioned 2 //down near bottom for people hard-of-hearing
  33. #define STR_LocationCard 3 //location cards in the middle of the screen
  34. //definitions of subtitle themes
  35. #define STT_CloseCaptioned 14
  36. #define STT_LocationCard 15
  37. //definitions of subtitle actors
  38. #define STA_FleetCommand 0
  39. #define STA_AllShips0 1
  40. #define STA_AllShips2 2
  41. #define STA_AllShips3 3
  42. #define STA_FleetIntel 4
  43. #define STA_Traders 5
  44. #define STA_Pirates2 6
  45. #define STA_AllEnemyShips 7
  46. #define STA_Ambassador 8
  47. #define STA_Defector 9
  48. #define STA_Narrator 10
  49. #define STA_KharSelim 11
  50. #define STA_Emperor 12
  51. #define STA_LocationCard 112
  52. #define SUB_MaxLinesPerSubtitle 64 //maximum number of lines a subtitle can be chopped up into
  53. #define SUB_SubtitleLength 2040
  54. #define SUB_NumberNewSubtitles 8 //max number of new subtitles that can be added in a single frame
  55. #define SUB_SemaphoreName "SUBSEMAPHORE"
  56. #define SUB_NumberThemes 16
  57. #define SUB_NumberRegions 4
  58. #define SUB_ScriptFile "Subtitle.script"
  59. #define SUB_ScrollDwellStart 0.7f
  60. #define SUB_ScrollDwellEnd 0.5f
  61. #define SUB_ScrollShortest 0.25f
  62. #define SUB_TitleShortest 1.2f
  63. #define SUB_InterlineSpacing 1 //spacing between lines
  64. //definitions for pictures
  65. #define SUB_PictureWidth 64
  66. #define SUB_PictureHeight 64
  67. #define SUB_PictureMarginY 0
  68. #define SUB_PictureMarginX 3
  69. /*=============================================================================
  70. Type definitions:
  71. =============================================================================*/
  72. //structure for a single "line" or "card" within a subtitle region. It may be more than 1 line when all's all is said and done.
  73. typedef struct
  74. {
  75. real32 creationTime; //when this text card was created
  76. real32 duration; //how long this text card is supposed to last, including fades
  77. real32 fadeIn; //duration of fade in from black, if any
  78. real32 fadeOut; //duration of fade out to black, if any
  79. color c; //color of text card
  80. bool bDropShadow;
  81. fonthandle font; //font to draw in
  82. sdword x, y; //where to draw the text
  83. // sword margin; //margin for use with multi-line text
  84. char *text; //what text to draw
  85. }
  86. subcard;
  87. //structure for a region where subtitles are to go
  88. typedef struct
  89. {
  90. //real-time stuff for the region
  91. real32 textScrollStart; //when scrolling starts
  92. real32 textScrollEnd; //when scrolling will end
  93. real32 scrollDistance; //how far to scroll
  94. trhandle picture; //what picture to draw, if any, at the side of the text
  95. bool8 bAborted; //if true, this is fading out because it was aborted
  96. bool8 bContinuousEvent; //this event will keep playing after this speech fragment
  97. //settings for the region
  98. rectangle defaultRect; //rectangle in 640x480 rez
  99. rectangle rect; //where the text is printed
  100. bool8 bScaleRezX, bScaleRezY; //TRUE if the rectangle is to scale with the screen rez
  101. bool8 bEnabled; //a subtitle region can be disabled
  102. sdword iconOffsetX, iconOffsetY; //offsets to the speech icon
  103. //actual text cards
  104. sdword numberCards; //max number of sentences in this region
  105. sdword cardIndex; //number of sentences currenly in use
  106. char chopBuffer[SUB_SubtitleLength + SUB_MaxLinesPerSubtitle];
  107. subcard *card; //actual lines of text
  108. }
  109. subregion;
  110. //structure for a text theme
  111. typedef struct
  112. {
  113. color textColor; //color of the text
  114. trhandle picture; //what picture to draw at side
  115. ubyte bPicture; //is there a picure?
  116. ubyte pictureColorScheme; //color scheme this picture uses
  117. ubyte colorSchemeOfPicture; //what color scheme the picture is
  118. bool8 bDropShadow; //is there a dropshadow?
  119. bool8 bCentred; //is it centred in the region?
  120. sdword margin; //margin to use when wrapping
  121. fonthandle font; //font to use
  122. real32 fadeIn; //duration of fade-in, seconds
  123. real32 fadeOut; //duration of fade-out, seconds
  124. }
  125. subtheme;
  126. //structure for communicating new subtitles from the streamer thread
  127. typedef struct
  128. {
  129. sdword actor;
  130. sdword speechEvent;
  131. sdword length;
  132. real32 time;
  133. char text[SUB_SubtitleLength];
  134. }
  135. subnewsubtitle;
  136. /*=============================================================================
  137. Data:
  138. =============================================================================*/
  139. extern subregion subRegion[SUB_NumberRegions];
  140. extern real32 *subTimeElapsed;
  141. extern bool8 subCloseCaptionsEnabled;
  142. extern sdword subMessageEnded;
  143. /*=============================================================================
  144. Functions:
  145. =============================================================================*/
  146. void subStartup(void);
  147. void subReset(void);
  148. void subTexturesReset(void);
  149. void subShutdown(void);
  150. void subRegionsRescale(void);
  151. bool subAnyCardsOnScreen(void);
  152. sdword subTitleAdd(sdword actor, sdword speechEvent, char *text, sdword length, real32 time);
  153. void subTitlesUpdate(void);
  154. void subTitlesDraw(subregion *region);
  155. void subTitlesFadeOut(subregion *region, real32 fadeTime);
  156. sdword subStringsChop(rectangle *region, fonthandle font, sdword longLength, char *longString, char *chopBuffer, char **choppedStrings);
  157. #endif