summaryrefslogtreecommitdiff
path: root/src/hexen/m_misc.c
diff options
context:
space:
mode:
authorSimon Howard2008-10-01 17:31:28 +0000
committerSimon Howard2008-10-01 17:31:28 +0000
commitbf5e84859e2aca7f543f88a4a93bb971332aa989 (patch)
tree377a3eac2ccbfdc6859f7b28ac83cc589d9a1c01 /src/hexen/m_misc.c
parentfde2f7883fbd50ea4b56c0cc35f15161ff3ab649 (diff)
downloadchocolate-doom-bf5e84859e2aca7f543f88a4a93bb971332aa989.tar.gz
chocolate-doom-bf5e84859e2aca7f543f88a4a93bb971332aa989.tar.bz2
chocolate-doom-bf5e84859e2aca7f543f88a4a93bb971332aa989.zip
Merge Hexen fixed_t and angle definitions to common code, plus byte
swapping macros, bounding box checking, read/write file, screenshot and command line argument code. Update Heretic code to use ANG1_X rather than the new (correct) ANG1 definition. Subversion-branch: /branches/raven-branch Subversion-revision: 1311
Diffstat (limited to 'src/hexen/m_misc.c')
-rw-r--r--src/hexen/m_misc.c397
1 files changed, 1 insertions, 396 deletions
diff --git a/src/hexen/m_misc.c b/src/hexen/m_misc.c
index 6955cfb8..0d38941a 100644
--- a/src/hexen/m_misc.c
+++ b/src/hexen/m_misc.c
@@ -34,6 +34,7 @@
#endif
#include <ctype.h>
#include "h2def.h"
+#include "m_argv.h"
#include "p_local.h"
#include "soundst.h"
@@ -50,59 +51,17 @@
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
-static int ReadFile(char const *name, byte ** buffer, int mallocType);
-
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
extern char *SavePath;
// PUBLIC DATA DEFINITIONS -------------------------------------------------
-int myargc;
-char **myargv;
-
// PRIVATE DATA DEFINITIONS ------------------------------------------------
// CODE --------------------------------------------------------------------
//==========================================================================
//
-// 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_ParmExists
-//
-// Returns true if the given parameter exists in the program's command
-// line arguments, false if not.
-//
-//==========================================================================
-
-boolean M_ParmExists(char *check)
-{
- return M_CheckParm(check) != 0 ? true : false;
-}
-
-//==========================================================================
-//
// M_ExtractFileBase
//
//==========================================================================
@@ -185,206 +144,6 @@ void M_ClearRandom(void)
rndindex = prndindex = 0;
}
-
-void M_ClearBox(fixed_t * box)
-{
- box[BOXTOP] = box[BOXRIGHT] = INT_MIN;
- box[BOXBOTTOM] = box[BOXLEFT] = INT_MAX;
-}
-
-void M_AddToBox(fixed_t * box, fixed_t x, fixed_t y)
-{
- if (x < box[BOXLEFT])
- box[BOXLEFT] = x;
- else if (x > box[BOXRIGHT])
- box[BOXRIGHT] = x;
- if (y < box[BOXBOTTOM])
- box[BOXBOTTOM] = y;
- else if (y > box[BOXTOP])
- 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
-//
-// Read a file into a buffer allocated using Z_Malloc().
-//
-//==========================================================================
-
-int M_ReadFile(char const *name, byte ** buffer)
-{
- return ReadFile(name, buffer, MALLOC_ZONE);
-}
-
-//==========================================================================
-//
-// M_ReadFileCLib
-//
-// Read a file into a buffer allocated using malloc().
-//
-//==========================================================================
-
-int M_ReadFileCLib(char const *name, byte ** buffer)
-{
- return ReadFile(name, buffer, MALLOC_CLIB);
-}
-
-//==========================================================================
-//
-// ReadFile
-//
-//==========================================================================
-
-static int ReadFile(char const *name, byte ** buffer, int mallocType)
-{
- 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;
- if (mallocType == MALLOC_ZONE)
- { // Use zone memory allocation
- buf = Z_Malloc(length, PU_STATIC, NULL);
- }
- else
- { // Use c library memory allocation
- buf = malloc(length);
- if (buf == NULL)
- {
- I_Error("Couldn't malloc buffer %d for file %s.", length, name);
- }
- }
- 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);
- }
- ST_Message("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"))
- {
- ST_Message("%d command-line args:\n", myargc);
- for (k = 1; k < myargc; k++)
- {
- ST_Message("%s\n", myargv[k]);
- }
- }
- break;
- }
- }
-}
-
//---------------------------------------------------------------------------
//
// PROC M_ForceUppercase
@@ -734,157 +493,3 @@ void M_LoadDefaults(char *fileName)
#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 = screen;
-#endif
-//
-// find a file name to save it to
-//
- strcpy(lbmname, "HEXEN00.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);
-
- P_SetMessage(&players[consoleplayer], "SCREEN SHOT", false);
-#ifdef __WATCOMC__
- Z_Free(pal);
-#endif
-}