From 546221a7e1333c0bb59085874e1ab1dc63384bc0 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Fri, 19 Oct 2001 08:06:20 +0000 Subject: [PATCH] Partial application of linux/alpha patch. Courtesy of Falk Hueffner --- 2d/bitmap.h | 4 +++- 3d/interp.c | 11 ++++++--- acconfig.h | 3 +++ cfile/cfile.c | 37 +++++++++++++++++++++--------- include/cfile.h | 6 +++++ main/bm.c | 60 ++++++++++++++++++++++++++++--------------------- mem/mem.c | 23 +++++++++++-------- misc/fileutil.c | 16 ------------- misc/fileutil.h | 2 -- 9 files changed, 94 insertions(+), 68 deletions(-) diff --git a/2d/bitmap.h b/2d/bitmap.h index 1c4d1f04..736ec581 100644 --- a/2d/bitmap.h +++ b/2d/bitmap.h @@ -59,10 +59,12 @@ again_ddn: static void decode_data_asm(ubyte *data, int num_pixels, ubyte *colormap, int *count) { int i; + ubyte mapped; for (i = 0; i < num_pixels; i++) { count[*data]++; - *data = colormap[*data]; + mapped = *data; + *data = colormap[mapped]; data++; } } diff --git a/3d/interp.c b/3d/interp.c index 8d269636..3854d4f2 100644 --- a/3d/interp.c +++ b/3d/interp.c @@ -12,13 +12,16 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ /* * $Source: /cvs/cvsroot/d2x/3d/interp.c,v $ - * $Revision: 1.2 $ + * $Revision: 1.3 $ * $Author: bradleyb $ - * $Date: 2001-01-31 15:17:48 $ + * $Date: 2001-10-19 08:06:20 $ * * Polygon object interpreter * * $Log: not supported by cvs2svn $ + * Revision 1.2 2001/01/31 15:17:48 bradleyb + * Makefile and conf.h fixes + * * Revision 1.1.1.1 2001/01/19 03:29:58 bradleyb * Import of d2x-0.0.8 * @@ -48,7 +51,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef RCS -static char rcsid[] = "$Id: interp.c,v 1.2 2001-01-31 15:17:48 bradleyb Exp $"; +static char rcsid[] = "$Id: interp.c,v 1.3 2001-10-19 08:06:20 bradleyb Exp $"; #endif #include @@ -525,6 +528,8 @@ void init_model_sub(ubyte *p) case OP_GLOW: p += 4; break; + default: + Assert(0); } } } diff --git a/acconfig.h b/acconfig.h index 1a9d3863..07b9a8fc 100644 --- a/acconfig.h +++ b/acconfig.h @@ -16,6 +16,9 @@ /* Define to disable asserts, int3, etc. */ #undef NDEBUG +/* Define to enable cross-platform bitmap/palette loading functions */ +#undef PORTABLE_LOADER + @BOTTOM@ /* General defines */ diff --git a/cfile/cfile.c b/cfile/cfile.c index 99df140f..7418ba32 100644 --- a/cfile/cfile.c +++ b/cfile/cfile.c @@ -431,10 +431,10 @@ void cfclose( CFILE * fp ) int cfile_read_int(CFILE *file) { - int i; + int32_t i; if (cfread( &i, sizeof(i), 1, file) != 1) - Error( "Error reading short in cfile_read_int()" ); + Error( "Error reading int in cfile_read_int()" ); i = INTEL_INT(i); return i; @@ -442,7 +442,7 @@ int cfile_read_int(CFILE *file) short cfile_read_short(CFILE *file) { - short s; + int16_t s; if (cfread( &s, sizeof(s), 1, file) != 1) Error( "Error reading short in cfile_read_short()" ); @@ -461,23 +461,38 @@ byte cfile_read_byte(CFILE *file) return b; } -#if 0 -fix read_fix(CFILE *file) +fix cfile_read_fix(CFILE *file) { fix f; if (cfread( &f, sizeof(f), 1, file) != 1) - Error( "Error reading fix in gamesave.c" ); + Error( "Error reading fix in cfile_read_fix()" ); f = (fix)INTEL_INT((int)f); return f; } -static void read_vector(vms_vector *v,CFILE *file) +fixang cfile_read_fixang(CFILE *file) { - v->x = read_fix(file); - v->y = read_fix(file); - v->z = read_fix(file); + fixang f; + + if (cfread(&f, 2, 1, file) != 1) + Error("Error reading fixang in cfile_read_fixang()"); + + f = (fixang) INTEL_SHORT((int) f); + return f; } -#endif +void cfile_read_vector(vms_vector *v, CFILE *file) +{ + v->x = 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); +} diff --git a/include/cfile.h b/include/cfile.h index ae8bcab7..7a7c6bfe 100644 --- a/include/cfile.h +++ b/include/cfile.h @@ -16,6 +16,9 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #ifndef _CFILE_H #define _CFILE_H +#include "maths.h" +#include "vecmat.h" + typedef struct CFILE { FILE *file; int size; @@ -54,5 +57,8 @@ void cfile_set_critical_error_counter_ptr(int *ptr); int cfile_read_int(CFILE *file); short cfile_read_short(CFILE *file); byte cfile_read_byte(CFILE *file); +fix cfile_read_fix(CFILE *file); +void cfile_read_vector(vms_vector *v, CFILE *file); +void cfile_read_angvec(vms_angvec *v, CFILE *file); #endif diff --git a/main/bm.c b/main/bm.c index f432b0a1..98092f5f 100644 --- a/main/bm.c +++ b/main/bm.c @@ -11,14 +11,22 @@ AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ +/* + * $Source: /cvs/cvsroot/d2x/main/bm.c,v $ + * $Revision: 1.4 $ + * $Author: bradleyb $ + * $Date: 2001-10-19 08:06:20 $ + * + * Bitmap and palette loading functions. + * + * $Log: not supported by cvs2svn $ + * + */ + #ifdef HAVE_CONFIG_H #include #endif -#ifdef RCS -static char rcsid[] = "$Id: bm.c,v 1.3 2001-01-31 15:17:49 bradleyb Exp $"; -#endif - #include #include @@ -87,7 +95,7 @@ int First_multi_bitmap_num=-1; bitmap_index ObjBitmaps[MAX_OBJ_BITMAPS]; ushort ObjBitmapPtrs[MAX_OBJ_BITMAPS]; // These point back into ObjBitmaps, since some are used twice. -#ifdef MACINTOSH +#ifdef PORTABLE_LOADER void read_tmap_info(CFILE *fp, int inNumTexturesToRead, int inOffset) { int i; @@ -359,23 +367,23 @@ void read_polygon_models(CFILE *fp, int inNumPolygonModelsToRead, int inOffset) { Polygon_models[i].n_models = cfile_read_int(fp); Polygon_models[i].model_data_size = cfile_read_int(fp); - Polygon_models[i].model_data = (ubyte *)read_int_swap(fp); + Polygon_models[i].model_data = (ubyte *) cfile_read_int(fp); for (j = 0; j < MAX_SUBMODELS; j++) Polygon_models[i].submodel_ptrs[j] = cfile_read_int(fp); for (j = 0; j < MAX_SUBMODELS; j++) - cfile_read_vector(&(Polygon_models[i].submodel_offsets), fp); + cfile_read_vector(&(Polygon_models[i].submodel_offsets[j]), fp); for (j = 0; j < MAX_SUBMODELS; j++) - cfile_read_vector(&(Polygon_models[i].submodel_norms), fp); + cfile_read_vector(&(Polygon_models[i].submodel_norms[j]), fp); for (j = 0; j < MAX_SUBMODELS; j++) - cfile_read_vector(&(Polygon_models[i].submodel_pnts), fp); + cfile_read_vector(&(Polygon_models[i].submodel_pnts[j]), fp); for (j = 0; j < MAX_SUBMODELS; j++) Polygon_models[i].submodel_rads[j] = cfile_read_fix(fp); for (j = 0; j < MAX_SUBMODELS; j++) Polygon_models[i].submodel_parents[j] = cfile_read_byte(fp); for (j = 0; j < MAX_SUBMODELS; j++) - cfile_read_vector(&(Polygon_models[i].submodel_mins), fp); + cfile_read_vector(&(Polygon_models[i].submodel_mins[j]), fp); for (j = 0; j < MAX_SUBMODELS; j++) - cfile_read_vector(&(Polygon_models[i].submodel_maxs), fp); + cfile_read_vector(&(Polygon_models[i].submodel_maxs[j]), fp); cfile_read_vector(&(Polygon_models[i].mins), fp); cfile_read_vector(&(Polygon_models[i].maxs), fp); Polygon_models[i].rad = cfile_read_fix(fp); @@ -411,9 +419,9 @@ void read_reactor_info(CFILE *fp, int inNumReactorsToRead, int inOffset) Reactors[i].model_num = cfile_read_int(fp); Reactors[i].n_guns = cfile_read_int(fp); for (j = 0; j < MAX_CONTROLCEN_GUNS; j++) - cfile_read_vector(&(Reactors[i].gun_points), fp); + cfile_read_vector(&(Reactors[i].gun_points[j]), fp); for (j = 0; j < MAX_CONTROLCEN_GUNS; j++) - cfile_read_vector(&(Reactors[i].gun_dirs), fp); + cfile_read_vector(&(Reactors[i].gun_dirs[j]), fp); } } @@ -489,7 +497,7 @@ void load_exit_models() exit_modelnum = N_polygon_models++; destroyed_exit_modelnum = N_polygon_models++; - #ifndef MACINTOSH +#ifndef PORTABLE_LOADER cfread( &Polygon_models[exit_modelnum], sizeof(polymodel), 1, exit_hamfile ); cfread( &Polygon_models[destroyed_exit_modelnum], sizeof(polymodel), 1, exit_hamfile ); #else @@ -545,7 +553,7 @@ void load_exit_models() } #endif // SHAREWARE -#endif // MACINTOSH +#endif // PORTABLE_LOADER //----------------------------------------------------------------- // Read data from piggy. @@ -571,7 +579,7 @@ void bm_read_all(CFILE * fp) int i,t; NumTextures = cfile_read_int(fp); -#ifndef MACINTOSH +#ifndef PORTABLE_LOADER cfread( Textures, sizeof(bitmap_index), NumTextures, fp ); cfread( TmapInfo, sizeof(tmap_info), NumTextures, fp ); #else @@ -585,55 +593,55 @@ void bm_read_all(CFILE * fp) cfread( AltSounds, sizeof(ubyte), t, fp ); Num_vclips = cfile_read_int(fp); -#ifndef MACINTOSH +#ifndef PORTABLE_LOADER cfread( Vclip, sizeof(vclip), Num_vclips, fp ); #else read_vclip_info(fp, Num_vclips, 0); #endif Num_effects = cfile_read_int(fp); -#ifndef MACINTOSH +#ifndef PORTABLE_LOADER cfread( Effects, sizeof(eclip), Num_effects, fp ); #else read_effect_info(fp, Num_effects, 0); #endif Num_wall_anims = cfile_read_int(fp); -#ifndef MACINTOSH +#ifndef PORTABLE_LOADER cfread( WallAnims, sizeof(wclip), Num_wall_anims, fp ); #else read_wallanim_info(fp, Num_wall_anims, 0); #endif N_robot_types = cfile_read_int(fp); -#ifndef MACINTOSH +#ifndef PORTABLE_LOADER cfread( Robot_info, sizeof(robot_info), N_robot_types, fp ); #else read_robot_info(fp, N_robot_types, 0); #endif N_robot_joints = cfile_read_int(fp); -#ifndef MACINTOSH +#ifndef PORTABLE_LOADER cfread( Robot_joints, sizeof(jointpos), N_robot_joints, fp ); #else read_robot_joint_info(fp, N_robot_joints, 0); #endif N_weapon_types = cfile_read_int(fp); -#ifndef MACINTOSH +#ifndef PORTABLE_LOADER cfread( Weapon_info, sizeof(weapon_info), N_weapon_types, fp ); #else read_weapon_info(fp, N_weapon_types, 0); #endif N_powerup_types = cfile_read_int(fp); -#ifndef MACINTOSH +#ifndef PORTABLE_LOADER cfread( Powerup_info, sizeof(powerup_type_info), N_powerup_types, fp ); #else read_powerup_info(fp, N_powerup_types, 0); #endif N_polygon_models = cfile_read_int(fp); -#ifndef MACINTOSH +#ifndef PORTABLE_LOADER cfread( Polygon_models, sizeof(polymodel), N_polygon_models, fp ); #else read_polygon_models(fp, N_polygon_models, 0); @@ -682,7 +690,7 @@ void bm_read_all(CFILE * fp) } #endif -#ifndef MACINTOSH +#ifndef PORTABLE_LOADER cfread( &only_player_ship, sizeof(player_ship), 1, fp ); #else read_player_ship(fp); @@ -690,7 +698,7 @@ void bm_read_all(CFILE * fp) Num_cockpits = cfile_read_int(fp); cfread( cockpit_bitmap, sizeof(bitmap_index), Num_cockpits, fp ); -#ifdef MACINTOSH +#ifdef PORTABLE_LOADER for (i = 0; i < Num_cockpits; i++) cockpit_bitmap[i].index = SWAPSHORT(cockpit_bitmap[i].index); #endif diff --git a/mem/mem.c b/mem/mem.c index f1c3ed33..e5511b1d 100644 --- a/mem/mem.c +++ b/mem/mem.c @@ -11,12 +11,21 @@ AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ - -#ifdef RCS -static char rcsid[] = "$Id: mem.c,v 1.4 2001-08-02 22:02:37 thimo Exp $"; +/* + * $Source: /cvs/cvsroot/d2x/mem/mem.c,v $ + * $Revision: 1.5 $ + * $Author: bradleyb $ + * $Date: 2001-10-19 08:06:20 $ + * + * Files for debugging memory allocator + * + * $Log: not supported by cvs2svn $ + */ + +#ifdef HAVE_CONFIG_H +#include #endif - // Warning( "MEM: Too many malloc's!" ); // Warning( "MEM: Malloc returnd an already alloced block!" ); // Warning( "MEM: Malloc Failed!" ); @@ -25,7 +34,6 @@ static char rcsid[] = "$Id: mem.c,v 1.4 2001-08-02 22:02:37 thimo Exp $"; // Warning( "MEM: %d/%d check bytes were overwritten at the end of %8x", ec, CHECKSIZE, buffer ); // Warning( "MEM: %d blocks were left allocated!", numleft ); -#include #include #include #include @@ -160,7 +168,6 @@ void PrintInfo( int id ) void * mem_malloc( unsigned int size, char * var, char * filename, int line, int fill_zero ) { - void *base; int i, id; void *ptr; char * pc; @@ -230,9 +237,7 @@ void * mem_malloc( unsigned int size, char * var, char * filename, int line, int Error( "MEM_OUT_OF_MEMORY" ); } - base = (void *)ptr; - - MallocBase[id] = (void *)ptr; + MallocBase[id] = ptr; MallocSize[id] = size; Varname[id] = var; Filename[id] = filename; diff --git a/misc/fileutil.c b/misc/fileutil.c index cc9e70f9..e6c39c75 100644 --- a/misc/fileutil.c +++ b/misc/fileutil.c @@ -63,14 +63,6 @@ int read_int(CFILE *fp) return i; } -int read_int_swap(CFILE *fp) -{ - uint i; - - cfread(&i, sizeof(uint), 1, fp); - return swapint(i); -} - fix read_fix(CFILE *fp) { fix f; @@ -79,14 +71,6 @@ fix read_fix(CFILE *fp) return f; } -fix read_fix_swap(CFILE *fp) -{ - fix f; - - cfread(&f, sizeof(fix), 1, fp); - return (fix)swapint((uint)f); -} - int write_byte(FILE *fp, byte b) { return (fwrite(&b, sizeof(byte), 1, fp)); diff --git a/misc/fileutil.h b/misc/fileutil.h index 885a688d..da8110cc 100644 --- a/misc/fileutil.h +++ b/misc/fileutil.h @@ -29,8 +29,6 @@ extern fix read_fix(CFILE *fp); // versions which swap bytes #define read_byte_swap(fp) read_byte(fp) extern short read_short_swap(CFILE *fp); -extern int read_int_swap(CFILE *fp); -extern fix read_fix_swap(CFILE *fp); // routines which write basic data types extern int write_byte(FILE *fp, byte b); -- 2.39.2