summaryrefslogtreecommitdiff
path: root/src/p_saveg.c
diff options
context:
space:
mode:
authorSimon Howard2006-01-16 21:40:38 +0000
committerSimon Howard2006-01-16 21:40:38 +0000
commit764d7ecb7a88b2ad0381574a05b90ccedce6655c (patch)
treeb2199ebe0f8f6b4ee80e9d1f3e327a4f5af7695c /src/p_saveg.c
parent5b378612cd308c77be72e5636430368ad713a40d (diff)
downloadchocolate-doom-764d7ecb7a88b2ad0381574a05b90ccedce6655c.tar.gz
chocolate-doom-764d7ecb7a88b2ad0381574a05b90ccedce6655c.tar.bz2
chocolate-doom-764d7ecb7a88b2ad0381574a05b90ccedce6655c.zip
Vanilla savegame load/save
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 296
Diffstat (limited to 'src/p_saveg.c')
-rw-r--r--src/p_saveg.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/src/p_saveg.c b/src/p_saveg.c
index 0073e6e3..455dc61a 100644
--- a/src/p_saveg.c
+++ b/src/p_saveg.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: p_saveg.c 202 2005-10-16 01:18:10Z fraggle $
+// $Id: p_saveg.c 296 2006-01-16 21:40:38Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -22,6 +22,9 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.4 2006/01/16 21:40:38 fraggle
+// Vanilla savegame load/save
+//
// Revision 1.3 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
@@ -40,7 +43,7 @@
//-----------------------------------------------------------------------------
static const char
-rcsid[] = "$Id: p_saveg.c 202 2005-10-16 01:18:10Z fraggle $";
+rcsid[] = "$Id: p_saveg.c 296 2006-01-16 21:40:38Z fraggle $";
#include "dstrings.h"
#include "deh_main.h"
@@ -257,6 +260,19 @@ typedef enum
} thinkerclass_t;
+// There is a small issue with the packing of mobjs. The 'mapthing'
+// field in mobj_t is 10 bytes long. Watcom packed this without any
+// alignment issues; gcc aligns the fields to 4-byte boundaries. This
+// means that the size of the mobj_t structure is 2 bytes extra than
+// in Vanilla Doom.
+//
+// These functions have a temporary fix for this. We copy the tracer
+// field back two bytes to manually pack the data. This is obviously
+// horrible, non compiler-portable, not endian safe, etc. etc.
+//
+// This will be properly fixed once I rework the savegame code.
+// The correct size of the mobj_t structure is 154 bytes.
+
//
// P_ArchiveThinkers
@@ -265,7 +281,7 @@ void P_ArchiveThinkers (void)
{
thinker_t* th;
mobj_t* mobj;
-
+
// save off the current thinkers
for (th = thinkercap.next ; th != &thinkercap ; th=th->next)
{
@@ -276,6 +292,15 @@ void P_ArchiveThinkers (void)
mobj = (mobj_t *)save_p;
memcpy (mobj, th, sizeof(*mobj));
save_p += sizeof(*mobj);
+
+ // Hack fix for structure packing bug, see above.
+
+ if (sizeof(mobj_t) == 156)
+ {
+ memmove(save_p - 6, save_p - 4, 4);
+ save_p -= 2;
+ }
+
mobj->state = (state_t *)(mobj->state - states);
if (mobj->player)
@@ -316,7 +341,7 @@ void P_UnArchiveThinkers (void)
currentthinker = next;
}
P_InitThinkers ();
-
+
// read in saved thinkers
while (1)
{
@@ -331,6 +356,15 @@ void P_UnArchiveThinkers (void)
mobj = Z_Malloc (sizeof(*mobj), PU_LEVEL, NULL);
memcpy (mobj, save_p, sizeof(*mobj));
save_p += sizeof(*mobj);
+
+ // Hack fix for structure packing bug, see above.
+
+ if (sizeof(mobj_t) == 156)
+ {
+ save_p -= 2;
+ memmove(&mobj->tracer, save_p - 4, 4);
+ }
+
mobj->state = &states[(int)mobj->state];
mobj->target = NULL;
if (mobj->player)