From 717673ef80aff9ae1a271b73d3c7f43f2bb27a1a Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Thu, 19 Jan 2006 18:46:24 +0000 Subject: Move savegame header read/write code into p_saveg.c Subversion-branch: /trunk/chocolate-doom Subversion-revision: 300 --- src/g_game.c | 69 ++++++++++++++---------------------------- src/p_saveg.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/p_saveg.h | 18 ++++++++++- 3 files changed, 133 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/g_game.c b/src/g_game.c index 9afe6ace..8c1da54b 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: g_game.c 291 2006-01-13 23:56:00Z fraggle $ +// $Id: g_game.c 300 2006-01-19 18:46:24Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -22,6 +22,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.20 2006/01/19 18:46:24 fraggle +// Move savegame header read/write code into p_saveg.c +// // Revision 1.19 2006/01/13 23:56:00 fraggle // Add text-mode I/O functions. // Use text-mode screen for the waiting screen. @@ -102,7 +105,7 @@ static const char -rcsid[] = "$Id: g_game.c 291 2006-01-13 23:56:00Z fraggle $"; +rcsid[] = "$Id: g_game.c 300 2006-01-19 18:46:24Z fraggle $"; #include #include @@ -155,7 +158,6 @@ rcsid[] = "$Id: g_game.c 291 2006-01-13 23:56:00Z fraggle $"; #define SAVEGAMESIZE 0x2c000 -#define SAVESTRINGSIZE 24 @@ -1318,45 +1320,34 @@ void G_LoadGame (char* name) void G_DoLoadGame (void) { - int length; - int i; - int a,b,c; - char vcheck[VERSIONSIZE]; + int length; + int savedleveltime; gameaction = ga_nothing; length = M_ReadFile (savename, &savebuffer); - save_p = savebuffer + SAVESTRINGSIZE; - - // skip the description field - memset (vcheck,0,sizeof(vcheck)); - sprintf (vcheck,"version %i",DOOM_VERSION); - if (strcmp ((char *) save_p, vcheck)) - return; // bad version - save_p += VERSIONSIZE; - - gameskill = *save_p++; - gameepisode = *save_p++; - gamemap = *save_p++; - for (i=0 ; i>16; - *save_p++ = leveltime>>8; - *save_p++ = leveltime; + P_WriteSaveGameHeader(description); P_ArchivePlayers (); P_ArchiveWorld (); P_ArchiveThinkers (); P_ArchiveSpecials (); - *save_p++ = 0x1d; // consistancy marker + P_WriteSaveGameEOF(); length = save_p - savebuffer; if (length > SAVEGAMESIZE) I_Error ("Savegame buffer overrun"); M_WriteFile (name, savebuffer, length); gameaction = ga_nothing; - savedescription[0] = 0; + strcpy(savedescription, ""); players[consoleplayer].message = DEH_String(GGSAVED); diff --git a/src/p_saveg.c b/src/p_saveg.c index 7391fe4b..fbec93a0 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: p_saveg.c 299 2006-01-19 00:17:01Z fraggle $ +// $Id: p_saveg.c 300 2006-01-19 18:46:24Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -22,6 +22,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.7 2006/01/19 18:46:24 fraggle +// Move savegame header read/write code into p_saveg.c +// // Revision 1.6 2006/01/19 00:17:01 fraggle // Remove now-redundant note about structure packing. // @@ -52,18 +55,22 @@ //----------------------------------------------------------------------------- static const char -rcsid[] = "$Id: p_saveg.c 299 2006-01-19 00:17:01Z fraggle $"; +rcsid[] = "$Id: p_saveg.c 300 2006-01-19 18:46:24Z fraggle $"; #include "dstrings.h" #include "deh_main.h" #include "i_system.h" #include "z_zone.h" #include "p_local.h" +#include "p_saveg.h" // State. #include "doomstat.h" #include "r_state.h" +#define SAVEGAME_EOF 0x1d +#define VERSIONSIZE 16 + byte* save_p; @@ -1305,6 +1312,91 @@ static void saveg_write_glow_t(glow_t *str) saveg_write32(str->direction); } +// +// Write the header for a savegame +// + +void P_WriteSaveGameHeader(char *description) +{ + char name[VERSIONSIZE]; + int i; + + memcpy (save_p, description, SAVESTRINGSIZE); + save_p += SAVESTRINGSIZE; + + memset (name,0,sizeof(name)); + sprintf (name,"version %i",DOOM_VERSION); + memcpy (save_p, name, VERSIONSIZE); + save_p += VERSIONSIZE; + + saveg_write8(gameskill); + saveg_write8(gameepisode); + saveg_write8(gamemap); + + for (i=0 ; i> 16) & 0xff); + saveg_write8((leveltime >> 8) & 0xff); + saveg_write8(leveltime & 0xff); +} + +// +// Read the header for a savegame +// + +boolean P_ReadSaveGameHeader(void) +{ + int i; + byte a, b, c; + char vcheck[VERSIONSIZE]; + + save_p += SAVESTRINGSIZE; + + // skip the description field + memset (vcheck,0,sizeof(vcheck)); + sprintf (vcheck,"version %i",DOOM_VERSION); + if (strcmp ((char *) save_p, vcheck)) + return false; // bad version + save_p += VERSIONSIZE; + + gameskill = saveg_read8(); + gameepisode = saveg_read8(); + gamemap = saveg_read8(); + + for (i=0 ; i