summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/g_game.c69
-rw-r--r--src/p_saveg.c96
-rw-r--r--src/p_saveg.h18
3 files changed, 133 insertions, 50 deletions
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 <string.h>
#include <stdlib.h>
@@ -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<MAXPLAYERS ; i++)
- playeringame[i] = *save_p++;
+ save_p = savebuffer;
+ if (!P_ReadSaveGameHeader())
+ {
+ Z_Free(savebuffer);
+ return;
+ }
+
+ savedleveltime = leveltime;
+
// load a base level
G_InitNew (gameskill, gameepisode, gamemap);
- // get the times
- a = *save_p++;
- b = *save_p++;
- c = *save_p++;
- leveltime = (a<<16) + (b<<8) + c;
-
+ leveltime = savedleveltime;
+
// dearchive all the modifications
P_UnArchivePlayers ();
P_UnArchiveWorld ();
P_UnArchiveThinkers ();
P_UnArchiveSpecials ();
- if (*save_p != 0x1d)
+ if (!P_ReadSaveGameEOF())
I_Error ("Bad savegame");
// done
@@ -1388,10 +1379,8 @@ G_SaveGame
void G_DoSaveGame (void)
{
char name[100];
- char name2[VERSIONSIZE];
char* description;
int length;
- int i;
strcpy(name, P_SaveGameFile(savegameslot));
@@ -1399,35 +1388,21 @@ void G_DoSaveGame (void)
save_p = savebuffer = screens[1]+0x4000;
- memcpy (save_p, description, SAVESTRINGSIZE);
- save_p += SAVESTRINGSIZE;
- memset (name2,0,sizeof(name2));
- sprintf (name2,"version %i",DOOM_VERSION);
- memcpy (save_p, name2, VERSIONSIZE);
- save_p += VERSIONSIZE;
-
- *save_p++ = gameskill;
- *save_p++ = gameepisode;
- *save_p++ = gamemap;
- for (i=0 ; i<MAXPLAYERS ; i++)
- *save_p++ = playeringame[i];
- *save_p++ = leveltime>>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<MAXPLAYERS ; i++)
+ saveg_write8(playeringame[i]);
+
+ saveg_write8((leveltime >> 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<MAXPLAYERS ; i++)
+ playeringame[i] = saveg_read8();
+
+ // get the times
+ a = saveg_read8();
+ b = saveg_read8();
+ c = saveg_read8();
+ leveltime = (a<<16) + (b<<8) + c;
+
+ return true;
+}
+
+//
+// Read the end of file marker. Returns true if read successfully.
+//
+
+boolean P_ReadSaveGameEOF(void)
+{
+ int value;
+
+ value = saveg_read8();
+
+ return value == SAVEGAME_EOF;
+}
+
+//
+// Write the end of file marker
+//
+
+void P_WriteSaveGameEOF(void)
+{
+ saveg_write8(SAVEGAME_EOF);
+}
//
// P_ArchivePlayers
diff --git a/src/p_saveg.h b/src/p_saveg.h
index d6f95f11..3217e9d3 100644
--- a/src/p_saveg.h
+++ b/src/p_saveg.h
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: p_saveg.h 202 2005-10-16 01:18:10Z fraggle $
+// $Id: p_saveg.h 300 2006-01-19 18:46:24Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -30,10 +30,23 @@
#ifndef __P_SAVEG__
#define __P_SAVEG__
+// maximum size of a savegame description
+
+#define SAVESTRINGSIZE 24
+
// filename to use for a savegame slot
char *P_SaveGameFile(int slot);
+// Savegame file header read/write functions
+
+boolean P_ReadSaveGameHeader(void);
+void P_WriteSaveGameHeader(char *description);
+
+// Savegame end-of-file read/write functions
+
+boolean P_ReadSaveGameEOF(void);
+void P_WriteSaveGameEOF(void);
// Persistent storage/archiving.
// These are the load / save game routines.
@@ -53,6 +66,9 @@ extern byte* save_p;
//-----------------------------------------------------------------------------
//
// $Log$
+// Revision 1.5 2006/01/19 18:46:24 fraggle
+// Move savegame header read/write code into p_saveg.c
+//
// Revision 1.4 2005/10/16 01:18:10 fraggle
// Global "configdir" variable with directory to store config files in.
// Create a function to find the filename for a savegame slot. Store