From aaef412823945719c30231d4c41d3fb9053dc0fb Mon Sep 17 00:00:00 2001 From: Nev3r Date: Mon, 30 Dec 2019 11:33:22 +0100 Subject: [PATCH 01/26] Add basic textmap support; currently crashes when trying to free the virtres, at vres_free(). --- src/doomdef.h | 2 + src/m_misc.c | 14 ++ src/p_setup.c | 371 +++++++++++++++++++++++++++++++++++++++++++++++++- src/w_wad.c | 2 + 4 files changed, 382 insertions(+), 7 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index 51a15bd64..0d673a426 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -461,6 +461,8 @@ extern void *(*M_Memcpy)(void* dest, const void* src, size_t n) FUNCNONNULL; char *va(const char *format, ...) FUNCPRINTF; char *M_GetToken(const char *inputString); void M_UnGetToken(void); +UINT32 M_GetTokenPos(void); +void M_SetTokenPos(UINT32 newPos); char *sizeu1(size_t num); char *sizeu2(size_t num); char *sizeu3(size_t num); diff --git a/src/m_misc.c b/src/m_misc.c index b0a1fb8c5..edb24ab1e 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1908,6 +1908,20 @@ void M_UnGetToken(void) endPos = oldendPos; } +/** Returns the current token's position. + */ +UINT32 M_GetTokenPos(void) +{ + return endPos; +} + +/** Sets the current token's position. + */ +void M_SetTokenPos(UINT32 newPos) +{ + endPos = newPos; +} + /** Count bits in a number. */ UINT8 M_CountBits(UINT32 num, UINT8 size) diff --git a/src/p_setup.c b/src/p_setup.c index 99da5ccee..c7eb50382 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -83,6 +83,8 @@ #include "p_slopes.h" #endif +#include "fastcmp.h" // textmap parsing + // // Map MD5, calculated on level load. // Sent to clients in PT_SERVERINFO. @@ -1236,10 +1238,367 @@ static void P_LoadThings(UINT8 *data) } } +// Stores positions for relevant map data spread through a TEXTMAP. +UINT32 mapthingsPos[UINT16_MAX]; +UINT32 linesPos[UINT16_MAX]; +UINT32 sidesPos[UINT16_MAX]; +UINT32 vertexesPos[UINT16_MAX]; +UINT32 sectorsPos[UINT16_MAX]; + +static boolean TextmapCount (UINT8 *data, size_t size) +{ + char *nsp1 = M_GetToken((char *)data); + boolean ret = true; + + // Determine total amount of map data in TEXTMAP. + // Look for namespace at the beginning. + if (fastcmp(nsp1, "namespace")) + { + char *nsp2 = M_GetToken(NULL); + char *tkn = M_GetToken(NULL); + + // Check if namespace is valid. + if (!fastcmp(nsp2, "srb2")) + CONS_Alert(CONS_WARNING, "Invalid namespace '%s', only 'srb2' is supported.\n", nsp2); + Z_Free(nsp2); + + while (tkn != NULL && M_GetTokenPos() < size) + { + // Avoid anything inside bracketed stuff, only look for external keywords. + // Assuming there's only one level of bracket nesting. + if (fastcmp(tkn, "{")) + { + Z_Free(tkn); + while (!fastcmp(tkn, "}")) + { + Z_Free(tkn); + tkn = M_GetToken(NULL); + } + } + // Check for valid fields. + else if (fastcmp(tkn, "thing")) + mapthingsPos[nummapthings++] = M_GetTokenPos(); + else if (fastcmp(tkn, "linedef")) + linesPos[numlines++] = M_GetTokenPos(); + else if (fastcmp(tkn, "sidedef")) + sidesPos[numsides++] = M_GetTokenPos(); + else if (fastcmp(tkn, "vertex")) + vertexesPos[numvertexes++] = M_GetTokenPos(); + else if (fastcmp(tkn, "sector")) + sectorsPos[numsectors++] = M_GetTokenPos(); + else + CONS_Alert(CONS_NOTICE, "Unknown field '%s'.\n", tkn); + + Z_Free(tkn); + tkn = M_GetToken(NULL); + } + } + else + { + CONS_Alert(CONS_WARNING, "No namespace at beginning of lump!\n"); + ret = false; + } + + Z_Free(nsp1); + return ret; +} + +static char* dat; + +/** Auxiliary function for TextmapParse. + * + * \param Vertex number. + * \param Parameter string. + */ +static void TextmapVertex(UINT32 i, char *param) +{ + if (fastcmp(param, "x")) + vertexes[i].x = FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL))); + else if (fastcmp(param, "y")) + vertexes[i].y = FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL))); +} + +/** Auxiliary function for TextmapParse. + * + * \param Sector number. + * \param Parameter string. + */ +static void TextmapSector(UINT32 i, char *param) +{ + if (fastcmp(param, "heightfloor")) + sectors[i].floorheight = atol(dat = M_GetToken(NULL)) << FRACBITS; + else if (fastcmp(param, "heightceiling")) + sectors[i].ceilingheight = atol(dat = M_GetToken(NULL)) << FRACBITS; + if (fastcmp(param, "texturefloor")) + sectors[i].floorpic = P_AddLevelFlat(dat = M_GetToken(NULL), foundflats); + else if (fastcmp(param, "textureceiling")) + sectors[i].ceilingpic = P_AddLevelFlat(dat = M_GetToken(NULL), foundflats); + else if (fastcmp(param, "lightlevel")) + sectors[i].lightlevel = atol(dat = M_GetToken(NULL)); + else if (fastcmp(param, "special")) + sectors[i].special = atol(dat = M_GetToken(NULL)); + else if (fastcmp(param, "id")) + sectors[i].tag = atol(dat = M_GetToken(NULL)); +} + +/** Auxiliary function for TextmapParse. + * + * \param Side number. + * \param Parameter string. + */ +static void TextmapSide(UINT32 i, char *param) +{ + if (fastcmp(param, "offsetx")) + sides[i].textureoffset = atol(dat = M_GetToken(NULL))<z = 0; + + TextmapParse(vertexesPos[i], i, TextmapVertex); + } + + for (i = 0, sc = sectors; i < numsectors; i++, sc++) + { + // Defaults. + sc->floorheight = 0; + sc->ceilingheight = 0; + + sc->floorpic = 0; + sc->ceilingpic = 0; + + sc->lightlevel = 255; + + sc->special = 0; + sc->tag = 0; + + sc->floor_xoffs = sc->floor_yoffs = sc->ceiling_xoffs = sc->ceiling_yoffs = 0; + sc->floorpic_angle = sc->ceilingpic_angle = 0; + + TextmapParse(sectorsPos[i], i, TextmapSector); + + P_InitializeSector(sc); + } + + for (i = 0, ld = lines; i < numlines; i++, ld++) + { + // Defaults. + ld->tag = 0; + ld->special = 0; + ld->sidenum[1] = 0xffff; + + TextmapParse(linesPos[i], i, TextmapLine); + + P_InitializeLinedef(ld); + } + + for (i = 0, sd = sides; i < numsides; i++, sd++) + { + // Defaults. + sd->rowoffset = 0; + sd->textureoffset = 0; + + sd->toptexture = R_TextureNumForName("-"); + sd->midtexture = R_TextureNumForName("-"); + sd->bottomtexture = R_TextureNumForName("-"); + sd->repeatcnt = 0; + + TextmapParse(sidesPos[i], i, TextmapSide); + } + + for (i = 0, mt = mapthings; i < nummapthings; i++, mt++) + { + // Defaults. + mt->z = 0; + mt->angle = 0; + + TextmapParse(mapthingsPos[i], i, TextmapThing); + } +} + +/** Provides a fix to the flat alignment coordinate transform from standard Textmaps. + */ +static void TextmapFixFlatOffsets (void) +{ + fixed_t pc, ps; + fixed_t xoffs, yoffs; + size_t i; + sector_t* sec = sectors; + for (i = 0; i < numsectors; i++, sec++) + { + if (sec->floorpic_angle) + { + pc = FINECOSINE(sec->floorpic_angle>>ANGLETOFINESHIFT); + ps = FINESINE (sec->floorpic_angle>>ANGLETOFINESHIFT); + xoffs = sec->floor_xoffs; + yoffs = sec->floor_yoffs; + #define MAXFLATSIZE (2048<floor_xoffs = (FixedMul(xoffs, pc) % MAXFLATSIZE) - (FixedMul(yoffs, ps) % MAXFLATSIZE); + sec->floor_yoffs = (FixedMul(xoffs, ps) % MAXFLATSIZE) + (FixedMul(yoffs, pc) % MAXFLATSIZE); + #undef MAXFLATSIZE + } + + if (sec->ceilingpic_angle) + { + pc = FINECOSINE(sec->ceilingpic_angle>>ANGLETOFINESHIFT); + ps = FINESINE (sec->ceilingpic_angle>>ANGLETOFINESHIFT); + xoffs = sec->ceiling_xoffs; + yoffs = sec->ceiling_yoffs; + #define MAXFLATSIZE (2048<ceiling_xoffs = (FixedMul(xoffs, pc) % MAXFLATSIZE) - (FixedMul(yoffs, ps) % MAXFLATSIZE); + sec->ceiling_yoffs = (FixedMul(xoffs, ps) % MAXFLATSIZE) + (FixedMul(yoffs, pc) % MAXFLATSIZE); + #undef MAXFLATSIZE + } + } +} + static void P_LoadMapData(const virtres_t *virt) { virtlump_t* virtvertexes = NULL, * virtsectors = NULL, * virtsidedefs = NULL, * virtlinedefs = NULL, * virtthings = NULL; -#ifdef UDMF virtlump_t* textmap = vres_Find(virt, "TEXTMAP"); // Count map data. @@ -1252,10 +1611,9 @@ static void P_LoadMapData(const virtres_t *virt) numsectors = 0; // Count how many entries for each type we got in textmap. - //TextmapCount(vtextmap->data, vtextmap->size); + TextmapCount(textmap->data, textmap->size); } else -#endif { virtthings = vres_Find(virt, "THINGS"); virtvertexes = vres_Find(virt, "VERTEXES"); @@ -1305,15 +1663,14 @@ static void P_LoadMapData(const virtres_t *virt) numlevelflats = 0; -#ifdef UDMF + // Load map data. if (textmap) { - + P_LoadTextmap(); + TextmapFixFlatOffsets(); } else -#endif { - // Strict map data P_LoadVertices(virtvertexes->data); P_LoadSectors(virtsectors->data); P_LoadLinedefs(virtlinedefs->data); diff --git a/src/w_wad.c b/src/w_wad.c index 62992441a..47c3f42d0 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1942,6 +1942,8 @@ void vres_Free(virtres_t* vres) Z_Free(vres->vlumps[vres->numlumps].data); Z_Free(vres->vlumps); Z_Free(vres); + + CONS_Printf("A A A\n"); } /** (Debug) Prints lumps from a virtual resource into console. From ed114f655bd84576d8f3eea314921b9cc611b49e Mon Sep 17 00:00:00 2001 From: Nev3r Date: Mon, 30 Dec 2019 12:07:02 +0100 Subject: [PATCH 02/26] Fixed missing M_GetToken(NULL); --- src/p_setup.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/p_setup.c b/src/p_setup.c index c7eb50382..71d1ca880 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1269,6 +1269,7 @@ static boolean TextmapCount (UINT8 *data, size_t size) if (fastcmp(tkn, "{")) { Z_Free(tkn); + tkn = M_GetToken(NULL); while (!fastcmp(tkn, "}")) { Z_Free(tkn); From f49b8de5fd8999965f28bc7fcec5ff666ac1b3d3 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Mon, 30 Dec 2019 12:07:54 +0100 Subject: [PATCH 03/26] Adapt P_MakeMapMD5() for textmaps. --- src/p_setup.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 71d1ca880..198b8ae6a 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2668,27 +2668,34 @@ static INT32 P_MakeBufferMD5(const char *buffer, size_t len, void *resblock) static void P_MakeMapMD5(virtres_t *virt, void *dest) { - unsigned char linemd5[16]; - unsigned char sectormd5[16]; - unsigned char thingmd5[16]; - unsigned char sidedefmd5[16]; + virtlump_t* textmap = vres_Find(virt, "TEXTMAP"); unsigned char resmd5[16]; - UINT8 i; - // Create a hash for the current map - // get the actual lumps! - virtlump_t *virtlines = vres_Find(virt, "LINEDEFS"); - virtlump_t *virtsectors = vres_Find(virt, "SECTORS"); - virtlump_t *virtmthings = vres_Find(virt, "THINGS"); - virtlump_t *virtsides = vres_Find(virt, "SIDEDEFS"); + if (textmap) + P_MakeBufferMD5((char*)textmap->data, textmap->size, resmd5); + else + { + unsigned char linemd5[16]; + unsigned char sectormd5[16]; + unsigned char thingmd5[16]; + unsigned char sidedefmd5[16]; + UINT8 i; - P_MakeBufferMD5((char*)virtlines->data, virtlines->size, linemd5); - P_MakeBufferMD5((char*)virtsectors->data, virtsectors->size, sectormd5); - P_MakeBufferMD5((char*)virtmthings->data, virtmthings->size, thingmd5); - P_MakeBufferMD5((char*)virtsides->data, virtsides->size, sidedefmd5); + // Create a hash for the current map + // get the actual lumps! + virtlump_t* virtlines = vres_Find(virt, "LINEDEFS"); + virtlump_t* virtsectors = vres_Find(virt, "SECTORS"); + virtlump_t* virtmthings = vres_Find(virt, "THINGS"); + virtlump_t* virtsides = vres_Find(virt, "SIDEDEFS"); - for (i = 0; i < 16; i++) - resmd5[i] = (linemd5[i] + sectormd5[i] + thingmd5[i] + sidedefmd5[i]) & 0xFF; + P_MakeBufferMD5((char*)virtlines->data, virtlines->size, linemd5); + P_MakeBufferMD5((char*)virtsectors->data, virtsectors->size, sectormd5); + P_MakeBufferMD5((char*)virtmthings->data, virtmthings->size, thingmd5); + P_MakeBufferMD5((char*)virtsides->data, virtsides->size, sidedefmd5); + + for (i = 0; i < 16; i++) + resmd5[i] = (linemd5[i] + sectormd5[i] + thingmd5[i] + sidedefmd5[i]) & 0xFF; + } M_Memcpy(dest, &resmd5, 16); } From 493c6c8ae2e725870ceded26f97ed5b936ff4bea Mon Sep 17 00:00:00 2001 From: Nev3r Date: Mon, 30 Dec 2019 12:23:31 +0100 Subject: [PATCH 04/26] AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA --- src/w_wad.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 47c3f42d0..62992441a 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1942,8 +1942,6 @@ void vres_Free(virtres_t* vres) Z_Free(vres->vlumps[vres->numlumps].data); Z_Free(vres->vlumps); Z_Free(vres); - - CONS_Printf("A A A\n"); } /** (Debug) Prints lumps from a virtual resource into console. From f9aabe753e76bb028746251b7ab867b297285c23 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Mon, 30 Dec 2019 12:31:55 +0100 Subject: [PATCH 05/26] Refactor TextmapFixFlatOffsets(). --- src/p_setup.c | 53 +++++++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 198b8ae6a..2334a9a03 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1523,6 +1523,7 @@ static void P_LoadTextmap (void) TextmapParse(sectorsPos[i], i, TextmapSector); P_InitializeSector(sc); + TextmapFixFlatOffsets(sc); } for (i = 0, ld = lines; i < numlines; i++, ld++) @@ -1563,37 +1564,30 @@ static void P_LoadTextmap (void) /** Provides a fix to the flat alignment coordinate transform from standard Textmaps. */ -static void TextmapFixFlatOffsets (void) +static void TextmapFixFlatOffsets (sector_t* sec) { - fixed_t pc, ps; - fixed_t xoffs, yoffs; - size_t i; - sector_t* sec = sectors; - for (i = 0; i < numsectors; i++, sec++) + if (sec->floorpic_angle) { - if (sec->floorpic_angle) - { - pc = FINECOSINE(sec->floorpic_angle>>ANGLETOFINESHIFT); - ps = FINESINE (sec->floorpic_angle>>ANGLETOFINESHIFT); - xoffs = sec->floor_xoffs; - yoffs = sec->floor_yoffs; - #define MAXFLATSIZE (2048<floor_xoffs = (FixedMul(xoffs, pc) % MAXFLATSIZE) - (FixedMul(yoffs, ps) % MAXFLATSIZE); - sec->floor_yoffs = (FixedMul(xoffs, ps) % MAXFLATSIZE) + (FixedMul(yoffs, pc) % MAXFLATSIZE); - #undef MAXFLATSIZE - } + fixed_t pc = FINECOSINE(sec->floorpic_angle>>ANGLETOFINESHIFT); + fixed_t ps = FINESINE (sec->floorpic_angle>>ANGLETOFINESHIFT); + fixed_t xoffs = sec->floor_xoffs; + fixed_t yoffs = sec->floor_yoffs; + #define MAXFLATSIZE (2048<floor_xoffs = (FixedMul(xoffs, pc) % MAXFLATSIZE) - (FixedMul(yoffs, ps) % MAXFLATSIZE); + sec->floor_yoffs = (FixedMul(xoffs, ps) % MAXFLATSIZE) + (FixedMul(yoffs, pc) % MAXFLATSIZE); + #undef MAXFLATSIZE + } - if (sec->ceilingpic_angle) - { - pc = FINECOSINE(sec->ceilingpic_angle>>ANGLETOFINESHIFT); - ps = FINESINE (sec->ceilingpic_angle>>ANGLETOFINESHIFT); - xoffs = sec->ceiling_xoffs; - yoffs = sec->ceiling_yoffs; - #define MAXFLATSIZE (2048<ceiling_xoffs = (FixedMul(xoffs, pc) % MAXFLATSIZE) - (FixedMul(yoffs, ps) % MAXFLATSIZE); - sec->ceiling_yoffs = (FixedMul(xoffs, ps) % MAXFLATSIZE) + (FixedMul(yoffs, pc) % MAXFLATSIZE); - #undef MAXFLATSIZE - } + if (sec->ceilingpic_angle) + { + fixed_t pc = FINECOSINE(sec->ceilingpic_angle>>ANGLETOFINESHIFT); + fixed_t ps = FINESINE (sec->ceilingpic_angle>>ANGLETOFINESHIFT); + fixed_t xoffs = sec->ceiling_xoffs; + fixed_t yoffs = sec->ceiling_yoffs; + #define MAXFLATSIZE (2048<ceiling_xoffs = (FixedMul(xoffs, pc) % MAXFLATSIZE) - (FixedMul(yoffs, ps) % MAXFLATSIZE); + sec->ceiling_yoffs = (FixedMul(xoffs, ps) % MAXFLATSIZE) + (FixedMul(yoffs, pc) % MAXFLATSIZE); + #undef MAXFLATSIZE } } @@ -1666,10 +1660,7 @@ static void P_LoadMapData(const virtres_t *virt) // Load map data. if (textmap) - { P_LoadTextmap(); - TextmapFixFlatOffsets(); - } else { P_LoadVertices(virtvertexes->data); From e43df2993fd06e7e3acefdb58a08a8f47b7b4e68 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Mon, 30 Dec 2019 12:33:24 +0100 Subject: [PATCH 06/26] Move TextmapFixFlatOffsets() above P_LoadTextmap() so that it can compile. --- src/p_setup.c | 58 +++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 2334a9a03..09ef07c1a 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1478,6 +1478,35 @@ static void TextmapParse(UINT32 dataPos, size_t num, void (*parser)(UINT32, char Z_Free(open); } +/** Provides a fix to the flat alignment coordinate transform from standard Textmaps. + */ +static void TextmapFixFlatOffsets (sector_t* sec) +{ + if (sec->floorpic_angle) + { + fixed_t pc = FINECOSINE(sec->floorpic_angle>>ANGLETOFINESHIFT); + fixed_t ps = FINESINE (sec->floorpic_angle>>ANGLETOFINESHIFT); + fixed_t xoffs = sec->floor_xoffs; + fixed_t yoffs = sec->floor_yoffs; + #define MAXFLATSIZE (2048<floor_xoffs = (FixedMul(xoffs, pc) % MAXFLATSIZE) - (FixedMul(yoffs, ps) % MAXFLATSIZE); + sec->floor_yoffs = (FixedMul(xoffs, ps) % MAXFLATSIZE) + (FixedMul(yoffs, pc) % MAXFLATSIZE); + #undef MAXFLATSIZE + } + + if (sec->ceilingpic_angle) + { + fixed_t pc = FINECOSINE(sec->ceilingpic_angle>>ANGLETOFINESHIFT); + fixed_t ps = FINESINE (sec->ceilingpic_angle>>ANGLETOFINESHIFT); + fixed_t xoffs = sec->ceiling_xoffs; + fixed_t yoffs = sec->ceiling_yoffs; + #define MAXFLATSIZE (2048<ceiling_xoffs = (FixedMul(xoffs, pc) % MAXFLATSIZE) - (FixedMul(yoffs, ps) % MAXFLATSIZE); + sec->ceiling_yoffs = (FixedMul(xoffs, ps) % MAXFLATSIZE) + (FixedMul(yoffs, pc) % MAXFLATSIZE); + #undef MAXFLATSIZE + } +} + /** Loads the textmap data, after obtaining the elements count and allocating their respective space. */ static void P_LoadTextmap (void) @@ -1562,35 +1591,6 @@ static void P_LoadTextmap (void) } } -/** Provides a fix to the flat alignment coordinate transform from standard Textmaps. - */ -static void TextmapFixFlatOffsets (sector_t* sec) -{ - if (sec->floorpic_angle) - { - fixed_t pc = FINECOSINE(sec->floorpic_angle>>ANGLETOFINESHIFT); - fixed_t ps = FINESINE (sec->floorpic_angle>>ANGLETOFINESHIFT); - fixed_t xoffs = sec->floor_xoffs; - fixed_t yoffs = sec->floor_yoffs; - #define MAXFLATSIZE (2048<floor_xoffs = (FixedMul(xoffs, pc) % MAXFLATSIZE) - (FixedMul(yoffs, ps) % MAXFLATSIZE); - sec->floor_yoffs = (FixedMul(xoffs, ps) % MAXFLATSIZE) + (FixedMul(yoffs, pc) % MAXFLATSIZE); - #undef MAXFLATSIZE - } - - if (sec->ceilingpic_angle) - { - fixed_t pc = FINECOSINE(sec->ceilingpic_angle>>ANGLETOFINESHIFT); - fixed_t ps = FINESINE (sec->ceilingpic_angle>>ANGLETOFINESHIFT); - fixed_t xoffs = sec->ceiling_xoffs; - fixed_t yoffs = sec->ceiling_yoffs; - #define MAXFLATSIZE (2048<ceiling_xoffs = (FixedMul(xoffs, pc) % MAXFLATSIZE) - (FixedMul(yoffs, ps) % MAXFLATSIZE); - sec->ceiling_yoffs = (FixedMul(xoffs, ps) % MAXFLATSIZE) + (FixedMul(yoffs, pc) % MAXFLATSIZE); - #undef MAXFLATSIZE - } -} - static void P_LoadMapData(const virtres_t *virt) { virtlump_t* virtvertexes = NULL, * virtsectors = NULL, * virtsidedefs = NULL, * virtlinedefs = NULL, * virtthings = NULL; From 4aee4e3684ce3f70e6a6e60fc427eb998ddb0b9c Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Mon, 30 Dec 2019 13:27:05 +0100 Subject: [PATCH 07/26] Refactor TextmapCount --- src/p_setup.c | 107 +++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 09ef07c1a..ccb528687 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1245,63 +1245,71 @@ UINT32 sidesPos[UINT16_MAX]; UINT32 vertexesPos[UINT16_MAX]; UINT32 sectorsPos[UINT16_MAX]; -static boolean TextmapCount (UINT8 *data, size_t size) +// Determine total amount of map data in TEXTMAP. +static boolean TextmapCount(UINT8 *data, size_t size) { - char *nsp1 = M_GetToken((char *)data); - boolean ret = true; + char *tkn = M_GetToken((char *)data); + + nummapthings = 0; + numlines = 0; + numsides = 0; + numvertexes = 0; + numsectors = 0; - // Determine total amount of map data in TEXTMAP. // Look for namespace at the beginning. - if (fastcmp(nsp1, "namespace")) + if (!fastcmp(tkn, "namespace")) { - char *nsp2 = M_GetToken(NULL); - char *tkn = M_GetToken(NULL); + Z_Free(tkn); + CONS_Alert(CONS_WARNING, "No namespace at beginning of lump!\n"); + return false; + } + Z_Free(tkn); - // Check if namespace is valid. - if (!fastcmp(nsp2, "srb2")) - CONS_Alert(CONS_WARNING, "Invalid namespace '%s', only 'srb2' is supported.\n", nsp2); - Z_Free(nsp2); + // Check if namespace is valid. + tkn = M_GetToken(NULL); + if (!fastcmp(tkn, "srb2")) + CONS_Alert(CONS_WARNING, "Invalid namespace '%s', only 'srb2' is supported.\n", tkn); + Z_Free(tkn); - while (tkn != NULL && M_GetTokenPos() < size) + tkn = M_GetToken(NULL); + while (tkn && M_GetTokenPos() < size) + { + // Avoid anything inside bracketed stuff, only look for external keywords. + // Assuming there's only one level of bracket nesting. + if (fastcmp(tkn, "{")) { - // Avoid anything inside bracketed stuff, only look for external keywords. - // Assuming there's only one level of bracket nesting. - if (fastcmp(tkn, "{")) + do { Z_Free(tkn); tkn = M_GetToken(NULL); - while (!fastcmp(tkn, "}")) + if (!tkn || M_GetTokenPos() >= size) { Z_Free(tkn); - tkn = M_GetToken(NULL); + CONS_Alert(CONS_WARNING, "Opening bracket not closed!\n"); + return false; } - } - // Check for valid fields. - else if (fastcmp(tkn, "thing")) - mapthingsPos[nummapthings++] = M_GetTokenPos(); - else if (fastcmp(tkn, "linedef")) - linesPos[numlines++] = M_GetTokenPos(); - else if (fastcmp(tkn, "sidedef")) - sidesPos[numsides++] = M_GetTokenPos(); - else if (fastcmp(tkn, "vertex")) - vertexesPos[numvertexes++] = M_GetTokenPos(); - else if (fastcmp(tkn, "sector")) - sectorsPos[numsectors++] = M_GetTokenPos(); - else - CONS_Alert(CONS_NOTICE, "Unknown field '%s'.\n", tkn); - - Z_Free(tkn); - tkn = M_GetToken(NULL); + } while (!fastcmp(tkn, "}")); } - } - else - { - CONS_Alert(CONS_WARNING, "No namespace at beginning of lump!\n"); - ret = false; + // Check for valid fields. + else if (fastcmp(tkn, "thing")) + mapthingsPos[nummapthings++] = M_GetTokenPos(); + else if (fastcmp(tkn, "linedef")) + linesPos[numlines++] = M_GetTokenPos(); + else if (fastcmp(tkn, "sidedef")) + sidesPos[numsides++] = M_GetTokenPos(); + else if (fastcmp(tkn, "vertex")) + vertexesPos[numvertexes++] = M_GetTokenPos(); + else if (fastcmp(tkn, "sector")) + sectorsPos[numsectors++] = M_GetTokenPos(); + else + CONS_Alert(CONS_NOTICE, "Unknown field '%s'.\n", tkn); + + Z_Free(tkn); + tkn = M_GetToken(NULL); } - Z_Free(nsp1); - return ret; + Z_Free(tkn); + return true; } static char* dat; @@ -1593,21 +1601,12 @@ static void P_LoadTextmap (void) static void P_LoadMapData(const virtres_t *virt) { - virtlump_t* virtvertexes = NULL, * virtsectors = NULL, * virtsidedefs = NULL, * virtlinedefs = NULL, * virtthings = NULL; - virtlump_t* textmap = vres_Find(virt, "TEXTMAP"); + virtlump_t *virtvertexes = NULL, *virtsectors = NULL, *virtsidedefs = NULL, *virtlinedefs = NULL, *virtthings = NULL; + virtlump_t *textmap = vres_Find(virt, "TEXTMAP"); // Count map data. - if (textmap) - { - nummapthings = 0; - numlines = 0; - numsides = 0; - numvertexes = 0; - numsectors = 0; - - // Count how many entries for each type we got in textmap. + if (textmap) // Count how many entries for each type we got in textmap. TextmapCount(textmap->data, textmap->size); - } else { virtthings = vres_Find(virt, "THINGS"); @@ -2659,7 +2658,7 @@ static INT32 P_MakeBufferMD5(const char *buffer, size_t len, void *resblock) static void P_MakeMapMD5(virtres_t *virt, void *dest) { - virtlump_t* textmap = vres_Find(virt, "TEXTMAP"); + virtlump_t *textmap = vres_Find(virt, "TEXTMAP"); unsigned char resmd5[16]; if (textmap) From c6c00aa7d5e5ba923b28c3fa8ad53fb5eed501ad Mon Sep 17 00:00:00 2001 From: Nev3r Date: Mon, 30 Dec 2019 13:38:52 +0100 Subject: [PATCH 08/26] Tweak TextmapCount()'s bracket detection to account for multiple levels, if that ever happens. --- src/p_setup.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index ccb528687..55f0b4f3e 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1249,6 +1249,7 @@ UINT32 sectorsPos[UINT16_MAX]; static boolean TextmapCount(UINT8 *data, size_t size) { char *tkn = M_GetToken((char *)data); + UINT8 brackets = 0; nummapthings = 0; numlines = 0; @@ -1275,21 +1276,13 @@ static boolean TextmapCount(UINT8 *data, size_t size) while (tkn && M_GetTokenPos() < size) { // Avoid anything inside bracketed stuff, only look for external keywords. - // Assuming there's only one level of bracket nesting. - if (fastcmp(tkn, "{")) + if (brackets) { - do - { - Z_Free(tkn); - tkn = M_GetToken(NULL); - if (!tkn || M_GetTokenPos() >= size) - { - Z_Free(tkn); - CONS_Alert(CONS_WARNING, "Opening bracket not closed!\n"); - return false; - } - } while (!fastcmp(tkn, "}")); + if (fastcmp(tkn, "}")) + brackets--; } + else if (fastcmp(tkn, "{")) + brackets++; // Check for valid fields. else if (fastcmp(tkn, "thing")) mapthingsPos[nummapthings++] = M_GetTokenPos(); From ea87af007678a8ca516437b4bd713d9242240eaa Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Mon, 30 Dec 2019 14:33:41 +0100 Subject: [PATCH 09/26] Refactor TextmapParse --- src/p_setup.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 55f0b4f3e..16cb785ab 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1455,33 +1455,35 @@ static void TextmapThing(UINT32 i, char *param) */ static void TextmapParse(UINT32 dataPos, size_t num, void (*parser)(UINT32, char *)) { - char *open; + char *tkn; M_SetTokenPos(dataPos); - open = M_GetToken(NULL); - if (fastcmp(open, "{")) + tkn = M_GetToken(NULL); + if (!fastcmp(tkn, "{")) { - char *tkn = M_GetToken(NULL); - while (!fastcmp(tkn, "}")) - { - dat = NULL; - parser(num, tkn); - if (dat) - Z_Free(dat); - - Z_Free(tkn); - tkn = M_GetToken(NULL); - } Z_Free(tkn); - } - else CONS_Alert(CONS_WARNING, "Invalid UDMF data capsule!\n"); - Z_Free(open); + return; + } + + Z_Free(tkn); + tkn = M_GetToken(NULL); + while (!fastcmp(tkn, "}")) + { + dat = NULL; + parser(num, tkn); + if (dat) + Z_Free(dat); + + Z_Free(tkn); + tkn = M_GetToken(NULL); + } + Z_Free(tkn); } /** Provides a fix to the flat alignment coordinate transform from standard Textmaps. */ -static void TextmapFixFlatOffsets (sector_t* sec) +static void TextmapFixFlatOffsets(sector_t *sec) { if (sec->floorpic_angle) { @@ -1510,7 +1512,7 @@ static void TextmapFixFlatOffsets (sector_t* sec) /** Loads the textmap data, after obtaining the elements count and allocating their respective space. */ -static void P_LoadTextmap (void) +static void P_LoadTextmap(void) { UINT32 i; From 7ae2143c9102c798c7db9d2583aadbc3b77f2631 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Mon, 30 Dec 2019 14:42:41 +0100 Subject: [PATCH 10/26] Add a disclaimer when loading textmaps/UDMF. --- src/p_setup.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/p_setup.c b/src/p_setup.c index 55f0b4f3e..839e583c8 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1520,6 +1520,8 @@ static void P_LoadTextmap (void) side_t *sd; mapthing_t *mt; + CONS_Alert(CONS_NOTICE, "UDMF support is still a work-in-progress; its specs and features are prone to change until it is fully implemented.\n"); + /// Given the UDMF specs, some fields are given a default value. /// If an element's field has a default value set, it is ommited /// from the textmap, and therefore we have to account for it by From f9d6e26558aa6fd4439edfcb5380691b0074c495 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Mon, 30 Dec 2019 14:45:39 +0100 Subject: [PATCH 11/26] Replace INT16_MAX with LUMPERROR in lump check. --- src/p_setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_setup.c b/src/p_setup.c index 839e583c8..73c3b44f6 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3536,7 +3536,7 @@ boolean P_LoadLevel(boolean fromnetsave) // internal game map maplumpname = G_BuildMapName(gamemap); lastloadedmaplumpnum = W_CheckNumForName(maplumpname); - if (lastloadedmaplumpnum == INT16_MAX) + if (lastloadedmaplumpnum == LUMPERROR) I_Error("Map %s not found.\n", maplumpname); R_ReInitColormaps(mapheaderinfo[gamemap-1]->palette); From 4a5498473c3ff07feb45006943e59ec0b504282a Mon Sep 17 00:00:00 2001 From: Nev3r Date: Mon, 30 Dec 2019 14:47:48 +0100 Subject: [PATCH 12/26] Make P_LoadMapData() a return a boolean as well as P_LoadMapFromFile(); if they fail to load, they return false, and thus P_SetupLevel() will also return false. TextmapCount() also now returns false if brackets are left open inside a textmap. --- src/p_setup.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 73c3b44f6..f9ca4dcf0 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1261,7 +1261,7 @@ static boolean TextmapCount(UINT8 *data, size_t size) if (!fastcmp(tkn, "namespace")) { Z_Free(tkn); - CONS_Alert(CONS_WARNING, "No namespace at beginning of lump!\n"); + CONS_Alert(CONS_ERROR, "No namespace at beginning of lump!\n"); return false; } Z_Free(tkn); @@ -1302,6 +1302,13 @@ static boolean TextmapCount(UINT8 *data, size_t size) } Z_Free(tkn); + + if (brackets) + { + CONS_Alert(CONS_ERROR, "Unclosed brackets detected in textmap lump.\n"); + return false; + } + return true; } @@ -1594,14 +1601,17 @@ static void P_LoadTextmap (void) } } -static void P_LoadMapData(const virtres_t *virt) +static boolean P_LoadMapData(const virtres_t *virt) { virtlump_t *virtvertexes = NULL, *virtsectors = NULL, *virtsidedefs = NULL, *virtlinedefs = NULL, *virtthings = NULL; virtlump_t *textmap = vres_Find(virt, "TEXTMAP"); // Count map data. if (textmap) // Count how many entries for each type we got in textmap. - TextmapCount(textmap->data, textmap->size); + { + if (!TextmapCount(textmap->data, textmap->size)) + return false; + } else { virtthings = vres_Find(virt, "THINGS"); @@ -1684,6 +1694,8 @@ static void P_LoadMapData(const virtres_t *virt) memcpy(spawnsectors, sectors, numsectors * sizeof (*sectors)); memcpy(spawnlines, lines, numlines * sizeof (*lines)); memcpy(spawnsides, sides, numsides * sizeof (*sides)); + + return true; } static void P_InitializeSubsector(subsector_t *ss) @@ -2685,11 +2697,12 @@ static void P_MakeMapMD5(virtres_t *virt, void *dest) M_Memcpy(dest, &resmd5, 16); } -static void P_LoadMapFromFile(void) +static boolean P_LoadMapFromFile(void) { virtres_t *virt = vres_GetMap(lastloadedmaplumpnum); - P_LoadMapData(virt); + if (!P_LoadMapData(virt)) + return false; P_LoadMapBSP(virt); P_LoadMapLUT(virt); @@ -2701,6 +2714,7 @@ static void P_LoadMapFromFile(void) P_MakeMapMD5(virt, &mapmd5); vres_Free(virt); + return true; } // @@ -3549,8 +3563,8 @@ boolean P_LoadLevel(boolean fromnetsave) P_MapStart(); - if (lastloadedmaplumpnum) - P_LoadMapFromFile(); + if (!P_LoadMapFromFile()) + return false; // init gravity, tag lists, // anything that P_ResetDynamicSlopes/P_LoadThings needs to know From 72bb67320969b17d116c18392a2781751d19af58 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Mon, 30 Dec 2019 16:28:22 +0100 Subject: [PATCH 13/26] Some minor refactoring of textmap loading code --- src/p_setup.c | 54 +++++++++++++++------------------------------------ 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 78792f306..4d4eaff6d 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1314,12 +1314,7 @@ static boolean TextmapCount(UINT8 *data, size_t size) static char* dat; -/** Auxiliary function for TextmapParse. - * - * \param Vertex number. - * \param Parameter string. - */ -static void TextmapVertex(UINT32 i, char *param) +static void ParseTextmapVertexParameter(UINT32 i, char *param) { if (fastcmp(param, "x")) vertexes[i].x = FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL))); @@ -1327,12 +1322,7 @@ static void TextmapVertex(UINT32 i, char *param) vertexes[i].y = FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL))); } -/** Auxiliary function for TextmapParse. - * - * \param Sector number. - * \param Parameter string. - */ -static void TextmapSector(UINT32 i, char *param) +static void ParseTextmapSectorParameter(UINT32 i, char *param) { if (fastcmp(param, "heightfloor")) sectors[i].floorheight = atol(dat = M_GetToken(NULL)) << FRACBITS; @@ -1350,12 +1340,7 @@ static void TextmapSector(UINT32 i, char *param) sectors[i].tag = atol(dat = M_GetToken(NULL)); } -/** Auxiliary function for TextmapParse. - * - * \param Side number. - * \param Parameter string. - */ -static void TextmapSide(UINT32 i, char *param) +static void ParseTextmapSidedefParameter(UINT32 i, char *param) { if (fastcmp(param, "offsetx")) sides[i].textureoffset = atol(dat = M_GetToken(NULL))<floorpic_angle>>ANGLETOFINESHIFT); fixed_t xoffs = sec->floor_xoffs; fixed_t yoffs = sec->floor_yoffs; - #define MAXFLATSIZE (2048<floor_xoffs = (FixedMul(xoffs, pc) % MAXFLATSIZE) - (FixedMul(yoffs, ps) % MAXFLATSIZE); sec->floor_yoffs = (FixedMul(xoffs, ps) % MAXFLATSIZE) + (FixedMul(yoffs, pc) % MAXFLATSIZE); - #undef MAXFLATSIZE } if (sec->ceilingpic_angle) @@ -1510,13 +1488,13 @@ static void TextmapFixFlatOffsets(sector_t *sec) fixed_t ps = FINESINE (sec->ceilingpic_angle>>ANGLETOFINESHIFT); fixed_t xoffs = sec->ceiling_xoffs; fixed_t yoffs = sec->ceiling_yoffs; - #define MAXFLATSIZE (2048<ceiling_xoffs = (FixedMul(xoffs, pc) % MAXFLATSIZE) - (FixedMul(yoffs, ps) % MAXFLATSIZE); sec->ceiling_yoffs = (FixedMul(xoffs, ps) % MAXFLATSIZE) + (FixedMul(yoffs, pc) % MAXFLATSIZE); - #undef MAXFLATSIZE } } +#undef MAXFLATSIZE + /** Loads the textmap data, after obtaining the elements count and allocating their respective space. */ static void P_LoadTextmap(void) @@ -1532,7 +1510,7 @@ static void P_LoadTextmap(void) CONS_Alert(CONS_NOTICE, "UDMF support is still a work-in-progress; its specs and features are prone to change until it is fully implemented.\n"); /// Given the UDMF specs, some fields are given a default value. - /// If an element's field has a default value set, it is ommited + /// If an element's field has a default value set, it is omitted /// from the textmap, and therefore we have to account for it by /// preemptively setting that value beforehand. @@ -1541,7 +1519,7 @@ static void P_LoadTextmap(void) // Defaults. vt->z = 0; - TextmapParse(vertexesPos[i], i, TextmapVertex); + TextmapParse(vertexesPos[i], i, ParseTextmapVertexParameter); } for (i = 0, sc = sectors; i < numsectors; i++, sc++) @@ -1561,7 +1539,7 @@ static void P_LoadTextmap(void) sc->floor_xoffs = sc->floor_yoffs = sc->ceiling_xoffs = sc->ceiling_yoffs = 0; sc->floorpic_angle = sc->ceilingpic_angle = 0; - TextmapParse(sectorsPos[i], i, TextmapSector); + TextmapParse(sectorsPos[i], i, ParseTextmapSectorParameter); P_InitializeSector(sc); TextmapFixFlatOffsets(sc); @@ -1574,7 +1552,7 @@ static void P_LoadTextmap(void) ld->special = 0; ld->sidenum[1] = 0xffff; - TextmapParse(linesPos[i], i, TextmapLine); + TextmapParse(linesPos[i], i, ParseTextmapLinedefParameter); P_InitializeLinedef(ld); } @@ -1590,7 +1568,7 @@ static void P_LoadTextmap(void) sd->bottomtexture = R_TextureNumForName("-"); sd->repeatcnt = 0; - TextmapParse(sidesPos[i], i, TextmapSide); + TextmapParse(sidesPos[i], i, ParseTextmapSidedefParameter); } for (i = 0, mt = mapthings; i < nummapthings; i++, mt++) @@ -1599,7 +1577,7 @@ static void P_LoadTextmap(void) mt->z = 0; mt->angle = 0; - TextmapParse(mapthingsPos[i], i, TextmapThing); + TextmapParse(mapthingsPos[i], i, ParseTextmapThingParameter); } } From 05a97530c18a5f8e87fc47d27187b6a3a3542eb5 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Mon, 30 Dec 2019 17:28:10 +0100 Subject: [PATCH 14/26] Add support for flat offset and rotation fields in UDMF --- src/p_setup.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 4d4eaff6d..e4b73570f 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1338,6 +1338,18 @@ static void ParseTextmapSectorParameter(UINT32 i, char *param) sectors[i].special = atol(dat = M_GetToken(NULL)); else if (fastcmp(param, "id")) sectors[i].tag = atol(dat = M_GetToken(NULL)); + else if (fastcmp(param, "xpanningfloor")) + sectors[i].floor_xoffs = FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL))); + else if (fastcmp(param, "ypanningfloor")) + sectors[i].floor_yoffs = FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL))); + else if (fastcmp(param, "xpanningceiling")) + sectors[i].ceiling_xoffs = FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL))); + else if (fastcmp(param, "ypanningceiling")) + sectors[i].ceiling_yoffs = FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL))); + else if (fastcmp(param, "rotationfloor")) + sectors[i].floorpic_angle = FixedAngle(FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL)))); + else if (fastcmp(param, "rotationceiling")) + sectors[i].ceilingpic_angle = FixedAngle(FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL)))); } static void ParseTextmapSidedefParameter(UINT32 i, char *param) @@ -1536,12 +1548,8 @@ static void P_LoadTextmap(void) sc->special = 0; sc->tag = 0; - sc->floor_xoffs = sc->floor_yoffs = sc->ceiling_xoffs = sc->ceiling_yoffs = 0; - sc->floorpic_angle = sc->ceilingpic_angle = 0; - - TextmapParse(sectorsPos[i], i, ParseTextmapSectorParameter); - P_InitializeSector(sc); + TextmapParse(sectorsPos[i], i, ParseTextmapSectorParameter); TextmapFixFlatOffsets(sc); } From 013f1f70d91dff68e496e481357dfa1d9f9b426f Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Mon, 30 Dec 2019 21:23:00 +0100 Subject: [PATCH 15/26] -Set defaults for vertex and mapthing fields in textmap -Fix P_InitializeSector being called too early (band-aid fix for now, will reorganize this properly later) --- src/p_setup.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index e4b73570f..a48cfe909 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -865,11 +865,6 @@ static void P_InitializeSector(sector_t *ss) ss->lightingdata = NULL; ss->fadecolormapdata = NULL; - ss->floor_xoffs = ss->floor_yoffs = 0; - ss->ceiling_xoffs = ss->ceiling_yoffs = 0; - - ss->floorpic_angle = ss->ceilingpic_angle = 0; - ss->heightsec = -1; ss->camsec = -1; @@ -945,6 +940,11 @@ static void P_LoadSectors(UINT8 *data) ss->special = SHORT(ms->special); ss->tag = SHORT(ms->tag); + ss->floor_xoffs = ss->floor_yoffs = 0; + ss->ceiling_xoffs = ss->ceiling_yoffs = 0; + + ss->floorpic_angle = ss->ceilingpic_angle = 0; + P_InitializeSector(ss); } } @@ -1235,6 +1235,8 @@ static void P_LoadThings(UINT8 *data) mt->z = mt->options; // NiGHTS Hoops use the full flags bits to set the height. else mt->z = mt->options >> ZSHIFT; + + mt->mobj = NULL; } } @@ -1529,7 +1531,7 @@ static void P_LoadTextmap(void) for (i = 0, vt = vertexes; i < numvertexes; i++, vt++) { // Defaults. - vt->z = 0; + vt->x = vt->y = vt->z = 0; TextmapParse(vertexesPos[i], i, ParseTextmapVertexParameter); } @@ -1548,8 +1550,13 @@ static void P_LoadTextmap(void) sc->special = 0; sc->tag = 0; - P_InitializeSector(sc); + sc->floor_xoffs = sc->floor_yoffs = 0; + sc->ceiling_xoffs = sc->ceiling_yoffs = 0; + + sc->floorpic_angle = sc->ceilingpic_angle = 0; + TextmapParse(sectorsPos[i], i, ParseTextmapSectorParameter); + P_InitializeSector(sc); TextmapFixFlatOffsets(sc); } @@ -1582,8 +1589,13 @@ static void P_LoadTextmap(void) for (i = 0, mt = mapthings; i < nummapthings; i++, mt++) { // Defaults. - mt->z = 0; + mt->x = mt->y = 0; mt->angle = 0; + mt->type = 0; + mt->options = 0; + mt->z = 0; + mt->extrainfo = 0; + mt->mobj = NULL; TextmapParse(mapthingsPos[i], i, ParseTextmapThingParameter); } From 24d68ba07e862ce4b36633d416b00868c72b6607 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Wed, 1 Jan 2020 13:40:17 +0100 Subject: [PATCH 16/26] P_LoadTextmap: Set defaults for all linedef and sidedef fields that UDMF is allowed to set --- src/p_setup.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index a48cfe909..e71d6094f 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1563,8 +1563,11 @@ static void P_LoadTextmap(void) for (i = 0, ld = lines; i < numlines; i++, ld++) { // Defaults. - ld->tag = 0; + ld->v1 = ld->v2 = NULL; + ld->flags = 0; ld->special = 0; + ld->tag = 0; + ld->sidenum[0] = 0xffff; ld->sidenum[1] = 0xffff; TextmapParse(linesPos[i], i, ParseTextmapLinedefParameter); @@ -1575,12 +1578,12 @@ static void P_LoadTextmap(void) for (i = 0, sd = sides; i < numsides; i++, sd++) { // Defaults. - sd->rowoffset = 0; sd->textureoffset = 0; - + sd->rowoffset = 0; sd->toptexture = R_TextureNumForName("-"); sd->midtexture = R_TextureNumForName("-"); sd->bottomtexture = R_TextureNumForName("-"); + sd->sector = NULL; sd->repeatcnt = 0; TextmapParse(sidesPos[i], i, ParseTextmapSidedefParameter); From b59532bccaa332182b56087d6a3ca1e2fe1455a2 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Wed, 1 Jan 2020 14:13:24 +0100 Subject: [PATCH 17/26] Setup repeatcnt in P_LoadSidedefs instead of P_ProcessLinedefsWithSidedefs, since UDMF can set it directly --- src/p_setup.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index e71d6094f..d00eebfc8 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1014,13 +1014,11 @@ static void P_InitializeLinedef(line_t *ld) { sides[ld->sidenum[0]].special = ld->special; sides[ld->sidenum[0]].line = ld; - } if (ld->sidenum[1] != 0xffff) { sides[ld->sidenum[1]].special = ld->special; sides[ld->sidenum[1]].line = ld; - } } @@ -1053,10 +1051,30 @@ static void P_LoadSidedefs(UINT8 *data) for (i = 0; i < numsides; i++, sd++, msd++) { + INT16 textureoffset = SHORT(msd->textureoffset); UINT16 sector_num; - boolean isfrontside = !sd->line || sd->line->sidenum[0] == i; + boolean isfrontside; - sd->textureoffset = SHORT(msd->textureoffset)<line) + { + CONS_Debug(DBG_SETUP, "P_LoadSidedefs: Sidedef %s is not used by any linedef\n", sizeu1((size_t)(sd - sides))); + sd->line = &lines[0]; + } + + isfrontside = sd->line->sidenum[0] == i; + + // Repeat count for midtexture + if (((sd->line->flags & (ML_TWOSIDED|ML_EFFECT5)) == (ML_TWOSIDED|ML_EFFECT5)) + && !(sd->special >= 300 && sd->special < 500)) // exempt linedef exec specials + { + sd->repeatcnt = (INT16)(((unsigned)textureoffset) >> 12); + sd->textureoffset = (((unsigned)textureoffset) & 2047) << FRACBITS; + } + else + { + sd->repeatcnt = 0; + sd->textureoffset = textureoffset << FRACBITS; + } sd->rowoffset = SHORT(msd->rowoffset)<frontsector = sides[ld->sidenum[0]].sector; //e6y: Can't be -1 here ld->backsector = ld->sidenum[1] != 0xffff ? sides[ld->sidenum[1]].sector : 0; - // Repeat count for midtexture - if ((ld->flags & ML_EFFECT5) && (ld->sidenum[1] != 0xffff) - && !(ld->special >= 300 && ld->special < 500)) // exempt linedef exec specials - { - sides[ld->sidenum[0]].repeatcnt = (INT16)(((unsigned)sides[ld->sidenum[0]].textureoffset >> FRACBITS) >> 12); - sides[ld->sidenum[0]].textureoffset = (((unsigned)sides[ld->sidenum[0]].textureoffset >> FRACBITS) & 2047) << FRACBITS; - sides[ld->sidenum[1]].repeatcnt = (INT16)(((unsigned)sides[ld->sidenum[1]].textureoffset >> FRACBITS) >> 12); - sides[ld->sidenum[1]].textureoffset = (((unsigned)sides[ld->sidenum[1]].textureoffset >> FRACBITS) & 2047) << FRACBITS; - } - // Compile linedef 'text' from both sidedefs 'text' for appropriate specials. switch(ld->special) { From fe198b8a324e9cadee99ffcccf69b4102a4c3609 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Wed, 1 Jan 2020 14:27:01 +0100 Subject: [PATCH 18/26] Check if certain mandatory linedef and sidedef fields are set, and use fallback values if not --- src/p_setup.c | 70 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index d00eebfc8..c915000d9 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1022,6 +1022,26 @@ static void P_InitializeLinedef(line_t *ld) } } +static void P_SetLinedefV1(size_t i, UINT16 vertex_num) +{ + if (vertex_num >= numvertexes) + { + CONS_Debug(DBG_SETUP, "P_SetLinedefV1: linedef %s has out-of-range v1 num %u\n", sizeu1(i), vertex_num); + vertex_num = 0; + } + lines[i].v1 = &vertexes[vertex_num]; +} + +static void P_SetLinedefV2(size_t i, UINT16 vertex_num) +{ + if (vertex_num >= numvertexes) + { + CONS_Debug(DBG_SETUP, "P_SetLinedefV2: linedef %s has out-of-range v2 num %u\n", sizeu1(i), vertex_num); + vertex_num = 0; + } + lines[i].v2 = &vertexes[vertex_num]; +} + static void P_LoadLinedefs(UINT8 *data) { maplinedef_t *mld = (maplinedef_t *)data; @@ -1033,8 +1053,8 @@ static void P_LoadLinedefs(UINT8 *data) ld->flags = SHORT(mld->flags); ld->special = SHORT(mld->special); ld->tag = SHORT(mld->tag); - ld->v1 = &vertexes[SHORT(mld->v1)]; - ld->v2 = &vertexes[SHORT(mld->v2)]; + P_SetLinedefV1(i, SHORT(mld->v1)); + P_SetLinedefV2(i, SHORT(mld->v2)); ld->sidenum[0] = SHORT(mld->sidenum[0]); ld->sidenum[1] = SHORT(mld->sidenum[1]); @@ -1043,6 +1063,17 @@ static void P_LoadLinedefs(UINT8 *data) } } +static void P_SetSidedefSector(size_t i, UINT16 sector_num) +{ + // cph 2006/09/30 - catch out-of-range sector numbers; use sector 0 instead + if (sector_num >= numsectors) + { + CONS_Debug(DBG_SETUP, "P_SetSidedefSector: sidedef %s has out-of-range sector num %u\n", sizeu1(i), sector_num); + sector_num = 0; + } + sides[i].sector = §ors[sector_num]; +} + static void P_LoadSidedefs(UINT8 *data) { mapsidedef_t *msd = (mapsidedef_t*)data; @@ -1052,12 +1083,11 @@ static void P_LoadSidedefs(UINT8 *data) for (i = 0; i < numsides; i++, sd++, msd++) { INT16 textureoffset = SHORT(msd->textureoffset); - UINT16 sector_num; boolean isfrontside; if (!sd->line) { - CONS_Debug(DBG_SETUP, "P_LoadSidedefs: Sidedef %s is not used by any linedef\n", sizeu1((size_t)(sd - sides))); + CONS_Debug(DBG_SETUP, "P_LoadSidedefs: Sidedef %s is not used by any linedef\n", sizeu1(i)); sd->line = &lines[0]; } @@ -1077,14 +1107,7 @@ static void P_LoadSidedefs(UINT8 *data) } sd->rowoffset = SHORT(msd->rowoffset)<sector); - if (sector_num >= numsectors) - { - CONS_Debug(DBG_SETUP, "P_LoadSidedefs: sidedef %s has out-of-range sector num %u\n", sizeu1(i), sector_num); - sector_num = 0; - } - sd->sector = §ors[sector_num]; + P_SetSidedefSector(i, SHORT(msd->sector)); sd->colormap_data = NULL; @@ -1385,7 +1408,7 @@ static void ParseTextmapSidedefParameter(UINT32 i, char *param) else if (fastcmp(param, "texturemiddle")) sides[i].midtexture = R_TextureNumForName(dat = M_GetToken(NULL)); else if (fastcmp(param, "sector")) - sides[i].sector = §ors[atol(dat = M_GetToken(NULL))]; + P_SetSidedefSector(i, atol(dat = M_GetToken(NULL))); else if (fastcmp(param, "repeatcnt")) sides[i].repeatcnt = atol(dat = M_GetToken(NULL)); } @@ -1397,9 +1420,9 @@ static void ParseTextmapLinedefParameter(UINT32 i, char *param) else if (fastcmp(param, "special")) lines[i].special = atol(dat = M_GetToken(NULL)); else if (fastcmp(param, "v1")) - lines[i].v1 = &vertexes[atol(dat = M_GetToken(NULL))]; + P_SetLinedefV1(i, atol(dat = M_GetToken(NULL))); else if (fastcmp(param, "v2")) - lines[i].v2 = &vertexes[atol(dat = M_GetToken(NULL))]; + P_SetLinedefV2(i, atol(dat = M_GetToken(NULL))); else if (fastcmp(param, "sidefront")) lines[i].sidenum[0] = atol(dat = M_GetToken(NULL)); else if (fastcmp(param, "sideback")) @@ -1589,7 +1612,16 @@ static void P_LoadTextmap(void) ld->sidenum[1] = 0xffff; TextmapParse(linesPos[i], i, ParseTextmapLinedefParameter); - + if (!ld->v1) + { + CONS_Debug(DBG_SETUP, "P_LoadTextmap: linedef %s has no v1 set; defaulting to 0\n", sizeu1(i)); + ld->v1 = &vertexes[0]; + } + if (!ld->v2) + { + CONS_Debug(DBG_SETUP, "P_LoadTextmap: linedef %s has no v2 set; defaulting to 0\n", sizeu1(i)); + ld->v2 = &vertexes[0]; + } P_InitializeLinedef(ld); } @@ -1605,6 +1637,12 @@ static void P_LoadTextmap(void) sd->repeatcnt = 0; TextmapParse(sidesPos[i], i, ParseTextmapSidedefParameter); + + if (!sd->sector) + { + CONS_Debug(DBG_SETUP, "P_LoadTextmap: sidedef %s has no sector set; defaulting to 0\n", sizeu1(i)); + sd->sector = §ors[0]; + } } for (i = 0, mt = mapthings; i < nummapthings; i++, mt++) From a41c6405591fd6ba8bd3f4081620be321f3dfc06 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Wed, 1 Jan 2020 15:10:41 +0100 Subject: [PATCH 19/26] Move shared parts of sidedef initialization into P_InitializeSidedef --- src/p_setup.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index c915000d9..e2ae29cf7 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1074,6 +1074,19 @@ static void P_SetSidedefSector(size_t i, UINT16 sector_num) sides[i].sector = §ors[sector_num]; } +static void P_InitializeSidedef(side_t *sd) +{ + if (!sd->line) + { + CONS_Debug(DBG_SETUP, "P_LoadSidedefs: Sidedef %s is not used by any linedef\n", sizeu1(i)); + sd->line = &lines[0]; + sd->special = sd->line->special; + } + + sd->text = NULL; + sd->colormap_data = NULL; +} + static void P_LoadSidedefs(UINT8 *data) { mapsidedef_t *msd = (mapsidedef_t*)data; @@ -1085,11 +1098,7 @@ static void P_LoadSidedefs(UINT8 *data) INT16 textureoffset = SHORT(msd->textureoffset); boolean isfrontside; - if (!sd->line) - { - CONS_Debug(DBG_SETUP, "P_LoadSidedefs: Sidedef %s is not used by any linedef\n", sizeu1(i)); - sd->line = &lines[0]; - } + P_InitializeSidedef(sd); isfrontside = sd->line->sidenum[0] == i; @@ -1109,8 +1118,6 @@ static void P_LoadSidedefs(UINT8 *data) P_SetSidedefSector(i, SHORT(msd->sector)); - sd->colormap_data = NULL; - // Special info stored in texture fields! switch (sd->special) { @@ -1643,6 +1650,7 @@ static void P_LoadTextmap(void) CONS_Debug(DBG_SETUP, "P_LoadTextmap: sidedef %s has no sector set; defaulting to 0\n", sizeu1(i)); sd->sector = §ors[0]; } + P_InitializeSidedef(sd); } for (i = 0, mt = mapthings; i < nummapthings; i++, mt++) From 6724b11c368ced28b65315942de1bd5b6003df98 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Wed, 1 Jan 2020 15:11:39 +0100 Subject: [PATCH 20/26] Whoops --- src/p_setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_setup.c b/src/p_setup.c index e2ae29cf7..f72e25da0 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1078,7 +1078,7 @@ static void P_InitializeSidedef(side_t *sd) { if (!sd->line) { - CONS_Debug(DBG_SETUP, "P_LoadSidedefs: Sidedef %s is not used by any linedef\n", sizeu1(i)); + CONS_Debug(DBG_SETUP, "P_LoadSidedefs: Sidedef %s is not used by any linedef\n", sizeu1((size_t)(sd - sides))); sd->line = &lines[0]; sd->special = sd->line->special; } From 9cda82d896a47179f307c0177525e390494c9219 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Wed, 1 Jan 2020 15:52:59 +0100 Subject: [PATCH 21/26] Rework textmap parser to always read a parameter's value, even if it doesn't recognize the parameter --- src/p_setup.c | 151 +++++++++++++++++++++++++------------------------- 1 file changed, 75 insertions(+), 76 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index f72e25da0..dc115ed19 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1362,135 +1362,133 @@ static boolean TextmapCount(UINT8 *data, size_t size) return true; } -static char* dat; - -static void ParseTextmapVertexParameter(UINT32 i, char *param) +static void ParseTextmapVertexParameter(UINT32 i, char *param, char *val) { if (fastcmp(param, "x")) - vertexes[i].x = FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL))); + vertexes[i].x = FLOAT_TO_FIXED(atof(val)); else if (fastcmp(param, "y")) - vertexes[i].y = FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL))); + vertexes[i].y = FLOAT_TO_FIXED(atof(val)); } -static void ParseTextmapSectorParameter(UINT32 i, char *param) +static void ParseTextmapSectorParameter(UINT32 i, char *param, char *val) { if (fastcmp(param, "heightfloor")) - sectors[i].floorheight = atol(dat = M_GetToken(NULL)) << FRACBITS; + sectors[i].floorheight = atol(val) << FRACBITS; else if (fastcmp(param, "heightceiling")) - sectors[i].ceilingheight = atol(dat = M_GetToken(NULL)) << FRACBITS; + sectors[i].ceilingheight = atol(val) << FRACBITS; if (fastcmp(param, "texturefloor")) - sectors[i].floorpic = P_AddLevelFlat(dat = M_GetToken(NULL), foundflats); + sectors[i].floorpic = P_AddLevelFlat(val, foundflats); else if (fastcmp(param, "textureceiling")) - sectors[i].ceilingpic = P_AddLevelFlat(dat = M_GetToken(NULL), foundflats); + sectors[i].ceilingpic = P_AddLevelFlat(val, foundflats); else if (fastcmp(param, "lightlevel")) - sectors[i].lightlevel = atol(dat = M_GetToken(NULL)); + sectors[i].lightlevel = atol(val); else if (fastcmp(param, "special")) - sectors[i].special = atol(dat = M_GetToken(NULL)); + sectors[i].special = atol(val); else if (fastcmp(param, "id")) - sectors[i].tag = atol(dat = M_GetToken(NULL)); + sectors[i].tag = atol(val); else if (fastcmp(param, "xpanningfloor")) - sectors[i].floor_xoffs = FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL))); + sectors[i].floor_xoffs = FLOAT_TO_FIXED(atof(val)); else if (fastcmp(param, "ypanningfloor")) - sectors[i].floor_yoffs = FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL))); + sectors[i].floor_yoffs = FLOAT_TO_FIXED(atof(val)); else if (fastcmp(param, "xpanningceiling")) - sectors[i].ceiling_xoffs = FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL))); + sectors[i].ceiling_xoffs = FLOAT_TO_FIXED(atof(val)); else if (fastcmp(param, "ypanningceiling")) - sectors[i].ceiling_yoffs = FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL))); + sectors[i].ceiling_yoffs = FLOAT_TO_FIXED(atof(val)); else if (fastcmp(param, "rotationfloor")) - sectors[i].floorpic_angle = FixedAngle(FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL)))); + sectors[i].floorpic_angle = FixedAngle(FLOAT_TO_FIXED(atof(val))); else if (fastcmp(param, "rotationceiling")) - sectors[i].ceilingpic_angle = FixedAngle(FLOAT_TO_FIXED(atof(dat = M_GetToken(NULL)))); + sectors[i].ceilingpic_angle = FixedAngle(FLOAT_TO_FIXED(atof(val))); } -static void ParseTextmapSidedefParameter(UINT32 i, char *param) +static void ParseTextmapSidedefParameter(UINT32 i, char *param, char *val) { if (fastcmp(param, "offsetx")) - sides[i].textureoffset = atol(dat = M_GetToken(NULL))< Date: Wed, 1 Jan 2020 16:01:07 +0100 Subject: [PATCH 22/26] Move MAXFLATSIZE define to p_spec.h so p_spec.c doesn't have to redefine it --- src/p_setup.c | 4 ---- src/p_spec.c | 3 --- src/p_spec.h | 3 +++ 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index dc115ed19..8b82e8c69 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1527,8 +1527,6 @@ static void TextmapParse(UINT32 dataPos, size_t num, void (*parser)(UINT32, char } } -#define MAXFLATSIZE (2048<> ((j-1)*4))&15) +// This must be updated whenever we up the max flat size - quicker to assume rather than figuring out the sqrt of the specific flat's filesize. +#define MAXFLATSIZE (2048< Date: Wed, 1 Jan 2020 23:52:30 +0100 Subject: [PATCH 23/26] P_LoadTextmap: Bail out if certain mandatory fields are not set --- src/p_setup.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 8b82e8c69..de6503dca 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1574,9 +1574,15 @@ static void P_LoadTextmap(void) for (i = 0, vt = vertexes; i < numvertexes; i++, vt++) { // Defaults. - vt->x = vt->y = vt->z = 0; + vt->x = vt->y = INT32_MAX; + vt->z = 0; TextmapParse(vertexesPos[i], i, ParseTextmapVertexParameter); + + if (vt->x == INT32_MAX) + I_Error("P_LoadTextmap: vertex %s has no x value set!\n", sizeu1(i)); + if (vt->y == INT32_MAX) + I_Error("P_LoadTextmap: vertex %s has no y value set!\n", sizeu1(i)); } for (i = 0, sc = sectors; i < numsectors; i++, sc++) @@ -1614,16 +1620,14 @@ static void P_LoadTextmap(void) ld->sidenum[1] = 0xffff; TextmapParse(linesPos[i], i, ParseTextmapLinedefParameter); + if (!ld->v1) - { - CONS_Debug(DBG_SETUP, "P_LoadTextmap: linedef %s has no v1 set; defaulting to 0\n", sizeu1(i)); - ld->v1 = &vertexes[0]; - } + I_Error("P_LoadTextmap: linedef %s has no v1 value set!\n", sizeu1(i)); if (!ld->v2) - { - CONS_Debug(DBG_SETUP, "P_LoadTextmap: linedef %s has no v2 set; defaulting to 0\n", sizeu1(i)); - ld->v2 = &vertexes[0]; - } + I_Error("P_LoadTextmap: linedef %s has no v2 value set!\n", sizeu1(i)); + if (ld->sidenum[0] == 0xffff) + I_Error("P_LoadTextmap: linedef %s has no sidefront value set!\n", sizeu1(i)); + P_InitializeLinedef(ld); } @@ -1641,10 +1645,8 @@ static void P_LoadTextmap(void) TextmapParse(sidesPos[i], i, ParseTextmapSidedefParameter); if (!sd->sector) - { - CONS_Debug(DBG_SETUP, "P_LoadTextmap: sidedef %s has no sector set; defaulting to 0\n", sizeu1(i)); - sd->sector = §ors[0]; - } + I_Error("P_LoadTextmap: sidedef %s has no sector value set!\n", sizeu1(i)); + P_InitializeSidedef(sd); } From 02acf6222be72d9c594f55792ad6324221e4bc52 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Thu, 2 Jan 2020 00:32:29 +0100 Subject: [PATCH 24/26] P_LoadExtendedSubsectorsAndSegs: Slightly simplify the seg vertex reading code --- src/p_setup.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index de6503dca..d83b7adaa 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2027,13 +2027,8 @@ static boolean P_LoadExtendedSubsectorsAndSegs(UINT8 **data, nodetype_t nodetype for (m = 0; m < subsectors[i].numlines; m++, k++) { UINT16 linenum; - UINT32 vert = READUINT32((*data)); - segs[k].v1 = &vertexes[vert]; - if (m == 0) - segs[k + subsectors[i].numlines - 1].v2 = &vertexes[vert]; - else - segs[k - 1].v2 = segs[k].v1; + segs[k - 1 + ((m == 0) ? 0 : subsectors[i].numlines)].v2 = segs[k].v1 = &vertexes[READUINT32((*data))]; (*data) += 4; // partner, can be ignored by software renderer if (nodetype == NT_XGL3) From 5ba179ad7c53a82cdb5810c1f292d2a0e00ed2b1 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Thu, 2 Jan 2020 09:51:07 +0100 Subject: [PATCH 25/26] Fix two bugs in extended segs loading, and add some error checking while I'm at it --- src/p_setup.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index d83b7adaa..4de5fedc8 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1840,10 +1840,13 @@ static inline float P_SegLengthFloat(seg_t *seg) static void P_InitializeSeg(seg_t *seg) { - seg->sidedef = &sides[seg->linedef->sidenum[seg->side]]; + if (seg->linedef) + { + seg->sidedef = &sides[seg->linedef->sidenum[seg->side]]; - seg->frontsector = seg->sidedef->sector; - seg->backsector = (seg->linedef->flags & ML_TWOSIDED) ? sides[seg->linedef->sidenum[seg->side ^ 1]].sector : NULL; + seg->frontsector = seg->sidedef->sector; + seg->backsector = (seg->linedef->flags & ML_TWOSIDED) ? sides[seg->linedef->sidenum[seg->side ^ 1]].sector : NULL; + } #ifdef HWRENDER seg->pv1 = seg->pv2 = NULL; @@ -2026,15 +2029,21 @@ static boolean P_LoadExtendedSubsectorsAndSegs(UINT8 **data, nodetype_t nodetype case NT_XGL3: for (m = 0; m < subsectors[i].numlines; m++, k++) { + UINT32 vertexnum = READUINT32((*data)); UINT16 linenum; - segs[k - 1 + ((m == 0) ? 0 : subsectors[i].numlines)].v2 = segs[k].v1 = &vertexes[READUINT32((*data))]; + if (vertexnum >= numvertexes) + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %d in subsector %d has invalid vertex %d!\n", k, m, vertexnum); - (*data) += 4; // partner, can be ignored by software renderer + segs[k - 1 + ((m == 0) ? subsectors[i].numlines : 0)].v2 = segs[k].v1 = &vertexes[vertexnum]; + + READUINT32((*data)); // partner, can be ignored by software renderer if (nodetype == NT_XGL3) - (*data) += 2; // Line number is 32-bit in XGL3, but we're limited to 16 bits. + READUINT16((*data)); // Line number is 32-bit in XGL3, but we're limited to 16 bits. linenum = READUINT16((*data)); + if (linenum != 0xFFFF && linenum >= numlines) + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %d in subsector %d has invalid linedef %d!\n", k, m, linenum); segs[k].glseg = (linenum == 0xFFFF); segs[k].linedef = (linenum == 0xFFFF) ? NULL : &lines[linenum]; segs[k].side = READUINT8((*data)); @@ -2044,9 +2053,20 @@ static boolean P_LoadExtendedSubsectorsAndSegs(UINT8 **data, nodetype_t nodetype case NT_XNOD: for (m = 0; m < subsectors[i].numlines; m++, k++) { - segs[k].v1 = &vertexes[READUINT32((*data))]; - segs[k].v2 = &vertexes[READUINT32((*data))]; - segs[k].linedef = &lines[READUINT16((*data))]; + UINT32 v1num = READUINT32((*data)); + UINT32 v2num = READUINT32((*data)); + UINT16 linenum = READUINT16((*data)); + + if (v1num >= numvertexes) + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %d in subsector %d has invalid v1 %d!\n", k, m, v1num); + if (v2num >= numvertexes) + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %d in subsector %d has invalid v2 %d!\n", k, m, v2num); + if (linenum >= numlines) + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %d in subsector %d has invalid linedef %d!\n", k, m, linenum); + + segs[k].v1 = &vertexes[v1num]; + segs[k].v2 = &vertexes[v2num]; + segs[k].linedef = &lines[linenum]; segs[k].side = READUINT8((*data)); segs[k].glseg = false; } @@ -2063,7 +2083,8 @@ static boolean P_LoadExtendedSubsectorsAndSegs(UINT8 **data, nodetype_t nodetype vertex_t *v2 = seg->v2; P_InitializeSeg(seg); seg->angle = R_PointToAngle2(v1->x, v1->y, v2->x, v2->y); - seg->offset = FixedHypot(v1->x - seg->linedef->v1->x, v1->y - seg->linedef->v1->y); + if (seg->linedef) + segs[i].offset = FixedHypot(v1->x - seg->linedef->v1->x, v1->y - seg->linedef->v1->y); } return true; From dc0c17dbb85ebd06cf0e659ac33cc7ff2add7cc7 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Thu, 2 Jan 2020 22:28:32 +0100 Subject: [PATCH 26/26] P_LoadExtendedSubsectorsAndSegs: Print size_t with %s --- src/p_setup.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 4de5fedc8..e3a7e1e58 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2033,7 +2033,7 @@ static boolean P_LoadExtendedSubsectorsAndSegs(UINT8 **data, nodetype_t nodetype UINT16 linenum; if (vertexnum >= numvertexes) - I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %d in subsector %d has invalid vertex %d!\n", k, m, vertexnum); + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %d has invalid vertex %d!\n", sizeu1(k), m, vertexnum); segs[k - 1 + ((m == 0) ? subsectors[i].numlines : 0)].v2 = segs[k].v1 = &vertexes[vertexnum]; @@ -2043,7 +2043,7 @@ static boolean P_LoadExtendedSubsectorsAndSegs(UINT8 **data, nodetype_t nodetype linenum = READUINT16((*data)); if (linenum != 0xFFFF && linenum >= numlines) - I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %d in subsector %d has invalid linedef %d!\n", k, m, linenum); + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %d has invalid linedef %d!\n", sizeu1(k), m, linenum); segs[k].glseg = (linenum == 0xFFFF); segs[k].linedef = (linenum == 0xFFFF) ? NULL : &lines[linenum]; segs[k].side = READUINT8((*data)); @@ -2058,11 +2058,11 @@ static boolean P_LoadExtendedSubsectorsAndSegs(UINT8 **data, nodetype_t nodetype UINT16 linenum = READUINT16((*data)); if (v1num >= numvertexes) - I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %d in subsector %d has invalid v1 %d!\n", k, m, v1num); + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %d has invalid v1 %d!\n", sizeu1(k), m, v1num); if (v2num >= numvertexes) - I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %d in subsector %d has invalid v2 %d!\n", k, m, v2num); + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %d has invalid v2 %d!\n", sizeu1(k), m, v2num); if (linenum >= numlines) - I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %d in subsector %d has invalid linedef %d!\n", k, m, linenum); + I_Error("P_LoadExtendedSubsectorsAndSegs: Seg %s in subsector %d has invalid linedef %d!\n", sizeu1(k), m, linenum); segs[k].v1 = &vertexes[v1num]; segs[k].v2 = &vertexes[v2num];