Commit 31fb323b authored by Steven Fuller's avatar Steven Fuller

* Some cleanups

* Save/Load
parent da45c877
......@@ -17,10 +17,8 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "wolfdef.h" /* Get the prototypes */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "wolfdef.h"
#define BRGR 0x42524752
......
......@@ -18,7 +18,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "wolfdef.h"
#include <string.h>
/**********************************
......
......@@ -18,8 +18,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "wolfdef.h"
#include <string.h>
#include <stdlib.h>
extern Word NumberIndex; /* Hack for drawing numbers */
static LongWord BJTime; /* Time to draw BJ? */
......
......@@ -17,8 +17,8 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "wolfdef.h"
#include <ctype.h>
#include "wolfdef.h"
/**********************************
......
......@@ -18,7 +18,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "wolfdef.h"
#include <string.h>
/* static object info*/
......
......@@ -17,11 +17,8 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "wolfdef.h"
#include <string.h>
#include <stdlib.h>
#include <setjmp.h>
#include <ctype.h>
#include "wolfdef.h"
/**********************************
......
......@@ -18,7 +18,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "wolfdef.h"
#include <string.h>
Word *src1,*src2,*dest; /* Used by the sort */
......
......@@ -17,9 +17,8 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "wolfdef.h"
#include <string.h>
#include <math.h>
#include "wolfdef.h"
#define DOORPIC 59
......
......@@ -18,7 +18,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "wolfdef.h"
#include <stdlib.h>
Word MathSize; /* What size of math data is calculated? */
Word *scaleatzptr; /* Pointer to the scale table for z projection */
......
......@@ -18,6 +18,10 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "wolfdef.h"
/*
......@@ -44,21 +48,149 @@ unsigned long lMSB(unsigned long x)
/*
Save and load save games
These functions must be updated if the saved structures are ever changed!
*/
static char id1[4] = "WOLF";
static char id2[4] = "SAVE";
static char id3[4] = "LV00";
static char id4[4] = "0000";
Boolean SaveGame(char *file)
{
FILE *fp;
Word PWallWord;
fp = fopen(file, "wb");
if (fp == NULL)
goto fail;
fwrite(id1, 1, sizeof(id1), fp);
fwrite(id2, 1, sizeof(id2), fp);
fwrite(id3, 1, sizeof(id3), fp);
fwrite(id4, 1, sizeof(id4), fp);
fwrite(&MapListPtr->MaxMap, 1, sizeof(MapListPtr->MaxMap), fp);
fwrite(&gamestate, 1, sizeof(gamestate), fp);
fwrite(&PushWallRec, 1, sizeof(PushWallRec), fp);
fwrite(&nummissiles, 1, sizeof(nummissiles), fp);
if (nummissiles)
fwrite(missiles, 1, nummissiles*sizeof(missile_t), fp);
fwrite(&numactors, 1, sizeof(numactors), fp);
if (numactors)
fwrite(actors, 1, numactors*sizeof(actor_t), fp);
fwrite(&numdoors, 1, sizeof(numdoors), fp);
if (numdoors)
fwrite(doors, 1, numdoors*sizeof(door_t), fp);
fwrite(&numstatics, 1, sizeof(numstatics), fp);
if (numstatics)
fwrite(statics, 1, numstatics*sizeof(static_t), fp);
fwrite(MapPtr, 1, 64*64, fp);
fwrite(&tilemap, 1, sizeof(tilemap), fp);
fwrite(&ConnectCount, 1, sizeof(ConnectCount), fp);
if (ConnectCount)
fwrite(areaconnect, 1, ConnectCount*sizeof(connect_t), fp);
fwrite(areabyplayer, 1, sizeof(areabyplayer), fp);
fwrite(textures, 1, (128+5)*64, fp);
PWallWord = 0;
if (pwallseg)
PWallWord = (pwallseg-(saveseg_t*)nodes)+1;
fwrite(&PWallWord, 1, sizeof(PWallWord), fp);
fwrite(nodes, 1, MapPtr->numnodes*sizeof(savenode_t), fp);
fclose(fp);
return TRUE;
fail:
if (fp)
fclose(fp);
return FALSE;
}
FILE *lfp;
Boolean LoadGame(char *file)
{
FILE *fp;
unsigned short maxmap;
char tmp[4];
fp = fopen(file, "rb");
if (fp == NULL)
goto fail;
fread(tmp, 1, 4, fp);
if (strncmp(tmp, id1, 4))
goto fail;
fread(tmp, 1, 4, fp);
if (strncmp(tmp, id2, 4))
goto fail;
fread(tmp, 1, 4, fp);
if (strncmp(tmp, id3, 4))
goto fail;
fread(tmp, 1, 4, fp);
if (strncmp(tmp, id4, 4))
goto fail;
fread(&maxmap, 1, sizeof(MapListPtr->MaxMap), fp);
if (MapListPtr->MaxMap != maxmap)
goto fail;
fread(&gamestate, 1, sizeof(gamestate), fp);
lfp = fp;
return TRUE;
fail:
if (fp)
fclose(fp);
return FALSE;
}
void FinishLoadGame(void)
void FinishLoadGame()
{
Word PWallWord;
if (lfp == NULL)
Quit("FinishLoadGame called without handle!");
fseek(lfp, -sizeof(gamestate), SEEK_CUR);
fread(&gamestate, 1, sizeof(gamestate), lfp);
fread(&PushWallRec, 1, sizeof(PushWallRec), lfp);
fread(&nummissiles, 1, sizeof(nummissiles), lfp);
if (nummissiles)
fread(missiles, 1, nummissiles*sizeof(missile_t), lfp);
fread(&numactors, 1, sizeof(numactors), lfp);
if (numactors)
fread(actors, 1, numactors*sizeof(actor_t), lfp);
fread(&numdoors, 1, sizeof(numdoors), lfp);
if (numdoors)
fread(doors, 1, numdoors*sizeof(door_t), lfp);
fread(&numstatics, 1, sizeof(numstatics), lfp);
if (numstatics)
fread(statics, 1, numstatics*sizeof(static_t), lfp);
fread(MapPtr, 1, 64*64, lfp);
fread(&tilemap, 1, sizeof(tilemap), lfp);
fread(&ConnectCount, 1, sizeof(ConnectCount), lfp);
if (ConnectCount)
fread(areaconnect, 1, ConnectCount*sizeof(connect_t), lfp);
fread(areabyplayer, 1, sizeof(areabyplayer), lfp);
fread(textures, 1, (128+5)*64, lfp);
PWallWord = 0;
fread(&PWallWord, 1, sizeof(PWallWord), lfp);
if (PWallWord) {
pwallseg = (saveseg_t *)nodes;
pwallseg = &pwallseg[PWallWord-1];
}
fread(nodes, 1, MapPtr->numnodes*sizeof(savenode_t), lfp);
fclose(lfp);
lfp = NULL;
}
/*
......
......@@ -10,7 +10,7 @@ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
......
......@@ -17,8 +17,8 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "wolfdef.h"
#include <string.h>
#include "wolfdef.h"
/**********************************
......
......@@ -23,9 +23,9 @@ TODO:
- Is GL_REPLACE faster than GL_MODULATE for textures?
- Save "draw state" so redrawing works right when screen is
resized/exposed
* Save/Load Games
- Menu code does not exist yet -- so just have a compiled in default save
and load files
- What about using CVAs for the Walls - when loading level create a
CVA with every wall entry, then just reference the right one (go by BSP
number)
* Documentation
* Sound!
- Need to write sound playing code (probably access /dev/dsp directly
......
......@@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <stdlib.h>
#include <ctype.h>
#include <getopt.h>
#include <setjmp.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
......@@ -40,8 +41,6 @@ XVisualInfo *vi;
GLXContext ctx;
Atom wmDeleteWindow;
int VidWidth, VidHeight, ViewHeight;
#ifdef GL_EXT_shared_texture_palette
extern int UseSharedTexturePalette;
extern PFNGLCOLORTABLEEXTPROC pglColorTableEXT;
......@@ -49,8 +48,13 @@ extern PFNGLCOLORTABLEEXTPROC pglColorTableEXT;
extern int CheckToken(const char *str, const char *item);
int VidWidth, VidHeight, ViewHeight;
int HandleEvents();
extern jmp_buf ResetJmp;
extern Boolean JumpOK;
int attrib[] = {
GLX_RGBA,
GLX_RED_SIZE, 5,
......@@ -424,6 +428,19 @@ void keyboard_handler(KeySym keycode, int press)
switch(keycode) {
case XK_Escape:
Quit(NULL); /* fast way out */
case XK_F2:
if (playstate == EX_STILLPLAYING) {
if (!SaveGame("wolf3d.sav"))
fprintf(stderr, "Unable to save game\n");
}
break;
case XK_F3:
if (!LoadGame("wolf3d.sav")) {
fprintf(stderr, "Unable to load game\n");
} else {
longjmp(ResetJmp, EX_LOADGAME);
}
break;
default:
break;
}
......
......@@ -595,6 +595,8 @@ extern void InitData();
extern int WolfMain(int argc, char *argv[]);
extern void FreeResources();
extern void RedrawScreen();
extern Boolean SaveGame(char *file);
extern Boolean LoadGame(char *file);
extern void BlastScreen(void);
extern void BlastScreen2(Rect *BlastRect);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment