Debian Codegraph @

src/sprite.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 "sprite.h"
20
21 #include "file.h"
22 #include "opentyr.h"
23 #include "video.h"
24
25 #include <assert.h>
26 #include <ctype.h>
27 #include <stdlib.h>
28
29 Sprite_array sprite_table[SPRITE_TABLES_MAX];
30
31 Sprite2_array shopSpriteSheet;
32
33 Sprite2_array explosionSpriteSheet;
34
35 Sprite2_array enemySpriteSheets[4];
36 Uint8 enemySpriteSheetIds[4];
37
38 Sprite2_array destructSpriteSheet;
39
40 Sprite2_array spriteSheet8;
41 Sprite2_array spriteSheet9;
42 Sprite2_array spriteSheet10;
43 Sprite2_array spriteSheet11;
44 Sprite2_array spriteSheet12;
45
46 void load_sprites_file(unsigned int table, const char *filename)
47 {
48 free_sprites(table);
49
50 FILE *f = dir_fopen_die(data_dir(), filename, "rb");
51
52 load_sprites(table, f);
53
54 fclose(f);
55 }
56
57 void load_sprites(unsigned int table, FILE *f)
58 {
59 free_sprites(table);
60
61 Uint16 temp;
62 fread_u16_die(&temp, 1, f);
63
64 sprite_table[table].count = temp;
65
66 assert(sprite_table[table].count <= SPRITES_PER_TABLE_MAX);
67
68 for (unsigned int i = 0; i < sprite_table[table].count; ++i)
69 {
70 Sprite * const cur_sprite = sprite(table, i);
71
72 bool populated;
73 fread_bool_die(&populated, f);
74 if (!populated) // sprite is empty
75 continue;
76
77 fread_u16_die(&cur_sprite->width, 1, f);
78 fread_u16_die(&cur_sprite->height, 1, f);
79 fread_u16_die(&cur_sprite->size, 1, f);
80
81 cur_sprite->data = malloc(cur_sprite->size);
82
83 fread_u8_die(cur_sprite->data, cur_sprite->size, f);
84 }
85 }
86
87 void free_sprites(unsigned int table)
88 {
89 for (unsigned int i = 0; i < sprite_table[table].count; ++i)
90 {
91 Sprite * const cur_sprite = sprite(table, i);
92
93 cur_sprite->width = 0;
94 cur_sprite->height = 0;
95 cur_sprite->size = 0;
96
97 free(cur_sprite->data);
98 cur_sprite->data = NULL;
99 }
100
101 sprite_table[table].count = 0;
102 }
103
104 // does not clip on left or right edges of surface
105 void blit_sprite(SDL_Surface *surface, int x, int y, unsigned int table, unsigned int index)
106 {
107 if (index >= sprite_table[table].count || !sprite_exists(table, index))
108 {
109 assert(false);
110 return;
111 }
112
113 const Sprite * const cur_sprite = sprite(table, index);
114
115 const Uint8 *data = cur_sprite->data;
116 const Uint8 * const data_ul = data + cur_sprite->size;
117
118 const unsigned int width = cur_sprite->width;
119 unsigned int x_offset = 0;
120
121 assert(surface->format->BitsPerPixel == 8);
122 Uint8 * pixels = (Uint8 *)surface->pixels + (y * surface->pitch) + x;
123 const Uint8 * const pixels_ll = (Uint8 *)surface->pixels, // lower limit
124 * const pixels_ul = (Uint8 *)surface->pixels + (surface->h * surface->pitch); // upper limit
125
126 for (; data < data_ul; ++data)
127 {
128 switch (*data)
129 {
130 case 255: // transparent pixels
131 data++; // next byte tells how many
132 pixels += *data;
133 x_offset += *data;
134 break;
135
136 case 254: // next pixel row
137 pixels += width - x_offset;
138 x_offset = width;
139 break;
140
141 case 253: // 1 transparent pixel
142 pixels++;
143 x_offset++;
144 break;
145
146 default: // set a pixel
147 if (pixels >= pixels_ul)
148 return;
149 if (pixels >= pixels_ll)
150 *pixels = *data;
151
152 pixels++;
153 x_offset++;
154 break;
155 }
156 if (x_offset >= width)
157 {
158 pixels += surface->pitch - x_offset;
159 x_offset = 0;
160 }
161 }
162 }
163
164 // does not clip on left or right edges of surface
165 void blit_sprite_blend(SDL_Surface *surface, int x, int y, unsigned int table, unsigned int index)
166 {
167 if (index >= sprite_table[table].count || !sprite_exists(table, index))
168 {
169 assert(false);
170 return;
171 }
172
173 const Sprite * const cur_sprite = sprite(table, index);
174
175 const Uint8 *data = cur_sprite->data;
176 const Uint8 * const data_ul = data + cur_sprite->size;
177
178 const unsigned int width = cur_sprite->width;
179 unsigned int x_offset = 0;
180
181 assert(surface->format->BitsPerPixel == 8);
182 Uint8 * pixels = (Uint8 *)surface->pixels + (y * surface->pitch) + x;
183 const Uint8 * const pixels_ll = (Uint8 *)surface->pixels, // lower limit
184 * const pixels_ul = (Uint8 *)surface->pixels + (surface->h * surface->pitch); // upper limit
185
186 for (; data < data_ul; ++data)
187 {
188 switch (*data)
189 {
190 case 255: // transparent pixels
191 data++; // next byte tells how many
192 pixels += *data;
193 x_offset += *data;
194 break;
195
196 case 254: // next pixel row
197 pixels += width - x_offset;
198 x_offset = width;
199 break;
200
201 case 253: // 1 transparent pixel
202 pixels++;
203 x_offset++;
204 break;
205
206 default: // set a pixel
207 if (pixels >= pixels_ul)
208 return;
209 if (pixels >= pixels_ll)
210 *pixels = (*data & 0xf0) | (((*pixels & 0x0f) + (*data & 0x0f)) / 2);
211
212 pixels++;
213 x_offset++;
214 break;
215 }
216 if (x_offset >= width)
217 {
218 pixels += surface->pitch - x_offset;
219 x_offset = 0;
220 }
221 }
222 }
223
224 // does not clip on left or right edges of surface
225 // unsafe because it doesn't check that value won't overflow into hue
226 // we can replace it when we know that we don't rely on that 'feature'
227 void blit_sprite_hv_unsafe(SDL_Surface *surface, int x, int y, unsigned int table, unsigned int index, Uint8 hue, Sint8 value)
228 {
229 if (index >= sprite_table[table].count || !sprite_exists(table, index))
230 {
231 assert(false);
232 return;
233 }
234
235 hue <<= 4;
236
237 const Sprite * const cur_sprite = sprite(table, index);
238
239 const Uint8 *data = cur_sprite->data;
240 const Uint8 * const data_ul = data + cur_sprite->size;
241
242 const unsigned int width = cur_sprite->width;
243 unsigned int x_offset = 0;
244
245 assert(surface->format->BitsPerPixel == 8);
246 Uint8 * pixels = (Uint8 *)surface->pixels + (y * surface->pitch) + x;
247 const Uint8 * const pixels_ll = (Uint8 *)surface->pixels, // lower limit
248 * const pixels_ul = (Uint8 *)surface->pixels + (surface->h * surface->pitch); // upper limit
249
250 for (; data < data_ul; ++data)
251 {
252 switch (*data)
253 {
254 case 255: // transparent pixels
255 data++; // next byte tells how many
256 pixels += *data;
257 x_offset += *data;
258 break;
259
260 case 254: // next pixel row
261 pixels += width - x_offset;
262 x_offset = width;
263 break;
264
265 case 253: // 1 transparent pixel
266 pixels++;
267 x_offset++;
268 break;
269
270 default: // set a pixel
271 if (pixels >= pixels_ul)
272 return;
273 if (pixels >= pixels_ll)
274 *pixels = hue | ((*data & 0x0f) + value);
275
276 pixels++;
277 x_offset++;
278 break;
279 }
280 if (x_offset >= width)
281 {
282 pixels += surface->pitch - x_offset;
283 x_offset = 0;
284 }
285 }
286 }
287
288 // does not clip on left or right edges of surface
289 void blit_sprite_hv(SDL_Surface *surface, int x, int y, unsigned int table, unsigned int index, Uint8 hue, Sint8 value)
290 {
291 if (index >= sprite_table[table].count || !sprite_exists(table, index))
292 {
293 assert(false);
294 return;
295 }
296
297 hue <<= 4;
298
299 const Sprite * const cur_sprite = sprite(table, index);
300
301 const Uint8 *data = cur_sprite->data;
302 const Uint8 * const data_ul = data + cur_sprite->size;
303
304 const unsigned int width = cur_sprite->width;
305 unsigned int x_offset = 0;
306
307 assert(surface->format->BitsPerPixel == 8);
308 Uint8 * pixels = (Uint8 *)surface->pixels + (y * surface->pitch) + x;
309 const Uint8 * const pixels_ll = (Uint8 *)surface->pixels, // lower limit
310 * const pixels_ul = (Uint8 *)surface->pixels + (surface->h * surface->pitch); // upper limit
311
312 for (; data < data_ul; ++data)
313 {
314 switch (*data)
315 {
316 case 255: // transparent pixels
317 data++; // next byte tells how many
318 pixels += *data;
319 x_offset += *data;
320 break;
321
322 case 254: // next pixel row
323 pixels += width - x_offset;
324 x_offset = width;
325 break;
326
327 case 253: // 1 transparent pixel
328 pixels++;
329 x_offset++;
330 break;
331
332 default: // set a pixel
333 if (pixels >= pixels_ul)
334 return;
335 if (pixels >= pixels_ll)
336 {
337 Uint8 temp_value = (*data & 0x0f) + value;
338 if (temp_value > 0xf)
339 temp_value = (temp_value >= 0x1f) ? 0x0 : 0xf;
340
341 *pixels = hue | temp_value;
342 }
343
344 pixels++;
345 x_offset++;
346 break;
347 }
348 if (x_offset >= width)
349 {
350 pixels += surface->pitch - x_offset;
351 x_offset = 0;
352 }
353 }
354 }
355
356 // does not clip on left or right edges of surface
357 void blit_sprite_hv_blend(SDL_Surface *surface, int x, int y, unsigned int table, unsigned int index, Uint8 hue, Sint8 value)
358 {
359 if (index >= sprite_table[table].count || !sprite_exists(table, index))
360 {
361 assert(false);
362 return;
363 }
364
365 hue <<= 4;
366
367 const Sprite * const cur_sprite = sprite(table, index);
368
369 const Uint8 *data = cur_sprite->data;
370 const Uint8 * const data_ul = data + cur_sprite->size;
371
372 const unsigned int width = cur_sprite->width;
373 unsigned int x_offset = 0;
374
375 assert(surface->format->BitsPerPixel == 8);
376 Uint8 * pixels = (Uint8 *)surface->pixels + (y * surface->pitch) + x;
377 const Uint8 * const pixels_ll = (Uint8 *)surface->pixels, // lower limit
378 * const pixels_ul = (Uint8 *)surface->pixels + (surface->h * surface->pitch); // upper limit
379
380 for (; data < data_ul; ++data)
381 {
382 switch (*data)
383 {
384 case 255: // transparent pixels
385 data++; // next byte tells how many
386 pixels += *data;
387 x_offset += *data;
388 break;
389
390 case 254: // next pixel row
391 pixels += width - x_offset;
392 x_offset = width;
393 break;
394
395 case 253: // 1 transparent pixel
396 pixels++;
397 x_offset++;
398 break;
399
400 default: // set a pixel
401 if (pixels >= pixels_ul)
402 return;
403 if (pixels >= pixels_ll)
404 {
405 Uint8 temp_value = (*data & 0x0f) + value;
406 if (temp_value > 0xf)
407 temp_value = (temp_value >= 0x1f) ? 0x0 : 0xf;
408
409 *pixels = hue | (((*pixels & 0x0f) + temp_value) / 2);
410 }
411
412 pixels++;
413 x_offset++;
414 break;
415 }
416 if (x_offset >= width)
417 {
418 pixels += surface->pitch - x_offset;
419 x_offset = 0;
420 }
421 }
422 }
423
424 // does not clip on left or right edges of surface
425 void blit_sprite_dark(SDL_Surface *surface, int x, int y, unsigned int table, unsigned int index, bool black)
426 {
427 if (index >= sprite_table[table].count || !sprite_exists(table, index))
428 {
429 assert(false);
430 return;
431 }
432
433 const Sprite * const cur_sprite = sprite(table, index);
434
435 const Uint8 *data = cur_sprite->data;
436 const Uint8 * const data_ul = data + cur_sprite->size;
437
438 const unsigned int width = cur_sprite->width;
439 unsigned int x_offset = 0;
440
441 assert(surface->format->BitsPerPixel == 8);
442 Uint8 * pixels = (Uint8 *)surface->pixels + (y * surface->pitch) + x;
443 const Uint8 * const pixels_ll = (Uint8 *)surface->pixels, // lower limit
444 * const pixels_ul = (Uint8 *)surface->pixels + (surface->h * surface->pitch); // upper limit
445
446 for (; data < data_ul; ++data)
447 {
448 switch (*data)
449 {
450 case 255: // transparent pixels
451 data++; // next byte tells how many
452 pixels += *data;
453 x_offset += *data;
454 break;
455
456 case 254: // next pixel row
457 pixels += width - x_offset;
458 x_offset = width;
459 break;
460
461 case 253: // 1 transparent pixel
462 pixels++;
463 x_offset++;
464 break;
465
466 default: // set a pixel
467 if (pixels >= pixels_ul)
468 return;
469 if (pixels >= pixels_ll)
470 *pixels = black ? 0x00 : ((*pixels & 0xf0) | ((*pixels & 0x0f) / 2));
471
472 pixels++;
473 x_offset++;
474 break;
475 }
476 if (x_offset >= width)
477 {
478 pixels += surface->pitch - x_offset;
479 x_offset = 0;
480 }
481 }
482 }
483
484 void JE_loadCompShapes(Sprite2_array *sprite2s, char s)
485 {
486 free_sprite2s(sprite2s);
487
488 char buffer[20];
489 snprintf(buffer, sizeof(buffer), "newsh%c.shp", tolower((unsigned char)s));
490
491 FILE *f = dir_fopen_die(data_dir(), buffer, "rb");
492
493 sprite2s->size = ftell_eof(f);
494
495 JE_loadCompShapesB(sprite2s, f);
496
497 fclose(f);
498 }
499
500 void JE_loadCompShapesB(Sprite2_array *sprite2s, FILE *f)
501 {
502 assert(sprite2s->data == NULL);
503
504 sprite2s->data = malloc(sprite2s->size);
505 fread_u8_die(sprite2s->data, sprite2s->size, f);
506 }
507
508 void free_sprite2s(Sprite2_array *sprite2s)
509 {
510 free(sprite2s->data);
511 sprite2s->data = NULL;
512
513 sprite2s->size = 0;
514 }
515
516 // does not clip on left or right edges of surface
517 void blit_sprite2(SDL_Surface *surface, int x, int y, Sprite2_array sprite2s, unsigned int index)
518 {
519 assert(surface->format->BitsPerPixel == 8);
520 Uint8 * pixels = (Uint8 *)surface->pixels + (y * surface->pitch) + x;
521 const Uint8 * const pixels_ll = (Uint8 *)surface->pixels, // lower limit
522 * const pixels_ul = (Uint8 *)surface->pixels + (surface->h * surface->pitch); // upper limit
523
524 const Uint8 *data = sprite2s.data + SDL_SwapLE16(((Uint16 *)sprite2s.data)[index - 1]);
525
526 for (; *data != 0x0f; ++data)
527 {
528 pixels += *data & 0x0f; // second nibble: transparent pixel count
529 unsigned int count = (*data & 0xf0) >> 4; // first nibble: opaque pixel count
530
531 if (count == 0) // move to next pixel row
532 {
533 pixels += VGAScreen->pitch - 12;
534 }
535 else
536 {
537 while (count--)
538 {
539 ++data;
540
541 if (pixels >= pixels_ul)
542 return;
543 if (pixels >= pixels_ll)
544 *pixels = *data;
545
546 ++pixels;
547 }
548 }
549 }
550 }
551
552 void blit_sprite2_clip(SDL_Surface *surface, int x, int y, Sprite2_array sprite2s, unsigned int index)
553 {
554 assert(surface->format->BitsPerPixel == 8);
555
556 const Uint8 *data = sprite2s.data + SDL_SwapLE16(((Uint16 *)sprite2s.data)[index - 1]);
557
558 for (; *data != 0x0f; ++data)
559 {
560 if (y >= surface->h)
561 return;
562
563 Uint8 skip_count = *data & 0x0f;
564 Uint8 fill_count = (*data >> 4) & 0x0f;
565
566 x += skip_count;
567
568 if (fill_count == 0) // move to next pixel row
569 {
570 y += 1;
571 x -= 12;
572 }
573 else if (y >= 0)
574 {
575 Uint8 *const pixel_row = (Uint8 *)surface->pixels + (y * surface->pitch);
576 do
577 {
578 ++data;
579
580 if (x >= 0 && x < surface->pitch)
581 pixel_row[x] = *data;
582 x += 1;
583 } while (--fill_count);
584 }
585 else
586 {
587 data += fill_count;
588 x += fill_count;
589 }
590 }
591 }
592
593 // does not clip on left or right edges of surface
594 void blit_sprite2_blend(SDL_Surface *surface, int x, int y, Sprite2_array sprite2s, unsigned int index)
595 {
596 assert(surface->format->BitsPerPixel == 8);
597 Uint8 * pixels = (Uint8 *)surface->pixels + (y * surface->pitch) + x;
598 const Uint8 * const pixels_ll = (Uint8 *)surface->pixels, // lower limit
599 * const pixels_ul = (Uint8 *)surface->pixels + (surface->h * surface->pitch); // upper limit
600
601 const Uint8 *data = sprite2s.data + SDL_SwapLE16(((Uint16 *)sprite2s.data)[index - 1]);
602
603 for (; *data != 0x0f; ++data)
604 {
605 pixels += *data & 0x0f; // second nibble: transparent pixel count
606 unsigned int count = (*data & 0xf0) >> 4; // first nibble: opaque pixel count
607
608 if (count == 0) // move to next pixel row
609 {
610 pixels += VGAScreen->pitch - 12;
611 }
612 else
613 {
614 while (count--)
615 {
616 ++data;
617
618 if (pixels >= pixels_ul)
619 return;
620 if (pixels >= pixels_ll)
621 *pixels = (((*data & 0x0f) + (*pixels & 0x0f)) / 2) | (*data & 0xf0);
622
623 ++pixels;
624 }
625 }
626 }
627 }
628
629 // does not clip on left or right edges of surface
630 void blit_sprite2_darken(SDL_Surface *surface, int x, int y, Sprite2_array sprite2s, unsigned int index)
631 {
632 assert(surface->format->BitsPerPixel == 8);
633 Uint8 * pixels = (Uint8 *)surface->pixels + (y * surface->pitch) + x;
634 const Uint8 * const pixels_ll = (Uint8 *)surface->pixels, // lower limit
635 * const pixels_ul = (Uint8 *)surface->pixels + (surface->h * surface->pitch); // upper limit
636
637 const Uint8 *data = sprite2s.data + SDL_SwapLE16(((Uint16 *)sprite2s.data)[index - 1]);
638
639 for (; *data != 0x0f; ++data)
640 {
641 pixels += *data & 0x0f; // second nibble: transparent pixel count
642 unsigned int count = (*data & 0xf0) >> 4; // first nibble: opaque pixel count
643
644 if (count == 0) // move to next pixel row
645 {
646 pixels += VGAScreen->pitch - 12;
647 }
648 else
649 {
650 while (count--)
651 {
652 ++data;
653
654 if (pixels >= pixels_ul)
655 return;
656 if (pixels >= pixels_ll)
657 *pixels = ((*pixels & 0x0f) / 2) + (*pixels & 0xf0);
658
659 ++pixels;
660 }
661 }
662 }
663 }
664
665 // does not clip on left or right edges of surface
666 void blit_sprite2_filter(SDL_Surface *surface, int x, int y, Sprite2_array sprite2s, unsigned int index, Uint8 filter)
667 {
668 assert(surface->format->BitsPerPixel == 8);
669 Uint8 * pixels = (Uint8 *)surface->pixels + (y * surface->pitch) + x;
670 const Uint8 * const pixels_ll = (Uint8 *)surface->pixels, // lower limit
671 * const pixels_ul = (Uint8 *)surface->pixels + (surface->h * surface->pitch); // upper limit
672
673 const Uint8 *data = sprite2s.data + SDL_SwapLE16(((Uint16 *)sprite2s.data)[index - 1]);
674
675 for (; *data != 0x0f; ++data)
676 {
677 pixels += *data & 0x0f; // second nibble: transparent pixel count
678 unsigned int count = (*data & 0xf0) >> 4; // first nibble: opaque pixel count
679
680 if (count == 0) // move to next pixel row
681 {
682 pixels += VGAScreen->pitch - 12;
683 }
684 else
685 {
686 while (count--)
687 {
688 ++data;
689
690 if (pixels >= pixels_ul)
691 return;
692 if (pixels >= pixels_ll)
693 *pixels = filter | (*data & 0x0f);
694
695 ++pixels;
696 }
697 }
698 }
699 }
700
701 void blit_sprite2_filter_clip(SDL_Surface *surface, int x, int y, Sprite2_array sprite2s, unsigned int index, Uint8 filter)
702 {
703 assert(surface->format->BitsPerPixel == 8);
704
705 const Uint8 *data = sprite2s.data + SDL_SwapLE16(((Uint16 *)sprite2s.data)[index - 1]);
706
707 for (; *data != 0x0f; ++data)
708 {
709 if (y >= surface->h)
710 return;
711
712 Uint8 skip_count = *data & 0x0f;
713 Uint8 fill_count = (*data >> 4) & 0x0f;
714
715 x += skip_count;
716
717 if (fill_count == 0) // move to next pixel row
718 {
719 y += 1;
720 x -= 12;
721 }
722 else if (y >= 0)
723 {
724 Uint8 *const pixel_row = (Uint8 *)surface->pixels + (y * surface->pitch);
725 do
726 {
727 ++data;
728
729 if (x >= 0 && x < surface->pitch)
730 pixel_row[x] = filter | (*data & 0x0f);;
731 x += 1;
732 } while (--fill_count);
733 }
734 else
735 {
736 data += fill_count;
737 x += fill_count;
738 }
739 }
740 }
741
742 // does not clip on left or right edges of surface
743 void blit_sprite2x2(SDL_Surface *surface, int x, int y, Sprite2_array sprite2s, unsigned int index)
744 {
745 blit_sprite2(surface, x, y, sprite2s, index);
746 blit_sprite2(surface, x + 12, y, sprite2s, index + 1);
747 blit_sprite2(surface, x, y + 14, sprite2s, index + 19);
748 blit_sprite2(surface, x + 12, y + 14, sprite2s, index + 20);
749 }
750
751 void blit_sprite2x2_clip(SDL_Surface *surface, int x, int y, Sprite2_array sprite2s, unsigned int index)
752 {
753 blit_sprite2_clip(surface, x, y, sprite2s, index);
754 blit_sprite2_clip(surface, x + 12, y, sprite2s, index + 1);
755 blit_sprite2_clip(surface, x, y + 14, sprite2s, index + 19);
756 blit_sprite2_clip(surface, x + 12, y + 14, sprite2s, index + 20);
757 }
758
759 // does not clip on left or right edges of surface
760 void blit_sprite2x2_blend(SDL_Surface *surface, int x, int y, Sprite2_array sprite2s, unsigned int index)
761 {
762 blit_sprite2_blend(surface, x, y, sprite2s, index);
763 blit_sprite2_blend(surface, x + 12, y, sprite2s, index + 1);
764 blit_sprite2_blend(surface, x, y + 14, sprite2s, index + 19);
765 blit_sprite2_blend(surface, x + 12, y + 14, sprite2s, index + 20);
766 }
767
768 // does not clip on left or right edges of surface
769 void blit_sprite2x2_darken(SDL_Surface *surface, int x, int y, Sprite2_array sprite2s, unsigned int index)
770 {
771 blit_sprite2_darken(surface, x, y, sprite2s, index);
772 blit_sprite2_darken(surface, x + 12, y, sprite2s, index + 1);
773 blit_sprite2_darken(surface, x, y + 14, sprite2s, index + 19);
774 blit_sprite2_darken(surface, x + 12, y + 14, sprite2s, index + 20);
775 }
776
777 // does not clip on left or right edges of surface
778 void blit_sprite2x2_filter(SDL_Surface *surface, int x, int y, Sprite2_array sprite2s, unsigned int index, Uint8 filter)
779 {
780 blit_sprite2_filter(surface, x, y, sprite2s, index, filter);
781 blit_sprite2_filter(surface, x + 12, y, sprite2s, index + 1, filter);
782 blit_sprite2_filter(surface, x, y + 14, sprite2s, index + 19, filter);
783 blit_sprite2_filter(surface, x + 12, y + 14, sprite2s, index + 20, filter);
784 }
785
786 void blit_sprite2x2_filter_clip(SDL_Surface *surface, int x, int y, Sprite2_array sprite2s, unsigned int index, Uint8 filter)
787 {
788 blit_sprite2_filter_clip(surface, x, y, sprite2s, index, filter);
789 blit_sprite2_filter_clip(surface, x + 12, y, sprite2s, index + 1, filter);
790 blit_sprite2_filter_clip(surface, x, y + 14, sprite2s, index + 19, filter);
791 blit_sprite2_filter_clip(surface, x + 12, y + 14, sprite2s, index + 20, filter);
792 }
793
794 void JE_loadMainShapeTables(const char *shpfile)
795 {
796 enum { SHP_NUM = 12 };
797
798 FILE *f = dir_fopen_die(data_dir(), shpfile, "rb");
799
800 JE_word shpNumb;
801 JE_longint shpPos[SHP_NUM + 1]; // +1 for storing file length
802
803 fread_u16_die(&shpNumb, 1, f);
804 assert(shpNumb + 1u == COUNTOF(shpPos));
805
806 fread_s32_die(shpPos, shpNumb, f);
807
808 fseek(f, 0, SEEK_END);
809 for (unsigned int i = shpNumb; i < COUNTOF(shpPos); ++i)
810 shpPos[i] = ftell(f);
811
812 int i;
813 // fonts, interface, option sprites
814 for (i = 0; i < 7; i++)
815 {
816 fseek(f, shpPos[i], SEEK_SET);
817 load_sprites(i, f);
818 }
819
820 // player shot sprites
821 spriteSheet8.size = shpPos[i + 1] - shpPos[i];
822 JE_loadCompShapesB(&spriteSheet8, f);
823 i++;
824
825 // player ship sprites
826 spriteSheet9.size = shpPos[i + 1] - shpPos[i];
827 JE_loadCompShapesB(&spriteSheet9 , f);
828 i++;
829
830 // power-up sprites
831 spriteSheet10.size = shpPos[i + 1] - shpPos[i];
832 JE_loadCompShapesB(&spriteSheet10, f);
833 i++;
834
835 // coins, datacubes, etc sprites
836 spriteSheet11.size = shpPos[i + 1] - shpPos[i];
837 JE_loadCompShapesB(&spriteSheet11, f);
838 i++;
839
840 // more player shot sprites
841 spriteSheet12.size = shpPos[i + 1] - shpPos[i];
842 JE_loadCompShapesB(&spriteSheet12, f);
843
844 fclose(f);
845 }
846
847 void free_main_shape_tables(void)
848 {
849 for (uint i = 0; i < COUNTOF(sprite_table); ++i)
850 free_sprites(i);
851
852 free_sprite2s(&spriteSheet8);
853 free_sprite2s(&spriteSheet9);
854 free_sprite2s(&spriteSheet10);
855 free_sprite2s(&spriteSheet11);
856 free_sprite2s(&spriteSheet12);
857 }