shithub: choc

Download patch

ref: 764d7ecb7a88b2ad0381574a05b90ccedce6655c
parent: 5b378612cd308c77be72e5636430368ad713a40d
author: Simon Howard <[email protected]>
date: Mon Jan 16 16:40:38 EST 2006

Vanilla savegame load/save

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 296

--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,8 @@
          the ENDOOM screen to be disabled.
 
     Fixes for big endian machines (thanks locust)
+    Savegame fixes: we now load and save to the Vanilla Doom savegame
+        format.
     Fixed the behavior of the dehacked maximum health setting.
     Fix the "-skill 0" hack to play without any items (thanks to Janizdreg
         for pointing out that this was nonfunctional)
--- 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,7 +260,20 @@
 } 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 @@
 {
     thinker_t*		th;
     mobj_t*		mobj;
-	
+
     // save off the current thinkers
     for (th = thinkercap.next ; th != &thinkercap ; th=th->next)
     {
@@ -276,6 +292,15 @@
 	    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 @@
 	currentthinker = next;
     }
     P_InitThinkers ();
-	
+    
     // read in saved thinkers
     while (1)
     {
@@ -331,6 +356,15 @@
 	    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)