From cede90c2fb3a026b152ecef025359891993b0bc2 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 6 Oct 2013 16:20:00 +0000 Subject: [PATCH] Restructure piggy.c for merging --- d1x-rebirth/main/piggy.c | 56 ++++++++++++-------- d2x-rebirth/main/piggy.c | 112 ++++++++++++++++++++------------------- 2 files changed, 90 insertions(+), 78 deletions(-) diff --git a/d1x-rebirth/main/piggy.c b/d1x-rebirth/main/piggy.c index 488fc8601..447886650 100644 --- a/d1x-rebirth/main/piggy.c +++ b/d1x-rebirth/main/piggy.c @@ -45,12 +45,13 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "newmenu.h" #include "custom.h" +#define DEFAULT_PIGFILE_REGISTERED "descent.pig" + + #ifdef EDITOR static int piggy_is_substitutable_bitmap( char * name, char * subst_name ); #endif -//#define NO_DUMP_SOUNDS 1 //if set, dump bitmaps but not sounds - ubyte *BitmapBits = NULL; ubyte *SoundBits = NULL; @@ -83,13 +84,21 @@ ubyte * Piggy_bitmap_cache_data = NULL; /*static*/ ubyte GameBitmapFlags[MAX_BITMAP_FILES]; ushort GameBitmapXlat[MAX_BITMAP_FILES]; -#define DEFAULT_PIGFILE_REGISTERED "descent.pig" - #define PIGGY_BUFFER_SIZE (2048*1024) #define PIGGY_SMALL_BUFFER_SIZE (1400*1024) // size of buffer when GameArg.SysLowMem is set int piggy_page_flushed = 0; +PHYSFS_file * Piggy_fp = NULL; + +ubyte bogus_data[64*64]; +ubyte bogus_bitmap_initialized=0; +digi_sound bogus_sound; +grs_bitmap bogus_bitmap; +int MacPig = 0; // using the Macintosh pigfile? +int PCSharePig = 0; // using PC Shareware pigfile? +static int SoundCompressed[ MAX_SOUND_FILES ]; + typedef struct DiskBitmapHeader { char name[8]; ubyte dflags; @@ -132,8 +141,6 @@ static void DiskSoundHeader_read(DiskSoundHeader *dsh, PHYSFS_file *fp) dsh->offset = PHYSFSX_readInt(fp); } -static int SoundCompressed[ MAX_SOUND_FILES ]; - void swap_0_255(grs_bitmap *bmp) { int i; @@ -236,8 +243,6 @@ int piggy_find_sound( char * name ) return i; } -PHYSFS_file * Piggy_fp = NULL; - static void piggy_close_file() { if ( Piggy_fp ) { @@ -246,13 +251,6 @@ static void piggy_close_file() } } -ubyte bogus_data[64*64]; -grs_bitmap bogus_bitmap; -ubyte bogus_bitmap_initialized=0; -digi_sound bogus_sound; -int MacPig = 0; // using the Macintosh pigfile? -int PCSharePig = 0; // using PC Shareware pigfile? - int properties_init() { int sbytes = 0; @@ -601,8 +599,7 @@ void piggy_bitmap_page_in( bitmap_index bitmap ) gr_set_bitmap_data (bmp, &Piggy_bitmap_cache_data [Piggy_bitmap_cache_next]); if ( bmp->bm_flags & BM_FLAG_RLE ) { - int zsize = 0; - zsize = PHYSFSX_readInt(Piggy_fp); + int zsize = PHYSFSX_readInt(Piggy_fp); // GET JOHN NOW IF YOU GET THIS ASSERT!!! Assert( Piggy_bitmap_cache_next+zsize < Piggy_bitmap_cache_size ); @@ -921,7 +918,7 @@ void piggy_close() } #ifdef EDITOR -static int piggy_does_bitmap_exist_slow( char * name ) +static int piggy_does_bitmap_exist_slow(const char * name ) { int i; @@ -933,13 +930,26 @@ static int piggy_does_bitmap_exist_slow( char * name ) } -#define NUM_GAUGE_BITMAPS 14 -static const char gauge_bitmap_names[NUM_GAUGE_BITMAPS][9] = { "gauge01", "gauge02", "gauge06", "targ01", "targ02", "targ03", "targ04", "targ05", "targ06", "gauge18", "targ01pc", "targ02pc", "targ03pc", "gaug18pc" }; +static const char gauge_bitmap_names[][9] = { + "gauge01", + "gauge02", + "gauge06", + "targ01", + "targ02", + "targ03", + "targ04", + "targ05", + "targ06", + "gauge18", + "targ01pc", + "targ02pc", + "targ03pc", + "gaug18pc" +}; -static int piggy_is_gauge_bitmap( char * base_name ) +static int piggy_is_gauge_bitmap(const char * base_name ) { - int i; - for (i=0; ioffset = PHYSFSX_readInt(fp); } -#ifdef EDITOR -static void piggy_write_pigfile(const char *filename); -static void write_int(int i,PHYSFS_file *file); -#endif - void swap_0_255(grs_bitmap *bmp) { int i; @@ -269,11 +280,11 @@ bitmap_index piggy_find_bitmap( char * name ) { bitmap_index bmp; int i; - char *t; bmp.index = 0; size_t namelen; + char *t; if ((t=strchr(name,'#'))!=NULL) namelen = t - name; else @@ -314,10 +325,6 @@ int piggy_find_sound( char * name ) return i; } -PHYSFS_file * Piggy_fp = NULL; - -char Current_pigfile[FILENAME_LEN] = ""; - static void piggy_close_file() { if ( Piggy_fp ) { @@ -327,11 +334,6 @@ static void piggy_close_file() } } -int Pigfile_initialized=0; - -#define PIGFILE_ID MAKE_SIG('G','I','P','P') //PPIG -#define PIGFILE_VERSION 2 - //initialize a pigfile, reading headers //returns the size of all the bitmap data void piggy_init_pigfile(const char *filename) @@ -426,10 +428,6 @@ void piggy_init_pigfile(const char *filename) Pigfile_initialized=1; } -#define MAX_BITMAPS_PER_BRUSH 30 - -ubyte *Bitmap_replacement_data = NULL; - //reads in a new pigfile (for new palette) //returns the size of all the bitmap data void piggy_new_pigfile(char *pigname) @@ -673,10 +671,6 @@ void piggy_new_pigfile(char *pigname) } -ubyte bogus_data[64*64]; -ubyte bogus_bitmap_initialized=0; -digi_sound bogus_sound; - #define HAMFILE_ID MAKE_SIG('!','M','A','H') //HAM! #define HAMFILE_VERSION 3 //version 1 -> 2: save marker_model_num @@ -909,7 +903,7 @@ int properties_init(void) return (ham_ok && snd_ok); //read ok } -int piggy_is_needed(int soundnum) +static int piggy_is_needed(int soundnum) { int i; @@ -994,8 +988,8 @@ void piggy_bitmap_page_in( bitmap_index bitmap ) gr_set_bitmap_flags (bmp, GameBitmapFlags[i]); if ( bmp->bm_flags & BM_FLAG_RLE ) { - int zsize = 0, pigsize = PHYSFS_fileLength(Piggy_fp); - zsize = PHYSFSX_readInt(Piggy_fp); + int zsize = PHYSFSX_readInt(Piggy_fp); + int pigsize = PHYSFS_fileLength(Piggy_fp); // GET JOHN NOW IF YOU GET THIS ASSERT!!! //Assert( Piggy_bitmap_cache_next+zsize < Piggy_bitmap_cache_size ); @@ -1361,7 +1355,7 @@ void piggy_close() } #ifdef EDITOR -static int piggy_does_bitmap_exist_slow( char * name ) +static int piggy_does_bitmap_exist_slow(const char * name ) { int i; @@ -1373,27 +1367,35 @@ static int piggy_does_bitmap_exist_slow( char * name ) } -#define NUM_GAUGE_BITMAPS 23 -const char *const gauge_bitmap_names[NUM_GAUGE_BITMAPS] = { - "gauge01", "gauge01b", - "gauge02", "gauge02b", - "gauge06", "gauge06b", - "targ01", "targ01b", - "targ02", "targ02b", - "targ03", "targ03b", - "targ04", "targ04b", - "targ05", "targ05b", - "targ06", "targ06b", - "gauge18", "gauge18b", - "gauss1", "helix1", +static const char gauge_bitmap_names[][9] = { + "gauge01", + "gauge02", + "gauge06", + "targ01", + "targ02", + "targ03", + "targ04", + "targ05", + "targ06", + "gauge18", + "gauge01b", + "gauge02b", + "gauge06b", + "targ01b", + "targ02b", + "targ03b", + "targ04b", + "targ05b", + "targ06b", + "gauge18b", + "gauss1", + "helix1", "phoenix1" }; - -static int piggy_is_gauge_bitmap( char * base_name ) +static int piggy_is_gauge_bitmap(const char * base_name ) { - int i; - for (i=0; i= new_size ); - bitmap->bm_data = d_realloc(bitmap->bm_data, new_size); + bitmap->bm_data = (ubyte *) d_realloc(bitmap->bm_data, new_size); Assert(bitmap->bm_data); } } @@ -1602,7 +1604,7 @@ static void bitmap_read_d1( grs_bitmap *bitmap, /* read into this bitmap */ * "Textures" looks up a d2 bitmap index given a d2 tmap_num. * "d1_tmap_nums" looks up a d1 tmap_num given a d1 bitmap. "-1" means "None". */ -short *d1_tmap_nums = NULL; +static short *d1_tmap_nums = NULL; static void free_d1_tmap_nums() { if (d1_tmap_nums) {