ref: 871d3b3da6c84be394963d1f5a41de12bfc5a2bc
parent: f19a6f2ae93df6da9e39694b11e710c4e3b7594a
author: Simon Howard <fraggle@gmail.com>
date: Sat Sep 20 17:48:37 EDT 2008
Remove bits from heretic/m_misc.c that are in common; change V_ScreenShot to take a format string describing the format of the filename for the screen shot file. Subversion-branch: /branches/raven-branch Subversion-revision: 1255
--- a/src/doom/g_game.c
+++ b/src/doom/g_game.c
@@ -801,7 +801,7 @@
G_DoWorldDone ();
break;
case ga_screenshot:
- V_ScreenShot ();
+ V_ScreenShot("DOOM%02i.pcx");
players[consoleplayer].message = DEH_String("screen shot");
gameaction = ga_nothing;
break;
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -23,15 +23,11 @@
// D_main.c
-#ifdef __WATCOMC__
-#include <dos.h>
-#include <graph.h>
-#include <sys\types.h>
-#include <direct.h>
-#endif
#include <stdio.h>
#include <stdlib.h>
+
#include "doomdef.h"
+#include "m_argv.h"
#include "p_local.h"
#include "s_sound.h"
#include "v_video.h"
--- a/src/heretic/doomdef.h
+++ b/src/heretic/doomdef.h
@@ -909,10 +909,6 @@
//----
//MISC
//----
-extern int myargc;
-extern char **myargv;
-
-int M_CheckParm(char *check);
// returns the position of the given parameter in the arg list (0 if not found)
boolean M_ValidEpisodeMap(int episode, int map);
@@ -930,16 +926,9 @@
void M_ClearRandom(void);
// fix randoms for demos
-void M_FindResponseFile(void);
-
void M_ClearBox(fixed_t * box);
void M_AddToBox(fixed_t * box, fixed_t x, fixed_t y);
// bounding box functions
-
-boolean M_WriteFile(char const *name, void *source, int length);
-int M_ReadFile(char const *name, byte ** buffer);
-
-void M_ScreenShot(void);
void M_LoadDefaults(void);
--- a/src/heretic/g_game.c
+++ b/src/heretic/g_game.c
@@ -27,6 +27,7 @@
#include <string.h>
#include "doomdef.h"
#include "doomkeys.h"
+#include "m_misc.h"
#include "p_local.h"
#include "s_sound.h"
#include "v_video.h"
@@ -963,7 +964,7 @@
G_DoPlayDemo();
break;
case ga_screenshot:
- M_ScreenShot();
+ V_ScreenShot("HTIC%02i.pcx");
gameaction = ga_nothing;
break;
case ga_completed:
--- a/src/heretic/m_misc.c
+++ b/src/heretic/m_misc.c
@@ -33,11 +33,9 @@
#include "doomdef.h"
#include "i_swap.h"
#include "i_video.h"
+#include "m_argv.h"
#include "s_sound.h"
-int myargc;
-char **myargv;
-
//---------------------------------------------------------------------------
//
// FUNC M_ValidEpisodeMap
@@ -89,33 +87,6 @@
}
/*
-=================
-=
-= M_CheckParm
-=
-= Checks for the given parameter in the program's command line arguments
-=
-= Returns the argument number (1 to argc-1) or 0 if not present
-=
-=================
-*/
-
-int M_CheckParm(char *check)
-{
- int i;
-
- for (i = 1; i < myargc; i++)
- {
- if (!strcasecmp(check, myargv[i]))
- return i;
- }
-
- return 0;
-}
-
-
-
-/*
===============
=
= M_Random
@@ -185,153 +156,8 @@
box[BOXTOP] = y;
}
-
-
-/*
-==================
-=
-= M_WriteFile
-=
-==================
-*/
-
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
-
-boolean M_WriteFile(char const *name, void *source, int length)
-{
- int handle, count;
-
- handle = open(name, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
- if (handle == -1)
- return false;
- count = write(handle, source, length);
- close(handle);
-
- if (count < length)
- return false;
-
- return true;
-}
-
-
-/*
-==================
-=
-= M_ReadFile
-=
-==================
-*/
-
-int M_ReadFile(char const *name, byte ** buffer)
-{
- int handle, count, length;
- struct stat fileinfo;
- byte *buf;
-
- handle = open(name, O_RDONLY | O_BINARY, 0666);
- if (handle == -1)
- I_Error("Couldn't read file %s", name);
- if (fstat(handle, &fileinfo) == -1)
- I_Error("Couldn't read file %s", name);
- length = fileinfo.st_size;
- buf = Z_Malloc(length, PU_STATIC, NULL);
- count = read(handle, buf, length);
- close(handle);
-
- if (count < length)
- I_Error("Couldn't read file %s", name);
-
- *buffer = buf;
- return length;
-}
-
//---------------------------------------------------------------------------
//
-// PROC M_FindResponseFile
-//
-//---------------------------------------------------------------------------
-
-#define MAXARGVS 100
-
-void M_FindResponseFile(void)
-{
- int i;
-
- for (i = 1; i < myargc; i++)
- {
- if (myargv[i][0] == '@')
- {
- FILE *handle;
- int size;
- int k;
- int index;
- int indexinfile;
- char *infile;
- char *file;
- char *moreargs[20];
- char *firstargv;
-
- // READ THE RESPONSE FILE INTO MEMORY
- handle = fopen(&myargv[i][1], "rb");
- if (!handle)
- {
- printf("\nNo such response file!");
- exit(1);
- }
- printf("Found response file %s!\n", &myargv[i][1]);
- fseek(handle, 0, SEEK_END);
- size = ftell(handle);
- fseek(handle, 0, SEEK_SET);
- file = malloc(size);
- fread(file, size, 1, handle);
- fclose(handle);
-
- // KEEP ALL CMDLINE ARGS FOLLOWING @RESPONSEFILE ARG
- for (index = 0, k = i + 1; k < myargc; k++)
- moreargs[index++] = myargv[k];
-
- firstargv = myargv[0];
- myargv = malloc(sizeof(char *) * MAXARGVS);
- memset(myargv, 0, sizeof(char *) * MAXARGVS);
- myargv[0] = firstargv;
-
- infile = file;
- indexinfile = k = 0;
- indexinfile++; // SKIP PAST ARGV[0] (KEEP IT)
- do
- {
- myargv[indexinfile++] = infile + k;
- while (k < size &&
- ((*(infile + k) >= ' ' + 1) && (*(infile + k) <= 'z')))
- k++;
- *(infile + k) = 0;
- while (k < size &&
- ((*(infile + k) <= ' ') || (*(infile + k) > 'z')))
- k++;
- }
- while (k < size);
-
- for (k = 0; k < index; k++)
- myargv[indexinfile++] = moreargs[k];
- myargc = indexinfile;
- // DISPLAY ARGS
- if (M_CheckParm("-debug"))
- {
- printf("%d command-line args:\n", myargc);
- for (k = 1; k < myargc; k++)
- {
- printf("%s\n", myargv[k]);
- }
- }
- break;
- }
- }
-}
-
-//---------------------------------------------------------------------------
-//
// PROC M_ForceUppercase
//
// Change string to uppercase.
@@ -661,158 +487,3 @@
#endif
}
-
-/*
-==============================================================================
-
- SCREEN SHOTS
-
-==============================================================================
-*/
-
-
-typedef struct
-{
- char manufacturer;
- char version;
- char encoding;
- char bits_per_pixel;
- unsigned short xmin, ymin, xmax, ymax;
- unsigned short hres, vres;
- unsigned char palette[48];
- char reserved;
- char color_planes;
- unsigned short bytes_per_line;
- unsigned short palette_type;
- char filler[58];
- unsigned char data; // unbounded
-} pcx_t;
-
-/*
-==============
-=
-= WritePCXfile
-=
-==============
-*/
-
-void WritePCXfile(char *filename, byte * data, int width, int height,
- byte * palette)
-{
- int i, length;
- pcx_t *pcx;
- byte *pack;
-
- pcx = Z_Malloc(width * height * 2 + 1000, PU_STATIC, NULL);
-
- pcx->manufacturer = 0x0a; // PCX id
- pcx->version = 5; // 256 color
- pcx->encoding = 1; // uncompressed
- pcx->bits_per_pixel = 8; // 256 color
- pcx->xmin = 0;
- pcx->ymin = 0;
- pcx->xmax = SHORT(width - 1);
- pcx->ymax = SHORT(height - 1);
- pcx->hres = SHORT(width);
- pcx->vres = SHORT(height);
- memset(pcx->palette, 0, sizeof(pcx->palette));
- pcx->color_planes = 1; // chunky image
- pcx->bytes_per_line = SHORT(width);
- pcx->palette_type = SHORT(2); // not a grey scale
- memset(pcx->filler, 0, sizeof(pcx->filler));
-
-//
-// pack the image
-//
- pack = &pcx->data;
-
- for (i = 0; i < width * height; i++)
- if ((*data & 0xc0) != 0xc0)
- *pack++ = *data++;
- else
- {
- *pack++ = 0xc1;
- *pack++ = *data++;
- }
-
-//
-// write the palette
-//
- *pack++ = 0x0c; // palette ID byte
- for (i = 0; i < 768; i++)
- *pack++ = *palette++;
-
-//
-// write output file
-//
- length = pack - (byte *) pcx;
- M_WriteFile(filename, pcx, length);
-
- Z_Free(pcx);
-}
-
-
-//==============================================================================
-
-/*
-==================
-=
-= M_ScreenShot
-=
-==================
-*/
-
-void M_ScreenShot(void)
-{
- int i;
- byte *linear;
- char lbmname[12];
- byte *pal;
-
-#ifdef _WATCOMC_
- extern byte *pcscreen;
-#endif
-//
-// munge planar buffer to linear
-//
-#ifdef _WATCOMC_
- linear = pcscreen;
-#else
- linear = I_VideoBuffer;
-#endif
-//
-// find a file name to save it to
-//
- strcpy(lbmname, "HRTIC00.pcx");
-
- for (i = 0; i <= 99; i++)
- {
- lbmname[5] = i / 10 + '0';
- lbmname[6] = i % 10 + '0';
- if (access(lbmname, 0) == -1)
- break; // file doesn't exist
- }
- if (i == 100)
- I_Error("M_ScreenShot: Couldn't create a PCX");
-
-//
-// save the pcx file
-//
-#ifdef __WATCOMC__
- pal = (byte *) Z_Malloc(768, PU_STATIC, NULL);
- outp(0x3c7, 0);
- for (i = 0; i < 768; i++)
- {
- *(pal + i) = inp(0x3c9) << 2;
- }
-#else
- pal = (byte *) W_CacheLumpName("PLAYPAL", PU_CACHE);
-#endif
-
- WritePCXfile(lbmname, linear, SCREENWIDTH, SCREENHEIGHT, pal);
-
- players[consoleplayer].message = "SCREEN SHOT";
-#ifdef __WATCOMC__
- Z_Free(pal);
-#endif
-}
--- a/src/heretic/p_setup.c
+++ b/src/heretic/p_setup.c
@@ -28,6 +28,7 @@
#include "doomdef.h"
#include "i_swap.h"
+#include "m_argv.h"
#include "p_local.h"
#include "s_sound.h"
--- a/src/v_video.c
+++ b/src/v_video.c
@@ -582,7 +582,7 @@
// V_ScreenShot
//
-void V_ScreenShot (void)
+void V_ScreenShot(char *format)
{
int i;
char lbmname[12];
@@ -591,7 +591,7 @@
for (i=0; i<=99; i++)
{
- sprintf(lbmname, "DOOM%02i.pcx", i);
+ sprintf(lbmname, format, i);
if (!M_FileExists(lbmname))
{
--- a/src/v_video.h
+++ b/src/v_video.h
@@ -80,7 +80,11 @@
void V_RestoreBuffer(void);
-void V_ScreenShot(void);
+// Save a screenshot of the current screen to a file, named in the
+// format described in the string passed to the function, eg.
+// "DOOM%02i.pcx"
+
+void V_ScreenShot(char *format);
#endif