Started work on FLIPX/FLIPY support for patches. Doesn't do anything yet, but the parser should know how to look for them now

Note: I had to create M_UnGetToken in order to avoid problems with looking for patch parameters (marked by { and }) but not finding anything
This commit is contained in:
Monster Iestyn 2016-10-22 23:19:24 +01:00
parent 326ad8a14f
commit 587c0079e2
5 changed files with 64 additions and 4 deletions

View file

@ -2778,7 +2778,7 @@ static void readpatch(MYFILE *f, const char *name, UINT16 wad)
char *word2; char *word2;
char *tmp; char *tmp;
INT32 i = 0, j = 0, value; INT32 i = 0, j = 0, value;
texpatch_t patch = {0, 0, UINT16_MAX, UINT16_MAX}; texpatch_t patch = {0, 0, UINT16_MAX, UINT16_MAX, 0};
// Jump to the texture this patch belongs to, which, // Jump to the texture this patch belongs to, which,
// coincidentally, is always the last one on the buffer cache. // coincidentally, is always the last one on the buffer cache.

View file

@ -407,6 +407,7 @@ void M_StartupLocale(void);
extern void *(*M_Memcpy)(void* dest, const void* src, size_t n) FUNCNONNULL; extern void *(*M_Memcpy)(void* dest, const void* src, size_t n) FUNCNONNULL;
char *va(const char *format, ...) FUNCPRINTF; char *va(const char *format, ...) FUNCPRINTF;
char *M_GetToken(const char *inputString); char *M_GetToken(const char *inputString);
void M_UnGetToken(void);
char *sizeu1(size_t num); char *sizeu1(size_t num);
char *sizeu2(size_t num); char *sizeu2(size_t num);
char *sizeu3(size_t num); char *sizeu3(size_t num);

View file

@ -1617,6 +1617,11 @@ INT32 axtoi(const char *hexStg)
return intValue; return intValue;
} }
// Token parser variables
static UINT32 oldendPos = 0; // old value of endPos, used by M_UnGetToken
static UINT32 endPos = 0; // now external to M_GetToken, but still static
/** Token parser for TEXTURES, ANIMDEFS, and potentially other lumps later down the line. /** Token parser for TEXTURES, ANIMDEFS, and potentially other lumps later down the line.
* Was originally R_GetTexturesToken when I was coding up the TEXTURES parser, until I realized I needed it for ANIMDEFS too. * Was originally R_GetTexturesToken when I was coding up the TEXTURES parser, until I realized I needed it for ANIMDEFS too.
* Parses up to the next whitespace character or comma. When finding the start of the next token, whitespace is skipped. * Parses up to the next whitespace character or comma. When finding the start of the next token, whitespace is skipped.
@ -1631,7 +1636,7 @@ char *M_GetToken(const char *inputString)
{ {
static const char *stringToUse = NULL; // Populated if inputString != NULL; used otherwise static const char *stringToUse = NULL; // Populated if inputString != NULL; used otherwise
static UINT32 startPos = 0; static UINT32 startPos = 0;
static UINT32 endPos = 0; // static UINT32 endPos = 0;
static UINT32 stringLength = 0; static UINT32 stringLength = 0;
static UINT8 inComment = 0; // 0 = not in comment, 1 = // Single-line, 2 = /* Multi-line */ static UINT8 inComment = 0; // 0 = not in comment, 1 = // Single-line, 2 = /* Multi-line */
char *texturesToken = NULL; char *texturesToken = NULL;
@ -1641,12 +1646,12 @@ char *M_GetToken(const char *inputString)
{ {
stringToUse = inputString; stringToUse = inputString;
startPos = 0; startPos = 0;
endPos = 0; oldendPos = endPos = 0;
stringLength = strlen(inputString); stringLength = strlen(inputString);
} }
else else
{ {
startPos = endPos; startPos = oldendPos = endPos;
} }
if (stringToUse == NULL) if (stringToUse == NULL)
return NULL; return NULL;
@ -1777,6 +1782,16 @@ char *M_GetToken(const char *inputString)
return texturesToken; return texturesToken;
} }
/** Undoes the last M_GetToken call
* The current position along the string being parsed is reset to the last saved position.
* This exists mostly because of R_ParseTexture/R_ParsePatch honestly, but could be useful elsewhere?
* -Monster Iestyn (22/10/16)
*/
void M_UnGetToken(void)
{
endPos = oldendPos;
}
/** Count bits in a number. /** Count bits in a number.
*/ */
UINT8 M_CountBits(UINT32 num, UINT8 size) UINT8 M_CountBits(UINT32 num, UINT8 size)

View file

@ -502,6 +502,7 @@ static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch)
char *patchName = NULL; char *patchName = NULL;
INT16 patchXPos; INT16 patchXPos;
INT16 patchYPos; INT16 patchYPos;
UINT8 flip = 0;
texpatch_t *resultPatch = NULL; texpatch_t *resultPatch = NULL;
lumpnum_t patchLumpNum; lumpnum_t patchLumpNum;
@ -598,6 +599,47 @@ static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch)
} }
Z_Free(texturesToken); Z_Free(texturesToken);
// Patch parameters block (OPTIONAL)
// added by Monster Iestyn (22/10/16)
// Left Curly Brace
texturesToken = M_GetToken(NULL);
if (texturesToken == NULL)
; // move on and ignore, R_ParseTextures will deal with this
else
{
if (strcmp(texturesToken,"{")==0)
{
Z_Free(texturesToken);
texturesToken = M_GetToken(NULL);
if (texturesToken == NULL)
{
I_Error("Error parsing TEXTURES lump: Unexpected end of file where patch \"%s\"'s parameters should be",patchName);
}
while (strcmp(texturesToken,"}")!=0)
{
if (stricmp(texturesToken, "FLIPX")==0)
flip |= 1;
else if (stricmp(texturesToken, "FLIPY")==0)
flip |= 2;
Z_Free(texturesToken);
texturesToken = M_GetToken(NULL);
if (texturesToken == NULL)
{
I_Error("Error parsing TEXTURES lump: Unexpected end of file where patch \"%s\"'s parameters or right curly brace should be",patchName);
}
}
}
else
{
// this is not what we wanted...
// undo last read so R_ParseTextures can re-get the token for its own purposes
M_UnGetToken();
}
Z_Free(texturesToken);
}
if (actuallyLoadPatch == true) if (actuallyLoadPatch == true)
{ {
// Check lump exists // Check lump exists
@ -608,6 +650,7 @@ static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch)
resultPatch->originy = patchYPos; resultPatch->originy = patchYPos;
resultPatch->lump = patchLumpNum & 65535; resultPatch->lump = patchLumpNum & 65535;
resultPatch->wad = patchLumpNum>>16; resultPatch->wad = patchLumpNum>>16;
resultPatch->flip = flip;
// Clean up a little after ourselves // Clean up a little after ourselves
Z_Free(patchName); Z_Free(patchName);
// Then return it // Then return it

View file

@ -31,6 +31,7 @@ typedef struct
// Block origin (always UL), which has already accounted for the internal origin of the patch. // Block origin (always UL), which has already accounted for the internal origin of the patch.
INT16 originx, originy; INT16 originx, originy;
UINT16 wad, lump; UINT16 wad, lump;
UINT8 flip; // 1 = flipx, 2 = flipy, 3 = both
} texpatch_t; } texpatch_t;
// A maptexturedef_t describes a rectangular texture, // A maptexturedef_t describes a rectangular texture,