Add key bindings for pause, message refresh.
[chocolate-doom.git] / src / f_wipe.c
bloba3fe1fb389deaf7c9f8a36819100a6c732553c52
1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // Copyright(C) 1993-1996 Id Software, Inc.
5 // Copyright(C) 2005 Simon Howard
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 // 02111-1307, USA.
22 // DESCRIPTION:
23 // Mission begin melt/wipe screen special effect.
25 //-----------------------------------------------------------------------------
31 #include "z_zone.h"
32 #include "i_video.h"
33 #include "v_video.h"
34 #include "m_random.h"
36 #include "doomdef.h"
38 #include "f_wipe.h"
41 // SCREEN WIPE PACKAGE
44 // when zero, stop the wipe
45 static boolean go = 0;
47 static byte* wipe_scr_start;
48 static byte* wipe_scr_end;
49 static byte* wipe_scr;
52 void
53 wipe_shittyColMajorXform
54 ( short* array,
55 int width,
56 int height )
58 int x;
59 int y;
60 short* dest;
62 dest = (short*) Z_Malloc(width*height*2, PU_STATIC, 0);
64 for(y=0;y<height;y++)
65 for(x=0;x<width;x++)
66 dest[x*height+y] = array[y*width+x];
68 memcpy(array, dest, width*height*2);
70 Z_Free(dest);
74 int
75 wipe_initColorXForm
76 ( int width,
77 int height,
78 int ticks )
80 memcpy(wipe_scr, wipe_scr_start, width*height);
81 return 0;
84 int
85 wipe_doColorXForm
86 ( int width,
87 int height,
88 int ticks )
90 boolean changed;
91 byte* w;
92 byte* e;
93 int newval;
95 changed = false;
96 w = wipe_scr;
97 e = wipe_scr_end;
99 while (w!=wipe_scr+width*height)
101 if (*w != *e)
103 if (*w > *e)
105 newval = *w - ticks;
106 if (newval < *e)
107 *w = *e;
108 else
109 *w = newval;
110 changed = true;
112 else if (*w < *e)
114 newval = *w + ticks;
115 if (newval > *e)
116 *w = *e;
117 else
118 *w = newval;
119 changed = true;
122 w++;
123 e++;
126 return !changed;
131 wipe_exitColorXForm
132 ( int width,
133 int height,
134 int ticks )
136 return 0;
140 static int* y;
143 wipe_initMelt
144 ( int width,
145 int height,
146 int ticks )
148 int i, r;
150 // copy start screen to main screen
151 memcpy(wipe_scr, wipe_scr_start, width*height);
153 // makes this wipe faster (in theory)
154 // to have stuff in column-major format
155 wipe_shittyColMajorXform((short*)wipe_scr_start, width/2, height);
156 wipe_shittyColMajorXform((short*)wipe_scr_end, width/2, height);
158 // setup initial column positions
159 // (y<0 => not ready to scroll yet)
160 y = (int *) Z_Malloc(width*sizeof(int), PU_STATIC, 0);
161 y[0] = -(M_Random()%16);
162 for (i=1;i<width;i++)
164 r = (M_Random()%3) - 1;
165 y[i] = y[i-1] + r;
166 if (y[i] > 0) y[i] = 0;
167 else if (y[i] == -16) y[i] = -15;
170 return 0;
174 wipe_doMelt
175 ( int width,
176 int height,
177 int ticks )
179 int i;
180 int j;
181 int dy;
182 int idx;
184 short* s;
185 short* d;
186 boolean done = true;
188 width/=2;
190 while (ticks--)
192 for (i=0;i<width;i++)
194 if (y[i]<0)
196 y[i]++; done = false;
198 else if (y[i] < height)
200 dy = (y[i] < 16) ? y[i]+1 : 8;
201 if (y[i]+dy >= height) dy = height - y[i];
202 s = &((short *)wipe_scr_end)[i*height+y[i]];
203 d = &((short *)wipe_scr)[y[i]*width+i];
204 idx = 0;
205 for (j=dy;j;j--)
207 d[idx] = *(s++);
208 idx += width;
210 y[i] += dy;
211 s = &((short *)wipe_scr_start)[i*height];
212 d = &((short *)wipe_scr)[y[i]*width+i];
213 idx = 0;
214 for (j=height-y[i];j;j--)
216 d[idx] = *(s++);
217 idx += width;
219 done = false;
224 return done;
229 wipe_exitMelt
230 ( int width,
231 int height,
232 int ticks )
234 Z_Free(y);
235 return 0;
239 wipe_StartScreen
240 ( int x,
241 int y,
242 int width,
243 int height )
245 wipe_scr_start = screens[2];
246 I_ReadScreen(wipe_scr_start);
247 return 0;
251 wipe_EndScreen
252 ( int x,
253 int y,
254 int width,
255 int height )
257 wipe_scr_end = screens[3];
258 I_ReadScreen(wipe_scr_end);
259 V_DrawBlock(x, y, 0, width, height, wipe_scr_start); // restore start scr.
260 return 0;
264 wipe_ScreenWipe
265 ( int wipeno,
266 int x,
267 int y,
268 int width,
269 int height,
270 int ticks )
272 int rc;
273 static int (*wipes[])(int, int, int) =
275 wipe_initColorXForm, wipe_doColorXForm, wipe_exitColorXForm,
276 wipe_initMelt, wipe_doMelt, wipe_exitMelt
279 void V_MarkRect(int, int, int, int);
281 // initial stuff
282 if (!go)
284 go = 1;
285 // wipe_scr = (byte *) Z_Malloc(width*height, PU_STATIC, 0); // DEBUG
286 wipe_scr = screens[0];
287 (*wipes[wipeno*3])(width, height, ticks);
290 // do a piece of wipe-in
291 V_MarkRect(0, 0, width, height);
292 rc = (*wipes[wipeno*3+1])(width, height, ticks);
293 // V_DrawBlock(x, y, 0, width, height, wipe_scr); // DEBUG
295 // final stuff
296 if (rc)
298 go = 0;
299 (*wipes[wipeno*3+2])(width, height, ticks);
302 return !go;