From 0837b91f53dc5361682ff0bc2ac9ae378ec7080f Mon Sep 17 00:00:00 2001 From: kreatordxx <> Date: Sun, 13 Jan 2008 00:58:49 +0000 Subject: [PATCH] complete bigendian support, without touching network code --- 2d/font.c | 75 +++---- 2d/pcx.c | 41 +++- 3d/interp.c | 198 +++++++++++++++---- CHANGELOG.txt | 1 + cfile/cfile.c | 135 +++++++++++++ include/cfile.h | 27 +++ include/pstypes.h | 14 ++ main/bm.c | 153 +++++++++----- main/cntrlcen.c | 22 +++ main/cntrlcen.h | 22 ++- main/custom.c | 167 ++++++++-------- main/custom.h | 6 - main/effects.c | 35 ++++ main/effects.h | 11 +- main/fuelcen.c | 16 +- main/fuelcen.h | 17 +- main/gamemine.c | 90 +++++---- main/gamesave.c | 492 +++++++++++++++------------------------------- main/loadrl2.c | 291 ++++++++++----------------- main/newdemo.c | 52 +++-- main/piggy.c | 72 ++++++- main/piggy.h | 15 ++ main/playsave.c | 19 +- main/polyobj.c | 57 +++--- main/powerup.c | 18 ++ main/powerup.h | 9 + main/robot.c | 79 ++++++++ main/robot.h | 15 ++ main/scores.c | 50 ++++- main/switch.c | 20 ++ main/switch.h | 9 + main/vclip.c | 22 +++ main/vclip.h | 11 +- main/wall.c | 99 ++++++++++ main/wall.h | 71 +++++++ main/weapon.c | 52 +++++ main/weapon.h | 5 + 37 files changed, 1632 insertions(+), 856 deletions(-) diff --git a/2d/font.c b/2d/font.c index 012cac79e..8138b3ab8 100644 --- a/2d/font.c +++ b/2d/font.c @@ -1244,7 +1244,7 @@ grs_font * gr_init_font( char * fontname ) unsigned char * ptr; int nchars; CFILE *fontfile; - u_int32_t file_id; + char file_id[4]; int32_t datasize; //size up to (but not including) palette fontfile = cfopen(fontname, "rb"); @@ -1252,40 +1252,43 @@ grs_font * gr_init_font( char * fontname ) if (!fontfile) Error( "Can't open font file %s", fontname ); - cfread(&file_id,sizeof(file_id),1,fontfile); - file_id=INTEL_INT(file_id); - cfread(&datasize,sizeof(datasize),1,fontfile); - datasize=INTEL_INT(datasize); - - if (file_id != 0x4e465350) /* 'NFSP' */ - Error( "File %s is not a font file", fontname ); + cfread(file_id, 4, 1, fontfile); + if ( !strncmp( file_id, "NFSP", 4 ) ) { + mprintf((0, "File %s is not a font file\n", fontname )); + return NULL; + } + + datasize = cfile_read_int(fontfile); font = (old_grs_font *) malloc(datasize); newfont = (grs_font *) malloc(sizeof(grs_font)); newfont->oldfont=font; cfread(font,1,datasize,fontfile); - - newfont->ft_flags=INTEL_INT(font->ft_flags); + + newfont->ft_flags=INTEL_SHORT(font->ft_flags); newfont->ft_w=INTEL_SHORT(font->ft_w); newfont->ft_h=INTEL_SHORT(font->ft_h); newfont->ft_baseline=INTEL_SHORT(font->ft_baseline); newfont->ft_maxchar=font->ft_maxchar; newfont->ft_minchar=font->ft_minchar; newfont->ft_bytewidth=INTEL_SHORT(font->ft_bytewidth); - + nchars = newfont->ft_maxchar-newfont->ft_minchar+1; if (newfont->ft_flags & FT_PROPORTIONAL) { newfont->ft_widths = (short *) (INTEL_INT(font->ft_widths) + ((ubyte *) font)); - + + for (i = 0; i < nchars; i++) + newfont->ft_widths[i] = INTEL_SHORT(newfont->ft_widths[i]); + newfont->ft_data = (INTEL_INT(font->ft_data)) + ((ubyte *) font); - + newfont->ft_chars = (unsigned char **)malloc( nchars * sizeof(unsigned char *)); - + ptr = newfont->ft_data; - + for (i=0; i< nchars; i++ ) { newfont->ft_chars[i] = ptr; if (newfont->ft_flags & FT_COLOR) @@ -1293,59 +1296,59 @@ grs_font * gr_init_font( char * fontname ) else ptr += BITS_TO_BYTES(newfont->ft_widths[i]) * newfont->ft_h; } - + } else { - + newfont->ft_data = ((unsigned char *) font) + sizeof(*font); - + newfont->ft_chars = NULL; newfont->ft_widths = NULL; - + ptr = newfont->ft_data + (nchars * newfont->ft_w * newfont->ft_h); } - + if (newfont->ft_flags & FT_KERNED) newfont->ft_kerndata = INTEL_INT(font->ft_kerndata) + ((ubyte *) font); - - + + if (newfont->ft_flags & FT_COLOR) { //remap palette ubyte palette[256*3]; ubyte colormap[256]; int freq[256]; - + cfread(palette,3,256,fontfile); //read the palette - + build_colormap_good( (ubyte *)&palette, colormap, freq ); - + colormap[255] = 255; - + decode_data_asm(newfont->ft_data, ptr-newfont->ft_data, colormap, freq ); } - + cfclose(fontfile); - -// memcpy(newfont,font,(ubyte*)&newfont->oldfont-(ubyte*)newfont);//fill in newfont data from oldfont struct -// mprintf((0,"%i %i %i\n",sizeof(grs_font),sizeof(old_grs_font),(ubyte*)&newfont->oldfont-(ubyte*)newfont)); - + + // memcpy(newfont,font,(ubyte*)&newfont->oldfont-(ubyte*)newfont);//fill in newfont data from oldfont struct + // mprintf((0,"%i %i %i\n",sizeof(grs_font),sizeof(old_grs_font),(ubyte*)&newfont->oldfont-(ubyte*)newfont)); + //set curcanv vars - + FONT = newfont; FG_COLOR = 0; BG_COLOR = 0; - + { int x,y,aw; char tests[]="abcdefghij1234.A"; gr_get_string_size(tests,&x,&y,&aw); newfont->ft_aw=x/(float)strlen(tests); } - + #ifdef OGL ogl_init_font(newfont); #endif - + return newfont; - + } diff --git a/2d/pcx.c b/2d/pcx.c index 0cbb6f732..122eb686c 100644 --- a/2d/pcx.c +++ b/2d/pcx.c @@ -90,6 +90,37 @@ typedef struct { } PCXHeader; +#ifdef FAST_FILE_IO +#define PCXHeader_read_n(ph, n, fp) cfread(ph, sizeof(PCXHeader), n, fp) +#else +/* + * reads n PCXHeader structs from a CFILE + */ +int PCXHeader_read_n(PCXHeader *ph, int n, CFILE *fp) +{ + int i; + + for (i = 0; i < n; i++) { + ph->Manufacturer = cfile_read_byte(fp); + ph->Version = cfile_read_byte(fp); + ph->Encoding = cfile_read_byte(fp); + ph->BitsPerPixel = cfile_read_byte(fp); + ph->Xmin = cfile_read_short(fp); + ph->Ymin = cfile_read_short(fp); + ph->Xmax = cfile_read_short(fp); + ph->Ymax = cfile_read_short(fp); + ph->Hdpi = cfile_read_short(fp); + ph->Vdpi = cfile_read_short(fp); + cfread(&ph->ColorMap, 16*3, 1, fp); + ph->Reserved = cfile_read_byte(fp); + ph->Nplanes = cfile_read_byte(fp); + ph->BytesPerLine = cfile_read_short(fp); + cfread(&ph->filler, 60, 1, fp); + } + return i; +} +#endif + int pcx_read_bitmap( char * filename, grs_bitmap * bmp,int bitmap_type ,ubyte * palette ) { PCXHeader header; @@ -102,11 +133,11 @@ int pcx_read_bitmap( char * filename, grs_bitmap * bmp,int bitmap_type ,ubyte * return PCX_ERROR_OPENING; // read 128 char PCX header - if (cfread( &header, sizeof(PCXHeader), 1, PCXfile )!=1) { + if (PCXHeader_read_n( &header, 1, PCXfile )!=1) { cfclose( PCXfile ); return PCX_ERROR_NO_HEADER; } - + // Is it a 256 color PCX file? if ((header.Manufacturer != 10)||(header.Encoding != 1)||(header.Nplanes != 1)||(header.BitsPerPixel != 8)||(header.Version != 5)) { cfclose( PCXfile ); @@ -206,9 +237,9 @@ int pcx_write_bitmap( char * filename, grs_bitmap * bmp, ubyte * palette ) header.Nplanes = 1; header.BitsPerPixel = 8; header.Version = 5; - header.Xmax = bmp->bm_w-1; - header.Ymax = bmp->bm_h-1; - header.BytesPerLine = bmp->bm_w; + header.Xmax = (ushort)(bmp->bm_w-1); + header.Ymax = (ushort)(bmp->bm_h-1); + header.BytesPerLine = (ushort)bmp->bm_w; PCXfile = fopen( filename , "wb" ); if ( !PCXfile ) diff --git a/3d/interp.c b/3d/interp.c index fcada4ce0..c6c8dc458 100644 --- a/3d/interp.c +++ b/3d/interp.c @@ -90,6 +90,7 @@ void g3_set_interp_points(g3s_point *pointlist) #define w(p) (*((short *) (p))) #define wp(p) ((short *) (p)) +#define fp(p) ((fix *) (p)) #define vp(p) ((vms_vector *) (p)) void rotate_point_list(g3s_point *dest,vms_vector *src,int n) @@ -525,6 +526,131 @@ void g3_init_polygon_model(void *model_ptr) init_model_sub((ubyte *) model_ptr); } +#ifdef WORDS_BIGENDIAN +void short_swap(short *s) +{ + *s = SWAPSHORT(*s); +} + +void fix_swap(fix *f) +{ + *f = (fix)SWAPINT((int)*f); +} + +void vms_vector_swap(vms_vector *v) +{ + fix_swap(fp(&v->x)); + fix_swap(fp(&v->y)); + fix_swap(fp(&v->z)); +} + +void fixang_swap(fixang *f) +{ + *f = (fixang)SWAPSHORT((short)*f); +} + +void vms_angvec_swap(vms_angvec *v) +{ + fixang_swap(&v->p); + fixang_swap(&v->b); + fixang_swap(&v->h); +} + +void swap_polygon_model_data(ubyte *data) +{ + int i; + short n; + g3s_uvl *uvl_val; + ubyte *p = data; + + short_swap(wp(p)); + + while (w(p) != OP_EOF) { + switch (w(p)) { + case OP_DEFPOINTS: + short_swap(wp(p + 2)); + n = w(p+2); + for (i = 0; i < n; i++) + vms_vector_swap(vp((p + 4) + (i * sizeof(vms_vector)))); + p += n*sizeof(struct vms_vector) + 4; + break; + + case OP_DEFP_START: + short_swap(wp(p + 2)); + short_swap(wp(p + 4)); + n = w(p+2); + for (i = 0; i < n; i++) + vms_vector_swap(vp((p + 8) + (i * sizeof(vms_vector)))); + p += n*sizeof(struct vms_vector) + 8; + break; + + case OP_FLATPOLY: + short_swap(wp(p+2)); + n = w(p+2); + vms_vector_swap(vp(p + 4)); + vms_vector_swap(vp(p + 16)); + short_swap(wp(p+28)); + for (i=0; i < n; i++) + short_swap(wp(p + 30 + (i * 2))); + p += 30 + ((n&~1)+1)*2; + break; + + case OP_TMAPPOLY: + short_swap(wp(p+2)); + n = w(p+2); + vms_vector_swap(vp(p + 4)); + vms_vector_swap(vp(p + 16)); + for (i=0;iu); + fix_swap(&uvl_val->v); + } + short_swap(wp(p+28)); + for (i=0;ix = cfile_read_fix(file); + v->y = cfile_read_fix(file); + v->z = cfile_read_fix(file); +} + +void cfile_read_angvec(vms_angvec *v, CFILE *file) +{ + v->p = cfile_read_fixang(file); + v->b = cfile_read_fixang(file); + v->h = cfile_read_fixang(file); +} + +void cfile_read_matrix(vms_matrix *m,CFILE *file) +{ + cfile_read_vector(&m->rvec,file); + cfile_read_vector(&m->uvec,file); + cfile_read_vector(&m->fvec,file); +} +void cfile_read_string(char *buf, int n, CFILE *file) +{ + char c; + + do { + c = (char)cfile_read_byte(file); + if (n > 0) + { + *buf++ = c; + n--; + } + } while (c != 0); +} + + +#if 0 +// equivalent write functions of above read functions follow + +int cfile_write_int(int i, CFILE *file) +{ + i = INTEL_INT(i); + return cfwrite(&i, sizeof(i), 1, file); +} + + +int cfile_write_short(short s, CFILE *file) +{ + s = INTEL_SHORT(s); + return cfwrite(&s, sizeof(s), 1, file); +} + + +int cfile_write_byte(sbyte b, CFILE *file) +{ + return cfwrite(&b, sizeof(b), 1, file); +} + + +int cfile_write_string(char *buf, CFILE *file) +{ + int len; + + if ((!buf) || (buf && !buf[0])) + return cfile_write_byte(0, file); + + len = strlen(buf); + if (!cfwrite(buf, len, 1, file)) + return 0; + + return cfile_write_byte(0, file); // write out NULL termination +} +#endif + diff --git a/include/cfile.h b/include/cfile.h index cea9234c5..6feb08478 100644 --- a/include/cfile.h +++ b/include/cfile.h @@ -70,6 +70,9 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define _CFILE_H #include +#include "pstypes.h" +#include "maths.h" +#include "vecmat.h" typedef struct CFILE { FILE *file; @@ -100,4 +103,28 @@ void cfile_use_alternate_hogdir( char * path ); extern char AltHogDir[]; extern char AltHogdir_initialized; +// prototypes for reading basic types from cfile +int cfile_read_int(CFILE *file); +short cfile_read_short(CFILE *file); +sbyte cfile_read_byte(CFILE *file); +fix cfile_read_fix(CFILE *file); +fixang cfile_read_fixang(CFILE *file); +void cfile_read_vector(vms_vector *v, CFILE *file); +void cfile_read_angvec(vms_angvec *v, CFILE *file); +void cfile_read_matrix(vms_matrix *v, CFILE *file); + +// Reads variable length, null-termined string. Will only read up +// to n characters. +void cfile_read_string(char *buf, int n, CFILE *file); + +#if 0 // unused +// functions for writing cfiles +int cfile_write_int(int i, CFILE *file); +int cfile_write_short(short s, CFILE *file); +int cfile_write_byte(sbyte u, CFILE *file); + +// writes variable length, null-termined string. +int cfile_write_string(char *buf, CFILE *file); +#endif + #endif diff --git a/include/pstypes.h b/include/pstypes.h index 61f3ba7c4..3004fca6b 100644 --- a/include/pstypes.h +++ b/include/pstypes.h @@ -125,6 +125,20 @@ typedef ubyte bool; #define _dos_getvect(int) NULL #endif +// the following stuff has nothing to do with types but needed everywhere, +// and since this file is included everywhere, it's here. +#if defined(__i386__) || defined(__ia64__) || defined(WIN32) || \ +(defined(__alpha__) || defined(__alpha)) || \ +defined(__arm__) || defined(ARM) || \ +(defined(__mips__) && defined(__MIPSEL__)) || \ +defined(__SYMBIAN32__) || \ +defined(__x86_64__) || \ +defined(__LITTLE_ENDIAN__) // from physfs_internal.h +//# define WORDS_BIGENDIAN 0 +#else +# define WORDS_BIGENDIAN 1 +#endif + #ifdef __GNUC__ # define __pack__ __attribute__((packed)) #elif defined(_MSC_VER) diff --git a/main/bm.c b/main/bm.c index 0eb13d5e1..9eb50b5b1 100644 --- a/main/bm.c +++ b/main/bm.c @@ -122,6 +122,44 @@ bitmap_index ObjBitmaps[MAX_OBJ_BITMAPS]; ushort ObjBitmapPtrs[MAX_OBJ_BITMAPS]; // These point back into ObjBitmaps, since some are used twice. #ifndef SHAREWARE +#ifdef FAST_FILE_IO +#define tmap_info_read_n(ti, n, fp) cfread(ti, TMAP_INFO_SIZE, n, fp) +#else +/* + * reads n tmap_info structs from a CFILE + */ +int tmap_info_read_n(tmap_info *ti, int n, CFILE *fp) +{ + int i; + + for (i = 0; i < n; i++) { + cfread(TmapInfo[i].filename, 13, 1, fp); + ti[i].flags = cfile_read_byte(fp); + ti[i].lighting = cfile_read_fix(fp); + ti[i].damage = cfile_read_fix(fp); + ti[i].eclip_num = cfile_read_int(fp); + } + return i; +} +#endif + +int player_ship_read(player_ship *ps, CFILE *fp) +{ + int i; + ps->model_num = cfile_read_int(fp); + ps->expl_vclip_num = cfile_read_int(fp); + ps->mass = cfile_read_fix(fp); + ps->drag = cfile_read_fix(fp); + ps->max_thrust = cfile_read_fix(fp); + ps->reverse_thrust = cfile_read_fix(fp); + ps->brakes = cfile_read_fix(fp); + ps->wiggle = cfile_read_fix(fp); + ps->max_rotthrust = cfile_read_fix(fp); + for (i = 0; i < N_PLAYER_GUNS; i++) + cfile_read_vector(&ps->gun_points[i], fp); + return i; +} + //----------------------------------------------------------------- // Initializes all bitmaps from BITMAPS.TBL file. int bm_init() @@ -136,70 +174,79 @@ int bm_init() void bm_read_all(CFILE * fp) { int i; - - cfread( &NumTextures, sizeof(int), 1, fp ); - cfread( Textures, sizeof(bitmap_index), MAX_TEXTURES, fp ); - cfread( TmapInfo, sizeof(tmap_info), MAX_TEXTURES, fp ); + + // bitmap_index is a short + + NumTextures = cfile_read_int(fp); + bitmap_index_read_n(Textures, MAX_TEXTURES, fp ); + tmap_info_read_n(TmapInfo, MAX_TEXTURES, fp); cfread( Sounds, sizeof(ubyte), MAX_SOUNDS, fp ); cfread( AltSounds, sizeof(ubyte), MAX_SOUNDS, fp ); - - cfread( &Num_vclips, sizeof(int), 1, fp ); - cfread( Vclip, sizeof(vclip), VCLIP_MAXNUM, fp ); - - cfread( &Num_effects, sizeof(int), 1, fp ); - cfread( Effects, sizeof(eclip), MAX_EFFECTS, fp ); - - cfread( &Num_wall_anims, sizeof(int), 1, fp ); - cfread( WallAnims, sizeof(wclip), MAX_WALL_ANIMS, fp ); - - cfread( &N_robot_types, sizeof(int), 1, fp ); - cfread( Robot_info, sizeof(robot_info), MAX_ROBOT_TYPES, fp ); - - cfread( &N_robot_joints, sizeof(int), 1, fp ); - cfread( Robot_joints, sizeof(jointpos), MAX_ROBOT_JOINTS, fp ); - - cfread( &N_weapon_types, sizeof(int), 1, fp ); - cfread( Weapon_info, sizeof(weapon_info), MAX_WEAPON_TYPES, fp ); - - cfread( &N_powerup_types, sizeof(int), 1, fp ); - cfread( Powerup_info, sizeof(powerup_type_info), MAX_POWERUP_TYPES, fp ); - cfread( &N_polygon_models, sizeof(int), 1, fp ); + Num_vclips = cfile_read_int(fp); + vclip_read_n(Vclip, VCLIP_MAXNUM, fp); + + Num_effects = cfile_read_int(fp); + eclip_read_n(Effects, MAX_EFFECTS, fp); + + Num_wall_anims = cfile_read_int(fp); + wclip_read_n(WallAnims, MAX_WALL_ANIMS, fp); + + N_robot_types = cfile_read_int(fp); + robot_info_read_n(Robot_info, MAX_ROBOT_TYPES, fp); + + N_robot_joints = cfile_read_int(fp); + jointpos_read_n(Robot_joints, MAX_ROBOT_JOINTS, fp); + + N_weapon_types = cfile_read_int(fp); + weapon_info_read_n(Weapon_info, MAX_WEAPON_TYPES, fp); + + N_powerup_types = cfile_read_int(fp); + powerup_type_info_read_n(Powerup_info, MAX_POWERUP_TYPES, fp); + + N_polygon_models = cfile_read_int(fp); polymodel_read_n(Polygon_models, N_polygon_models, fp); for (i=0; i 0 && num_bitmaps < cfilelength(f)) { // >=v1.4 pig? cfseek(f, num_bitmaps, SEEK_SET); data_ofs = num_bitmaps + 8; - num_bitmaps = read_int(f); - num_sounds = read_int(f); + num_bitmaps = cfile_read_int(f); + num_sounds = cfile_read_int(f); } else return -1; // invalid pig file if ((unsigned int)num_bitmaps >= MAX_BITMAP_FILES || @@ -168,10 +168,10 @@ int load_pog(CFILE *f, int pog_sig, int pog_ver, int *num_custom, struct custom_ int *d2tmap = NULL; CFILE *f2 = NULL; if ((f2 = cfopen("d2tmap.bin", "rb"))) { - N_d2tmap = read_int(f2); + N_d2tmap = cfile_read_int(f2); if ((d2tmap = malloc(N_d2tmap * sizeof(d2tmap[0])))) for (i = 0; i < N_d2tmap; i++) - d2tmap[i] = read_short(f2); + d2tmap[i] = cfile_read_short(f2); cfclose(f2); } #endif @@ -181,14 +181,14 @@ int load_pog(CFILE *f, int pog_sig, int pog_ver, int *num_custom, struct custom_ no_repl = 1; else if (pog_sig != 0x474f5044 || pog_ver != 1) /* DPOG */ return -1; // no pig2/pog file/unknown version - num_bitmaps = read_int(f); + num_bitmaps = cfile_read_int(f); if (!(*ci = cip = malloc(num_bitmaps * sizeof(struct custom_info)))) return -1; // out of memory data_ofs = 12 + num_bitmaps * sizeof(DiskBitmapHeader2); if (!no_repl) { i = num_bitmaps; while (i--) - (cip++)->repl_idx = read_short(f); + (cip++)->repl_idx = cfile_read_short(f); cip = *ci; data_ofs += num_bitmaps * 2; } @@ -234,8 +234,8 @@ int load_pigpog(const char *pogname) { if (!(f = cfopen((char *)pogname, "rb"))) return -1; // pog file doesn't exist - i = read_int(f); - x = read_int(f); + i = cfile_read_int(f); + x = cfile_read_int(f); if (load_pog(f, i, x, &num_custom, &custom_info) && load_pig1(f, i, x, &num_custom, &custom_info)) goto err; // unknown format/read error @@ -246,7 +246,7 @@ int load_pigpog(const char *pogname) { if ((x = cip->repl_idx) >= 0) { cfseek( f, cip->offset, SEEK_SET ); if ( cip->flags & BM_FLAG_RLE ) - j = read_int(f); + j = cfile_read_int(f); else j = cip->width * cip->height; if (!(p = malloc(j))) @@ -328,87 +328,84 @@ int read_d2_robot_info(CFILE *fp, robot_info *ri) { int j, k; - ri->model_num = read_int(fp); - for (j = 0; j < MAX_GUNS; j++) { - ri->gun_points[j].x = read_fix(fp); - ri->gun_points[j].y = read_fix(fp); - ri->gun_points[j].z = read_fix(fp); - } + ri->model_num = cfile_read_int(fp); for (j = 0; j < MAX_GUNS; j++) - ri->gun_submodels[j] = read_byte(fp); - ri->exp1_vclip_num = read_short(fp); - ri->exp1_sound_num = read_short(fp); - ri->exp2_vclip_num = read_short(fp); - ri->exp2_sound_num = read_short(fp); - ri->weapon_type = read_byte(fp); + cfile_read_vector(&ri->gun_points[j], fp); + for (j = 0; j < MAX_GUNS; j++) + ri->gun_submodels[j] = cfile_read_byte(fp); + ri->exp1_vclip_num = cfile_read_short(fp); + ri->exp1_sound_num = cfile_read_short(fp); + ri->exp2_vclip_num = cfile_read_short(fp); + ri->exp2_sound_num = cfile_read_short(fp); + ri->weapon_type = cfile_read_byte(fp); if (ri->weapon_type >= N_weapon_types) ri->weapon_type = 0; - /*ri->weapon_type2 =*/ read_byte(fp); - ri->n_guns = read_byte(fp); - ri->contains_id = read_byte(fp); - ri->contains_count = read_byte(fp); - ri->contains_prob = read_byte(fp); - ri->contains_type = read_byte(fp); - /*ri->kamikaze =*/ read_byte(fp); - ri->score_value = read_short(fp); - /*ri->badass =*/ read_byte(fp); - /*ri->energy_drain =*/ read_byte(fp); - ri->lighting = read_fix(fp); - ri->strength = read_fix(fp); - ri->mass = read_fix(fp); - ri->drag = read_fix(fp); + /*ri->weapon_type2 =*/ cfile_read_byte(fp); + ri->n_guns = cfile_read_byte(fp); + ri->contains_id = cfile_read_byte(fp); + ri->contains_count = cfile_read_byte(fp); + ri->contains_prob = cfile_read_byte(fp); + ri->contains_type = cfile_read_byte(fp); + /*ri->kamikaze =*/ cfile_read_byte(fp); + ri->score_value = cfile_read_short(fp); + /*ri->badass =*/ cfile_read_byte(fp); + /*ri->energy_drain =*/ cfile_read_byte(fp); + ri->lighting = cfile_read_fix(fp); + ri->strength = cfile_read_fix(fp); + ri->mass = cfile_read_fix(fp); + ri->drag = cfile_read_fix(fp); for (j = 0; j < NDL; j++) - ri->field_of_view[j] = read_fix(fp); + ri->field_of_view[j] = cfile_read_fix(fp); for (j = 0; j < NDL; j++) - ri->firing_wait[j] = read_fix(fp); + ri->firing_wait[j] = cfile_read_fix(fp); for (j = 0; j < NDL; j++) - /*ri->firing_wait2[j] =*/ read_fix(fp); + /*ri->firing_wait2[j] =*/ cfile_read_fix(fp); for (j = 0; j < NDL; j++) - ri->turn_time[j] = read_fix(fp); + ri->turn_time[j] = cfile_read_fix(fp); #if 0 // not used in d1, removed in d2 for (j = 0; j < NDL; j++) - ri->fire_power[j] = read_fix(fp); + ri->fire_power[j] = cfile_read_fix(fp); for (j = 0; j < NDL; j++) - ri->shield[j] = read_fix(fp); + ri->shield[j] = cfile_read_fix(fp); #endif for (j = 0; j < NDL; j++) - ri->max_speed[j] = read_fix(fp); + ri->max_speed[j] = cfile_read_fix(fp); for (j = 0; j < NDL; j++) - ri->circle_distance[j] = read_fix(fp); + ri->circle_distance[j] = cfile_read_fix(fp); for (j = 0; j < NDL; j++) - ri->rapidfire_count[j] = read_byte(fp); + ri->rapidfire_count[j] = cfile_read_byte(fp); for (j = 0; j < NDL; j++) - ri->evade_speed[j] = read_byte(fp); - ri->cloak_type = read_byte(fp); - ri->attack_type = read_byte(fp); - ri->see_sound = read_byte(fp); - ri->attack_sound = read_byte(fp); - ri->claw_sound = read_byte(fp); - /*ri->taunt_sound =*/ read_byte(fp); - ri->boss_flag = read_byte(fp); - /*ri->companion =*/ read_byte(fp); - /*ri->smart_blobs =*/ read_byte(fp); - /*ri->energy_blobs =*/ read_byte(fp); - /*ri->thief =*/ read_byte(fp); - /*ri->pursuit =*/ read_byte(fp); - /*ri->lightcast =*/ read_byte(fp); - /*ri->death_roll =*/ read_byte(fp); - /*ri->flags =*/ read_byte(fp); - /*ri->pad[0] =*/ read_byte(fp); - /*ri->pad[1] =*/ read_byte(fp); - /*ri->pad[2] =*/ read_byte(fp); - /*ri->deathroll_sound =*/ read_byte(fp); - /*ri->glow =*/ read_byte(fp); - /*ri->behavior =*/ read_byte(fp); - /*ri->aim =*/ read_byte(fp); + ri->evade_speed[j] = cfile_read_byte(fp); + ri->cloak_type = cfile_read_byte(fp); + ri->attack_type = cfile_read_byte(fp); + ri->see_sound = cfile_read_byte(fp); + ri->attack_sound = cfile_read_byte(fp); + ri->claw_sound = cfile_read_byte(fp); + /*ri->taunt_sound =*/ cfile_read_byte(fp); + ri->boss_flag = cfile_read_byte(fp); + /*ri->companion =*/ cfile_read_byte(fp); + /*ri->smart_blobs =*/ cfile_read_byte(fp); + /*ri->energy_blobs =*/ cfile_read_byte(fp); + /*ri->thief =*/ cfile_read_byte(fp); + /*ri->pursuit =*/ cfile_read_byte(fp); + /*ri->lightcast =*/ cfile_read_byte(fp); + /*ri->death_roll =*/ cfile_read_byte(fp); + /*ri->flags =*/ cfile_read_byte(fp); + /*ri->pad[0] =*/ cfile_read_byte(fp); + /*ri->pad[1] =*/ cfile_read_byte(fp); + /*ri->pad[2] =*/ cfile_read_byte(fp); + /*ri->deathroll_sound =*/ cfile_read_byte(fp); + /*ri->glow =*/ cfile_read_byte(fp); + /*ri->behavior =*/ cfile_read_byte(fp); + /*ri->aim =*/ cfile_read_byte(fp); for (j = 0; j < MAX_GUNS + 1; j++) { for (k = 0; k < N_ANIM_STATES; k++) { - ri->anim_states[j][k].n_joints = read_short(fp); - ri->anim_states[j][k].offset = read_short(fp); + ri->anim_states[j][k].n_joints = cfile_read_short(fp); + ri->anim_states[j][k].offset = cfile_read_short(fp); } } - ri->always_0xabcd = read_int(fp); + ri->always_0xabcd = cfile_read_int(fp); return 1; } @@ -420,15 +417,15 @@ void load_hxm(const char *hxmname) { if (!(f = cfopen((char *)hxmname, "rb"))) return; // hxm file doesn't exist - if (read_int(f) != 0x21584d48) /* HMX! */ + if (cfile_read_int(f) != 0x21584d48) /* HMX! */ goto err; // invalid hxm file - if (read_int(f) != 1) + if (cfile_read_int(f) != 1) goto err; // unknown version // read robot info - if ((n_items = read_int(f)) != 0) { + if ((n_items = cfile_read_int(f)) != 0) { for (i = 0; i < n_items; i++) { - repl_num = read_int(f); + repl_num = cfile_read_int(f); if (repl_num >= MAX_ROBOT_TYPES) cfseek(f, 480, SEEK_CUR); /* sizeof d2_robot_info */ else @@ -438,9 +435,9 @@ void load_hxm(const char *hxmname) { } // read joint positions - if ((n_items = read_int(f)) != 0) { + if ((n_items = cfile_read_int(f)) != 0) { for (i = 0; i < n_items; i++) { - repl_num = read_int(f); + repl_num = cfile_read_int(f); if (repl_num >= MAX_ROBOT_JOINTS) cfseek(f, sizeof(jointpos), SEEK_CUR); else @@ -450,14 +447,14 @@ void load_hxm(const char *hxmname) { } // read polygon models - if ((n_items = read_int(f)) != 0) { + if ((n_items = cfile_read_int(f)) != 0) { for (i = 0; i < n_items; i++) { polymodel *pm; - repl_num = read_int(f); + repl_num = cfile_read_int(f); if (repl_num >= MAX_POLYGON_MODELS) { - read_int(f); // skip n_models - cfseek(f, 734 - 8 + read_int(f) + 8, SEEK_CUR); + cfile_read_int(f); // skip n_models + cfseek(f, 734 - 8 + cfile_read_int(f) + 8, SEEK_CUR); } else { pm = &Polygon_models[repl_num]; if (pm->model_data) @@ -472,20 +469,20 @@ void load_hxm(const char *hxmname) { pm->model_data = NULL; goto err; } - Dying_modelnums[repl_num] = read_int(f); - Dead_modelnums[repl_num] = read_int(f); + Dying_modelnums[repl_num] = cfile_read_int(f); + Dead_modelnums[repl_num] = cfile_read_int(f); } } } // read object bitmaps - if ((n_items = read_int(f)) != 0) { + if ((n_items = cfile_read_int(f)) != 0) { for (i = 0; i < n_items; i++) { - repl_num = read_int(f); + repl_num = cfile_read_int(f); if (repl_num >= MAX_OBJ_BITMAPS) cfseek(f, 2, SEEK_CUR); else { - ObjBitmaps[repl_num].index = read_short(f); + ObjBitmaps[repl_num].index = cfile_read_short(f); } } } diff --git a/main/custom.h b/main/custom.h index 0740e4510..165f30911 100644 --- a/main/custom.h +++ b/main/custom.h @@ -9,12 +9,6 @@ extern int GameBitmapOffset[MAX_BITMAP_FILES]; extern ubyte GameBitmapFlags[MAX_BITMAP_FILES]; extern ubyte * Piggy_bitmap_cache_data; -/* from gamesave.c */ -int read_int(CFILE *f); -short read_short(CFILE *f); -fix read_fix(CFILE *f); -sbyte read_byte(CFILE *f); - void load_custom_data(char *level_file); void custom_close(); diff --git a/main/effects.c b/main/effects.c index f5f279ed0..8255394b8 100644 --- a/main/effects.c +++ b/main/effects.c @@ -256,3 +256,38 @@ void restart_effect(int effect_num) //Assert(Effects[effect_num].bm_ptr != -1); } +#ifndef FAST_FILE_IO +/* + * reads n eclip structs from a CFILE + */ +int eclip_read_n(eclip *ec, int n, CFILE *fp) +{ + int i, j; + + for (i = 0; i < n; i++) { + ec[i].vc.play_time = cfile_read_fix(fp); + ec[i].vc.num_frames = cfile_read_int(fp); + ec[i].vc.frame_time = cfile_read_fix(fp); + ec[i].vc.flags = cfile_read_int(fp); + ec[i].vc.sound_num = cfile_read_short(fp); + for (j = 0; j < VCLIP_MAX_FRAMES; j++) + ec[i].vc.frames[j].index = cfile_read_short(fp); + ec[i].vc.light_value = cfile_read_fix(fp); + ec[i].time_left = cfile_read_fix(fp); + ec[i].frame_count = cfile_read_int(fp); + ec[i].changing_wall_texture = cfile_read_short(fp); + ec[i].changing_object_texture = cfile_read_short(fp); + ec[i].flags = cfile_read_int(fp); + ec[i].crit_clip = cfile_read_int(fp); + ec[i].dest_bm_num = cfile_read_int(fp); + ec[i].dest_vclip = cfile_read_int(fp); + ec[i].dest_eclip = cfile_read_int(fp); + ec[i].dest_size = cfile_read_fix(fp); + ec[i].sound_num = cfile_read_int(fp); + ec[i].segnum = cfile_read_int(fp); + ec[i].sidenum = cfile_read_int(fp); + } + return i; +} +#endif + diff --git a/main/effects.h b/main/effects.h index 9873f9959..cb8d9ef65 100644 --- a/main/effects.h +++ b/main/effects.h @@ -131,5 +131,14 @@ void stop_effect(int effect_num); //restart a stopped effect void restart_effect(int effect_num); +#ifdef FAST_FILE_IO +#define eclip_read_n(ec, n, fp) cfread(ec, sizeof(eclip), n, fp) +#else +/* + * reads n eclip structs from a CFILE + */ +extern int eclip_read_n(eclip *ec, int n, CFILE *fp); #endif - + +#endif /* _EFFECTS_H */ + diff --git a/main/fuelcen.c b/main/fuelcen.c index c7c71412d..1b5f993dc 100644 --- a/main/fuelcen.c +++ b/main/fuelcen.c @@ -76,8 +76,6 @@ int Fuelcen_seconds_left = 0; matcen_info RobotCenters[MAX_ROBOT_CENTERS]; int Num_robot_centers; -control_center_triggers ControlCenterTriggers; - FuelCenter Station[MAX_NUM_FUELCENS]; int Num_fuelcenters = 0; @@ -1123,3 +1121,17 @@ void init_all_matcens(void) #endif } + +#ifndef FAST_FILE_IO +/* + * reads a matcen_info structure from a CFILE + */ +void matcen_info_read(matcen_info *mi, CFILE *fp) +{ + mi->robot_flags = cfile_read_int(fp); + mi->hit_points = cfile_read_fix(fp); + mi->interval = cfile_read_fix(fp); + mi->segnum = cfile_read_short(fp); + mi->fuelcen_num = cfile_read_short(fp); +} +#endif diff --git a/main/fuelcen.h b/main/fuelcen.h index be48ce950..43189af0d 100644 --- a/main/fuelcen.h +++ b/main/fuelcen.h @@ -198,12 +198,6 @@ extern int Fuelcen_seconds_left; //--repair-- //if repairing, cut it short //--repair-- abort_repair_center(); -typedef struct control_center_triggers { - short num_links; - short seg[MAX_WALLS_PER_LINK]; - short side[MAX_WALLS_PER_LINK]; -} __pack__ control_center_triggers; - // An array of pointers to segments with fuel centers. typedef struct FuelCenter { int Type; @@ -221,8 +215,6 @@ typedef struct FuelCenter { vms_vector Center; } __pack__ FuelCenter; -extern control_center_triggers ControlCenterTriggers; - // The max number of robot centers per mine. #define MAX_ROBOT_CENTERS 20 @@ -255,5 +247,14 @@ extern void init_all_matcens(void); extern fix EnergyToCreateOneRobot; +#ifdef FAST_FILE_IO +#define matcen_info_read(mi, fp) cfread(mi, sizeof(matcen_info), 1, fp) +#else +/* + * reads a matcen_info structure from a CFILE + */ +void matcen_info_read(matcen_info *ps, CFILE *fp); +#endif + #endif diff --git a/main/gamemine.c b/main/gamemine.c index e736e27ae..9380f7e5d 100644 --- a/main/gamemine.c +++ b/main/gamemine.c @@ -607,11 +607,17 @@ int load_mine_data_compiled(CFILE *LoadFile) //=============================== Reading part ============================== cfread( &version, sizeof(ubyte), 1, LoadFile ); // 1 byte = compiled version Assert( version==COMPILED_MINE_VERSION ); - cfread( &Num_vertices, sizeof(int), 1, LoadFile ); // 4 bytes = Num_vertices +// cfread( &Num_vertices, sizeof(int), 1, LoadFile ); // 4 bytes = Num_vertices + Num_vertices = cfile_read_int(LoadFile); Assert( Num_vertices <= MAX_VERTICES ); - cfread( &Num_segments, sizeof(int), 1, LoadFile ); // 4 bytes = Num_segments +// cfread( &Num_segments, sizeof(int), 1, LoadFile ); // 4 bytes = Num_segments + Num_segments = cfile_read_int(LoadFile); Assert( Num_segments <= MAX_SEGMENTS ); - cfread( Vertices, sizeof(vms_vector), Num_vertices, LoadFile ); +// cfread( Vertices, sizeof(vms_vector), Num_vertices, LoadFile ); + + for (i = 0; i < Num_vertices; i++) + cfile_read_vector(&Vertices[i], LoadFile); + for (segnum=0; segnum>5, write as short, l>>1 write as short) for (i=0; i<4; i++ ) { - cfread( &temp_short, sizeof(short), 1, LoadFile ); +// cfread( &temp_short, sizeof(short), 1, LoadFile ); + temp_short = cfile_read_short(LoadFile); Segments[segnum].sides[sidenum].uvls[i].u = ((fix)temp_short) << 5; - cfread( &temp_short, sizeof(short), 1, LoadFile ); +// cfread( &temp_short, sizeof(short), 1, LoadFile ); + temp_short = cfile_read_short(LoadFile); Segments[segnum].sides[sidenum].uvls[i].v = ((fix)temp_short) << 5; - cfread( &temp_ushort, sizeof(temp_ushort), 1, LoadFile ); +// cfread( &temp_ushort, sizeof(temp_ushort), 1, LoadFile ); + temp_ushort = cfile_read_short(LoadFile); Segments[segnum].sides[sidenum].uvls[i].l = ((fix)temp_ushort) << 1; - //cfread( &Segments[segnum].sides[sidenum].uvls[i].l, sizeof(fix), 1, LoadFile ); +// cfread( &Segments[segnum].sides[sidenum].uvls[i].l, sizeof(fix), 1, LoadFile ); } } else { Segments[segnum].sides[sidenum].tmap_num = 0; @@ -715,16 +735,15 @@ int load_mine_data_compiled_new(CFILE *LoadFile) cfread( &version, sizeof(ubyte), 1, LoadFile ); // 1 byte = compiled version Assert( version==COMPILED_MINE_VERSION ); - cfread( &temp_ushort, sizeof(ushort), 1, LoadFile ); // 2 bytes = Num_vertices - Num_vertices = temp_ushort; + Num_vertices = cfile_read_short(LoadFile); Assert( Num_vertices <= MAX_VERTICES ); - cfread( &temp_ushort, sizeof(ushort), 1, LoadFile ); // 2 bytes = Num_segments - Num_segments = temp_ushort; + Num_segments = cfile_read_short(LoadFile); Assert( Num_segments <= MAX_SEGMENTS ); - cfread( Vertices, sizeof(vms_vector), Num_vertices, LoadFile ); - + for (i = 0; i < Num_vertices; i++) + cfile_read_vector(&Vertices[i], LoadFile); + for (segnum=0; segnum>5, write as short, l>>1 write as short) for (i=0; i<4; i++ ) { - cfread( &temp_short, sizeof(short), 1, LoadFile ); + temp_short = cfile_read_short(LoadFile); Segments[segnum].sides[sidenum].uvls[i].u = ((fix)temp_short) << 5; - cfread( &temp_short, sizeof(short), 1, LoadFile ); + temp_short = cfile_read_short(LoadFile); Segments[segnum].sides[sidenum].uvls[i].v = ((fix)temp_short) << 5; - cfread( &temp_ushort, sizeof(temp_ushort), 1, LoadFile ); + temp_ushort = cfile_read_short(LoadFile); Segments[segnum].sides[sidenum].uvls[i].l = ((fix)temp_ushort) << 1; - //cfread( &Segments[segnum].sides[sidenum].uvls[i].l, sizeof(fix), 1, LoadFile ); } } else { Segments[segnum].sides[sidenum].tmap_num = 0; diff --git a/main/gamesave.c b/main/gamesave.c index 67ee1e7a1..6cbe6f268 100644 --- a/main/gamesave.c +++ b/main/gamesave.c @@ -321,6 +321,7 @@ static char rcsid[] = "$Id: gamesave.c,v 1.1.1.1 2006/03/17 19:44:30 zicodxx Exp #include "menu.h" #include "switch.h" #include "fuelcen.h" +#include "cntrlcen.h" #include "powerup.h" #include "hostage.h" #include "weapon.h" @@ -397,38 +398,6 @@ char Gamesave_current_filename[128]; #define HOSTAGE_DATA_VERSION 0 -//Start old wall structures - -typedef struct v16_wall { - sbyte type; // What kind of special wall. - sbyte flags; // Flags for the wall. - fix hps; // "Hit points" of the wall. - sbyte trigger; // Which trigger is associated with the wall. - sbyte clip_num; // Which animation associated with the wall. - sbyte keys; - } __pack__ v16_wall; - -typedef struct v19_wall { - int segnum,sidenum; // Seg & side for this wall - sbyte type; // What kind of special wall. - sbyte flags; // Flags for the wall. - fix hps; // "Hit points" of the wall. - sbyte trigger; // Which trigger is associated with the wall. - sbyte clip_num; // Which animation associated with the wall. - sbyte keys; - int linked_wall; // number of linked wall - } __pack__ v19_wall; - -typedef struct v19_door { - int n_parts; // for linked walls - short seg[2]; // Segment pointer of door. - short side[2]; // Side number of door. - short type[2]; // What kind of door animation. - fix open; // How long it has been open. -} __pack__ v19_door; - -//End old wall structures - struct { ushort fileinfo_signature; ushort fileinfo_version; @@ -702,190 +671,60 @@ void verify_object( object * obj ) { } -/*static*/ int read_int(CFILE *file) -{ - int i; - - if (cfread( &i, sizeof(i), 1, file) != 1) - Error( "Error reading int in gamesave.c" ); - - return i; -} - -/*static*/ fix read_fix(CFILE *file) -{ - fix f; - - if (cfread( &f, sizeof(f), 1, file) != 1) - Error( "Error reading fix in gamesave.c" ); - - return f; -} - -/*static*/ short read_short(CFILE *file) -{ - short s; - - if (cfread( &s, sizeof(s), 1, file) != 1) - Error( "Error reading short in gamesave.c" ); - - return s; -} - -static short read_fixang(CFILE *file) -{ - fixang f; - - if (cfread( &f, sizeof(f), 1, file) != 1) - Error( "Error reading fixang in gamesave.c" ); - - return f; -} - -/*static*/ sbyte read_byte(CFILE *file) -{ - sbyte b; - - if (cfread( &b, sizeof(b), 1, file) != 1) - Error( "Error reading byte in gamesave.c" ); - - return b; -} - -/*static */void read_vector(vms_vector *v,CFILE *file) -{ - v->x = read_fix(file); - v->y = read_fix(file); - v->z = read_fix(file); -} - -static void read_matrix(vms_matrix *m,CFILE *file) -{ - read_vector(&m->rvec,file); - read_vector(&m->uvec,file); - read_vector(&m->fvec,file); -} - -static void read_angvec(vms_angvec *v,CFILE *file) -{ - v->p = read_fixang(file); - v->b = read_fixang(file); - v->h = read_fixang(file); -} - //static gs_skip(int len,CFILE *file) //{ // // cfseek(file,len,SEEK_CUR); //} -#ifdef EDITOR -static void gs_write_int(int i,FILE *file) -{ - if (fwrite( &i, sizeof(i), 1, file) != 1) - Error( "Error reading int in gamesave.c" ); - -} - -static void gs_write_fix(fix f,FILE *file) -{ - if (fwrite( &f, sizeof(f), 1, file) != 1) - Error( "Error reading fix in gamesave.c" ); - -} - -static void gs_write_short(short s,FILE *file) -{ - if (fwrite( &s, sizeof(s), 1, file) != 1) - Error( "Error reading short in gamesave.c" ); - -} - -static void gs_write_fixang(fixang f,FILE *file) -{ - if (fwrite( &f, sizeof(f), 1, file) != 1) - Error( "Error reading fixang in gamesave.c" ); - -} - -static void gs_write_byte(sbyte b,FILE *file) -{ - if (fwrite( &b, sizeof(b), 1, file) != 1) - Error( "Error reading byte in gamesave.c" ); - -} - -static void gr_write_vector(vms_vector *v,FILE *file) -{ - gs_write_fix(v->x,file); - gs_write_fix(v->y,file); - gs_write_fix(v->z,file); -} - -static void gs_write_matrix(vms_matrix *m,FILE *file) -{ - gr_write_vector(&m->rvec,file); - gr_write_vector(&m->uvec,file); - gr_write_vector(&m->fvec,file); -} - -static void gs_write_angvec(vms_angvec *v,FILE *file) -{ - gs_write_fixang(v->p,file); - gs_write_fixang(v->b,file); - gs_write_fixang(v->h,file); -} - -#endif - //reads one object of the given version from the given file void read_object(object *obj,CFILE *f,int version) { - obj->type = read_byte(f); - obj->id = read_byte(f); + obj->type = cfile_read_byte(f); + obj->id = cfile_read_byte(f); - obj->control_type = read_byte(f); - obj->movement_type = read_byte(f); - obj->render_type = read_byte(f); - obj->flags = read_byte(f); + obj->control_type = cfile_read_byte(f); + obj->movement_type = cfile_read_byte(f); + obj->render_type = cfile_read_byte(f); + obj->flags = cfile_read_byte(f); - obj->segnum = read_short(f); + obj->segnum = cfile_read_short(f); obj->attached_obj = -1; - read_vector(&obj->pos,f); - read_matrix(&obj->orient,f); + cfile_read_vector(&obj->pos,f); + cfile_read_matrix(&obj->orient,f); - obj->size = read_fix(f); - obj->shields = read_fix(f); + obj->size = cfile_read_fix(f); + obj->shields = cfile_read_fix(f); - read_vector(&obj->last_pos,f); + cfile_read_vector(&obj->last_pos,f); - obj->contains_type = read_byte(f); - obj->contains_id = read_byte(f); - obj->contains_count = read_byte(f); + obj->contains_type = cfile_read_byte(f); + obj->contains_id = cfile_read_byte(f); + obj->contains_count = cfile_read_byte(f); switch (obj->movement_type) { case MT_PHYSICS: - read_vector(&obj->mtype.phys_info.velocity,f); - read_vector(&obj->mtype.phys_info.thrust,f); + cfile_read_vector(&obj->mtype.phys_info.velocity,f); + cfile_read_vector(&obj->mtype.phys_info.thrust,f); - obj->mtype.phys_info.mass = read_fix(f); - obj->mtype.phys_info.drag = read_fix(f); - obj->mtype.phys_info.brakes = read_fix(f); + obj->mtype.phys_info.mass = cfile_read_fix(f); + obj->mtype.phys_info.drag = cfile_read_fix(f); + obj->mtype.phys_info.brakes = cfile_read_fix(f); - read_vector(&obj->mtype.phys_info.rotvel,f); - read_vector(&obj->mtype.phys_info.rotthrust,f); + cfile_read_vector(&obj->mtype.phys_info.rotvel,f); + cfile_read_vector(&obj->mtype.phys_info.rotthrust,f); - obj->mtype.phys_info.turnroll = read_fixang(f); - obj->mtype.phys_info.flags = read_short(f); + obj->mtype.phys_info.turnroll = cfile_read_fixang(f); + obj->mtype.phys_info.flags = cfile_read_short(f); break; case MT_SPINNING: - read_vector(&obj->mtype.spin_rate,f); + cfile_read_vector(&obj->mtype.spin_rate,f); break; case MT_NONE: @@ -900,27 +739,27 @@ void read_object(object *obj,CFILE *f,int version) case CT_AI: { int i; - obj->ctype.ai_info.behavior = read_byte(f); + obj->ctype.ai_info.behavior = cfile_read_byte(f); for (i=0;ictype.ai_info.flags[i] = read_byte(f); + obj->ctype.ai_info.flags[i] = cfile_read_byte(f); - obj->ctype.ai_info.hide_segment = read_short(f); - obj->ctype.ai_info.hide_index = read_short(f); - obj->ctype.ai_info.path_length = read_short(f); - obj->ctype.ai_info.cur_path_index = read_short(f); + obj->ctype.ai_info.hide_segment = cfile_read_short(f); + obj->ctype.ai_info.hide_index = cfile_read_short(f); + obj->ctype.ai_info.path_length = cfile_read_short(f); + obj->ctype.ai_info.cur_path_index = cfile_read_short(f); - obj->ctype.ai_info.follow_path_start_seg = read_short(f); - obj->ctype.ai_info.follow_path_end_seg = read_short(f); + obj->ctype.ai_info.follow_path_start_seg = cfile_read_short(f); + obj->ctype.ai_info.follow_path_end_seg = cfile_read_short(f); break; } case CT_EXPLOSION: - obj->ctype.expl_info.spawn_time = read_fix(f); - obj->ctype.expl_info.delete_time = read_fix(f); - obj->ctype.expl_info.delete_objnum = read_short(f); + obj->ctype.expl_info.spawn_time = cfile_read_fix(f); + obj->ctype.expl_info.delete_time = cfile_read_fix(f); + obj->ctype.expl_info.delete_objnum = cfile_read_short(f); obj->ctype.expl_info.next_attach = obj->ctype.expl_info.prev_attach = obj->ctype.expl_info.attach_parent = -1; break; @@ -929,21 +768,21 @@ void read_object(object *obj,CFILE *f,int version) //do I really need to read these? Are they even saved to disk? - obj->ctype.laser_info.parent_type = read_short(f); - obj->ctype.laser_info.parent_num = read_short(f); - obj->ctype.laser_info.parent_signature = read_int(f); + obj->ctype.laser_info.parent_type = cfile_read_short(f); + obj->ctype.laser_info.parent_num = cfile_read_short(f); + obj->ctype.laser_info.parent_signature = cfile_read_int(f); break; case CT_LIGHT: - obj->ctype.light_info.intensity = read_fix(f); + obj->ctype.light_info.intensity = cfile_read_fix(f); break; case CT_POWERUP: if (version >= 25) - obj->ctype.powerup_info.count = read_int(f); + obj->ctype.powerup_info.count = cfile_read_int(f); else obj->ctype.powerup_info.count = 1; @@ -981,14 +820,14 @@ void read_object(object *obj,CFILE *f,int version) case RT_POLYOBJ: { int i,tmo; - obj->rtype.pobj_info.model_num = read_int(f); + obj->rtype.pobj_info.model_num = cfile_read_int(f); for (i=0;irtype.pobj_info.anim_angles[i],f); + cfile_read_angvec(&obj->rtype.pobj_info.anim_angles[i],f); - obj->rtype.pobj_info.subobj_flags = read_int(f); + obj->rtype.pobj_info.subobj_flags = cfile_read_int(f); - tmo = read_int(f); + tmo = cfile_read_int(f); #ifndef EDITOR obj->rtype.pobj_info.tmap_override = tmo; @@ -1016,9 +855,9 @@ void read_object(object *obj,CFILE *f,int version) case RT_POWERUP: case RT_FIREBALL: - obj->rtype.vclip_info.vclip_num = read_int(f); - obj->rtype.vclip_info.frametime = read_fix(f); - obj->rtype.vclip_info.framenum = read_byte(f); + obj->rtype.vclip_info.vclip_num = cfile_read_int(f); + obj->rtype.vclip_info.frametime = cfile_read_fix(f); + obj->rtype.vclip_info.framenum = cfile_read_byte(f); break; @@ -1037,27 +876,27 @@ void read_object(object *obj,CFILE *f,int version) //writes one object to the given file void write_object(object *obj,FILE *f) { - gs_write_byte(obj->type,f); - gs_write_byte(obj->id,f); + cfile_write_byte(obj->type,f); + cfile_write_byte(obj->id,f); - gs_write_byte(obj->control_type,f); - gs_write_byte(obj->movement_type,f); - gs_write_byte(obj->render_type,f); - gs_write_byte(obj->flags,f); + cfile_write_byte(obj->control_type,f); + cfile_write_byte(obj->movement_type,f); + cfile_write_byte(obj->render_type,f); + cfile_write_byte(obj->flags,f); - gs_write_short(obj->segnum,f); + cfile_write_short(obj->segnum,f); gr_write_vector(&obj->pos,f); - gs_write_matrix(&obj->orient,f); + cfile_write_matrix(&obj->orient,f); - gs_write_fix(obj->size,f); - gs_write_fix(obj->shields,f); + cfile_write_fix(obj->size,f); + cfile_write_fix(obj->shields,f); gr_write_vector(&obj->last_pos,f); - gs_write_byte(obj->contains_type,f); - gs_write_byte(obj->contains_id,f); - gs_write_byte(obj->contains_count,f); + cfile_write_byte(obj->contains_type,f); + cfile_write_byte(obj->contains_id,f); + cfile_write_byte(obj->contains_count,f); switch (obj->movement_type) { @@ -1066,15 +905,15 @@ void write_object(object *obj,FILE *f) gr_write_vector(&obj->mtype.phys_info.velocity,f); gr_write_vector(&obj->mtype.phys_info.thrust,f); - gs_write_fix(obj->mtype.phys_info.mass,f); - gs_write_fix(obj->mtype.phys_info.drag,f); - gs_write_fix(obj->mtype.phys_info.brakes,f); + cfile_write_fix(obj->mtype.phys_info.mass,f); + cfile_write_fix(obj->mtype.phys_info.drag,f); + cfile_write_fix(obj->mtype.phys_info.brakes,f); gr_write_vector(&obj->mtype.phys_info.rotvel,f); gr_write_vector(&obj->mtype.phys_info.rotthrust,f); - gs_write_fixang(obj->mtype.phys_info.turnroll,f); - gs_write_short(obj->mtype.phys_info.flags,f); + cfile_write_fixang(obj->mtype.phys_info.turnroll,f); + cfile_write_short(obj->mtype.phys_info.flags,f); break; @@ -1095,27 +934,27 @@ void write_object(object *obj,FILE *f) case CT_AI: { int i; - gs_write_byte(obj->ctype.ai_info.behavior,f); + cfile_write_byte(obj->ctype.ai_info.behavior,f); for (i=0;ictype.ai_info.flags[i],f); + cfile_write_byte(obj->ctype.ai_info.flags[i],f); - gs_write_short(obj->ctype.ai_info.hide_segment,f); - gs_write_short(obj->ctype.ai_info.hide_index,f); - gs_write_short(obj->ctype.ai_info.path_length,f); - gs_write_short(obj->ctype.ai_info.cur_path_index,f); + cfile_write_short(obj->ctype.ai_info.hide_segment,f); + cfile_write_short(obj->ctype.ai_info.hide_index,f); + cfile_write_short(obj->ctype.ai_info.path_length,f); + cfile_write_short(obj->ctype.ai_info.cur_path_index,f); - gs_write_short(obj->ctype.ai_info.follow_path_start_seg,f); - gs_write_short(obj->ctype.ai_info.follow_path_end_seg,f); + cfile_write_short(obj->ctype.ai_info.follow_path_start_seg,f); + cfile_write_short(obj->ctype.ai_info.follow_path_end_seg,f); break; } case CT_EXPLOSION: - gs_write_fix(obj->ctype.expl_info.spawn_time,f); - gs_write_fix(obj->ctype.expl_info.delete_time,f); - gs_write_short(obj->ctype.expl_info.delete_objnum,f); + cfile_write_fix(obj->ctype.expl_info.spawn_time,f); + cfile_write_fix(obj->ctype.expl_info.delete_time,f); + cfile_write_short(obj->ctype.expl_info.delete_objnum,f); break; @@ -1123,9 +962,9 @@ void write_object(object *obj,FILE *f) //do I really need to write these objects? - gs_write_short(obj->ctype.laser_info.parent_type,f); - gs_write_short(obj->ctype.laser_info.parent_num,f); - gs_write_int(obj->ctype.laser_info.parent_signature,f); + cfile_write_short(obj->ctype.laser_info.parent_type,f); + cfile_write_short(obj->ctype.laser_info.parent_num,f); + cfile_write_int(obj->ctype.laser_info.parent_signature,f); break; @@ -1133,12 +972,12 @@ void write_object(object *obj,FILE *f) case CT_LIGHT: - gs_write_fix(obj->ctype.light_info.intensity,f); + cfile_write_fix(obj->ctype.light_info.intensity,f); break; case CT_POWERUP: - gs_write_int(obj->ctype.powerup_info.count,f); + cfile_write_int(obj->ctype.powerup_info.count,f); break; case CT_NONE: @@ -1169,14 +1008,14 @@ void write_object(object *obj,FILE *f) case RT_POLYOBJ: { int i; - gs_write_int(obj->rtype.pobj_info.model_num,f); + cfile_write_int(obj->rtype.pobj_info.model_num,f); for (i=0;irtype.pobj_info.anim_angles[i],f); + cfile_write_angvec(&obj->rtype.pobj_info.anim_angles[i],f); - gs_write_int(obj->rtype.pobj_info.subobj_flags,f); + cfile_write_int(obj->rtype.pobj_info.subobj_flags,f); - gs_write_int(obj->rtype.pobj_info.tmap_override,f); + cfile_write_int(obj->rtype.pobj_info.tmap_override,f); break; } @@ -1186,9 +1025,9 @@ void write_object(object *obj,FILE *f) case RT_POWERUP: case RT_FIREBALL: - gs_write_int(obj->rtype.vclip_info.vclip_num,f); - gs_write_fix(obj->rtype.vclip_info.frametime,f); - gs_write_byte(obj->rtype.vclip_info.framenum,f); + cfile_write_int(obj->rtype.vclip_info.vclip_num,f); + cfile_write_fix(obj->rtype.vclip_info.frametime,f); + cfile_write_byte(obj->rtype.vclip_info.framenum,f); break; @@ -1241,13 +1080,13 @@ int load_game_data(CFILE *LoadFile) game_fileinfo.matcen_howmany = 0; game_fileinfo.matcen_sizeof = sizeof(matcen_info); + if (cfseek(LoadFile, start_offset, SEEK_SET)) + Error("Error seeking in gamesave.c"); + // Read in game_top_fileinfo to get size of saved fileinfo. - - if (cfseek( LoadFile, start_offset, SEEK_SET )) - Error( "Error seeking in gamesave.c" ); - - if (cfread( &game_top_fileinfo, sizeof(game_top_fileinfo), 1, LoadFile) != 1) - Error( "Error reading game_top_fileinfo in gamesave.c" ); + game_top_fileinfo.fileinfo_signature = cfile_read_short(LoadFile); + game_top_fileinfo.fileinfo_version = cfile_read_short(LoadFile); + game_top_fileinfo.fileinfo_sizeof = cfile_read_int(LoadFile); // Check signature if (game_top_fileinfo.fileinfo_signature != 0x6705) @@ -1261,39 +1100,36 @@ int load_game_data(CFILE *LoadFile) if (cfseek( LoadFile, start_offset, SEEK_SET )) Error( "Error seeking to game_fileinfo in gamesave.c" ); - game_fileinfo.fileinfo_signature = read_short(LoadFile); + game_fileinfo.fileinfo_signature = cfile_read_short(LoadFile); - game_fileinfo.fileinfo_version = read_short(LoadFile); - game_fileinfo.fileinfo_sizeof = read_int(LoadFile); + game_fileinfo.fileinfo_version = cfile_read_short(LoadFile); + game_fileinfo.fileinfo_sizeof = cfile_read_int(LoadFile); for(i=0; i<15; i++) - game_fileinfo.mine_filename[i] = read_byte(LoadFile); - game_fileinfo.level = read_int(LoadFile); - game_fileinfo.player_offset = read_int(LoadFile); // Player info - game_fileinfo.player_sizeof = read_int(LoadFile); - game_fileinfo.object_offset = read_int(LoadFile); // Object info - game_fileinfo.object_howmany = read_int(LoadFile); - game_fileinfo.object_sizeof = read_int(LoadFile); - game_fileinfo.walls_offset = read_int(LoadFile); - game_fileinfo.walls_howmany = read_int(LoadFile); - game_fileinfo.walls_sizeof = read_int(LoadFile); - game_fileinfo.doors_offset = read_int(LoadFile); - game_fileinfo.doors_howmany = read_int(LoadFile); - game_fileinfo.doors_sizeof = read_int(LoadFile); - game_fileinfo.triggers_offset = read_int(LoadFile); - game_fileinfo.triggers_howmany = read_int(LoadFile); - game_fileinfo.triggers_sizeof = read_int(LoadFile); - game_fileinfo.links_offset = read_int(LoadFile); - game_fileinfo.links_howmany = read_int(LoadFile); - game_fileinfo.links_sizeof = read_int(LoadFile); - game_fileinfo.control_offset = read_int(LoadFile); - game_fileinfo.control_howmany = read_int(LoadFile); - game_fileinfo.control_sizeof = read_int(LoadFile); - game_fileinfo.matcen_offset = read_int(LoadFile); - game_fileinfo.matcen_howmany = read_int(LoadFile); - game_fileinfo.matcen_sizeof = read_int(LoadFile); - -// if (cfread( &game_fileinfo, game_top_fileinfo.fileinfo_sizeof, 1, LoadFile )!=1) -// Error( "Error reading game_fileinfo in gamesave.c" ); + game_fileinfo.mine_filename[i] = cfile_read_byte(LoadFile); + game_fileinfo.level = cfile_read_int(LoadFile); + game_fileinfo.player_offset = cfile_read_int(LoadFile); // Player info + game_fileinfo.player_sizeof = cfile_read_int(LoadFile); + game_fileinfo.object_offset = cfile_read_int(LoadFile); // Object info + game_fileinfo.object_howmany = cfile_read_int(LoadFile); + game_fileinfo.object_sizeof = cfile_read_int(LoadFile); + game_fileinfo.walls_offset = cfile_read_int(LoadFile); + game_fileinfo.walls_howmany = cfile_read_int(LoadFile); + game_fileinfo.walls_sizeof = cfile_read_int(LoadFile); + game_fileinfo.doors_offset = cfile_read_int(LoadFile); + game_fileinfo.doors_howmany = cfile_read_int(LoadFile); + game_fileinfo.doors_sizeof = cfile_read_int(LoadFile); + game_fileinfo.triggers_offset = cfile_read_int(LoadFile); + game_fileinfo.triggers_howmany = cfile_read_int(LoadFile); + game_fileinfo.triggers_sizeof = cfile_read_int(LoadFile); + game_fileinfo.links_offset = cfile_read_int(LoadFile); + game_fileinfo.links_howmany = cfile_read_int(LoadFile); + game_fileinfo.links_sizeof = cfile_read_int(LoadFile); + game_fileinfo.control_offset = cfile_read_int(LoadFile); + game_fileinfo.control_howmany = cfile_read_int(LoadFile); + game_fileinfo.control_sizeof = cfile_read_int(LoadFile); + game_fileinfo.matcen_offset = cfile_read_int(LoadFile); + game_fileinfo.matcen_howmany = cfile_read_int(LoadFile); + game_fileinfo.matcen_sizeof = cfile_read_int(LoadFile); if (game_top_fileinfo.fileinfo_version >= 14) { //load mine filename char *p=Current_level_name; @@ -1304,7 +1140,7 @@ int load_game_data(CFILE *LoadFile) Current_level_name[0]=0; if (game_top_fileinfo.fileinfo_version >= 19) { //load pof names - cfread(&N_save_pof_names,2,1,LoadFile); + N_save_pof_names = cfile_read_short(LoadFile); cfread(Save_pof_names,N_save_pof_names,13,LoadFile); } @@ -1321,7 +1157,7 @@ int load_game_data(CFILE *LoadFile) Error( "Error seeking to object_offset in gamesave.c" ); for (i=0;i= 17) { v19_wall w; Assert(sizeof(w) == game_fileinfo.walls_sizeof); - if (cfread(&w, game_fileinfo.walls_sizeof, 1,LoadFile)!=1) - Error( "Error reading Walls[%d] in gamesave.c", i); + v19_wall_read(&w, LoadFile); Walls[i].segnum = w.segnum; Walls[i].sidenum = w.sidenum; @@ -1371,8 +1205,7 @@ int load_game_data(CFILE *LoadFile) Assert(sizeof(w) == game_fileinfo.walls_sizeof); - if (cfread(&w, game_fileinfo.walls_sizeof, 1,LoadFile)!=1) - Error( "Error reading Walls[%d] in gamesave.c", i); + v16_wall_read(&w, LoadFile); Walls[i].segnum = Walls[i].sidenum = Walls[i].linked_wall = -1; @@ -1400,8 +1233,7 @@ int load_game_data(CFILE *LoadFile) Assert(sizeof(ActiveDoors[i]) == game_fileinfo.doors_sizeof); - if (cfread(&ActiveDoors[i], game_fileinfo.doors_sizeof,1,LoadFile)!=1) - Error( "Error reading ActiveDoors[%d] in gamesave.c", i); + active_door_read(&ActiveDoors[i], LoadFile); } else { v19_door d; @@ -1409,8 +1241,7 @@ int load_game_data(CFILE *LoadFile) Assert(sizeof(d) == game_fileinfo.doors_sizeof); - if (cfread(&d, game_fileinfo.doors_sizeof, 1,LoadFile)!=1) - Error( "Error reading Doors[%d] in gamesave.c", i); + v19_door_read(&d, LoadFile); ActiveDoors[i].n_parts = d.n_parts; @@ -1434,19 +1265,8 @@ int load_game_data(CFILE *LoadFile) if (game_fileinfo.triggers_offset > -1) { if (!cfseek( LoadFile, game_fileinfo.triggers_offset,SEEK_SET )) { for (i=0;i=MAX_HOSTAGES || Hostage_face_clip[Hostages[i].vclip_num].num_frames<=0) diff --git a/main/loadrl2.c b/main/loadrl2.c index 16656bdfc..a500aeecd 100644 --- a/main/loadrl2.c +++ b/main/loadrl2.c @@ -157,141 +157,58 @@ void verify_object( object * obj ) { } #endif -/*static*/ int read_int(CFILE *file) -{ - int i; - - if (cfread( &i, sizeof(i), 1, file) != 1) - Error( "Error reading int in gamesave.c" ); - - return i; -} - -/*static*/ fix read_fix(CFILE *file) -{ - fix f; - - if (cfread( &f, sizeof(f), 1, file) != 1) - Error( "Error reading fix in gamesave.c" ); - - return f; -} - -/*static*/ short read_short(CFILE *file) -{ - short s; - - if (cfread( &s, sizeof(s), 1, file) != 1) - Error( "Error reading short in gamesave.c" ); - - return s; -} - -static short read_fixang(CFILE *file) -{ - fixang f; - - if (cfread( &f, sizeof(f), 1, file) != 1) - Error( "Error reading fixang in gamesave.c" ); - - return f; -} - -/*static*/ sbyte read_byte(CFILE *file) -{ - sbyte b; - - if (cfread( &b, sizeof(b), 1, file) != 1) - Error( "Error reading byte in gamesave.c" ); - - return b; -} - -#if 0 -static ubyte read_ubyte(CFILE *file) -{ - byte b; - - if (cfread( &b, sizeof(b), 1, file) != 1) - Error( "Error reading byte in gamesave.c" ); - - return b; -} -#endif - -/*static*/ void read_vector(vms_vector *v,CFILE *file) -{ - v->x = read_fix(file); - v->y = read_fix(file); - v->z = read_fix(file); -} - -static void read_matrix(vms_matrix *m,CFILE *file) -{ - read_vector(&m->rvec,file); - read_vector(&m->uvec,file); - read_vector(&m->fvec,file); -} - -static void read_angvec(vms_angvec *v,CFILE *file) -{ - v->p = read_fixang(file); - v->b = read_fixang(file); - v->h = read_fixang(file); -} - //reads one object of the given version from the given file void read_object(object *obj,CFILE *f,int version) { - obj->type = read_byte(f); - obj->id = read_byte(f); + obj->type = cfile_read_byte(f); + obj->id = cfile_read_byte(f); if (obj->type == OBJ_ROBOT && obj->id > 23) { obj->id = obj->id % 24; } - obj->control_type = read_byte(f); - obj->movement_type = read_byte(f); - obj->render_type = read_byte(f); - obj->flags = read_byte(f); + obj->control_type = cfile_read_byte(f); + obj->movement_type = cfile_read_byte(f); + obj->render_type = cfile_read_byte(f); + obj->flags = cfile_read_byte(f); - obj->segnum = read_short(f); + obj->segnum = cfile_read_short(f); obj->attached_obj = -1; - read_vector(&obj->pos,f); - read_matrix(&obj->orient,f); + cfile_read_vector(&obj->pos,f); + cfile_read_matrix(&obj->orient,f); - obj->size = read_fix(f); - obj->shields = read_fix(f); + obj->size = cfile_read_fix(f); + obj->shields = cfile_read_fix(f); - read_vector(&obj->last_pos,f); + cfile_read_vector(&obj->last_pos,f); - obj->contains_type = read_byte(f); - obj->contains_id = read_byte(f); - obj->contains_count = read_byte(f); + obj->contains_type = cfile_read_byte(f); + obj->contains_id = cfile_read_byte(f); + obj->contains_count = cfile_read_byte(f); switch (obj->movement_type) { case MT_PHYSICS: - read_vector(&obj->mtype.phys_info.velocity,f); - read_vector(&obj->mtype.phys_info.thrust,f); + cfile_read_vector(&obj->mtype.phys_info.velocity,f); + cfile_read_vector(&obj->mtype.phys_info.thrust,f); - obj->mtype.phys_info.mass = read_fix(f); - obj->mtype.phys_info.drag = read_fix(f); - obj->mtype.phys_info.brakes = read_fix(f); + obj->mtype.phys_info.mass = cfile_read_fix(f); + obj->mtype.phys_info.drag = cfile_read_fix(f); + obj->mtype.phys_info.brakes = cfile_read_fix(f); - read_vector(&obj->mtype.phys_info.rotvel,f); - read_vector(&obj->mtype.phys_info.rotthrust,f); + cfile_read_vector(&obj->mtype.phys_info.rotvel,f); + cfile_read_vector(&obj->mtype.phys_info.rotthrust,f); - obj->mtype.phys_info.turnroll = read_fixang(f); - obj->mtype.phys_info.flags = read_short(f); + obj->mtype.phys_info.turnroll = cfile_read_fixang(f); + obj->mtype.phys_info.flags = cfile_read_short(f); break; case MT_SPINNING: - read_vector(&obj->mtype.spin_rate,f); + cfile_read_vector(&obj->mtype.spin_rate,f); break; case MT_NONE: @@ -306,19 +223,19 @@ void read_object(object *obj,CFILE *f,int version) case CT_AI: { int i; - obj->ctype.ai_info.behavior = read_byte(f); + obj->ctype.ai_info.behavior = cfile_read_byte(f); for (i=0;ictype.ai_info.flags[i] = read_byte(f); + obj->ctype.ai_info.flags[i] = cfile_read_byte(f); - obj->ctype.ai_info.hide_segment = read_short(f); - obj->ctype.ai_info.hide_index = read_short(f); - obj->ctype.ai_info.path_length = read_short(f); - obj->ctype.ai_info.cur_path_index = read_short(f); + obj->ctype.ai_info.hide_segment = cfile_read_short(f); + obj->ctype.ai_info.hide_index = cfile_read_short(f); + obj->ctype.ai_info.path_length = cfile_read_short(f); + obj->ctype.ai_info.cur_path_index = cfile_read_short(f); if (version <= 25) { - obj->ctype.ai_info.follow_path_start_seg = read_short(f); - obj->ctype.ai_info.follow_path_end_seg = read_short(f); + obj->ctype.ai_info.follow_path_start_seg = cfile_read_short(f); + obj->ctype.ai_info.follow_path_end_seg = cfile_read_short(f); } break; @@ -326,9 +243,9 @@ void read_object(object *obj,CFILE *f,int version) case CT_EXPLOSION: - obj->ctype.expl_info.spawn_time = read_fix(f); - obj->ctype.expl_info.delete_time = read_fix(f); - obj->ctype.expl_info.delete_objnum = read_short(f); + obj->ctype.expl_info.spawn_time = cfile_read_fix(f); + obj->ctype.expl_info.delete_time = cfile_read_fix(f); + obj->ctype.expl_info.delete_objnum = cfile_read_short(f); obj->ctype.expl_info.next_attach = obj->ctype.expl_info.prev_attach = obj->ctype.expl_info.attach_parent = -1; break; @@ -337,21 +254,21 @@ void read_object(object *obj,CFILE *f,int version) //do I really need to read these? Are they even saved to disk? - obj->ctype.laser_info.parent_type = read_short(f); - obj->ctype.laser_info.parent_num = read_short(f); - obj->ctype.laser_info.parent_signature = read_int(f); + obj->ctype.laser_info.parent_type = cfile_read_short(f); + obj->ctype.laser_info.parent_num = cfile_read_short(f); + obj->ctype.laser_info.parent_signature = cfile_read_int(f); break; case CT_LIGHT: - obj->ctype.light_info.intensity = read_fix(f); + obj->ctype.light_info.intensity = cfile_read_fix(f); break; case CT_POWERUP: if (version >= 25) - obj->ctype.powerup_info.count = read_int(f); + obj->ctype.powerup_info.count = cfile_read_int(f); else obj->ctype.powerup_info.count = 1; @@ -389,14 +306,14 @@ void read_object(object *obj,CFILE *f,int version) case RT_POLYOBJ: { int i,tmo; - obj->rtype.pobj_info.model_num = convert_polymod(read_int(f)); + obj->rtype.pobj_info.model_num = convert_polymod(cfile_read_int(f)); for (i=0;irtype.pobj_info.anim_angles[i],f); + cfile_read_angvec(&obj->rtype.pobj_info.anim_angles[i],f); - obj->rtype.pobj_info.subobj_flags = read_int(f); + obj->rtype.pobj_info.subobj_flags = cfile_read_int(f); - tmo = read_int(f); + tmo = cfile_read_int(f); #ifndef EDITOR obj->rtype.pobj_info.tmap_override = convert_tmap(tmo); @@ -424,9 +341,9 @@ void read_object(object *obj,CFILE *f,int version) case RT_POWERUP: case RT_FIREBALL: - obj->rtype.vclip_info.vclip_num = convert_vclip(read_int(f)); - obj->rtype.vclip_info.frametime = read_fix(f); - obj->rtype.vclip_info.framenum = read_byte(f); + obj->rtype.vclip_info.vclip_num = convert_vclip(cfile_read_int(f)); + obj->rtype.vclip_info.frametime = cfile_read_fix(f); + obj->rtype.vclip_info.framenum = cfile_read_byte(f); break; @@ -672,36 +589,36 @@ int load_game_data(CFILE *LoadFile) if (cfseek( LoadFile, start_offset, SEEK_SET )) Error( "Error seeking to game_fileinfo in gamesave.c" ); - game_fileinfo.fileinfo_signature = read_short(LoadFile); + game_fileinfo.fileinfo_signature = cfile_read_short(LoadFile); - game_fileinfo.fileinfo_version = read_short(LoadFile); - game_fileinfo.fileinfo_sizeof = read_int(LoadFile); + game_fileinfo.fileinfo_version = cfile_read_short(LoadFile); + game_fileinfo.fileinfo_sizeof = cfile_read_int(LoadFile); for(i=0; i<15; i++) - game_fileinfo.mine_filename[i] = read_byte(LoadFile); - game_fileinfo.level = read_int(LoadFile); - game_fileinfo.player_offset = read_int(LoadFile); // Player info - game_fileinfo.player_sizeof = read_int(LoadFile); - game_fileinfo.object_offset = read_int(LoadFile); // Object info - game_fileinfo.object_howmany = read_int(LoadFile); - game_fileinfo.object_sizeof = read_int(LoadFile); - game_fileinfo.walls_offset = read_int(LoadFile); - game_fileinfo.walls_howmany = read_int(LoadFile); - game_fileinfo.walls_sizeof = read_int(LoadFile); - game_fileinfo.doors_offset = read_int(LoadFile); - game_fileinfo.doors_howmany = read_int(LoadFile); - game_fileinfo.doors_sizeof = read_int(LoadFile); - game_fileinfo.triggers_offset = read_int(LoadFile); - game_fileinfo.triggers_howmany = read_int(LoadFile); - game_fileinfo.triggers_sizeof = read_int(LoadFile); - game_fileinfo.links_offset = read_int(LoadFile); - game_fileinfo.links_howmany = read_int(LoadFile); - game_fileinfo.links_sizeof = read_int(LoadFile); - game_fileinfo.control_offset = read_int(LoadFile); - game_fileinfo.control_howmany = read_int(LoadFile); - game_fileinfo.control_sizeof = read_int(LoadFile); - game_fileinfo.matcen_offset = read_int(LoadFile); - game_fileinfo.matcen_howmany = read_int(LoadFile); - game_fileinfo.matcen_sizeof = read_int(LoadFile); + game_fileinfo.mine_filename[i] = cfile_read_byte(LoadFile); + game_fileinfo.level = cfile_read_int(LoadFile); + game_fileinfo.player_offset = cfile_read_int(LoadFile); // Player info + game_fileinfo.player_sizeof = cfile_read_int(LoadFile); + game_fileinfo.object_offset = cfile_read_int(LoadFile); // Object info + game_fileinfo.object_howmany = cfile_read_int(LoadFile); + game_fileinfo.object_sizeof = cfile_read_int(LoadFile); + game_fileinfo.walls_offset = cfile_read_int(LoadFile); + game_fileinfo.walls_howmany = cfile_read_int(LoadFile); + game_fileinfo.walls_sizeof = cfile_read_int(LoadFile); + game_fileinfo.doors_offset = cfile_read_int(LoadFile); + game_fileinfo.doors_howmany = cfile_read_int(LoadFile); + game_fileinfo.doors_sizeof = cfile_read_int(LoadFile); + game_fileinfo.triggers_offset = cfile_read_int(LoadFile); + game_fileinfo.triggers_howmany = cfile_read_int(LoadFile); + game_fileinfo.triggers_sizeof = cfile_read_int(LoadFile); + game_fileinfo.links_offset = cfile_read_int(LoadFile); + game_fileinfo.links_howmany = cfile_read_int(LoadFile); + game_fileinfo.links_sizeof = cfile_read_int(LoadFile); + game_fileinfo.control_offset = cfile_read_int(LoadFile); + game_fileinfo.control_howmany = cfile_read_int(LoadFile); + game_fileinfo.control_sizeof = cfile_read_int(LoadFile); + game_fileinfo.matcen_offset = cfile_read_int(LoadFile); + game_fileinfo.matcen_howmany = cfile_read_int(LoadFile); + game_fileinfo.matcen_sizeof = cfile_read_int(LoadFile); if (game_top_fileinfo.fileinfo_version > 25) cfseek(LoadFile,2*3*4,SEEK_CUR); // skip blastable light info if (game_top_fileinfo.fileinfo_version >= 14) { //load mine filename @@ -855,15 +772,15 @@ int load_game_data(CFILE *LoadFile) //if (cfread(&Triggers[i], game_fileinfo.triggers_sizeof,1,LoadFile)!=1) // Error( "Error reading Triggers[%d] in gamesave.c", i); if (game_top_fileinfo.fileinfo_version <= 25) { - Triggers[i].type = read_byte(LoadFile); - Triggers[i].flags = read_short(LoadFile); - Triggers[i].value = read_int(LoadFile); - Triggers[i].time = read_int(LoadFile); - Triggers[i].link_num = read_byte(LoadFile); - Triggers[i].num_links = read_short(LoadFile); + Triggers[i].type = cfile_read_byte(LoadFile); + Triggers[i].flags = cfile_read_short(LoadFile); + Triggers[i].value = cfile_read_int(LoadFile); + Triggers[i].time = cfile_read_int(LoadFile); + Triggers[i].link_num = cfile_read_byte(LoadFile); + Triggers[i].num_links = cfile_read_short(LoadFile); } else { int type; - switch (type = read_short(LoadFile)) { + switch (type = cfile_read_short(LoadFile)) { case 0: // door Triggers[i].type = 0; Triggers[i].flags = TRIGGER_CONTROL_DOORS; @@ -883,14 +800,14 @@ int load_game_data(CFILE *LoadFile) default: printf("Warning: unknown trigger type %d (%d)\n", type, i); } - Triggers[i].num_links = read_short(LoadFile); - Triggers[i].value = read_int(LoadFile); - Triggers[i].time = read_int(LoadFile); + Triggers[i].num_links = cfile_read_short(LoadFile); + Triggers[i].value = cfile_read_int(LoadFile); + Triggers[i].time = cfile_read_int(LoadFile); } for (j=0; j 25) - /*RobotCenters[i].robot_flags2 =*/ read_int(LoadFile); - RobotCenters[i].hit_points = read_fix(LoadFile); - RobotCenters[i].interval = read_fix(LoadFile); - RobotCenters[i].segnum = read_short(LoadFile); - RobotCenters[i].fuelcen_num = read_short(LoadFile); + /*RobotCenters[i].robot_flags2 =*/ cfile_read_int(LoadFile); + RobotCenters[i].hit_points = cfile_read_fix(LoadFile); + RobotCenters[i].interval = cfile_read_fix(LoadFile); + RobotCenters[i].segnum = cfile_read_short(LoadFile); + RobotCenters[i].fuelcen_num = cfile_read_short(LoadFile); // Set links in RobotCenters to Station array for (j=0; j<=Highest_segment_index; j++) if (Segments[j].special == SEGMENT_IS_ROBOTMAKER) @@ -1024,20 +941,20 @@ int load_level(char * filename_passed) if (!LoadFile) Error("Can't open file <%s>\n",filename); - sig = read_int(LoadFile); + sig = cfile_read_int(LoadFile); Assert(sig == 0x504c564c); /* 'PLVL' */ - version = read_int(LoadFile); - minedata_offset = read_int(LoadFile); - gamedata_offset = read_int(LoadFile); + version = cfile_read_int(LoadFile); + minedata_offset = cfile_read_int(LoadFile); + gamedata_offset = cfile_read_int(LoadFile); if (version == 1) - hostagetext_offset = read_int(LoadFile); + hostagetext_offset = cfile_read_int(LoadFile); else { char *p = Level_palette; do *p = cfgetc(LoadFile); while (*p++!=0x0a); - if (read_int(LoadFile) != 0x1e) + if (cfile_read_int(LoadFile) != 0x1e) Error("rl2 int 1 != 0x1e"); - if (read_int(LoadFile) != -1) + if (cfile_read_int(LoadFile) != -1) Error("rl2 int 2 != -1"); } diff --git a/main/newdemo.c b/main/newdemo.c index 9bd186129..3860433e2 100644 --- a/main/newdemo.c +++ b/main/newdemo.c @@ -72,6 +72,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "mission.h" #include "piggy.h" #include "d_glob.h" +#include "byteswap.h" #include "d_io.h" //added 05/17/99 Matt Mueller #include "u_mem.h" @@ -271,12 +272,18 @@ static void nd_write_byte(sbyte b) static void nd_write_short(short s) { - newdemo_write(&s, 2, 1); + short ss; + + ss = INTEL_SHORT(s); + newdemo_write(&ss, 2, 1); } static void nd_write_int(int i) { - newdemo_write(&i, 4, 1); + int si; + + si = INTEL_INT(i); + newdemo_write(&si, 4, 1); } static void nd_write_string(char *str) @@ -287,12 +294,18 @@ static void nd_write_string(char *str) static void nd_write_fix(fix f) { - newdemo_write(&f, sizeof(fix), 1); + int si; + + si = INTEL_INT((int)f); + newdemo_write(&si, sizeof(fix), 1); } static void nd_write_fixang(fixang f) { - newdemo_write(&f, sizeof(fixang), 1); + int si; + + si = INTEL_INT((int)f); + newdemo_write(&si, sizeof(fixang), 1); } static void nd_write_vector(vms_vector *v) @@ -346,12 +359,16 @@ static void nd_read_byte(sbyte *b) static void nd_read_short(short *s) { - newdemo_read(s, 2, 1); + short ss; + newdemo_read(&ss, 2, 1); + *s = INTEL_SHORT(ss); } static void nd_read_int(int *i) { - newdemo_read(i, 4, 1); + int si; + newdemo_read(&si, 4, 1); + *i = INTEL_INT(si); } static void nd_read_string(char *str) @@ -364,18 +381,22 @@ static void nd_read_string(char *str) static void nd_read_fix(fix *f) { - newdemo_read(f, sizeof(fix), 1); + int si; + newdemo_read(&si, sizeof(fix), 1); + *f = (fix)INTEL_INT(si); } static void nd_read_fixang(fixang *f) { - newdemo_read(f, sizeof(fixang), 1); + int si; + newdemo_read(&si, sizeof(fixang), 1); + *f = (fixang)INTEL_INT(si); } static void nd_read_vector(vms_vector *v) { - nd_read_fix(&(v->x)); - nd_read_fix(&(v->y)); + nd_read_fix(&(v->x)); + nd_read_fix(&(v->y)); nd_read_fix(&(v->z)); } @@ -416,8 +437,10 @@ object *prev_obj=NULL; //ptr to last object read in void nd_read_object(object *obj) { + sbyte b; + short s; + memset(obj, 0, sizeof(object)); - int* sig = &(obj->signature); /* * Do render type first, since with render_type == RT_NONE, we * blow by all other object information @@ -429,7 +452,8 @@ void nd_read_object(object *obj) nd_read_byte((sbyte *)&(obj->id)); nd_read_byte((sbyte *)&(obj->flags)); - nd_read_short(/*(short *)&(obj->signature)*/(short*)sig); + nd_read_short(/*(short *)&(obj->signature)*/&s); // for big endian machines + obj->signature = s; nd_read_shortpos(obj); obj->attached_obj = -1; @@ -484,8 +508,8 @@ void nd_read_object(object *obj) if ((obj->type == OBJ_WEAPON) && (obj->render_type == RT_WEAPON_VCLIP)) nd_read_fix(&(obj->lifeleft)); else { - nd_read_byte((sbyte *)&(obj->lifeleft)); - obj->lifeleft = (fix)((int)obj->lifeleft << 12); + nd_read_byte(/*(sbyte *)&(obj->lifeleft)*/ &b); // for big endian computers + obj->lifeleft = (fix)((int)b << 12); } #ifndef SHAREWARE diff --git a/main/piggy.c b/main/piggy.c index c0d9afa2b..cedb579c0 100644 --- a/main/piggy.c +++ b/main/piggy.c @@ -118,6 +118,36 @@ typedef struct DiskSoundHeader { int offset; } __pack__ DiskSoundHeader; +#ifdef FAST_FILE_IO +#define DiskBitmapHeader_read(dbh, fp) cfread(dbh, sizeof(DiskBitmapHeader), 1, fp) +#define DiskSoundHeader_read(dsh, fp) cfread(dsh, sizeof(DiskSoundHeader), 1, fp) +#else +/* + * reads a DiskBitmapHeader structure from a CFILE + */ +void DiskBitmapHeader_read(DiskBitmapHeader *dbh, CFILE *fp) +{ + cfread(dbh->name, 8, 1, fp); + dbh->dflags = cfile_read_byte(fp); + dbh->width = cfile_read_byte(fp); + dbh->height = cfile_read_byte(fp); + dbh->flags = cfile_read_byte(fp); + dbh->avg_color = cfile_read_byte(fp); + dbh->offset = cfile_read_int(fp); +} + +/* + * reads a DiskSoundHeader structure from a CFILE + */ +void DiskSoundHeader_read(DiskSoundHeader *dsh, CFILE *fp) +{ + cfread(dsh->name, 8, 1, fp); + dsh->length = cfile_read_int(fp); + dsh->data_length = cfile_read_int(fp); + dsh->offset = cfile_read_int(fp); +} +#endif // FAST_FILE_IO + #ifdef SHAREWARE static int SoundCompressed[ MAX_SOUND_FILES ]; #endif @@ -374,13 +404,14 @@ int piggy_init() #ifdef SHAREWARE Pigdata_start = 0; #else - cfread( &Pigdata_start, sizeof(int), 1, Piggy_fp ); + Pigdata_start = cfile_read_int(Piggy_fp); #ifdef EDITOR if (GameArg.EdiNoBm) #endif { bm_read_all( Piggy_fp ); // Note connection to above if!!! - cfread( GameBitmapXlat, sizeof(ushort)*MAX_BITMAP_FILES, 1, Piggy_fp ); + for (i = 0; i < MAX_BITMAP_FILES; i++) + GameBitmapXlat[i] = cfile_read_short(Piggy_fp); } #endif @@ -389,16 +420,16 @@ int piggy_init() length = size; mprintf( (0, "\nReading data (%d KB) ", size/1024 )); - cfread( &N_bitmaps, sizeof(int), 1, Piggy_fp ); + N_bitmaps = cfile_read_int(Piggy_fp); size -= sizeof(int); - cfread( &N_sounds, sizeof(int), 1, Piggy_fp ); + N_sounds = cfile_read_int(Piggy_fp); size -= sizeof(int); header_size = (N_bitmaps*sizeof(DiskBitmapHeader)) + (N_sounds*sizeof(DiskSoundHeader)); for (i=0; ibm_flags & BM_FLAG_RLE ) { int zsize = 0; descent_critical_error = 0; - temp = cfread( &zsize, 1, sizeof(int), Piggy_fp ); + zsize = cfile_read_int(Piggy_fp); if ( descent_critical_error ) { piggy_critical_error(); goto ReDoIt; @@ -1018,3 +1049,24 @@ int piggy_is_substitutable_bitmap( char * name, char * subst_name ) return 0; } +#ifndef FAST_FILE_IO +/* + * reads a bitmap_index structure from a CFILE + */ +void bitmap_index_read(bitmap_index *bi, CFILE *fp) +{ + bi->index = cfile_read_short(fp); +} + +/* + * reads n bitmap_index structs from a CFILE + */ +int bitmap_index_read_n(bitmap_index *bi, int n, CFILE *fp) +{ + int i; + + for (i = 0; i < n; i++) + bi[i].index = cfile_read_short(fp); + return i; +} +#endif // FAST_FILE_IO diff --git a/main/piggy.h b/main/piggy.h index ff949c4c7..7c8e2611e 100644 --- a/main/piggy.h +++ b/main/piggy.h @@ -172,5 +172,20 @@ do { #define PIGGY_PAGE_IN(bmp) #endif // PIGGY_USE_PAGING +#ifdef FAST_FILE_IO +#define bitmap_index_read(bi, fp) cfread(bi, sizeof(bitmap_index), 1, fp) +#define bitmap_index_read_n(bi, n, fp) cfread(bi, sizeof(bitmap_index), n, fp) +#else +/* + * reads a bitmap_index structure from a CFILE + */ +void bitmap_index_read(bitmap_index *bi, CFILE *fp); + +/* + * reads n bitmap_index structs from a CFILE + */ +int bitmap_index_read_n(bitmap_index *bi, int n, CFILE *fp); +#endif // FAST_FILE_IO + #endif // _PIGGY_H diff --git a/main/playsave.c b/main/playsave.c index 7bf583bd0..b7900d823 100644 --- a/main/playsave.c +++ b/main/playsave.c @@ -58,6 +58,7 @@ static char rcsid[] = "$Id: playsave.c,v 1.1.1.1 2006/03/17 19:42:10 zicodxx Exp #include "strutil.h" #include "strio.h" #include "vers_id.h" +#include "byteswap.h" #ifndef PATH_MAX #define PATH_MAX 255 @@ -674,6 +675,12 @@ int read_player_file() fclose(file); return errno_ret; } + info.id = INTEL_INT(info.id); + info.saved_game_version = INTEL_SHORT(info.saved_game_version); + info.player_struct_version = INTEL_SHORT(info.player_struct_version); + info.n_highest_levels = INTEL_INT(info.n_highest_levels); + info.default_difficulty_level = INTEL_INT(info.default_difficulty_level); + info.default_leveling_on = INTEL_INT(info.default_leveling_on); if (info.id!=SAVE_FILE_ID) { nm_messagebox(TXT_ERROR, 1, TXT_OK, "Invalid player file"); @@ -946,13 +953,13 @@ int write_player_file() errno_ret = WriteConfigFile(); - info.id = SAVE_FILE_ID; - info.saved_game_version = SAVED_GAME_VERSION; - info.player_struct_version = PLAYER_STRUCT_VERSION; - info.default_difficulty_level = Player_default_difficulty; - info.default_leveling_on = Auto_leveling_on; + info.id = INTEL_INT(SAVE_FILE_ID); + info.saved_game_version = INTEL_SHORT(SAVED_GAME_VERSION); + info.player_struct_version = INTEL_SHORT(PLAYER_STRUCT_VERSION); + info.default_difficulty_level = INTEL_INT(Player_default_difficulty); + info.default_leveling_on = INTEL_INT(Auto_leveling_on); - info.n_highest_levels = n_highest_levels; + info.n_highest_levels = INTEL_INT(n_highest_levels); sprintf(filename, GameArg.SysUsePlayersDir? "Players/%.8s.plx" : "%.8s.plx", Players[Player_num].callsign); write_player_d1x(filename); diff --git a/main/polyobj.c b/main/polyobj.c index 65a9905dd..1ba580488 100644 --- a/main/polyobj.c +++ b/main/polyobj.c @@ -95,7 +95,7 @@ int pof_read_int(ubyte *bufp) i = *((int *) &bufp[Pof_addr]); Pof_addr += 4; - return i; + return INTEL_INT(i); // if (cfread(&i,sizeof(i),1,f) != 1) // Error("Unexpected end-of-file while reading object"); @@ -127,7 +127,7 @@ short pof_read_short(ubyte *bufp) s = *((short *) &bufp[Pof_addr]); Pof_addr += 2; - return s; + return INTEL_SHORT(s); // if (cfread(&s,sizeof(s),1,f) != 1) // Error("Unexpected end-of-file while reading object"); // @@ -178,12 +178,12 @@ void robot_set_angles(robot_info *r,polymodel *pm,vms_angvec angs[N_ANIM_STATES] #ifdef WORDS_NEED_ALIGNMENT ubyte * old_dest(chunk o) // return where chunk is (in unaligned struct) { - return o.old_base + swapshort(*((short *)(o.old_base + o.offset))); + return o.old_base + INTEL_SHORT(*((short *)(o.old_base + o.offset))); } ubyte * new_dest(chunk o) // return where chunk is (in aligned struct) { - return o.new_base + swapshort(*((short *)(o.old_base + o.offset))) + o.correction; + return o.new_base + INTEL_SHORT(*((short *)(o.old_base + o.offset))) + o.correction; } /* @@ -238,8 +238,8 @@ void align_polygon_model_data(polymodel *pm) } //write (corrected) chunk for current chunk: *((short *)(cur_ch.new_base + cur_ch.offset)) - = swapshort(cur_ch.correction - + swapshort(*((short *)(cur_ch.old_base + cur_ch.offset)))); + = INTEL_SHORT(cur_ch.correction + + INTEL_SHORT(*((short *)(cur_ch.old_base + cur_ch.offset)))); //write (correctly aligned) chunk: cur_old = old_dest(cur_ch); cur_new = new_dest(cur_ch); @@ -290,7 +290,7 @@ polymodel *read_model_file(polymodel *pm,char *filename,robot_info *r) Error("Bad version (%d) in model file <%s>",version,filename); while (new_pof_read_int(id,model_buf) == 1) { - + id = INTEL_INT(id); //id = pof_read_int(model_buf); len = pof_read_int(model_buf); next_chunk = Pof_addr + len; @@ -465,7 +465,7 @@ int read_model_guns(char *filename,vms_vector *gun_points, vms_vector *gun_dirs, Error("Bad version (%d) in model file <%s>",version,filename); while (new_pof_read_int(id,model_buf) == 1) { - + id = INTEL_INT(id); //id = pof_read_int(model_buf); len = pof_read_int(model_buf); @@ -753,12 +753,6 @@ void draw_model_picture(int mn,vms_angvec *orient_angles) g3_end_frame(); } -extern int read_int(CFILE *file); -extern fix read_fix(CFILE *file); -extern short read_short(CFILE *file); -extern sbyte read_byte(CFILE *file); -extern void read_vector(vms_vector *v,CFILE *file); - /* * reads n polymodel structs from a CFILE */ @@ -767,30 +761,30 @@ extern int polymodel_read_n(polymodel *pm, int n, CFILE *fp) int i, j; for (i = 0; i < n; i++) { - pm[i].n_models = read_int(fp); - pm[i].model_data_size = read_int(fp); - pm[i].model_data = (ubyte *) (size_t)read_int(fp); + pm[i].n_models = cfile_read_int(fp); + pm[i].model_data_size = cfile_read_int(fp); + pm[i].model_data = (ubyte *) (size_t)cfile_read_int(fp); for (j = 0; j < MAX_SUBMODELS; j++) - pm[i].submodel_ptrs[j] = read_int(fp); + pm[i].submodel_ptrs[j] = cfile_read_int(fp); for (j = 0; j < MAX_SUBMODELS; j++) - read_vector(&(pm[i].submodel_offsets[j]), fp); + cfile_read_vector(&(pm[i].submodel_offsets[j]), fp); for (j = 0; j < MAX_SUBMODELS; j++) - read_vector(&(pm[i].submodel_norms[j]), fp); + cfile_read_vector(&(pm[i].submodel_norms[j]), fp); for (j = 0; j < MAX_SUBMODELS; j++) - read_vector(&(pm[i].submodel_pnts[j]), fp); + cfile_read_vector(&(pm[i].submodel_pnts[j]), fp); for (j = 0; j < MAX_SUBMODELS; j++) - pm[i].submodel_rads[j] = read_fix(fp); + pm[i].submodel_rads[j] = cfile_read_fix(fp); cfread(pm[i].submodel_parents, MAX_SUBMODELS, 1, fp); for (j = 0; j < MAX_SUBMODELS; j++) - read_vector(&(pm[i].submodel_mins[j]), fp); + cfile_read_vector(&(pm[i].submodel_mins[j]), fp); for (j = 0; j < MAX_SUBMODELS; j++) - read_vector(&(pm[i].submodel_maxs[j]), fp); - read_vector(&(pm[i].mins), fp); - read_vector(&(pm[i].maxs), fp); - pm[i].rad = read_fix(fp); - pm[i].n_textures = read_byte(fp); - pm[i].first_texture = read_short(fp); - pm[i].simpler_model = read_byte(fp); + cfile_read_vector(&(pm[i].submodel_maxs[j]), fp); + cfile_read_vector(&(pm[i].mins), fp); + cfile_read_vector(&(pm[i].maxs), fp); + pm[i].rad = cfile_read_fix(fp); + pm[i].n_textures = cfile_read_byte(fp); + pm[i].first_texture = cfile_read_short(fp); + pm[i].simpler_model = cfile_read_byte(fp); } return i; } @@ -807,4 +801,7 @@ void polygon_model_data_read(polymodel *pm, CFILE *fp) #ifdef WORDS_NEED_ALIGNMENT align_polygon_model_data(pm); #endif +#ifdef WORDS_BIGENDIAN + swap_polygon_model_data(pm->model_data); +#endif } diff --git a/main/powerup.c b/main/powerup.c index 0f3e2921f..bb09525ce 100644 --- a/main/powerup.c +++ b/main/powerup.c @@ -687,3 +687,21 @@ void dump_pow_count(char *title, int *pow_count) { mprintf((1, "-- powerup count different: %d\n", j)); } #endif + +#ifndef FAST_FILE_IO +/* + * reads n powerup_type_info structs from a CFILE + */ +int powerup_type_info_read_n(powerup_type_info *pti, int n, CFILE *fp) +{ + int i; + + for (i = 0; i < n; i++) { + pti[i].vclip_num = cfile_read_int(fp); + pti[i].hit_sound = cfile_read_int(fp); + pti[i].size = cfile_read_fix(fp); + pti[i].light = cfile_read_fix(fp); + } + return i; +} +#endif diff --git a/main/powerup.h b/main/powerup.h index f49ea4dc3..38194858c 100644 --- a/main/powerup.h +++ b/main/powerup.h @@ -268,5 +268,14 @@ extern void clip_player_pow_count(int *pow_count); // returns number of powerups left if true, otherwise 0. extern int may_create_powerup(int powerup); +#ifdef FAST_FILE_IO +#define powerup_type_info_read_n(pti, n, fp) cfread(pti, sizeof(powerup_type_info), n, fp) +#else +/* + * reads n powerup_type_info structs from a CFILE + */ +extern int powerup_type_info_read_n(powerup_type_info *pti, int n, CFILE *fp); #endif + +#endif /* _POWERUP_H */ diff --git a/main/robot.c b/main/robot.c index 31fa869db..528eb92e9 100644 --- a/main/robot.c +++ b/main/robot.c @@ -324,4 +324,83 @@ void robot_set_angles(robot_info *r,polymodel *pm,vms_angvec angs[N_ANIM_STATES] } +#ifndef FAST_FILE_IO +/* + * reads n robot_info structs from a CFILE + */ +int robot_info_read_n(robot_info *ri, int n, CFILE *fp) +{ + int i, j, k; + + for (i = 0; i < n; i++) { + ri[i].model_num = cfile_read_int(fp); + ri[i].n_guns = cfile_read_int(fp); + for (j = 0; j < MAX_GUNS; j++) + cfile_read_vector(&ri[i].gun_points[j], fp); + for (j = 0; j < MAX_GUNS; j++) + ri[i].gun_submodels[j] = cfile_read_byte(fp); + ri[i].exp1_vclip_num = cfile_read_short(fp); + ri[i].exp1_sound_num = cfile_read_short(fp); + ri[i].exp2_vclip_num = cfile_read_short(fp); + ri[i].exp2_sound_num = cfile_read_short(fp); + ri[i].weapon_type = cfile_read_short(fp); + ri[i].contains_id = cfile_read_byte(fp); + ri[i].contains_count = cfile_read_byte(fp); + ri[i].contains_prob = cfile_read_byte(fp); + ri[i].contains_type = cfile_read_byte(fp); + ri[i].score_value = cfile_read_int(fp); + ri[i].lighting = cfile_read_fix(fp); + ri[i].strength = cfile_read_fix(fp); + ri[i].mass = cfile_read_fix(fp); + ri[i].drag = cfile_read_fix(fp); + for (j = 0; j < NDL; j++) + ri[i].field_of_view[j] = cfile_read_fix(fp); + for (j = 0; j < NDL; j++) + ri[i].firing_wait[j] = cfile_read_fix(fp); + for (j = 0; j < NDL; j++) + ri[i].turn_time[j] = cfile_read_fix(fp); + for (j = 0; j < NDL; j++) + ri[i].fire_power[j] = cfile_read_fix(fp); + for (j = 0; j < NDL; j++) + ri[i].shield[j] = cfile_read_fix(fp); + for (j = 0; j < NDL; j++) + ri[i].max_speed[j] = cfile_read_fix(fp); + for (j = 0; j < NDL; j++) + ri[i].circle_distance[j] = cfile_read_fix(fp); + for (j = 0; j < NDL; j++) + cfread(&(ri[i].rapidfire_count[j]), sizeof(ubyte), 1, fp); + for (j = 0; j < NDL; j++) + cfread(&(ri[i].evade_speed[j]), sizeof(ubyte), 1, fp); + ri[i].cloak_type = cfile_read_byte(fp); + ri[i].attack_type = cfile_read_byte(fp); + ri[i].boss_flag = cfile_read_byte(fp); + ri[i].see_sound = cfile_read_byte(fp); + ri[i].attack_sound = cfile_read_byte(fp); + ri[i].claw_sound = cfile_read_byte(fp); + + for (j = 0; j < MAX_GUNS + 1; j++) { + for (k = 0; k < N_ANIM_STATES; k++) { + ri[i].anim_states[j][k].n_joints = cfile_read_short(fp); + ri[i].anim_states[j][k].offset = cfile_read_short(fp); + } + } + + ri[i].always_0xabcd = cfile_read_int(fp); + } + return i; +} +/* + * reads n jointpos structs from a CFILE + */ +int jointpos_read_n(jointpos *jp, int n, CFILE *fp) +{ + int i; + + for (i = 0; i < n; i++) { + jp[i].jointnum = cfile_read_short(fp); + cfile_read_angvec(&jp[i].angles, fp); + } + return i; +} +#endif diff --git a/main/robot.h b/main/robot.h index 348fab196..02d6f7c1a 100644 --- a/main/robot.h +++ b/main/robot.h @@ -227,4 +227,19 @@ void calc_gun_point(vms_vector *gun_point,object *obj,int gun_num); // jp_list_ptr is stuffed with a pointer to a static array of joint positions. This pointer is valid forever. extern int robot_get_anim_state(jointpos **jp_list_ptr,int robot_type,int gun_num,int state); +#ifdef FAST_FILE_IO +#define robot_info_read_n(ri, n, fp) cfread(ri, sizeof(robot_info), n, fp) +#define jointpos_read_n(jp, n, fp) cfread(jp, sizeof(jointpos), n, fp) +#else +/* + * reads n robot_info structs from a CFILE + */ +extern int robot_info_read_n(robot_info *ri, int n, CFILE *fp); + +/* + * reads n jointpos structs from a CFILE + */ +extern int jointpos_read_n(jointpos *jp, int n, CFILE *fp); +#endif + #endif diff --git a/main/scores.c b/main/scores.c index 0886ed710..100961b6e 100644 --- a/main/scores.c +++ b/main/scores.c @@ -47,6 +47,7 @@ static char rcsid[] = "$Id: scores.c,v 1.1.1.1 2006/03/17 19:42:39 zicodxx Exp $ #include "timer.h" #include "text.h" #include "d_io.h" +#include "byteswap.h" #ifdef OGL #include "ogl_init.h" @@ -110,7 +111,7 @@ char * get_scores_filename() void scores_read() { FILE * fp; - int fsize; + int fsize, i; // clear score array... memset( &Scores, 0, sizeof(all_scores) ); @@ -143,8 +144,27 @@ void scores_read() fclose(fp); return; } + // Read 'em in... - fread( &Scores, sizeof(all_scores),1, fp ); + fread( Scores.signature, 3, 1, fp); + fread( &(Scores.version), 1, 1, fp); + fread( Scores.cool_saying, COOL_MESSAGE_LEN, 1, fp); + for (i = 0; i < MAX_HIGH_SCORES; i++) { + fread( Scores.stats[i].name, CALLSIGN_LEN+1, 1, fp); + fread( &(Scores.stats[i].score), 4, 1, fp); + fread( &(Scores.stats[i].starting_level), 1, 1, fp); + fread( &(Scores.stats[i].ending_level), 1, 1, fp); + fread( &(Scores.stats[i].diff_level), 1, 1, fp); + fread( &(Scores.stats[i].kill_ratio), 2, 1, fp); + fread( &(Scores.stats[i].hostage_ratio), 2, 1, fp); + fread( &(Scores.stats[i].seconds), 4, 1, fp); + + Scores.stats[i].score = INTEL_INT(Scores.stats[i].score); + Scores.stats[i].kill_ratio = INTEL_SHORT(Scores.stats[i].kill_ratio); + Scores.stats[i].hostage_ratio = INTEL_SHORT(Scores.stats[i].hostage_ratio); + Scores.stats[i].seconds = INTEL_INT(Scores.stats[i].seconds); + } + fclose(fp); if ( (Scores.version!=VERSION_NUMBER)||(Scores.signature[0]!='D')||(Scores.signature[1]!='H')||(Scores.signature[2]!='S') ) { @@ -156,6 +176,7 @@ void scores_read() void scores_write() { FILE * fp; + int i; fp = fopen( get_scores_filename(), "wb" ); if (fp==NULL) { @@ -167,7 +188,30 @@ void scores_write() Scores.signature[1]='H'; Scores.signature[2]='S'; Scores.version = VERSION_NUMBER; - fwrite( &Scores,sizeof(all_scores),1, fp ); + fwrite( Scores.signature, 3, 1, fp); + fwrite( &(Scores.version), 1, 1, fp); + fwrite( Scores.cool_saying, COOL_MESSAGE_LEN, 1, fp); + for (i = 0; i < MAX_HIGH_SCORES; i++) { + Scores.stats[i].score = INTEL_INT(Scores.stats[i].score); + Scores.stats[i].kill_ratio = INTEL_SHORT(Scores.stats[i].kill_ratio); + Scores.stats[i].hostage_ratio = INTEL_SHORT(Scores.stats[i].hostage_ratio); + Scores.stats[i].seconds = INTEL_INT(Scores.stats[i].seconds); + + fwrite( Scores.stats[i].name, CALLSIGN_LEN+1, 1, fp); + fwrite( &(Scores.stats[i].score), 4, 1, fp); + fwrite( &(Scores.stats[i].starting_level), 1, 1, fp); + fwrite( &(Scores.stats[i].ending_level), 1, 1, fp); + fwrite( &(Scores.stats[i].diff_level), 1, 1, fp); + fwrite( &(Scores.stats[i].kill_ratio), 2, 1, fp); + fwrite( &(Scores.stats[i].hostage_ratio), 2, 1, fp); + fwrite( &(Scores.stats[i].seconds), 4, 1, fp); + + Scores.stats[i].score = INTEL_INT(Scores.stats[i].score); + Scores.stats[i].kill_ratio = INTEL_SHORT(Scores.stats[i].kill_ratio); + Scores.stats[i].hostage_ratio = INTEL_SHORT(Scores.stats[i].hostage_ratio); + Scores.stats[i].seconds = INTEL_INT(Scores.stats[i].seconds); + + } fclose(fp); } diff --git a/main/switch.c b/main/switch.c index 251f34572..4797fffdf 100644 --- a/main/switch.c +++ b/main/switch.c @@ -414,3 +414,23 @@ void triggers_frame_process() Triggers[i].time -= FrameTime; } +#ifndef FAST_FILE_IO +/* + * reads a v29_trigger structure from a CFILE + */ +extern void trigger_read(trigger *t, CFILE *fp) +{ + int i; + + t->type = cfile_read_byte(fp); + t->flags = cfile_read_short(fp); + t->value = cfile_read_fix(fp); + t->time = cfile_read_fix(fp); + t->link_num = cfile_read_byte(fp); + t->num_links = cfile_read_short(fp); + for (i=0; iseg[i] = cfile_read_short(fp); + for (i=0; iside[i] = cfile_read_short(fp); +} +#endif diff --git a/main/switch.h b/main/switch.h index 28efbb4d5..57985f7b7 100644 --- a/main/switch.h +++ b/main/switch.h @@ -132,5 +132,14 @@ extern int check_trigger_sub(int trigger_num, int player_num); extern void triggers_frame_process(); +#ifdef FAST_FILE_IO +#define trigger_read(t, fp) cfread(t, sizeof(trigger), 1, fp) +#else +/* + * reads a trigger structure from a CFILE + */ +extern void trigger_read(trigger *t, CFILE *fp); +#endif + #endif diff --git a/main/vclip.c b/main/vclip.c index 65a892328..0aa43c545 100644 --- a/main/vclip.c +++ b/main/vclip.c @@ -125,3 +125,25 @@ void draw_weapon_vclip(object *obj) } +#ifndef FAST_FILE_IO +/* + * reads n vclip structs from a CFILE + */ +int vclip_read_n(vclip *vc, int n, CFILE *fp) +{ + int i, j; + + for (i = 0; i < n; i++) { + vc[i].play_time = cfile_read_fix(fp); + vc[i].num_frames = cfile_read_int(fp); + vc[i].frame_time = cfile_read_fix(fp); + vc[i].flags = cfile_read_int(fp); + vc[i].sound_num = cfile_read_short(fp); + for (j = 0; j < VCLIP_MAX_FRAMES; j++) + vc[i].frames[j].index = cfile_read_short(fp); + vc[i].light_value = cfile_read_fix(fp); + } + return i; +} +#endif + diff --git a/main/vclip.h b/main/vclip.h index 553ff2b94..2c9be4b4b 100644 --- a/main/vclip.h +++ b/main/vclip.h @@ -174,5 +174,14 @@ extern vclip Vclip[VCLIP_MAXNUM]; void draw_vclip_object(object *obj,fix timeleft,int lighted, int vclip_num); extern void draw_weapon_vclip(object *obj); +#ifdef FAST_FILE_IO +#define vclip_read_n(vc, n, fp) cfread(vc, sizeof(vclip), n, fp) +#else +/* + * reads n vclip structs from a CFILE + */ +extern int vclip_read_n(vclip *vc, int n, CFILE *fp); #endif - + +#endif /* _VCLIP_H */ + diff --git a/main/wall.c b/main/wall.c index 642e9c2c5..5f1dbc798 100644 --- a/main/wall.c +++ b/main/wall.c @@ -968,3 +968,102 @@ void kill_stuck_objects(int wallnum) Num_stuck_objects++; } +#ifndef FAST_FILE_IO +/* + * reads a wclip structure from a CFILE + */ +int wclip_read_n(wclip *wc, int n, CFILE *fp) +{ + int i, j; + + for (i = 0; i < n; i++) { + WallAnims[i].play_time = cfile_read_fix(fp);; + WallAnims[i].num_frames = cfile_read_short(fp);; + for (j = 0; j < MAX_CLIP_FRAMES; j++) + WallAnims[i].frames[j] = cfile_read_short(fp); + WallAnims[i].open_sound = cfile_read_short(fp); + WallAnims[i].close_sound = cfile_read_short(fp); + WallAnims[i].flags = cfile_read_short(fp); + cfread(WallAnims[i].filename, 13, 1, fp); + WallAnims[i].pad = cfile_read_byte(fp); + } + return i; +} + +/* + * reads a v16_wall structure from a CFILE + */ +extern void v16_wall_read(v16_wall *w, CFILE *fp) +{ + w->type = cfile_read_byte(fp); + w->flags = cfile_read_byte(fp); + w->hps = cfile_read_fix(fp); + w->trigger = cfile_read_byte(fp); + w->clip_num = cfile_read_byte(fp); + w->keys = cfile_read_byte(fp); +} + +/* + * reads a v19_wall structure from a CFILE + */ +extern void v19_wall_read(v19_wall *w, CFILE *fp) +{ + w->segnum = cfile_read_int(fp); + w->sidenum = cfile_read_int(fp); + w->type = cfile_read_byte(fp); + w->flags = cfile_read_byte(fp); + w->hps = cfile_read_fix(fp); + w->trigger = cfile_read_byte(fp); + w->clip_num = cfile_read_byte(fp); + w->keys = cfile_read_byte(fp); + w->linked_wall = cfile_read_int(fp); +} + +/* + * reads a wall structure from a CFILE + */ +extern void wall_read(wall *w, CFILE *fp) +{ + w->segnum = cfile_read_int(fp); + w->sidenum = cfile_read_int(fp); + w->hps = cfile_read_fix(fp); + w->linked_wall = cfile_read_int(fp); + w->type = cfile_read_byte(fp); + w->flags = cfile_read_byte(fp); + w->state = cfile_read_byte(fp); + w->trigger = cfile_read_byte(fp); + w->clip_num = cfile_read_byte(fp); + w->keys = cfile_read_byte(fp); + /*w->controlling_trigger =*/ cfile_read_byte(fp); + /*w->cloak_value =*/ cfile_read_byte(fp); +} + +/* + * reads a v19_door structure from a CFILE + */ +extern void v19_door_read(v19_door *d, CFILE *fp) +{ + d->n_parts = cfile_read_int(fp); + d->seg[0] = cfile_read_short(fp); + d->seg[1] = cfile_read_short(fp); + d->side[0] = cfile_read_short(fp); + d->side[1] = cfile_read_short(fp); + d->type[0] = cfile_read_short(fp); + d->type[1] = cfile_read_short(fp); + d->open = cfile_read_fix(fp); +} + +/* + * reads an active_door structure from a CFILE + */ +extern void active_door_read(active_door *ad, CFILE *fp) +{ + ad->n_parts = cfile_read_int(fp); + ad->front_wallnum[0] = cfile_read_short(fp); + ad->front_wallnum[1] = cfile_read_short(fp); + ad->back_wallnum[0] = cfile_read_short(fp); + ad->back_wallnum[1] = cfile_read_short(fp); + ad->time = cfile_read_fix(fp); +} +#endif + diff --git a/main/wall.h b/main/wall.h index 034ad16ee..c2f62a805 100644 --- a/main/wall.h +++ b/main/wall.h @@ -173,6 +173,38 @@ typedef struct stuckobj { int signature; } stuckobj; +//Start old wall structures + +typedef struct v16_wall { + sbyte type; // What kind of special wall. + sbyte flags; // Flags for the wall. + fix hps; // "Hit points" of the wall. + sbyte trigger; // Which trigger is associated with the wall. + sbyte clip_num; // Which animation associated with the wall. + sbyte keys; +} __pack__ v16_wall; + +typedef struct v19_wall { + int segnum,sidenum; // Seg & side for this wall + sbyte type; // What kind of special wall. + sbyte flags; // Flags for the wall. + fix hps; // "Hit points" of the wall. + sbyte trigger; // Which trigger is associated with the wall. + sbyte clip_num; // Which animation associated with the wall. + sbyte keys; + int linked_wall; // number of linked wall +} __pack__ v19_wall; + +typedef struct v19_door { + int n_parts; // for linked walls + short seg[2]; // Segment pointer of door. + short side[2]; // Side number of door. + short type[2]; // What kind of door animation. + fix open; // How long it has been open. +} __pack__ v19_door; + +//End old wall structures + typedef struct wall { int segnum,sidenum; // Seg & side for this wall fix hps; // "Hit points" of the wall. @@ -284,4 +316,43 @@ extern void remove_obsolete_stuck_objects(void); //set the tmap_num or tmap_num2 field for a wall/door extern void wall_set_tmap_num(segment *seg,int side,segment *csegp,int cside,int anim_num,int frame_num); +#ifdef FAST_FILE_IO +#define wclip_read_n(wc, n, fp) cfread(wc, sizeof(wclip), n, fp) +#define v16_wall_read(w, fp) cfread(w, sizeof(v16_wall), 1, fp) +#define v19_wall_read(w, fp) cfread(w, sizeof(v19_wall), 1, fp) +#define wall_read(w, fp) cfread(w, sizeof(wall), 1, fp) +#define v19_door_read(d, fp) cfread(d, sizeof(v19_door), 1, fp) +#define active_door_read(d, fp) cfread(d, sizeof(active_door), 1, fp) +#else +/* + * reads n wclip structs from a CFILE + */ +extern int wclip_read_n(wclip *wc, int n, CFILE *fp); + +/* + * reads a v16_wall structure from a CFILE + */ +extern void v16_wall_read(v16_wall *w, CFILE *fp); + +/* + * reads a v19_wall structure from a CFILE + */ +extern void v19_wall_read(v19_wall *w, CFILE *fp); + +/* + * reads a wall structure from a CFILE + */ +extern void wall_read(wall *w, CFILE *fp); + +/* + * reads a v19_door structure from a CFILE + */ +extern void v19_door_read(v19_door *d, CFILE *fp); + +/* + * reads an active_door structure from a CFILE + */ +extern void active_door_read(active_door *ad, CFILE *fp); +#endif + #endif diff --git a/main/weapon.c b/main/weapon.c index 5b7fe504e..0d5748a80 100644 --- a/main/weapon.c +++ b/main/weapon.c @@ -448,3 +448,55 @@ int pick_up_ammo(int class_flag,int weapon_index,int ammo_count) return 1; } + +/* + * reads n weapon_info structs from a CFILE + */ +int weapon_info_read_n(weapon_info *wi, int n, CFILE *fp) +{ + int i, j; + + for (i = 0; i < n; i++) { + wi[i].render_type = cfile_read_byte(fp); + wi[i].model_num = cfile_read_byte(fp); + wi[i].model_num_inner = cfile_read_byte(fp); + wi[i].persistent = cfile_read_byte(fp); + wi[i].flash_vclip = cfile_read_byte(fp); + wi[i].flash_sound = cfile_read_short(fp); + wi[i].robot_hit_vclip = cfile_read_byte(fp); + wi[i].robot_hit_sound = cfile_read_short(fp); + wi[i].wall_hit_vclip = cfile_read_byte(fp); + wi[i].wall_hit_sound = cfile_read_short(fp); + wi[i].fire_count = cfile_read_byte(fp); + wi[i].ammo_usage = cfile_read_byte(fp); + wi[i].weapon_vclip = cfile_read_byte(fp); + wi[i].destroyable = cfile_read_byte(fp); + wi[i].matter = cfile_read_byte(fp); + wi[i].bounce = cfile_read_byte(fp); + wi[i].homing_flag = cfile_read_byte(fp); + wi[i].dum1 = cfile_read_byte(fp); + wi[i].dum2 = cfile_read_byte(fp); + wi[i].dum3 = cfile_read_byte(fp); + wi[i].energy_usage = cfile_read_fix(fp); + wi[i].fire_wait = cfile_read_fix(fp); + wi[i].bitmap.index = cfile_read_short(fp); // bitmap_index = short + wi[i].blob_size = cfile_read_fix(fp); + wi[i].flash_size = cfile_read_fix(fp); + wi[i].impact_size = cfile_read_fix(fp); + for (j = 0; j < NDL; j++) + wi[i].strength[j] = cfile_read_fix(fp); + for (j = 0; j < NDL; j++) + wi[i].speed[j] = cfile_read_fix(fp); + wi[i].mass = cfile_read_fix(fp); + wi[i].drag = cfile_read_fix(fp); + wi[i].thrust = cfile_read_fix(fp); + + wi[i].po_len_to_width_ratio = cfile_read_fix(fp); + wi[i].light = cfile_read_fix(fp); + wi[i].lifetime = cfile_read_fix(fp); + wi[i].damage_radius = cfile_read_fix(fp); + wi[i].picture.index = cfile_read_short(fp); // bitmap_index is a short + } + return i; +} + diff --git a/main/weapon.h b/main/weapon.h index 8e85beeb2..3c58b658f 100644 --- a/main/weapon.h +++ b/main/weapon.h @@ -286,4 +286,9 @@ int pick_up_ammo(int class_flag,int weapon_index,int ammo_count); extern void maybe_select_primary(int weapon_index); extern void maybe_select_secondary(int weapon_index); +/* + * reads n weapon_info structs from a CFILE + */ +extern int weapon_info_read_n(weapon_info *wi, int n, CFILE *fp); + #endif