From b143abf90e6b058a66776d94bb29edeb125fc720 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Sat, 29 Mar 2003 22:35:00 +0000 Subject: [PATCH] rewrote endlevel stuff to reread exit model info every time --- ChangeLog | 4 + main/bm.c | 364 +++++++++++++++++++++++++----------------------- main/endlevel.c | 4 +- main/piggy.c | 8 +- main/piggy.h | 4 +- main/polyobj.c | 7 +- 6 files changed, 207 insertions(+), 184 deletions(-) diff --git a/ChangeLog b/ChangeLog index b3aff61a..48339d79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2003-03-29 Bradley Bell + * main/bm.c, main/endlevel.c, main/piggy.c, main/piggy.h, + main/polyobj.c: rewrote endlevel stuff to reread exit model info + every time + * arch/sdl/joy.c: fixed text seen for hats in control config screen diff --git a/main/bm.c b/main/bm.c index b15b6db9..2dbc0508 100644 --- a/main/bm.c +++ b/main/bm.c @@ -1,4 +1,4 @@ -/* $Id: bm.c,v 1.30 2003-03-29 02:37:17 btb Exp $ */ +/* $Id: bm.c,v 1.31 2003-03-29 22:34:59 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -152,170 +152,6 @@ int tmap_info_read_n_d1(tmap_info *ti, int n, CFILE *fp) return i; } -extern int Num_bitmap_files; -int extra_bitmap_num; - -bitmap_index exitmodel_bm_load_sub( char * filename ) -{ - bitmap_index bitmap_num; - grs_bitmap * new = &GameBitmaps[extra_bitmap_num]; - ubyte newpal[256*3]; - int iff_error; //reference parm to avoid warning message - - bitmap_num.index = 0; - - //MALLOC( new, grs_bitmap, 1 ); - iff_error = iff_read_bitmap(filename,new,BM_LINEAR,newpal); - new->bm_handle=0; - if (iff_error != IFF_NO_ERROR) { - con_printf(CON_DEBUG, "Error loading exit model bitmap <%s> - IFF error: %s\n", filename, iff_errormsg(iff_error)); - return bitmap_num; - } - - if ( iff_has_transparency ) - gr_remap_bitmap_good( new, newpal, iff_transparent_color, 254 ); - else - gr_remap_bitmap_good( new, newpal, -1, 254 ); - - new->avg_color = 0; //compute_average_pixel(new); - - bitmap_num.index = extra_bitmap_num; - - GameBitmaps[extra_bitmap_num++] = *new; - - //d_free( new ); - return bitmap_num; -} - -grs_bitmap *load_exit_model_bitmap(char *name) -{ - Assert(N_ObjBitmaps < MAX_OBJ_BITMAPS); - - { - ObjBitmaps[N_ObjBitmaps] = exitmodel_bm_load_sub(name); - - if (ObjBitmaps[N_ObjBitmaps].index == 0) - { - char *name2 = d_strdup(name); - *strrchr(name2, '.') = '\0'; - ObjBitmaps[N_ObjBitmaps] = read_extra_d1_bitmap(name2); - d_free(name2); - } - if (ObjBitmaps[N_ObjBitmaps].index == 0) - return NULL; - - if (GameBitmaps[ObjBitmaps[N_ObjBitmaps].index].bm_w!=64 || GameBitmaps[ObjBitmaps[N_ObjBitmaps].index].bm_h!=64) - Error("Bitmap <%s> is not 64x64",name); - ObjBitmapPtrs[N_ObjBitmaps] = N_ObjBitmaps; - N_ObjBitmaps++; - Assert(N_ObjBitmaps < MAX_OBJ_BITMAPS); - return &GameBitmaps[ObjBitmaps[N_ObjBitmaps-1].index]; - } -} - -void -bm_free_extra_bitmaps() -{ - int i; - - for (i = Num_bitmap_files; i < extra_bitmap_num; i++) - d_free(GameBitmaps[i].bm_data); - extra_bitmap_num = Num_bitmap_files; -} - - -#ifdef OGL -void ogl_cache_polymodel_textures(int model_num); -#endif - -int load_exit_models() -{ - CFILE *exit_hamfile; - int start_num; - - start_num = N_ObjBitmaps; - extra_bitmap_num = Num_bitmap_files; - if (!load_exit_model_bitmap("steel1.bbm") || - !load_exit_model_bitmap("rbot061.bbm") || - !load_exit_model_bitmap("rbot062.bbm") || - !load_exit_model_bitmap("steel1.bbm") || - !load_exit_model_bitmap("rbot061.bbm") || - !load_exit_model_bitmap("rbot063.bbm")) - { - Warning("Can't load exit models!\n"); - return 0; - } - -#ifndef MACINTOSH - exit_hamfile = cfopen("exit.ham","rb"); -#else - exit_hamfile = cfopen(":Data:exit.ham","rb"); -#endif - if (exit_hamfile) { - polymodel_read(&Polygon_models[exit_modelnum], exit_hamfile); - polymodel_read(&Polygon_models[destroyed_exit_modelnum], exit_hamfile); - Polygon_models[exit_modelnum].first_texture = start_num; - Polygon_models[destroyed_exit_modelnum].first_texture = start_num+3; - - polygon_model_data_read(&Polygon_models[exit_modelnum], exit_hamfile); - - polygon_model_data_read(&Polygon_models[destroyed_exit_modelnum], exit_hamfile); - - cfclose(exit_hamfile); - - } else if (cfexist("exit01.pof") && cfexist("exit01d.pof")) { - - exit_modelnum = load_polygon_model("exit01.pof", 3, start_num, NULL); - destroyed_exit_modelnum = load_polygon_model("exit01d.pof", 3, start_num + 3, NULL); - -#ifdef OGL - ogl_cache_polymodel_textures(exit_modelnum); - ogl_cache_polymodel_textures(destroyed_exit_modelnum); -#endif - } - else if (cfexist(D1_PIGFILE)) - { - int offset, offset2; - - exit_hamfile = cfopen(D1_PIGFILE, "rb"); - switch (cfilelength(exit_hamfile)) { //total hack for loading models - case D1_PIGSIZE: - offset = 91848; /* and 92582 */ - offset2 = 383390; /* and 394022 */ - break; - default: - Int3(); - case D1_SHAREWARE_10_PIGSIZE: - case D1_SHAREWARE_PIGSIZE: - Int3(); /* exit models should be in .pofs */ - case D1_OEM_PIGSIZE: - case D1_MAC_PIGSIZE: - case D1_MAC_SHARE_PIGSIZE: - Warning("Can't load exit models!\n"); - return 0; - break; - } - cfseek(exit_hamfile, offset, SEEK_SET); - polymodel_read(&Polygon_models[exit_modelnum], exit_hamfile); - polymodel_read(&Polygon_models[destroyed_exit_modelnum], exit_hamfile); - Polygon_models[exit_modelnum].first_texture = start_num; - Polygon_models[destroyed_exit_modelnum].first_texture = start_num+3; - - cfseek(exit_hamfile, offset2, SEEK_SET); - polygon_model_data_read(&Polygon_models[exit_modelnum], exit_hamfile); - polygon_model_data_read(&Polygon_models[destroyed_exit_modelnum], exit_hamfile); - - cfclose(exit_hamfile); - } else { - Warning("Can't load exit models!\n"); - return 0; - } - - atexit(bm_free_extra_bitmaps); - - return 1; -} - //----------------------------------------------------------------- // Read data from piggy. @@ -411,12 +247,9 @@ void bm_read_all(CFILE * fp) if (Piggy_hamfile_version < 3) { exit_modelnum = cfile_read_int(fp); destroyed_exit_modelnum = cfile_read_int(fp); - } else { - exit_modelnum = N_polygon_models++; - destroyed_exit_modelnum = N_polygon_models++; - Polygon_models[exit_modelnum].model_data = NULL; - Polygon_models[destroyed_exit_modelnum].model_data = NULL; } + else + exit_modelnum = destroyed_exit_modelnum = N_polygon_models; } #define D1_MAX_TEXTURES 800 @@ -573,10 +406,30 @@ void bm_read_all_d1(CFILE * fp) #define N_D2_OBJBITMAPPTRS 502 #define N_D2_WEAPON_TYPES 62 -void bm_free_extra_robots() +extern int Num_bitmap_files; +int extra_bitmap_num = 0; + +void bm_free_extra_objbitmaps() +{ + int i; + + if (!extra_bitmap_num) + extra_bitmap_num = Num_bitmap_files; + + for (i = Num_bitmap_files; i < extra_bitmap_num; i++) + { + N_ObjBitmaps--; + d_free(GameBitmaps[i].bm_data); + } + extra_bitmap_num = Num_bitmap_files; +} + +void bm_free_extra_models() { while (N_polygon_models > N_D2_POLYGON_MODELS) free_model(&Polygon_models[--N_polygon_models]); + while (N_polygon_models > exit_modelnum) + free_model(&Polygon_models[--N_polygon_models]); } //type==1 means 1.1, type==2 means 1.2 (with weapons) @@ -599,7 +452,8 @@ void bm_read_extra_robots(char *fname,int type) else version = 0; - bm_free_extra_robots(); + bm_free_extra_models(); + bm_free_extra_objbitmaps(); //read extra weapons @@ -725,3 +579,169 @@ void load_robot_replacements(char *level_name) cfclose(fp); } + + +/* + * Routines for loading exit models + * + * Used by d1 levels (including some add-ons), and by d2 shareware. + * Could potentially be used by d2 add-on levels, but only if they + * don't use "extra" robots... + */ + +// formerly exitmodel_bm_load_sub +bitmap_index read_extra_bitmap_iff( char * filename ) +{ + bitmap_index bitmap_num; + grs_bitmap * new = &GameBitmaps[extra_bitmap_num]; + ubyte newpal[256*3]; + int iff_error; //reference parm to avoid warning message + + bitmap_num.index = 0; + + //MALLOC( new, grs_bitmap, 1 ); + iff_error = iff_read_bitmap(filename,new,BM_LINEAR,newpal); + new->bm_handle=0; + if (iff_error != IFF_NO_ERROR) { + con_printf(CON_DEBUG, "Error loading exit model bitmap <%s> - IFF error: %s\n", filename, iff_errormsg(iff_error)); + return bitmap_num; + } + + if ( iff_has_transparency ) + gr_remap_bitmap_good( new, newpal, iff_transparent_color, 254 ); + else + gr_remap_bitmap_good( new, newpal, -1, 254 ); + + new->avg_color = 0; //compute_average_pixel(new); + + bitmap_num.index = extra_bitmap_num; + + GameBitmaps[extra_bitmap_num++] = *new; + + //d_free( new ); + return bitmap_num; +} + +// formerly load_exit_model_bitmap +grs_bitmap *bm_load_extra_objbitmap(char *name) +{ + Assert(N_ObjBitmaps < MAX_OBJ_BITMAPS); + + { + ObjBitmaps[N_ObjBitmaps] = read_extra_bitmap_iff(name); + + if (ObjBitmaps[N_ObjBitmaps].index == 0) + { + char *name2 = d_strdup(name); + *strrchr(name2, '.') = '\0'; + ObjBitmaps[N_ObjBitmaps] = read_extra_bitmap_d1_pig(name2); + d_free(name2); + } + if (ObjBitmaps[N_ObjBitmaps].index == 0) + return NULL; + + if (GameBitmaps[ObjBitmaps[N_ObjBitmaps].index].bm_w!=64 || GameBitmaps[ObjBitmaps[N_ObjBitmaps].index].bm_h!=64) + Error("Bitmap <%s> is not 64x64",name); + ObjBitmapPtrs[N_ObjBitmaps] = N_ObjBitmaps; + N_ObjBitmaps++; + Assert(N_ObjBitmaps < MAX_OBJ_BITMAPS); + return &GameBitmaps[ObjBitmaps[N_ObjBitmaps-1].index]; + } +} + +#ifdef OGL +void ogl_cache_polymodel_textures(int model_num); +#endif + +int load_exit_models() +{ + CFILE *exit_hamfile; + int start_num; + + bm_free_extra_models(); + bm_free_extra_objbitmaps(); + + start_num = N_ObjBitmaps; + if (!bm_load_extra_objbitmap("steel1.bbm") || + !bm_load_extra_objbitmap("rbot061.bbm") || + !bm_load_extra_objbitmap("rbot062.bbm") || + !bm_load_extra_objbitmap("steel1.bbm") || + !bm_load_extra_objbitmap("rbot061.bbm") || + !bm_load_extra_objbitmap("rbot063.bbm")) + { + Warning("Can't load exit models!\n"); + return 0; + } + +#ifndef MACINTOSH + exit_hamfile = cfopen("exit.ham","rb"); +#else + exit_hamfile = cfopen(":Data:exit.ham","rb"); +#endif + if (exit_hamfile) { + exit_modelnum = N_polygon_models++; + destroyed_exit_modelnum = N_polygon_models++; + polymodel_read(&Polygon_models[exit_modelnum], exit_hamfile); + polymodel_read(&Polygon_models[destroyed_exit_modelnum], exit_hamfile); + Polygon_models[exit_modelnum].first_texture = start_num; + Polygon_models[destroyed_exit_modelnum].first_texture = start_num+3; + + polygon_model_data_read(&Polygon_models[exit_modelnum], exit_hamfile); + + polygon_model_data_read(&Polygon_models[destroyed_exit_modelnum], exit_hamfile); + + cfclose(exit_hamfile); + + } else if (cfexist("exit01.pof") && cfexist("exit01d.pof")) { + + exit_modelnum = load_polygon_model("exit01.pof", 3, start_num, NULL); + destroyed_exit_modelnum = load_polygon_model("exit01d.pof", 3, start_num + 3, NULL); + +#ifdef OGL + ogl_cache_polymodel_textures(exit_modelnum); + ogl_cache_polymodel_textures(destroyed_exit_modelnum); +#endif + } + else if (cfexist(D1_PIGFILE)) + { + int offset, offset2; + + exit_hamfile = cfopen(D1_PIGFILE, "rb"); + switch (cfilelength(exit_hamfile)) { //total hack for loading models + case D1_PIGSIZE: + offset = 91848; /* and 92582 */ + offset2 = 383390; /* and 394022 */ + break; + default: + case D1_SHAREWARE_10_PIGSIZE: + case D1_SHAREWARE_PIGSIZE: + Int3(); /* exit models should be in .pofs */ + case D1_OEM_PIGSIZE: + case D1_MAC_PIGSIZE: + case D1_MAC_SHARE_PIGSIZE: + Warning("Can't load exit models!\n"); + return 0; + break; + } + cfseek(exit_hamfile, offset, SEEK_SET); + exit_modelnum = N_polygon_models++; + destroyed_exit_modelnum = N_polygon_models++; + polymodel_read(&Polygon_models[exit_modelnum], exit_hamfile); + polymodel_read(&Polygon_models[destroyed_exit_modelnum], exit_hamfile); + Polygon_models[exit_modelnum].first_texture = start_num; + Polygon_models[destroyed_exit_modelnum].first_texture = start_num+3; + + cfseek(exit_hamfile, offset2, SEEK_SET); + polygon_model_data_read(&Polygon_models[exit_modelnum], exit_hamfile); + polygon_model_data_read(&Polygon_models[destroyed_exit_modelnum], exit_hamfile); + + cfclose(exit_hamfile); + } else { + Warning("Can't load exit models!\n"); + return 0; + } + + atexit(bm_free_extra_objbitmaps); + + return 1; +} diff --git a/main/endlevel.c b/main/endlevel.c index 82ec24fa..eacecf50 100644 --- a/main/endlevel.c +++ b/main/endlevel.c @@ -17,7 +17,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef RCS -static char rcsid[] = "$Id: endlevel.c,v 1.12 2003-03-25 08:19:12 btb Exp $"; +static char rcsid[] = "$Id: endlevel.c,v 1.13 2003-03-29 22:34:59 btb Exp $"; #endif //#define SLEW_ON 1 @@ -303,7 +303,7 @@ void start_endlevel_sequence() { int i; int movie_played = MOVIE_NOT_PLAYED; - static int inited = 0; + int inited = 0; if (!inited) { if (Piggy_hamfile_version >= 3) diff --git a/main/piggy.c b/main/piggy.c index f65b66ee..fe21e4d8 100644 --- a/main/piggy.c +++ b/main/piggy.c @@ -1,4 +1,4 @@ -/* $Id: piggy.c,v 1.30 2003-03-27 01:26:47 btb Exp $ */ +/* $Id: piggy.c,v 1.31 2003-03-29 22:35:00 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.30 2003-03-27 01:26:47 btb Exp $"; +static char rcsid[] = "$Id: piggy.c,v 1.31 2003-03-29 22:35:00 btb Exp $"; #endif @@ -2371,9 +2371,9 @@ extern int extra_bitmap_num; /* * Find and load the named bitmap from descent.pig - * similar to exitmodel_bm_load_sub + * similar to read_extra_bitmap_iff */ -bitmap_index read_extra_d1_bitmap(char *name) +bitmap_index read_extra_bitmap_d1_pig(char *name) { bitmap_index bitmap_num; grs_bitmap * new = &GameBitmaps[extra_bitmap_num]; diff --git a/main/piggy.h b/main/piggy.h index 7802e8e1..efa3a0e0 100644 --- a/main/piggy.h +++ b/main/piggy.h @@ -1,4 +1,4 @@ -/* $Id: piggy.h,v 1.15 2003-03-25 10:17:05 btb Exp $ */ +/* $Id: piggy.h,v 1.16 2003-03-29 22:35:00 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -165,6 +165,6 @@ void DiskBitmapHeader_d1_read(DiskBitmapHeader *dbh, CFILE *fp); /* * Find and load the named bitmap from descent.pig */ -bitmap_index read_extra_d1_bitmap(char *name); +bitmap_index read_extra_bitmap_d1_pig(char *name); #endif //_PIGGY_H diff --git a/main/polyobj.c b/main/polyobj.c index 97c7a88e..8e11e787 100644 --- a/main/polyobj.c +++ b/main/polyobj.c @@ -1,4 +1,4 @@ -/* $Id: polyobj.c,v 1.13 2003-03-23 23:34:38 btb Exp $ */ +/* $Id: polyobj.c,v 1.14 2003-03-29 22:35:00 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 -static char rcsid[] = "$Id: polyobj.c,v 1.13 2003-03-23 23:34:38 btb Exp $"; +static char rcsid[] = "$Id: polyobj.c,v 1.14 2003-03-29 22:35:00 btb Exp $"; #endif #include @@ -580,8 +580,7 @@ int read_model_guns(char *filename,vms_vector *gun_points, vms_vector *gun_dirs, //free up a model, getting rid of all its memory void free_model(polymodel *po) { - if (po->model_data) - d_free(po->model_data); + d_free(po->model_data); } grs_bitmap *texture_list[MAX_POLYOBJ_TEXTURES]; -- 2.39.2