move bitmap replacement functions to piggy.c
authorBradley Bell <btb@icculus.org>
Sat, 22 Mar 2003 03:14:30 +0000 (03:14 +0000)
committerBradley Bell <btb@icculus.org>
Sat, 22 Mar 2003 03:14:30 +0000 (03:14 +0000)
ChangeLog
main/gameseq.c
main/piggy.c

index 78ff257..bd147cf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2003-03-21  Martin Schaffner <maschaffner@gmx.ch>
 
+       * main/gameseq.c, main/piggy.c, main/piggy.h: move bitmap
+       replacement functions to piggy.c
+
        * main/gameseq.c: attempt to support mac d1 descent.pig
 
        * main/bm.c: fix mem leak
index 8f0f0de..f09b07e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: gameseq.c,v 1.22 2003-03-22 02:41:42 btb Exp $ */
+/* $Id: gameseq.c,v 1.23 2003-03-22 03:14:30 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -17,7 +17,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #endif
 
 #ifdef RCS
-char gameseq_rcsid[] = "$Id: gameseq.c,v 1.22 2003-03-22 02:41:42 btb Exp $";
+char gameseq_rcsid[] = "$Id: gameseq.c,v 1.23 2003-03-22 03:14:30 btb Exp $";
 #endif
 
 #ifdef WINDOWS
@@ -818,214 +818,6 @@ do_menu_again:
        return 1;
 }
 
-extern void change_filename_extension( char *dest, char *src, char *new_ext );
-extern char last_palette_loaded_pig[];
-
-ubyte *Bitmap_replacement_data=NULL;
-
-void free_bitmap_replacements()
-{
-       if (Bitmap_replacement_data) {
-               d_free(Bitmap_replacement_data);
-               Bitmap_replacement_data = NULL;
-       }
-}
-
-void load_bitmap_replacements(char *level_name)
-{
-       char ifile_name[FILENAME_LEN];
-       CFILE *ifile;
-       int i;
-
-       //first, free up data allocated for old bitmaps
-       free_bitmap_replacements();
-
-       change_filename_extension(ifile_name, level_name, ".POG" );
-       
-       ifile = cfopen(ifile_name,"rb");
-
-       if (ifile) {
-               int id,version,n_bitmaps;
-               int bitmap_data_size;
-               ushort *indices;
-               id = cfile_read_int(ifile);
-               version = cfile_read_int(ifile);
-
-               if (id != MAKE_SIG('G','O','P','D') || version != 1) {
-                       cfclose(ifile);
-                       return;
-               }
-
-               n_bitmaps = cfile_read_int(ifile);
-
-               MALLOC( indices, ushort, n_bitmaps );
-               
-               for (i = 0; i < n_bitmaps; i++)
-                       indices[i] = cfile_read_short(ifile);
-
-               bitmap_data_size = cfilelength(ifile) - cftell(ifile) - DISKBITMAPHEADER_SIZE * n_bitmaps;
-               MALLOC( Bitmap_replacement_data, ubyte, bitmap_data_size );
-
-               for (i=0;i<n_bitmaps;i++) {
-                       DiskBitmapHeader bmh;
-                       grs_bitmap temp_bitmap;
-
-                       DiskBitmapHeader_read(&bmh, ifile);
-
-                       memset( &temp_bitmap, 0, sizeof(grs_bitmap) );
-       
-                       temp_bitmap.bm_w = temp_bitmap.bm_rowsize = bmh.width + ((short) (bmh.wh_extra&0x0f)<<8);
-                       temp_bitmap.bm_h = bmh.height + ((short) (bmh.wh_extra&0xf0)<<4);
-                       temp_bitmap.avg_color = bmh.avg_color;
-                       temp_bitmap.bm_data = Bitmap_replacement_data + bmh.offset;
-       
-                       if ( bmh.flags & BM_FLAG_TRANSPARENT ) temp_bitmap.bm_flags |= BM_FLAG_TRANSPARENT;
-                       if ( bmh.flags & BM_FLAG_SUPER_TRANSPARENT ) temp_bitmap.bm_flags |= BM_FLAG_SUPER_TRANSPARENT;
-                       if ( bmh.flags & BM_FLAG_NO_LIGHTING ) temp_bitmap.bm_flags |= BM_FLAG_NO_LIGHTING;
-                       if ( bmh.flags & BM_FLAG_RLE ) temp_bitmap.bm_flags |= BM_FLAG_RLE;
-                       if ( bmh.flags & BM_FLAG_RLE_BIG ) temp_bitmap.bm_flags |= BM_FLAG_RLE_BIG;
-
-                       GameBitmaps[indices[i]] = temp_bitmap;
-               }
-
-               cfread(Bitmap_replacement_data,1,bitmap_data_size,ifile);
-
-               d_free(indices);
-
-               cfclose(ifile);
-
-               last_palette_loaded_pig[0]= 0;  //force pig re-load
-
-               texmerge_flush();               //for re-merging with new textures
-       }
-
-       atexit(free_bitmap_replacements);
-}
-
-#define FIRST_D1_TEXTURE 722
-#define LAST_D1_STATIC_TEXTURE 1042//1342 //afterwards, we have door frames and stuff
-#define FIRST_D2_TEXTURE 1243
-
-void load_d1_bitmap_replacements()
-{
-       CFILE * d1_Piggy_fp;
-       grs_bitmap temp_bitmap;
-       DiskBitmapHeader bmh;
-       int pig_data_start, bitmap_header_start, bitmap_data_start;
-       int N_bitmaps, zsize;
-       int d1_index, d2_index;
-       ubyte colormap[256];
-       ubyte *next_bitmap; // to which address we write the next bitmap
-
-#ifndef MACINTOSH
-       d1_Piggy_fp = cfopen( "descent.pig", "rb" );
-#else
-       d1_Piggy_fp = cfopen( "Data:Descent.pig", "rb" );
-#endif  // end of ifndef/else MACINTOSH
-
-       if (!d1_Piggy_fp)
-               return; // use d2 bitmaps instead...
-
-       //first, free up data allocated for old bitmaps
-       free_bitmap_replacements();
-
-       // read d1 palette, build colormap
-       {
-               int freq[256];
-               ubyte d1_palette[256*3];
-               CFILE * palette_file = cfopen( "palette.256", "rb" );
-               Assert( palette_file );
-               Assert( cfilelength( palette_file ) == 9472 );
-               cfread( d1_palette, 256, 3, palette_file);
-               cfclose( palette_file );
-               build_colormap_good( d1_palette, colormap, freq );
-               // don't change transparencies:
-               colormap[254] = 254;
-               colormap[255] = 255;
-       }
-
-
-       if (0) //TODO: put here cfilelength(d1_Piggy_fp) == D1_PIG_SHARE
-               pig_data_start = 0;
-       else {
-               //int i;
-               pig_data_start = cfile_read_int(d1_Piggy_fp );
-               bm_read_all_d1( d1_Piggy_fp );
-               //for (i = 0; i < 1800; i++) GameBitmapXlat[i] = cfile_read_short(d1_Piggy_fp);
-       }
-       cfseek( d1_Piggy_fp, pig_data_start, SEEK_SET );
-       N_bitmaps = cfile_read_int(d1_Piggy_fp);
-       {
-               int N_sounds = cfile_read_int(d1_Piggy_fp);
-               int header_size = N_bitmaps * DISKBITMAPHEADER_D1_SIZE
-                               + N_sounds * DISKSOUNDHEADER_SIZE;
-               bitmap_header_start = pig_data_start + 2 * sizeof(int);
-               bitmap_data_start = bitmap_header_start + header_size;
-       }
-
-       MALLOC( Bitmap_replacement_data, ubyte, cfilelength(d1_Piggy_fp) - bitmap_data_start ); // too much
-       //TODO: handle case where b_r_d == 0! (have to convert textures, return, not bm_read_all_d1)
-
-       next_bitmap = Bitmap_replacement_data;
-
-       for (d1_index=1; d1_index<=N_bitmaps; d1_index++ ) {
-               // only change wall texture bitmaps
-               if (d1_index >= FIRST_D1_TEXTURE && d1_index <= LAST_D1_STATIC_TEXTURE) {
-                       d2_index = d1_index + FIRST_D2_TEXTURE - FIRST_D1_TEXTURE;
-
-                       cfseek(d1_Piggy_fp, bitmap_header_start + (d1_index-1) * DISKBITMAPHEADER_D1_SIZE, SEEK_SET);
-                       DiskBitmapHeader_d1_read(&bmh, d1_Piggy_fp);
-
-                       memset( &temp_bitmap, 0, sizeof(grs_bitmap) );
-
-                       temp_bitmap.bm_w = temp_bitmap.bm_rowsize = bmh.width + ((short) (bmh.wh_extra&0x0f)<<8);
-                       temp_bitmap.bm_h = bmh.height + ((short) (bmh.wh_extra&0xf0)<<4);
-                       temp_bitmap.avg_color = bmh.avg_color;
-
-                       //GameBitmapFlags[convert_d1_bitmap_num(d1_index)] = 0;
-
-                       if ( bmh.flags & BM_FLAG_TRANSPARENT )
-                               temp_bitmap.bm_flags |= BM_FLAG_TRANSPARENT;
-                       if ( bmh.flags & BM_FLAG_SUPER_TRANSPARENT )
-                               temp_bitmap.bm_flags |= BM_FLAG_SUPER_TRANSPARENT;
-                       if ( bmh.flags & BM_FLAG_NO_LIGHTING )
-                               temp_bitmap.bm_flags |= BM_FLAG_NO_LIGHTING;
-                       if ( bmh.flags & BM_FLAG_RLE )
-                               temp_bitmap.bm_flags |= BM_FLAG_RLE;
-                       if ( bmh.flags & BM_FLAG_RLE_BIG )
-                               temp_bitmap.bm_flags |= BM_FLAG_RLE_BIG;
-
-                       temp_bitmap.bm_data = next_bitmap;
-
-                       cfseek(d1_Piggy_fp, bitmap_data_start + bmh.offset, SEEK_SET);
-                       zsize = cfile_read_int(d1_Piggy_fp);
-                       cfseek(d1_Piggy_fp, bitmap_data_start + bmh.offset, SEEK_SET);
-                       cfread(next_bitmap, 1, zsize, d1_Piggy_fp);
-
-                       switch(cfilelength(d1_Piggy_fp)) {
-                       case D1_MAC_PIGSIZE:
-                       case D1_MAC_SHARE_PIGSIZE:
-                               rle_swap_0_255(&temp_bitmap);
-                       }
-                       rle_remap(&temp_bitmap, colormap);
-
-                       GameBitmaps[d2_index] = temp_bitmap;
-
-                       memcpy(&zsize, temp_bitmap.bm_data, 4);
-                       next_bitmap += zsize;
-               }
-       }
-
-       cfclose(d1_Piggy_fp);
-
-       last_palette_loaded_pig[0]= 0;  //force pig re-load
-
-       texmerge_flush();               //for re-merging with new textures
-
-       atexit(free_bitmap_replacements);
-}
-
 
 void load_robot_replacements(char *level_name);
 int read_hamfile();
index ebe5834..7d3bbef 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: piggy.c,v 1.24 2003-03-20 23:14:14 btb Exp $ */
+/* $Id: piggy.c,v 1.25 2003-03-22 03:14:30 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -386,7 +386,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #endif
 
 #ifdef RCS
-static char rcsid[] = "$Id: piggy.c,v 1.24 2003-03-20 23:14:14 btb Exp $";
+static char rcsid[] = "$Id: piggy.c,v 1.25 2003-03-22 03:14:30 btb Exp $";
 #endif
 
 
@@ -2148,7 +2148,223 @@ void piggy_bitmap_page_out_all_w()
 {
 }
 
-#endif
+#endif // WINDOWS
+
+
+/*
+ * Functions for loading replacement textures
+ *  1) From .pog files
+ *  2) From descent.pig (for loading d1 levels)
+ */
+
+extern void change_filename_extension( char *dest, char *src, char *new_ext );
+extern char last_palette_loaded_pig[];
+
+ubyte *Bitmap_replacement_data=NULL;
+
+void free_bitmap_replacements()
+{
+       if (Bitmap_replacement_data) {
+               d_free(Bitmap_replacement_data);
+               Bitmap_replacement_data = NULL;
+       }
+}
+
+void load_bitmap_replacements(char *level_name)
+{
+       char ifile_name[FILENAME_LEN];
+       CFILE *ifile;
+       int i;
+
+       //first, free up data allocated for old bitmaps
+       free_bitmap_replacements();
+
+       change_filename_extension(ifile_name, level_name, ".POG" );
+
+       ifile = cfopen(ifile_name,"rb");
+
+       if (ifile) {
+               int id,version,n_bitmaps;
+               int bitmap_data_size;
+               ushort *indices;
+
+               id = cfile_read_int(ifile);
+               version = cfile_read_int(ifile);
+
+               if (id != MAKE_SIG('G','O','P','D') || version != 1) {
+                       cfclose(ifile);
+                       return;
+               }
+
+               n_bitmaps = cfile_read_int(ifile);
+
+               MALLOC( indices, ushort, n_bitmaps );
+
+               for (i = 0; i < n_bitmaps; i++)
+                       indices[i] = cfile_read_short(ifile);
+
+               bitmap_data_size = cfilelength(ifile) - cftell(ifile) - DISKBITMAPHEADER_SIZE * n_bitmaps;
+               MALLOC( Bitmap_replacement_data, ubyte, bitmap_data_size );
+
+               for (i=0;i<n_bitmaps;i++) {
+                       DiskBitmapHeader bmh;
+                       grs_bitmap temp_bitmap;
+
+                       DiskBitmapHeader_read(&bmh, ifile);
+
+                       memset( &temp_bitmap, 0, sizeof(grs_bitmap) );
+
+                       temp_bitmap.bm_w = temp_bitmap.bm_rowsize = bmh.width + ((short) (bmh.wh_extra&0x0f)<<8);
+                       temp_bitmap.bm_h = bmh.height + ((short) (bmh.wh_extra&0xf0)<<4);
+                       temp_bitmap.avg_color = bmh.avg_color;
+                       temp_bitmap.bm_data = Bitmap_replacement_data + bmh.offset;
+
+                       if ( bmh.flags & BM_FLAG_TRANSPARENT ) temp_bitmap.bm_flags |= BM_FLAG_TRANSPARENT;
+                       if ( bmh.flags & BM_FLAG_SUPER_TRANSPARENT ) temp_bitmap.bm_flags |= BM_FLAG_SUPER_TRANSPARENT;
+                       if ( bmh.flags & BM_FLAG_NO_LIGHTING ) temp_bitmap.bm_flags |= BM_FLAG_NO_LIGHTING;
+                       if ( bmh.flags & BM_FLAG_RLE ) temp_bitmap.bm_flags |= BM_FLAG_RLE;
+                       if ( bmh.flags & BM_FLAG_RLE_BIG ) temp_bitmap.bm_flags |= BM_FLAG_RLE_BIG;
+
+                       GameBitmaps[indices[i]] = temp_bitmap;
+               }
+
+               cfread(Bitmap_replacement_data,1,bitmap_data_size,ifile);
+
+               d_free(indices);
+
+               cfclose(ifile);
+
+               last_palette_loaded_pig[0]= 0;  //force pig re-load
+
+               texmerge_flush();               //for re-merging with new textures
+       }
+
+       atexit(free_bitmap_replacements);
+}
+
+#define FIRST_D1_TEXTURE 722
+#define LAST_D1_STATIC_TEXTURE 1042//1342 //afterwards, we have door frames and stuff
+#define FIRST_D2_TEXTURE 1243
+
+void load_d1_bitmap_replacements()
+{
+       CFILE * d1_Piggy_fp;
+       grs_bitmap temp_bitmap;
+       DiskBitmapHeader bmh;
+       int pig_data_start, bitmap_header_start, bitmap_data_start;
+       int N_bitmaps, zsize;
+       int d1_index, d2_index;
+       ubyte colormap[256];
+       ubyte *next_bitmap; // to which address we write the next bitmap
+
+#ifndef MACINTOSH
+       d1_Piggy_fp = cfopen( "descent.pig", "rb" );
+#else
+       d1_Piggy_fp = cfopen( "Data:Descent.pig", "rb" );
+#endif  // end of ifndef/else MACINTOSH
+
+       if (!d1_Piggy_fp)
+               return; // use d2 bitmaps instead...
+
+       //first, free up data allocated for old bitmaps
+       free_bitmap_replacements();
+
+       // read d1 palette, build colormap
+       {
+               int freq[256];
+               ubyte d1_palette[256*3];
+               CFILE * palette_file = cfopen( "palette.256", "rb" );
+               Assert( palette_file );
+               Assert( cfilelength( palette_file ) == 9472 );
+               cfread( d1_palette, 256, 3, palette_file);
+               cfclose( palette_file );
+               build_colormap_good( d1_palette, colormap, freq );
+               // don't change transparencies:
+               colormap[254] = 254;
+               colormap[255] = 255;
+       }
+
+
+       if (0) //TODO: put here cfilelength(d1_Piggy_fp) == D1_PIG_SHARE
+               pig_data_start = 0;
+       else {
+               //int i;
+               pig_data_start = cfile_read_int(d1_Piggy_fp );
+               bm_read_all_d1( d1_Piggy_fp );
+               //for (i = 0; i < 1800; i++) GameBitmapXlat[i] = cfile_read_short(d1_Piggy_fp);
+       }
+       cfseek( d1_Piggy_fp, pig_data_start, SEEK_SET );
+       N_bitmaps = cfile_read_int(d1_Piggy_fp);
+       {
+               int N_sounds = cfile_read_int(d1_Piggy_fp);
+               int header_size = N_bitmaps * DISKBITMAPHEADER_D1_SIZE
+                               + N_sounds * DISKSOUNDHEADER_SIZE;
+               bitmap_header_start = pig_data_start + 2 * sizeof(int);
+               bitmap_data_start = bitmap_header_start + header_size;
+       }
+
+       MALLOC( Bitmap_replacement_data, ubyte, cfilelength(d1_Piggy_fp) - bitmap_data_start ); // too much
+       //TODO: handle case where b_r_d == 0! (have to convert textures, return, not bm_read_all_d1)
+
+       next_bitmap = Bitmap_replacement_data;
+
+       for (d1_index=1; d1_index<=N_bitmaps; d1_index++ ) {
+               // only change wall texture bitmaps
+               if (d1_index >= FIRST_D1_TEXTURE && d1_index <= LAST_D1_STATIC_TEXTURE) {
+                       d2_index = d1_index + FIRST_D2_TEXTURE - FIRST_D1_TEXTURE;
+
+                       cfseek(d1_Piggy_fp, bitmap_header_start + (d1_index-1) * DISKBITMAPHEADER_D1_SIZE, SEEK_SET);
+                       DiskBitmapHeader_d1_read(&bmh, d1_Piggy_fp);
+
+                       memset( &temp_bitmap, 0, sizeof(grs_bitmap) );
+
+                       temp_bitmap.bm_w = temp_bitmap.bm_rowsize = bmh.width + ((short) (bmh.wh_extra&0x0f)<<8);
+                       temp_bitmap.bm_h = bmh.height + ((short) (bmh.wh_extra&0xf0)<<4);
+                       temp_bitmap.avg_color = bmh.avg_color;
+
+                       //GameBitmapFlags[convert_d1_bitmap_num(d1_index)] = 0;
+
+                       if ( bmh.flags & BM_FLAG_TRANSPARENT )
+                               temp_bitmap.bm_flags |= BM_FLAG_TRANSPARENT;
+                       if ( bmh.flags & BM_FLAG_SUPER_TRANSPARENT )
+                               temp_bitmap.bm_flags |= BM_FLAG_SUPER_TRANSPARENT;
+                       if ( bmh.flags & BM_FLAG_NO_LIGHTING )
+                               temp_bitmap.bm_flags |= BM_FLAG_NO_LIGHTING;
+                       if ( bmh.flags & BM_FLAG_RLE )
+                               temp_bitmap.bm_flags |= BM_FLAG_RLE;
+                       if ( bmh.flags & BM_FLAG_RLE_BIG )
+                               temp_bitmap.bm_flags |= BM_FLAG_RLE_BIG;
+
+                       temp_bitmap.bm_data = next_bitmap;
+
+                       cfseek(d1_Piggy_fp, bitmap_data_start + bmh.offset, SEEK_SET);
+                       zsize = cfile_read_int(d1_Piggy_fp);
+                       cfseek(d1_Piggy_fp, bitmap_data_start + bmh.offset, SEEK_SET);
+                       cfread(next_bitmap, 1, zsize, d1_Piggy_fp);
+
+                       switch(cfilelength(d1_Piggy_fp)) {
+                       case D1_MAC_PIGSIZE:
+                       case D1_MAC_SHARE_PIGSIZE:
+                               rle_swap_0_255(&temp_bitmap);
+                       }
+                       rle_remap(&temp_bitmap, colormap);
+
+                       GameBitmaps[d2_index] = temp_bitmap;
+
+                       memcpy(&zsize, temp_bitmap.bm_data, 4);
+                       next_bitmap += zsize;
+               }
+       }
+
+       cfclose(d1_Piggy_fp);
+
+       last_palette_loaded_pig[0]= 0;  //force pig re-load
+
+       texmerge_flush();               //for re-merging with new textures
+
+       atexit(free_bitmap_replacements);
+}
+
 
 #ifndef FAST_FILE_IO
 /*