From 6a01ae9f1b01864e68f4b166344f7354a2749a33 Mon Sep 17 00:00:00 2001 From: Martin Schaffner Date: Sat, 26 Jun 2004 16:27:17 +0000 Subject: [PATCH] remove some unneccesary globals --- ChangeLog | 5 + main/gamemine.c | 10 +- main/gamemine.h | 5 +- main/gamesave.c | 464 +++++++++++++++++++----------------------------- 4 files changed, 198 insertions(+), 286 deletions(-) diff --git a/ChangeLog b/ChangeLog index ca4b085b..3fc8059b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2004-06-26 Chris Taylor + + * main/gamemine.c, main/gamemine.h, main/gamesave.c: remove some + unnecessary globals + 2004-06-01 Bradley Bell * libmve/mve_main.c: cast malloc function pointer diff --git a/main/gamemine.c b/main/gamemine.c index 2fac73ae..eabf801a 100644 --- a/main/gamemine.c +++ b/main/gamemine.c @@ -1,4 +1,4 @@ -/* $Id: gamemine.c,v 1.26 2003-10-22 15:00:37 schaffner Exp $ */ +/* $Id: gamemine.c,v 1.27 2004-06-26 16:27:17 schaffner Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -142,7 +142,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef RCS -static char rcsid[] = "$Id: gamemine.c,v 1.26 2003-10-22 15:00:37 schaffner Exp $"; +static char rcsid[] = "$Id: gamemine.c,v 1.27 2004-06-26 16:27:17 schaffner Exp $"; #endif #include @@ -186,10 +186,12 @@ fix Level_shake_frequency = 0, Level_shake_duration = 0; int Secret_return_segment = 0; vms_matrix Secret_return_orient; -struct mtfi mine_top_fileinfo; // Should be same as first two fields below... +#if 0 +struct mtfi mine_top_fileinfo; // Should be same as first two fields below... struct mfi mine_fileinfo; struct mh mine_header; struct me mine_editor; +#endif // 0 typedef struct v16_segment { #ifdef EDITOR @@ -211,6 +213,7 @@ typedef struct v16_segment { #endif } v16_segment; +#if 0 struct mfi_v19 { ushort fileinfo_signature; ushort fileinfo_version; @@ -263,6 +266,7 @@ struct mfi_v19 { int delta_light_sizeof; }; +#endif // 0 int CreateDefaultNewSegment(); diff --git a/main/gamemine.h b/main/gamemine.h index 55664ba4..af39f0e2 100644 --- a/main/gamemine.h +++ b/main/gamemine.h @@ -1,4 +1,4 @@ -/* $Id: gamemine.h,v 1.6 2003-10-10 09:36:35 btb Exp $ */ +/* $Id: gamemine.h,v 1.7 2004-06-26 16:27:17 schaffner Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -80,6 +80,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define MINE_VERSION 20 // Current version expected #define COMPATIBLE_VERSION 16 // Oldest version that can safely be loaded. +#if 0 struct mtfi { ushort fileinfo_signature; ushort fileinfo_version; @@ -141,8 +142,8 @@ struct mfi { int segment2_offset; int segment2_howmany; int segment2_sizeof; - }; +#endif // 0 struct mh { int num_vertices; diff --git a/main/gamesave.c b/main/gamesave.c index 911ff4af..9a2df7e3 100644 --- a/main/gamesave.c +++ b/main/gamesave.c @@ -1,4 +1,4 @@ -/* $Id: gamesave.c,v 1.21 2003-06-16 07:15:59 btb Exp $ */ +/* $Id: gamesave.c,v 1.22 2004-06-26 16:27:17 schaffner Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -287,7 +287,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef RCS -char gamesave_rcsid[] = "$Id: gamesave.c,v 1.21 2003-06-16 07:15:59 btb Exp $"; +char gamesave_rcsid[] = "$Id: gamesave.c,v 1.22 2004-06-26 16:27:17 schaffner Exp $"; #endif #include @@ -352,6 +352,7 @@ int Gamesave_current_version; #define MENU_CURSOR_X_MIN MENU_X #define MENU_CURSOR_X_MAX MENU_X+6 +#if 0 struct { ushort fileinfo_signature; ushort fileinfo_version; @@ -394,6 +395,7 @@ struct { int delta_light_howmany; int delta_light_sizeof; } game_fileinfo; +#endif // 0 // LINT: adding function prototypes void read_object(object *obj, CFILE *f, int version); @@ -1079,7 +1081,7 @@ void write_object(object *obj,FILE *f) extern int remove_trigger_num(int trigger_num); -// ----------------------------------------------------------------------------- +// -------------------------------------------------------------------- // Load game // Loads all the relevant data for a level. // If level != -1, it loads the filename with extension changed to .min @@ -1088,118 +1090,64 @@ extern int remove_trigger_num(int trigger_num); int load_game_data(CFILE *LoadFile) { int i,j; - int start_offset; - start_offset = cftell(LoadFile); + short game_top_fileinfo_version; + int object_offset; + int gs_num_objects; + int num_delta_lights; + int trig_size; //===================== READ FILE INFO ======================== - // Set default values - game_fileinfo.level = -1; - game_fileinfo.player_offset = -1; - game_fileinfo.player_sizeof = sizeof(player); - game_fileinfo.object_offset = -1; - game_fileinfo.object_howmany = 0; - game_fileinfo.object_sizeof = sizeof(object); - game_fileinfo.walls_offset = -1; - game_fileinfo.walls_howmany = 0; - game_fileinfo.walls_sizeof = sizeof(wall); - game_fileinfo.doors_offset = -1; - game_fileinfo.doors_howmany = 0; - game_fileinfo.doors_sizeof = sizeof(active_door); - game_fileinfo.triggers_offset = -1; - game_fileinfo.triggers_howmany = 0; - game_fileinfo.triggers_sizeof = sizeof(trigger); - game_fileinfo.control_offset = -1; - game_fileinfo.control_howmany = 0; - game_fileinfo.control_sizeof = sizeof(control_center_triggers); - game_fileinfo.matcen_offset = -1; - game_fileinfo.matcen_howmany = 0; - game_fileinfo.matcen_sizeof = sizeof(matcen_info); +#if 0 + cfread(&game_top_fileinfo, sizeof(game_top_fileinfo), 1, LoadFile); +#endif - game_fileinfo.dl_indices_offset = -1; - game_fileinfo.dl_indices_howmany = 0; - game_fileinfo.dl_indices_sizeof = sizeof(dl_index); + // Check signature + if (cfile_read_short(LoadFile) != 0x6705) + return -1; - game_fileinfo.delta_light_offset = -1; - game_fileinfo.delta_light_howmany = 0; - game_fileinfo.delta_light_sizeof = sizeof(delta_light); + // Read and check version number + game_top_fileinfo_version = cfile_read_short(LoadFile); + if (game_top_fileinfo_version < GAME_COMPATIBLE_VERSION ) + return -1; - // Read in game_top_fileinfo to get size of saved fileinfo. + // We skip some parts of the former game_top_fileinfo + cfseek(LoadFile, 31, SEEK_CUR); - if (cfseek( LoadFile, start_offset, SEEK_SET )) - Error( "Error seeking in gamesave.c" ); + object_offset = cfile_read_int(LoadFile); + gs_num_objects = cfile_read_int(LoadFile); + cfseek(LoadFile, 8, SEEK_CUR); -// if (cfread( &game_top_fileinfo, sizeof(game_top_fileinfo), 1, LoadFile) != 1) -// Error( "Error reading game_top_fileinfo in gamesave.c" ); + Num_walls = cfile_read_int(LoadFile); + cfseek(LoadFile, 20, SEEK_CUR); - 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); + Num_triggers = cfile_read_int(LoadFile); + cfseek(LoadFile, 24, SEEK_CUR); - // Check signature - if (game_top_fileinfo.fileinfo_signature != 0x6705) - return -1; + trig_size = cfile_read_int(LoadFile); + Assert(trig_size == sizeof(ControlCenterTriggers)); + cfseek(LoadFile, 4, SEEK_CUR); - // Check version number - if (game_top_fileinfo.fileinfo_version < GAME_COMPATIBLE_VERSION ) - return -1; + Num_robot_centers = cfile_read_int(LoadFile); + cfseek(LoadFile, 4, SEEK_CUR); - // Now, Read in the fileinfo - if (cfseek( LoadFile, start_offset, SEEK_SET )) - Error( "Error seeking to game_fileinfo in gamesave.c" ); - -// if (cfread( &game_fileinfo, game_top_fileinfo.fileinfo_sizeof, 1, LoadFile )!=1) -// Error( "Error reading game_fileinfo in gamesave.c" ); - - game_fileinfo.fileinfo_signature = cfile_read_short(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] = 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 >= 29) { - game_fileinfo.dl_indices_offset = cfile_read_int(LoadFile); - game_fileinfo.dl_indices_howmany = cfile_read_int(LoadFile); - game_fileinfo.dl_indices_sizeof = cfile_read_int(LoadFile); - - game_fileinfo.delta_light_offset = cfile_read_int(LoadFile); - game_fileinfo.delta_light_howmany = cfile_read_int(LoadFile); - game_fileinfo.delta_light_sizeof = cfile_read_int(LoadFile); + if (game_top_fileinfo_version >= 29) { + cfseek(LoadFile, 4, SEEK_CUR); + Num_static_lights = cfile_read_int(LoadFile); + cfseek(LoadFile, 8, SEEK_CUR); + num_delta_lights = cfile_read_int(LoadFile); + cfseek(LoadFile, 4, SEEK_CUR); } - if (game_top_fileinfo.fileinfo_version >= 31) { //load mine filename + if (game_top_fileinfo_version >= 31) { //load mine filename // read newline-terminated string, not sure what version this changed. cfgets(Current_level_name,sizeof(Current_level_name),LoadFile); if (Current_level_name[strlen(Current_level_name)-1] == '\n') Current_level_name[strlen(Current_level_name)-1] = 0; } - else if (game_top_fileinfo.fileinfo_version >= 14) { //load mine filename + else if (game_top_fileinfo_version >= 14) { //load mine filename // read null-terminated string char *p=Current_level_name; //must do read one char at a time, since no cfgets() @@ -1208,7 +1156,7 @@ int load_game_data(CFILE *LoadFile) else Current_level_name[0]=0; - if (game_top_fileinfo.fileinfo_version >= 19) { //load pof names + if (game_top_fileinfo_version >= 19) { //load pof names N_save_pof_names = cfile_read_short(LoadFile); if (N_save_pof_names != 0x614d && N_save_pof_names != 0x5547) { // "Ma"de w/DMB beta/"GU"ILE Assert(N_save_pof_names < MAX_POLYGON_MODELS); @@ -1224,13 +1172,13 @@ int load_game_data(CFILE *LoadFile) Gamesave_num_org_robots = 0; Gamesave_num_players = 0; - if (game_fileinfo.object_offset > -1) { - if (cfseek( LoadFile, game_fileinfo.object_offset, SEEK_SET )) + if (object_offset > -1) { + if (cfseek( LoadFile, object_offset, SEEK_SET )) Error( "Error seeking to object_offset in gamesave.c" ); - for (i=0;i -1) - { - - if (!cfseek( LoadFile, game_fileinfo.walls_offset,SEEK_SET )) { - for (i=0;i= 20) - wall_read(&Walls[i], LoadFile); // v20 walls and up. - else if (game_top_fileinfo.fileinfo_version >= 17) { - v19_wall w; - - v19_wall_read(&w, LoadFile); - - Walls[i].segnum = w.segnum; - Walls[i].sidenum = w.sidenum; - Walls[i].linked_wall = w.linked_wall; - - Walls[i].type = w.type; - Walls[i].flags = w.flags; - Walls[i].hps = w.hps; - Walls[i].trigger = w.trigger; - Walls[i].clip_num = w.clip_num; - Walls[i].keys = w.keys; - - Walls[i].state = WALL_DOOR_CLOSED; - } else { - v16_wall w; - - v16_wall_read(&w, LoadFile); - - Walls[i].segnum = Walls[i].sidenum = Walls[i].linked_wall = -1; - - Walls[i].type = w.type; - Walls[i].flags = w.flags; - Walls[i].hps = w.hps; - Walls[i].trigger = w.trigger; - Walls[i].clip_num = w.clip_num; - Walls[i].keys = w.keys; - } - - } + for (i = 0; i < Num_walls; i++) { + if (game_top_fileinfo_version >= 20) + wall_read(&Walls[i], LoadFile); // v20 walls and up. + else if (game_top_fileinfo_version >= 17) { + v19_wall w; + v19_wall_read(&w, LoadFile); + Walls[i].segnum = w.segnum; + Walls[i].sidenum = w.sidenum; + Walls[i].linked_wall = w.linked_wall; + Walls[i].type = w.type; + Walls[i].flags = w.flags; + Walls[i].hps = w.hps; + Walls[i].trigger = w.trigger; + Walls[i].clip_num = w.clip_num; + Walls[i].keys = w.keys; + Walls[i].state = WALL_DOOR_CLOSED; + } else { + v16_wall w; + v16_wall_read(&w, LoadFile); + Walls[i].segnum = Walls[i].sidenum = Walls[i].linked_wall = -1; + Walls[i].type = w.type; + Walls[i].flags = w.flags; + Walls[i].hps = w.hps; + Walls[i].trigger = w.trigger; + Walls[i].clip_num = w.clip_num; + Walls[i].keys = w.keys; } } +#if 0 //===================== READ DOOR INFO ============================ if (game_fileinfo.doors_offset > -1) @@ -1292,7 +1226,7 @@ int load_game_data(CFILE *LoadFile) for (i=0;i= 20) + if (game_top_fileinfo_version >= 20) active_door_read(&ActiveDoors[i], LoadFile); // version 20 and up else { v19_door d; @@ -1316,153 +1250,127 @@ int load_game_data(CFILE *LoadFile) } } } +#endif // 0 //==================== READ TRIGGER INFO ========================== // for MACINTOSH -- assume all triggers >= verion 31 triggers. - if (game_fileinfo.triggers_offset > -1) + for (i = 0; i < Num_triggers; i++) { - if (!cfseek( LoadFile, game_fileinfo.triggers_offset,SEEK_SET )) { - for (i=0;i -1) if (!cfseek(LoadFile, game_fileinfo.control_offset, SEEK_SET)) { Assert(game_fileinfo.control_sizeof == sizeof(control_center_triggers)); - control_center_triggers_read_n(&ControlCenterTriggers, game_fileinfo.control_howmany, LoadFile); - } +#endif // 0 + control_center_triggers_read_n(&ControlCenterTriggers, 1, LoadFile); //================ READ MATERIALOGRIFIZATIONATORS INFO =============== - if (game_fileinfo.matcen_offset > -1) - { int j; - - if (!cfseek( LoadFile, game_fileinfo.matcen_offset,SEEK_SET )) { - // mprintf((0, "Reading %i materialization centers.\n", game_fileinfo.matcen_howmany)); - for (i=0;i -1) { - int i; - - if (!cfseek( LoadFile, game_fileinfo.dl_indices_offset, SEEK_SET )) { - Num_static_lights = game_fileinfo.dl_indices_howmany; - for (i=0; i -1) { - int i; - - if (!cfseek( LoadFile, game_fileinfo.delta_light_offset, SEEK_SET )) { - for (i=0; i