LoadingHook.cpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. #include "stdafx.h"
  13. #include "LCDDrawing.h"
  14. #include <locale.h>
  15. #define USECUSTOMTEXT 0
  16. extern CGame *_pGame;
  17. #if USECUSTOMTEXT
  18. static CTString _strCustomText = "";
  19. #endif
  20. static CDrawPort *_pdpLoadingHook = NULL; // drawport for loading hook
  21. extern BOOL _bUserBreakEnabled;
  22. extern BOOL map_bIsFirstEncounter;
  23. #define REFRESHTIME (0.2f)
  24. void RemapLevelNames(INDEX &iLevel)
  25. {
  26. switch( iLevel) {
  27. case 10: iLevel = 1; break;
  28. case 11: iLevel = 2; break;
  29. case 12: iLevel = 3; break;
  30. case 13: iLevel = 4; break;
  31. case 14: iLevel = 5; break;
  32. case 15: iLevel = 6; break;
  33. case 21: iLevel = 7; break;
  34. case 22: iLevel = 8; break;
  35. case 23: iLevel = 9; break;
  36. case 24: iLevel = 10; break;
  37. case 31: iLevel = 11; break;
  38. case 32: iLevel = 12; break;
  39. case 33: iLevel = 13; break;
  40. default: iLevel = -1; break;
  41. }
  42. }
  43. static void LoadingHook_t(CProgressHookInfo *pphi)
  44. {
  45. // if user presses escape
  46. ULONG ulCheckFlags = 0x8000;
  47. if (pphi->phi_fCompleted>0) {
  48. ulCheckFlags |= 0x0001;
  49. }
  50. if (_bUserBreakEnabled && (GetAsyncKeyState(VK_ESCAPE)&ulCheckFlags)) {
  51. // break loading
  52. throw TRANS("User break!");
  53. }
  54. #if USECUSTOMTEXT
  55. // if no custom loading text
  56. if (_strCustomText=="") {
  57. // load it
  58. try {
  59. _strCustomText.Load_t(CTFILENAME("Data\\LoadingText.txt"));
  60. } catch (char *strError) {
  61. _strCustomText = strError;
  62. }
  63. }
  64. #endif
  65. // measure time since last call
  66. static CTimerValue tvLast(0I64);
  67. CTimerValue tvNow = _pTimer->GetHighPrecisionTimer();
  68. // if not first or final update, and not enough time passed
  69. if (pphi->phi_fCompleted!=0 && pphi->phi_fCompleted!=1 &&
  70. (tvNow-tvLast).GetSeconds() < REFRESHTIME) {
  71. // do nothing
  72. return;
  73. }
  74. tvLast = tvNow;
  75. // skip if cannot lock drawport
  76. CDrawPort *pdp = _pdpLoadingHook;
  77. ASSERT(pdp!=NULL);
  78. CDrawPort dpHook(pdp, TRUE);
  79. if( !dpHook.Lock()) return;
  80. // clear screen
  81. dpHook.Fill(C_BLACK|255);
  82. // get session properties currently loading
  83. CSessionProperties *psp = (CSessionProperties *)_pNetwork->GetSessionProperties();
  84. ULONG ulLevelMask = psp->sp_ulLevelsMask;
  85. if (psp->sp_bCooperative) {
  86. INDEX iLevel = -1;
  87. INDEX iLevelNext = -1;
  88. CTString strLevelName = _pNetwork->ga_fnmWorld.FileName();
  89. CTString strNextLevelName = _pNetwork->ga_fnmNextLevel.FileName();
  90. // second encounter
  91. INDEX u, v;
  92. u = v = -1;
  93. strLevelName.ScanF("%01d_%01d_", &u, &v);
  94. iLevel = u*10+v;
  95. RemapLevelNames(iLevel);
  96. u = v = -1;
  97. strNextLevelName.ScanF("%01d_%01d_", &u, &v);
  98. iLevelNext = u*10+v;
  99. RemapLevelNames(iLevelNext);
  100. // first encounter
  101. if(iLevel == -1) {
  102. strLevelName.ScanF("%02d_", &iLevel);
  103. strNextLevelName.ScanF("%02d_", &iLevelNext);
  104. if(iLevel != -1) {
  105. map_bIsFirstEncounter = TRUE;
  106. }
  107. } else {
  108. map_bIsFirstEncounter = FALSE;
  109. }
  110. if (iLevel>0) {
  111. ulLevelMask|=1<<(iLevel-1);
  112. }
  113. if (iLevelNext>0) {
  114. ulLevelMask|=1<<(iLevelNext-1);
  115. }
  116. }
  117. if (ulLevelMask!=0 && !_pNetwork->IsPlayingDemo()) {
  118. // map hook
  119. extern void RenderMap( CDrawPort *pdp, ULONG ulLevelMask, CProgressHookInfo *pphi);
  120. RenderMap(&dpHook, ulLevelMask, pphi);
  121. // finish rendering
  122. dpHook.Unlock();
  123. dpHook.dp_Raster->ra_pvpViewPort->SwapBuffers();
  124. // keep current time
  125. tvLast = _pTimer->GetHighPrecisionTimer();
  126. return;
  127. }
  128. // get sizes
  129. PIX pixSizeI = dpHook.GetWidth();
  130. PIX pixSizeJ = dpHook.GetHeight();
  131. CFontData *pfd = _pfdConsoleFont;
  132. PIX pixCharSizeI = pfd->fd_pixCharWidth + pfd->fd_pixCharSpacing;
  133. PIX pixCharSizeJ = pfd->fd_pixCharHeight + pfd->fd_pixLineSpacing;
  134. PIX pixBarSizeJ = 17;//*pixSizeJ/480;
  135. COLOR colBcg = LerpColor(C_BLACK, SE_COL_BLUE_LIGHT, 0.30f)|0xff;
  136. COLOR colBar = LerpColor(C_BLACK, SE_COL_BLUE_LIGHT, 0.45f)|0xff;
  137. COLOR colLines = colBar; //C_vdGREEN|0xff;
  138. COLOR colText = LerpColor(C_BLACK, SE_COL_BLUE_LIGHT, 0.95f)|0xff;
  139. COLOR colEsc = C_WHITE|0xFF;
  140. dpHook.Fill(0, pixSizeJ-pixBarSizeJ, pixSizeI, pixBarSizeJ, colBcg);
  141. dpHook.Fill(0, pixSizeJ-pixBarSizeJ, pixSizeI*pphi->phi_fCompleted, pixBarSizeJ, colBar);
  142. dpHook.DrawBorder(0, pixSizeJ-pixBarSizeJ, pixSizeI, pixBarSizeJ, colLines);
  143. dpHook.SetFont( _pfdConsoleFont);
  144. dpHook.SetTextScaling( 1.0f);
  145. dpHook.SetTextAspect( 1.0f);
  146. // print status text
  147. setlocale(LC_ALL, "");
  148. CTString strDesc(0, "%s", pphi->phi_strDescription); strupr((char*)(const char*)strDesc);
  149. setlocale(LC_ALL, "C");
  150. CTString strPerc(0, "%3.0f%%", pphi->phi_fCompleted*100);
  151. //dpHook.PutText(strDesc, pixCharSizeI/2, pixSizeJ-pixBarSizeJ-2-pixCharSizeJ, C_GREEN|255);
  152. //dpHook.PutTextCXY(strPerc, pixSizeI/2, pixSizeJ-pixBarSizeJ/2+1, C_GREEN|255);
  153. dpHook.PutText(strDesc, pixCharSizeI/2, pixSizeJ-pixBarSizeJ+pixCharSizeJ/2, colText);
  154. dpHook.PutTextR(strPerc, pixSizeI-pixCharSizeI/2, pixSizeJ-pixBarSizeJ+pixCharSizeJ/2, colText);
  155. if (_bUserBreakEnabled && !_pGame->gm_bFirstLoading) {
  156. dpHook.PutTextC( TRANS( "PRESS ESC TO ABORT"), pixSizeI/2, pixSizeJ-pixBarSizeJ-2-pixCharSizeJ, colEsc);
  157. }
  158. /*
  159. //LCDPrepare(1.0f);
  160. //LCDSetDrawport(&dpHook);
  161. // fill the box with background dirt and grid
  162. //LCDRenderClouds1();
  163. //LCDRenderGrid();
  164. // draw progress bar
  165. PIX pixBarCentI = pixBoxSizeI*1/2;
  166. PIX pixBarCentJ = pixBoxSizeJ*3/4;
  167. PIX pixBarSizeI = pixBoxSizeI*7/8;
  168. PIX pixBarSizeJ = pixBoxSizeJ*3/8;
  169. PIX pixBarMinI = pixBarCentI-pixBarSizeI/2;
  170. PIX pixBarMaxI = pixBarCentI+pixBarSizeI/2;
  171. PIX pixBarMinJ = pixBarCentJ-pixBarSizeJ/2;
  172. PIX pixBarMaxJ = pixBarCentJ+pixBarSizeJ/2;
  173. dpBox.Fill(pixBarMinI, pixBarMinJ,
  174. pixBarMaxI-pixBarMinI, pixBarMaxJ-pixBarMinJ, C_BLACK|255);
  175. dpBox.Fill(pixBarMinI, pixBarMinJ,
  176. (pixBarMaxI-pixBarMinI)*pphi->phi_fCompleted, pixBarMaxJ-pixBarMinJ, C_GREEN|255);
  177. // put more dirt
  178. LCDRenderClouds2Light();
  179. // draw borders
  180. COLOR colBorders = LerpColor(C_GREEN, C_BLACK, 200);
  181. LCDDrawBox(0,-1, PIXaabbox2D(
  182. PIX2D(pixBarMinI, pixBarMinJ),
  183. PIX2D(pixBarMaxI, pixBarMaxJ)),
  184. colBorders|255);
  185. LCDDrawBox(0,-1, PIXaabbox2D(
  186. PIX2D(0,0), PIX2D(dpBox.GetWidth(), dpBox.GetHeight())),
  187. colBorders|255);
  188. // print status text
  189. dpBox.SetFont( _pfdDisplayFont);
  190. dpBox.SetTextScaling( 1.0f);
  191. dpBox.SetTextAspect( 1.0f);
  192. // print status text
  193. CTString strRes;
  194. strRes.PrintF( "%s", pphi->phi_strDescription);
  195. //strupr((char*)(const char*)strRes);
  196. dpBox.PutTextC( strRes, 160, 17, C_GREEN|255);
  197. strRes.PrintF( "%3.0f%%", pphi->phi_fCompleted*100);
  198. dpBox.PutTextCXY( strRes, pixBarCentI, pixBarCentJ, C_GREEN|255);
  199. dpBox.Unlock();
  200. if( Flesh.gm_bFirstLoading) {
  201. #if USECUSTOMTEXT
  202. FLOAT fScaling = (FLOAT)slSizeI/640.0f;
  203. dpHook.Lock();
  204. dpHook.SetFont( _pfdDisplayFont);
  205. dpHook.SetTextScaling( fScaling);
  206. dpHook.SetTextAspect( 1.0f);
  207. //dpHook.Fill( 0, 0, slSizeI, pixCenterJ, C_vdGREEN|255, C_vdGREEN|255, C_vdGREEN|0, C_vdGREEN|0);
  208. dpHook.PutTextC( TRANS( "SERIOUS SAM - TEST VERSION"), pixCenterI, 5*fScaling, C_WHITE|255);
  209. dpHook.PutTextC( TRANS( "THIS IS NOT A DEMO VERSION, THIS IS A COMPATIBILITY TEST!"), pixCenterI, 25*fScaling, C_WHITE|255);
  210. dpHook.PutTextC( TRANS( "Serious Sam (c) 2000 Croteam LLC, All Rights Reserved.\n"), pixCenterI, 45*fScaling, C_WHITE|255);
  211. dpHook.PutText( _strCustomText, 1*fScaling, 85*fScaling, C_GREEN|255);
  212. dpHook.Unlock();
  213. #endif
  214. } else if (_bUserBreakEnabled) {
  215. FLOAT fScaling = (FLOAT)slSizeI/640.0f;
  216. dpHook.Lock();
  217. dpHook.SetFont( _pfdDisplayFont);
  218. dpHook.SetTextScaling( fScaling);
  219. dpHook.SetTextAspect( 1.0f);
  220. //dpHook.Fill( 0, 0, slSizeI, pixCenterJ, C_vdGREEN|255, C_vdGREEN|255, C_vdGREEN|0, C_vdGREEN|0);
  221. dpHook.PutTextC( TRANS( "PRESS ESC TO ABORT"), pixCenterI, pixCenterJ+pixBoxSizeJ+5*fScaling, C_WHITE|255);
  222. }
  223. */
  224. dpHook.Unlock();
  225. // finish rendering
  226. dpHook.dp_Raster->ra_pvpViewPort->SwapBuffers();
  227. // keep current time
  228. tvLast = _pTimer->GetHighPrecisionTimer();
  229. }
  230. // loading hook functions
  231. void CGame::EnableLoadingHook(CDrawPort *pdpDrawport)
  232. {
  233. _pdpLoadingHook = pdpDrawport;
  234. SetProgressHook(LoadingHook_t);
  235. }
  236. void CGame::DisableLoadingHook(void)
  237. {
  238. SetProgressHook(NULL);
  239. _pdpLoadingHook = NULL;
  240. }