Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
298 | serge | 1 | // Emacs style mode select -*- C++ -*- |
2 | //----------------------------------------------------------------------------- |
||
3 | // |
||
4 | // $Id:$ |
||
5 | // |
||
6 | // Copyright (C) 1993-1996 by id Software, Inc. |
||
7 | // |
||
8 | // This source is available for distribution and/or modification |
||
9 | // only under the terms of the DOOM Source Code License as |
||
10 | // published by id Software. All rights reserved. |
||
11 | // |
||
12 | // The source is distributed in the hope that it will be useful, |
||
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License |
||
15 | // for more details. |
||
16 | // |
||
17 | // $Log:$ |
||
18 | // |
||
19 | // DESCRIPTION: |
||
20 | // Mission begin melt/wipe screen special effect. |
||
21 | // |
||
22 | //----------------------------------------------------------------------------- |
||
23 | |||
24 | |||
25 | static const char rcsid[] = "$Id: f_wipe.c,v 1.2 1997/02/03 22:45:09 b1 Exp $"; |
||
26 | |||
27 | |||
28 | |||
29 | #include "z_zone.h" |
||
30 | #include "i_video.h" |
||
31 | #include "v_video.h" |
||
32 | #include "m_random.h" |
||
33 | |||
34 | #include "doomdef.h" |
||
35 | |||
36 | #include "f_wipe.h" |
||
37 | |||
38 | // |
||
39 | // SCREEN WIPE PACKAGE |
||
40 | // |
||
41 | |||
42 | // when zero, stop the wipe |
||
43 | static boolean go = 0; |
||
44 | |||
45 | static byte* wipe_scr_start; |
||
46 | static byte* wipe_scr_end; |
||
47 | static byte* wipe_scr; |
||
48 | |||
49 | |||
50 | void |
||
51 | wipe_shittyColMajorXform |
||
52 | ( short* array, |
||
53 | int width, |
||
54 | int height ) |
||
55 | { |
||
56 | int x; |
||
57 | int y; |
||
58 | short* dest; |
||
59 | |||
60 | dest = (short*) Z_Malloc(width*height*2, PU_STATIC, 0); |
||
61 | |||
62 | for(y=0;y |
||
63 | for(x=0;x |
||
64 | dest[x*height+y] = array[y*width+x]; |
||
65 | |||
66 | memcpy(array, dest, width*height*2); |
||
67 | |||
68 | Z_Free(dest); |
||
69 | |||
70 | } |
||
71 | |||
72 | int |
||
73 | wipe_initColorXForm |
||
74 | ( int width, |
||
75 | int height, |
||
76 | int ticks ) |
||
77 | { |
||
78 | memcpy(wipe_scr, wipe_scr_start, width*height); |
||
79 | return 0; |
||
80 | } |
||
81 | |||
82 | int |
||
83 | wipe_doColorXForm |
||
84 | ( int width, |
||
85 | int height, |
||
86 | int ticks ) |
||
87 | { |
||
88 | boolean changed; |
||
89 | byte* w; |
||
90 | byte* e; |
||
91 | int newval; |
||
92 | |||
93 | changed = false; |
||
94 | w = wipe_scr; |
||
95 | e = wipe_scr_end; |
||
96 | |||
97 | while (w!=wipe_scr+width*height) |
||
98 | { |
||
99 | if (*w != *e) |
||
100 | { |
||
101 | if (*w > *e) |
||
102 | { |
||
103 | newval = *w - ticks; |
||
104 | if (newval < *e) |
||
105 | *w = *e; |
||
106 | else |
||
107 | *w = newval; |
||
108 | changed = true; |
||
109 | } |
||
110 | else if (*w < *e) |
||
111 | { |
||
112 | newval = *w + ticks; |
||
113 | if (newval > *e) |
||
114 | *w = *e; |
||
115 | else |
||
116 | *w = newval; |
||
117 | changed = true; |
||
118 | } |
||
119 | } |
||
120 | w++; |
||
121 | e++; |
||
122 | } |
||
123 | |||
124 | return !changed; |
||
125 | |||
126 | } |
||
127 | |||
128 | int |
||
129 | wipe_exitColorXForm |
||
130 | ( int width, |
||
131 | int height, |
||
132 | int ticks ) |
||
133 | { |
||
134 | return 0; |
||
135 | } |
||
136 | |||
137 | |||
138 | static int* y; |
||
139 | |||
140 | int |
||
141 | wipe_initMelt |
||
142 | ( int width, |
||
143 | int height, |
||
144 | int ticks ) |
||
145 | { |
||
146 | int i, r; |
||
147 | |||
148 | // copy start screen to main screen |
||
149 | memcpy(wipe_scr, wipe_scr_start, width*height); |
||
150 | |||
151 | // makes this wipe faster (in theory) |
||
152 | // to have stuff in column-major format |
||
153 | wipe_shittyColMajorXform((short*)wipe_scr_start, width/2, height); |
||
154 | wipe_shittyColMajorXform((short*)wipe_scr_end, width/2, height); |
||
155 | |||
156 | // setup initial column positions |
||
157 | // (y<0 => not ready to scroll yet) |
||
158 | y = (int *) Z_Malloc(width*sizeof(int), PU_STATIC, 0); |
||
159 | y[0] = -(M_Random()%16); |
||
160 | for (i=1;i |
||
161 | { |
||
162 | r = (M_Random()%3) - 1; |
||
163 | y[i] = y[i-1] + r; |
||
164 | if (y[i] > 0) y[i] = 0; |
||
165 | else if (y[i] == -16) y[i] = -15; |
||
166 | } |
||
167 | |||
168 | return 0; |
||
169 | } |
||
170 | |||
171 | int |
||
172 | wipe_doMelt |
||
173 | ( int width, |
||
174 | int height, |
||
175 | int ticks ) |
||
176 | { |
||
177 | int i; |
||
178 | int j; |
||
179 | int dy; |
||
180 | int idx; |
||
181 | |||
182 | short* s; |
||
183 | short* d; |
||
184 | boolean done = true; |
||
185 | |||
186 | width/=2; |
||
187 | |||
188 | while (ticks--) |
||
189 | { |
||
190 | for (i=0;i |
||
191 | { |
||
192 | if (y[i]<0) |
||
193 | { |
||
194 | y[i]++; done = false; |
||
195 | } |
||
196 | else if (y[i] < height) |
||
197 | { |
||
198 | dy = (y[i] < 16) ? y[i]+1 : 8; |
||
199 | if (y[i]+dy >= height) dy = height - y[i]; |
||
200 | s = &((short *)wipe_scr_end)[i*height+y[i]]; |
||
201 | d = &((short *)wipe_scr)[y[i]*width+i]; |
||
202 | idx = 0; |
||
203 | for (j=dy;j;j--) |
||
204 | { |
||
205 | d[idx] = *(s++); |
||
206 | idx += width; |
||
207 | } |
||
208 | y[i] += dy; |
||
209 | s = &((short *)wipe_scr_start)[i*height]; |
||
210 | d = &((short *)wipe_scr)[y[i]*width+i]; |
||
211 | idx = 0; |
||
212 | for (j=height-y[i];j;j--) |
||
213 | { |
||
214 | d[idx] = *(s++); |
||
215 | idx += width; |
||
216 | } |
||
217 | done = false; |
||
218 | } |
||
219 | } |
||
220 | } |
||
221 | |||
222 | return done; |
||
223 | |||
224 | } |
||
225 | |||
226 | int |
||
227 | wipe_exitMelt |
||
228 | ( int width, |
||
229 | int height, |
||
230 | int ticks ) |
||
231 | { |
||
232 | Z_Free(y); |
||
233 | return 0; |
||
234 | } |
||
235 | |||
236 | int |
||
237 | wipe_StartScreen |
||
238 | ( int x, |
||
239 | int y, |
||
240 | int width, |
||
241 | int height ) |
||
242 | { |
||
243 | wipe_scr_start = screens[2]; |
||
244 | I_ReadScreen(wipe_scr_start); |
||
245 | return 0; |
||
246 | } |
||
247 | |||
248 | int |
||
249 | wipe_EndScreen |
||
250 | ( int x, |
||
251 | int y, |
||
252 | int width, |
||
253 | int height ) |
||
254 | { |
||
255 | wipe_scr_end = screens[3]; |
||
256 | I_ReadScreen(wipe_scr_end); |
||
257 | V_DrawBlock(x, y, 0, width, height, wipe_scr_start); // restore start scr. |
||
258 | return 0; |
||
259 | } |
||
260 | |||
261 | int |
||
262 | wipe_ScreenWipe |
||
263 | ( int wipeno, |
||
264 | int x, |
||
265 | int y, |
||
266 | int width, |
||
267 | int height, |
||
268 | int ticks ) |
||
269 | { |
||
270 | int rc; |
||
271 | static int (*wipes[])(int, int, int) = |
||
272 | { |
||
273 | wipe_initColorXForm, wipe_doColorXForm, wipe_exitColorXForm, |
||
274 | wipe_initMelt, wipe_doMelt, wipe_exitMelt |
||
275 | }; |
||
276 | |||
277 | void V_MarkRect(int, int, int, int); |
||
278 | |||
279 | // initial stuff |
||
280 | if (!go) |
||
281 | { |
||
282 | go = 1; |
||
283 | // wipe_scr = (byte *) Z_Malloc(width*height, PU_STATIC, 0); // DEBUG |
||
284 | wipe_scr = screens[0]; |
||
285 | (*wipes[wipeno*3])(width, height, ticks); |
||
286 | } |
||
287 | |||
288 | // do a piece of wipe-in |
||
289 | V_MarkRect(0, 0, width, height); |
||
290 | rc = (*wipes[wipeno*3+1])(width, height, ticks); |
||
291 | // V_DrawBlock(x, y, 0, width, height, wipe_scr); // DEBUG |
||
292 | |||
293 | // final stuff |
||
294 | if (rc) |
||
295 | { |
||
296 | go = 0; |
||
297 | (*wipes[wipeno*3+2])(width, height, ticks); |
||
298 | } |
||
299 | |||
300 | return !go; |
||
301 | |||
302 | }>>0) |