f_wipe.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code 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. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "Precompiled.h"
  21. #include "globaldata.h"
  22. #include "z_zone.h"
  23. #include "i_video.h"
  24. #include "i_system.h"
  25. #include "v_video.h"
  26. #include "m_random.h"
  27. #include "doomdef.h"
  28. #include "f_wipe.h"
  29. //
  30. // SCREEN WIPE PACKAGE
  31. //
  32. // when zero, stop the wipe
  33. void
  34. wipe_shittyColMajorXform
  35. ( short* array,
  36. int width,
  37. int height )
  38. {
  39. int x;
  40. int y;
  41. short* dest;
  42. //dest = (short*) DoomLib::Z_Malloc(width*height*2, PU_STATIC, 0 );
  43. dest = new short[ width * height ];
  44. for(y=0;y<height;y++)
  45. for(x=0;x<width;x++)
  46. dest[x*height+y] = array[y*width+x];
  47. memcpy(array, dest, width*height*2);
  48. //Z_Free(dest);
  49. delete[] dest;
  50. }
  51. int
  52. wipe_initMelt
  53. ( int width,
  54. int height,
  55. int ticks )
  56. {
  57. int i, r;
  58. // copy start screen to main screen
  59. memcpy(::g->wipe_scr, ::g->wipe_scr_start, width*height);
  60. // makes this wipe faster (in theory)
  61. // to have stuff in column-major format
  62. wipe_shittyColMajorXform((short*)::g->wipe_scr_start, width/2, height);
  63. wipe_shittyColMajorXform((short*)::g->wipe_scr_end, width/2, height);
  64. // setup initial column positions
  65. // (::g->wipe_y<0 => not ready to scroll yet)
  66. ::g->wipe_y = (int *) DoomLib::Z_Malloc(width*sizeof(int), PU_STATIC, 0);
  67. ::g->wipe_y[0] = -(M_Random()%16);
  68. for (i=1;i<width;i++)
  69. {
  70. r = (M_Random()%3) - 1;
  71. ::g->wipe_y[i] = ::g->wipe_y[i-1] + r;
  72. if (::g->wipe_y[i] > 0)
  73. ::g->wipe_y[i] = 0;
  74. else if (::g->wipe_y[i] == -16)
  75. ::g->wipe_y[i] = -15;
  76. }
  77. return 0;
  78. }
  79. int wipe_doMelt( int width, int height, int ticks ) {
  80. int i;
  81. int j;
  82. int dy;
  83. int idx;
  84. short* s;
  85. short* d;
  86. qboolean done = true;
  87. width/=2;
  88. while (ticks--)
  89. {
  90. for (i=0;i<width;i++)
  91. {
  92. if (::g->wipe_y[i]<0) {
  93. ::g->wipe_y[i]++;
  94. done = false;
  95. }
  96. else if (::g->wipe_y[i] < height) {
  97. dy = (::g->wipe_y[i] < 16 * GLOBAL_IMAGE_SCALER) ? ::g->wipe_y[i]+1 : 8 * GLOBAL_IMAGE_SCALER;
  98. if (::g->wipe_y[i]+dy >= height)
  99. dy = height - ::g->wipe_y[i];
  100. s = &((short *)::g->wipe_scr_end)[i*height+::g->wipe_y[i]];
  101. d = &((short *)::g->wipe_scr)[::g->wipe_y[i]*width+i];
  102. idx = 0;
  103. for (j=dy;j;j--)
  104. {
  105. d[idx] = *(s++);
  106. idx += width;
  107. }
  108. ::g->wipe_y[i] += dy;
  109. s = &((short *)::g->wipe_scr_start)[i*height];
  110. d = &((short *)::g->wipe_scr)[::g->wipe_y[i]*width+i];
  111. idx = 0;
  112. for (j=height-::g->wipe_y[i];j;j--)
  113. {
  114. d[idx] = *(s++);
  115. idx += width;
  116. }
  117. done = false;
  118. }
  119. }
  120. }
  121. return done;
  122. }
  123. int
  124. wipe_exitMelt
  125. ( int width,
  126. int height,
  127. int ticks )
  128. {
  129. Z_Free(::g->wipe_y);
  130. ::g->wipe_y = NULL;
  131. return 0;
  132. }
  133. int
  134. wipe_StartScreen
  135. ( int x,
  136. int y,
  137. int width,
  138. int height )
  139. {
  140. ::g->wipe_scr_start = ::g->screens[2];
  141. I_ReadScreen(::g->wipe_scr_start);
  142. return 0;
  143. }
  144. int
  145. wipe_EndScreen
  146. ( int x,
  147. int y,
  148. int width,
  149. int height )
  150. {
  151. ::g->wipe_scr_end = ::g->screens[3];
  152. I_ReadScreen(::g->wipe_scr_end);
  153. V_DrawBlock(x, y, 0, width, height, ::g->wipe_scr_start); // restore start scr.
  154. return 0;
  155. }
  156. int
  157. wipe_ScreenWipe
  158. ( int x,
  159. int y,
  160. int width,
  161. int height,
  162. int ticks )
  163. {
  164. int rc;
  165. // initial stuff
  166. if (!::g->go)
  167. {
  168. ::g->go = 1;
  169. ::g->wipe_scr = ::g->screens[0];
  170. wipe_initMelt(width, height, ticks);
  171. }
  172. // do a piece of wipe-in
  173. V_MarkRect(0, 0, width, height);
  174. rc = wipe_doMelt(width, height, ticks);
  175. // final stuff
  176. if (rc)
  177. {
  178. ::g->go = 0;
  179. wipe_exitMelt(width, height, ticks);
  180. }
  181. return !::g->go;
  182. }