cutscene.cpp 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // cutscene.cpp
  19. // Project: Postal
  20. //
  21. // This module handles all the cut-scenes.
  22. //
  23. // History:
  24. // 04/18/97 MJR Started.
  25. //
  26. // 04/20/07 BRH Problem compiling this file due to RPrint print being
  27. // defined more than once. It may have just been cut and
  28. // pasted code.
  29. //
  30. // 04/21/97 MJR Created real version of CutScene().
  31. //
  32. // 04/22/97 MJR Testing and tuning.
  33. //
  34. // 04/26/97 JRD Added a swirling blur effect to the cutscenes
  35. //
  36. // 04/27/97 JRD Merged CSwirl::Configure with CutScene to allow greater flxibility
  37. //
  38. // 06/08/97 MJR Changed interface in order to properly clean everything
  39. // up without memory leaks.
  40. //
  41. // 06/11/97 JMI Changed so CutSceneStart() does not require a prefs file
  42. // and section name but instead opens and creates them using
  43. // a single realm number that is now passed in.
  44. //
  45. // 06/12/97 MJR Renamed m_pszRealm to m_pszRealmPrefsFile.
  46. //
  47. // 06/14/97 MJR Fixed problem regarding default multialpha name and what
  48. // happens if none gets loaded (i.e. - it crashed).
  49. //
  50. // MJR Added support for sepearate network sections in realms
  51. // prefs file.
  52. //
  53. // 06/17/97 JMI Added NULL in call to PlaySample() corresponding to new
  54. // param.
  55. //
  56. // 07/05/97 MJR Changed to RSP_BLACK_INDEX instead of 0.
  57. //
  58. // 07/14/97 BRH Added challenge mode parameter to CutSceneStart so that
  59. // the proper text can be displayed for the Gauntlet.
  60. //
  61. // 07/17/97 JMI Changed RSnd*'s to SampleMaster::SoundInstances.
  62. // Now uses new SampleMaster interface for volume and play
  63. // instance reference.
  64. //
  65. // 07/18/97 MJR Got progress bars working in a ROUGH sort of way. They
  66. // still need some tuning to look better and we need to save
  67. // and load the "total bytes" (aka cumm units) for each
  68. // realm to the prefs file.
  69. //
  70. // 07/18/97 JMI Got rid of bogus immitation PlaySample functions.
  71. // Now there is one PlaySample() function. Also, you now
  72. // MUST specify a category and you don't have to specify a
  73. // SoundInstance ptr to specify a volume.
  74. //
  75. // 07/20/97 JMI Added NUM_ELEMENTS() macro as alternative to
  76. // (sizeof(a)/sizeof(a[0]) ).
  77. // Changed asWavyY to be of type short (was no specific type
  78. // and, therefore, int before).
  79. // Fix parenthesis bug in CutScene_RFileCallback() with index
  80. // that caused it to hit -1.
  81. //
  82. // 08/18/97 BRH Changed default cutscene from cut00 to abstract.
  83. //
  84. // 08/18/97 JMI Now works with the four different combinations of missing
  85. // assets I could conceive.
  86. //
  87. // 08/20/97 JMI Now uses source clipping when copying the progress bar
  88. // area out of m_pimBGLayer for safety (normally they should
  89. // be the correct size).
  90. //
  91. // 08/21/97 JMI Changed call to Update() to UpdateSystem() and occurrences
  92. // of rspUpdateDisplay() to UpdateDisplay().
  93. //
  94. // 08/22/97 BRH Added ability to load a different sound file for each
  95. // cutscene, specified in the realms.ini file.
  96. //
  97. // 08/22/97 JMI Changed calls to UpdateDisplay() back to rspUpdateDisplay()
  98. // since we no longer need UpdateDisplay() now that we are
  99. // using rspLock/Unlock* functions properly.
  100. // Also, now set the PlaySample() call to purge the sample
  101. // when done.
  102. //
  103. // 08/27/97 JRD Adding a compact stand along Martini effect for us with the
  104. // end of the game called MartiniDo
  105. //
  106. // 08/27/97 JRD Made MartiniDo WAY to easy for Bill to use, by putting up
  107. // with him justpassing the whole screen buffer, me doing a
  108. // general lock on it, creating a temporary bmp, and copying
  109. // it in. Happy Bill?
  110. //
  111. // 08/28/97 JRD Refined martini effect and added fade out option.
  112. //
  113. // 08/30/97 BRH Fixed path for loading the realms.ini file. It now loads
  114. // from the CD path rather thant the HD path.
  115. //
  116. // 09/08/97 BRH I just learned about rspGetQuitStatus() and found it to
  117. // be so much fun, that I just started adding it to every
  118. // function I could find, including MartiniDo()
  119. //
  120. // 09/11/97 JMI Added some protection for when the cutscene image is not
  121. // available. Only tested for missing cutscenes with CompUSA
  122. // version though which doesn't let you get to the martini
  123. // effect so that may still not work without a BMP (although,
  124. // I did put in the appropriate checking, it may still have
  125. // side effects of using different numbers than the real
  126. // cutscene would (like say a width of 0) ).
  127. //
  128. // 09/24/97 JMI Now initializes bFemalePain member of m_musicID. This
  129. // member indicates whether the sample is of a female in pain
  130. // which some countries (so far just UK) don't want in the
  131. // game.
  132. //
  133. // 10/07/97 JMI Changed bFemalePain to usDescFlags.
  134. //
  135. // 06/03/98 BRH Had to change the path for the realms.ini file back to
  136. // loading from the HD for the add-on pack since the
  137. // new cutscenes are now only stored on the HD while the
  138. // original PostalCD is in their CD drive (it only has
  139. // the old cutscene images).
  140. //
  141. // 02/04/00 MJR Changed so that it now checks the HD first and the VD
  142. // second when trying to load bg's and multialphas. This
  143. // was done to fix problems with the Japan Add On.
  144. //
  145. ////////////////////////////////////////////////////////////////////////////////
  146. #include "RSPiX.h"
  147. #include "cutscene.h"
  148. #include "game.h"
  149. #include "update.h"
  150. #include "SampleMaster.h"
  151. #include "AlphaAnimType.h"
  152. ////////////////////////////////////////////////////////////////////////////////
  153. // Macros/types/etc.
  154. ////////////////////////////////////////////////////////////////////////////////
  155. #define FONT_FILE "res/fonts/smash.fnt"
  156. #define DEFAULT_TITLE "Loading..."
  157. #define DEFAULT_BG "res/cutscene/abstract.bmp"
  158. #define DEFAULT_TEXT ""
  159. #define DEFAULT_MULTIALPHA "res/cutscene/abstract.mlp"
  160. #define DEFAULT_MUSIC "psychedelic1.wav"
  161. #define BG_X (ms_pCut->m_pimDst->m_sWidth / 2 - ms_pCut->m_pimBGLayer->m_sWidth / 2)
  162. #define BG_Y (ms_pCut->m_pimDst->m_sHeight / 2 - ms_pCut->m_pimBGLayer->m_sHeight / 2)
  163. #define NAME_Y 85
  164. #define TEXT_Y (280 - 48)
  165. #define MARGIN 24
  166. #define BLOOD_FORE_R 128 //200
  167. #define BLOOD_FORE_G 0 //10
  168. #define BLOOD_FORE_B 0 //10
  169. #define FONT_FORE_R 255 //180
  170. #define FONT_FORE_G 0 //10
  171. #define FONT_FORE_B 0 //10
  172. #define FONT_SHAD_R 0
  173. #define FONT_SHAD_G 0
  174. #define FONT_SHAD_B 0
  175. // Starting position for progress bar
  176. #define PROGRESS_BAR_START_X 165
  177. #define PROGRESS_BAR_START_Y 460
  178. // Width of progress bar
  179. #define PROGRESS_BAR_WIDTH 310
  180. // Random values for creating spread of pixels (it does +/- these values!!!!)
  181. #define PROGRESS_BAR_RANDOM_X 7
  182. #define PROGRESS_BAR_RANDOM_Y 2
  183. // Number of pixels to plot each time
  184. #define PROGRESS_BAR_DENSITY 10
  185. // How often to update the progress bar (in milliseconds)
  186. #define PROGRESS_BAR_UPDATE_TIME 250
  187. // Area of the screen that needs to be updated (keep 16-byte aligned for speed!!!)
  188. #define PROGRESS_BOX_X 96
  189. #define PROGRESS_BOX_Y 440
  190. #define PROGRESS_BOX_WIDTH 448
  191. #define PROGRESS_BOX_HEIGHT 40
  192. // Get a random number plus/minus the specified value
  193. #define RandomPlusMinus(x) ((MyRandom() % (((x) + 1) * 2)) - (x))
  194. // Determines the number of elements in the passed array at compile time.
  195. #define NUM_ELEMENTS(a) (sizeof(a) / sizeof(a[0]) )
  196. ////////////////////////////////////////////////////////////////////////////////
  197. //
  198. // Local random stuff
  199. //
  200. ////////////////////////////////////////////////////////////////////////////////
  201. static int ms_lRandom;
  202. inline void MySeedRandom(long seed)
  203. {
  204. ms_lRandom = seed;
  205. }
  206. inline long MyRandom(void)
  207. {
  208. return (((ms_lRandom = ms_lRandom * 214013L + 2531011L) >> 16) & 0x7fff);
  209. }
  210. ////////////////////////////////////////////////////////////////////////////////
  211. //
  212. //
  213. ////////////////////////////////////////////////////////////////////////////////
  214. class CCutSceneInfo
  215. {
  216. public:
  217. //-----------------------------------------
  218. RFont* m_pFont;
  219. char m_szTitle[256];
  220. char m_szText[4096];
  221. char m_szMusic[RSP_MAX_PATH];
  222. UCHAR m_ucForeText;
  223. UCHAR m_ucShadowText;
  224. RImage* m_pimBGLayer;
  225. RImage* m_pimTextLayer;
  226. RImage* m_pimDst;
  227. RMultiAlpha* m_pmaAlpha;
  228. bool m_bDeleteFont;
  229. short m_sDelW;
  230. short m_sDelH;
  231. long m_lTotalBytes;
  232. long m_lTimeToUpdate;
  233. long m_lBytesSoFar;
  234. U8 m_u8BloodColor;
  235. short m_sLastDistance;
  236. SampleMasterID m_musicID;
  237. //-----------------------------------------
  238. void Clear()
  239. {
  240. m_pFont = NULL;
  241. m_szTitle[0] = 0;
  242. m_szText[0] = 0;
  243. m_szMusic[0] = 0;
  244. m_ucForeText = 0;
  245. m_ucShadowText = 0;
  246. m_pimBGLayer = NULL;
  247. m_pimTextLayer = NULL;
  248. m_pimDst = NULL;
  249. m_pmaAlpha = NULL;
  250. m_bDeleteFont = true;
  251. m_sDelW = 0;
  252. m_sDelH = 0;
  253. m_lTotalBytes = 0;
  254. m_lTimeToUpdate = 0;
  255. m_lBytesSoFar = 0;
  256. m_u8BloodColor = 0;
  257. m_sLastDistance = 0;
  258. m_musicID = g_smidNil;
  259. }
  260. CCutSceneInfo()
  261. {
  262. Clear();
  263. }
  264. ~CCutSceneInfo()
  265. {
  266. if (m_bDeleteFont && m_pFont) delete m_pFont;
  267. if (m_pimBGLayer) delete m_pimBGLayer;
  268. if (m_pimTextLayer) delete m_pimTextLayer;
  269. if (m_pmaAlpha) delete m_pmaAlpha;
  270. Clear();
  271. }
  272. };
  273. ////////////////////////////////////////////////////////////////////////////////
  274. //
  275. // MartiniDo - this is a greatly simplified version of the cutscene Martini
  276. //
  277. // It allows the user a few parameters and then does the effect for a set
  278. // amount of time, regardless of user input. There are no text overlays.
  279. // The program will blacken the screen when done. (g_pimScreenBuf)
  280. //
  281. ////////////////////////////////////////////////////////////////////////////////
  282. short MartiniDo( RImage* pimBackground, // actually, this is the ONLY graphic
  283. short sStartX, // logical start position of image
  284. short sStartY, // NOTE: it will be clipped so won't actually hit this point!
  285. RMultiAlpha* pAlpha, // only need 50% - see cut scenes
  286. long lMilliLen, // how long to do the effect
  287. short sRadius, // Your tuning pleasure
  288. long lSpinTime, // in milliseconds
  289. long lSwayTime, // in milliseconds
  290. RRect* prCenter, // if not NULL, use this portion of the image only!
  291. long lFadeTime, // fade to black, in milliseconds.
  292. SampleMaster::SoundInstance siFade // to make sound fade out
  293. )
  294. {
  295. // In casew Bill just haphazardly passed me the screen buffer, make a dubber copy:
  296. RImage imSwirl;
  297. rspGeneralLock(pimBackground);
  298. if (prCenter)
  299. {
  300. imSwirl.CreateImage(prCenter->sW,prCenter->sH,RImage::BMP8);
  301. rspBlit(pimBackground,&imSwirl,
  302. prCenter->sX,prCenter->sY,0,0,
  303. prCenter->sW,prCenter->sH);
  304. sStartX += prCenter->sX;
  305. sStartY += prCenter->sY;
  306. }
  307. else
  308. {
  309. imSwirl.CreateImage(pimBackground->m_sWidth,pimBackground->m_sHeight,RImage::BMP8);
  310. rspBlit(pimBackground,&imSwirl,0,0,0,0,pimBackground->m_sWidth,pimBackground->m_sHeight);
  311. }
  312. rspGeneralUnlock(pimBackground);
  313. rspLockBuffer();
  314. rspRect(RSP_BLACK_INDEX,g_pimScreenBuf,0,0,g_pimScreenBuf->m_sWidth,g_pimScreenBuf->m_sHeight);
  315. rspUnlockBuffer(); // Dom't show th black!
  316. //==============================================================================
  317. // Set up clipping parameters based on radius:
  318. RRect rClip(sStartX,sStartY,imSwirl.m_sWidth,imSwirl.m_sHeight);
  319. // shrink by radius (should work! - this should hide all redrawing!)
  320. rClip.sX += sRadius;
  321. rClip.sY += sRadius;
  322. rClip.sW -= sRadius<<1;
  323. rClip.sH -= sRadius<<1;
  324. //==============================================================================
  325. // Copy the palette:
  326. UCHAR PaletteCopy[256 * 3] = {0,};
  327. rspGetPaletteEntries(10,236,PaletteCopy+30,PaletteCopy + 31,PaletteCopy + 32,3);
  328. long lStartTime = rspGetMilliseconds();
  329. long lCurrentTime = -1;
  330. long lStartFadeTime = lMilliLen - lFadeTime; // lCurrentTime is relative to lStartTime
  331. // Attempt to do a fade out while swirling....
  332. while (((lCurrentTime = (rspGetMilliseconds() - lStartTime)) < lMilliLen) && !(rspGetQuitStatus()))
  333. {
  334. long lCurrentFadeTime = lCurrentTime - lStartFadeTime;
  335. //==============================================================================
  336. // Figure out stage of motion:
  337. //==============================================================================
  338. short sDeg = short((360 * lCurrentTime)/lSpinTime);
  339. sDeg = rspMod360(sDeg);
  340. short sSwayDeg = short((360 * lCurrentTime)/lSwayTime);
  341. sSwayDeg = rspMod360(sSwayDeg);
  342. short sR = short(sRadius * rspSin(sSwayDeg));
  343. short sOffX = short(rspCos(sDeg) * sR);
  344. short sOffY = short(rspSin(sDeg) * sR);
  345. //==============================================================================
  346. // Draw the frame!
  347. rspLockBuffer();
  348. // Opaque Blit!
  349. rspBlit(&imSwirl,g_pimScreenBuf,0,0,sStartX + sOffX,sStartY + sOffY,
  350. imSwirl.m_sWidth,imSwirl.m_sHeight,&rClip);
  351. // Alpha Blit!
  352. rspAlphaBlitT(128,pAlpha,&imSwirl,g_pimScreenBuf,
  353. sStartX - sOffX,sStartY - sOffY,&rClip);
  354. rspUnlockBuffer();
  355. rspUpdateDisplay();
  356. //---------------------------------------
  357. // Do a palette fade out:
  358. if (lCurrentFadeTime > 0)
  359. {
  360. // Update the Palette:
  361. short i=0;
  362. short sCurPal = 10 * 3;
  363. short sByteLevel = short((255.0 * lCurrentFadeTime) / lFadeTime);
  364. for (i=10; i < 246; i++, sCurPal += 3)
  365. {
  366. rspSetPaletteEntry( i,
  367. (PaletteCopy[sCurPal + 0] * (256 - sByteLevel)) / 256,
  368. (PaletteCopy[sCurPal + 1] * (256 - sByteLevel)) / 256,
  369. (PaletteCopy[sCurPal + 2] * (256 - sByteLevel)) / 256
  370. );
  371. }
  372. rspUpdatePalette();
  373. if (siFade) // adjust sound volume:
  374. {
  375. SetInstanceVolume(siFade,255 - sByteLevel);
  376. }
  377. }
  378. //---------------------------------------
  379. UpdateSystem();
  380. }
  381. //==============================================================================
  382. // Now do a fade out
  383. //==============================================================================
  384. rspLockBuffer();
  385. rspRect(RSP_BLACK_INDEX,g_pimScreenBuf,0,0,g_pimScreenBuf->m_sWidth,g_pimScreenBuf->m_sHeight);
  386. rspUpdateDisplay();
  387. rspUnlockBuffer();
  388. return SUCCESS;
  389. }
  390. ////////////////////////////////////////////////////////////////////////////////
  391. //
  392. //
  393. ////////////////////////////////////////////////////////////////////////////////
  394. class CSwirlMe
  395. {
  396. public:
  397. //------------------------------------------------------------------
  398. short m_sCenX; // radius in pixels
  399. short m_sRadX;
  400. short m_sCenY; // radius in pixels
  401. short m_sRadY;
  402. double m_dCenA; // Alpha level (0.0 to 1.0)
  403. double m_dRadA;
  404. long m_lCycleTimeX; // in milliseconds (Min, Max, Min)
  405. long m_lCycleTimeY; // in milliseconds (Min, Max, Min)
  406. long m_lCycleTimeA; //
  407. long m_lTimeSpin;
  408. long m_lBaseTime;
  409. RRect m_rClip; // To offset and limit the effect to a rect:
  410. SampleMaster::SoundInstance m_siSound;
  411. CCutSceneInfo* m_pCut;
  412. //------------------------------------------------------------------
  413. ////////////////////////////////////////////////////////////////////////////
  414. // Make next frame of effect
  415. ////////////////////////////////////////////////////////////////////////////
  416. short MakeFrame(SampleMasterID* psmid)
  417. {
  418. if (!IsSamplePlaying(*psmid))
  419. {
  420. PlaySample( // Returns nothing.
  421. // Does not fail.
  422. *psmid, // In: Identifier of sample you want played.
  423. SampleMaster::Unspecified, // In: Sound Volume Category for user adjustment
  424. 255, // In: Initial Sound Volume (0 - 255)
  425. &m_siSound, // Out: Handle for adjusting sound volume
  426. NULL, // Out: Sample duration in ms, if not NULL.
  427. 0, // In: Where to loop back to in milliseconds.
  428. // -1 indicates no looping (unless m_sLoop is
  429. // explicitly set).
  430. 0, // In: Where to loop back from in milliseconds.
  431. // In: If less than 1, the end + lLoopEndTime is used.
  432. true); // In: Call ReleaseAndPurge rather than Release after playing
  433. }
  434. if (!m_lBaseTime) m_lBaseTime = rspGetMilliseconds();
  435. long lDeltaTime = rspGetMilliseconds() - m_lBaseTime;
  436. short sDegX = (360 * lDeltaTime) / m_lCycleTimeX;
  437. short sDegY = (360 * lDeltaTime) / m_lCycleTimeY;
  438. short sDegAlpha = (360 * lDeltaTime) / m_lCycleTimeA;
  439. short sDegSpin = (360 * lDeltaTime) / m_lTimeSpin;
  440. sDegX = rspMod360(sDegX);
  441. sDegY = rspMod360(sDegY);
  442. sDegAlpha = rspMod360(sDegAlpha);
  443. sDegSpin = rspMod360(sDegSpin);
  444. short sRx = m_sCenX + short(rspSin(sDegX) * m_sRadX);
  445. short sRy = m_sCenY + short(rspSin(sDegY) * m_sRadY);
  446. if (sRx < 0) sRx = 0;
  447. if (sRy < 0) sRy = 0;
  448. short sOffX = short(rspCos(sDegSpin) * sRx);
  449. short sOffY = -short(rspSin(sDegSpin) * sRy);
  450. sOffX >>= 1;
  451. sOffY >>= 1;
  452. double dAlpha = m_dCenA + rspSin(sDegAlpha) * m_dRadA;
  453. //----------------------- Use global alpha --------------------
  454. RRect rSafeClip = m_rClip;
  455. rSafeClip.sX += m_sRadX;
  456. rSafeClip.sY += m_sRadY;
  457. rSafeClip.sW -= (m_sRadX<<1);
  458. rSafeClip.sH -= (m_sRadY<<1);
  459. //******************************************************************************
  460. // THIS IS A COMPLETE HACK - IT IS A LAST MINUTE ATTEMPT TO ADJUST FOR THE
  461. // CHANGE TO THE CUT SCENE ASSEST WHICH ADDED BLACK STRIPS TO THE TOP AND
  462. // BOTTOM OF THE SCREEN....
  463. //******************************************************************************
  464. rSafeClip.sY += 40; // HARD CODED FOR POSTAL!
  465. rSafeClip.sH -= 80; // HARD CODED FOR POSTAL!
  466. //******************************************************************************
  467. // 1) Put original image down upon target:
  468. if (m_pCut->m_pimBGLayer)
  469. {
  470. rspLockBuffer();
  471. rspBlit(m_pCut->m_pimBGLayer,m_pCut->m_pimDst,0,0,m_rClip.sX - sOffX,m_rClip.sY - sOffY,
  472. m_rClip.sW,m_rClip.sH,&rSafeClip);
  473. // 2) Alpha Blit Upon it:
  474. if (m_pCut->m_pmaAlpha != NULL)
  475. {
  476. rspAlphaBlitT(short(255.9*dAlpha),m_pCut->m_pmaAlpha,m_pCut->m_pimBGLayer,m_pCut->m_pimDst,
  477. m_rClip.sX + sOffX,m_rClip.sY + sOffY,&rSafeClip);
  478. }
  479. // 3) GENLOCK the text:
  480. rspBlit(m_pCut->m_pimTextLayer,m_pCut->m_pimDst,0,0);
  481. // 4) You're done - let the app update the screen -> he can use
  482. // the given function or do it himself!
  483. rspUnlockBuffer();
  484. }
  485. return SUCCESS;
  486. }
  487. ////////////////////////////////////////////////////////////////////////////
  488. // Configure effect
  489. ////////////////////////////////////////////////////////////////////////////
  490. short Configure(//RImage* pimDst,RImage* pimSrc,RMultiAlpha* pX,
  491. long lTimeSpin,
  492. short sMinX,short sMaxX,long lTimeX,
  493. short sMinY,short sMaxY,long lTimeY,
  494. double dMinA,double dMaxA,long lTimeA,
  495. short sX,short sY,short sW,short sH)
  496. {
  497. ASSERT(m_pCut);
  498. ASSERT(lTimeX > 0);
  499. ASSERT(lTimeY > 0);
  500. ASSERT(lTimeA > 0);
  501. ASSERT(lTimeSpin > 0);
  502. ASSERT((dMinA >= 0.0) && (dMinA <= 1.0));
  503. ASSERT((dMaxA >= 0.0) && (dMaxA <= 1.0));
  504. ASSERT(sW > 0);
  505. ASSERT(sH> 0);
  506. //----------------------------------------------
  507. m_sRadX = (sMaxX - sMinX)>>1;
  508. m_sCenX = sMinX + m_sRadX;
  509. m_sRadY = (sMaxY - sMinY)>>1;
  510. m_sCenY = sMinY + m_sRadY;
  511. m_dRadA = (dMaxA - dMinA)/2.0;
  512. m_dCenA = dMinA + m_dRadA;
  513. m_lCycleTimeX = lTimeX;
  514. m_lCycleTimeY = lTimeY;
  515. m_lCycleTimeA = lTimeA;
  516. m_lTimeSpin = lTimeSpin;
  517. // Center the effect!
  518. if (m_pCut->m_pimBGLayer)
  519. {
  520. m_pCut->m_sDelW = m_pCut->m_pimDst->m_sWidth - m_pCut->m_pimBGLayer->m_sWidth;
  521. m_pCut->m_sDelH = m_pCut->m_pimDst->m_sHeight - m_pCut->m_pimBGLayer->m_sHeight;
  522. }
  523. else
  524. {
  525. m_pCut->m_sDelW = 0;
  526. m_pCut->m_sDelH = 0;
  527. }
  528. m_rClip.sX = sX + (m_pCut->m_sDelW >> 1);
  529. m_rClip.sY = sY + (m_pCut->m_sDelH >> 1);
  530. m_rClip.sW = sW - m_pCut->m_sDelW;
  531. m_rClip.sH = sH - m_pCut->m_sDelH;
  532. rspLockBuffer();
  533. rspRect(RSP_BLACK_INDEX,m_pCut->m_pimDst,0,0,m_pCut->m_pimDst->m_sWidth,m_pCut->m_pimDst->m_sHeight);
  534. rspUnlockBuffer();
  535. m_lBaseTime = 0;//rspGetMilliseconds();
  536. return SUCCESS;
  537. }
  538. ////////////////////////////////////////////////////////////////////////////
  539. // Erase
  540. ////////////////////////////////////////////////////////////////////////////
  541. void Erase()
  542. {
  543. m_sCenX = m_sCenY = m_sRadX = m_sRadY =
  544. m_lTimeSpin = m_lCycleTimeX = m_lCycleTimeY = m_lCycleTimeA = 0;
  545. m_dCenA = m_dRadA = 0.0;
  546. m_rClip = RRect(0,0,0,0);
  547. m_siSound = NULL;
  548. }
  549. ////////////////////////////////////////////////////////////////////////////
  550. // CSwirlMe
  551. ////////////////////////////////////////////////////////////////////////////
  552. CSwirlMe(
  553. CCutSceneInfo* pCut)
  554. {
  555. m_pCut = pCut; // YOU must free the cut scene info - we won't clear it!
  556. Erase();
  557. }
  558. ////////////////////////////////////////////////////////////////////////////
  559. // ~CSwirlMe
  560. ////////////////////////////////////////////////////////////////////////////
  561. ~CSwirlMe()
  562. {
  563. if (m_siSound != 0) AbortSample(m_siSound);
  564. m_siSound = 0;
  565. m_pCut = NULL; // we don't free this - you do!
  566. }
  567. ////////////////////////////////////////////////////////////////////////////
  568. // Update (optional) - from screen buffer only!
  569. ////////////////////////////////////////////////////////////////////////////
  570. void Update()
  571. {
  572. rspUpdateDisplay(m_rClip.sX,m_rClip.sY,m_rClip.sW,m_rClip.sH);
  573. }
  574. ////////////////////////////////////////////////////////////////////////////
  575. // Clear
  576. ////////////////////////////////////////////////////////////////////////////
  577. void Clear()
  578. {
  579. //if (m_pimCopy) delete m_pimCopy;
  580. Erase();
  581. }
  582. };
  583. ////////////////////////////////////////////////////////////////////////////////
  584. // Variables/data
  585. ////////////////////////////////////////////////////////////////////////////////
  586. static CCutSceneInfo* ms_pCut = NULL;
  587. static CSwirlMe* pSwirl = NULL;
  588. ////////////////////////////////////////////////////////////////////////////////
  589. // Function prototypes
  590. ////////////////////////////////////////////////////////////////////////////////
  591. static void CutScene_RFileCallback(long lBytes);
  592. ////////////////////////////////////////////////////////////////////////////////
  593. //
  594. // Start cutscene.
  595. //
  596. // If 'simple' mode is true, a simple background is displayed with the name
  597. // of the realm file printed on it.
  598. //
  599. // Otherwise, the variables in the specified section of the specified prefs file
  600. // determine what text is printed on top of the background.
  601. //
  602. // If a special effect is desired, CutSceneConfig() must be called, followed
  603. // by repeated calls to CutSceneUpdate().
  604. //
  605. // CutSceneEnd() must be called when the cutscene is no longer needed.
  606. //
  607. ////////////////////////////////////////////////////////////////////////////////
  608. extern void CutSceneStart(
  609. bool bSimple, // In: Set to 'true' for simple mode
  610. const RString* pstrSection, // In: Section to use for this realm
  611. const RString* pstrEntry, // In: Entry to use for this realm
  612. short sBorderX,
  613. short sBorderY)
  614. {
  615. // This is used for more than just paths, so it has a larger size!
  616. char szText[2048];
  617. // Init stuff
  618. ms_pCut = new CCutSceneInfo;
  619. ms_pCut->m_pimDst = g_pimScreenBuf;
  620. // Clear screen
  621. rspLockBuffer();
  622. rspRect(RSP_BLACK_INDEX, ms_pCut->m_pimDst, 0, 0, ms_pCut->m_pimDst->m_sWidth, ms_pCut->m_pimDst->m_sHeight);
  623. rspUnlockBuffer();
  624. rspUpdateDisplay();
  625. // Open the realm prefs file
  626. RPrefs prefsRealm;
  627. if (prefsRealm.Open(FullPathHD(g_GameSettings.m_pszRealmPrefsFile), "rt") != 0)
  628. {
  629. TRACE("CutSceneStart(): Error opening prefs file.\n");
  630. return ;
  631. }
  632. //------------------------------------------------------------------------------
  633. // Get BG
  634. //------------------------------------------------------------------------------
  635. // In simple mode, use default bg. Otherwise, get bg from prefs file.
  636. if (bSimple)
  637. {
  638. strcpy(szText, DEFAULT_BG);
  639. }
  640. else
  641. {
  642. prefsRealm.GetVal(*pstrSection, "Bg", DEFAULT_BG, szText);
  643. if ((strlen(szText) + 1) >= RSP_MAX_PATH)
  644. {
  645. TRACE("CutScene(): Bg file name/path too long: '%s'!\n", szText);
  646. strcpy(szText, DEFAULT_BG);
  647. }
  648. }
  649. // Load bg, but do NOT display yet!
  650. ms_pCut->m_pimBGLayer = new RImage;
  651. if ((ms_pCut->m_pimBGLayer->Load(FullPathHD(szText)) == 0) ||
  652. (ms_pCut->m_pimBGLayer->Load(FullPathVD(szText)) == 0))
  653. {
  654. // Set palette
  655. ASSERT(ms_pCut->m_pimBGLayer->m_pPalette != NULL);
  656. ASSERT(ms_pCut->m_pimBGLayer->m_pPalette->m_type == RPal::PDIB);
  657. rspSetPaletteEntries(
  658. 0, 256, ms_pCut->m_pimBGLayer->m_pPalette->Red(0),
  659. ms_pCut->m_pimBGLayer->m_pPalette->Green(0),
  660. ms_pCut->m_pimBGLayer->m_pPalette->Blue(0),
  661. ms_pCut->m_pimBGLayer->m_pPalette->m_sPalEntrySize);
  662. rspUpdatePalette();
  663. }
  664. else
  665. {
  666. TRACE("CutScene(): Error loading bg image: '%s'\n", FullPathVD(szText));
  667. delete ms_pCut->m_pimBGLayer;
  668. ms_pCut->m_pimBGLayer = NULL;
  669. }
  670. //------------------------------------------------------------------------------
  671. // Get tables used for color matching
  672. //------------------------------------------------------------------------------
  673. U8 au8Red[256];
  674. U8 au8Green[256];
  675. U8 au8Blue[256];
  676. rspGetPaletteEntries(0, 256, au8Red, au8Green, au8Blue, sizeof(U8));
  677. //------------------------------------------------------------------------------
  678. // Get multialpha
  679. //------------------------------------------------------------------------------
  680. ms_pCut->m_pmaAlpha = new RMultiAlpha;
  681. prefsRealm.GetVal(*pstrSection, "Alpha", DEFAULT_MULTIALPHA, szText);
  682. if ((ms_pCut->m_pmaAlpha->Load(FullPathHD(szText)) == 0) ||
  683. (ms_pCut->m_pmaAlpha->Load(FullPathVD(szText)) == 0))
  684. {
  685. }
  686. else
  687. {
  688. TRACE("CutScene(): Error loading multialpha: '%s'\n", FullPathVD(szText));
  689. delete ms_pCut->m_pmaAlpha;
  690. ms_pCut->m_pmaAlpha = NULL;
  691. }
  692. //------------------------------------------------------------------------------
  693. // Get font
  694. //------------------------------------------------------------------------------
  695. // Try to load font, but if it fails, use the already-loaded game font
  696. ms_pCut->m_bDeleteFont = true;
  697. ms_pCut->m_pFont = new RFont;
  698. if (ms_pCut->m_pFont->Load(FullPathVD(FONT_FILE)) != SUCCESS)
  699. {
  700. TRACE("CutScene(): Error loading font: '%s'!\n", FullPathVD(FONT_FILE));
  701. delete ms_pCut->m_pFont;
  702. ms_pCut->m_pFont = &g_fontBig; // system font
  703. ms_pCut->m_bDeleteFont = false; // don't try to free it!
  704. }
  705. // Find closest matches for the desired colors
  706. ms_pCut->m_ucForeText = rspMatchColorRGB(
  707. FONT_FORE_R, FONT_FORE_G, FONT_FORE_B, 10, 236, au8Red, au8Green, au8Blue, sizeof(U8));
  708. ms_pCut->m_ucShadowText = rspMatchColorRGB(
  709. FONT_SHAD_R, FONT_SHAD_G, FONT_SHAD_B, 10, 236, au8Red, au8Green, au8Blue, sizeof(U8));
  710. // Setup print
  711. RPrint print;
  712. //------------------------------------------------------------------------------
  713. // Get title
  714. //------------------------------------------------------------------------------
  715. // In simple mode, use default title. Otherwise, get title from prefs file.
  716. if (bSimple)
  717. {
  718. strcpy(ms_pCut->m_szTitle, DEFAULT_TITLE);
  719. }
  720. else
  721. {
  722. prefsRealm.GetVal(*pstrSection, "Title", DEFAULT_TITLE, ms_pCut->m_szTitle);
  723. if ((strlen(ms_pCut->m_szTitle) + 1) >= sizeof(ms_pCut->m_szTitle))
  724. {
  725. TRACE("CutScene(): Title too long: '%s'!\n", ms_pCut->m_szTitle);
  726. strcpy(ms_pCut->m_szTitle, DEFAULT_TITLE);
  727. }
  728. }
  729. //------------------------------------------------------------------------------
  730. // Get music
  731. //------------------------------------------------------------------------------
  732. // In simple mode, use the default music, otherwise get the music from prefs file
  733. if (bSimple)
  734. {
  735. strcpy(ms_pCut->m_szMusic, DEFAULT_MUSIC);
  736. }
  737. else
  738. {
  739. prefsRealm.GetVal(*pstrSection, "Music", DEFAULT_MUSIC, ms_pCut->m_szMusic);
  740. if ((strlen(ms_pCut->m_szMusic) + 1) >= sizeof(ms_pCut->m_szMusic))
  741. {
  742. TRACE("CutScene(): Music filename too long: '%s'!\n", ms_pCut->m_szMusic);
  743. strcpy(ms_pCut->m_szMusic, DEFAULT_MUSIC);
  744. }
  745. }
  746. // Set the resource name for the sample
  747. ms_pCut->m_musicID.pszId = ms_pCut->m_szMusic;
  748. ms_pCut->m_musicID.usDescFlags = SMDF_NO_DESCRIPT;
  749. //------------------------------------------------------------------------------
  750. // Create the Text overlay layer (GENLOCK!)
  751. //------------------------------------------------------------------------------
  752. ms_pCut->m_pimTextLayer = new RImage;
  753. ms_pCut->m_pimTextLayer->CreateImage(ms_pCut->m_pimDst->m_sWidth,ms_pCut->m_pimDst->m_sHeight,RImage::BMP8);
  754. // Create text layer
  755. print.SetDestination(ms_pCut->m_pimTextLayer);
  756. print.SetFont(48, ms_pCut->m_pFont);
  757. print.SetColor(ms_pCut->m_ucForeText, 0, ms_pCut->m_ucShadowText);
  758. print.SetEffectAbs(RPrint::SHADOW_X, 2);
  759. print.SetEffectAbs(RPrint::SHADOW_Y, 2);
  760. print.print(((ms_pCut->m_pimTextLayer->m_sWidth - print.GetWidth(ms_pCut->m_szTitle)) / 2),
  761. NAME_Y, ms_pCut->m_szTitle);
  762. // Get text to be displayed
  763. if (bSimple)
  764. {
  765. strcpy(ms_pCut->m_szText, DEFAULT_TEXT);
  766. }
  767. else
  768. {
  769. prefsRealm.GetVal(*pstrSection, "Text", DEFAULT_TEXT, ms_pCut->m_szText);
  770. if ((strlen(ms_pCut->m_szText) + 1) >= sizeof(ms_pCut->m_szText))
  771. {
  772. TRACE("CutScene(): Text too long: '%s'!\n", ms_pCut->m_szText);
  773. strcpy(ms_pCut->m_szText, DEFAULT_TEXT);
  774. }
  775. }
  776. // Create cropping rectangle
  777. // Try to compensate by the way the POSTAL cut scene assets were hosed
  778. RRect rCrop;
  779. if (ms_pCut->m_pimBGLayer)
  780. {
  781. rCrop = RRect(
  782. BG_X + sBorderX,
  783. BG_Y + sBorderY + 40, // there were horizontal strips implanted
  784. ms_pCut->m_pimBGLayer->m_sWidth - (sBorderX * 2),
  785. ms_pCut->m_pimBGLayer->m_sHeight - (sBorderY * 2) - 80);
  786. }
  787. else
  788. {
  789. rCrop.sX = 0;
  790. rCrop.sY = 0;
  791. rCrop.sW = g_pimScreenBuf->m_sWidth - (sBorderX * 2);
  792. rCrop.sH = g_pimScreenBuf->m_sHeight - (sBorderY * 2) - 80;
  793. }
  794. // Create text layer
  795. print.SetFont(28, ms_pCut->m_pFont);
  796. print.SetColor(ms_pCut->m_ucForeText, 0, ms_pCut->m_ucShadowText);
  797. print.SetEffectAbs(RPrint::SHADOW_X, 1);
  798. print.SetEffectAbs(RPrint::SHADOW_Y, 1);
  799. print.SetWordWrap(TRUE);
  800. print.SetColumn(rCrop.sX + MARGIN, rCrop.sY, rCrop.sW - (MARGIN*2), rCrop.sH);
  801. print.print(0, TEXT_Y, ms_pCut->m_szText);
  802. ms_pCut->m_pimTextLayer->Convert(RImage::FSPR8);
  803. //------------------------------------------------------------------------------
  804. // Update the actual screen now that everything is ready
  805. //------------------------------------------------------------------------------
  806. // We must lock the composite buffer before reading/writing it.
  807. rspLockBuffer();
  808. // Clear dst to black
  809. rspRect(
  810. RSP_BLACK_INDEX,
  811. ms_pCut->m_pimDst,
  812. 0, 0,
  813. ms_pCut->m_pimDst->m_sWidth, ms_pCut->m_pimDst->m_sHeight);
  814. if (ms_pCut->m_pimBGLayer)
  815. {
  816. // Copy bg image to dst, cropping as we go
  817. rspBlit(
  818. ms_pCut->m_pimBGLayer,
  819. ms_pCut->m_pimDst,
  820. 0, 0,
  821. BG_X, BG_Y,
  822. ms_pCut->m_pimBGLayer->m_sWidth, ms_pCut->m_pimBGLayer->m_sHeight,
  823. &rCrop);
  824. RRect rcBGClipper(
  825. 0,
  826. 0,
  827. ms_pCut->m_pimBGLayer->m_sWidth,
  828. ms_pCut->m_pimBGLayer->m_sHeight);
  829. // Copy progress bar area of bg image to dst with SOURCE clipping
  830. // just in case image is too small.
  831. rspBlit(
  832. ms_pCut->m_pimBGLayer, // Src.
  833. ms_pCut->m_pimDst, // Dst.
  834. PROGRESS_BOX_X, PROGRESS_BOX_Y, // Src.
  835. PROGRESS_BOX_X, PROGRESS_BOX_Y, // Dst.
  836. PROGRESS_BOX_WIDTH, PROGRESS_BOX_HEIGHT, // Both.
  837. NULL, // Dst.
  838. &rcBGClipper); // Src.
  839. }
  840. // Copy text image to dst, cropping as we go
  841. rspBlit(
  842. ms_pCut->m_pimTextLayer,
  843. ms_pCut->m_pimDst,
  844. 0, 0,
  845. &rCrop);
  846. // Release composite buffer now that we are done.
  847. rspUnlockBuffer();
  848. // Update display
  849. rspUpdateDisplay();
  850. //------------------------------------------------------------------------------
  851. // Close prefs file.
  852. //------------------------------------------------------------------------------
  853. prefsRealm.Close();
  854. //------------------------------------------------------------------------------
  855. // Setup stuff for the progress bar
  856. //------------------------------------------------------------------------------
  857. // Hook the RFile callback that tells us how much data is about to be read/written
  858. RFile::ms_criticall = CutScene_RFileCallback;
  859. // Reset various stuff
  860. ms_pCut->m_lBytesSoFar = 0;
  861. ms_pCut->m_lTotalBytes = 12000000;
  862. ms_pCut->m_lTimeToUpdate = rspGetMilliseconds();
  863. ms_pCut->m_sLastDistance = 0;
  864. // Find good blood color
  865. ms_pCut->m_u8BloodColor = rspMatchColorRGB(
  866. BLOOD_FORE_R, BLOOD_FORE_G, BLOOD_FORE_B, 1, 254, au8Red, au8Green, au8Blue, sizeof(U8));
  867. }
  868. ////////////////////////////////////////////////////////////////////////////
  869. //
  870. // Configure cutscene effect
  871. //
  872. ////////////////////////////////////////////////////////////////////////////
  873. extern short CutSceneConfig(
  874. long lTimeSpin,
  875. short sMinX,short sMaxX,long lTimeX,
  876. short sMinY,short sMaxY,long lTimeY,
  877. double dMinA,double dMaxA,long lTimeA,
  878. short sX,short sY,short sW,short sH)
  879. {
  880. ASSERT(ms_pCut);
  881. pSwirl = new CSwirlMe(ms_pCut);
  882. if (ms_pCut->m_pimBGLayer)
  883. {
  884. // Erase progress bar region from BG layer and dst and display
  885. // Note: We use the color index in the upper left corner of the BG layer
  886. // to erase this area. We can't use the expected RSP_BLACK_INDEX because
  887. // on the mac, it creates problems with the multialpha stuff. We assume
  888. // the pixel in the upper left corner is black, but it's a DIFFERENT black
  889. // which is safe to use with the multialpha stuff.
  890. rspRect(
  891. *(ms_pCut->m_pimBGLayer->m_pData),
  892. ms_pCut->m_pimBGLayer,
  893. PROGRESS_BOX_X, PROGRESS_BOX_Y,
  894. PROGRESS_BOX_WIDTH, PROGRESS_BOX_HEIGHT);
  895. RRect rcBGClipper(
  896. 0,
  897. 0,
  898. ms_pCut->m_pimBGLayer->m_sWidth,
  899. ms_pCut->m_pimBGLayer->m_sHeight);
  900. rspLockBuffer();
  901. // Copy progress bar area of bg image to dst with SOURCE clipping
  902. // just in case image is too small.
  903. rspBlit(
  904. ms_pCut->m_pimBGLayer, // Src.
  905. ms_pCut->m_pimDst, // Dst.
  906. PROGRESS_BOX_X, PROGRESS_BOX_Y, // Src.
  907. PROGRESS_BOX_X, PROGRESS_BOX_Y, // Dst.
  908. PROGRESS_BOX_WIDTH, PROGRESS_BOX_HEIGHT, // Both.
  909. NULL, // Dst.
  910. &rcBGClipper); // Src.
  911. rspUnlockBuffer();
  912. rspUpdateDisplay(PROGRESS_BOX_X, PROGRESS_BOX_Y, PROGRESS_BOX_WIDTH, PROGRESS_BOX_HEIGHT);
  913. }
  914. // Clear RFile hook so nothing gets drawn after this
  915. RFile::ms_criticall = 0;
  916. return pSwirl->Configure(
  917. lTimeSpin,
  918. sMinX, sMaxX, lTimeX,
  919. sMinY, sMaxY, lTimeY,
  920. dMinA, dMaxA, lTimeA,
  921. sX, sY, sW, sH);
  922. }
  923. ////////////////////////////////////////////////////////////////////////////
  924. //
  925. // Update cutscene effect
  926. //
  927. ////////////////////////////////////////////////////////////////////////////
  928. extern void CutSceneUpdate(void)
  929. {
  930. ASSERT(ms_pCut);
  931. ASSERT(pSwirl);
  932. pSwirl->MakeFrame(&(ms_pCut->m_musicID));
  933. pSwirl->Update();
  934. }
  935. ////////////////////////////////////////////////////////////////////////////////
  936. //
  937. // Clean up after the cutscene. It is safe to call this multiple times.
  938. //
  939. ////////////////////////////////////////////////////////////////////////////////
  940. extern void CutSceneEnd(void)
  941. {
  942. delete ms_pCut;
  943. ms_pCut = 0;
  944. delete pSwirl;
  945. pSwirl = 0;
  946. // Clear RFile hook
  947. RFile::ms_criticall = 0;
  948. }
  949. ////////////////////////////////////////////////////////////////////////////////
  950. //
  951. // Our RFile callback
  952. //
  953. ////////////////////////////////////////////////////////////////////////////////
  954. static void CutScene_RFileCallback(long lBytes)
  955. {
  956. static short asWavyY[] =
  957. {
  958. 0, 1, 2, 0, -2, -1, 1, 0, -1, 0, 1, 2, 1, 0,
  959. 1, 0, -1, -2, -1, -2, 0, 1, 2, 0, -2, -1, 0, 0
  960. };
  961. if (ms_pCut)
  962. {
  963. if (ms_pCut->m_pimBGLayer && ms_pCut->m_pmaAlpha)
  964. {
  965. if (ms_pCut->m_pimBGLayer->m_type != RImage::NOT_SUPPORTED)
  966. {
  967. // Update bytes so far
  968. ms_pCut->m_lBytesSoFar += lBytes;
  969. // Check if time for an update
  970. long lNow = rspGetMilliseconds();
  971. if ((lNow - ms_pCut->m_lTimeToUpdate) > PROGRESS_BAR_UPDATE_TIME)
  972. {
  973. // Get percentage that's been loaded so far (result is from 0 to 1)
  974. double dPercentage = (double)ms_pCut->m_lBytesSoFar / (double)ms_pCut->m_lTotalBytes;
  975. if (dPercentage > 1.0)
  976. dPercentage = 1.0;
  977. short sDistance = (short)((double)PROGRESS_BAR_WIDTH * dPercentage);
  978. short sBaseY = asWavyY[(short)(dPercentage * (NUM_ELEMENTS(asWavyY) - 1) )];
  979. // Draw from previous distance to current distance in case a big jump occurred
  980. for (short sBaseX = ms_pCut->m_sLastDistance; sBaseX <= sDistance; sBaseX++)
  981. {
  982. // Draw a few pixels at a time to get a more solid look
  983. for (short i = 0; i < PROGRESS_BAR_DENSITY; i++)
  984. {
  985. // Choose random location nearby the specified location
  986. short sX = PROGRESS_BAR_START_X + sBaseX + RandomPlusMinus(PROGRESS_BAR_RANDOM_X);
  987. short sY = PROGRESS_BAR_START_Y + sBaseY + RandomPlusMinus(PROGRESS_BAR_RANDOM_Y);
  988. // Draw an alpha'd pixel at this location
  989. U8 u8dst = *(ms_pCut->m_pimBGLayer->m_pData + (sY * ms_pCut->m_pimBGLayer->m_lPitch) + sX);
  990. rspPlot(
  991. rspBlendColor(150, ms_pCut->m_pmaAlpha, ms_pCut->m_u8BloodColor, u8dst),
  992. ms_pCut->m_pimBGLayer,
  993. sX,
  994. sY);
  995. }
  996. }
  997. // Save for next time
  998. ms_pCut->m_sLastDistance = sDistance;
  999. // Update progress bar area
  1000. RRect rcBGClipper(
  1001. 0,
  1002. 0,
  1003. ms_pCut->m_pimBGLayer->m_sWidth,
  1004. ms_pCut->m_pimBGLayer->m_sHeight);
  1005. rspLockBuffer();
  1006. // Copy progress bar area of bg image to dst with SOURCE clipping
  1007. // just in case image is too small.
  1008. rspBlit(
  1009. ms_pCut->m_pimBGLayer, // Src.
  1010. ms_pCut->m_pimDst, // Dst.
  1011. PROGRESS_BOX_X, PROGRESS_BOX_Y, // Src.
  1012. PROGRESS_BOX_X, PROGRESS_BOX_Y, // Dst.
  1013. PROGRESS_BOX_WIDTH, PROGRESS_BOX_HEIGHT, // Both.
  1014. NULL, // Dst.
  1015. &rcBGClipper); // Src.
  1016. rspUnlockBuffer();
  1017. rspUpdateDisplay(PROGRESS_BOX_X, PROGRESS_BOX_Y, PROGRESS_BOX_WIDTH, PROGRESS_BOX_HEIGHT);
  1018. // Do an update
  1019. UpdateSystem();
  1020. // Save new time
  1021. ms_pCut->m_lTimeToUpdate = lNow;
  1022. }
  1023. }
  1024. }
  1025. }
  1026. }
  1027. ////////////////////////////////////////////////////////////////////////////////
  1028. // EOF
  1029. ////////////////////////////////////////////////////////////////////////////////