Debian Codegraph @

src/backgrnd.c

raw symbols SCIP
1 /*
2 * OpenTyrian: A modern cross-platform port of Tyrian
3 * Copyright (C) 2007-2009 The OpenTyrian Development Team
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program 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 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 #include "backgrnd.h"cxx . . $ `<file>/src/backgrnd.h`/
20
21 #include "config.h"cxx . . $ `<file>/src/config.h`/
22 #include "mtrand.h"cxx . . $ `<file>/src/mtrand.h`/
23 #include "opentyr.h"cxx . . $ `<file>/src/opentyr.h`/
24 #include "varz.h"cxx . . $ `<file>/src/varz.h`/
25 #include "video.h"cxx . . $ `<file>/src/video.h`/
26
27 #include <assert.h>
28
29 /*Special Background 2 and Background 3*/
30
31 /*Back Pos 3*/
32 JE_wordcxx . . $ JE_word# backPoscxx . . $ backPos., backPos2cxx . . $ backPos2., backPos3cxx . . $ backPos3.;
33 JE_wordcxx . . $ JE_word# backMovecxx . . $ backMove., backMove2cxx . . $ backMove2., backMove3cxx . . $ backMove3.;
34
35 /*Main Maps*/
36 JE_wordcxx . . $ JE_word# mapXcxx . . $ mapX., mapYcxx . . $ mapY., mapX2cxx . . $ mapX2., mapX3cxx . . $ mapX3., mapY2cxx . . $ mapY2., mapY3cxx . . $ mapY3.;
37 JE_bytecxx . . $ JE_byte# **mapYPoscxx . . $ mapYPos., **mapY2Poscxx . . $ mapY2Pos., **mapY3Poscxx . . $ mapY3Pos.;
38 JE_wordcxx . . $ JE_word# mapXPoscxx . . $ mapXPos., oldMapXOfscxx . . $ oldMapXOfs., mapXOfscxx . . $ mapXOfs., mapX2Ofscxx . . $ mapX2Ofs., mapX2Poscxx . . $ mapX2Pos., mapX3Poscxx . . $ mapX3Pos., oldMapX3Ofscxx . . $ oldMapX3Ofs., mapX3Ofscxx . . $ mapX3Ofs., tempMapXOfscxx . . $ tempMapXOfs.;
39 intptr_tcxx . . $ intptr_t# mapXbpPoscxx . . $ mapXbpPos., mapX2bpPoscxx . . $ mapX2bpPos., mapX3bpPoscxx . . $ mapX3bpPos.;
40 JE_bytecxx . . $ JE_byte# map1YDelaycxx . . $ map1YDelay., map1YDelayMaxcxx . . $ map1YDelayMax., map2YDelaycxx . . $ map2YDelay., map2YDelayMaxcxx . . $ map2YDelayMax.;
41
42 JE_booleancxx . . $ JE_boolean# anySmoothiescxx . . $ anySmoothies.;
43 JE_bytecxx . . $ JE_byte# smoothie_datacxx . . $ smoothie_data.[9]; /* [1..9] */
44
45 void JE_darkenBackgroundcxx . . $ JE_darkenBackground(ed53e3bbd3fa2f69).(JE_wordcxx . . $ JE_word# neat) /* wild detail level */
46 {
47 Uint8cxx . . $ Uint8# *s = VGAScreencxx . . $ VGAScreen.->pixelscxx . . $ SDL_Surface#pixels.; /* screen pointer, 8-bit specific */
48 int x, y;
49
50 s += 24;
51
52 for (y = 184; y; y--)
53 {
54 for (x = 264; x; x--)
55 {
56 *s = ((((*s & 0x0f) << 4) - (*s & 0x0f) + ((((x - neat - y) >> 2) + *(s-2) + (y == 184 ? 0 : *(s-(VGAScreencxx . . $ VGAScreen.->pitchcxx . . $ SDL_Surface#pitch.-1)))) & 0x0f)) >> 4) | (*s & 0xf0);
57 s++;
58 }
59 s += VGAScreencxx . . $ VGAScreen.->pitchcxx . . $ SDL_Surface#pitch. - 264;
60 }
61 }
62
63 void blit_background_rowcxx . . $ blit_background_row(ff424ea3c1aad680).(SDL_Surfacecxx . . $ SDL_Surface# *surface, int x, int y, Uint8cxx . . $ Uint8# **map)
64 {
65 assertcxx . . $ `/usr/include/assert.h:50:10`!(surface->format->BitsPerPixel == 8);
66
67 Uint8cxx . . $ Uint8# *pixels = (Uint8cxx . . $ Uint8# *)surface->pixelscxx . . $ SDL_Surface#pixels. + (y * surface->pitchcxx . . $ SDL_Surface#pitch.) + x,
68 *pixels_ll = (Uint8cxx . . $ Uint8# *)surface->pixelscxx . . $ SDL_Surface#pixels., // lower limit
69 *pixels_ul = (Uint8cxx . . $ Uint8# *)surface->pixelscxx . . $ SDL_Surface#pixels. + (surface->hcxx . . $ SDL_Surface#h. * surface->pitchcxx . . $ SDL_Surface#pitch.); // upper limit
70
71 for (int y = 0; y < 28; y++)
72 {
73 // not drawing on screen yet; skip y
74 if ((pixels + (12 * 24)) < pixels_ll)
75 {
76 pixels += surface->pitchcxx . . $ SDL_Surface#pitch.;
77 continue;
78 }
79
80 for (int tile = 0; tile < 12; tile++)
81 {
82 Uint8cxx . . $ Uint8# *data = *(map + tile);
83
84 // no tile; skip tile
85 if (data == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
86 {
87 pixels += 24;
88 continue;
89 }
90
91 data += y * 24;
92
93 for (int x = 24; x; x--)
94 {
95 if (pixels >= pixels_ul)
96 return;
97 if (pixels >= pixels_ll && *data != 0)
98 *pixels = *data;
99
100 pixels++;
101 data++;
102 }
103 }
104
105 pixels += surface->pitchcxx . . $ SDL_Surface#pitch. - 12 * 24;
106 }
107 }
108
109 void blit_background_row_blendcxx . . $ blit_background_row_blend(ff424ea3c1aad680).(SDL_Surfacecxx . . $ SDL_Surface# *surface, int x, int y, Uint8cxx . . $ Uint8# **map)
110 {
111 assertcxx . . $ `/usr/include/assert.h:50:10`!(surface->format->BitsPerPixel == 8);
112
113 Uint8cxx . . $ Uint8# *pixels = (Uint8cxx . . $ Uint8# *)surface->pixelscxx . . $ SDL_Surface#pixels. + (y * surface->pitchcxx . . $ SDL_Surface#pitch.) + x,
114 *pixels_ll = (Uint8cxx . . $ Uint8# *)surface->pixelscxx . . $ SDL_Surface#pixels., // lower limit
115 *pixels_ul = (Uint8cxx . . $ Uint8# *)surface->pixelscxx . . $ SDL_Surface#pixels. + (surface->hcxx . . $ SDL_Surface#h. * surface->pitchcxx . . $ SDL_Surface#pitch.); // upper limit
116
117 for (int y = 0; y < 28; y++)
118 {
119 // not drawing on screen yet; skip y
120 if ((pixels + (12 * 24)) < pixels_ll)
121 {
122 pixels += surface->pitchcxx . . $ SDL_Surface#pitch.;
123 continue;
124 }
125
126 for (int tile = 0; tile < 12; tile++)
127 {
128 Uint8cxx . . $ Uint8# *data = *(map + tile);
129
130 // no tile; skip tile
131 if (data == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
132 {
133 pixels += 24;
134 continue;
135 }
136
137 data += y * 24;
138
139 for (int x = 24; x; x--)
140 {
141 if (pixels >= pixels_ul)
142 return;
143 if (pixels >= pixels_ll && *data != 0)
144 *pixels = (*data & 0xf0) | (((*pixels & 0x0f) + (*data & 0x0f)) / 2);
145
146 pixels++;
147 data++;
148 }
149 }
150
151 pixels += surface->pitchcxx . . $ SDL_Surface#pitch. - 12 * 24;
152 }
153 }
154
155 void draw_background_1cxx . . $ draw_background_1(60a0b30a00b4fc6d).(SDL_Surfacecxx . . $ SDL_Surface# *surface)
156 {
157 SDL_FillRectcxx . . $ SDL_FillRect(3ec95406e4bae91).(surface, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
158
159 Uint8cxx . . $ Uint8# **map = (Uint8cxx . . $ Uint8# **)mapYPoscxx . . $ mapYPos. + mapXbpPoscxx . . $ mapXbpPos. - 12;
160
161 for (int i = -1; i < 7; i++)
162 {
163 blit_background_rowcxx . . $ blit_background_row(ff424ea3c1aad680).(surface, mapXPoscxx . . $ mapXPos., (i * 28) + backPoscxx . . $ backPos., map);
164
165 map += 14;
166 }
167 }
168
169 void draw_background_2cxx . . $ draw_background_2(60a0b30a00b4fc6d).(SDL_Surfacecxx . . $ SDL_Surface# *surface)
170 {
171 if (map2YDelayMaxcxx . . $ map2YDelayMax. > 1 && backMove2cxx . . $ backMove2. < 2)
172 backMove2cxx . . $ backMove2. = (map2YDelaycxx . . $ map2YDelay. == 1) ? 1 : 0;
173
174 if (background2cxx . . $ background2. != 0)
175 {
176 // water effect combines background 1 and 2 by synchronizing the x coordinate
177 int x = smoothiescxx . . $ smoothies.[1] ? mapXPoscxx . . $ mapXPos. : mapX2Poscxx . . $ mapX2Pos.;
178
179 Uint8cxx . . $ Uint8# **map = (Uint8cxx . . $ Uint8# **)mapY2Poscxx . . $ mapY2Pos. + (smoothiescxx . . $ smoothies.[1] ? mapXbpPoscxx . . $ mapXbpPos. : mapX2bpPoscxx . . $ mapX2bpPos.) - 12;
180
181 for (int i = -1; i < 7; i++)
182 {
183 blit_background_rowcxx . . $ blit_background_row(ff424ea3c1aad680).(surface, x, (i * 28) + backPos2cxx . . $ backPos2., map);
184
185 map += 14;
186 }
187 }
188
189 /*Set Movement of background*/
190 if (--map2YDelaycxx . . $ map2YDelay. == 0)
191 {
192 map2YDelaycxx . . $ map2YDelay. = map2YDelayMaxcxx . . $ map2YDelayMax.;
193
194 backPos2cxx . . $ backPos2. += backMove2cxx . . $ backMove2.;
195
196 if (backPos2cxx . . $ backPos2. > 27)
197 {
198 backPos2cxx . . $ backPos2. -= 28;
199 mapY2cxx . . $ mapY2.--;
200 mapY2Poscxx . . $ mapY2Pos. -= 14; /*Map Width*/
201 }
202 }
203 }
204
205 void draw_background_2_blendcxx . . $ draw_background_2_blend(60a0b30a00b4fc6d).(SDL_Surfacecxx . . $ SDL_Surface# *surface)
206 {
207 if (map2YDelayMaxcxx . . $ map2YDelayMax. > 1 && backMove2cxx . . $ backMove2. < 2)
208 backMove2cxx . . $ backMove2. = (map2YDelaycxx . . $ map2YDelay. == 1) ? 1 : 0;
209
210 Uint8cxx . . $ Uint8# **map = (Uint8cxx . . $ Uint8# **)mapY2Poscxx . . $ mapY2Pos. + mapX2bpPoscxx . . $ mapX2bpPos. - 12;
211
212 for (int i = -1; i < 7; i++)
213 {
214 blit_background_row_blendcxx . . $ blit_background_row_blend(ff424ea3c1aad680).(surface, mapX2Poscxx . . $ mapX2Pos., (i * 28) + backPos2cxx . . $ backPos2., map);
215
216 map += 14;
217 }
218
219 /*Set Movement of background*/
220 if (--map2YDelaycxx . . $ map2YDelay. == 0)
221 {
222 map2YDelaycxx . . $ map2YDelay. = map2YDelayMaxcxx . . $ map2YDelayMax.;
223
224 backPos2cxx . . $ backPos2. += backMove2cxx . . $ backMove2.;
225
226 if (backPos2cxx . . $ backPos2. > 27)
227 {
228 backPos2cxx . . $ backPos2. -= 28;
229 mapY2cxx . . $ mapY2.--;
230 mapY2Poscxx . . $ mapY2Pos. -= 14; /*Map Width*/
231 }
232 }
233 }
234
235 void draw_background_3cxx . . $ draw_background_3(60a0b30a00b4fc6d).(SDL_Surfacecxx . . $ SDL_Surface# *surface)
236 {
237 /* Movement of background */
238 backPos3cxx . . $ backPos3. += backMove3cxx . . $ backMove3.;
239
240 if (backPos3cxx . . $ backPos3. > 27)
241 {
242 backPos3cxx . . $ backPos3. -= 28;
243 mapY3cxx . . $ mapY3.--;
244 mapY3Poscxx . . $ mapY3Pos. -= 15; /*Map Width*/
245 }
246
247 Uint8cxx . . $ Uint8# **map = (Uint8cxx . . $ Uint8# **)mapY3Poscxx . . $ mapY3Pos. + mapX3bpPoscxx . . $ mapX3bpPos. - 12;
248
249 for (int i = -1; i < 7; i++)
250 {
251 blit_background_rowcxx . . $ blit_background_row(ff424ea3c1aad680).(surface, mapX3Poscxx . . $ mapX3Pos., (i * 28) + backPos3cxx . . $ backPos3., map);
252
253 map += 15;
254 }
255 }
256
257 void JE_filterScreencxx . . $ JE_filterScreen(d8573db2507826ee).(JE_shortintcxx . . $ JE_shortint# col, JE_shortintcxx . . $ JE_shortint# int_)
258 {
259 Uint8cxx . . $ Uint8# *s = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; /* screen pointer, 8-bit specific */
260 int x, y;
261 unsigned int temp;
262
263 if (filterFadecxx . . $ filterFade.)
264 {
265 levelBrightnesscxx . . $ levelBrightness. += levelBrightnessChgcxx . . $ levelBrightnessChg.;
266 if ((filterFadeStartcxx . . $ filterFadeStart. && levelBrightnesscxx . . $ levelBrightness. < -14) || levelBrightnesscxx . . $ levelBrightness. > 14)
267 {
268 levelBrightnessChgcxx . . $ levelBrightnessChg. = -levelBrightnessChgcxx . . $ levelBrightnessChg.;
269 filterFadeStartcxx . . $ filterFadeStart. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
270 levelFiltercxx . . $ levelFilter. = levelFilterNewcxx . . $ levelFilterNew.;
271 }
272 if (!filterFadeStartcxx . . $ filterFadeStart. && levelBrightnesscxx . . $ levelBrightness. == 0)
273 {
274 filterFadecxx . . $ filterFade. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
275 levelBrightnesscxx . . $ levelBrightness. = -99;
276 }
277 }
278
279 if (col != -99 && filtrationAvailcxx . . $ filtrationAvail.)
280 {
281 s = VGAScreencxx . . $ VGAScreen.->pixelscxx . . $ SDL_Surface#pixels.;
282 s += 24;
283
284 col <<= 4;
285
286 for (y = 184; y; y--)
287 {
288 for (x = 264; x; x--)
289 {
290 *s = col | (*s & 0x0f);
291 s++;
292 }
293 s += VGAScreencxx . . $ VGAScreen.->pitchcxx . . $ SDL_Surface#pitch. - 264;
294 }
295 }
296
297 if (int_ != -99 && explosionTransparentcxx . . $ explosionTransparent.)
298 {
299 s = VGAScreencxx . . $ VGAScreen.->pixelscxx . . $ SDL_Surface#pixels.;
300 s += 24;
301
302 for (y = 184; y; y--)
303 {
304 for (x = 264; x; x--)
305 {
306 temp = (*s & 0x0f) + int_;
307 *s = (*s & 0xf0) | (temp >= 0x1f ? 0 : (temp >= 0x0f ? 0x0f : temp));
308 s++;
309 }
310 s += VGAScreencxx . . $ VGAScreen.->pitchcxx . . $ SDL_Surface#pitch. - 264;
311 }
312 }
313 }
314
315 void JE_checkSmoothiescxx . . $ JE_checkSmoothies(49f6e7a06ebc5aa8).(void)
316 {
317 anySmoothiescxx . . $ anySmoothies. = (processorTypecxx . . $ processorType. > 2 && (smoothiescxx . . $ smoothies.[1-1] || smoothiescxx . . $ smoothies.[2-1])) || (processorTypecxx . . $ processorType. > 1 && (smoothiescxx . . $ smoothies.[3-1] || smoothiescxx . . $ smoothies.[4-1] || smoothiescxx . . $ smoothies.[5-1]));
318 }
319
320 void lava_filtercxx . . $ lava_filter(fac4f6e207c3be86).(SDL_Surfacecxx . . $ SDL_Surface# *dst, SDL_Surfacecxx . . $ SDL_Surface# *src)
321 {
322 assertcxx . . $ `/usr/include/assert.h:50:10`!(src->format->BitsPerPixel == 8 && dst->format->BitsPerPixel == 8);
323
324 /* we don't need to check for over-reading the pixel surfaces since we only
325 * read from the top 185+1 scanlines, and there should be 320 */
326
327 const int dst_pitch = dst->pitchcxx . . $ SDL_Surface#pitch.;
328 Uint8cxx . . $ Uint8# *dst_pixel = (Uint8cxx . . $ Uint8# *)dst->pixelscxx . . $ SDL_Surface#pixels. + (185 * dst_pitch);
329 const Uint8cxx . . $ Uint8# * const dst_pixel_ll = (Uint8cxx . . $ Uint8# *)dst->pixelscxx . . $ SDL_Surface#pixels.; // lower limit
330
331 const int src_pitch = src->pitchcxx . . $ SDL_Surface#pitch.;
332 const Uint8cxx . . $ Uint8# *src_pixel = (Uint8cxx . . $ Uint8# *)src->pixelscxx . . $ SDL_Surface#pixels. + (185 * src->pitchcxx . . $ SDL_Surface#pitch.);
333 const Uint8cxx . . $ Uint8# * const src_pixel_ll = (Uint8cxx . . $ Uint8# *)src->pixelscxx . . $ SDL_Surface#pixels.; // lower limit
334
335 int w = 320 * 185 - 1;
336
337 for (int y = 185 - 1; y >= 0; --y)
338 {
339 dst_pixel -= (dst_pitch - 320); // in case pitch is not 320
340 src_pixel -= (src_pitch - 320); // in case pitch is not 320
341
342 for (int x = 320 - 1; x >= 0; x -= 8)
343 {
344 int waver = abscxx . . $ abs(7864480464b09eea).(((w >> 9) & 0x0f) - 8) - 1;
345 w -= 8;
346
347 for (int xi = 8 - 1; xi >= 0; --xi)
348 {
349 --dst_pixel;
350 --src_pixel;
351
352 // value is average value of source pixel (2x), destination pixel above, and destination pixel below (all with waver)
353 // hue is red
354 Uint8cxx . . $ Uint8# value = 0;
355
356 if (src_pixel + waver >= src_pixel_ll)
357 value += (*(src_pixel + waver) & 0x0f) * 2;
358 value += *(dst_pixel + waver + dst_pitch) & 0x0f;
359 if (dst_pixel + waver - dst_pitch >= dst_pixel_ll)
360 value += *(dst_pixel + waver - dst_pitch) & 0x0f;
361
362 *dst_pixel = (value / 4) | 0x70;
363 }
364 }
365 }
366 }
367
368 void water_filtercxx . . $ water_filter(fac4f6e207c3be86).(SDL_Surfacecxx . . $ SDL_Surface# *dst, SDL_Surfacecxx . . $ SDL_Surface# *src)
369 {
370 assertcxx . . $ `/usr/include/assert.h:50:10`!(src->format->BitsPerPixel == 8 && dst->format->BitsPerPixel == 8);
371
372 Uint8cxx . . $ Uint8# hue = smoothie_datacxx . . $ smoothie_data.[1] << 4;
373
374 /* we don't need to check for over-reading the pixel surfaces since we only
375 * read from the top 185+1 scanlines, and there should be 320 */
376
377 const int dst_pitch = dst->pitchcxx . . $ SDL_Surface#pitch.;
378 Uint8cxx . . $ Uint8# *dst_pixel = (Uint8cxx . . $ Uint8# *)dst->pixelscxx . . $ SDL_Surface#pixels. + (185 * dst_pitch);
379
380 const Uint8cxx . . $ Uint8# *src_pixel = (Uint8cxx . . $ Uint8# *)src->pixelscxx . . $ SDL_Surface#pixels. + (185 * src->pitchcxx . . $ SDL_Surface#pitch.);
381
382 int w = 320 * 185 - 1;
383
384 for (int y = 185 - 1; y >= 0; --y)
385 {
386 dst_pixel -= (dst_pitch - 320); // in case pitch is not 320
387 src_pixel -= (src->pitchcxx . . $ SDL_Surface#pitch. - 320); // in case pitch is not 320
388
389 for (int x = 320 - 1; x >= 0; x -= 8)
390 {
391 int waver = abscxx . . $ abs(7864480464b09eea).(((w >> 10) & 0x07) - 4) - 1;
392 w -= 8;
393
394 for (int xi = 8 - 1; xi >= 0; --xi)
395 {
396 --dst_pixel;
397 --src_pixel;
398
399 // pixel is copied from source if not blue
400 // otherwise, value is average of value of source pixel and destination pixel below (with waver)
401 if ((*src_pixel & 0x30) == 0)
402 {
403 *dst_pixel = *src_pixel;
404 }
405 else
406 {
407 Uint8cxx . . $ Uint8# value = *src_pixel & 0x0f;
408 value += *(dst_pixel + waver + dst_pitch) & 0x0f;
409 *dst_pixel = (value / 2) | hue;
410 }
411 }
412 }
413 }
414 }
415
416 void iced_blur_filtercxx . . $ iced_blur_filter(fac4f6e207c3be86).(SDL_Surfacecxx . . $ SDL_Surface# *dst, SDL_Surfacecxx . . $ SDL_Surface# *src)
417 {
418 assertcxx . . $ `/usr/include/assert.h:50:10`!(src->format->BitsPerPixel == 8 && dst->format->BitsPerPixel == 8);
419
420 Uint8cxx . . $ Uint8# *dst_pixel = dst->pixelscxx . . $ SDL_Surface#pixels.;
421 const Uint8cxx . . $ Uint8# *src_pixel = src->pixelscxx . . $ SDL_Surface#pixels.;
422
423 for (int y = 0; y < 184; ++y)
424 {
425 for (int x = 0; x < 320; ++x)
426 {
427 // value is average value of source pixel and destination pixel
428 // hue is icy blue
429
430 const Uint8cxx . . $ Uint8# value = (*src_pixel & 0x0f) + (*dst_pixel & 0x0f);
431 *dst_pixel = (value / 2) | 0x80;
432
433 ++dst_pixel;
434 ++src_pixel;
435 }
436
437 dst_pixel += (dst->pitchcxx . . $ SDL_Surface#pitch. - 320); // in case pitch is not 320
438 src_pixel += (src->pitchcxx . . $ SDL_Surface#pitch. - 320); // in case pitch is not 320
439 }
440 }
441
442 void blur_filtercxx . . $ blur_filter(fac4f6e207c3be86).(SDL_Surfacecxx . . $ SDL_Surface# *dst, SDL_Surfacecxx . . $ SDL_Surface# *src)
443 {
444 assertcxx . . $ `/usr/include/assert.h:50:10`!(src->format->BitsPerPixel == 8 && dst->format->BitsPerPixel == 8);
445
446 Uint8cxx . . $ Uint8# *dst_pixel = dst->pixelscxx . . $ SDL_Surface#pixels.;
447 const Uint8cxx . . $ Uint8# *src_pixel = src->pixelscxx . . $ SDL_Surface#pixels.;
448
449 for (int y = 0; y < 184; ++y)
450 {
451 for (int x = 0; x < 320; ++x)
452 {
453 // value is average value of source pixel and destination pixel
454 // hue is source pixel hue
455
456 const Uint8cxx . . $ Uint8# value = (*src_pixel & 0x0f) + (*dst_pixel & 0x0f);
457 *dst_pixel = (value / 2) | (*src_pixel & 0xf0);
458
459 ++dst_pixel;
460 ++src_pixel;
461 }
462
463 dst_pixel += (dst->pitchcxx . . $ SDL_Surface#pitch. - 320); // in case pitch is not 320
464 src_pixel += (src->pitchcxx . . $ SDL_Surface#pitch. - 320); // in case pitch is not 320
465 }
466 }
467
468 /* Background Starfield */
469 typedef structcxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#
470 {
471 Uint8cxx . . $ Uint8# colorcxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#color.;
472 JE_wordcxx . . $ JE_word# positioncxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#position.; // relies on overflow wrap-around
473 int speedcxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#speed.;
474 } StarfieldStarcxx . . $ StarfieldStar#;
475
476 #define MAX_STARScxx . . $ `src/backgrnd.c:476:9`! 100
477 #define STARFIELD_HUEcxx . . $ `src/backgrnd.c:477:9`! 0x90
478 static StarfieldStarcxx . . $ StarfieldStar# starfield_starscxx . . $ starfield_stars.[MAX_STARScxx . . $ `src/backgrnd.c:476:9`!];
479 int starfield_speedcxx . . $ starfield_speed.;
480
481 void initialize_starfieldcxx . . $ initialize_starfield(49f6e7a06ebc5aa8).(void)
482 {
483 for (int i = MAX_STARScxx . . $ `src/backgrnd.c:476:9`!-1; i >= 0; --i)
484 {
485 starfield_starscxx . . $ starfield_stars.[i].positioncxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#position. = mt_randcxx . . $ mt_rand(f708dce9a8856c70).() % 320 + mt_randcxx . . $ mt_rand(f708dce9a8856c70).() % 200 * VGAScreencxx . . $ VGAScreen.->pitchcxx . . $ SDL_Surface#pitch.;
486 starfield_starscxx . . $ starfield_stars.[i].speedcxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#speed. = mt_randcxx . . $ mt_rand(f708dce9a8856c70).() % 3 + 2;
487 starfield_starscxx . . $ starfield_stars.[i].colorcxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#color. = mt_randcxx . . $ mt_rand(f708dce9a8856c70).() % 16 + STARFIELD_HUEcxx . . $ `src/backgrnd.c:477:9`!;
488 }
489 }
490
491 void update_and_draw_starfieldcxx . . $ update_and_draw_starfield(114b59e033bfc6fe).(SDL_Surfacecxx . . $ SDL_Surface#* surface, int move_speed)
492 {
493 Uint8cxx . . $ Uint8#* p = (Uint8cxx . . $ Uint8#*)surface->pixelscxx . . $ SDL_Surface#pixels.;
494
495 for (int i = MAX_STARScxx . . $ `src/backgrnd.c:476:9`!-1; i >= 0; --i)
496 {
497 StarfieldStarcxx . . $ StarfieldStar#* star = &starfield_starscxx . . $ starfield_stars.[i];
498
499 star->positioncxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#position. += (star->speedcxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#speed. + move_speed) * surface->pitchcxx . . $ SDL_Surface#pitch.;
500
501 if (star->positioncxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#position. < 177 * surface->pitchcxx . . $ SDL_Surface#pitch.)
502 {
503 if (p[star->positioncxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#position.] == 0)
504 {
505 p[star->positioncxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#position.] = star->colorcxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#color.;
506 }
507
508 // If star is bright enough, draw surrounding pixels
509 if (star->colorcxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#color. - 4 >= STARFIELD_HUEcxx . . $ `src/backgrnd.c:477:9`!)
510 {
511 if (p[star->positioncxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#position. + 1] == 0)
512 p[star->positioncxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#position. + 1] = star->colorcxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#color. - 4;
513
514 if (star->positioncxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#position. > 0 && p[star->positioncxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#position. - 1] == 0)
515 p[star->positioncxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#position. - 1] = star->colorcxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#color. - 4;
516
517 if (p[star->positioncxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#position. + surface->pitchcxx . . $ SDL_Surface#pitch.] == 0)
518 p[star->positioncxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#position. + surface->pitchcxx . . $ SDL_Surface#pitch.] = star->colorcxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#color. - 4;
519
520 if (star->positioncxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#position. >= surface->pitchcxx . . $ SDL_Surface#pitch. && p[star->positioncxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#position. - surface->pitchcxx . . $ SDL_Surface#pitch.] == 0)
521 p[star->positioncxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#position. - surface->pitchcxx . . $ SDL_Surface#pitch.] = star->colorcxx . . $ $anonymous_type_f0e2bdf378f9a52b_0#color. - 4;
522 }
523 }
524 }
525 }