From a7e99ab5cfd2acb306542c448dfb6af9140e4d28 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sun, 12 Apr 2020 11:56:36 +0200 Subject: [PATCH 01/75] Added static multitag read and storage on mapload. --- src/CMakeLists.txt | 2 ++ src/Makefile | 1 + src/doomdata.h | 3 +++ src/p_setup.c | 50 +++++++++++++++++++++++++++++++++++++++++++++- src/r_defs.h | 4 ++++ src/taglist.c | 8 ++++++++ src/taglist.h | 14 +++++++++++++ 7 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/taglist.c create mode 100644 src/taglist.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b0a593bb1..7f18407ac 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -164,6 +164,7 @@ set(SRB2_CORE_GAME_SOURCES p_telept.c p_tick.c p_user.c + taglist.c p_local.h p_maputl.h @@ -175,6 +176,7 @@ set(SRB2_CORE_GAME_SOURCES p_slopes.h p_spec.h p_tick.h + taglist.h ) if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) diff --git a/src/Makefile b/src/Makefile index fdf9c78b7..d27883563 100644 --- a/src/Makefile +++ b/src/Makefile @@ -474,6 +474,7 @@ OBJS:=$(i_main_o) \ $(OBJDIR)/r_patch.o \ $(OBJDIR)/r_portal.o \ $(OBJDIR)/screen.o \ + $(OBJDIR)/taglist.o \ $(OBJDIR)/v_video.o \ $(OBJDIR)/s_sound.o \ $(OBJDIR)/sounds.o \ diff --git a/src/doomdata.h b/src/doomdata.h index d9bfb43b1..884c043a4 100644 --- a/src/doomdata.h +++ b/src/doomdata.h @@ -23,6 +23,8 @@ // Some global defines, that configure the game. #include "doomdef.h" +#include "taglist.h" + // // Map level types. // The following data structures define the persistent format @@ -204,6 +206,7 @@ typedef struct INT16 z; UINT8 extrainfo; INT16 tag; + taglist_t tags; struct mobj_s *mobj; } mapthing_t; diff --git a/src/p_setup.c b/src/p_setup.c index 871fb14fe..e4658d742 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -81,6 +81,8 @@ #include "fastcmp.h" // textmap parsing +#include "taglist.h" + // // Map MD5, calculated on level load. // Sent to clients in PT_SERVERINFO. @@ -935,6 +937,8 @@ static void P_LoadSectors(UINT8 *data) ss->lightlevel = SHORT(ms->lightlevel); ss->special = SHORT(ms->special); ss->tag = SHORT(ms->tag); + if (ss->tag) + Tag_Add(&ss->tags, ss->tag); ss->floor_xoffs = ss->floor_yoffs = 0; ss->ceiling_xoffs = ss->ceiling_yoffs = 0; @@ -1049,6 +1053,8 @@ static void P_LoadLinedefs(UINT8 *data) ld->flags = SHORT(mld->flags); ld->special = SHORT(mld->special); ld->tag = SHORT(mld->tag); + if (ld->tag) + Tag_Add(&ld->tags, ld->tag); memset(ld->args, 0, NUMLINEARGS*sizeof(*ld->args)); memset(ld->stringargs, 0x00, NUMLINESTRINGARGS*sizeof(*ld->stringargs)); ld->alpha = FRACUNIT; @@ -1398,7 +1404,21 @@ static void ParseTextmapSectorParameter(UINT32 i, char *param, char *val) else if (fastcmp(param, "special")) sectors[i].special = atol(val); else if (fastcmp(param, "id")) + { sectors[i].tag = atol(val); + if (sectors[i].tag) + Tag_Add(§ors[i].tags, sectors[i].tag); + } + else if (fastcmp(param, "moreids")) + { + char* id = val; + while (id) + { + Tag_Add(§ors[i].tags, atol(id)); + if ((id = strchr(id, ' '))) + id++; + } + } else if (fastcmp(param, "xpanningfloor")) sectors[i].floor_xoffs = FLOAT_TO_FIXED(atof(val)); else if (fastcmp(param, "ypanningfloor")) @@ -1434,7 +1454,21 @@ static void ParseTextmapSidedefParameter(UINT32 i, char *param, char *val) static void ParseTextmapLinedefParameter(UINT32 i, char *param, char *val) { if (fastcmp(param, "id")) + { lines[i].tag = atol(val); + if (lines[i].tag) + Tag_Add(&lines[i].tags, lines[i].tag); + } + else if (fastcmp(param, "moreids")) + { + char* id = val; + while (id) + { + Tag_Add(&lines[i].tags, atol(id)); + if ((id = strchr(id, ' '))) + id++; + } + } else if (fastcmp(param, "special")) lines[i].special = atol(val); else if (fastcmp(param, "v1")) @@ -1501,8 +1535,22 @@ static void ParseTextmapLinedefParameter(UINT32 i, char *param, char *val) static void ParseTextmapThingParameter(UINT32 i, char *param, char *val) { if (fastcmp(param, "id")) + { mapthings[i].tag = atol(val); - if (fastcmp(param, "x")) + if (mapthings[i].tag) + Tag_Add(&mapthings[i].tags, mapthings[i].tag); + } + else if (fastcmp(param, "moreids")) + { + char* id = val; + while (id) + { + Tag_Add(&mapthings[i].tags, atol(id)); + if ((id = strchr(id, ' '))) + id++; + } + } + else if (fastcmp(param, "x")) mapthings[i].x = atol(val); else if (fastcmp(param, "y")) mapthings[i].y = atol(val); diff --git a/src/r_defs.h b/src/r_defs.h index 943f54761..ab35b2055 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -30,6 +30,8 @@ #define POLYOBJECTS +#include "taglist.h" + // // ClipWallSegment // Clips the given range of columns @@ -290,6 +292,7 @@ typedef struct sector_s INT16 lightlevel; INT16 special; UINT16 tag; + taglist_t tags; INT32 nexttag, firsttag; // for fast tag searches // origin for any sounds played by the sector @@ -413,6 +416,7 @@ typedef struct line_s INT16 flags; INT16 special; INT16 tag; + taglist_t tags; INT32 args[NUMLINEARGS]; char *stringargs[NUMLINESTRINGARGS]; diff --git a/src/taglist.c b/src/taglist.c new file mode 100644 index 000000000..9090d4e0b --- /dev/null +++ b/src/taglist.c @@ -0,0 +1,8 @@ +#include "taglist.h" +#include "z_zone.h" + +void Tag_Add (taglist_t* list, const UINT16 tag) +{ + list->tags = Z_Realloc(list->tags, (list->count + 1) * sizeof(list->tags), PU_LEVEL, NULL); + list->tags[list->count++] = tag; +} diff --git a/src/taglist.h b/src/taglist.h new file mode 100644 index 000000000..744918d7c --- /dev/null +++ b/src/taglist.h @@ -0,0 +1,14 @@ +#include "doomtype.h" + +#ifndef __R_TAGLIST__ +#define __R_TAGLIST__ + +/// Multitag list. +typedef struct +{ + UINT16* tags; + UINT16 count; +} taglist_t; + +void Tag_Add (taglist_t* list, const UINT16 tag); +#endif //__R_TAGLIST__ From ab2619d5386336044b1d13e0f9785d7ad4f808ba Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sun, 12 Apr 2020 13:04:15 +0200 Subject: [PATCH 02/75] Wrap P_FindSectorFromLineTag() is now a wrapper for P_FindSectorFromTag(). --- src/p_spec.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index cf4ab3da3..529c50e4d 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -998,23 +998,7 @@ static sector_t *P_FindModelCeilingSector(fixed_t ceildestheight, INT32 secnum) */ INT32 P_FindSectorFromLineTag(line_t *line, INT32 start) { - if (line->tag == -1) - { - start++; - - if (start >= (INT32)numsectors) - return -1; - - return start; - } - else - { - start = start >= 0 ? sectors[start].nexttag : - sectors[(unsigned)line->tag % numsectors].firsttag; - while (start >= 0 && sectors[start].tag != line->tag) - start = sectors[start].nexttag; - return start; - } + return P_FindSectorFromTag(line->tag, start); } /** Searches the tag lists for the next sector with a given tag. From bfd48c4c83d34d667648f31c8edf034f5f88f2ae Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sun, 12 Apr 2020 13:05:21 +0200 Subject: [PATCH 03/75] add Tag_Compare() --- src/taglist.c | 14 ++++++++++++++ src/taglist.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/taglist.c b/src/taglist.c index 9090d4e0b..ceaebf9aa 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -6,3 +6,17 @@ void Tag_Add (taglist_t* list, const UINT16 tag) list->tags = Z_Realloc(list->tags, (list->count + 1) * sizeof(list->tags), PU_LEVEL, NULL); list->tags[list->count++] = tag; } + +boolean Tag_Compare (const taglist_t* list1, const taglist_t* list2) +{ + size_t i; + + if (list1->count != list2->count) + return false; + + for (i = 0; i < list1->count; i++) + if (list1->tags[i] != list2->tags[i]) + return false; + + return true; +} diff --git a/src/taglist.h b/src/taglist.h index 744918d7c..62fac0d82 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -11,4 +11,5 @@ typedef struct } taglist_t; void Tag_Add (taglist_t* list, const UINT16 tag); +boolean Tag_Compare (const taglist_t* list1, const taglist_t* list2); #endif //__R_TAGLIST__ From fe4ab5d29f5d68759820912bc3762d5803d6a968 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sun, 12 Apr 2020 13:14:39 +0200 Subject: [PATCH 04/75] Use Tags_Compare wrapper on software renderer to compare sector tags. --- src/r_bsp.c | 5 +++-- src/r_segs.c | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/r_bsp.c b/src/r_bsp.c index 77ab2a82f..e581e6687 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -21,6 +21,7 @@ #include "p_local.h" // camera #include "p_slopes.h" #include "z_zone.h" // Check R_Prep3DFloors +#include "taglist.h" seg_t *curline; side_t *sidedef; @@ -376,7 +377,7 @@ boolean R_IsEmptyLine(seg_t *line, sector_t *front, sector_t *back) // Consider colormaps && back->extra_colormap == front->extra_colormap && ((!front->ffloors && !back->ffloors) - || front->tag == back->tag)); + || Tags_Compare(&front->tags, &back->tags))); } // @@ -488,7 +489,7 @@ static void R_AddLine(seg_t *line) #endif !line->sidedef->midtexture && ((!frontsector->ffloors && !backsector->ffloors) - || (frontsector->tag == backsector->tag))) + || Tags_Compare(&frontsector->tags, &backsector->tags))) return; // line is empty, don't even bother goto clippass; // treat like wide open window instead diff --git a/src/r_segs.c b/src/r_segs.c index e777ab2d0..1d6a56467 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -25,6 +25,7 @@ #include "p_local.h" // Camera... #include "p_slopes.h" #include "console.h" // con_clipviewtop +#include "taglist.h" // OPTIMIZE: closed two sided lines as single sided @@ -2014,7 +2015,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) || backsector->floorlightsec != frontsector->floorlightsec //SoM: 4/3/2000: Check for colormaps || frontsector->extra_colormap != backsector->extra_colormap - || (frontsector->ffloors != backsector->ffloors && frontsector->tag != backsector->tag)) + || (frontsector->ffloors != backsector->ffloors && !Tags_Compare(&frontsector->tags, &backsector->tags)) { markfloor = true; } @@ -2045,7 +2046,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) || backsector->ceilinglightsec != frontsector->ceilinglightsec //SoM: 4/3/2000: Check for colormaps || frontsector->extra_colormap != backsector->extra_colormap - || (frontsector->ffloors != backsector->ffloors && frontsector->tag != backsector->tag)) + || (frontsector->ffloors != backsector->ffloors && !Tags_Compare(&frontsector->tags, &backsector->tags)) { markceiling = true; } @@ -2135,7 +2136,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) rw_bottomtexturemid += sidedef->rowoffset; // allocate space for masked texture tables - if (frontsector && backsector && frontsector->tag != backsector->tag && (backsector->ffloors || frontsector->ffloors)) + if (frontsector && backsector && !Tags_Compare(&frontsector->tags, &backsector->tags) && (backsector->ffloors || frontsector->ffloors)) { ffloor_t *rover; ffloor_t *r2; From 64e2e7c12f5e9c40000c113f39c602a6bcedd43c Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sun, 12 Apr 2020 13:16:33 +0200 Subject: [PATCH 05/75] Use Tags_Compare wrapper in the OpenGL renderer, as well. --- src/hardware/hw_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 235505341..05b7c997f 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1862,7 +1862,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) //Hurdler: 3d-floors test #ifdef R_FAKEFLOORS - if (gr_frontsector && gr_backsector && gr_frontsector->tag != gr_backsector->tag && (gr_backsector->ffloors || gr_frontsector->ffloors)) + if (gr_frontsector && gr_backsector && !Tags_Compare(&gr_frontsector->tags, &gr_backsector->tags) && (gr_backsector->ffloors || gr_frontsector->ffloors)) { ffloor_t * rover; fixed_t highcut = 0, lowcut = 0; @@ -2662,7 +2662,7 @@ static void HWR_AddLine(seg_t * line) #endif !line->sidedef->midtexture && ((!gr_frontsector->ffloors && !gr_backsector->ffloors) - || (gr_frontsector->tag == gr_backsector->tag))) + || Tags_Compare(&gr_frontsector->tags, &gr_backsector->tags))) return; // line is empty, don't even bother // treat like wide open window instead HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D @@ -2704,7 +2704,7 @@ static void HWR_AddLine(seg_t * line) #endif !line->sidedef->midtexture && ((!gr_frontsector->ffloors && !gr_backsector->ffloors) - || (gr_frontsector->tag == gr_backsector->tag))) + || Tags_Compare(&gr_frontsector->tags, &gr_backsector->tags))) return; // line is empty, don't even bother goto clippass; // treat like wide open window instead From 38e92aecfd8ec57e53d398bf4149ac6f9f785287 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sun, 12 Apr 2020 15:03:14 +0200 Subject: [PATCH 06/75] Fix Tags_Compare() typo to Tag_Compare(). --- src/hardware/hw_main.c | 6 +++--- src/r_bsp.c | 4 ++-- src/r_segs.c | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 05b7c997f..7ebdb0f07 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1862,7 +1862,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) //Hurdler: 3d-floors test #ifdef R_FAKEFLOORS - if (gr_frontsector && gr_backsector && !Tags_Compare(&gr_frontsector->tags, &gr_backsector->tags) && (gr_backsector->ffloors || gr_frontsector->ffloors)) + if (gr_frontsector && gr_backsector && !Tag_Compare(&gr_frontsector->tags, &gr_backsector->tags) && (gr_backsector->ffloors || gr_frontsector->ffloors)) { ffloor_t * rover; fixed_t highcut = 0, lowcut = 0; @@ -2662,7 +2662,7 @@ static void HWR_AddLine(seg_t * line) #endif !line->sidedef->midtexture && ((!gr_frontsector->ffloors && !gr_backsector->ffloors) - || Tags_Compare(&gr_frontsector->tags, &gr_backsector->tags))) + || Tag_Compare(&gr_frontsector->tags, &gr_backsector->tags))) return; // line is empty, don't even bother // treat like wide open window instead HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D @@ -2704,7 +2704,7 @@ static void HWR_AddLine(seg_t * line) #endif !line->sidedef->midtexture && ((!gr_frontsector->ffloors && !gr_backsector->ffloors) - || Tags_Compare(&gr_frontsector->tags, &gr_backsector->tags))) + || Tag_Compare(&gr_frontsector->tags, &gr_backsector->tags))) return; // line is empty, don't even bother goto clippass; // treat like wide open window instead diff --git a/src/r_bsp.c b/src/r_bsp.c index e581e6687..e360e4376 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -377,7 +377,7 @@ boolean R_IsEmptyLine(seg_t *line, sector_t *front, sector_t *back) // Consider colormaps && back->extra_colormap == front->extra_colormap && ((!front->ffloors && !back->ffloors) - || Tags_Compare(&front->tags, &back->tags))); + || Tag_Compare(&front->tags, &back->tags))); } // @@ -489,7 +489,7 @@ static void R_AddLine(seg_t *line) #endif !line->sidedef->midtexture && ((!frontsector->ffloors && !backsector->ffloors) - || Tags_Compare(&frontsector->tags, &backsector->tags))) + || Tag_Compare(&frontsector->tags, &backsector->tags))) return; // line is empty, don't even bother goto clippass; // treat like wide open window instead diff --git a/src/r_segs.c b/src/r_segs.c index 1d6a56467..4fc74ce9d 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -2015,7 +2015,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) || backsector->floorlightsec != frontsector->floorlightsec //SoM: 4/3/2000: Check for colormaps || frontsector->extra_colormap != backsector->extra_colormap - || (frontsector->ffloors != backsector->ffloors && !Tags_Compare(&frontsector->tags, &backsector->tags)) + || (frontsector->ffloors != backsector->ffloors && !Tag_Compare(&frontsector->tags, &backsector->tags))) { markfloor = true; } @@ -2046,7 +2046,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) || backsector->ceilinglightsec != frontsector->ceilinglightsec //SoM: 4/3/2000: Check for colormaps || frontsector->extra_colormap != backsector->extra_colormap - || (frontsector->ffloors != backsector->ffloors && !Tags_Compare(&frontsector->tags, &backsector->tags)) + || (frontsector->ffloors != backsector->ffloors && !Tag_Compare(&frontsector->tags, &backsector->tags))) { markceiling = true; } @@ -2136,7 +2136,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) rw_bottomtexturemid += sidedef->rowoffset; // allocate space for masked texture tables - if (frontsector && backsector && !Tags_Compare(&frontsector->tags, &backsector->tags) && (backsector->ffloors || frontsector->ffloors)) + if (frontsector && backsector && !Tag_Compare(&frontsector->tags, &backsector->tags) && (backsector->ffloors || frontsector->ffloors)) { ffloor_t *rover; ffloor_t *r2; From 07b4d0ee3d028b2298c6c9a1aac1218736de864f Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sun, 12 Apr 2020 15:16:04 +0200 Subject: [PATCH 07/75] Add lookup tag tables construction. --- src/p_spec.c | 35 +++++++++++++++++++++++++++++------ src/taglist.c | 36 ++++++++++++++++++++++++++++++++++++ src/taglist.h | 15 +++++++++++++++ 3 files changed, 80 insertions(+), 6 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 529c50e4d..53e7f5916 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1578,6 +1578,7 @@ void P_RunNightsCapsuleTouchExecutors(mobj_t *actor, boolean entering, boolean e static inline void P_InitTagLists(void) { register size_t i; + size_t j; for (i = numsectors - 1; i != (size_t)-1; i--) { @@ -1592,6 +1593,28 @@ static inline void P_InitTagLists(void) lines[i].nexttag = lines[j].firsttag; lines[j].firsttag = (INT32)i; } + + for (i = 0; i < MAXTAGS; i++) + { + tags_sectors[i] = NULL; + tags_lines[i] = NULL; + tags_mapthings[i] = NULL; + } + for (i = 0; i < numsectors; i++) + { + for (j = 0; j < sectors[i].tags.count; j++) + Taglist_AddToSectors(sectors[i].tags.tags[j], i); + } + for (i = 0; i < numlines; i++) + { + for (j = 0; j < lines[i].tags.count; j++) + Taglist_AddToLines(lines[i].tags.tags[j], i); + } + for (i = 0; i < nummapthings; i++) + { + for (j = 0; j < mapthings[i].tags.count; j++) + Taglist_AddToMapthings(mapthings[i].tags.tags[j], i); + } } /** Finds minimum light from an adjacent sector. @@ -2025,7 +2048,7 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller INT32 triggercolor = (INT32)sides[triggerline->sidenum[0]].toptexture; UINT8 color = (actor->player ? actor->player->powers[pw_dye] : actor->color); boolean invert = (triggerline->flags & ML_NOCLIMB ? true : false); - + if (invert ^ (triggercolor != color)) return false; } @@ -4034,23 +4057,23 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) } } break; - + case 463: // Dye object { INT32 color = sides[line->sidenum[0]].toptexture; - + if (mo) { if (color < 0 || color >= MAXTRANSLATIONS) return; - + var1 = 0; var2 = color; A_Dye(mo); } } break; - + #ifdef POLYOBJECTS case 480: // Polyobj_DoorSlide case 481: // Polyobj_DoorSwing @@ -7271,7 +7294,7 @@ void P_SpawnSpecials(boolean fromnetsave) case 331: case 333: break; - + // Object dye executors case 334: case 336: diff --git a/src/taglist.c b/src/taglist.c index ceaebf9aa..087f069c4 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -20,3 +20,39 @@ boolean Tag_Compare (const taglist_t* list1, const taglist_t* list2) return true; } + +void Taglist_AddToSectors (const size_t tag, const size_t itemid) +{ + taggroup_t* tagelems; + if (!tags_sectors[tag]) + tags_sectors[tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); + + tagelems = tags_sectors[tag]; + tagelems->count++; + tagelems->elements = Z_Realloc(tagelems->elements, tagelems->count * sizeof(size_t), PU_LEVEL, NULL); + tagelems->elements[tagelems->count - 1] = itemid; +} + +void Taglist_AddToLines (const size_t tag, const size_t itemid) +{ + taggroup_t* tagelems; + if (!tags_lines[tag]) + tags_lines[tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); + + tagelems = tags_lines[tag]; + tagelems->count++; + tagelems->elements = Z_Realloc(tagelems->elements, tagelems->count * sizeof(size_t), PU_LEVEL, NULL); + tagelems->elements[tagelems->count - 1] = itemid; +} + +void Taglist_AddToMapthings (const size_t tag, const size_t itemid) +{ + taggroup_t* tagelems; + if (!tags_mapthings[tag]) + tags_mapthings[tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); + + tagelems = tags_mapthings[tag]; + tagelems->count++; + tagelems->elements = Z_Realloc(tagelems->elements, tagelems->count * sizeof(size_t), PU_LEVEL, NULL); + tagelems->elements[tagelems->count - 1] = itemid; +} diff --git a/src/taglist.h b/src/taglist.h index 62fac0d82..51cc82ce9 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -12,4 +12,19 @@ typedef struct void Tag_Add (taglist_t* list, const UINT16 tag); boolean Tag_Compare (const taglist_t* list1, const taglist_t* list2); + +typedef struct +{ + size_t *elements; + size_t count; +} taggroup_t; + +#define MAXTAGS 65536 +taggroup_t* tags_sectors[MAXTAGS]; +taggroup_t* tags_lines[MAXTAGS]; +taggroup_t* tags_mapthings[MAXTAGS]; + +void Taglist_AddToSectors (const size_t tag, const size_t itemid); +void Taglist_AddToLines (const size_t tag, const size_t itemid); +void Taglist_AddToMapthings (const size_t tag, const size_t itemid); #endif //__R_TAGLIST__ From f7f9b68bb955ed192b45c4e244140d76185fc173 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sun, 12 Apr 2020 16:28:47 +0200 Subject: [PATCH 08/75] Introduce tagged element iteration macros. --- src/taglist.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/taglist.h b/src/taglist.h index 51cc82ce9..e44696d3e 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -28,3 +28,24 @@ void Taglist_AddToSectors (const size_t tag, const size_t itemid); void Taglist_AddToLines (const size_t tag, const size_t itemid); void Taglist_AddToMapthings (const size_t tag, const size_t itemid); #endif //__R_TAGLIST__ + +#define Tag_IterateSectors(tag, sc)\ +size_t kk;\ +if(tags_sectors[tag])\ + for(kk = 0, sc = tags_sectors[tag]->elements[0];\ + kk < tags_sectors[tag]->count;\ + sc = tags_sectors[tag]->elements[++kk]) + +#define Tag_IterateLines(tag, li)\ +size_t kk;\ +if(tags_lines[tag])\ + for(kk = 0, li = tags_lines[tag]->elements[0];\ + kk < tags_lines[tag]->count;\ + li = tags_lines[tag]->elements[++kk]) + +#define Tag_IterateMapthings(tag, mt)\ +size_t kk;\ +if(tags_mapthings[tag])\ + for(kk = 0, mt = tags_mapthings[tag]->elements[0];\ + kk < tags_mapthings[tag]->count;\ + mt = tags_mapthings[tag]->elements[++kk]) From cb2571b12cbe9bbddf5807cf43c9d15315f78cd6 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sun, 12 Apr 2020 17:52:38 +0200 Subject: [PATCH 09/75] Rename the macros, reshape them slightly to avoid mixed declarations, and add a finalizer. --- src/taglist.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/taglist.h b/src/taglist.h index e44696d3e..3fe24fdcb 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -29,23 +29,25 @@ void Taglist_AddToLines (const size_t tag, const size_t itemid); void Taglist_AddToMapthings (const size_t tag, const size_t itemid); #endif //__R_TAGLIST__ -#define Tag_IterateSectors(tag, sc)\ -size_t kk;\ +#define TAG_ITER_SECTORS(tag, sc)\ if(tags_sectors[tag])\ +{ size_t kk;\ for(kk = 0, sc = tags_sectors[tag]->elements[0];\ kk < tags_sectors[tag]->count;\ sc = tags_sectors[tag]->elements[++kk]) -#define Tag_IterateLines(tag, li)\ -size_t kk;\ +#define TAG_ITER_LINES(tag, li)\ if(tags_lines[tag])\ +{ size_t kk;\ for(kk = 0, li = tags_lines[tag]->elements[0];\ kk < tags_lines[tag]->count;\ li = tags_lines[tag]->elements[++kk]) -#define Tag_IterateMapthings(tag, mt)\ -size_t kk;\ +#define TAG_ITER_THINGS(tag, mt)\ if(tags_mapthings[tag])\ +{ size_t kk;\ for(kk = 0, mt = tags_mapthings[tag]->elements[0];\ kk < tags_mapthings[tag]->count;\ mt = tags_mapthings[tag]->elements[++kk]) + +#define TAG_ITER_END } From 499c88450128d3329e0c884d7f3bbb3d15d9dd6f Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sun, 12 Apr 2020 18:52:47 +0200 Subject: [PATCH 10/75] Add multitag support to FOF spawners. --- src/p_spec.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 53e7f5916..e0bfbbe23 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -7484,9 +7484,10 @@ static void P_AddFakeFloorsByLine(size_t line, ffloortype_e ffloorflags, thinker { INT32 s; size_t sec = sides[*lines[line].sidenum].sector-sectors; - - for (s = -1; (s = P_FindSectorFromLineTag(lines+line, s)) >= 0 ;) - P_AddFakeFloor(§ors[s], §ors[sec], lines+line, ffloorflags, secthinkers); + line_t* li = lines + line; + TAG_ITER_SECTORS(li->tag, s) + P_AddFakeFloor(§ors[s], §ors[sec], li, ffloorflags, secthinkers); + TAG_ITER_END } /* From 0d1f8988692fcabb28063448f68cdc210df3c49e Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sun, 12 Apr 2020 19:05:17 +0200 Subject: [PATCH 11/75] Added disabled test code in P_FindSectorFromTag(). --- src/p_spec.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/p_spec.c b/src/p_spec.c index e0bfbbe23..4c6d1d407 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1020,6 +1020,25 @@ INT32 P_FindSectorFromTag(INT16 tag, INT32 start) return start; } +#if 0 + INT32 tpos = 0; + + if (tags_sectors[tag]) + { + // Resume previous position. + if (start != -1) + for (; tpos < tags_sectors[(UINT16)tag]->count;) + if (start == tags_sectors[(UINT16)tag]->elements[tpos++]) + break; + + if (tpos >= tags_sectors[(UINT16)tag]->count) + return -1; + + return tags_sectors[(UINT16)tag]->elements[tpos++]; + } + + return -1; +#else else { start = start >= 0 ? sectors[start].nexttag : @@ -1028,6 +1047,7 @@ INT32 P_FindSectorFromTag(INT16 tag, INT32 start) start = sectors[start].nexttag; return start; } +#endif } /** Searches the tag lists for the next line tagged to a line. From de07c04f5cd20853fdbf587818572395d44d2ae8 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Mon, 13 Apr 2020 13:09:58 +0200 Subject: [PATCH 12/75] Make the macros and their usage relatively cleaner. --- src/p_spec.c | 2 +- src/taglist.h | 29 +++++++++-------------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 4c6d1d407..ce89a6887 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -7502,12 +7502,12 @@ void P_SpawnSpecials(boolean fromnetsave) */ static void P_AddFakeFloorsByLine(size_t line, ffloortype_e ffloorflags, thinkerlist_t *secthinkers) { + TAG_ITER_C INT32 s; size_t sec = sides[*lines[line].sidenum].sector-sectors; line_t* li = lines + line; TAG_ITER_SECTORS(li->tag, s) P_AddFakeFloor(§ors[s], §ors[sec], li, ffloorflags, secthinkers); - TAG_ITER_END } /* diff --git a/src/taglist.h b/src/taglist.h index 3fe24fdcb..7572b8042 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -29,25 +29,14 @@ void Taglist_AddToLines (const size_t tag, const size_t itemid); void Taglist_AddToMapthings (const size_t tag, const size_t itemid); #endif //__R_TAGLIST__ -#define TAG_ITER_SECTORS(tag, sc)\ -if(tags_sectors[tag])\ -{ size_t kk;\ - for(kk = 0, sc = tags_sectors[tag]->elements[0];\ - kk < tags_sectors[tag]->count;\ - sc = tags_sectors[tag]->elements[++kk]) +#define TAG_ITER_C size_t kkkk; -#define TAG_ITER_LINES(tag, li)\ -if(tags_lines[tag])\ -{ size_t kk;\ - for(kk = 0, li = tags_lines[tag]->elements[0];\ - kk < tags_lines[tag]->count;\ - li = tags_lines[tag]->elements[++kk]) +#define TAG_ITER(group, tag, id)\ +if (group[tag])\ + for(id = group[tag]->elements[kkkk = 0] = 0;\ + kkkk < group[tag]->count;\ + id = group[tag]->elements[++kkkk]) -#define TAG_ITER_THINGS(tag, mt)\ -if(tags_mapthings[tag])\ -{ size_t kk;\ - for(kk = 0, mt = tags_mapthings[tag]->elements[0];\ - kk < tags_mapthings[tag]->count;\ - mt = tags_mapthings[tag]->elements[++kk]) - -#define TAG_ITER_END } +#define TAG_ITER_SECTORS(tag, id) TAG_ITER(tags_sectors, tag, id) +#define TAG_ITER_LINES(tag, id) TAG_ITER(tags_lines, tag, id) +#define TAG_ITER_THINGS(tag, id) TAG_ITER(tags_mapthings, tag, id) From 909268d175ef420e50e0b799a24175a4e72e36a4 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Mon, 13 Apr 2020 13:10:38 +0200 Subject: [PATCH 13/75] Replace P_FindLineFromLineTag() instances with macros and remove its code. --- src/p_spec.c | 69 ++++++---------------------------------------------- 1 file changed, 8 insertions(+), 61 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index ce89a6887..c5186b531 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1050,65 +1050,6 @@ INT32 P_FindSectorFromTag(INT16 tag, INT32 start) #endif } -/** Searches the tag lists for the next line tagged to a line. - * - * \param line Tagged line used as a reference. - * \param start -1 to start anew, or the result of a previous call to keep - * searching. - * \return Number of the next tagged line found. - * \sa P_FindSectorFromLineTag - */ -static INT32 P_FindLineFromLineTag(const line_t *line, INT32 start) -{ - if (line->tag == -1) - { - start++; - - if (start >= (INT32)numlines) - return -1; - - return start; - } - else - { - start = start >= 0 ? lines[start].nexttag : - lines[(unsigned)line->tag % numlines].firsttag; - while (start >= 0 && lines[start].tag != line->tag) - start = lines[start].nexttag; - return start; - } -} -#if 0 -/** Searches the tag lists for the next line with a given tag and special. - * - * \param tag Tag number. - * \param start -1 to start anew, or the result of a previous call to keep - * searching. - * \return Number of next suitable line found. - * \sa P_FindLineFromLineTag - * \author Graue - */ -static INT32 P_FindLineFromTag(INT32 tag, INT32 start) -{ - if (tag == -1) - { - start++; - - if (start >= numlines) - return -1; - - return start; - } - else - { - start = start >= 0 ? lines[start].nexttag : - lines[(unsigned)tag % numlines].firsttag; - while (start >= 0 && lines[start].tag != tag) - start = lines[start].nexttag; - return start; - } -} -#endif // // P_FindSpecialLineFromTag // @@ -6771,13 +6712,16 @@ void P_SpawnSpecials(boolean fromnetsave) if (sectors[s].lines[j]->special >= 100 && sectors[s].lines[j]->special < 300) Add_MasterDisappearer(abs(lines[i].dx>>FRACBITS), abs(lines[i].dy>>FRACBITS), abs(sides[lines[i].sidenum[0]].sector->floorheight>>FRACBITS), (INT32)(sectors[s].lines[j]-lines), (INT32)i); } else // Find FOFs by effect sector tag - for (s = -1; (s = P_FindLineFromLineTag(lines + i, s)) >= 0 ;) + { + TAG_ITER_C + TAG_ITER_LINES((lines + i)->tag, s) { if ((size_t)s == i) continue; if (sides[lines[s].sidenum[0]].sector->tag == sides[lines[i].sidenum[0]].sector->tag) Add_MasterDisappearer(abs(lines[i].dx>>FRACBITS), abs(lines[i].dy>>FRACBITS), abs(sides[lines[i].sidenum[0]].sector->floorheight>>FRACBITS), s, (INT32)i); } + } break; case 65: // Bridge Thinker @@ -7899,10 +7843,13 @@ static void P_SpawnScrollers(void) // scroll wall according to linedef // (same direction and speed as scrolling floors) case 502: - for (s = -1; (s = P_FindLineFromLineTag(l, s)) >= 0 ;) + { + TAG_ITER_C + TAG_ITER_LINES(l->tag, s) if (s != (INT32)i) Add_Scroller(sc_side, dx, dy, control, lines[s].sidenum[0], accel, 0); break; + } case 505: s = lines[i].sidenum[0]; From dbf0f14dc4373ec7192b60a13ce99359ad0c288a Mon Sep 17 00:00:00 2001 From: Nev3r Date: Mon, 13 Apr 2020 13:27:45 +0200 Subject: [PATCH 14/75] Replace P_FindSectorFromLineTag() in p_floor.c --- src/p_floor.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/p_floor.c b/src/p_floor.c index b8b40df3c..78616bdfe 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -2028,8 +2028,9 @@ void T_NoEnemiesSector(levelspecthink_t *nobaddies) msecnode_t *node; mobj_t *thing; boolean FOFsector = false; + TAG_ITER_C - while ((secnum = P_FindSectorFromLineTag(nobaddies->sourceline, secnum)) >= 0) + TAG_ITER_SECTORS(nobaddies->sourceline->tag, secnum) { sec = §ors[secnum]; @@ -2039,13 +2040,14 @@ void T_NoEnemiesSector(levelspecthink_t *nobaddies) for (i = 0; i < sec->linecount; i++) { INT32 targetsecnum = -1; + TAG_ITER_C if (sec->lines[i]->special < 100 || sec->lines[i]->special >= 300) continue; FOFsector = true; - while ((targetsecnum = P_FindSectorFromLineTag(sec->lines[i], targetsecnum)) >= 0) + TAG_ITER_SECTORS(sec->lines[i]->tag, targetsecnum) { targetsec = §ors[targetsecnum]; @@ -2171,6 +2173,7 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) fixed_t bottomheight, topheight; msecnode_t *node; ffloor_t *rover; + TAG_ITER_C for (i = 0; i < MAXPLAYERS; i++) { @@ -2191,7 +2194,7 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) playersOnArea[i] = false; } - while ((secnum = P_FindSectorFromLineTag(eachtime->sourceline, secnum)) >= 0) + TAG_ITER_SECTORS(eachtime->sourceline->tag, secnum) { sec = §ors[secnum]; @@ -2208,13 +2211,14 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) for (i = 0; i < sec->linecount; i++) { INT32 targetsecnum = -1; + TAG_ITER_C if (sec->lines[i]->special < 100 || sec->lines[i]->special >= 300) continue; FOFsector = true; - while ((targetsecnum = P_FindSectorFromLineTag(sec->lines[i], targetsecnum)) >= 0) + TAG_ITER_SECTORS(sec->lines[i]->tag, targetsecnum) { targetsec = §ors[targetsecnum]; @@ -2740,8 +2744,9 @@ INT32 EV_DoFloor(line_t *line, floor_e floortype) INT32 secnum = -1; sector_t *sec; floormove_t *dofloor; + TAG_ITER_C - while ((secnum = P_FindSectorFromLineTag(line, secnum)) >= 0) + TAG_ITER_SECTORS(line->tag, secnum) { sec = §ors[secnum]; @@ -2959,9 +2964,10 @@ INT32 EV_DoElevator(line_t *line, elevator_e elevtype, boolean customspeed) INT32 rtn = 0; sector_t *sec; elevator_t *elevator; + TAG_ITER_C // act on all sectors with the same tag as the triggering linedef - while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0) + TAG_ITER_SECTORS(line->tag, secnum) { sec = §ors[secnum]; From e820b9e369156353d5c4f7f9a3c947cb193bc3f3 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Mon, 13 Apr 2020 19:45:41 +0200 Subject: [PATCH 15/75] Fixed a typo worthy of divine punishment. --- src/taglist.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/taglist.h b/src/taglist.h index 7572b8042..2a2dbfcb3 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -33,7 +33,7 @@ void Taglist_AddToMapthings (const size_t tag, const size_t itemid); #define TAG_ITER(group, tag, id)\ if (group[tag])\ - for(id = group[tag]->elements[kkkk = 0] = 0;\ + for(id = group[tag]->elements[kkkk = 0];\ kkkk < group[tag]->count;\ id = group[tag]->elements[++kkkk]) From 8495b5989046832e4458735ed9876d11073c350a Mon Sep 17 00:00:00 2001 From: Nev3r Date: Tue, 14 Apr 2020 18:53:05 +0200 Subject: [PATCH 16/75] Added hilarious -1 tag support for the iteration macros. --- src/taglist.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/taglist.h b/src/taglist.h index 2a2dbfcb3..5dab7315f 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -31,12 +31,12 @@ void Taglist_AddToMapthings (const size_t tag, const size_t itemid); #define TAG_ITER_C size_t kkkk; -#define TAG_ITER(group, tag, id)\ -if (group[tag])\ - for(id = group[tag]->elements[kkkk = 0];\ - kkkk < group[tag]->count;\ - id = group[tag]->elements[++kkkk]) +#define TAG_ITER(group, grouptotal, tag, id)\ +if (group[tag] || tag == -1) for(\ + tag != -1 ? (id = group[tag]->elements[kkkk = 0]) : (id = 0);\ + tag != -1 ? (kkkk < group[tag]->count) : (id < grouptotal);\ + tag != -1 ? (id = group[tag]->elements[++kkkk]) : (id++)) -#define TAG_ITER_SECTORS(tag, id) TAG_ITER(tags_sectors, tag, id) -#define TAG_ITER_LINES(tag, id) TAG_ITER(tags_lines, tag, id) -#define TAG_ITER_THINGS(tag, id) TAG_ITER(tags_mapthings, tag, id) +#define TAG_ITER_SECTORS(tag, id) TAG_ITER(tags_sectors, numsectors, tag, id) +#define TAG_ITER_LINES(tag, id) TAG_ITER(tags_lines, numlines, tag, id) +#define TAG_ITER_THINGS(tag, id) TAG_ITER(tags_mapthings, nummapthings, tag, id) From 5df60f8e156d72930c4d4ff7403298c847023164 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Tue, 14 Apr 2020 20:59:04 +0200 Subject: [PATCH 17/75] Make use of functions for the tag lists iterations instead of bloated macros. --- src/taglist.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/taglist.h | 22 ++++++++++----------- 2 files changed, 66 insertions(+), 11 deletions(-) diff --git a/src/taglist.c b/src/taglist.c index 087f069c4..2e91cd770 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -1,5 +1,6 @@ #include "taglist.h" #include "z_zone.h" +#include "r_data.h" void Tag_Add (taglist_t* list, const UINT16 tag) { @@ -56,3 +57,57 @@ void Taglist_AddToMapthings (const size_t tag, const size_t itemid) tagelems->elements = Z_Realloc(tagelems->elements, tagelems->count * sizeof(size_t), PU_LEVEL, NULL); tagelems->elements[tagelems->count - 1] = itemid; } + +INT32 Tag_Iterate_Sectors (const INT16 tag, const size_t p) +{ + if (tag == -1) + { + if (p < numsectors) + return p; + return -1; + } + + if (tags_sectors[tag]) + { + if (p < tags_sectors[tag]->count) + return tags_sectors[tag]->elements[p]; + return -1; + } + return -1; +} + +INT32 Tag_Iterate_Lines (const INT16 tag, const size_t p) +{ + if (tag == -1) + { + if (p < numlines) + return p; + return -1; + } + + if (tags_lines[tag]) + { + if (p < tags_lines[tag]->count) + return tags_lines[tag]->elements[p]; + return -1; + } + return -1; +} + +INT32 Tag_Iterate_Things (const INT16 tag, const size_t p) +{ + if (tag == -1) + { + if (p < nummapthings) + return p; + return -1; + } + + if (tags_mapthings[tag]) + { + if (p < tags_mapthings[tag]->count) + return tags_mapthings[tag]->elements[p]; + return -1; + } + return -1; +} diff --git a/src/taglist.h b/src/taglist.h index 5dab7315f..ca3a7d834 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -1,8 +1,8 @@ -#include "doomtype.h" - #ifndef __R_TAGLIST__ #define __R_TAGLIST__ +#include "doomtype.h" + /// Multitag list. typedef struct { @@ -27,16 +27,16 @@ taggroup_t* tags_mapthings[MAXTAGS]; void Taglist_AddToSectors (const size_t tag, const size_t itemid); void Taglist_AddToLines (const size_t tag, const size_t itemid); void Taglist_AddToMapthings (const size_t tag, const size_t itemid); -#endif //__R_TAGLIST__ + +INT32 Tag_Iterate_Sectors (const INT16 tag, const size_t p); +INT32 Tag_Iterate_Lines (const INT16 tag, const size_t p); +INT32 Tag_Iterate_Things (const INT16 tag, const size_t p); #define TAG_ITER_C size_t kkkk; +#define TAG_ITER(fn, tag, id) for(kkkk = 0; (id = fn(tag, kkkk)) >= 0; kkkk++) -#define TAG_ITER(group, grouptotal, tag, id)\ -if (group[tag] || tag == -1) for(\ - tag != -1 ? (id = group[tag]->elements[kkkk = 0]) : (id = 0);\ - tag != -1 ? (kkkk < group[tag]->count) : (id < grouptotal);\ - tag != -1 ? (id = group[tag]->elements[++kkkk]) : (id++)) +#define TAG_ITER_SECTORS(tag, id) TAG_ITER(Tag_Iterate_Sectors, tag, id) +#define TAG_ITER_LINES(tag, id) TAG_ITER(Tag_Iterate_Lines, tag, id) +#define TAG_ITER_THINGS(tag, id) TAG_ITER(Tag_Iterate_Things, tag, id) -#define TAG_ITER_SECTORS(tag, id) TAG_ITER(tags_sectors, numsectors, tag, id) -#define TAG_ITER_LINES(tag, id) TAG_ITER(tags_lines, numlines, tag, id) -#define TAG_ITER_THINGS(tag, id) TAG_ITER(tags_mapthings, nummapthings, tag, id) +#endif //__R_TAGLIST__ From 24baf5bea0431835b675d96ec97f241ef5e3ee0a Mon Sep 17 00:00:00 2001 From: Nev3r Date: Tue, 14 Apr 2020 22:19:18 +0200 Subject: [PATCH 18/75] Replace P_FindSectorFromLineTag() with its corresponding macro for most cases. --- src/p_ceilng.c | 6 ++- src/p_spec.c | 107 ++++++++++++++++++++++++++----------------------- 2 files changed, 60 insertions(+), 53 deletions(-) diff --git a/src/p_ceilng.c b/src/p_ceilng.c index c65156b6f..a6e8e8cda 100644 --- a/src/p_ceilng.c +++ b/src/p_ceilng.c @@ -398,8 +398,9 @@ INT32 EV_DoCeiling(line_t *line, ceiling_e type) INT32 secnum = -1; sector_t *sec; ceiling_t *ceiling; + TAG_ITER_C - while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0) + TAG_ITER_SECTORS(line->tag, secnum) { sec = §ors[secnum]; @@ -618,8 +619,9 @@ INT32 EV_DoCrush(line_t *line, ceiling_e type) INT32 secnum = -1; sector_t *sec; ceiling_t *ceiling; + TAG_ITER_C - while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0) + TAG_ITER_SECTORS(line->tag, secnum) { sec = §ors[secnum]; diff --git a/src/p_spec.c b/src/p_spec.c index c5186b531..1f9b6099b 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2442,6 +2442,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { INT32 secnum = -1; mobj_t *bot = NULL; + TAG_ITER_C I_Assert(!mo || !P_MobjWasRemoved(mo)); // If mo is there, mo must be valid! @@ -2469,7 +2470,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) newceilinglightsec = line->frontsector->ceilinglightsec; // act on all sectors with the same tag as the triggering linedef - while ((secnum = P_FindSectorFromLineTag(line, secnum)) >= 0) + TAG_ITER_SECTORS(line->tag, secnum) { if (sectors[secnum].lightingdata) { @@ -2524,7 +2525,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) case 409: // Change tagged sectors' tag // (formerly "Change calling sectors' tag", but behavior was changed) { - while ((secnum = P_FindSectorFromLineTag(line, secnum)) >= 0) + TAG_ITER_SECTORS(line->tag, secnum) P_ChangeSectorTag(secnum,(INT16)(sides[line->sidenum[0]].textureoffset>>FRACBITS)); break; } @@ -2534,7 +2535,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 411: // Stop floor/ceiling movement in tagged sector(s) - while ((secnum = P_FindSectorFromLineTag(line, secnum)) >= 0) + TAG_ITER_SECTORS(line->tag, secnum) { if (sectors[secnum].floordata) { @@ -2604,7 +2605,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) } else { - if ((secnum = P_FindSectorFromLineTag(line, -1)) < 0) + if ((secnum = Tag_Iterate_Sectors(line->tag, 0)) < 0) return; dest = P_GetObjectTypeInSectorNum(MT_TELEPORTMAN, secnum); @@ -2719,7 +2720,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) // Additionally play the sound from tagged sectors' soundorgs sector_t *sec; - while ((secnum = P_FindSectorFromLineTag(line, secnum)) >= 0) + TAG_ITER_SECTORS(line->tag, secnum) { sec = §ors[secnum]; S_StartSound(&sec->soundorg, sfxnum); @@ -2834,7 +2835,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 416: // Spawn adjustable fire flicker - while ((secnum = P_FindSectorFromLineTag(line, secnum)) >= 0) + TAG_ITER_SECTORS(line->tag, secnum) { if (line->flags & ML_NOCLIMB && line->backsector) { @@ -2868,7 +2869,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 417: // Spawn adjustable glowing light - while ((secnum = P_FindSectorFromLineTag(line, secnum)) >= 0) + TAG_ITER_SECTORS(line->tag, secnum) { if (line->flags & ML_NOCLIMB && line->backsector) { @@ -2902,7 +2903,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 418: // Spawn adjustable strobe flash (unsynchronized) - while ((secnum = P_FindSectorFromLineTag(line, secnum)) >= 0) + TAG_ITER_SECTORS(line->tag, secnum) { if (line->flags & ML_NOCLIMB && line->backsector) { @@ -2936,7 +2937,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 419: // Spawn adjustable strobe flash (synchronized) - while ((secnum = P_FindSectorFromLineTag(line, secnum)) >= 0) + TAG_ITER_SECTORS(line->tag, secnum) { if (line->flags & ML_NOCLIMB && line->backsector) { @@ -2984,7 +2985,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 421: // Stop lighting effect in tagged sectors - while ((secnum = P_FindSectorFromLineTag(line, secnum)) >= 0) + TAG_ITER_SECTORS(line->tag, secnum) if (sectors[secnum].lightingdata) { P_RemoveThinker(&((elevator_t *)sectors[secnum].lightingdata)->thinker); @@ -2999,7 +3000,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if ((!mo || !mo->player) && !titlemapinaction) // only players have views, and title screens return; - if ((secnum = P_FindSectorFromLineTag(line, -1)) < 0) + if ((secnum = Tag_Iterate_Sectors(line->tag, 0)) < 0) return; altview = P_GetObjectTypeInSectorNum(MT_ALTVIEWMAN, secnum); @@ -3318,7 +3319,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (line->sidenum[1] != 0xffff) state = (statenum_t)sides[line->sidenum[1]].toptexture; - while ((secnum = P_FindSectorFromLineTag(line, secnum)) >= 0) + TAG_ITER_SECTORS(line->tag, secnum) { boolean tryagain; sec = sectors + secnum; @@ -3473,7 +3474,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) // Except it is activated by linedef executor, not level load // This could even override existing colormaps I believe // -- Monster Iestyn 14/06/18 - for (secnum = -1; (secnum = P_FindSectorFromLineTag(line, secnum)) >= 0 ;) + TAG_ITER_SECTORS(line->tag, secnum) { P_ResetColormapFader(§ors[secnum]); @@ -3801,7 +3802,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) } case 455: // Fade colormap - for (secnum = -1; (secnum = P_FindSectorFromLineTag(line, secnum)) >= 0 ;) + TAG_ITER_SECTORS(line->tag, secnum) { extracolormap_t *source_exc, *dest_exc, *exc; INT32 speed = (INT32)((line->flags & ML_DONTPEGBOTTOM) || !sides[line->sidenum[0]].rowoffset) && line->sidenum[1] != 0xFFFF ? @@ -3890,7 +3891,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 456: // Stop fade colormap - for (secnum = -1; (secnum = P_FindSectorFromLineTag(line, secnum)) >= 0 ;) + TAG_ITER_SECTORS(line->tag, secnum) P_ResetColormapFader(§ors[secnum]); break; @@ -3904,7 +3905,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) boolean persist = (line->flags & ML_EFFECT2); mobj_t *anchormo; - if ((secnum = P_FindSectorFromLineTag(line, -1)) < 0) + if ((secnum = Tag_Iterate_Sectors(line->tag, 0)) < 0) return; anchormo = P_GetObjectTypeInSectorNum(MT_ANGLEMAN, secnum); @@ -6547,10 +6548,11 @@ void P_SpawnSpecials(boolean fromnetsave) INT32 s; size_t sec; ffloortype_e ffloorflags; + TAG_ITER_C case 1: // Definable gravity per sector sec = sides[*lines[i].sidenum].sector - sectors; - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) { sectors[s].gravity = §ors[sec].floorheight; // This allows it to change in realtime! @@ -6574,7 +6576,7 @@ void P_SpawnSpecials(boolean fromnetsave) case 5: // Change camera info sec = sides[*lines[i].sidenum].sector - sectors; - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) P_AddCameraScanner(§ors[sec], §ors[s], R_PointToAngle2(lines[i].v2->x, lines[i].v2->y, lines[i].v1->x, lines[i].v1->y)); break; @@ -6601,7 +6603,7 @@ void P_SpawnSpecials(boolean fromnetsave) P_ApplyFlatAlignment(lines + i, lines[i].frontsector, flatangle, xoffs, yoffs); else { - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0;) + TAG_ITER_SECTORS(lines[i].tag, s) P_ApplyFlatAlignment(lines + i, sectors + s, flatangle, xoffs, yoffs); } } @@ -6612,7 +6614,7 @@ void P_SpawnSpecials(boolean fromnetsave) break; case 8: // Sector Parameters - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) { if (lines[i].flags & ML_NOCLIMB) { @@ -6640,7 +6642,7 @@ void P_SpawnSpecials(boolean fromnetsave) case 10: // Vertical culling plane for sprites and FOFs sec = sides[*lines[i].sidenum].sector - sectors; - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) sectors[s].cullheight = &lines[i]; // This allows it to change in realtime! break; @@ -6701,19 +6703,18 @@ void P_SpawnSpecials(boolean fromnetsave) case 63: // support for drawn heights coming from different sector sec = sides[*lines[i].sidenum].sector-sectors; - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) sectors[s].heightsec = (INT32)sec; break; case 64: // Appearing/Disappearing FOF option if (lines[i].flags & ML_BLOCKMONSTERS) { // Find FOFs by control sector tag - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) for (j = 0; (unsigned)j < sectors[s].linecount; j++) if (sectors[s].lines[j]->special >= 100 && sectors[s].lines[j]->special < 300) Add_MasterDisappearer(abs(lines[i].dx>>FRACBITS), abs(lines[i].dy>>FRACBITS), abs(sides[lines[i].sidenum[0]].sector->floorheight>>FRACBITS), (INT32)(sectors[s].lines[j]-lines), (INT32)i); } else // Find FOFs by effect sector tag { - TAG_ITER_C TAG_ITER_LINES((lines + i)->tag, s) { if ((size_t)s == i) @@ -6732,15 +6733,15 @@ void P_SpawnSpecials(boolean fromnetsave) break; case 66: // Displace floor by front sector - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) P_AddPlaneDisplaceThinker(pd_floor, P_AproxDistance(lines[i].dx, lines[i].dy)>>8, sides[lines[i].sidenum[0]].sector-sectors, s, !!(lines[i].flags & ML_NOCLIMB)); break; case 67: // Displace ceiling by front sector - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) P_AddPlaneDisplaceThinker(pd_ceiling, P_AproxDistance(lines[i].dx, lines[i].dy)>>8, sides[lines[i].sidenum[0]].sector-sectors, s, !!(lines[i].flags & ML_NOCLIMB)); break; case 68: // Displace both floor AND ceiling by front sector - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) P_AddPlaneDisplaceThinker(pd_both, P_AproxDistance(lines[i].dx, lines[i].dy)>>8, sides[lines[i].sidenum[0]].sector-sectors, s, !!(lines[i].flags & ML_NOCLIMB)); break; @@ -7115,7 +7116,7 @@ void P_SpawnSpecials(boolean fromnetsave) case 251: // A THWOMP! sec = sides[*lines[i].sidenum].sector - sectors; - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) { P_AddThwompThinker(§ors[sec], §ors[s], &lines[i]); P_AddFakeFloor(§ors[s], §ors[sec], lines + i, @@ -7163,7 +7164,7 @@ void P_SpawnSpecials(boolean fromnetsave) sec = sides[*lines[i].sidenum].sector - sectors; // No longer totally disrupts netgames - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) EV_AddLaserThinker(§ors[s], §ors[sec], lines + i, secthinkers); break; @@ -7355,46 +7356,46 @@ void P_SpawnSpecials(boolean fromnetsave) case 600: // floor lighting independently (e.g. lava) sec = sides[*lines[i].sidenum].sector-sectors; - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) sectors[s].floorlightsec = (INT32)sec; break; case 601: // ceiling lighting independently sec = sides[*lines[i].sidenum].sector-sectors; - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) sectors[s].ceilinglightsec = (INT32)sec; break; case 602: // Adjustable pulsating light sec = sides[*lines[i].sidenum].sector - sectors; - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) P_SpawnAdjustableGlowingLight(§ors[sec], §ors[s], P_AproxDistance(lines[i].dx, lines[i].dy)>>FRACBITS); break; case 603: // Adjustable flickering light sec = sides[*lines[i].sidenum].sector - sectors; - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) P_SpawnAdjustableFireFlicker(§ors[sec], §ors[s], P_AproxDistance(lines[i].dx, lines[i].dy)>>FRACBITS); break; case 604: // Adjustable Blinking Light (unsynchronized) sec = sides[*lines[i].sidenum].sector - sectors; - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) P_SpawnAdjustableStrobeFlash(§ors[sec], §ors[s], abs(lines[i].dx)>>FRACBITS, abs(lines[i].dy)>>FRACBITS, false); break; case 605: // Adjustable Blinking Light (synchronized) sec = sides[*lines[i].sidenum].sector - sectors; - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) P_SpawnAdjustableStrobeFlash(§ors[sec], §ors[s], abs(lines[i].dx)>>FRACBITS, abs(lines[i].dy)>>FRACBITS, true); break; case 606: // HACK! Copy colormaps. Just plain colormaps. - for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) + TAG_ITER_SECTORS(lines[i].tag, s) sectors[s].extra_colormap = sectors[s].spawn_extra_colormap = sides[lines[i].sidenum[0]].colormap_data; break; @@ -7560,6 +7561,7 @@ void T_Scroll(scroll_t *s) size_t i; INT32 sect; ffloor_t *rover; + TAG_ITER_C case sc_side: // scroll wall texture side = sides + s->affectee; @@ -7596,7 +7598,7 @@ void T_Scroll(scroll_t *s) if (!is3dblock) continue; - for (sect = -1; (sect = P_FindSectorFromTag(line->tag, sect)) >= 0 ;) + TAG_ITER_SECTORS(line->tag, sect) { sector_t *psec; psec = sectors + sect; @@ -7809,10 +7811,11 @@ static void P_SpawnScrollers(void) switch (special) { register INT32 s; + TAG_ITER_C case 513: // scroll effect ceiling case 533: // scroll and carry objects on ceiling - for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) + TAG_ITER_SECTORS(l->tag, s) Add_Scroller(sc_ceiling, -dx, dy, control, s, accel, l->flags & ML_NOCLIMB); if (special != 533) break; @@ -7821,13 +7824,13 @@ static void P_SpawnScrollers(void) case 523: // carry objects on ceiling dx = FixedMul(dx, CARRYFACTOR); dy = FixedMul(dy, CARRYFACTOR); - for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) + TAG_ITER_SECTORS(l->tag, s) Add_Scroller(sc_carry_ceiling, dx, dy, control, s, accel, l->flags & ML_NOCLIMB); break; case 510: // scroll effect floor case 530: // scroll and carry objects on floor - for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) + TAG_ITER_SECTORS(l->tag, s) Add_Scroller(sc_floor, -dx, dy, control, s, accel, l->flags & ML_NOCLIMB); if (special != 530) break; @@ -7836,7 +7839,7 @@ static void P_SpawnScrollers(void) case 520: // carry objects on floor dx = FixedMul(dx, CARRYFACTOR); dy = FixedMul(dy, CARRYFACTOR); - for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) + TAG_ITER_SECTORS(l->tag, s) Add_Scroller(sc_carry, dx, dy, control, s, accel, l->flags & ML_NOCLIMB); break; @@ -7844,7 +7847,6 @@ static void P_SpawnScrollers(void) // (same direction and speed as scrolling floors) case 502: { - TAG_ITER_C TAG_ITER_LINES(l->tag, s) if (s != (INT32)i) Add_Scroller(sc_side, dx, dy, control, lines[s].sidenum[0], accel, 0); @@ -7915,8 +7917,9 @@ void T_Disappear(disappear_t *d) { ffloor_t *rover; register INT32 s; + TAG_ITER_C - for (s = -1; (s = P_FindSectorFromLineTag(&lines[d->affectee], s)) >= 0 ;) + TAG_ITER_SECTORS(lines[d->affectee].tag, s) { for (rover = sectors[s].ffloors; rover; rover = rover->next) { @@ -8649,6 +8652,7 @@ static void P_SpawnFriction(void) fixed_t strength; // frontside texture offset controls magnitude fixed_t friction; // friction value to be applied during movement INT32 movefactor; // applied to each player move to simulate inertia + TAG_ITER_C for (i = 0; i < numlines; i++, l++) if (l->special == 540) @@ -8673,7 +8677,7 @@ static void P_SpawnFriction(void) else movefactor = FRACUNIT; - for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) + TAG_ITER_SECTORS(l->tag, s) Add_Friction(friction, movefactor, s, -1); } } @@ -9203,20 +9207,21 @@ static void P_SpawnPushers(void) line_t *l = lines; register INT32 s; mobj_t *thing; + TAG_ITER_C for (i = 0; i < numlines; i++, l++) switch (l->special) { case 541: // wind - for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) + TAG_ITER_SECTORS(l->tag, s) Add_Pusher(p_wind, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; case 544: // current - for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) + TAG_ITER_SECTORS(l->tag, s) Add_Pusher(p_current, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; case 547: // push/pull - for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) + TAG_ITER_SECTORS(l->tag, s) { thing = P_GetPushThing(s); if (thing) // No MT_P* means no effect @@ -9224,19 +9229,19 @@ static void P_SpawnPushers(void) } break; case 545: // current up - for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) + TAG_ITER_SECTORS(l->tag, s) Add_Pusher(p_upcurrent, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; case 546: // current down - for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) + TAG_ITER_SECTORS(l->tag, s) Add_Pusher(p_downcurrent, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; case 542: // wind up - for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) + TAG_ITER_SECTORS(l->tag, s) Add_Pusher(p_upwind, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; case 543: // wind down - for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) + TAG_ITER_SECTORS(l->tag, s) Add_Pusher(p_downwind, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; } From 25102ab4afc24f504d6b0e05416ec8233fce25db Mon Sep 17 00:00:00 2001 From: Nev3r Date: Tue, 14 Apr 2020 22:22:48 +0200 Subject: [PATCH 19/75] Remove P_FindSectorFromLineTag() --- src/p_spec.c | 14 -------------- src/p_spec.h | 1 - 2 files changed, 15 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 9d4b741c5..6e7e06823 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -988,26 +988,12 @@ static sector_t *P_FindModelCeilingSector(fixed_t ceildestheight, INT32 secnum) } #endif -/** Searches the tag lists for the next sector tagged to a line. - * - * \param line Tagged line used as a reference. - * \param start -1 to start at the beginning, or the result of a previous call - * to keep searching. - * \return Number of the next tagged sector found. - * \sa P_FindSectorFromTag, P_FindLineFromLineTag - */ -INT32 P_FindSectorFromLineTag(line_t *line, INT32 start) -{ - return P_FindSectorFromTag(line->tag, start); -} - /** Searches the tag lists for the next sector with a given tag. * * \param tag Tag number to look for. * \param start -1 to start anew, or the result of a previous call to keep * searching. * \return Number of the next tagged sector found. - * \sa P_FindSectorFromLineTag */ INT32 P_FindSectorFromTag(INT16 tag, INT32 start) { diff --git a/src/p_spec.h b/src/p_spec.h index d756f1942..590eb476b 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -55,7 +55,6 @@ fixed_t P_FindNextLowestFloor(sector_t *sec, fixed_t currentheight); fixed_t P_FindLowestCeilingSurrounding(sector_t *sec); fixed_t P_FindHighestCeilingSurrounding(sector_t *sec); -INT32 P_FindSectorFromLineTag(line_t *line, INT32 start); INT32 P_FindSectorFromTag(INT16 tag, INT32 start); INT32 P_FindSpecialLineFromTag(INT16 special, INT16 tag, INT32 start); From d51870333456bccb6bf6f137119015501efda19d Mon Sep 17 00:00:00 2001 From: Nev3r Date: Tue, 14 Apr 2020 23:33:56 +0200 Subject: [PATCH 20/75] Replaces P_FindSectorFromTag() occurrences with its corresponding macro and vanishes it from existence. --- src/p_floor.c | 30 ++++++++++++------------ src/p_lights.c | 4 +++- src/p_slopes.c | 4 ++-- src/p_spec.c | 63 ++++++-------------------------------------------- src/p_spec.h | 1 - 5 files changed, 27 insertions(+), 75 deletions(-) diff --git a/src/p_floor.c b/src/p_floor.c index fbcb1274b..5d57263d3 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -687,6 +687,7 @@ void T_BounceCheese(levelspecthink_t *bouncer) fixed_t floorheight; sector_t *actionsector; INT32 i; + TAG_ITER_C if (bouncer->sector->crumblestate == 4 || bouncer->sector->crumblestate == 1 || bouncer->sector->crumblestate == 2) // Oops! Crumbler says to remove yourself! @@ -701,7 +702,7 @@ void T_BounceCheese(levelspecthink_t *bouncer) } // You can use multiple target sectors, but at your own risk!!! - for (i = -1; (i = P_FindSectorFromTag(bouncer->sourceline->tag, i)) >= 0 ;) + TAG_ITER_SECTORS(bouncer->sourceline->tag, i) { actionsector = §ors[i]; actionsector->moved = true; @@ -844,6 +845,7 @@ void T_StartCrumble(elevator_t *elevator) ffloor_t *rover; sector_t *sector; INT32 i; + TAG_ITER_C // Once done, the no-return thinker just sits there, // constantly 'returning'... kind of an oxymoron, isn't it? @@ -873,7 +875,7 @@ void T_StartCrumble(elevator_t *elevator) } else if (++elevator->distance == 0) // Reposition back to original spot { - for (i = -1; (i = P_FindSectorFromTag(elevator->sourceline->tag, i)) >= 0 ;) + TAG_ITER_SECTORS(elevator->sourceline->tag, i) { sector = §ors[i]; @@ -904,7 +906,7 @@ void T_StartCrumble(elevator_t *elevator) // Flash to indicate that the platform is about to return. if (elevator->distance > -224 && (leveltime % ((abs(elevator->distance)/8) + 1) == 0)) { - for (i = -1; (i = P_FindSectorFromTag(elevator->sourceline->tag, i)) >= 0 ;) + TAG_ITER_SECTORS(elevator->sourceline->tag, i) { sector = §ors[i]; @@ -1000,7 +1002,7 @@ void T_StartCrumble(elevator_t *elevator) P_RemoveThinker(&elevator->thinker); } - for (i = -1; (i = P_FindSectorFromTag(elevator->sourceline->tag, i)) >= 0 ;) + TAG_ITER_SECTORS(elevator->sourceline->tag, i) { sector = §ors[i]; sector->moved = true; @@ -1016,6 +1018,7 @@ void T_StartCrumble(elevator_t *elevator) void T_MarioBlock(levelspecthink_t *block) { INT32 i; + TAG_ITER_C #define speed vars[1] #define direction vars[2] @@ -1057,8 +1060,7 @@ void T_MarioBlock(levelspecthink_t *block) block->sector->ceilspeed = 0; block->direction = 0; } - - for (i = -1; (i = P_FindSectorFromTag((INT16)block->vars[0], i)) >= 0 ;) + TAG_ITER_SECTORS((INT16)block->vars[0], i) P_RecalcPrecipInSector(§ors[i]); #undef speed @@ -1151,9 +1153,7 @@ void T_FloatSector(levelspecthink_t *floater) // Just find the first sector with the tag. // Doesn't work with multiple sectors that have different floor/ceiling heights. - secnum = P_FindSectorFromTag((INT16)floater->vars[0], -1); - - if (secnum > 0) + if ((secnum = Tag_Iterate_Sectors((INT16)floater->vars[0], 0)) >= 0) actionsector = §ors[secnum]; else actionsector = NULL; @@ -1288,9 +1288,7 @@ void T_ThwompSector(levelspecthink_t *thwomp) // Just find the first sector with the tag. // Doesn't work with multiple sectors that have different floor/ceiling heights. - secnum = P_FindSectorFromTag((INT16)thwomp->vars[0], -1); - - if (secnum > 0) + if ((secnum = Tag_Iterate_Sectors((INT16)thwomp->vars[0], 0)) >= 0) { actionsector = §ors[secnum]; @@ -1860,11 +1858,12 @@ void T_RaiseSector(levelspecthink_t *raise) boolean playeronme = false, active = false; fixed_t ceilingdestination, floordestination; result_e res = 0; + TAG_ITER_C if (raise->sector->crumblestate >= 3 || raise->sector->ceilingdata) return; - for (i = -1; (i = P_FindSectorFromTag(raise->sourceline->tag, i)) >= 0 ;) + TAG_ITER_SECTORS(raise->sourceline->tag, i) { sector = §ors[i]; @@ -2057,7 +2056,7 @@ void T_RaiseSector(levelspecthink_t *raise) raise->sector->ceilspeed = 42; raise->sector->floorspeed = raise->vars[3]*raise->vars[8]; - for (i = -1; (i = P_FindSectorFromTag(raise->sourceline->tag, i)) >= 0 ;) + TAG_ITER_SECTORS(raise->sourceline->tag, i) P_RecalcPrecipInSector(§ors[i]); } @@ -2726,6 +2725,7 @@ INT32 EV_StartCrumble(sector_t *sec, ffloor_t *rover, boolean floating, elevator_t *elevator; sector_t *foundsec; INT32 i; + TAG_ITER_C // If floor is already activated, skip it if (sec->floordata) @@ -2778,7 +2778,7 @@ INT32 EV_StartCrumble(sector_t *sec, ffloor_t *rover, boolean floating, elevator->sector->crumblestate = 2; - for (i = -1; (i = P_FindSectorFromTag(elevator->sourceline->tag, i)) >= 0 ;) + TAG_ITER_SECTORS(elevator->sourceline->tag, i) { foundsec = §ors[i]; diff --git a/src/p_lights.c b/src/p_lights.c index 371077a30..bb8ef6989 100644 --- a/src/p_lights.c +++ b/src/p_lights.c @@ -374,8 +374,10 @@ void P_FadeLightBySector(sector_t *sector, INT32 destvalue, INT32 speed, boolean void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed, boolean ticbased, boolean force) { INT32 i; + TAG_ITER_C + // search all sectors for ones with tag - for (i = -1; (i = P_FindSectorFromTag(tag, i)) >= 0 ;) + TAG_ITER_SECTORS(tag, i) { if (!force && ticbased // always let speed fader execute && sectors[i].lightingdata diff --git a/src/p_slopes.c b/src/p_slopes.c index c4ef28666..63a7aeb20 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -549,11 +549,11 @@ static boolean P_SetSlopeFromTag(sector_t *sec, INT32 tag, boolean ceiling) { INT32 i; pslope_t **secslope = ceiling ? &sec->c_slope : &sec->f_slope; + TAG_ITER_C if (!tag || *secslope) return false; - - for (i = -1; (i = P_FindSectorFromTag(tag, i)) >= 0;) + TAG_ITER_SECTORS(tag, i) { pslope_t *srcslope = ceiling ? sectors[i].c_slope : sectors[i].f_slope; if (srcslope) diff --git a/src/p_spec.c b/src/p_spec.c index 6e7e06823..8b5b5ac9b 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -988,54 +988,6 @@ static sector_t *P_FindModelCeilingSector(fixed_t ceildestheight, INT32 secnum) } #endif -/** Searches the tag lists for the next sector with a given tag. - * - * \param tag Tag number to look for. - * \param start -1 to start anew, or the result of a previous call to keep - * searching. - * \return Number of the next tagged sector found. - */ -INT32 P_FindSectorFromTag(INT16 tag, INT32 start) -{ - if (tag == -1) - { - start++; - - if (start >= (INT32)numsectors) - return -1; - - return start; - } -#if 0 - INT32 tpos = 0; - - if (tags_sectors[tag]) - { - // Resume previous position. - if (start != -1) - for (; tpos < tags_sectors[(UINT16)tag]->count;) - if (start == tags_sectors[(UINT16)tag]->elements[tpos++]) - break; - - if (tpos >= tags_sectors[(UINT16)tag]->count) - return -1; - - return tags_sectors[(UINT16)tag]->elements[tpos++]; - } - - return -1; -#else - else - { - start = start >= 0 ? sectors[start].nexttag : - sectors[(unsigned)tag % numsectors].firsttag; - while (start >= 0 && sectors[start].tag != tag) - start = sectors[start].nexttag; - return start; - } -#endif -} - // // P_FindSpecialLineFromTag // @@ -3181,7 +3133,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) ffloor_t *rover; // FOF that we are going to crumble boolean foundrover = false; // for debug, "Can't find a FOF" message - for (secnum = -1; (secnum = P_FindSectorFromTag(sectag, secnum)) >= 0 ;) + TAG_ITER_SECTORS(sectag, secnum) { sec = sectors + secnum; @@ -3365,7 +3317,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) boolean foundrover = false; // for debug, "Can't find a FOF" message ffloortype_e oldflags; // store FOF's old flags - for (secnum = -1; (secnum = P_FindSectorFromTag(sectag, secnum)) >= 0 ;) + TAG_ITER_SECTORS(sectag, secnum) { sec = sectors + secnum; @@ -3423,7 +3375,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (line->flags & ML_NOCLIMB) // don't respawn! respawn = false; - for (secnum = -1; (secnum = P_FindSectorFromTag(sectag, secnum)) >= 0 ;) + TAG_ITER_SECTORS(sectag, secnum) { sec = sectors + secnum; @@ -3608,7 +3560,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) ffloor_t *rover; // FOF that we are going to operate boolean foundrover = false; // for debug, "Can't find a FOF" message - for (secnum = -1; (secnum = P_FindSectorFromTag(sectag, secnum)) >= 0 ;) + TAG_ITER_SECTORS(sectag, secnum) { sec = sectors + secnum; @@ -3672,7 +3624,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) boolean foundrover = false; // for debug, "Can't find a FOF" message size_t j = 0; // sec->ffloors is saved as ffloor #0, ss->ffloors->next is #1, etc - for (secnum = -1; (secnum = P_FindSectorFromTag(sectag, secnum)) >= 0 ;) + TAG_ITER_SECTORS(sectag, secnum) { sec = sectors + secnum; @@ -3757,7 +3709,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) ffloor_t *rover; // FOF that we are going to operate boolean foundrover = false; // for debug, "Can't find a FOF" message - for (secnum = -1; (secnum = P_FindSectorFromTag(sectag, secnum)) >= 0 ;) + TAG_ITER_SECTORS(sectag, secnum) { sec = sectors + secnum; @@ -7617,8 +7569,7 @@ void T_Scroll(scroll_t *s) if (!is3dblock) continue; - - for (sect = -1; (sect = P_FindSectorFromTag(line->tag, sect)) >= 0 ;) + TAG_ITER_SECTORS(line->tag, sect) { sector_t *psec; psec = sectors + sect; diff --git a/src/p_spec.h b/src/p_spec.h index 590eb476b..271c04c08 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -55,7 +55,6 @@ fixed_t P_FindNextLowestFloor(sector_t *sec, fixed_t currentheight); fixed_t P_FindLowestCeilingSurrounding(sector_t *sec); fixed_t P_FindHighestCeilingSurrounding(sector_t *sec); -INT32 P_FindSectorFromTag(INT16 tag, INT32 start); INT32 P_FindSpecialLineFromTag(INT16 special, INT16 tag, INT32 start); INT32 P_FindMinSurroundingLight(sector_t *sector, INT32 max); From 439fde3434940b1abacf10af9b701e5b7d8ad77b Mon Sep 17 00:00:00 2001 From: Nev3r Date: Tue, 14 Apr 2020 23:59:22 +0200 Subject: [PATCH 21/75] Replace most P_FindSpecialLineFromTag() cases with Tag_FindLineSpecial(), which settle with the first found result. --- src/p_enemy.c | 8 ++++---- src/p_floor.c | 2 +- src/p_mobj.c | 9 ++++----- src/p_polyobj.c | 2 +- src/p_slopes.c | 2 +- src/p_spec.c | 10 +++++----- src/p_user.c | 8 ++++---- src/taglist.c | 16 ++++++++++++++++ src/taglist.h | 2 ++ 9 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/p_enemy.c b/src/p_enemy.c index 2341be6d3..8f96c1dee 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -6107,7 +6107,7 @@ void A_RockSpawn(mobj_t *actor) { mobj_t *mo; mobjtype_t type; - INT32 i = P_FindSpecialLineFromTag(12, (INT16)actor->threshold, -1); + INT32 i = Tag_FindLineSpecial(12, (INT16)actor->threshold); line_t *line; fixed_t dist; fixed_t randomoomph; @@ -8794,19 +8794,19 @@ void A_Dye(mobj_t *actor) #endif if (color >= MAXTRANSLATIONS) return; - + if (!color) target->colorized = false; else target->colorized = true; - + // What if it's a player? if (target->player) { target->player->powers[pw_dye] = color; return; } - + target->color = color; } diff --git a/src/p_floor.c b/src/p_floor.c index 5d57263d3..bcb546a5c 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -2549,7 +2549,7 @@ void EV_CrumbleChain(sector_t *sec, ffloor_t *rover) if (controlsec->tag != 0) { - INT32 tagline = P_FindSpecialLineFromTag(14, controlsec->tag, -1); + INT32 tagline = Tag_FindLineSpecial(14, controlsec->tag); if (tagline != -1) { if (sides[lines[tagline].sidenum[0]].toptexture) diff --git a/src/p_mobj.c b/src/p_mobj.c index aaea9d49b..c004d3257 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3552,7 +3552,7 @@ static boolean P_CameraCheckHeat(camera_t *thiscam) // see if we are in water sector = thiscam->subsector->sector; - if (P_FindSpecialLineFromTag(13, sector->tag, -1) != -1) + if (Tag_FindLineSpecial(13, sector->tag) != -1) return true; if (sector->ffloors) @@ -3573,7 +3573,7 @@ static boolean P_CameraCheckHeat(camera_t *thiscam) *rover->bottomheight)) continue; - if (P_FindSpecialLineFromTag(13, rover->master->frontsector->tag, -1) != -1) + if (Tag_FindLineSpecial(13, rover->master->frontsector->tag) != -1) return true; } } @@ -12035,8 +12035,7 @@ static boolean P_SetupMace(mapthing_t *mthing, mobj_t *mobj, boolean *doangle) const size_t mthingi = (size_t)(mthing - mapthings); // Find the corresponding linedef special, using angle as tag - // P_FindSpecialLineFromTag works here now =D - line = P_FindSpecialLineFromTag(9, mthing->angle, -1); + line = Tag_FindLineSpecial(9, mthing->angle); if (line == -1) { @@ -12346,7 +12345,7 @@ static boolean P_SetupParticleGen(mapthing_t *mthing, mobj_t *mobj) const size_t mthingi = (size_t)(mthing - mapthings); // Find the corresponding linedef special, using angle as tag - line = P_FindSpecialLineFromTag(15, mthing->angle, -1); + line = Tag_FindLineSpecial(15, mthing->angle); if (line == -1) { diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 7baa24994..cfe12db13 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -238,7 +238,7 @@ boolean P_BBoxInsidePolyobj(polyobj_t *po, fixed_t *bbox) // void Polyobj_GetInfo(INT16 poid, INT32 *poflags, INT32 *parentID, INT32 *potrans) { - INT32 i = P_FindSpecialLineFromTag(POLYINFO_SPECIALNUM, poid, -1); + INT32 i = Tag_FindLineSpecial(POLYINFO_SPECIALNUM, poid); if (i == -1) return; // no extra settings to apply, let's leave it diff --git a/src/p_slopes.c b/src/p_slopes.c index 63a7aeb20..9b147f046 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -139,7 +139,7 @@ void T_DynamicSlopeVert (dynplanethink_t* th) INT32 l; for (i = 0; i < 3; i++) { - l = P_FindSpecialLineFromTag(799, th->tags[i], -1); + l = Tag_FindLineSpecial(799, th->tags[i]); if (l != -1) { th->vex[i].z = lines[l].frontsector->floorheight; } diff --git a/src/p_spec.c b/src/p_spec.c index 8b5b5ac9b..1977e7a89 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -4535,7 +4535,7 @@ DoneSection2: if (player->powers[pw_flashing] != 0 && player->powers[pw_flashing] < TICRATE/2) break; - i = P_FindSpecialLineFromTag(4, sector->tag, -1); + i = Tag_FindLineSpecial(4, sector->tag); if (i != -1) { @@ -4647,7 +4647,7 @@ DoneSection2: // important: use sector->tag on next line instead of player->mo->subsector->tag // this part is different from in P_PlayerThink, this is what was causing // FOF custom exits not to work. - lineindex = P_FindSpecialLineFromTag(2, sector->tag, -1); + lineindex = Tag_FindLineSpecial(2, sector->tag); if (gametype == GT_COOP && lineindex != -1) // Custom exit! { @@ -4772,7 +4772,7 @@ DoneSection2: break; // Find line #3 tagged to this sector - lineindex = P_FindSpecialLineFromTag(3, sector->tag, -1); + lineindex = Tag_FindLineSpecial(3, sector->tag); if (lineindex == -1) { @@ -4854,7 +4854,7 @@ DoneSection2: break; // Find line #3 tagged to this sector - lineindex = P_FindSpecialLineFromTag(3, sector->tag, -1); + lineindex = Tag_FindLineSpecial(3, sector->tag); if (lineindex == -1) { @@ -5001,7 +5001,7 @@ DoneSection2: memset(&resulthigh, 0x00, sizeof(resulthigh)); // Find line #11 tagged to this sector - lineindex = P_FindSpecialLineFromTag(11, sector->tag, -1); + lineindex = Tag_FindLineSpecial(11, sector->tag); if (lineindex == -1) { diff --git a/src/p_user.c b/src/p_user.c index 994eb7007..131eedd9c 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -10654,7 +10654,7 @@ static void P_CalcPostImg(player_t *player) // see if we are in heat (no, not THAT kind of heat...) - if (P_FindSpecialLineFromTag(13, sector->tag, -1) != -1) + if (Tag_FindLineSpecial(13, sector->tag) != -1) *type = postimg_heat; else if (sector->ffloors) { @@ -10673,7 +10673,7 @@ static void P_CalcPostImg(player_t *player) if (pviewheight >= topheight || pviewheight <= bottomheight) continue; - if (P_FindSpecialLineFromTag(13, rover->master->frontsector->tag, -1) != -1) + if (Tag_FindLineSpecial(13, rover->master->frontsector->tag) != -1) *type = postimg_heat; } } @@ -10778,7 +10778,7 @@ static INT32 P_GetMinecartSpecialLine(sector_t *sec) return line; if (sec->tag != 0) - line = P_FindSpecialLineFromTag(16, sec->tag, -1); + line = Tag_FindLineSpecial(16, sec->tag); // Also try for lines facing the sector itself, with tag 0. { @@ -12213,7 +12213,7 @@ void P_PlayerThink(player_t *player) player->powers[pw_nocontrol]--; else player->powers[pw_nocontrol] = 0; - + //pw_super acts as a timer now if (player->powers[pw_super] && (player->mo->state < &states[S_PLAY_SUPER_TRANS1] diff --git a/src/taglist.c b/src/taglist.c index 2e91cd770..4b3ed1981 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -111,3 +111,19 @@ INT32 Tag_Iterate_Things (const INT16 tag, const size_t p) } return -1; } + +INT32 Tag_FindLineSpecial(const INT16 tag, const INT16 special) +{ + TAG_ITER_C + INT32 i; + + TAG_ITER_LINES(tag, i) + { + if (i == -1) + return -1; + + if (lines[i].special == special) + return i; + } + return -1; +} diff --git a/src/taglist.h b/src/taglist.h index ca3a7d834..9be0013f3 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -32,6 +32,8 @@ INT32 Tag_Iterate_Sectors (const INT16 tag, const size_t p); INT32 Tag_Iterate_Lines (const INT16 tag, const size_t p); INT32 Tag_Iterate_Things (const INT16 tag, const size_t p); +INT32 Tag_FindLineSpecial(const INT16 tag, const INT16 special); + #define TAG_ITER_C size_t kkkk; #define TAG_ITER(fn, tag, id) for(kkkk = 0; (id = fn(tag, kkkk)) >= 0; kkkk++) From 2d9b0e49067582fc8b73f867281503fa835a7083 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Wed, 15 Apr 2020 09:32:19 +0200 Subject: [PATCH 22/75] Fix the args in Tag_FindLineSpecial() being swapped. --- src/taglist.c | 2 +- src/taglist.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/taglist.c b/src/taglist.c index 4b3ed1981..61b8a147d 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -112,7 +112,7 @@ INT32 Tag_Iterate_Things (const INT16 tag, const size_t p) return -1; } -INT32 Tag_FindLineSpecial(const INT16 tag, const INT16 special) +INT32 Tag_FindLineSpecial(const INT16 special, const INT16 tag) { TAG_ITER_C INT32 i; diff --git a/src/taglist.h b/src/taglist.h index 9be0013f3..59ecd6106 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -32,7 +32,7 @@ INT32 Tag_Iterate_Sectors (const INT16 tag, const size_t p); INT32 Tag_Iterate_Lines (const INT16 tag, const size_t p); INT32 Tag_Iterate_Things (const INT16 tag, const size_t p); -INT32 Tag_FindLineSpecial(const INT16 tag, const INT16 special); +INT32 Tag_FindLineSpecial(const INT16 special, const INT16 tag); #define TAG_ITER_C size_t kkkk; #define TAG_ITER(fn, tag, id) for(kkkk = 0; (id = fn(tag, kkkk)) >= 0; kkkk++) From f9b1acb8139fb613335d363d30bf5a7ed5a30a92 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Wed, 15 Apr 2020 09:41:21 +0200 Subject: [PATCH 23/75] reworked Tag_FindLineSpecial() --- src/taglist.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/taglist.c b/src/taglist.c index 61b8a147d..f00f62ca4 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -114,16 +114,20 @@ INT32 Tag_Iterate_Things (const INT16 tag, const size_t p) INT32 Tag_FindLineSpecial(const INT16 special, const INT16 tag) { - TAG_ITER_C INT32 i; - TAG_ITER_LINES(tag, i) + if (tag == -1) { - if (i == -1) - return -1; - - if (lines[i].special == special) - return i; + for (i = 0; i < numlines; i++) + if (lines[i].special == special) + return i; + } + else if (tags_lines[tag]) + { + taggroup_t *tagged = tags_lines[tag]; + for (i = 0; i < tagged->count; i++) + if (lines[tagged->elements[i]].special == special) + return tagged->elements[i]; } return -1; } From 7d3d71c418fa6d4e5426e5c8a5d866e110c336ef Mon Sep 17 00:00:00 2001 From: Nev3r Date: Wed, 15 Apr 2020 10:05:59 +0200 Subject: [PATCH 24/75] Get rid of the last case of P_FindSpecialLineFromTag() in the main code. --- src/r_bsp.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/r_bsp.c b/src/r_bsp.c index e360e4376..d003db666 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -451,21 +451,25 @@ static void R_AddLine(seg_t *line) // Portal line if (line->linedef->special == 40 && line->side == 0) { + // Render portal if recursiveness limit hasn't been reached. + // Otherwise, render the wall normally. if (portalrender < cv_maxportals.value) { - // Find the other side! - INT32 line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, -1); - if (line->linedef == &lines[line2]) - line2 = P_FindSpecialLineFromTag(40, line->linedef->tag, line2); - if (line2 >= 0) // found it! + size_t p; + INT16 tag = line->linedef->tag; + INT32 li1 = line->linedef-lines; + INT32 li2; + + for (p = 0; (li2 = Tag_Iterate_Lines(tag, p)) >= 0; p++) { - Portal_Add2Lines(line->linedef-lines, line2, x1, x2); // Remember the lines for later rendering - //return; // Don't fill in that space now! + // Skip invalid lines. + if ((tag != lines[li2].tag) || (lines[li1].special != lines[li2].special) || (li1 == li2)) + continue; + + Portal_Add2Lines(li1, li2, x1, x2); goto clipsolid; } } - // Recursed TOO FAR (viewing a portal within a portal) - // So uhhh, render it as a normal wall instead or something ??? } // Single sided line? From 95c7690a40352e5cc73c7e313ffd5c487df48de7 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Wed, 15 Apr 2020 10:16:49 +0200 Subject: [PATCH 25/75] Remove P_FindSpecialLineFromTag() --- src/lua_baselib.c | 12 ------------ src/p_spec.c | 32 -------------------------------- src/p_spec.h | 2 -- 3 files changed, 46 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 48a503828..884588160 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1915,17 +1915,6 @@ static int lib_pFindHighestCeilingSurrounding(lua_State *L) return 1; } -static int lib_pFindSpecialLineFromTag(lua_State *L) -{ - INT16 special = (INT16)luaL_checkinteger(L, 1); - INT16 line = (INT16)luaL_checkinteger(L, 2); - INT32 start = (INT32)luaL_optinteger(L, 3, -1); - NOHUD - INLEVEL - lua_pushinteger(L, P_FindSpecialLineFromTag(special, line, start)); - return 1; -} - static int lib_pSwitchWeather(lua_State *L) { INT32 weathernum = (INT32)luaL_checkinteger(L, 1); @@ -3213,7 +3202,6 @@ static luaL_Reg lib[] = { {"P_FindNextLowestFloor",lib_pFindNextLowestFloor}, {"P_FindLowestCeilingSurrounding",lib_pFindLowestCeilingSurrounding}, {"P_FindHighestCeilingSurrounding",lib_pFindHighestCeilingSurrounding}, - {"P_FindSpecialLineFromTag",lib_pFindSpecialLineFromTag}, {"P_SwitchWeather",lib_pSwitchWeather}, {"P_LinedefExecute",lib_pLinedefExecute}, {"P_SpawnLightningFlash",lib_pSpawnLightningFlash}, diff --git a/src/p_spec.c b/src/p_spec.c index 1977e7a89..2e8f1b685 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -988,38 +988,6 @@ static sector_t *P_FindModelCeilingSector(fixed_t ceildestheight, INT32 secnum) } #endif -// -// P_FindSpecialLineFromTag -// -INT32 P_FindSpecialLineFromTag(INT16 special, INT16 tag, INT32 start) -{ - if (tag == -1) - { - start++; - - // This redundant check stops the compiler from complaining about function expansion - // elsewhere for some reason and everything is awful - if (start >= (INT32)numlines) - return -1; - - while (start < (INT32)numlines && lines[start].special != special) - start++; - - if (start >= (INT32)numlines) - return -1; - - return start; - } - else - { - start = start >= 0 ? lines[start].nexttag : - lines[(unsigned)tag % numlines].firsttag; - while (start >= 0 && (lines[start].tag != tag || lines[start].special != special)) - start = lines[start].nexttag; - return start; - } -} - // haleyjd: temporary define #ifdef POLYOBJECTS diff --git a/src/p_spec.h b/src/p_spec.h index 271c04c08..1e9ff1c41 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -55,8 +55,6 @@ fixed_t P_FindNextLowestFloor(sector_t *sec, fixed_t currentheight); fixed_t P_FindLowestCeilingSurrounding(sector_t *sec); fixed_t P_FindHighestCeilingSurrounding(sector_t *sec); -INT32 P_FindSpecialLineFromTag(INT16 special, INT16 tag, INT32 start); - INT32 P_FindMinSurroundingLight(sector_t *sector, INT32 max); void P_SetupSignExit(player_t *player); From 786e448f165d2a32560982785078ae6ce96bd6ad Mon Sep 17 00:00:00 2001 From: Nev3r Date: Wed, 15 Apr 2020 10:17:14 +0200 Subject: [PATCH 26/75] Do not add -1 to the global taglists. --- src/taglist.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/taglist.c b/src/taglist.c index f00f62ca4..fcce7adc3 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -25,6 +25,10 @@ boolean Tag_Compare (const taglist_t* list1, const taglist_t* list2) void Taglist_AddToSectors (const size_t tag, const size_t itemid) { taggroup_t* tagelems; + + if (tag == -1) + return; + if (!tags_sectors[tag]) tags_sectors[tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); @@ -40,6 +44,9 @@ void Taglist_AddToLines (const size_t tag, const size_t itemid) if (!tags_lines[tag]) tags_lines[tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); + if (tag == -1) + return; + tagelems = tags_lines[tag]; tagelems->count++; tagelems->elements = Z_Realloc(tagelems->elements, tagelems->count * sizeof(size_t), PU_LEVEL, NULL); @@ -52,6 +59,9 @@ void Taglist_AddToMapthings (const size_t tag, const size_t itemid) if (!tags_mapthings[tag]) tags_mapthings[tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); + if (tag == -1) + return; + tagelems = tags_mapthings[tag]; tagelems->count++; tagelems->elements = Z_Realloc(tagelems->elements, tagelems->count * sizeof(size_t), PU_LEVEL, NULL); From 1d572c5b2c1516b22cd004c5cd92e741fbe8edde Mon Sep 17 00:00:00 2001 From: Nev3r Date: Thu, 16 Apr 2020 14:37:01 +0200 Subject: [PATCH 27/75] Fix fuckup in the -1 tag bailout on the global tag lists. --- src/taglist.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/taglist.c b/src/taglist.c index fcce7adc3..5174fe2d7 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -41,12 +41,13 @@ void Taglist_AddToSectors (const size_t tag, const size_t itemid) void Taglist_AddToLines (const size_t tag, const size_t itemid) { taggroup_t* tagelems; - if (!tags_lines[tag]) - tags_lines[tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); if (tag == -1) return; + if (!tags_lines[tag]) + tags_lines[tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); + tagelems = tags_lines[tag]; tagelems->count++; tagelems->elements = Z_Realloc(tagelems->elements, tagelems->count * sizeof(size_t), PU_LEVEL, NULL); @@ -56,12 +57,13 @@ void Taglist_AddToLines (const size_t tag, const size_t itemid) void Taglist_AddToMapthings (const size_t tag, const size_t itemid) { taggroup_t* tagelems; - if (!tags_mapthings[tag]) - tags_mapthings[tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); if (tag == -1) return; + if (!tags_mapthings[tag]) + tags_mapthings[tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); + tagelems = tags_mapthings[tag]; tagelems->count++; tagelems->elements = Z_Realloc(tagelems->elements, tagelems->count * sizeof(size_t), PU_LEVEL, NULL); From c0b4090924bab2ccb225e1a207e3e976a86a4abb Mon Sep 17 00:00:00 2001 From: Nev3r Date: Thu, 16 Apr 2020 18:48:57 +0200 Subject: [PATCH 28/75] Clean up type inconsistency on tags. --- src/taglist.c | 70 +++++++++++++++++++++++++-------------------------- src/taglist.h | 27 +++++++++++--------- 2 files changed, 50 insertions(+), 47 deletions(-) diff --git a/src/taglist.c b/src/taglist.c index 5174fe2d7..bfa5814dd 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -2,7 +2,7 @@ #include "z_zone.h" #include "r_data.h" -void Tag_Add (taglist_t* list, const UINT16 tag) +void Tag_Add (taglist_t* list, const mtag_t tag) { list->tags = Z_Realloc(list->tags, (list->count + 1) * sizeof(list->tags), PU_LEVEL, NULL); list->tags[list->count++] = tag; @@ -22,121 +22,121 @@ boolean Tag_Compare (const taglist_t* list1, const taglist_t* list2) return true; } -void Taglist_AddToSectors (const size_t tag, const size_t itemid) +void Taglist_AddToSectors (const mtag_t tag, const size_t itemid) { taggroup_t* tagelems; - if (tag == -1) + if (tag == MTAG_GLOBAL) return; - if (!tags_sectors[tag]) - tags_sectors[tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); + if (!tags_sectors[(UINT16)tag]) + tags_sectors[(UINT16)tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); - tagelems = tags_sectors[tag]; + tagelems = tags_sectors[(UINT16)tag]; tagelems->count++; tagelems->elements = Z_Realloc(tagelems->elements, tagelems->count * sizeof(size_t), PU_LEVEL, NULL); tagelems->elements[tagelems->count - 1] = itemid; } -void Taglist_AddToLines (const size_t tag, const size_t itemid) +void Taglist_AddToLines (const mtag_t tag, const size_t itemid) { taggroup_t* tagelems; - if (tag == -1) + if (tag == MTAG_GLOBAL) return; - if (!tags_lines[tag]) - tags_lines[tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); + if (!tags_lines[(UINT16)tag]) + tags_lines[(UINT16)tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); - tagelems = tags_lines[tag]; + tagelems = tags_lines[(UINT16)tag]; tagelems->count++; tagelems->elements = Z_Realloc(tagelems->elements, tagelems->count * sizeof(size_t), PU_LEVEL, NULL); tagelems->elements[tagelems->count - 1] = itemid; } -void Taglist_AddToMapthings (const size_t tag, const size_t itemid) +void Taglist_AddToMapthings (const mtag_t tag, const size_t itemid) { taggroup_t* tagelems; - if (tag == -1) + if (tag == MTAG_GLOBAL) return; - if (!tags_mapthings[tag]) - tags_mapthings[tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); + if (!tags_mapthings[(UINT16)tag]) + tags_mapthings[(UINT16)tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); - tagelems = tags_mapthings[tag]; + tagelems = tags_mapthings[(UINT16)tag]; tagelems->count++; tagelems->elements = Z_Realloc(tagelems->elements, tagelems->count * sizeof(size_t), PU_LEVEL, NULL); tagelems->elements[tagelems->count - 1] = itemid; } -INT32 Tag_Iterate_Sectors (const INT16 tag, const size_t p) +INT32 Tag_Iterate_Sectors (const mtag_t tag, const size_t p) { - if (tag == -1) + if (tag == MTAG_GLOBAL) { if (p < numsectors) return p; return -1; } - if (tags_sectors[tag]) + if (tags_sectors[(UINT16)tag]) { - if (p < tags_sectors[tag]->count) - return tags_sectors[tag]->elements[p]; + if (p < tags_sectors[(UINT16)tag]->count) + return tags_sectors[(UINT16)tag]->elements[p]; return -1; } return -1; } -INT32 Tag_Iterate_Lines (const INT16 tag, const size_t p) +INT32 Tag_Iterate_Lines (const mtag_t tag, const size_t p) { - if (tag == -1) + if (tag == MTAG_GLOBAL) { if (p < numlines) return p; return -1; } - if (tags_lines[tag]) + if (tags_lines[(UINT16)tag]) { - if (p < tags_lines[tag]->count) - return tags_lines[tag]->elements[p]; + if (p < tags_lines[(UINT16)tag]->count) + return tags_lines[(UINT16)tag]->elements[p]; return -1; } return -1; } -INT32 Tag_Iterate_Things (const INT16 tag, const size_t p) +INT32 Tag_Iterate_Things (const mtag_t tag, const size_t p) { - if (tag == -1) + if (tag == MTAG_GLOBAL) { if (p < nummapthings) return p; return -1; } - if (tags_mapthings[tag]) + if (tags_mapthings[(UINT16)tag]) { - if (p < tags_mapthings[tag]->count) - return tags_mapthings[tag]->elements[p]; + if (p < tags_mapthings[(UINT16)tag]->count) + return tags_mapthings[(UINT16)tag]->elements[p]; return -1; } return -1; } -INT32 Tag_FindLineSpecial(const INT16 special, const INT16 tag) +INT32 Tag_FindLineSpecial(const INT16 special, const mtag_t tag) { INT32 i; - if (tag == -1) + if (tag == MTAG_GLOBAL) { for (i = 0; i < numlines; i++) if (lines[i].special == special) return i; } - else if (tags_lines[tag]) + else if (tags_lines[(UINT16)tag]) { - taggroup_t *tagged = tags_lines[tag]; + taggroup_t *tagged = tags_lines[(UINT16)tag]; for (i = 0; i < tagged->count; i++) if (lines[tagged->elements[i]].special == special) return tagged->elements[i]; diff --git a/src/taglist.h b/src/taglist.h index 59ecd6106..67665434c 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -3,14 +3,18 @@ #include "doomtype.h" +typedef INT16 mtag_t; +#define MAXTAGS UINT16_MAX +#define MTAG_GLOBAL -1 + /// Multitag list. typedef struct { - UINT16* tags; + mtag_t* tags; UINT16 count; } taglist_t; -void Tag_Add (taglist_t* list, const UINT16 tag); +void Tag_Add (taglist_t* list, const mtag_t tag); boolean Tag_Compare (const taglist_t* list1, const taglist_t* list2); typedef struct @@ -19,18 +23,17 @@ typedef struct size_t count; } taggroup_t; -#define MAXTAGS 65536 -taggroup_t* tags_sectors[MAXTAGS]; -taggroup_t* tags_lines[MAXTAGS]; -taggroup_t* tags_mapthings[MAXTAGS]; +taggroup_t* tags_sectors[MAXTAGS + 1]; +taggroup_t* tags_lines[MAXTAGS + 1]; +taggroup_t* tags_mapthings[MAXTAGS + 1]; -void Taglist_AddToSectors (const size_t tag, const size_t itemid); -void Taglist_AddToLines (const size_t tag, const size_t itemid); -void Taglist_AddToMapthings (const size_t tag, const size_t itemid); +void Taglist_AddToSectors (const mtag_t tag, const size_t itemid); +void Taglist_AddToLines (const mtag_t tag, const size_t itemid); +void Taglist_AddToMapthings (const mtag_t tag, const size_t itemid); -INT32 Tag_Iterate_Sectors (const INT16 tag, const size_t p); -INT32 Tag_Iterate_Lines (const INT16 tag, const size_t p); -INT32 Tag_Iterate_Things (const INT16 tag, const size_t p); +INT32 Tag_Iterate_Sectors (const mtag_t tag, const size_t p); +INT32 Tag_Iterate_Lines (const mtag_t tag, const size_t p); +INT32 Tag_Iterate_Things (const mtag_t tag, const size_t p); INT32 Tag_FindLineSpecial(const INT16 special, const INT16 tag); From 944716c45a207283799587014422137a4cd6f110 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 09:56:20 +0200 Subject: [PATCH 29/75] Add auxiliary functions to the taglist library. --- src/taglist.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/taglist.h | 6 ++++++ 2 files changed, 47 insertions(+) diff --git a/src/taglist.c b/src/taglist.c index bfa5814dd..0b7c8e23b 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -8,6 +8,47 @@ void Tag_Add (taglist_t* list, const mtag_t tag) list->tags[list->count++] = tag; } +/// Sets the first tag entry in a taglist. +void Tag_FSet (taglist_t* list, const mtag_t tag) +{ + if (!list->count) + { + Tag_Add(list, tag); + return; + } + + list->tags[0] = tag; +} + +/// Gets the first tag entry in a taglist. +mtag_t Tag_FGet (const taglist_t* list) +{ + if (list->count) + return list->tags[0]; + + return 0; +} + +boolean Tag_Find (const taglist_t* list, const mtag_t tag) +{ + size_t i; + for (i = 0; i < list->count; i++) + if (list->tags[i] == tag) + return true; + + return false; +} + +boolean Tag_Share (const taglist_t* list1, const taglist_t* list2) +{ + size_t i; + for (i = 0; i < list1->count; i++) + if (Tag_Find(list2, list1->tags[i])) + return true; + + return false; +} + boolean Tag_Compare (const taglist_t* list1, const taglist_t* list2) { size_t i; diff --git a/src/taglist.h b/src/taglist.h index 67665434c..c22f9f277 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -15,6 +15,12 @@ typedef struct } taglist_t; void Tag_Add (taglist_t* list, const mtag_t tag); + +void Tag_FSet (taglist_t* list, const mtag_t tag); +mtag_t Tag_FGet (const taglist_t* list); +boolean Tag_Find (const taglist_t* list, const mtag_t tag); +boolean Tag_Share (const taglist_t* list1, const taglist_t* list2); + boolean Tag_Compare (const taglist_t* list1, const taglist_t* list2); typedef struct From 81be6b4067dd5b55a6b35562e90de306bce1667e Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 10:04:11 +0200 Subject: [PATCH 30/75] Thing-based slope vertexes use taglists now. --- src/p_setup.c | 2 ++ src/p_slopes.c | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 7c06d5b7f..bf85e7146 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2836,6 +2836,8 @@ static void P_ConvertBinaryMap(void) switch (mapthings[i].type) { case 750: + Tag_Add(&mapthings[i].tags, mapthings[i].angle); + break; case 760: case 761: case 762: diff --git a/src/p_slopes.c b/src/p_slopes.c index 9b147f046..447c5fd93 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -426,11 +426,11 @@ static pslope_t *MakeViaMapthings(INT16 tag1, INT16 tag2, INT16 tag3, UINT8 flag if (mt->type != 750) // Haha, I'm hijacking the old Chaos Spawn thingtype for something! continue; - if (!vertices[0] && mt->tag == tag1) + if (!vertices[0] && Tag_Find(&mt->tags, tag1)) vertices[0] = mt; - else if (!vertices[1] && mt->tag == tag2) + else if (!vertices[1] && Tag_Find(&mt->tags, tag2)) vertices[1] = mt; - else if (!vertices[2] && mt->tag == tag3) + else if (!vertices[2] && Tag_Find(&mt->tags, tag3)) vertices[2] = mt; } From 4fc07473fdc885e79ae4e01e4d9f423945bf7e09 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 10:05:50 +0200 Subject: [PATCH 31/75] Skybox spawning now uses the taglists. --- src/p_mobj.c | 11 +++++++---- src/p_setup.c | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index c004d3257..5203c092f 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -12584,17 +12584,20 @@ static boolean P_SetupSpawnedMapThing(mapthing_t *mthing, mobj_t *mobj, boolean break; } case MT_SKYBOX: - if (mthing->tag < 0 || mthing->tag > 15) + { + mtag_t tag = Tag_FGet(&mthing->tags); + if (tag < 0 || tag > 15) { - CONS_Debug(DBG_GAMELOGIC, "P_SetupSpawnedMapThing: Skybox ID %d of mapthing %s is not between 0 and 15!\n", mthing->tag, sizeu1((size_t)(mthing - mapthings))); + CONS_Debug(DBG_GAMELOGIC, "P_SetupSpawnedMapThing: Skybox ID %d of mapthing %s is not between 0 and 15!\n", tag, sizeu1((size_t)(mthing - mapthings))); break; } if (mthing->options & MTF_OBJECTSPECIAL) - skyboxcenterpnts[mthing->tag] = mobj; + skyboxcenterpnts[tag] = mobj; else - skyboxviewpnts[mthing->tag] = mobj; + skyboxviewpnts[tag] = mobj; break; + } case MT_EGGSTATUE: if (mthing->options & MTF_EXTRA) { diff --git a/src/p_setup.c b/src/p_setup.c index bf85e7146..931a7cd8f 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2844,7 +2844,7 @@ static void P_ConvertBinaryMap(void) mapthings[i].tag = mapthings[i].angle; break; case 780: - mapthings[i].tag = mapthings[i].extrainfo; + Tag_FSet(&mapthings[i].tags, mapthings[i].extrainfo); break; default: break; From b9decb2837d1ba977f3bcbd2db474afcb1f2c9c7 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 10:30:38 +0200 Subject: [PATCH 32/75] Polyobject spawning now use the taglist. --- src/p_polyobj.c | 22 ++++++++++++---------- src/p_setup.c | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/p_polyobj.c b/src/p_polyobj.c index cfe12db13..3e4491fe2 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -539,7 +539,7 @@ static void Polyobj_findExplicit(polyobj_t *po) if (segs[i].linedef->special != POLYOBJ_EXPLICIT_LINE) continue; - Polyobj_GetInfo(segs[i].linedef->tag, &polyID, &parentID, NULL); + Polyobj_GetInfo(Tag_FGet(&segs[i].linedef->tags), &polyID, &parentID, NULL); if (polyID == po->id && parentID > 0) { @@ -622,7 +622,7 @@ static void Polyobj_spawnPolyObj(INT32 num, mobj_t *spawnSpot, INT32 id) if (seg->linedef->special != POLYOBJ_START_LINE) continue; - if (seg->linedef->tag != po->id) + if (Tag_FGet(&seg->linedef->tags) != po->id) continue; Polyobj_GetInfo(po->id, &poflags, &parentID, &potrans); // apply extra settings if they exist! @@ -659,7 +659,7 @@ static void Polyobj_spawnPolyObj(INT32 num, mobj_t *spawnSpot, INT32 id) if (po->isBad) return; - Polyobj_GetInfo(po->segs[0]->linedef->tag, NULL, NULL, &parent); + Polyobj_GetInfo(Tag_FGet(&po->segs[0]->linedef->tags), NULL, NULL, &parent); po->parent = parent; if (po->parent == po->id) // do not allow a self-reference po->parent = -1; @@ -707,10 +707,11 @@ static void Polyobj_moveToSpawnSpot(mapthing_t *anchor) polyobj_t *po; vertex_t dist, sspot; size_t i; + mtag_t tag = Tag_FGet(&anchor->tags); - if (!(po = Polyobj_GetForNum(anchor->tag))) + if (!(po = Polyobj_GetForNum(tag))) { - CONS_Debug(DBG_POLYOBJ, "Bad polyobject %d for anchor point\n", anchor->tag); + CONS_Debug(DBG_POLYOBJ, "Bad polyobject %d for anchor point\n", tag); return; } @@ -1574,7 +1575,7 @@ void Polyobj_InitLevel(void) { qitem = (mobjqitem_t *)M_QueueIterator(&spawnqueue); - Polyobj_spawnPolyObj(i, qitem->mo, qitem->mo->spawnpoint->tag); + Polyobj_spawnPolyObj(i, qitem->mo, Tag_FGet(&qitem->mo->spawnpoint->tags)); } // move polyobjects to spawn points @@ -2943,10 +2944,11 @@ INT32 EV_DoPolyObjFlag(line_t *pfdata) polymove_t *th; size_t i; INT32 start; + mtag_t tag = Tag_FGet(&pfdata->tags); - if (!(po = Polyobj_GetForNum(pfdata->tag))) + if (!(po = Polyobj_GetForNum(tag))) { - CONS_Debug(DBG_POLYOBJ, "EV_DoPolyFlag: bad polyobj %d\n", pfdata->tag); + CONS_Debug(DBG_POLYOBJ, "EV_DoPolyFlag: bad polyobj %d\n", tag); return 0; } @@ -2969,7 +2971,7 @@ INT32 EV_DoPolyObjFlag(line_t *pfdata) po->thinker = &th->thinker; // set fields - th->polyObjNum = pfdata->tag; + th->polyObjNum = tag; th->distance = 0; th->speed = P_AproxDistance(pfdata->dx, pfdata->dy)>>FRACBITS; th->angle = R_PointToAngle2(pfdata->v1->x, pfdata->v1->y, pfdata->v2->x, pfdata->v2->y)>>ANGLETOFINESHIFT; @@ -2985,7 +2987,7 @@ INT32 EV_DoPolyObjFlag(line_t *pfdata) start = 0; while ((po = Polyobj_GetChild(oldpo, &start))) { - pfdata->tag = po->id; + Tag_FSet(&pfdata->tags, po->id); EV_DoPolyObjFlag(pfdata); } diff --git a/src/p_setup.c b/src/p_setup.c index 931a7cd8f..2a514b50e 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2841,7 +2841,7 @@ static void P_ConvertBinaryMap(void) case 760: case 761: case 762: - mapthings[i].tag = mapthings[i].angle; + Tag_FSet(&mapthings[i].tags, mapthings[i].angle); break; case 780: Tag_FSet(&mapthings[i].tags, mapthings[i].extrainfo); From e59480e4cffa0a780397955b9dd5c891425c5d94 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 10:34:24 +0200 Subject: [PATCH 33/75] Portal lines now use the taglist's first element. --- src/r_bsp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_bsp.c b/src/r_bsp.c index d003db666..d5c18056c 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -456,14 +456,14 @@ static void R_AddLine(seg_t *line) if (portalrender < cv_maxportals.value) { size_t p; - INT16 tag = line->linedef->tag; + mtag_t tag = Tag_FGet(&line->linedef->tags); INT32 li1 = line->linedef-lines; INT32 li2; for (p = 0; (li2 = Tag_Iterate_Lines(tag, p)) >= 0; p++) { // Skip invalid lines. - if ((tag != lines[li2].tag) || (lines[li1].special != lines[li2].special) || (li1 == li2)) + if ((tag != Tag_FGet(&lines[li2].tags)) || (lines[li1].special != lines[li2].special) || (li1 == li2)) continue; Portal_Add2Lines(li1, li2, x1, x2); From 61c3e12d637a79a69cef4a53f0e04574173bc0a7 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 10:41:26 +0200 Subject: [PATCH 34/75] Make a commented out debug code account for taglists. --- src/p_user.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index 131eedd9c..c2f122ace 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -12342,12 +12342,14 @@ void P_PlayerThink(player_t *player) sector_t *controlsec; for (j=0; jtags); // Does this sector have a colormap? for (i=0; itag) + if (lines[i].special == 606 && linetag == controlsectag) break; } if (i == numlines) - CONS_Debug(DBG_GAMELOGIC, "%d, %d\n", j, sectors[j].tag); + CONS_Debug(DBG_GAMELOGIC, "%d, %d\n", j, sectag); } } From a5bc3fb507e2a1260d3427eb12f13074adcf4b45 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 10:52:12 +0200 Subject: [PATCH 35/75] P_SpawnSpecials() line special spawn sequence now uses the taglist, until we move on to using args[0]. --- src/p_spec.c | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 2e8f1b685..7abf8cbf4 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -6396,6 +6396,8 @@ void P_SpawnSpecials(boolean fromnetsave) // Init line EFFECTs for (i = 0; i < numlines; i++) { + mtag_t tag = Tag_FGet(&lines[i].tags); + if (lines[i].special != 7) // This is a hack. I can at least hope nobody wants to prevent flat alignment in netgames... { // set line specials to 0 here too, same reason as above @@ -6423,7 +6425,7 @@ void P_SpawnSpecials(boolean fromnetsave) case 1: // Definable gravity per sector sec = sides[*lines[i].sidenum].sector - sectors; - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) { sectors[s].gravity = §ors[sec].floorheight; // This allows it to change in realtime! @@ -6447,7 +6449,7 @@ void P_SpawnSpecials(boolean fromnetsave) case 5: // Change camera info sec = sides[*lines[i].sidenum].sector - sectors; - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) P_AddCameraScanner(§ors[sec], §ors[s], R_PointToAngle2(lines[i].v2->x, lines[i].v2->y, lines[i].v1->x, lines[i].v1->y)); break; @@ -6470,22 +6472,22 @@ void P_SpawnSpecials(boolean fromnetsave) } //If no tag is given, apply to front sector - if (lines[i].tag == 0) + if (tag == 0) P_ApplyFlatAlignment(lines + i, lines[i].frontsector, flatangle, xoffs, yoffs); else { - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) P_ApplyFlatAlignment(lines + i, sectors + s, flatangle, xoffs, yoffs); } } else // Otherwise, print a helpful warning. Can I do no less? CONS_Alert(CONS_WARNING, M_GetText("Flat alignment linedef (tag %d) doesn't have anything to do.\nConsider changing the linedef's flag configuration or removing it entirely.\n"), - lines[i].tag); + tag); break; case 8: // Sector Parameters - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) { if (lines[i].flags & ML_NOCLIMB) { @@ -6513,7 +6515,7 @@ void P_SpawnSpecials(boolean fromnetsave) case 10: // Vertical culling plane for sprites and FOFs sec = sides[*lines[i].sidenum].sector - sectors; - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) sectors[s].cullheight = &lines[i]; // This allows it to change in realtime! break; @@ -6574,13 +6576,13 @@ void P_SpawnSpecials(boolean fromnetsave) case 63: // support for drawn heights coming from different sector sec = sides[*lines[i].sidenum].sector-sectors; - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) sectors[s].heightsec = (INT32)sec; break; case 64: // Appearing/Disappearing FOF option if (lines[i].flags & ML_BLOCKMONSTERS) { // Find FOFs by control sector tag - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) for (j = 0; (unsigned)j < sectors[s].linecount; j++) if (sectors[s].lines[j]->special >= 100 && sectors[s].lines[j]->special < 300) Add_MasterDisappearer(abs(lines[i].dx>>FRACBITS), abs(lines[i].dy>>FRACBITS), abs(sides[lines[i].sidenum[0]].sector->floorheight>>FRACBITS), (INT32)(sectors[s].lines[j]-lines), (INT32)i); @@ -6597,15 +6599,15 @@ void P_SpawnSpecials(boolean fromnetsave) break; case 66: // Displace floor by front sector - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) P_AddPlaneDisplaceThinker(pd_floor, P_AproxDistance(lines[i].dx, lines[i].dy)>>8, sides[lines[i].sidenum[0]].sector-sectors, s, !!(lines[i].flags & ML_NOCLIMB)); break; case 67: // Displace ceiling by front sector - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) P_AddPlaneDisplaceThinker(pd_ceiling, P_AproxDistance(lines[i].dx, lines[i].dy)>>8, sides[lines[i].sidenum[0]].sector-sectors, s, !!(lines[i].flags & ML_NOCLIMB)); break; case 68: // Displace both floor AND ceiling by front sector - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) P_AddPlaneDisplaceThinker(pd_both, P_AproxDistance(lines[i].dx, lines[i].dy)>>8, sides[lines[i].sidenum[0]].sector-sectors, s, !!(lines[i].flags & ML_NOCLIMB)); break; @@ -6980,7 +6982,7 @@ void P_SpawnSpecials(boolean fromnetsave) case 251: // A THWOMP! sec = sides[*lines[i].sidenum].sector - sectors; - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) { P_AddThwompThinker(§ors[sec], §ors[s], &lines[i]); P_AddFakeFloor(§ors[s], §ors[sec], lines + i, @@ -7028,7 +7030,7 @@ void P_SpawnSpecials(boolean fromnetsave) sec = sides[*lines[i].sidenum].sector - sectors; // No longer totally disrupts netgames - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) EV_AddLaserThinker(§ors[s], §ors[sec], lines + i, secthinkers); break; @@ -7039,7 +7041,7 @@ void P_SpawnSpecials(boolean fromnetsave) P_AddFakeFloorsByLine(i, fofflags, secthinkers); } else - I_Error("Custom FOF (tag %d) found without a linedef back side!", lines[i].tag); + I_Error("Custom FOF (tag %d) found without a linedef back side!", tag); break; case 300: // Linedef executor (combines with sector special 974/975) and commands @@ -7174,7 +7176,7 @@ void P_SpawnSpecials(boolean fromnetsave) { CONS_Alert(CONS_WARNING, M_GetText("Boss enable linedef (tag %d) has an invalid texture x offset.\nConsider changing it or removing it entirely.\n"), - lines[i].tag); + tag); break; } if (!(lines[i].flags & ML_NOCLIMB)) @@ -7220,46 +7222,46 @@ void P_SpawnSpecials(boolean fromnetsave) case 600: // floor lighting independently (e.g. lava) sec = sides[*lines[i].sidenum].sector-sectors; - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) sectors[s].floorlightsec = (INT32)sec; break; case 601: // ceiling lighting independently sec = sides[*lines[i].sidenum].sector-sectors; - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) sectors[s].ceilinglightsec = (INT32)sec; break; case 602: // Adjustable pulsating light sec = sides[*lines[i].sidenum].sector - sectors; - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) P_SpawnAdjustableGlowingLight(§ors[sec], §ors[s], P_AproxDistance(lines[i].dx, lines[i].dy)>>FRACBITS); break; case 603: // Adjustable flickering light sec = sides[*lines[i].sidenum].sector - sectors; - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) P_SpawnAdjustableFireFlicker(§ors[sec], §ors[s], P_AproxDistance(lines[i].dx, lines[i].dy)>>FRACBITS); break; case 604: // Adjustable Blinking Light (unsynchronized) sec = sides[*lines[i].sidenum].sector - sectors; - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) P_SpawnAdjustableStrobeFlash(§ors[sec], §ors[s], abs(lines[i].dx)>>FRACBITS, abs(lines[i].dy)>>FRACBITS, false); break; case 605: // Adjustable Blinking Light (synchronized) sec = sides[*lines[i].sidenum].sector - sectors; - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) P_SpawnAdjustableStrobeFlash(§ors[sec], §ors[s], abs(lines[i].dx)>>FRACBITS, abs(lines[i].dy)>>FRACBITS, true); break; case 606: // HACK! Copy colormaps. Just plain colormaps. - TAG_ITER_SECTORS(lines[i].tag, s) + TAG_ITER_SECTORS(tag, s) sectors[s].extra_colormap = sectors[s].spawn_extra_colormap = sides[lines[i].sidenum[0]].colormap_data; break; From dd46b1ab4498770b275f019c488f8222d30fa03a Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 11:04:44 +0200 Subject: [PATCH 36/75] P_ConvertBinaryMap() line conversion now uses the first tag from taglists. --- src/p_setup.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 2a514b50e..54a3d27c5 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2728,6 +2728,8 @@ static void P_ConvertBinaryMap(void) for (i = 0; i < numlines; i++) { + mtag_t tag = Tag_FGet(&lines[i].tags); + switch (lines[i].special) { case 443: //Call Lua function @@ -2778,7 +2780,7 @@ static void P_ConvertBinaryMap(void) else if (lines[i].special == 715) lines[i].args[0] = 3; - lines[i].args[1] = lines[i].tag; + lines[i].args[1] = tag; if (lines[i].flags & ML_EFFECT6) { @@ -2810,9 +2812,9 @@ static void P_ConvertBinaryMap(void) case 721: //Copy front side ceiling slope case 722: //Copy front side floor and ceiling slope if (lines[i].special != 721) - lines[i].args[0] = lines[i].tag; + lines[i].args[0] = tag; if (lines[i].special != 720) - lines[i].args[1] = lines[i].tag; + lines[i].args[1] = tag; lines[i].special = 720; break; case 900: //Translucent wall (10%) From 209b8e76782c40302846e31a6a59946189b0e405 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 11:21:40 +0200 Subject: [PATCH 37/75] Map loading should consider tag 0 as a valid tag and add its respective entries just like the rest of tags. --- src/p_setup.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 54a3d27c5..f2323e532 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -936,8 +936,7 @@ static void P_LoadSectors(UINT8 *data) ss->lightlevel = SHORT(ms->lightlevel); ss->special = SHORT(ms->special); ss->tag = SHORT(ms->tag); - if (ss->tag) - Tag_Add(&ss->tags, ss->tag); + Tag_FSet(&ss->tags, ss->tag); ss->floor_xoffs = ss->floor_yoffs = 0; ss->ceiling_xoffs = ss->ceiling_yoffs = 0; @@ -1052,8 +1051,7 @@ static void P_LoadLinedefs(UINT8 *data) ld->flags = SHORT(mld->flags); ld->special = SHORT(mld->special); ld->tag = SHORT(mld->tag); - if (ld->tag) - Tag_Add(&ld->tags, ld->tag); + Tag_FSet(&ld->tags, ld->tag); memset(ld->args, 0, NUMLINEARGS*sizeof(*ld->args)); memset(ld->stringargs, 0x00, NUMLINESTRINGARGS*sizeof(*ld->stringargs)); ld->alpha = FRACUNIT; @@ -1284,6 +1282,7 @@ static void P_LoadThings(UINT8 *data) mt->options = READUINT16(data); mt->extrainfo = (UINT8)(mt->type >> 12); mt->tag = 0; + Tag_FSet(&mt->tags, mt->tag); mt->type &= 4095; @@ -1405,8 +1404,7 @@ static void ParseTextmapSectorParameter(UINT32 i, char *param, char *val) else if (fastcmp(param, "id")) { sectors[i].tag = atol(val); - if (sectors[i].tag) - Tag_Add(§ors[i].tags, sectors[i].tag); + Tag_FSet(§ors[i].tags, sectors[i].tag); } else if (fastcmp(param, "moreids")) { @@ -1455,8 +1453,7 @@ static void ParseTextmapLinedefParameter(UINT32 i, char *param, char *val) if (fastcmp(param, "id")) { lines[i].tag = atol(val); - if (lines[i].tag) - Tag_Add(&lines[i].tags, lines[i].tag); + Tag_FSet(&lines[i].tags, lines[i].tag); } else if (fastcmp(param, "moreids")) { @@ -1536,8 +1533,7 @@ static void ParseTextmapThingParameter(UINT32 i, char *param, char *val) if (fastcmp(param, "id")) { mapthings[i].tag = atol(val); - if (mapthings[i].tag) - Tag_Add(&mapthings[i].tags, mapthings[i].tag); + Tag_FSet(&mapthings[i].tags, mapthings[i].tag); } else if (fastcmp(param, "moreids")) { @@ -1678,6 +1674,7 @@ static void P_LoadTextmap(void) sc->special = 0; sc->tag = 0; + Tag_FSet(&sc->tags, 0); sc->floor_xoffs = sc->floor_yoffs = 0; sc->ceiling_xoffs = sc->ceiling_yoffs = 0; @@ -1685,6 +1682,7 @@ static void P_LoadTextmap(void) sc->floorpic_angle = sc->ceilingpic_angle = 0; TextmapParse(sectorsPos[i], i, ParseTextmapSectorParameter); + P_InitializeSector(sc); TextmapFixFlatOffsets(sc); } @@ -1696,6 +1694,8 @@ static void P_LoadTextmap(void) ld->flags = 0; ld->special = 0; ld->tag = 0; + Tag_FSet(&ld->tags, 0); + memset(ld->args, 0, NUMLINEARGS*sizeof(*ld->args)); memset(ld->stringargs, 0x00, NUMLINESTRINGARGS*sizeof(*ld->stringargs)); ld->alpha = FRACUNIT; @@ -1743,6 +1743,7 @@ static void P_LoadTextmap(void) mt->z = 0; mt->extrainfo = 0; mt->tag = 0; + Tag_FSet(&mt->tags, 0); mt->mobj = NULL; TextmapParse(mapthingsPos[i], i, ParseTextmapThingParameter); From b690d35a9941420e0643fef069712a34d1a34500 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 11:43:37 +0200 Subject: [PATCH 38/75] Move the global taglist init functionality to the taglist files. --- src/p_spec.c | 23 +---------------------- src/taglist.c | 33 ++++++++++++++++++++++++++++++--- src/taglist.h | 4 +--- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 7abf8cbf4..4e833ba6d 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1445,7 +1445,6 @@ void P_RunNightsCapsuleTouchExecutors(mobj_t *actor, boolean entering, boolean e static inline void P_InitTagLists(void) { register size_t i; - size_t j; for (i = numsectors - 1; i != (size_t)-1; i--) { @@ -1461,27 +1460,7 @@ static inline void P_InitTagLists(void) lines[j].firsttag = (INT32)i; } - for (i = 0; i < MAXTAGS; i++) - { - tags_sectors[i] = NULL; - tags_lines[i] = NULL; - tags_mapthings[i] = NULL; - } - for (i = 0; i < numsectors; i++) - { - for (j = 0; j < sectors[i].tags.count; j++) - Taglist_AddToSectors(sectors[i].tags.tags[j], i); - } - for (i = 0; i < numlines; i++) - { - for (j = 0; j < lines[i].tags.count; j++) - Taglist_AddToLines(lines[i].tags.tags[j], i); - } - for (i = 0; i < nummapthings; i++) - { - for (j = 0; j < mapthings[i].tags.count; j++) - Taglist_AddToMapthings(mapthings[i].tags.tags[j], i); - } + Taglist_InitGlobalTables(); } /** Finds minimum light from an adjacent sector. diff --git a/src/taglist.c b/src/taglist.c index 0b7c8e23b..99d23bf5f 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -63,7 +63,7 @@ boolean Tag_Compare (const taglist_t* list1, const taglist_t* list2) return true; } -void Taglist_AddToSectors (const mtag_t tag, const size_t itemid) +static void Taglist_AddToSectors (const mtag_t tag, const size_t itemid) { taggroup_t* tagelems; @@ -79,7 +79,7 @@ void Taglist_AddToSectors (const mtag_t tag, const size_t itemid) tagelems->elements[tagelems->count - 1] = itemid; } -void Taglist_AddToLines (const mtag_t tag, const size_t itemid) +static void Taglist_AddToLines (const mtag_t tag, const size_t itemid) { taggroup_t* tagelems; @@ -95,7 +95,7 @@ void Taglist_AddToLines (const mtag_t tag, const size_t itemid) tagelems->elements[tagelems->count - 1] = itemid; } -void Taglist_AddToMapthings (const mtag_t tag, const size_t itemid) +static void Taglist_AddToMapthings (const mtag_t tag, const size_t itemid) { taggroup_t* tagelems; @@ -111,6 +111,33 @@ void Taglist_AddToMapthings (const mtag_t tag, const size_t itemid) tagelems->elements[tagelems->count - 1] = itemid; } +void Taglist_InitGlobalTables(void) +{ + size_t i, j; + + for (i = 0; i < MAXTAGS; i++) + { + tags_sectors[i] = NULL; + tags_lines[i] = NULL; + tags_mapthings[i] = NULL; + } + for (i = 0; i < numsectors; i++) + { + for (j = 0; j < sectors[i].tags.count; j++) + Taglist_AddToSectors(sectors[i].tags.tags[j], i); + } + for (i = 0; i < numlines; i++) + { + for (j = 0; j < lines[i].tags.count; j++) + Taglist_AddToLines(lines[i].tags.tags[j], i); + } + for (i = 0; i < nummapthings; i++) + { + for (j = 0; j < mapthings[i].tags.count; j++) + Taglist_AddToMapthings(mapthings[i].tags.tags[j], i); + } +} + INT32 Tag_Iterate_Sectors (const mtag_t tag, const size_t p) { if (tag == MTAG_GLOBAL) diff --git a/src/taglist.h b/src/taglist.h index c22f9f277..b14c316ff 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -33,9 +33,7 @@ taggroup_t* tags_sectors[MAXTAGS + 1]; taggroup_t* tags_lines[MAXTAGS + 1]; taggroup_t* tags_mapthings[MAXTAGS + 1]; -void Taglist_AddToSectors (const mtag_t tag, const size_t itemid); -void Taglist_AddToLines (const mtag_t tag, const size_t itemid); -void Taglist_AddToMapthings (const mtag_t tag, const size_t itemid); +void Taglist_InitGlobalTables(void); INT32 Tag_Iterate_Sectors (const mtag_t tag, const size_t p); INT32 Tag_Iterate_Lines (const mtag_t tag, const size_t p); From e3dfdb448eba67832c2fc9d4060be92458fb564d Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 18:14:15 +0200 Subject: [PATCH 39/75] Add currently unused auxiliary function. --- src/taglist.c | 6 ++++++ src/taglist.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/taglist.c b/src/taglist.c index 99d23bf5f..1849c314c 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -111,6 +111,12 @@ static void Taglist_AddToMapthings (const mtag_t tag, const size_t itemid) tagelems->elements[tagelems->count - 1] = itemid; } +void Tag_SectorFSet (const size_t id, const mtag_t tag) +{ + sector_t* sec = §ors[id]; + Tag_FSet(&sec->tags, tag); +} + void Taglist_InitGlobalTables(void) { size_t i, j; diff --git a/src/taglist.h b/src/taglist.h index b14c316ff..050bebed7 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -23,6 +23,8 @@ boolean Tag_Share (const taglist_t* list1, const taglist_t* list2); boolean Tag_Compare (const taglist_t* list1, const taglist_t* list2); +void Tag_SectorFSet (const size_t id, const mtag_t tag); + typedef struct { size_t *elements; From b5eaad42fc89bff79730e836ab635d897204dc35 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 18:15:25 +0200 Subject: [PATCH 40/75] Carry over a considerable case regarding accessing the old tag vars. --- src/p_mobj.c | 30 ++++++++----- src/p_setup.c | 2 +- src/p_slopes.c | 3 -- src/p_spec.c | 120 ++++++++++++++++++++++++++++--------------------- src/p_user.c | 69 +++++++++++++++++----------- 5 files changed, 130 insertions(+), 94 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 5203c092f..a65d3bbf3 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -4621,7 +4621,7 @@ static boolean P_Boss4MoveCage(mobj_t *mobj, fixed_t delta) for (snum = sectors[tag%numsectors].firsttag; snum != -1; snum = sector->nexttag) { sector = §ors[snum]; - if (sector->tag != tag) + if (!Tag_Find(§or->tags, tag)) continue; sector->floorheight += delta; sector->ceilingheight += delta; @@ -4715,9 +4715,9 @@ static void P_Boss4DestroyCage(mobj_t *mobj) next = sector->nexttag; sector->nexttag = -1; - if (sector->tag != tag) + if (!Tag_Find(§or->tags, tag)) continue; - sector->tag = 0; + Tag_SectorFSet(sector - sectors, 0); // Destroy the FOFs. for (a = 0; a < sector->numattached; a++) @@ -10036,11 +10036,12 @@ void P_MobjThinker(mobj_t *mobj) // Sector special (2,8) allows ANY mobj to trigger a linedef exec if (mobj->subsector && GETSECSPECIAL(mobj->subsector->sector->special, 2) == 8) { - sector_t *sec2; - - sec2 = P_ThingOnSpecial3DFloor(mobj); + sector_t *sec2 = P_ThingOnSpecial3DFloor(mobj); if (sec2 && GETSECSPECIAL(sec2->special, 2) == 1) - P_LinedefExecute(sec2->tag, mobj, sec2); + { + mtag_t tag = Tag_FGet(&sec2->tags); + P_LinedefExecute(tag, mobj, sec2); + } } if (mobj->scale != mobj->destscale) @@ -10264,14 +10265,19 @@ void P_PushableThinker(mobj_t *mobj) sec = mobj->subsector->sector; if (GETSECSPECIAL(sec->special, 2) == 1 && mobj->z == sec->floorheight) - P_LinedefExecute(sec->tag, mobj, sec); + { + mtag_t tag = Tag_FGet(&sec->tags); + P_LinedefExecute(tag, mobj, sec); + } + // else if (GETSECSPECIAL(sec->special, 2) == 8) { - sector_t *sec2; - - sec2 = P_ThingOnSpecial3DFloor(mobj); + sector_t *sec2 = P_ThingOnSpecial3DFloor(mobj); if (sec2 && GETSECSPECIAL(sec2->special, 2) == 1) - P_LinedefExecute(sec2->tag, mobj, sec2); + { + mtag_t tag = Tag_FGet(&sec2->tags); + P_LinedefExecute(tag, mobj, sec2); + } } // it has to be pushable RIGHT NOW for this part to happen diff --git a/src/p_setup.c b/src/p_setup.c index f2323e532..2cbc2ceae 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1241,7 +1241,7 @@ static void P_LoadSidedefs(UINT8 *data) || (msd->toptexture[0] >= 'A' && msd->toptexture[0] <= 'F')) sd->toptexture = axtoi(msd->toptexture); else - I_Error("Custom FOF (tag %d) needs a value in the linedef's back side upper texture field.", sd->line->tag); + I_Error("Custom FOF (line id %d) needs a value in the linedef's back side upper texture field.", sd->line - lines); sd->midtexture = R_TextureNumForName(msd->midtexture); sd->bottomtexture = R_TextureNumForName(msd->bottomtexture); diff --git a/src/p_slopes.c b/src/p_slopes.c index 447c5fd93..39a49084b 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -405,9 +405,6 @@ static void line_SpawnViaLine(const int linenum, const boolean spawnthinker) P_AddDynSlopeThinker(cslope, DP_BACKCEIL, line, extent, NULL, NULL); } } - - if(!line->tag) - return; } /// Creates a new slope from three mapthings with the specified IDs diff --git a/src/p_spec.c b/src/p_spec.c index 4e833ba6d..6c47e24c1 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2061,7 +2061,7 @@ void P_LinedefExecute(INT16 tag, mobj_t *actor, sector_t *caller) for (masterline = 0; masterline < numlines; masterline++) { - if (lines[masterline].tag != tag) + if (Tag_FGet(&lines[masterline].tags) != tag) continue; // "No More Enemies" and "Level Load" take care of themselves. @@ -2327,6 +2327,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { INT32 secnum = -1; mobj_t *bot = NULL; + mtag_t tag = Tag_FGet(&line->tags); TAG_ITER_C I_Assert(!mo || !P_MobjWasRemoved(mo)); // If mo is there, mo must be valid! @@ -2355,7 +2356,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) newceilinglightsec = line->frontsector->ceilinglightsec; // act on all sectors with the same tag as the triggering linedef - TAG_ITER_SECTORS(line->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) { if (sectors[secnum].lightingdata) { @@ -2410,7 +2411,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) case 409: // Change tagged sectors' tag // (formerly "Change calling sectors' tag", but behavior was changed) { - TAG_ITER_SECTORS(line->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) P_ChangeSectorTag(secnum,(INT16)(sides[line->sidenum[0]].textureoffset>>FRACBITS)); break; } @@ -2420,7 +2421,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 411: // Stop floor/ceiling movement in tagged sector(s) - TAG_ITER_SECTORS(line->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) { if (sectors[secnum].floordata) { @@ -2490,7 +2491,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) } else { - if ((secnum = Tag_Iterate_Sectors(line->tag, 0)) < 0) + if ((secnum = Tag_Iterate_Sectors(tag, 0)) < 0) return; dest = P_GetObjectTypeInSectorNum(MT_TELEPORTMAN, secnum); @@ -2597,7 +2598,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) return; } - if (line->tag != 0) // Do special stuff only if a non-zero linedef tag is set + if (tag != 0) // Do special stuff only if a non-zero linedef tag is set { // Play sounds from tagged sectors' origins. if (line->flags & ML_EFFECT5) // Repeat Midtexture @@ -2605,7 +2606,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) // Additionally play the sound from tagged sectors' soundorgs sector_t *sec; - TAG_ITER_SECTORS(line->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) { sec = §ors[secnum]; S_StartSound(&sec->soundorg, sfxnum); @@ -2625,7 +2626,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (!camobj) continue; - if (foundit || (camobj->subsector->sector->tag == line->tag)) + if (foundit || (camobj->subsector->sector->tag == tag)) { foundit = true; break; @@ -2634,7 +2635,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) // Only trigger if mobj is touching the tag for(rover = camobj->subsector->sector->ffloors; rover; rover = rover->next) { - if (rover->master->frontsector->tag != line->tag) + if (rover->master->frontsector->tag != tag) continue; if (camobj->z > P_GetSpecialTopZ(camobj, sectors + rover->secnum, camobj->subsector->sector)) @@ -2720,7 +2721,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 416: // Spawn adjustable fire flicker - TAG_ITER_SECTORS(line->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) { if (line->flags & ML_NOCLIMB && line->backsector) { @@ -2754,7 +2755,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 417: // Spawn adjustable glowing light - TAG_ITER_SECTORS(line->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) { if (line->flags & ML_NOCLIMB && line->backsector) { @@ -2788,7 +2789,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 418: // Spawn adjustable strobe flash (unsynchronized) - TAG_ITER_SECTORS(line->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) { if (line->flags & ML_NOCLIMB && line->backsector) { @@ -2822,7 +2823,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 419: // Spawn adjustable strobe flash (synchronized) - TAG_ITER_SECTORS(line->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) { if (line->flags & ML_NOCLIMB && line->backsector) { @@ -2856,7 +2857,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 420: // Fade light levels in tagged sectors to new value - P_FadeLight(line->tag, + P_FadeLight(tag, (line->flags & ML_DONTPEGBOTTOM) ? max(sides[line->sidenum[0]].textureoffset>>FRACBITS, 0) : line->frontsector->lightlevel, // failsafe: if user specifies Back Y Offset and NOT Front Y Offset, use the Back Offset // to be consistent with other light and fade specials @@ -2870,7 +2871,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 421: // Stop lighting effect in tagged sectors - TAG_ITER_SECTORS(line->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) if (sectors[secnum].lightingdata) { P_RemoveThinker(&((elevator_t *)sectors[secnum].lightingdata)->thinker); @@ -2885,7 +2886,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if ((!mo || !mo->player) && !titlemapinaction) // only players have views, and title screens return; - if ((secnum = Tag_Iterate_Sectors(line->tag, 0)) < 0) + if ((secnum = Tag_Iterate_Sectors(tag, 0)) < 0) return; altview = P_GetObjectTypeInSectorNum(MT_ALTVIEWMAN, secnum); @@ -3062,8 +3063,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) continue; scroller = (scroll_t *)th; - - if (sectors[scroller->affectee].tag != line->tag) + if (!Tag_Find(§ors[scroller->affectee].tags, tag)) continue; scroller->dx = FixedMul(line->dx>>SCROLL_SHIFT, CARRYFACTOR); @@ -3139,12 +3139,13 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) size_t linenum; side_t *set = &sides[line->sidenum[0]], *this; boolean always = !(line->flags & ML_NOCLIMB); // If noclimb: Only change mid texture if mid texture already exists on tagged lines, etc. + for (linenum = 0; linenum < numlines; linenum++) { if (lines[linenum].special == 439) continue; // Don't override other set texture lines! - if (lines[linenum].tag != line->tag) + if (!Tag_Find(&lines[linenum].tags, tag)) continue; // Find tagged lines // Front side @@ -3204,7 +3205,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (line->sidenum[1] != 0xffff) state = (statenum_t)sides[line->sidenum[1]].toptexture; - TAG_ITER_SECTORS(line->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) { boolean tryagain; sec = sectors + secnum; @@ -3359,7 +3360,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) // Except it is activated by linedef executor, not level load // This could even override existing colormaps I believe // -- Monster Iestyn 14/06/18 - TAG_ITER_SECTORS(line->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) { P_ResetColormapFader(§ors[secnum]); @@ -3424,7 +3425,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { CONS_Alert(CONS_WARNING, M_GetText("Skybox switch linedef (tag %d) doesn't have anything to do.\nConsider changing the linedef's flag configuration or removing it entirely.\n"), - line->tag); + tag); } else { @@ -3462,7 +3463,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { CONS_Alert(CONS_WARNING, M_GetText("Boss enable linedef (tag %d) has an invalid texture x offset.\nConsider changing it or removing it entirely.\n"), - line->tag); + tag); break; } if (line->flags & ML_NOCLIMB) @@ -3479,7 +3480,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) } case 450: // Execute Linedef Executor - for recursion - P_LinedefExecute(line->tag, mo, NULL); + P_LinedefExecute(tag, mo, NULL); break; case 451: // Execute Random Linedef Executor @@ -3687,7 +3688,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) } case 455: // Fade colormap - TAG_ITER_SECTORS(line->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) { extracolormap_t *source_exc, *dest_exc, *exc; INT32 speed = (INT32)((line->flags & ML_DONTPEGBOTTOM) || !sides[line->sidenum[0]].rowoffset) && line->sidenum[1] != 0xFFFF ? @@ -3776,7 +3777,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 456: // Stop fade colormap - TAG_ITER_SECTORS(line->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) P_ResetColormapFader(§ors[secnum]); break; @@ -3790,7 +3791,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) boolean persist = (line->flags & ML_EFFECT2); mobj_t *anchormo; - if ((secnum = Tag_Iterate_Sectors(line->tag, 0)) < 0) + if ((secnum = Tag_Iterate_Sectors(tag, 0)) < 0) return; anchormo = P_GetObjectTypeInSectorNum(MT_ANGLEMAN, secnum); @@ -3821,7 +3822,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { INT32 promptnum = max(0, (sides[line->sidenum[0]].textureoffset>>FRACBITS)-1); INT32 pagenum = max(0, (sides[line->sidenum[0]].rowoffset>>FRACBITS)-1); - INT32 postexectag = abs((line->sidenum[1] != 0xFFFF) ? sides[line->sidenum[1]].textureoffset>>FRACBITS : line->tag); + INT32 postexectag = abs((line->sidenum[1] != 0xFFFF) ? sides[line->sidenum[1]].textureoffset>>FRACBITS : tag); boolean closetextprompt = (line->flags & ML_BLOCKMONSTERS); //boolean allplayers = (line->flags & ML_NOCLIMB); @@ -4258,6 +4259,7 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers INT32 i = 0; INT32 section1, section2, section3, section4; INT32 special; + mtag_t sectag = Tag_FGet(§or->tags); section1 = GETSECSPECIAL(sector->special, 1); section2 = GETSECSPECIAL(sector->special, 2); @@ -4411,7 +4413,7 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers case 6: // Linedef executor (7 Emeralds) case 7: // Linedef executor (NiGHTS Mare) if (!player->bot) - P_LinedefExecute(sector->tag, player->mo, sector); + P_LinedefExecute(sectag, player->mo, sector); break; case 8: // Tells pushable things to check FOFs break; @@ -4440,13 +4442,16 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers sector->special = 0; // Move the button down + Tag_FSet(&junk.tags, 680); junk.tag = 680; EV_DoElevator(&junk, elevateDown, false); // Open the top FOF + Tag_FSet(&junk.tags, 681); junk.tag = 681; EV_DoFloor(&junk, raiseFloorToNearestFast); // Open the bottom FOF + Tag_FSet(&junk.tags, 682); junk.tag = 682; EV_DoCeiling(&junk, lowerToLowestFast); @@ -4482,7 +4487,7 @@ DoneSection2: if (player->powers[pw_flashing] != 0 && player->powers[pw_flashing] < TICRATE/2) break; - i = Tag_FindLineSpecial(4, sector->tag); + i = Tag_FindLineSpecial(4, sectag); if (i != -1) { @@ -4495,7 +4500,7 @@ DoneSection2: if (linespeed == 0) { - CONS_Debug(DBG_GAMELOGIC, "ERROR: Speed pad (tag %d) at zero speed.\n", sector->tag); + CONS_Debug(DBG_GAMELOGIC, "ERROR: Speed pad (tag %d) at zero speed.\n", sectag); break; } @@ -4594,7 +4599,7 @@ DoneSection2: // important: use sector->tag on next line instead of player->mo->subsector->tag // this part is different from in P_PlayerThink, this is what was causing // FOF custom exits not to work. - lineindex = Tag_FindLineSpecial(2, sector->tag); + lineindex = Tag_FindLineSpecial(2, sectag); if (gametype == GT_COOP && lineindex != -1) // Custom exit! { @@ -4719,7 +4724,7 @@ DoneSection2: break; // Find line #3 tagged to this sector - lineindex = Tag_FindLineSpecial(3, sector->tag); + lineindex = Tag_FindLineSpecial(3, sectag); if (lineindex == -1) { @@ -4801,7 +4806,7 @@ DoneSection2: break; // Find line #3 tagged to this sector - lineindex = Tag_FindLineSpecial(3, sector->tag); + lineindex = Tag_FindLineSpecial(3, sectag); if (lineindex == -1) { @@ -4948,7 +4953,7 @@ DoneSection2: memset(&resulthigh, 0x00, sizeof(resulthigh)); // Find line #11 tagged to this sector - lineindex = Tag_FindLineSpecial(11, sector->tag); + lineindex = Tag_FindLineSpecial(11, sectag); if (lineindex == -1) { @@ -7294,9 +7299,10 @@ static void P_AddFakeFloorsByLine(size_t line, ffloortype_e ffloorflags, thinker { TAG_ITER_C INT32 s; + mtag_t tag = Tag_FGet(&lines[line].tags); size_t sec = sides[*lines[line].sidenum].sector-sectors; line_t* li = lines + line; - TAG_ITER_SECTORS(li->tag, s) + TAG_ITER_SECTORS(tag, s) P_AddFakeFloor(§ors[s], §ors[sec], li, ffloorflags, secthinkers); } @@ -7443,7 +7449,7 @@ void T_Scroll(scroll_t *s) if (!is3dblock) continue; - TAG_ITER_SECTORS(line->tag, sect) + TAG_ITER_SECTORS(Tag_FGet(&line->tags), sect) { sector_t *psec; psec = sectors + sect; @@ -7518,7 +7524,7 @@ void T_Scroll(scroll_t *s) if (!is3dblock) continue; - TAG_ITER_SECTORS(line->tag, sect) + TAG_ITER_SECTORS(Tag_FGet(&line->tags), sect) { sector_t *psec; psec = sectors + sect; @@ -7616,6 +7622,7 @@ static void P_SpawnScrollers(void) { size_t i; line_t *l = lines; + mtag_t tag; for (i = 0; i < numlines; i++, l++) { @@ -7624,6 +7631,8 @@ static void P_SpawnScrollers(void) INT32 control = -1, accel = 0; // no control sector or acceleration INT32 special = l->special; + tag = Tag_FGet(&l->tags); + // These types are same as the ones they get set to except that the // first side's sector's heights cause scrolling when they change, and // this linedef controls the direction and speed of the scrolling. The @@ -7659,7 +7668,7 @@ static void P_SpawnScrollers(void) case 513: // scroll effect ceiling case 533: // scroll and carry objects on ceiling - TAG_ITER_SECTORS(l->tag, s) + TAG_ITER_SECTORS(tag, s) Add_Scroller(sc_ceiling, -dx, dy, control, s, accel, l->flags & ML_NOCLIMB); if (special != 533) break; @@ -7668,13 +7677,13 @@ static void P_SpawnScrollers(void) case 523: // carry objects on ceiling dx = FixedMul(dx, CARRYFACTOR); dy = FixedMul(dy, CARRYFACTOR); - TAG_ITER_SECTORS(l->tag, s) + TAG_ITER_SECTORS(tag, s) Add_Scroller(sc_carry_ceiling, dx, dy, control, s, accel, l->flags & ML_NOCLIMB); break; case 510: // scroll effect floor case 530: // scroll and carry objects on floor - TAG_ITER_SECTORS(l->tag, s) + TAG_ITER_SECTORS(tag, s) Add_Scroller(sc_floor, -dx, dy, control, s, accel, l->flags & ML_NOCLIMB); if (special != 530) break; @@ -7683,7 +7692,7 @@ static void P_SpawnScrollers(void) case 520: // carry objects on floor dx = FixedMul(dx, CARRYFACTOR); dy = FixedMul(dy, CARRYFACTOR); - TAG_ITER_SECTORS(l->tag, s) + TAG_ITER_SECTORS(tag, s) Add_Scroller(sc_carry, dx, dy, control, s, accel, l->flags & ML_NOCLIMB); break; @@ -7691,7 +7700,7 @@ static void P_SpawnScrollers(void) // (same direction and speed as scrolling floors) case 502: { - TAG_ITER_LINES(l->tag, s) + TAG_ITER_LINES(tag, s) if (s != (INT32)i) Add_Scroller(sc_side, dx, dy, control, lines[s].sidenum[0], accel, 0); break; @@ -7761,9 +7770,10 @@ void T_Disappear(disappear_t *d) { ffloor_t *rover; register INT32 s; + mtag_t afftag = Tag_FGet(&lines[d->affectee].tags); TAG_ITER_C - TAG_ITER_SECTORS(lines[d->affectee].tag, s) + TAG_ITER_SECTORS(afftag, s) { for (rover = sectors[s].ffloors; rover; rover = rover->next) { @@ -8492,6 +8502,7 @@ static void P_SpawnFriction(void) { size_t i; line_t *l = lines; + mtag_t tag; register INT32 s; fixed_t strength; // frontside texture offset controls magnitude fixed_t friction; // friction value to be applied during movement @@ -8501,6 +8512,7 @@ static void P_SpawnFriction(void) for (i = 0; i < numlines; i++, l++) if (l->special == 540) { + tag = Tag_FGet(&l->tags); strength = sides[l->sidenum[0]].textureoffset>>FRACBITS; if (strength > 0) // sludge strength = strength*2; // otherwise, the maximum sludginess value is +967... @@ -8521,7 +8533,7 @@ static void P_SpawnFriction(void) else movefactor = FRACUNIT; - TAG_ITER_SECTORS(l->tag, s) + TAG_ITER_SECTORS(tag, s) Add_Friction(friction, movefactor, s, -1); } } @@ -9049,23 +9061,26 @@ static void P_SpawnPushers(void) { size_t i; line_t *l = lines; + mtag_t tag; register INT32 s; mobj_t *thing; TAG_ITER_C for (i = 0; i < numlines; i++, l++) + { + tag = Tag_FGet(&l->tags); switch (l->special) { case 541: // wind - TAG_ITER_SECTORS(l->tag, s) + TAG_ITER_SECTORS(tag, s) Add_Pusher(p_wind, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; case 544: // current - TAG_ITER_SECTORS(l->tag, s) + TAG_ITER_SECTORS(tag, s) Add_Pusher(p_current, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; case 547: // push/pull - TAG_ITER_SECTORS(l->tag, s) + TAG_ITER_SECTORS(tag, s) { thing = P_GetPushThing(s); if (thing) // No MT_P* means no effect @@ -9073,20 +9088,21 @@ static void P_SpawnPushers(void) } break; case 545: // current up - TAG_ITER_SECTORS(l->tag, s) + TAG_ITER_SECTORS(tag, s) Add_Pusher(p_upcurrent, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; case 546: // current down - TAG_ITER_SECTORS(l->tag, s) + TAG_ITER_SECTORS(tag, s) Add_Pusher(p_downcurrent, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; case 542: // wind up - TAG_ITER_SECTORS(l->tag, s) + TAG_ITER_SECTORS(tag, s) Add_Pusher(p_upwind, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; case 543: // wind down - TAG_ITER_SECTORS(l->tag, s) + TAG_ITER_SECTORS(tag, s) Add_Pusher(p_downwind, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; } + } } diff --git a/src/p_user.c b/src/p_user.c index c2f122ace..9fea83ec2 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -10629,6 +10629,7 @@ static void P_CalcPostImg(player_t *player) postimg_t *type; INT32 *param; fixed_t pviewheight; + size_t i; if (player->mo->eflags & MFE_VERTICALFLIP) pviewheight = player->mo->z + player->mo->height - player->viewheight; @@ -10653,28 +10654,45 @@ static void P_CalcPostImg(player_t *player) } // see if we are in heat (no, not THAT kind of heat...) - - if (Tag_FindLineSpecial(13, sector->tag) != -1) - *type = postimg_heat; - else if (sector->ffloors) + for (i = 0; i < sector->tags.count; i++) { - ffloor_t *rover; - fixed_t topheight; - fixed_t bottomheight; - - for (rover = sector->ffloors; rover; rover = rover->next) + if (Tag_FindLineSpecial(13, sector->tags.tags[i]) != -1) { - if (!(rover->flags & FF_EXISTS)) - continue; + *type = postimg_heat; + break; + } + else if (sector->ffloors) + { + ffloor_t *rover; + fixed_t topheight; + fixed_t bottomheight; + boolean gotres = false; - topheight = *rover->t_slope ? P_GetZAt(*rover->t_slope, player->mo->x, player->mo->y) : *rover->topheight; - bottomheight = *rover->b_slope ? P_GetZAt(*rover->b_slope, player->mo->x, player->mo->y) : *rover->bottomheight; + for (rover = sector->ffloors; rover; rover = rover->next) + { + size_t j; - if (pviewheight >= topheight || pviewheight <= bottomheight) - continue; + if (!(rover->flags & FF_EXISTS)) + continue; - if (Tag_FindLineSpecial(13, rover->master->frontsector->tag) != -1) - *type = postimg_heat; + topheight = *rover->t_slope ? P_GetZAt(*rover->t_slope, player->mo->x, player->mo->y) : *rover->topheight; + bottomheight = *rover->b_slope ? P_GetZAt(*rover->b_slope, player->mo->x, player->mo->y) : *rover->bottomheight; + + if (pviewheight >= topheight || pviewheight <= bottomheight) + continue; + + for (j = 0; j < rover->master->frontsector->tags.count; j++) + { + if (Tag_FindLineSpecial(13, rover->master->frontsector->tags.tags[j]) != -1) + { + *type = postimg_heat; + gotres = true; + break; + } + } + } + if (gotres) + break; } } @@ -10773,22 +10791,21 @@ static sector_t *P_GetMinecartSector(fixed_t x, fixed_t y, fixed_t z, fixed_t *n static INT32 P_GetMinecartSpecialLine(sector_t *sec) { INT32 line = -1; + size_t i; if (!sec) return line; - if (sec->tag != 0) - line = Tag_FindLineSpecial(16, sec->tag); + for (i = 0; i < sec->tags.count; i++) + if (sec->tags.tags[i] != 0) + line = Tag_FindLineSpecial(16, sec->tags.tags[i]); // Also try for lines facing the sector itself, with tag 0. + for (i = 0; i < sec->linecount; i++) { - UINT32 i; - for (i = 0; i < sec->linecount; i++) - { - line_t *li = sec->lines[i]; - if (li->tag == 0 && li->special == 16 && li->frontsector == sec) - line = li - lines; - } + line_t *li = sec->lines[i]; + if (Tag_Find(&li->tags, 0) && li->special == 16 && li->frontsector == sec) + line = li - lines; } return line; From 7904856e8e595692d0b5a1cf366b662277b056f5 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 22:26:04 +0200 Subject: [PATCH 41/75] Remove presumably the remaining old tag references in the gamelogic. --- src/p_ceilng.c | 10 ++++++---- src/p_enemy.c | 5 +++++ src/p_floor.c | 47 +++++++++++++++++++++++++++++------------------ src/p_inter.c | 1 + src/p_mobj.c | 10 +++++++--- src/p_spec.c | 48 ++++++++++++++++++++++++------------------------ 6 files changed, 72 insertions(+), 49 deletions(-) diff --git a/src/p_ceilng.c b/src/p_ceilng.c index a6e8e8cda..e80859189 100644 --- a/src/p_ceilng.c +++ b/src/p_ceilng.c @@ -398,9 +398,10 @@ INT32 EV_DoCeiling(line_t *line, ceiling_e type) INT32 secnum = -1; sector_t *sec; ceiling_t *ceiling; + mtag_t tag = Tag_FGet(&line->tags); TAG_ITER_C - TAG_ITER_SECTORS(line->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) { sec = §ors[secnum]; @@ -598,7 +599,7 @@ INT32 EV_DoCeiling(line_t *line, ceiling_e type) } - ceiling->tag = sec->tag; + ceiling->tag = tag; ceiling->type = type; firstone = 0; } @@ -619,9 +620,10 @@ INT32 EV_DoCrush(line_t *line, ceiling_e type) INT32 secnum = -1; sector_t *sec; ceiling_t *ceiling; + mtag_t tag = Tag_FGet(&line->tags); TAG_ITER_C - TAG_ITER_SECTORS(line->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) { sec = §ors[secnum]; @@ -676,7 +678,7 @@ INT32 EV_DoCrush(line_t *line, ceiling_e type) break; } - ceiling->tag = sec->tag; + ceiling->tag = tag; ceiling->type = type; } return rtn; diff --git a/src/p_enemy.c b/src/p_enemy.c index 8f96c1dee..a51d76cb0 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -3865,11 +3865,15 @@ void A_BossDeath(mobj_t *mo) else { // Bring the egg trap up to the surface + // Incredibly shitty code ahead junk.tag = LE_CAPSULE0; + Tag_FSet(&junk.tags, LE_CAPSULE0); EV_DoElevator(&junk, elevateHighest, false); junk.tag = LE_CAPSULE1; + Tag_FSet(&junk.tags, LE_CAPSULE1); EV_DoElevator(&junk, elevateUp, false); junk.tag = LE_CAPSULE2; + Tag_FSet(&junk.tags, LE_CAPSULE2); EV_DoElevator(&junk, elevateHighest, false); if (mapheaderinfo[gamemap-1]->muspostbossname[0] && @@ -3993,6 +3997,7 @@ bossjustdie: case MT_KOOPA: { junk.tag = LE_KOOPA; + Tag_FSet(&junk.tags, LE_KOOPA); EV_DoCeiling(&junk, raiseToHighest); return; } diff --git a/src/p_floor.c b/src/p_floor.c index bcb546a5c..91c264435 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -687,6 +687,7 @@ void T_BounceCheese(levelspecthink_t *bouncer) fixed_t floorheight; sector_t *actionsector; INT32 i; + mtag_t tag = Tag_FGet(&bouncer->sourceline->tags); TAG_ITER_C if (bouncer->sector->crumblestate == 4 || bouncer->sector->crumblestate == 1 @@ -702,7 +703,7 @@ void T_BounceCheese(levelspecthink_t *bouncer) } // You can use multiple target sectors, but at your own risk!!! - TAG_ITER_SECTORS(bouncer->sourceline->tag, i) + TAG_ITER_SECTORS(tag, i) { actionsector = §ors[i]; actionsector->moved = true; @@ -845,6 +846,7 @@ void T_StartCrumble(elevator_t *elevator) ffloor_t *rover; sector_t *sector; INT32 i; + mtag_t tag = Tag_FGet(&elevator->sourceline->tags); TAG_ITER_C // Once done, the no-return thinker just sits there, @@ -875,7 +877,7 @@ void T_StartCrumble(elevator_t *elevator) } else if (++elevator->distance == 0) // Reposition back to original spot { - TAG_ITER_SECTORS(elevator->sourceline->tag, i) + TAG_ITER_SECTORS(tag, i) { sector = §ors[i]; @@ -906,7 +908,7 @@ void T_StartCrumble(elevator_t *elevator) // Flash to indicate that the platform is about to return. if (elevator->distance > -224 && (leveltime % ((abs(elevator->distance)/8) + 1) == 0)) { - TAG_ITER_SECTORS(elevator->sourceline->tag, i) + TAG_ITER_SECTORS(tag, i) { sector = §ors[i]; @@ -1002,7 +1004,7 @@ void T_StartCrumble(elevator_t *elevator) P_RemoveThinker(&elevator->thinker); } - TAG_ITER_SECTORS(elevator->sourceline->tag, i) + TAG_ITER_SECTORS(tag, i) { sector = §ors[i]; sector->moved = true; @@ -1456,9 +1458,10 @@ void T_NoEnemiesSector(levelspecthink_t *nobaddies) msecnode_t *node; mobj_t *thing; boolean FOFsector = false; + mtag_t tag = Tag_FGet(&nobaddies->sourceline->tags); TAG_ITER_C - TAG_ITER_SECTORS(nobaddies->sourceline->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) { sec = §ors[secnum]; @@ -1468,6 +1471,7 @@ void T_NoEnemiesSector(levelspecthink_t *nobaddies) for (i = 0; i < sec->linecount; i++) { INT32 targetsecnum = -1; + mtag_t tag2 = Tag_FGet(&sec->lines[i]->tags); TAG_ITER_C if (sec->lines[i]->special < 100 || sec->lines[i]->special >= 300) @@ -1475,7 +1479,7 @@ void T_NoEnemiesSector(levelspecthink_t *nobaddies) FOFsector = true; - TAG_ITER_SECTORS(sec->lines[i]->tag, targetsecnum) + TAG_ITER_SECTORS(tag2, targetsecnum) { targetsec = §ors[targetsecnum]; @@ -1513,7 +1517,7 @@ void T_NoEnemiesSector(levelspecthink_t *nobaddies) } } - CONS_Debug(DBG_GAMELOGIC, "Running no-more-enemies exec with tag of %d\n", nobaddies->sourceline->tag); + CONS_Debug(DBG_GAMELOGIC, "Running no-more-enemies exec with tag of %d\n", tag); // No enemies found, run the linedef exec and terminate this thinker P_RunTriggerLinedef(nobaddies->sourceline, NULL, NULL); @@ -1601,6 +1605,7 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) fixed_t bottomheight, topheight; msecnode_t *node; ffloor_t *rover; + mtag_t tag = Tag_FGet(&eachtime->sourceline->tags); TAG_ITER_C for (i = 0; i < MAXPLAYERS; i++) @@ -1622,7 +1627,7 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) playersOnArea[i] = false; } - TAG_ITER_SECTORS(eachtime->sourceline->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) { sec = §ors[secnum]; @@ -1639,6 +1644,7 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) for (i = 0; i < sec->linecount; i++) { INT32 targetsecnum = -1; + mtag_t tag2 = Tag_FGet(&sec->lines[i]->tags); TAG_ITER_C if (sec->lines[i]->special < 100 || sec->lines[i]->special >= 300) @@ -1646,7 +1652,7 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) FOFsector = true; - TAG_ITER_SECTORS(sec->lines[i]->tag, targetsecnum) + TAG_ITER_SECTORS(tag2, targetsecnum) { targetsec = §ors[targetsecnum]; @@ -1828,7 +1834,7 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) } } - CONS_Debug(DBG_GAMELOGIC, "Trying to activate each time executor with tag %d\n", eachtime->sourceline->tag); + CONS_Debug(DBG_GAMELOGIC, "Trying to activate each time executor with tag %d\n", tag); // 03/08/14 -Monster Iestyn // No more stupid hacks involving changing eachtime->sourceline's tag or special or whatever! @@ -1858,12 +1864,13 @@ void T_RaiseSector(levelspecthink_t *raise) boolean playeronme = false, active = false; fixed_t ceilingdestination, floordestination; result_e res = 0; + mtag_t tag = Tag_FGet(&raise->sourceline->tags); TAG_ITER_C if (raise->sector->crumblestate >= 3 || raise->sector->ceilingdata) return; - TAG_ITER_SECTORS(raise->sourceline->tag, i) + TAG_ITER_SECTORS(tag, i) { sector = §ors[i]; @@ -2056,7 +2063,7 @@ void T_RaiseSector(levelspecthink_t *raise) raise->sector->ceilspeed = 42; raise->sector->floorspeed = raise->vars[3]*raise->vars[8]; - TAG_ITER_SECTORS(raise->sourceline->tag, i) + TAG_ITER_SECTORS(tag, i) P_RecalcPrecipInSector(§ors[i]); } @@ -2173,9 +2180,10 @@ INT32 EV_DoFloor(line_t *line, floor_e floortype) INT32 secnum = -1; sector_t *sec; floormove_t *dofloor; + mtag_t tag = Tag_FGet(&line->tags); TAG_ITER_C - TAG_ITER_SECTORS(line->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) { sec = §ors[secnum]; @@ -2393,10 +2401,11 @@ INT32 EV_DoElevator(line_t *line, elevator_e elevtype, boolean customspeed) INT32 rtn = 0; sector_t *sec; elevator_t *elevator; + mtag_t tag = Tag_FGet(&line->tags); TAG_ITER_C // act on all sectors with the same tag as the triggering linedef - TAG_ITER_SECTORS(line->tag, secnum) + TAG_ITER_SECTORS(tag, secnum) { sec = §ors[secnum]; @@ -2519,6 +2528,7 @@ void EV_CrumbleChain(sector_t *sec, ffloor_t *rover) INT16 flags; sector_t *controlsec = rover->master->frontsector; + mtag_t tag = Tag_FGet(&controlsec->tags); if (sec == NULL) { @@ -2547,9 +2557,9 @@ void EV_CrumbleChain(sector_t *sec, ffloor_t *rover) lifetime = 3*TICRATE; flags = 0; - if (controlsec->tag != 0) + if (tag != 0) { - INT32 tagline = Tag_FindLineSpecial(14, controlsec->tag); + INT32 tagline = Tag_FindLineSpecial(14, tag); if (tagline != -1) { if (sides[lines[tagline].sidenum[0]].toptexture) @@ -2725,6 +2735,7 @@ INT32 EV_StartCrumble(sector_t *sec, ffloor_t *rover, boolean floating, elevator_t *elevator; sector_t *foundsec; INT32 i; + mtag_t tag = Tag_FGet(&rover->master->tags); TAG_ITER_C // If floor is already activated, skip it @@ -2778,7 +2789,7 @@ INT32 EV_StartCrumble(sector_t *sec, ffloor_t *rover, boolean floating, elevator->sector->crumblestate = 2; - TAG_ITER_SECTORS(elevator->sourceline->tag, i) + TAG_ITER_SECTORS(tag, i) { foundsec = §ors[i]; @@ -2822,7 +2833,7 @@ INT32 EV_MarioBlock(ffloor_t *rover, sector_t *sector, mobj_t *puncher) // Set up the fields block->sector = roversec; - block->vars[0] = sector->tag; // actionsector + block->vars[0] = Tag_FGet(§or->tags); // actionsector block->vars[1] = 4*FRACUNIT; // speed block->vars[2] = 1; // Up // direction block->vars[3] = block->sector->floorheight; // floorwasheight diff --git a/src/p_inter.c b/src/p_inter.c index 30e3c31b1..0cdbe57b2 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -1377,6 +1377,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) return; junk.tag = LE_AXE; + Tag_FSet(&junk.tags, LE_AXE); EV_DoElevator(&junk, bridgeFall, false); // scan the remaining thinkers to find koopa diff --git a/src/p_mobj.c b/src/p_mobj.c index a65d3bbf3..180376727 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3548,16 +3548,19 @@ static boolean P_CameraCheckHeat(camera_t *thiscam) { sector_t *sector; fixed_t halfheight = thiscam->z + (thiscam->height >> 1); + size_t i; // see if we are in water sector = thiscam->subsector->sector; - if (Tag_FindLineSpecial(13, sector->tag) != -1) - return true; + for (i = 0; i < sector->tags.count; i++) + if (Tag_FindLineSpecial(13, sector->tags.tags[i]) != -1) + return true; if (sector->ffloors) { ffloor_t *rover; + size_t j; for (rover = sector->ffloors; rover; rover = rover->next) { @@ -3573,7 +3576,8 @@ static boolean P_CameraCheckHeat(camera_t *thiscam) *rover->bottomheight)) continue; - if (Tag_FindLineSpecial(13, rover->master->frontsector->tag) != -1) + for (j = 0; j < rover->master->frontsector->tags.count; j++) + if (Tag_FindLineSpecial(13, rover->master->frontsector->tags.tags[j]) != -1) return true; } } diff --git a/src/p_spec.c b/src/p_spec.c index 6c47e24c1..a0c46f3ac 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1000,7 +1000,7 @@ static boolean PolyDoor(line_t *line) { polydoordata_t pdd; - pdd.polyObjNum = line->tag; // polyobject id + pdd.polyObjNum = Tag_FGet(&line->tags); // polyobject id switch(line->special) { @@ -1041,7 +1041,7 @@ static boolean PolyMove(line_t *line) { polymovedata_t pmd; - pmd.polyObjNum = line->tag; + pmd.polyObjNum = Tag_FGet(&line->tags); pmd.speed = sides[line->sidenum[0]].textureoffset / 8; pmd.angle = R_PointToAngle2(line->v1->x, line->v1->y, line->v2->x, line->v2->y); pmd.distance = sides[line->sidenum[0]].rowoffset; @@ -1059,7 +1059,7 @@ static boolean PolyMove(line_t *line) // static void PolyInvisible(line_t *line) { - INT32 polyObjNum = line->tag; + INT32 polyObjNum = Tag_FGet(&line->tags); polyobj_t *po; if (!(po = Polyobj_GetForNum(polyObjNum))) @@ -1087,7 +1087,7 @@ static void PolyInvisible(line_t *line) // static void PolyVisible(line_t *line) { - INT32 polyObjNum = line->tag; + INT32 polyObjNum = Tag_FGet(&line->tags); polyobj_t *po; if (!(po = Polyobj_GetForNum(polyObjNum))) @@ -1115,7 +1115,7 @@ static void PolyVisible(line_t *line) // static void PolyTranslucency(line_t *line) { - INT32 polyObjNum = line->tag; + INT32 polyObjNum = Tag_FGet(&line->tags); polyobj_t *po; if (!(po = Polyobj_GetForNum(polyObjNum))) @@ -1156,7 +1156,7 @@ static void PolyTranslucency(line_t *line) // static boolean PolyFade(line_t *line) { - INT32 polyObjNum = line->tag; + INT32 polyObjNum = Tag_FGet(&line->tags); polyobj_t *po; polyfadedata_t pfd; @@ -1227,7 +1227,7 @@ static boolean PolyWaypoint(line_t *line) { polywaypointdata_t pwd; - pwd.polyObjNum = line->tag; + pwd.polyObjNum = Tag_FGet(&line->tags); pwd.speed = sides[line->sidenum[0]].textureoffset / 8; pwd.sequence = sides[line->sidenum[0]].rowoffset >> FRACBITS; // Sequence # pwd.reverse = (line->flags & ML_EFFECT1) == ML_EFFECT1; // Reverse? @@ -1247,7 +1247,7 @@ static boolean PolyRotate(line_t *line) { polyrotdata_t prd; - prd.polyObjNum = line->tag; + prd.polyObjNum = Tag_FGet(&line->tags); prd.speed = sides[line->sidenum[0]].textureoffset >> FRACBITS; // angular speed prd.distance = sides[line->sidenum[0]].rowoffset >> FRACBITS; // angular distance @@ -1276,7 +1276,7 @@ static boolean PolyDisplace(line_t *line) { polydisplacedata_t pdd; - pdd.polyObjNum = line->tag; + pdd.polyObjNum = Tag_FGet(&line->tags); pdd.controlSector = line->frontsector; pdd.dx = line->dx>>8; @@ -1293,7 +1293,7 @@ static boolean PolyRotDisplace(line_t *line) polyrotdisplacedata_t pdd; fixed_t anginter, distinter; - pdd.polyObjNum = line->tag; + pdd.polyObjNum = Tag_FGet(&line->tags); pdd.controlSector = line->frontsector; // Rotate 'anginter' interval for each 'distinter' interval from the control sector. @@ -2412,12 +2412,12 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) // (formerly "Change calling sectors' tag", but behavior was changed) { TAG_ITER_SECTORS(tag, secnum) - P_ChangeSectorTag(secnum,(INT16)(sides[line->sidenum[0]].textureoffset>>FRACBITS)); + Tag_SectorFSet(secnum,(INT16)(sides[line->sidenum[0]].textureoffset>>FRACBITS)); break; } case 410: // Change front sector's tag - P_ChangeSectorTag((UINT32)(line->frontsector - sectors), (INT16)(sides[line->sidenum[0]].textureoffset>>FRACBITS)); + Tag_SectorFSet((UINT32)(line->frontsector - sectors), (INT16)(sides[line->sidenum[0]].textureoffset>>FRACBITS)); break; case 411: // Stop floor/ceiling movement in tagged sector(s) @@ -2626,7 +2626,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (!camobj) continue; - if (foundit || (camobj->subsector->sector->tag == tag)) + if (foundit || Tag_Find(&camobj->subsector->sector->tags, tag)) { foundit = true; break; @@ -2635,7 +2635,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) // Only trigger if mobj is touching the tag for(rover = camobj->subsector->sector->ffloors; rover; rover = rover->next) { - if (rover->master->frontsector->tag != tag) + if (!Tag_Find(&rover->master->frontsector->tags, tag)) continue; if (camobj->z > P_GetSpecialTopZ(camobj, sectors + rover->secnum, camobj->subsector->sector)) @@ -3092,7 +3092,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) for (rover = sec->ffloors; rover; rover = rover->next) { - if (rover->master->frontsector->tag == foftag) + if (Tag_Find(&rover->master->frontsector->tags, foftag)) { foundrover = true; @@ -3277,7 +3277,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) for (rover = sec->ffloors; rover; rover = rover->next) { - if (rover->master->frontsector->tag == foftag) + if (Tag_Find(&rover->master->frontsector->tags, foftag)) { foundrover = true; @@ -3335,7 +3335,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) for (rover = sec->ffloors; rover; rover = rover->next) { - if (rover->master->frontsector->tag == foftag) + if (Tag_Find(&rover->master->frontsector->tags, foftag)) { foundrover = true; @@ -3520,7 +3520,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) for (rover = sec->ffloors; rover; rover = rover->next) { - if (rover->master->frontsector->tag == foftag) + if (Tag_Find(&rover->master->frontsector->tags, foftag)) { foundrover = true; @@ -3584,7 +3584,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) for (rover = sec->ffloors; rover; rover = rover->next) { - if (rover->master->frontsector->tag == foftag) + if (Tag_Find(&rover->master->frontsector->tags, foftag)) { foundrover = true; @@ -3669,7 +3669,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) for (rover = sec->ffloors; rover; rover = rover->next) { - if (rover->master->frontsector->tag == foftag) + if (Tag_Find(&rover->master->frontsector->tags, foftag)) { foundrover = true; @@ -5774,7 +5774,7 @@ static ffloor_t *P_AddFakeFloor(sector_t *sec, sector_t *sec2, line_t *master, f if ((flags & FF_FLOATBOB)) { - P_AddFloatThinker(sec2, sec->tag, master); + P_AddFloatThinker(sec2, Tag_FGet(&master->tags), master); CheckForFloatBob = true; } @@ -6011,7 +6011,7 @@ static inline void P_AddThwompThinker(sector_t *sec, sector_t *actionsector, lin // set up the fields according to the type of elevator action thwomp->sector = sec; - thwomp->vars[0] = actionsector->tag; + thwomp->vars[0] = Tag_FGet(&sourceline->tags); thwomp->floorwasheight = thwomp->sector->floorheight; thwomp->ceilingwasheight = thwomp->sector->ceilingheight; thwomp->direction = 0; @@ -6572,11 +6572,11 @@ void P_SpawnSpecials(boolean fromnetsave) Add_MasterDisappearer(abs(lines[i].dx>>FRACBITS), abs(lines[i].dy>>FRACBITS), abs(sides[lines[i].sidenum[0]].sector->floorheight>>FRACBITS), (INT32)(sectors[s].lines[j]-lines), (INT32)i); } else // Find FOFs by effect sector tag { - TAG_ITER_LINES((lines + i)->tag, s) + TAG_ITER_LINES(tag, s) { if ((size_t)s == i) continue; - if (sides[lines[s].sidenum[0]].sector->tag == sides[lines[i].sidenum[0]].sector->tag) + if (Tag_Find(&sides[lines[s].sidenum[0]].sector->tags, Tag_FGet(&sides[lines[i].sidenum[0]].sector->tags))) Add_MasterDisappearer(abs(lines[i].dx>>FRACBITS), abs(lines[i].dy>>FRACBITS), abs(sides[lines[i].sidenum[0]].sector->floorheight>>FRACBITS), s, (INT32)i); } } From ae07b7c96c92c15fa5658011024f96e59d046d66 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 22:29:26 +0200 Subject: [PATCH 42/75] Netsynch the sector local taglists. --- src/p_saveg.c | 24 ++++++++++++++++++++---- src/p_setup.c | 11 ++++++++--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index 4449a9d2b..ebdc251e6 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -798,7 +798,7 @@ static boolean P_AreStringArgsEqual(const line_t *li, const line_t *spawnli) // static void P_NetArchiveWorld(void) { - size_t i; + size_t i, j; INT32 statsec = 0, statline = 0; const line_t *li = lines; const line_t *spawnli = spawnlines; @@ -849,7 +849,7 @@ static void P_NetArchiveWorld(void) if (ss->ceilingpic_angle != spawnss->ceilingpic_angle) diff2 |= SD_CEILANG; - if (ss->tag != spawnss->tag) + if (!Tag_Compare(&ss->tags, &spawnss->tags)) diff2 |= SD_TAG; if (ss->nexttag != spawnss->nexttag || ss->firsttag != spawnss->firsttag) diff3 |= SD_TAGLIST; @@ -912,7 +912,12 @@ static void P_NetArchiveWorld(void) WRITEANGLE(put, ss->floorpic_angle); if (diff2 & SD_CEILANG) WRITEANGLE(put, ss->ceilingpic_angle); - if (diff2 & SD_TAG) // save only the tag + if (diff2 & SD_TAG) + { + WRITEUINT32(put, ss->tags.count); + for (j = 0; j < ss->tags.count; j++) + WRITEINT16(put, ss->tags.tags[j]); + } WRITEINT16(put, ss->tag); if (diff3 & SD_TAGLIST) // save both firsttag and nexttag { // either of these could be changed even if tag isn't @@ -1076,7 +1081,7 @@ static void P_NetArchiveWorld(void) // static void P_NetUnArchiveWorld(void) { - UINT16 i; + UINT16 i, j; line_t *li; side_t *si; UINT8 *get; @@ -1150,6 +1155,17 @@ static void P_NetUnArchiveWorld(void) if (diff2 & SD_CEILANG) sectors[i].ceilingpic_angle = READANGLE(get); if (diff2 & SD_TAG) + { + size_t ncount = READUINT32(get); + if (ncount != sectors[i].tags.count) + { + sectors[i].tags.count = ncount; + sectors[i].tags.tags = Z_Realloc(sectors[i].tags.tags, ncount*sizeof(mtag_t), PU_LEVEL, NULL); + } + + for (j = 0; j < ncount; j++) + sectors[i].tags.tags[j] = READINT16(get); + } sectors[i].tag = READINT16(get); // DON'T use P_ChangeSectorTag if (diff3 & SD_TAGLIST) { diff --git a/src/p_setup.c b/src/p_setup.c index 2cbc2ceae..d92eb929c 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -936,7 +936,7 @@ static void P_LoadSectors(UINT8 *data) ss->lightlevel = SHORT(ms->lightlevel); ss->special = SHORT(ms->special); ss->tag = SHORT(ms->tag); - Tag_FSet(&ss->tags, ss->tag); + Tag_FSet(&ss->tags, SHORT(ms->tag)); ss->floor_xoffs = ss->floor_yoffs = 0; ss->ceiling_xoffs = ss->ceiling_yoffs = 0; @@ -1051,7 +1051,7 @@ static void P_LoadLinedefs(UINT8 *data) ld->flags = SHORT(mld->flags); ld->special = SHORT(mld->special); ld->tag = SHORT(mld->tag); - Tag_FSet(&ld->tags, ld->tag); + Tag_FSet(&ld->tags, SHORT(mld->tag)); memset(ld->args, 0, NUMLINEARGS*sizeof(*ld->args)); memset(ld->stringargs, 0x00, NUMLINESTRINGARGS*sizeof(*ld->stringargs)); ld->alpha = FRACUNIT; @@ -1282,7 +1282,7 @@ static void P_LoadThings(UINT8 *data) mt->options = READUINT16(data); mt->extrainfo = (UINT8)(mt->type >> 12); mt->tag = 0; - Tag_FSet(&mt->tags, mt->tag); + Tag_FSet(&mt->tags, 0); mt->type &= 4095; @@ -2921,6 +2921,7 @@ static boolean P_LoadMapFromFile(void) { virtres_t *virt = vres_GetMap(lastloadedmaplumpnum); virtlump_t *textmap = vres_Find(virt, "TEXTMAP"); + size_t i; udmf = textmap != NULL; if (!P_LoadMapData(virt)) @@ -2942,6 +2943,10 @@ static boolean P_LoadMapFromFile(void) memcpy(spawnlines, lines, numlines * sizeof(*lines)); memcpy(spawnsides, sides, numsides * sizeof(*sides)); + for (i = 0; i < numsectors; i++) + if (sectors[i].tags.count) + spawnsectors[i].tags.tags = memcpy(Z_Malloc(sectors[i].tags.count*sizeof(mtag_t), PU_LEVEL, NULL), sectors[i].tags.tags, sectors[i].tags.count*sizeof(mtag_t)); + P_MakeMapMD5(virt, &mapmd5); vres_Free(virt); From 6c12e6701dc9ad8e0aaf0bdd19d3c079670cefd5 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 22:30:16 +0200 Subject: [PATCH 43/75] Make the Lua interface return/set the first tags from the local taglists. --- src/lua_maplib.c | 6 +++--- src/lua_mobjlib.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index a3bdd9aa8..a6b45e406 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -537,7 +537,7 @@ static int sector_get(lua_State *L) lua_pushinteger(L, sector->special); return 1; case sector_tag: - lua_pushinteger(L, sector->tag); + lua_pushinteger(L, Tag_FGet(§or->tags)); return 1; case sector_thinglist: // thinglist lua_pushcfunction(L, lib_iterateSectorThinglist); @@ -636,7 +636,7 @@ static int sector_set(lua_State *L) sector->special = (INT16)luaL_checkinteger(L, 3); break; case sector_tag: - P_ChangeSectorTag((UINT32)(sector - sectors), (INT16)luaL_checkinteger(L, 3)); + Tag_SectorFSet((UINT32)(sector - sectors), (INT16)luaL_checkinteger(L, 3)); break; } return 0; @@ -770,7 +770,7 @@ static int line_get(lua_State *L) lua_pushinteger(L, line->special); return 1; case line_tag: - lua_pushinteger(L, line->tag); + lua_pushinteger(L, Tag_FGet(&line->tags)); return 1; case line_args: LUA_PushUserdata(L, line->args, META_LINEARGS); diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 8d2aad91e..127ba607c 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -780,7 +780,7 @@ static int mapthing_get(lua_State *L) else if(fastcmp(field,"extrainfo")) number = mt->extrainfo; else if(fastcmp(field,"tag")) - number = mt->tag; + number = Tag_FGet(&mt->tags); else if(fastcmp(field,"mobj")) { LUA_PushUserdata(L, mt->mobj, META_MOBJ); return 1; @@ -824,7 +824,7 @@ static int mapthing_set(lua_State *L) mt->extrainfo = (UINT8)extrainfo; } else if (fastcmp(field,"tag")) - mt->tag = (INT16)luaL_checkinteger(L, 3); + Tag_FSet(&mt->tags, (INT16)luaL_checkinteger(L, 3)); else if(fastcmp(field,"mobj")) mt->mobj = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ)); else From 0c2fb80ec90154cf490e845397e1bc34e0b1bc39 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 22:41:04 +0200 Subject: [PATCH 44/75] Fuck. --- src/p_saveg.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index ebdc251e6..8e3a4b037 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -918,7 +918,6 @@ static void P_NetArchiveWorld(void) for (j = 0; j < ss->tags.count; j++) WRITEINT16(put, ss->tags.tags[j]); } - WRITEINT16(put, ss->tag); if (diff3 & SD_TAGLIST) // save both firsttag and nexttag { // either of these could be changed even if tag isn't WRITEINT32(put, ss->firsttag); From e2a98a15911d3d5ccde49b1bbafd1c1c734da0de Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 23:02:16 +0200 Subject: [PATCH 45/75] Double fuck. --- src/p_saveg.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index 8e3a4b037..e5241ec8a 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1165,7 +1165,6 @@ static void P_NetUnArchiveWorld(void) for (j = 0; j < ncount; j++) sectors[i].tags.tags[j] = READINT16(get); } - sectors[i].tag = READINT16(get); // DON'T use P_ChangeSectorTag if (diff3 & SD_TAGLIST) { sectors[i].firsttag = READINT32(get); From 9eb17e4104237b15b095d81eabb0455a0f1ad917 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 23:30:07 +0200 Subject: [PATCH 46/75] Remove P_ChangeSectorTag(). --- src/p_spec.c | 61 ---------------------------------------------------- src/p_spec.h | 1 - 2 files changed, 62 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index a0c46f3ac..5f5510372 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1315,67 +1315,6 @@ static boolean PolyRotDisplace(line_t *line) #endif // ifdef POLYOBJECTS -/** Changes a sector's tag. - * Used by the linedef executor tag changer and by crumblers. - * - * \param sector Sector whose tag will be changed. - * \param newtag New tag number for this sector. - * \sa P_InitTagLists, P_FindSectorFromTag - * \author Graue - */ -void P_ChangeSectorTag(UINT32 sector, INT16 newtag) -{ - INT16 oldtag; - INT32 i; - - I_Assert(sector < numsectors); - - if ((oldtag = sectors[sector].tag) == newtag) - return; - - // first you have to remove it from the old tag's taglist - i = sectors[(unsigned)oldtag % numsectors].firsttag; - - if (i == -1) // shouldn't happen - I_Error("Corrupt tag list for sector %u\n", sector); - else if ((UINT32)i == sector) - sectors[(unsigned)oldtag % numsectors].firsttag = sectors[sector].nexttag; - else - { - while (sectors[i].nexttag != -1 && (UINT32)sectors[i].nexttag < sector ) - i = sectors[i].nexttag; - - sectors[i].nexttag = sectors[sector].nexttag; - } - - sectors[sector].tag = newtag; - - // now add it to the new tag's taglist - if ((UINT32)sectors[(unsigned)newtag % numsectors].firsttag > sector) - { - sectors[sector].nexttag = sectors[(unsigned)newtag % numsectors].firsttag; - sectors[(unsigned)newtag % numsectors].firsttag = sector; - } - else - { - i = sectors[(unsigned)newtag % numsectors].firsttag; - - if (i == -1) - { - sectors[(unsigned)newtag % numsectors].firsttag = sector; - sectors[sector].nexttag = -1; - } - else - { - while (sectors[i].nexttag != -1 && (UINT32)sectors[i].nexttag < sector ) - i = sectors[i].nexttag; - - sectors[sector].nexttag = sectors[i].nexttag; - sectors[i].nexttag = sector; - } - } -} - // // P_RunNightserizeExecutors // diff --git a/src/p_spec.h b/src/p_spec.h index 1e9ff1c41..7c290c6f3 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -64,7 +64,6 @@ void P_SwitchWeather(INT32 weathernum); boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller); void P_LinedefExecute(INT16 tag, mobj_t *actor, sector_t *caller); -void P_ChangeSectorTag(UINT32 sector, INT16 newtag); void P_RunNightserizeExecutors(mobj_t *actor); void P_RunDeNightserizeExecutors(mobj_t *actor); void P_RunNightsLapExecutors(mobj_t *actor); From 7c11091c40d86479ef97836fddb2628505acd618 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 23:30:47 +0200 Subject: [PATCH 47/75] Remove old tag list netgame packing/unpacking. --- src/p_saveg.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index e5241ec8a..4fdc3d488 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -851,8 +851,6 @@ static void P_NetArchiveWorld(void) if (!Tag_Compare(&ss->tags, &spawnss->tags)) diff2 |= SD_TAG; - if (ss->nexttag != spawnss->nexttag || ss->firsttag != spawnss->firsttag) - diff3 |= SD_TAGLIST; if (ss->extra_colormap != spawnss->extra_colormap) diff3 |= SD_COLORMAP; @@ -918,11 +916,6 @@ static void P_NetArchiveWorld(void) for (j = 0; j < ss->tags.count; j++) WRITEINT16(put, ss->tags.tags[j]); } - if (diff3 & SD_TAGLIST) // save both firsttag and nexttag - { // either of these could be changed even if tag isn't - WRITEINT32(put, ss->firsttag); - WRITEINT32(put, ss->nexttag); - } if (diff3 & SD_COLORMAP) WRITEUINT32(put, CheckAddNetColormapToList(ss->extra_colormap)); @@ -1165,11 +1158,6 @@ static void P_NetUnArchiveWorld(void) for (j = 0; j < ncount; j++) sectors[i].tags.tags[j] = READINT16(get); } - if (diff3 & SD_TAGLIST) - { - sectors[i].firsttag = READINT32(get); - sectors[i].nexttag = READINT32(get); - } if (diff3 & SD_COLORMAP) sectors[i].extra_colormap = GetNetColormapFromList(READUINT32(get)); From 38c665fa79f9a31b148d4b30eeeb2c1308bfbcf1 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 23:31:08 +0200 Subject: [PATCH 48/75] Remove old taglist access from Lua. --- src/lua_maplib.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index a6b45e406..a8d445a6f 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -94,8 +94,6 @@ enum line_e { line_slopetype, line_frontsector, line_backsector, - line_firsttag, - line_nexttag, line_text, line_callcount }; @@ -118,8 +116,6 @@ static const char *const line_opt[] = { "slopetype", "frontsector", "backsector", - "firsttag", - "nexttag", "text", "callcount", NULL}; @@ -815,12 +811,6 @@ static int line_get(lua_State *L) case line_backsector: LUA_PushUserdata(L, line->backsector, META_SECTOR); return 1; - case line_firsttag: - lua_pushinteger(L, line->firsttag); - return 1; - case line_nexttag: - lua_pushinteger(L, line->nexttag); - return 1; case line_text: lua_pushstring(L, line->text); return 1; From d775a42e93a274fd054aaf07991381aec1902fc6 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 17 Apr 2020 23:32:24 +0200 Subject: [PATCH 49/75] Rewrote a bit of the boss 4 code, which still requires working dynamic global tag lists. --- src/p_mobj.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 180376727..9cfc15113 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -4622,16 +4622,18 @@ static boolean P_Boss4MoveCage(mobj_t *mobj, fixed_t delta) const UINT16 tag = 65534 + (mobj->spawnpoint ? mobj->spawnpoint->extrainfo*LE_PARAMWIDTH : 0); INT32 snum; sector_t *sector; - for (snum = sectors[tag%numsectors].firsttag; snum != -1; snum = sector->nexttag) + boolean gotcage = false; + TAG_ITER_C + + TAG_ITER_SECTORS(tag, snum) { sector = §ors[snum]; - if (!Tag_Find(§or->tags, tag)) - continue; sector->floorheight += delta; sector->ceilingheight += delta; P_CheckSector(sector, true); + gotcage = true; } - return sectors[tag%numsectors].firsttag != -1; + return gotcage; } // Move Boss4's arms to angle @@ -4703,22 +4705,15 @@ static void P_Boss4PinchSpikeballs(mobj_t *mobj, angle_t angle, fixed_t dz) static void P_Boss4DestroyCage(mobj_t *mobj) { const UINT16 tag = 65534 + (mobj->spawnpoint ? mobj->spawnpoint->extrainfo*LE_PARAMWIDTH : 0); - INT32 snum, next; + INT32 snum; size_t a; sector_t *sector, *rsec; ffloor_t *rover; + TAG_ITER_C - // This will be the final iteration of sector tag. - // We'll destroy the tag list as we go. - next = sectors[tag%numsectors].firsttag; - sectors[tag%numsectors].firsttag = -1; - - for (snum = next; snum != -1; snum = next) + TAG_ITER_SECTORS(tag, snum) { sector = §ors[snum]; - - next = sector->nexttag; - sector->nexttag = -1; if (!Tag_Find(§or->tags, tag)) continue; Tag_SectorFSet(sector - sectors, 0); From e87ad0fb384ea27a80be3da403ce988235a204e9 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sat, 18 Apr 2020 00:05:55 +0200 Subject: [PATCH 50/75] Delete old taglists. --- src/p_setup.c | 3 --- src/p_spec.c | 16 ---------------- src/r_defs.h | 2 -- 3 files changed, 21 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index d92eb929c..baa71c6b3 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -852,8 +852,6 @@ static void P_LoadVertices(UINT8 *data) static void P_InitializeSector(sector_t *ss) { - ss->nexttag = ss->firsttag = -1; - memset(&ss->soundorg, 0, sizeof(ss->soundorg)); ss->validcount = 0; @@ -976,7 +974,6 @@ static void P_InitializeLinedef(line_t *ld) #ifdef WALLSPLATS ld->splats = NULL; #endif - ld->firsttag = ld->nexttag = -1; #ifdef POLYOBJECTS ld->polyobj = NULL; #endif diff --git a/src/p_spec.c b/src/p_spec.c index 5f5510372..81a5e0e49 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1383,22 +1383,6 @@ void P_RunNightsCapsuleTouchExecutors(mobj_t *actor, boolean entering, boolean e */ static inline void P_InitTagLists(void) { - register size_t i; - - for (i = numsectors - 1; i != (size_t)-1; i--) - { - size_t j = (unsigned)sectors[i].tag % numsectors; - sectors[i].nexttag = sectors[j].firsttag; - sectors[j].firsttag = (INT32)i; - } - - for (i = numlines - 1; i != (size_t)-1; i--) - { - size_t j = (unsigned)lines[i].tag % numlines; - lines[i].nexttag = lines[j].firsttag; - lines[j].firsttag = (INT32)i; - } - Taglist_InitGlobalTables(); } diff --git a/src/r_defs.h b/src/r_defs.h index 6dc9cf66e..41d141ce8 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -293,7 +293,6 @@ typedef struct sector_s INT16 special; UINT16 tag; taglist_t tags; - INT32 nexttag, firsttag; // for fast tag searches // origin for any sounds played by the sector // also considered the center for e.g. Mario blocks @@ -433,7 +432,6 @@ typedef struct line_s #if 1//#ifdef WALLSPLATS void *splats; // wallsplat_t list #endif - INT32 firsttag, nexttag; // improves searches for tags. #ifdef POLYOBJECTS polyobj_t *polyobj; // Belongs to a polyobject? #endif From aa0d76f8faf072c4c07c8bb209210bad2708ff9c Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sat, 18 Apr 2020 00:23:24 +0200 Subject: [PATCH 51/75] Delete tags. --- src/doomdata.h | 1 - src/p_enemy.c | 4 ---- src/p_inter.c | 1 - src/p_setup.c | 21 +++------------------ src/p_spec.c | 5 +---- src/r_defs.h | 2 -- 6 files changed, 4 insertions(+), 30 deletions(-) diff --git a/src/doomdata.h b/src/doomdata.h index 884c043a4..8621a362a 100644 --- a/src/doomdata.h +++ b/src/doomdata.h @@ -205,7 +205,6 @@ typedef struct UINT16 options; INT16 z; UINT8 extrainfo; - INT16 tag; taglist_t tags; struct mobj_s *mobj; } mapthing_t; diff --git a/src/p_enemy.c b/src/p_enemy.c index a51d76cb0..72aac711e 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -3866,13 +3866,10 @@ void A_BossDeath(mobj_t *mo) { // Bring the egg trap up to the surface // Incredibly shitty code ahead - junk.tag = LE_CAPSULE0; Tag_FSet(&junk.tags, LE_CAPSULE0); EV_DoElevator(&junk, elevateHighest, false); - junk.tag = LE_CAPSULE1; Tag_FSet(&junk.tags, LE_CAPSULE1); EV_DoElevator(&junk, elevateUp, false); - junk.tag = LE_CAPSULE2; Tag_FSet(&junk.tags, LE_CAPSULE2); EV_DoElevator(&junk, elevateHighest, false); @@ -3996,7 +3993,6 @@ bossjustdie: } case MT_KOOPA: { - junk.tag = LE_KOOPA; Tag_FSet(&junk.tags, LE_KOOPA); EV_DoCeiling(&junk, raiseToHighest); return; diff --git a/src/p_inter.c b/src/p_inter.c index 0cdbe57b2..efe23d500 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -1376,7 +1376,6 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) if (player->bot) return; - junk.tag = LE_AXE; Tag_FSet(&junk.tags, LE_AXE); EV_DoElevator(&junk, bridgeFall, false); diff --git a/src/p_setup.c b/src/p_setup.c index baa71c6b3..fe0818249 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -933,7 +933,6 @@ static void P_LoadSectors(UINT8 *data) ss->lightlevel = SHORT(ms->lightlevel); ss->special = SHORT(ms->special); - ss->tag = SHORT(ms->tag); Tag_FSet(&ss->tags, SHORT(ms->tag)); ss->floor_xoffs = ss->floor_yoffs = 0; @@ -1047,7 +1046,6 @@ static void P_LoadLinedefs(UINT8 *data) { ld->flags = SHORT(mld->flags); ld->special = SHORT(mld->special); - ld->tag = SHORT(mld->tag); Tag_FSet(&ld->tags, SHORT(mld->tag)); memset(ld->args, 0, NUMLINEARGS*sizeof(*ld->args)); memset(ld->stringargs, 0x00, NUMLINESTRINGARGS*sizeof(*ld->stringargs)); @@ -1278,7 +1276,6 @@ static void P_LoadThings(UINT8 *data) mt->type = READUINT16(data); mt->options = READUINT16(data); mt->extrainfo = (UINT8)(mt->type >> 12); - mt->tag = 0; Tag_FSet(&mt->tags, 0); mt->type &= 4095; @@ -1399,10 +1396,7 @@ static void ParseTextmapSectorParameter(UINT32 i, char *param, char *val) else if (fastcmp(param, "special")) sectors[i].special = atol(val); else if (fastcmp(param, "id")) - { - sectors[i].tag = atol(val); - Tag_FSet(§ors[i].tags, sectors[i].tag); - } + Tag_FSet(§ors[i].tags, atol(val)); else if (fastcmp(param, "moreids")) { char* id = val; @@ -1448,10 +1442,7 @@ static void ParseTextmapSidedefParameter(UINT32 i, char *param, char *val) static void ParseTextmapLinedefParameter(UINT32 i, char *param, char *val) { if (fastcmp(param, "id")) - { - lines[i].tag = atol(val); - Tag_FSet(&lines[i].tags, lines[i].tag); - } + Tag_FSet(&lines[i].tags, atol(val)); else if (fastcmp(param, "moreids")) { char* id = val; @@ -1528,10 +1519,7 @@ static void ParseTextmapLinedefParameter(UINT32 i, char *param, char *val) static void ParseTextmapThingParameter(UINT32 i, char *param, char *val) { if (fastcmp(param, "id")) - { - mapthings[i].tag = atol(val); - Tag_FSet(&mapthings[i].tags, mapthings[i].tag); - } + Tag_FSet(&mapthings[i].tags, atol(val)); else if (fastcmp(param, "moreids")) { char* id = val; @@ -1670,7 +1658,6 @@ static void P_LoadTextmap(void) sc->lightlevel = 255; sc->special = 0; - sc->tag = 0; Tag_FSet(&sc->tags, 0); sc->floor_xoffs = sc->floor_yoffs = 0; @@ -1690,7 +1677,6 @@ static void P_LoadTextmap(void) ld->v1 = ld->v2 = NULL; ld->flags = 0; ld->special = 0; - ld->tag = 0; Tag_FSet(&ld->tags, 0); memset(ld->args, 0, NUMLINEARGS*sizeof(*ld->args)); @@ -1739,7 +1725,6 @@ static void P_LoadTextmap(void) mt->options = 0; mt->z = 0; mt->extrainfo = 0; - mt->tag = 0; Tag_FSet(&mt->tags, 0); mt->mobj = NULL; diff --git a/src/p_spec.c b/src/p_spec.c index 81a5e0e49..ccce18e30 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -4366,16 +4366,13 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers // Move the button down Tag_FSet(&junk.tags, 680); - junk.tag = 680; EV_DoElevator(&junk, elevateDown, false); // Open the top FOF Tag_FSet(&junk.tags, 681); - junk.tag = 681; EV_DoFloor(&junk, raiseFloorToNearestFast); // Open the bottom FOF Tag_FSet(&junk.tags, 682); - junk.tag = 682; EV_DoCeiling(&junk, lowerToLowestFast); // Mark all players with the time to exit thingy! @@ -5549,7 +5546,7 @@ static ffloor_t *P_AddFakeFloor(sector_t *sec, sector_t *sec2, line_t *master, f { fixed_t tempceiling = sec2->ceilingheight; //flip the sector around and print an error instead of crashing 12.1.08 -Inuyasha - CONS_Alert(CONS_ERROR, M_GetText("A FOF tagged %d has a top height below its bottom.\n"), master->tag); + CONS_Alert(CONS_ERROR, M_GetText("FOF (line %d) has a top height below its bottom.\n"), master - lines); sec2->ceilingheight = sec2->floorheight; sec2->floorheight = tempceiling; } diff --git a/src/r_defs.h b/src/r_defs.h index 41d141ce8..72e3675cb 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -291,7 +291,6 @@ typedef struct sector_s INT32 ceilingpic; INT16 lightlevel; INT16 special; - UINT16 tag; taglist_t tags; // origin for any sounds played by the sector @@ -409,7 +408,6 @@ typedef struct line_s // Animation related. INT16 flags; INT16 special; - INT16 tag; taglist_t tags; INT32 args[NUMLINEARGS]; char *stringargs[NUMLINESTRINGARGS]; From b7c4ed9c6bb0edb8f94ca2afa94c26e49cc3646d Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sat, 18 Apr 2020 11:34:59 +0200 Subject: [PATCH 52/75] Implement dynamic global taggroups/lists functionality. --- src/p_saveg.c | 10 ++++ src/taglist.c | 131 +++++++++++++++++++++++++++++++++++--------------- src/taglist.h | 3 ++ 3 files changed, 106 insertions(+), 38 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index 4fdc3d488..4a414e9e1 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1149,6 +1149,12 @@ static void P_NetUnArchiveWorld(void) if (diff2 & SD_TAG) { size_t ncount = READUINT32(get); + + // Remove entries from global lists. + for (j = 0; j < sectors[i].tags.count; j++) + Taggroup_Remove(tags_sectors, sectors[i].tags.tags[j], i); + + // Reallocate if size differs. if (ncount != sectors[i].tags.count) { sectors[i].tags.count = ncount; @@ -1157,6 +1163,10 @@ static void P_NetUnArchiveWorld(void) for (j = 0; j < ncount; j++) sectors[i].tags.tags[j] = READINT16(get); + + // Add new entries. + for (j = 0; j < sectors[i].tags.count; j++) + Taggroup_Remove(tags_sectors, sectors[i].tags.tags[j], i); } if (diff3 & SD_COLORMAP) diff --git a/src/taglist.c b/src/taglist.c index 1849c314c..3b0135abd 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -63,58 +63,97 @@ boolean Tag_Compare (const taglist_t* list1, const taglist_t* list2) return true; } -static void Taglist_AddToSectors (const mtag_t tag, const size_t itemid) + +size_t Taggroup_Find (const taggroup_t *group, const size_t id) { - taggroup_t* tagelems; + size_t i; + + if (!group) + return -1; + + for (i = 0; i < group->count; i++) + if (group->elements[i] == id) + return i; + + return -1; +} + +void Taggroup_Add (taggroup_t *garray[], const mtag_t tag, size_t id) +{ + taggroup_t *group; if (tag == MTAG_GLOBAL) return; - if (!tags_sectors[(UINT16)tag]) - tags_sectors[(UINT16)tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); + group = garray[(UINT16)tag]; - tagelems = tags_sectors[(UINT16)tag]; - tagelems->count++; - tagelems->elements = Z_Realloc(tagelems->elements, tagelems->count * sizeof(size_t), PU_LEVEL, NULL); - tagelems->elements[tagelems->count - 1] = itemid; + // Don't add duplicate entries. + if (Taggroup_Find(group, id) != (size_t)-1) + return; + + // Create group if empty. + if (!group) + group = garray[(UINT16)tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); + + group->count++; + group->elements = Z_Realloc(group->elements, group->count * sizeof(size_t), PU_LEVEL, NULL); + group->elements[group->count - 1] = id; +} + +void Taggroup_Remove (taggroup_t *garray[], const mtag_t tag, size_t id) +{ + taggroup_t *group; + size_t rempos; + size_t newcount; + + if (tag == MTAG_GLOBAL) + return; + + group = garray[(UINT16)tag]; + + if ((rempos = Taggroup_Find(group, id)) == (size_t)-1) + return; + + // Strip away taggroup if no elements left. + if (!(newcount = --group->count)) + { + Z_Free(group->elements); + Z_Free(group); + garray[(UINT16)tag] = NULL; + } + else + { + size_t *newelements = Z_Malloc(newcount * sizeof(size_t), PU_LEVEL, NULL); + size_t i; + + // Copy the previous entries save for the one to remove. + for (i = 0; i < rempos; i++) + newelements[i] = group->elements[i]; + + for (i = rempos + 1; i < group->count; i++) + newelements[i - 1] = group->elements[i]; + + Z_Free(group->elements); + group->elements = newelements; + group->count = newcount; + } +} + +// Initialization. + +static void Taglist_AddToSectors (const mtag_t tag, const size_t itemid) +{ + Taggroup_Add(tags_sectors, tag, itemid); } static void Taglist_AddToLines (const mtag_t tag, const size_t itemid) { - taggroup_t* tagelems; - - if (tag == MTAG_GLOBAL) - return; - - if (!tags_lines[(UINT16)tag]) - tags_lines[(UINT16)tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); - - tagelems = tags_lines[(UINT16)tag]; - tagelems->count++; - tagelems->elements = Z_Realloc(tagelems->elements, tagelems->count * sizeof(size_t), PU_LEVEL, NULL); - tagelems->elements[tagelems->count - 1] = itemid; + Taggroup_Add(tags_lines, tag, itemid); } static void Taglist_AddToMapthings (const mtag_t tag, const size_t itemid) { - taggroup_t* tagelems; - - if (tag == MTAG_GLOBAL) - return; - - if (!tags_mapthings[(UINT16)tag]) - tags_mapthings[(UINT16)tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); - - tagelems = tags_mapthings[(UINT16)tag]; - tagelems->count++; - tagelems->elements = Z_Realloc(tagelems->elements, tagelems->count * sizeof(size_t), PU_LEVEL, NULL); - tagelems->elements[tagelems->count - 1] = itemid; -} - -void Tag_SectorFSet (const size_t id, const mtag_t tag) -{ - sector_t* sec = §ors[id]; - Tag_FSet(&sec->tags, tag); + Taggroup_Add(tags_mapthings, tag, itemid); } void Taglist_InitGlobalTables(void) @@ -144,6 +183,8 @@ void Taglist_InitGlobalTables(void) } } +// Iteration, inagme search. + INT32 Tag_Iterate_Sectors (const mtag_t tag, const size_t p) { if (tag == MTAG_GLOBAL) @@ -217,3 +258,17 @@ INT32 Tag_FindLineSpecial(const INT16 special, const mtag_t tag) } return -1; } + +// Ingame list manipulation. + +void Tag_SectorFSet (const size_t id, const mtag_t tag) +{ + sector_t* sec = §ors[id]; + mtag_t curtag = Tag_FGet(&sec->tags); + if (curtag == tag) + return; + + Taggroup_Remove(tags_sectors, curtag, id); + Taggroup_Add(tags_sectors, tag, id); + Tag_FSet(&sec->tags, tag); +} diff --git a/src/taglist.h b/src/taglist.h index 050bebed7..d1acff6cb 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -35,6 +35,9 @@ taggroup_t* tags_sectors[MAXTAGS + 1]; taggroup_t* tags_lines[MAXTAGS + 1]; taggroup_t* tags_mapthings[MAXTAGS + 1]; +void Taggroup_Add (taggroup_t *garray[], const mtag_t tag, size_t id); +void Taggroup_Remove (taggroup_t *garray[], const mtag_t tag, size_t id); + void Taglist_InitGlobalTables(void); INT32 Tag_Iterate_Sectors (const mtag_t tag, const size_t p); From 6eaaa744f4b6f30f1db4a6987e20c4e5e32d6a89 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sun, 19 Apr 2020 12:21:22 +0200 Subject: [PATCH 53/75] Taggroups are now sorted when a new entry is added. --- src/taglist.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/taglist.c b/src/taglist.c index 3b0135abd..2c1ac85d7 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -81,6 +81,7 @@ size_t Taggroup_Find (const taggroup_t *group, const size_t id) void Taggroup_Add (taggroup_t *garray[], const mtag_t tag, size_t id) { taggroup_t *group; + size_t i; // Insert position. if (tag == MTAG_GLOBAL) return; @@ -93,11 +94,35 @@ void Taggroup_Add (taggroup_t *garray[], const mtag_t tag, size_t id) // Create group if empty. if (!group) + { + i = 0; group = garray[(UINT16)tag] = Z_Calloc(sizeof(taggroup_t), PU_LEVEL, NULL); + } + else + { + // Keep the group element ids in an ascending order. + // Find the location to insert the element to. + for (i = 0; i < group->count; i++) + if (group->elements[i] > id) + break; + + group->elements = Z_Realloc(group->elements, (group->count + 1) * sizeof(size_t), PU_LEVEL, NULL); + + // Offset existing elements to make room for the new one. + if (i < group->count) + { + // Temporary memory block for copying. + size_t size = group->count - i; + size_t *temp = malloc(size); + memcpy(temp, &group->elements[i], size); + memcpy(&group->elements[i + 1], temp, size); + free(temp); + } + } group->count++; group->elements = Z_Realloc(group->elements, group->count * sizeof(size_t), PU_LEVEL, NULL); - group->elements[group->count - 1] = id; + group->elements[i] = id; } void Taggroup_Remove (taggroup_t *garray[], const mtag_t tag, size_t id) From 9ac60a62b3f48232c0192733718ed2211b94dec1 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sun, 19 Apr 2020 13:13:17 +0200 Subject: [PATCH 54/75] Fix cage issue with boss 4. --- src/p_mobj.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 9cfc15113..15394746a 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -4714,9 +4714,6 @@ static void P_Boss4DestroyCage(mobj_t *mobj) TAG_ITER_SECTORS(tag, snum) { sector = §ors[snum]; - if (!Tag_Find(§or->tags, tag)) - continue; - Tag_SectorFSet(sector - sectors, 0); // Destroy the FOFs. for (a = 0; a < sector->numattached; a++) From 9f06903d7284553dbeb77ee6ae9ea40693998318 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sat, 11 Jul 2020 11:01:05 +0200 Subject: [PATCH 55/75] What the fuck was I thinking? Fixed really stupid brainless code piece involving polyobject spawnpoint tagging. --- src/p_setup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index e073cc110..981d02360 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3180,11 +3180,11 @@ static void P_ConvertBinaryMap(void) { INT32 check = -1; INT32 firstline = -1; - mtag_t tag = Tag_FGet(&lines[check].tags); + mtag_t tag = mapthings[i].angle; TAG_ITER_C - Tag_FSet(&mapthings[i].tags, mapthings[i].angle); + Tag_FSet(&mapthings[i].tags, tag); TAG_ITER_LINES(tag, check) { From 3b55c9e94070820d827a843568c3f8899dc69b81 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Wed, 29 Jul 2020 14:52:21 +0200 Subject: [PATCH 56/75] Fix FOF intersections in multitagging for the software renderer. --- src/r_segs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/r_segs.c b/src/r_segs.c index 5bf9b5c82..52c19d96e 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -2141,6 +2141,9 @@ void R_StoreWallRange(INT32 start, INT32 stop) for (r2 = frontsector->ffloors; r2; r2 = r2->next) { + if (r2->master == rover->master) // Skip if same control line. + continue; + if (!(r2->flags & FF_EXISTS) || !(r2->flags & FF_RENDERSIDES)) continue; From 729c8b2ec6cab99ed838a301ce938d9b04801406 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Wed, 29 Jul 2020 14:53:27 +0200 Subject: [PATCH 57/75] Fix FOF intersections with multitags for the OpenGL in a kind of hacky way. --- src/hardware/hw_main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 98b736b30..219bc905e 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1627,6 +1627,9 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom continue; if (*rover->topheight < lowcut || *rover->bottomheight > highcut) continue; + if (Tag_Find(&gl_frontsector->tags, rover->master->args[0])) // Skip FOF if on both sectors by checking arg0. Hacky but it works. + continue; + texnum = R_GetTextureNum(sides[rover->master->sidenum[0]].midtexture); @@ -1761,6 +1764,8 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom continue; if (*rover->topheight < lowcut || *rover->bottomheight > highcut) continue; + if (Tag_Find(&gl_backsector->tags, rover->master->args[0])) // Skip FOF if on both sectors by checking arg0. Hacky but it works. + continue; texnum = R_GetTextureNum(sides[rover->master->sidenum[0]].midtexture); From c914ac99b4e39110bca1203b4d12e9078d406656 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Wed, 29 Jul 2020 17:26:43 +0200 Subject: [PATCH 58/75] Bring back P_FindSpecialLineFromTag() for backwards compatibility reasons; emulate the old taglist behavior for this function. --- src/lua_baselib.c | 13 +++++++++++++ src/taglist.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/taglist.h | 3 ++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index a8a45ba20..5d1db5641 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -32,6 +32,7 @@ #include "lua_script.h" #include "lua_libs.h" #include "lua_hud.h" // hud_running errors +#include "taglist.h" // P_FindSpecialLineFromTag #define NOHUD if (hud_running)\ return luaL_error(L, "HUD rendering code should not call this function!"); @@ -2094,6 +2095,17 @@ static int lib_pFindHighestCeilingSurrounding(lua_State *L) return 1; } +static int lib_pFindSpecialLineFromTag(lua_State *L) +{ + INT16 special = (INT16)luaL_checkinteger(L, 1); + INT16 line = (INT16)luaL_checkinteger(L, 2); + INT32 start = (INT32)luaL_optinteger(L, 3, -1); + NOHUD + INLEVEL + lua_pushinteger(L, P_FindSpecialLineFromTag(special, line, start)); + return 1; +} + static int lib_pSwitchWeather(lua_State *L) { INT32 weathernum = (INT32)luaL_checkinteger(L, 1); @@ -3581,6 +3593,7 @@ static luaL_Reg lib[] = { {"P_FindNextLowestFloor",lib_pFindNextLowestFloor}, {"P_FindLowestCeilingSurrounding",lib_pFindLowestCeilingSurrounding}, {"P_FindHighestCeilingSurrounding",lib_pFindHighestCeilingSurrounding}, + {"P_FindSpecialLineFromTag",lib_pFindSpecialLineFromTag}, {"P_SwitchWeather",lib_pSwitchWeather}, {"P_LinedefExecute",lib_pLinedefExecute}, {"P_SpawnLightningFlash",lib_pSpawnLightningFlash}, diff --git a/src/taglist.c b/src/taglist.c index 2c1ac85d7..7fd2601c7 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -284,6 +284,48 @@ INT32 Tag_FindLineSpecial(const INT16 special, const mtag_t tag) return -1; } +/// Backwards compatibility iteration function for Lua scripts. +INT32 P_FindSpecialLineFromTag(INT16 special, INT16 tag, INT32 start) +{ + if (tag == -1) + { + start++; + + if (start >= (INT32)numlines) + return -1; + + while (start < (INT32)numlines && lines[start].special != special) + start++; + + return start; + } + else + { + size_t p = 0; + INT32 id; + + // For backwards compatibility's sake, simulate the old linked taglist behavior: + // Iterate through the taglist and find the "start" line's position in the list, + // And start checking with the next one (if it exists). + if (start != -1) + { + for (; (id = Tag_Iterate_Lines(tag, p)) >= 0; p++) + if (id == start) + { + p++; + break; + } + } + + for (; (id = Tag_Iterate_Lines(tag, p)) >= 0; p++) + if (lines[id].special == special) + return id; + + return -1; + } +} + + // Ingame list manipulation. void Tag_SectorFSet (const size_t id, const mtag_t tag) diff --git a/src/taglist.h b/src/taglist.h index d1acff6cb..7c3b4ad52 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -44,7 +44,8 @@ INT32 Tag_Iterate_Sectors (const mtag_t tag, const size_t p); INT32 Tag_Iterate_Lines (const mtag_t tag, const size_t p); INT32 Tag_Iterate_Things (const mtag_t tag, const size_t p); -INT32 Tag_FindLineSpecial(const INT16 special, const INT16 tag); +INT32 Tag_FindLineSpecial(const INT16 special, const mtag_t tag); +INT32 P_FindSpecialLineFromTag(INT16 special, INT16 tag, INT32 start); #define TAG_ITER_C size_t kkkk; #define TAG_ITER(fn, tag, id) for(kkkk = 0; (id = fn(tag, kkkk)) >= 0; kkkk++) From 0520725069a121af42c3f3b4dbe9f20c169bc5c0 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 31 Jul 2020 14:55:26 +0200 Subject: [PATCH 59/75] Fix the OpenGL FOF issue with a different approach. Not fond of it either but at least it works. --- src/hardware/hw_main.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 219bc905e..777fd6f1c 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1621,15 +1621,18 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { for (rover = gl_backsector->ffloors; rover; rover = rover->next) { + // Skip if it exists on both sectors. + ffloor_t * r2; + for (r2 = gl_frontsector->ffloors; r2; r2 = r2->next) + if (rover->master == r2->master) + continue; + if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERSIDES)) continue; if (!(rover->flags & FF_ALLSIDES) && rover->flags & FF_INVERTSIDES) continue; if (*rover->topheight < lowcut || *rover->bottomheight > highcut) continue; - if (Tag_Find(&gl_frontsector->tags, rover->master->args[0])) // Skip FOF if on both sectors by checking arg0. Hacky but it works. - continue; - texnum = R_GetTextureNum(sides[rover->master->sidenum[0]].midtexture); @@ -1758,14 +1761,18 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { for (rover = gl_frontsector->ffloors; rover; rover = rover->next) { + // Skip if it exists on both sectors. + ffloor_t * r2; + for (r2 = gl_backsector->ffloors; r2; r2 = r2->next) + if (rover->master == r2->master) + continue; + if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERSIDES)) continue; if (!(rover->flags & FF_ALLSIDES || rover->flags & FF_INVERTSIDES)) continue; if (*rover->topheight < lowcut || *rover->bottomheight > highcut) continue; - if (Tag_Find(&gl_backsector->tags, rover->master->args[0])) // Skip FOF if on both sectors by checking arg0. Hacky but it works. - continue; texnum = R_GetTextureNum(sides[rover->master->sidenum[0]].midtexture); From ba5d09eb2eb5f833bb9dccde832f8ded64071c8c Mon Sep 17 00:00:00 2001 From: Nev3r Date: Fri, 31 Jul 2020 22:38:37 +0200 Subject: [PATCH 60/75] Fix smooth brain bruhments. --- src/hardware/hw_main.c | 16 ++++++++++++++-- src/r_segs.c | 5 ++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 777fd6f1c..a1d7797ea 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1621,11 +1621,17 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { for (rover = gl_backsector->ffloors; rover; rover = rover->next) { + boolean bothsides = false; // Skip if it exists on both sectors. ffloor_t * r2; for (r2 = gl_frontsector->ffloors; r2; r2 = r2->next) if (rover->master == r2->master) - continue; + { + bothsides = true; + break; + } + + if (bothsides) continue; if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERSIDES)) continue; @@ -1761,11 +1767,17 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { for (rover = gl_frontsector->ffloors; rover; rover = rover->next) { + boolean bothsides = false; // Skip if it exists on both sectors. ffloor_t * r2; for (r2 = gl_backsector->ffloors; r2; r2 = r2->next) if (rover->master == r2->master) - continue; + { + bothsides = true; + break; + } + + if (bothsides) continue; if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERSIDES)) continue; diff --git a/src/r_segs.c b/src/r_segs.c index 52c19d96e..92b605180 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -2142,7 +2142,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) for (r2 = frontsector->ffloors; r2; r2 = r2->next) { if (r2->master == rover->master) // Skip if same control line. - continue; + break; if (!(r2->flags & FF_EXISTS) || !(r2->flags & FF_RENDERSIDES)) continue; @@ -2199,6 +2199,9 @@ void R_StoreWallRange(INT32 start, INT32 stop) for (r2 = backsector->ffloors; r2; r2 = r2->next) { + if (r2->master == rover->master) // Skip if same control line. + break; + if (!(r2->flags & FF_EXISTS) || !(r2->flags & FF_RENDERSIDES)) continue; From 77e438d4bd859febbc1a4cde9bee8f2ed0de9b3b Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sun, 16 Aug 2020 11:33:00 +0200 Subject: [PATCH 61/75] Some commenting tweaks. --- src/taglist.c | 2 +- src/taglist.h | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/taglist.c b/src/taglist.c index 7fd2601c7..bc5a166fd 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -208,7 +208,7 @@ void Taglist_InitGlobalTables(void) } } -// Iteration, inagme search. +// Iteration, ingame search. INT32 Tag_Iterate_Sectors (const mtag_t tag, const size_t p) { diff --git a/src/taglist.h b/src/taglist.h index 7c3b4ad52..896344c13 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -47,9 +47,12 @@ INT32 Tag_Iterate_Things (const mtag_t tag, const size_t p); INT32 Tag_FindLineSpecial(const INT16 special, const mtag_t tag); INT32 P_FindSpecialLineFromTag(INT16 special, INT16 tag, INT32 start); -#define TAG_ITER_C size_t kkkk; -#define TAG_ITER(fn, tag, id) for(kkkk = 0; (id = fn(tag, kkkk)) >= 0; kkkk++) +// Use this macro to declare the iterator position variable. +#define TAG_ITER_C size_t tag_iterator_pos; +#define TAG_ITER(fn, tag, id) for(tag_iterator_pos = 0; (id = fn(tag, tag_iterator_pos)) >= 0; tag_iterator_pos++) + +// Use these macros as wrappers for the taglist iterations. #define TAG_ITER_SECTORS(tag, id) TAG_ITER(Tag_Iterate_Sectors, tag, id) #define TAG_ITER_LINES(tag, id) TAG_ITER(Tag_Iterate_Lines, tag, id) #define TAG_ITER_THINGS(tag, id) TAG_ITER(Tag_Iterate_Things, tag, id) From 1d542d3676a583118a2345603ef3c79b78285160 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Tue, 10 Nov 2020 12:12:16 +0100 Subject: [PATCH 62/75] Add copyright notices. --- src/taglist.c | 13 +++++++++++++ src/taglist.h | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/taglist.c b/src/taglist.c index bc5a166fd..3c75f293f 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -1,3 +1,16 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2020 by Sonic Team Junior. +// Copyright (C) 2020 by Nev3r. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file taglist.c +/// \brief Ingame sector/line/mapthing tagging. + #include "taglist.h" #include "z_zone.h" #include "r_data.h" diff --git a/src/taglist.h b/src/taglist.h index 896344c13..ab69787dd 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -1,3 +1,16 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 1999-2020 by Sonic Team Junior. +// Copyright (C) 2020 by Nev3r. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file taglist.h +/// \brief Tag iteration and reading functions and macros' declarations. + #ifndef __R_TAGLIST__ #define __R_TAGLIST__ From 95a61a226be02dac53b1b8938fba486e64979327 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Tue, 10 Nov 2020 12:22:55 +0100 Subject: [PATCH 63/75] rename TAG_ITER_C to TAG_ITER_DECLARECOUNTER and remove the semicolon from the macro. --- src/p_ceilng.c | 4 ++-- src/p_floor.c | 22 +++++++++++----------- src/p_lights.c | 2 +- src/p_mobj.c | 4 ++-- src/p_setup.c | 4 ++-- src/p_slopes.c | 2 +- src/p_spec.c | 20 ++++++++++---------- src/taglist.h | 2 +- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/p_ceilng.c b/src/p_ceilng.c index f355ee011..0cea8c52f 100644 --- a/src/p_ceilng.c +++ b/src/p_ceilng.c @@ -395,7 +395,7 @@ INT32 EV_DoCeiling(line_t *line, ceiling_e type) sector_t *sec; ceiling_t *ceiling; mtag_t tag = Tag_FGet(&line->tags); - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; TAG_ITER_SECTORS(tag, secnum) { @@ -617,7 +617,7 @@ INT32 EV_DoCrush(line_t *line, ceiling_e type) sector_t *sec; ceiling_t *ceiling; mtag_t tag = Tag_FGet(&line->tags); - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; TAG_ITER_SECTORS(tag, secnum) { diff --git a/src/p_floor.c b/src/p_floor.c index 198148549..98a26039a 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -635,7 +635,7 @@ void T_BounceCheese(bouncecheese_t *bouncer) boolean remove; INT32 i; mtag_t tag = Tag_FGet(&bouncer->sourceline->tags); - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; if (bouncer->sector->crumblestate == CRUMBLE_RESTORE || bouncer->sector->crumblestate == CRUMBLE_WAIT || bouncer->sector->crumblestate == CRUMBLE_ACTIVATED) // Oops! Crumbler says to remove yourself! @@ -775,7 +775,7 @@ void T_StartCrumble(crumble_t *crumble) sector_t *sector; INT32 i; mtag_t tag = Tag_FGet(&crumble->sourceline->tags); - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; // Once done, the no-return thinker just sits there, // constantly 'returning'... kind of an oxymoron, isn't it? @@ -948,7 +948,7 @@ void T_StartCrumble(crumble_t *crumble) void T_MarioBlock(mariothink_t *block) { INT32 i; - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; T_MovePlane ( @@ -1295,7 +1295,7 @@ void T_NoEnemiesSector(noenemies_t *nobaddies) INT32 secnum = -1; boolean FOFsector = false; mtag_t tag = Tag_FGet(&nobaddies->sourceline->tags); - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; TAG_ITER_SECTORS(tag, secnum) { @@ -1308,7 +1308,7 @@ void T_NoEnemiesSector(noenemies_t *nobaddies) { INT32 targetsecnum = -1; mtag_t tag2 = Tag_FGet(&sec->lines[i]->tags); - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; if (sec->lines[i]->special < 100 || sec->lines[i]->special >= 300) continue; @@ -1402,7 +1402,7 @@ void T_EachTimeThinker(eachtime_t *eachtime) fixed_t bottomheight, topheight; ffloor_t *rover; mtag_t tag = Tag_FGet(&eachtime->sourceline->tags); - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; for (i = 0; i < MAXPLAYERS; i++) { @@ -1430,7 +1430,7 @@ void T_EachTimeThinker(eachtime_t *eachtime) { INT32 targetsecnum = -1; mtag_t tag2 = Tag_FGet(&sec->lines[i]->tags); - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; if (sec->lines[i]->special < 100 || sec->lines[i]->special >= 300) continue; @@ -1572,7 +1572,7 @@ void T_RaiseSector(raise_t *raise) INT32 direction; result_e res = 0; mtag_t tag = raise->tag; - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; if (raise->sector->crumblestate >= CRUMBLE_FALL || raise->sector->ceilingdata) return; @@ -1822,7 +1822,7 @@ void EV_DoFloor(line_t *line, floor_e floortype) sector_t *sec; floormove_t *dofloor; mtag_t tag = Tag_FGet(&line->tags); - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; TAG_ITER_SECTORS(tag, secnum) { @@ -2039,7 +2039,7 @@ void EV_DoElevator(line_t *line, elevator_e elevtype, boolean customspeed) sector_t *sec; elevator_t *elevator; mtag_t tag = Tag_FGet(&line->tags); - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; // act on all sectors with the same tag as the triggering linedef TAG_ITER_SECTORS(tag, secnum) @@ -2339,7 +2339,7 @@ INT32 EV_StartCrumble(sector_t *sec, ffloor_t *rover, boolean floating, sector_t *foundsec; INT32 i; mtag_t tag = Tag_FGet(&rover->master->tags); - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; // If floor is already activated, skip it if (sec->floordata) diff --git a/src/p_lights.c b/src/p_lights.c index bb8ef6989..326549477 100644 --- a/src/p_lights.c +++ b/src/p_lights.c @@ -374,7 +374,7 @@ void P_FadeLightBySector(sector_t *sector, INT32 destvalue, INT32 speed, boolean void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed, boolean ticbased, boolean force) { INT32 i; - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; // search all sectors for ones with tag TAG_ITER_SECTORS(tag, i) diff --git a/src/p_mobj.c b/src/p_mobj.c index 61a376729..2ae24b402 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -4631,7 +4631,7 @@ static boolean P_Boss4MoveCage(mobj_t *mobj, fixed_t delta) INT32 snum; sector_t *sector; boolean gotcage = false; - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; TAG_ITER_SECTORS(tag, snum) { @@ -4717,7 +4717,7 @@ static void P_Boss4DestroyCage(mobj_t *mobj) size_t a; sector_t *sector, *rsec; ffloor_t *rover; - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; TAG_ITER_SECTORS(tag, snum) { diff --git a/src/p_setup.c b/src/p_setup.c index 87fb2ac0d..dd49ae0be 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2971,7 +2971,7 @@ static void P_ConvertBinaryMap(void) INT32 check = -1; INT32 paramline = -1; - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; TAG_ITER_LINES(tag, check) { @@ -3188,7 +3188,7 @@ static void P_ConvertBinaryMap(void) INT32 firstline = -1; mtag_t tag = mapthings[i].angle; - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; Tag_FSet(&mapthings[i].tags, tag); diff --git a/src/p_slopes.c b/src/p_slopes.c index 412d13dd2..80278451a 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -546,7 +546,7 @@ static boolean P_SetSlopeFromTag(sector_t *sec, INT32 tag, boolean ceiling) { INT32 i; pslope_t **secslope = ceiling ? &sec->c_slope : &sec->f_slope; - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; if (!tag || *secslope) return false; diff --git a/src/p_spec.c b/src/p_spec.c index 39d7e9223..0746c65b0 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2223,7 +2223,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) INT32 secnum = -1; mobj_t *bot = NULL; mtag_t tag = Tag_FGet(&line->tags); - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; I_Assert(!mo || !P_MobjWasRemoved(mo)); // If mo is there, mo must be valid! @@ -3887,7 +3887,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) case 465: // Set linedef executor delay { INT32 linenum; - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; if (!udmf) break; @@ -5922,7 +5922,7 @@ void T_LaserFlash(laserthink_t *flash) sector_t *sector; sector_t *sourcesec = flash->sourceline->frontsector; fixed_t top, bottom; - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; TAG_ITER_SECTORS(flash->tag, s) { @@ -6204,7 +6204,7 @@ void P_SpawnSpecials(boolean fromnetsave) INT32 s; size_t sec; ffloortype_e ffloorflags; - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; case 1: // Definable gravity per sector sec = sides[*lines[i].sidenum].sector - sectors; @@ -7098,7 +7098,7 @@ void P_SpawnSpecials(boolean fromnetsave) */ static void P_AddFakeFloorsByLine(size_t line, ffloortype_e ffloorflags, thinkerlist_t *secthinkers) { - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; INT32 s; mtag_t tag = Tag_FGet(&lines[line].tags); size_t sec = sides[*lines[line].sidenum].sector-sectors; @@ -7214,7 +7214,7 @@ void T_Scroll(scroll_t *s) size_t i; INT32 sect; ffloor_t *rover; - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; case sc_side: // scroll wall texture side = sides + s->affectee; @@ -7466,7 +7466,7 @@ static void P_SpawnScrollers(void) switch (special) { register INT32 s; - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; case 513: // scroll effect ceiling case 533: // scroll and carry objects on ceiling @@ -7604,7 +7604,7 @@ void T_Disappear(disappear_t *d) ffloor_t *rover; register INT32 s; mtag_t afftag = Tag_FGet(&lines[d->affectee].tags); - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; TAG_ITER_SECTORS(afftag, s) { @@ -8337,7 +8337,7 @@ static void P_SpawnFriction(void) fixed_t strength; // frontside texture offset controls magnitude fixed_t friction; // friction value to be applied during movement INT32 movefactor; // applied to each player move to simulate inertia - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; for (i = 0; i < numlines; i++, l++) if (l->special == 540) @@ -8882,7 +8882,7 @@ static void P_SpawnPushers(void) mtag_t tag; register INT32 s; mobj_t *thing; - TAG_ITER_C + TAG_ITER_DECLARECOUNTER; for (i = 0; i < numlines; i++, l++) { diff --git a/src/taglist.h b/src/taglist.h index ab69787dd..caf99b807 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -61,7 +61,7 @@ INT32 Tag_FindLineSpecial(const INT16 special, const mtag_t tag); INT32 P_FindSpecialLineFromTag(INT16 special, INT16 tag, INT32 start); // Use this macro to declare the iterator position variable. -#define TAG_ITER_C size_t tag_iterator_pos; +#define TAG_ITER_DECLARECOUNTER size_t tag_iterator_pos #define TAG_ITER(fn, tag, id) for(tag_iterator_pos = 0; (id = fn(tag, tag_iterator_pos)) >= 0; tag_iterator_pos++) From d5355a11b004c797f08c51e030bcb74e2292bd82 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Tue, 10 Nov 2020 12:23:30 +0100 Subject: [PATCH 64/75] Indent --- src/taglist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/taglist.c b/src/taglist.c index 3c75f293f..b85d5d616 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -70,8 +70,8 @@ boolean Tag_Compare (const taglist_t* list1, const taglist_t* list2) return false; for (i = 0; i < list1->count; i++) - if (list1->tags[i] != list2->tags[i]) - return false; + if (list1->tags[i] != list2->tags[i]) + return false; return true; } From b65211d1481b1813d02276e3e007c28bec7b2d3e Mon Sep 17 00:00:00 2001 From: Nev3r Date: Tue, 10 Nov 2020 12:34:08 +0100 Subject: [PATCH 65/75] Use sizeu1() --- src/p_spec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index 0746c65b0..417c94c99 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -5510,7 +5510,7 @@ static ffloor_t *P_AddFakeFloor(sector_t *sec, sector_t *sec2, line_t *master, f { fixed_t tempceiling = sec2->ceilingheight; //flip the sector around and print an error instead of crashing 12.1.08 -Inuyasha - CONS_Alert(CONS_ERROR, M_GetText("FOF (line %d) has a top height below its bottom.\n"), master - lines); + CONS_Alert(CONS_ERROR, M_GetText("FOF (line %d) has a top height below its bottom.\n"), sizeu1(master - lines)); sec2->ceilingheight = sec2->floorheight; sec2->floorheight = tempceiling; } From 676f7f5dbfe27ccd1be14f558ebdfc14baf53554 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Tue, 10 Nov 2020 12:45:30 +0100 Subject: [PATCH 66/75] Use memmove() --- src/taglist.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/taglist.c b/src/taglist.c index b85d5d616..90608518b 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -123,14 +123,7 @@ void Taggroup_Add (taggroup_t *garray[], const mtag_t tag, size_t id) // Offset existing elements to make room for the new one. if (i < group->count) - { - // Temporary memory block for copying. - size_t size = group->count - i; - size_t *temp = malloc(size); - memcpy(temp, &group->elements[i], size); - memcpy(&group->elements[i + 1], temp, size); - free(temp); - } + memmove(&group->elements[i + 1], &group->elements[i], group->count - i); } group->count++; From a405f17d0b5492c63030496d2ffb86763ecdaac2 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Tue, 10 Nov 2020 13:09:30 +0100 Subject: [PATCH 67/75] Missing prototype. --- src/taglist.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/taglist.h b/src/taglist.h index caf99b807..52979b55f 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -50,6 +50,7 @@ taggroup_t* tags_mapthings[MAXTAGS + 1]; void Taggroup_Add (taggroup_t *garray[], const mtag_t tag, size_t id); void Taggroup_Remove (taggroup_t *garray[], const mtag_t tag, size_t id); +size_t Taggroup_Find (const taggroup_t *group, const size_t id); void Taglist_InitGlobalTables(void); From 56c3e93d3a6a825007130979b760489e44e8ecbb Mon Sep 17 00:00:00 2001 From: Nev3r Date: Tue, 10 Nov 2020 13:10:01 +0100 Subject: [PATCH 68/75] Remove unused tag parameter. --- src/p_spec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 417c94c99..f512e4583 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -5806,7 +5806,7 @@ static void P_AddAirbob(sector_t *sec, INT16 tag, fixed_t dist, boolean raise, b * \sa P_SpawnSpecials, T_ThwompSector * \author SSNTails */ -static inline void P_AddThwompThinker(sector_t *sec, INT16 tag, line_t *sourceline, fixed_t crushspeed, fixed_t retractspeed, UINT16 sound) +static inline void P_AddThwompThinker(sector_t *sec, line_t *sourceline, fixed_t crushspeed, fixed_t retractspeed, UINT16 sound) { thwomp_t *thwomp; @@ -6753,7 +6753,7 @@ void P_SpawnSpecials(boolean fromnetsave) fixed_t crushspeed = (lines[i].flags & ML_EFFECT5) ? lines[i].dy >> 3 : 10*FRACUNIT; fixed_t retractspeed = (lines[i].flags & ML_EFFECT5) ? lines[i].dx >> 3 : 2*FRACUNIT; UINT16 sound = (lines[i].flags & ML_EFFECT4) ? sides[lines[i].sidenum[0]].textureoffset >> FRACBITS : sfx_thwomp; - P_AddThwompThinker(lines[i].frontsector, tag, &lines[i], crushspeed, retractspeed, sound); + P_AddThwompThinker(lines[i].frontsector, &lines[i], crushspeed, retractspeed, sound); P_AddFakeFloorsByLine(i, FF_EXISTS|FF_SOLID|FF_RENDERALL|FF_CUTLEVEL, secthinkers); break; } From a931d09e7d67d48f5877ba592734f15293cdfbc3 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Tue, 10 Nov 2020 13:11:42 +0100 Subject: [PATCH 69/75] Forgot to change %d to %s for sizeu1(). --- src/p_spec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index f512e4583..c0b9983d1 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -5510,7 +5510,7 @@ static ffloor_t *P_AddFakeFloor(sector_t *sec, sector_t *sec2, line_t *master, f { fixed_t tempceiling = sec2->ceilingheight; //flip the sector around and print an error instead of crashing 12.1.08 -Inuyasha - CONS_Alert(CONS_ERROR, M_GetText("FOF (line %d) has a top height below its bottom.\n"), sizeu1(master - lines)); + CONS_Alert(CONS_ERROR, M_GetText("FOF (line %s) has a top height below its bottom.\n"), sizeu1(master - lines)); sec2->ceilingheight = sec2->floorheight; sec2->floorheight = tempceiling; } From a8f554075f784239e3df7ea2a80fa64a76a58deb Mon Sep 17 00:00:00 2001 From: Nev3r Date: Thu, 12 Nov 2020 12:25:02 +0100 Subject: [PATCH 70/75] Extern the global tag groups properly. --- src/taglist.c | 4 ++++ src/taglist.h | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/taglist.c b/src/taglist.c index 90608518b..a9879e495 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -15,6 +15,10 @@ #include "z_zone.h" #include "r_data.h" +taggroup_t* tags_sectors[MAXTAGS + 1]; +taggroup_t* tags_lines[MAXTAGS + 1]; +taggroup_t* tags_mapthings[MAXTAGS + 1]; + void Tag_Add (taglist_t* list, const mtag_t tag) { list->tags = Z_Realloc(list->tags, (list->count + 1) * sizeof(list->tags), PU_LEVEL, NULL); diff --git a/src/taglist.h b/src/taglist.h index 52979b55f..f3895eabb 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -44,9 +44,9 @@ typedef struct size_t count; } taggroup_t; -taggroup_t* tags_sectors[MAXTAGS + 1]; -taggroup_t* tags_lines[MAXTAGS + 1]; -taggroup_t* tags_mapthings[MAXTAGS + 1]; +extern taggroup_t* tags_sectors[]; +extern taggroup_t* tags_lines[]; +extern taggroup_t* tags_mapthings[]; void Taggroup_Add (taggroup_t *garray[], const mtag_t tag, size_t id); void Taggroup_Remove (taggroup_t *garray[], const mtag_t tag, size_t id); From 2c8a99f25ac0ba76ca24894e4f86608a66f920a3 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Thu, 12 Nov 2020 13:48:14 +0100 Subject: [PATCH 71/75] Add a level parameter to the iterators to account for nesting, and thus avoid variable shadowing. --- src/p_ceilng.c | 8 +-- src/p_floor.c | 50 +++++++++---------- src/p_lights.c | 4 +- src/p_mobj.c | 8 +-- src/p_setup.c | 8 +-- src/p_slopes.c | 4 +- src/p_spec.c | 132 ++++++++++++++++++++++++------------------------- src/taglist.h | 10 ++-- 8 files changed, 112 insertions(+), 112 deletions(-) diff --git a/src/p_ceilng.c b/src/p_ceilng.c index 0cea8c52f..f12499d5c 100644 --- a/src/p_ceilng.c +++ b/src/p_ceilng.c @@ -395,9 +395,9 @@ INT32 EV_DoCeiling(line_t *line, ceiling_e type) sector_t *sec; ceiling_t *ceiling; mtag_t tag = Tag_FGet(&line->tags); - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); - TAG_ITER_SECTORS(tag, secnum) + TAG_ITER_SECTORS(0, tag, secnum) { sec = §ors[secnum]; @@ -617,9 +617,9 @@ INT32 EV_DoCrush(line_t *line, ceiling_e type) sector_t *sec; ceiling_t *ceiling; mtag_t tag = Tag_FGet(&line->tags); - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); - TAG_ITER_SECTORS(tag, secnum) + TAG_ITER_SECTORS(0, tag, secnum) { sec = §ors[secnum]; diff --git a/src/p_floor.c b/src/p_floor.c index 98a26039a..ed49b03a3 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -635,7 +635,7 @@ void T_BounceCheese(bouncecheese_t *bouncer) boolean remove; INT32 i; mtag_t tag = Tag_FGet(&bouncer->sourceline->tags); - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); if (bouncer->sector->crumblestate == CRUMBLE_RESTORE || bouncer->sector->crumblestate == CRUMBLE_WAIT || bouncer->sector->crumblestate == CRUMBLE_ACTIVATED) // Oops! Crumbler says to remove yourself! @@ -650,7 +650,7 @@ void T_BounceCheese(bouncecheese_t *bouncer) } // You can use multiple target sectors, but at your own risk!!! - TAG_ITER_SECTORS(tag, i) + TAG_ITER_SECTORS(0, tag, i) { actionsector = §ors[i]; actionsector->moved = true; @@ -775,7 +775,7 @@ void T_StartCrumble(crumble_t *crumble) sector_t *sector; INT32 i; mtag_t tag = Tag_FGet(&crumble->sourceline->tags); - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); // Once done, the no-return thinker just sits there, // constantly 'returning'... kind of an oxymoron, isn't it? @@ -804,7 +804,7 @@ void T_StartCrumble(crumble_t *crumble) } else if (++crumble->timer == 0) // Reposition back to original spot { - TAG_ITER_SECTORS(tag, i) + TAG_ITER_SECTORS(0, tag, i) { sector = §ors[i]; @@ -840,7 +840,7 @@ void T_StartCrumble(crumble_t *crumble) // Flash to indicate that the platform is about to return. if (crumble->timer > -224 && (leveltime % ((abs(crumble->timer)/8) + 1) == 0)) { - TAG_ITER_SECTORS(tag, i) + TAG_ITER_SECTORS(0, tag, i) { sector = §ors[i]; @@ -932,7 +932,7 @@ void T_StartCrumble(crumble_t *crumble) P_RemoveThinker(&crumble->thinker); } - TAG_ITER_SECTORS(tag, i) + TAG_ITER_SECTORS(0, tag, i) { sector = §ors[i]; sector->moved = true; @@ -948,7 +948,7 @@ void T_StartCrumble(crumble_t *crumble) void T_MarioBlock(mariothink_t *block) { INT32 i; - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); T_MovePlane ( @@ -983,7 +983,7 @@ void T_MarioBlock(mariothink_t *block) block->sector->ceilspeed = 0; block->direction = 0; } - TAG_ITER_SECTORS((INT16)block->tag, i) + TAG_ITER_SECTORS(0, (INT16)block->tag, i) P_RecalcPrecipInSector(§ors[i]); } @@ -1295,9 +1295,9 @@ void T_NoEnemiesSector(noenemies_t *nobaddies) INT32 secnum = -1; boolean FOFsector = false; mtag_t tag = Tag_FGet(&nobaddies->sourceline->tags); - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); - TAG_ITER_SECTORS(tag, secnum) + TAG_ITER_SECTORS(0, tag, secnum) { sec = §ors[secnum]; @@ -1308,14 +1308,14 @@ void T_NoEnemiesSector(noenemies_t *nobaddies) { INT32 targetsecnum = -1; mtag_t tag2 = Tag_FGet(&sec->lines[i]->tags); - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(1); if (sec->lines[i]->special < 100 || sec->lines[i]->special >= 300) continue; FOFsector = true; - TAG_ITER_SECTORS(tag2, targetsecnum) + TAG_ITER_SECTORS(1, tag2, targetsecnum) { if (T_SectorHasEnemies(§ors[targetsecnum])) return; @@ -1402,7 +1402,7 @@ void T_EachTimeThinker(eachtime_t *eachtime) fixed_t bottomheight, topheight; ffloor_t *rover; mtag_t tag = Tag_FGet(&eachtime->sourceline->tags); - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); for (i = 0; i < MAXPLAYERS; i++) { @@ -1412,7 +1412,7 @@ void T_EachTimeThinker(eachtime_t *eachtime) eachtime->playersOnArea[i] = false; } - TAG_ITER_SECTORS(tag, secnum) + TAG_ITER_SECTORS(0, tag, secnum) { sec = §ors[secnum]; @@ -1430,14 +1430,14 @@ void T_EachTimeThinker(eachtime_t *eachtime) { INT32 targetsecnum = -1; mtag_t tag2 = Tag_FGet(&sec->lines[i]->tags); - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(1); if (sec->lines[i]->special < 100 || sec->lines[i]->special >= 300) continue; FOFsector = true; - TAG_ITER_SECTORS(tag2, targetsecnum) + TAG_ITER_SECTORS(1, tag2, targetsecnum) { targetsec = §ors[targetsecnum]; @@ -1572,12 +1572,12 @@ void T_RaiseSector(raise_t *raise) INT32 direction; result_e res = 0; mtag_t tag = raise->tag; - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); if (raise->sector->crumblestate >= CRUMBLE_FALL || raise->sector->ceilingdata) return; - TAG_ITER_SECTORS(tag, i) + TAG_ITER_SECTORS(0, tag, i) { sector = §ors[i]; @@ -1704,7 +1704,7 @@ void T_RaiseSector(raise_t *raise) raise->sector->ceilspeed = 42; raise->sector->floorspeed = speed*direction; - TAG_ITER_SECTORS(tag, i) + TAG_ITER_SECTORS(0, tag, i) P_RecalcPrecipInSector(§ors[i]); } @@ -1822,9 +1822,9 @@ void EV_DoFloor(line_t *line, floor_e floortype) sector_t *sec; floormove_t *dofloor; mtag_t tag = Tag_FGet(&line->tags); - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); - TAG_ITER_SECTORS(tag, secnum) + TAG_ITER_SECTORS(0, tag, secnum) { sec = §ors[secnum]; @@ -2039,10 +2039,10 @@ void EV_DoElevator(line_t *line, elevator_e elevtype, boolean customspeed) sector_t *sec; elevator_t *elevator; mtag_t tag = Tag_FGet(&line->tags); - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); // act on all sectors with the same tag as the triggering linedef - TAG_ITER_SECTORS(tag, secnum) + TAG_ITER_SECTORS(0, tag, secnum) { sec = §ors[secnum]; @@ -2339,7 +2339,7 @@ INT32 EV_StartCrumble(sector_t *sec, ffloor_t *rover, boolean floating, sector_t *foundsec; INT32 i; mtag_t tag = Tag_FGet(&rover->master->tags); - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); // If floor is already activated, skip it if (sec->floordata) @@ -2382,7 +2382,7 @@ INT32 EV_StartCrumble(sector_t *sec, ffloor_t *rover, boolean floating, crumble->sector->crumblestate = CRUMBLE_ACTIVATED; - TAG_ITER_SECTORS(tag, i) + TAG_ITER_SECTORS(0, tag, i) { foundsec = §ors[i]; diff --git a/src/p_lights.c b/src/p_lights.c index 326549477..d396e92d3 100644 --- a/src/p_lights.c +++ b/src/p_lights.c @@ -374,10 +374,10 @@ void P_FadeLightBySector(sector_t *sector, INT32 destvalue, INT32 speed, boolean void P_FadeLight(INT16 tag, INT32 destvalue, INT32 speed, boolean ticbased, boolean force) { INT32 i; - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); // search all sectors for ones with tag - TAG_ITER_SECTORS(tag, i) + TAG_ITER_SECTORS(0, tag, i) { if (!force && ticbased // always let speed fader execute && sectors[i].lightingdata diff --git a/src/p_mobj.c b/src/p_mobj.c index 2ae24b402..989f60c98 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -4631,9 +4631,9 @@ static boolean P_Boss4MoveCage(mobj_t *mobj, fixed_t delta) INT32 snum; sector_t *sector; boolean gotcage = false; - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); - TAG_ITER_SECTORS(tag, snum) + TAG_ITER_SECTORS(0, tag, snum) { sector = §ors[snum]; sector->floorheight += delta; @@ -4717,9 +4717,9 @@ static void P_Boss4DestroyCage(mobj_t *mobj) size_t a; sector_t *sector, *rsec; ffloor_t *rover; - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); - TAG_ITER_SECTORS(tag, snum) + TAG_ITER_SECTORS(0, tag, snum) { sector = §ors[snum]; diff --git a/src/p_setup.c b/src/p_setup.c index dd49ae0be..102c9b9a7 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2971,9 +2971,9 @@ static void P_ConvertBinaryMap(void) INT32 check = -1; INT32 paramline = -1; - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); - TAG_ITER_LINES(tag, check) + TAG_ITER_LINES(0, tag, check) { if (lines[check].special == 22) { @@ -3188,11 +3188,11 @@ static void P_ConvertBinaryMap(void) INT32 firstline = -1; mtag_t tag = mapthings[i].angle; - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); Tag_FSet(&mapthings[i].tags, tag); - TAG_ITER_LINES(tag, check) + TAG_ITER_LINES(0, tag, check) { if (lines[check].special == 20) { diff --git a/src/p_slopes.c b/src/p_slopes.c index 80278451a..aa46a8402 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -546,11 +546,11 @@ static boolean P_SetSlopeFromTag(sector_t *sec, INT32 tag, boolean ceiling) { INT32 i; pslope_t **secslope = ceiling ? &sec->c_slope : &sec->f_slope; - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); if (!tag || *secslope) return false; - TAG_ITER_SECTORS(tag, i) + TAG_ITER_SECTORS(0, tag, i) { pslope_t *srcslope = ceiling ? sectors[i].c_slope : sectors[i].f_slope; if (srcslope) diff --git a/src/p_spec.c b/src/p_spec.c index c0b9983d1..a1afdd00d 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2223,7 +2223,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) INT32 secnum = -1; mobj_t *bot = NULL; mtag_t tag = Tag_FGet(&line->tags); - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); I_Assert(!mo || !P_MobjWasRemoved(mo)); // If mo is there, mo must be valid! @@ -2251,7 +2251,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) newceilinglightsec = line->frontsector->ceilinglightsec; // act on all sectors with the same tag as the triggering linedef - TAG_ITER_SECTORS(tag, secnum) + TAG_ITER_SECTORS(0, tag, secnum) { if (sectors[secnum].lightingdata) { @@ -2306,7 +2306,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) case 409: // Change tagged sectors' tag // (formerly "Change calling sectors' tag", but behavior was changed) { - TAG_ITER_SECTORS(tag, secnum) + TAG_ITER_SECTORS(0, tag, secnum) Tag_SectorFSet(secnum,(INT16)(sides[line->sidenum[0]].textureoffset>>FRACBITS)); break; } @@ -2316,7 +2316,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 411: // Stop floor/ceiling movement in tagged sector(s) - TAG_ITER_SECTORS(tag, secnum) + TAG_ITER_SECTORS(0, tag, secnum) { if (sectors[secnum].floordata) { @@ -2501,7 +2501,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) // Additionally play the sound from tagged sectors' soundorgs sector_t *sec; - TAG_ITER_SECTORS(tag, secnum) + TAG_ITER_SECTORS(0, tag, secnum) { sec = §ors[secnum]; S_StartSound(&sec->soundorg, sfxnum); @@ -2616,7 +2616,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 416: // Spawn adjustable fire flicker - TAG_ITER_SECTORS(tag, secnum) + TAG_ITER_SECTORS(0, tag, secnum) { if (line->flags & ML_NOCLIMB && line->backsector) { @@ -2650,7 +2650,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 417: // Spawn adjustable glowing light - TAG_ITER_SECTORS(tag, secnum) + TAG_ITER_SECTORS(0, tag, secnum) { if (line->flags & ML_NOCLIMB && line->backsector) { @@ -2684,7 +2684,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 418: // Spawn adjustable strobe flash (unsynchronized) - TAG_ITER_SECTORS(tag, secnum) + TAG_ITER_SECTORS(0, tag, secnum) { if (line->flags & ML_NOCLIMB && line->backsector) { @@ -2718,7 +2718,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 419: // Spawn adjustable strobe flash (synchronized) - TAG_ITER_SECTORS(tag, secnum) + TAG_ITER_SECTORS(0, tag, secnum) { if (line->flags & ML_NOCLIMB && line->backsector) { @@ -2766,7 +2766,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 421: // Stop lighting effect in tagged sectors - TAG_ITER_SECTORS(tag, secnum) + TAG_ITER_SECTORS(0, tag, secnum) if (sectors[secnum].lightingdata) { P_RemoveThinker(&((elevator_t *)sectors[secnum].lightingdata)->thinker); @@ -2980,7 +2980,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) ffloor_t *rover; // FOF that we are going to crumble boolean foundrover = false; // for debug, "Can't find a FOF" message - TAG_ITER_SECTORS(sectag, secnum) + TAG_ITER_SECTORS(0, sectag, secnum) { sec = sectors + secnum; @@ -3105,7 +3105,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (line->sidenum[1] != 0xffff) state = (statenum_t)sides[line->sidenum[1]].toptexture; - TAG_ITER_SECTORS(tag, secnum) + TAG_ITER_SECTORS(0, tag, secnum) { boolean tryagain; sec = sectors + secnum; @@ -3165,7 +3165,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) boolean foundrover = false; // for debug, "Can't find a FOF" message ffloortype_e oldflags; // store FOF's old flags - TAG_ITER_SECTORS(sectag, secnum) + TAG_ITER_SECTORS(0, sectag, secnum) { sec = sectors + secnum; @@ -3223,7 +3223,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (line->flags & ML_NOCLIMB) // don't respawn! respawn = false; - TAG_ITER_SECTORS(sectag, secnum) + TAG_ITER_SECTORS(0, sectag, secnum) { sec = sectors + secnum; @@ -3279,7 +3279,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) source = sectors[sourcesec].extra_colormap; } } - TAG_ITER_SECTORS(line->args[0], secnum) + TAG_ITER_SECTORS(0, line->args[0], secnum) { if (sectors[secnum].colormap_protected) continue; @@ -3414,7 +3414,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) ffloor_t *rover; // FOF that we are going to operate boolean foundrover = false; // for debug, "Can't find a FOF" message - TAG_ITER_SECTORS(sectag, secnum) + TAG_ITER_SECTORS(0, sectag, secnum) { sec = sectors + secnum; @@ -3478,7 +3478,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) boolean foundrover = false; // for debug, "Can't find a FOF" message size_t j = 0; // sec->ffloors is saved as ffloor #0, ss->ffloors->next is #1, etc - TAG_ITER_SECTORS(sectag, secnum) + TAG_ITER_SECTORS(0, sectag, secnum) { sec = sectors + secnum; @@ -3563,7 +3563,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) ffloor_t *rover; // FOF that we are going to operate boolean foundrover = false; // for debug, "Can't find a FOF" message - TAG_ITER_SECTORS(sectag, secnum) + TAG_ITER_SECTORS(0, sectag, secnum) { sec = sectors + secnum; @@ -3614,7 +3614,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) } } - TAG_ITER_SECTORS(line->args[0], secnum) + TAG_ITER_SECTORS(0, line->args[0], secnum) { extracolormap_t *source_exc, *dest_exc, *exc; @@ -3694,7 +3694,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; } case 456: // Stop fade colormap - TAG_ITER_SECTORS(line->args[0], secnum) + TAG_ITER_SECTORS(0, line->args[0], secnum) P_ResetColormapFader(§ors[secnum]); break; @@ -3887,12 +3887,12 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) case 465: // Set linedef executor delay { INT32 linenum; - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(1); if (!udmf) break; - TAG_ITER_LINES(line->args[0], linenum) + TAG_ITER_LINES(1, line->args[0], linenum) { if (line->args[2]) lines[linenum].executordelay += line->args[1]; @@ -5922,9 +5922,9 @@ void T_LaserFlash(laserthink_t *flash) sector_t *sector; sector_t *sourcesec = flash->sourceline->frontsector; fixed_t top, bottom; - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); - TAG_ITER_SECTORS(flash->tag, s) + TAG_ITER_SECTORS(0, flash->tag, s) { sector = §ors[s]; for (fflr = sector->ffloors; fflr; fflr = fflr->next) @@ -6204,11 +6204,11 @@ void P_SpawnSpecials(boolean fromnetsave) INT32 s; size_t sec; ffloortype_e ffloorflags; - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); case 1: // Definable gravity per sector sec = sides[*lines[i].sidenum].sector - sectors; - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) { sectors[s].gravity = §ors[sec].floorheight; // This allows it to change in realtime! @@ -6232,7 +6232,7 @@ void P_SpawnSpecials(boolean fromnetsave) case 5: // Change camera info sec = sides[*lines[i].sidenum].sector - sectors; - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) P_AddCameraScanner(§ors[sec], §ors[s], R_PointToAngle2(lines[i].v2->x, lines[i].v2->y, lines[i].v1->x, lines[i].v1->y)); break; @@ -6259,7 +6259,7 @@ void P_SpawnSpecials(boolean fromnetsave) P_ApplyFlatAlignment(lines + i, lines[i].frontsector, flatangle, xoffs, yoffs); else { - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) P_ApplyFlatAlignment(lines + i, sectors + s, flatangle, xoffs, yoffs); } } @@ -6270,7 +6270,7 @@ void P_SpawnSpecials(boolean fromnetsave) break; case 8: // Sector Parameters - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) { if (lines[i].flags & ML_NOCLIMB) { @@ -6297,7 +6297,7 @@ void P_SpawnSpecials(boolean fromnetsave) break; case 10: // Vertical culling plane for sprites and FOFs - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) sectors[s].cullheight = &lines[i]; // This allows it to change in realtime! break; @@ -6358,19 +6358,19 @@ void P_SpawnSpecials(boolean fromnetsave) case 63: // support for drawn heights coming from different sector sec = sides[*lines[i].sidenum].sector-sectors; - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) sectors[s].heightsec = (INT32)sec; break; case 64: // Appearing/Disappearing FOF option if (lines[i].flags & ML_BLOCKMONSTERS) { // Find FOFs by control sector tag - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) for (j = 0; (unsigned)j < sectors[s].linecount; j++) if (sectors[s].lines[j]->special >= 100 && sectors[s].lines[j]->special < 300) Add_MasterDisappearer(abs(lines[i].dx>>FRACBITS), abs(lines[i].dy>>FRACBITS), abs(sides[lines[i].sidenum[0]].sector->floorheight>>FRACBITS), (INT32)(sectors[s].lines[j]-lines), (INT32)i); } else // Find FOFs by effect sector tag { - TAG_ITER_LINES(tag, s) + TAG_ITER_LINES(0, tag, s) { if ((size_t)s == i) continue; @@ -6381,15 +6381,15 @@ void P_SpawnSpecials(boolean fromnetsave) break; case 66: // Displace floor by front sector - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) P_AddPlaneDisplaceThinker(pd_floor, P_AproxDistance(lines[i].dx, lines[i].dy)>>8, sides[lines[i].sidenum[0]].sector-sectors, s, !!(lines[i].flags & ML_NOCLIMB)); break; case 67: // Displace ceiling by front sector - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) P_AddPlaneDisplaceThinker(pd_ceiling, P_AproxDistance(lines[i].dx, lines[i].dy)>>8, sides[lines[i].sidenum[0]].sector-sectors, s, !!(lines[i].flags & ML_NOCLIMB)); break; case 68: // Displace both floor AND ceiling by front sector - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) P_AddPlaneDisplaceThinker(pd_both, P_AproxDistance(lines[i].dx, lines[i].dy)>>8, sides[lines[i].sidenum[0]].sector-sectors, s, !!(lines[i].flags & ML_NOCLIMB)); break; @@ -6985,46 +6985,46 @@ void P_SpawnSpecials(boolean fromnetsave) case 600: // floor lighting independently (e.g. lava) sec = sides[*lines[i].sidenum].sector-sectors; - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) sectors[s].floorlightsec = (INT32)sec; break; case 601: // ceiling lighting independently sec = sides[*lines[i].sidenum].sector-sectors; - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) sectors[s].ceilinglightsec = (INT32)sec; break; case 602: // Adjustable pulsating light sec = sides[*lines[i].sidenum].sector - sectors; - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) P_SpawnAdjustableGlowingLight(§ors[sec], §ors[s], P_AproxDistance(lines[i].dx, lines[i].dy)>>FRACBITS); break; case 603: // Adjustable flickering light sec = sides[*lines[i].sidenum].sector - sectors; - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) P_SpawnAdjustableFireFlicker(§ors[sec], §ors[s], P_AproxDistance(lines[i].dx, lines[i].dy)>>FRACBITS); break; case 604: // Adjustable Blinking Light (unsynchronized) sec = sides[*lines[i].sidenum].sector - sectors; - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) P_SpawnAdjustableStrobeFlash(§ors[sec], §ors[s], abs(lines[i].dx)>>FRACBITS, abs(lines[i].dy)>>FRACBITS, false); break; case 605: // Adjustable Blinking Light (synchronized) sec = sides[*lines[i].sidenum].sector - sectors; - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) P_SpawnAdjustableStrobeFlash(§ors[sec], §ors[s], abs(lines[i].dx)>>FRACBITS, abs(lines[i].dy)>>FRACBITS, true); break; case 606: // HACK! Copy colormaps. Just plain colormaps. - TAG_ITER_SECTORS(lines[i].args[0], s) + TAG_ITER_SECTORS(0, lines[i].args[0], s) { extracolormap_t *exc; @@ -7098,13 +7098,13 @@ void P_SpawnSpecials(boolean fromnetsave) */ static void P_AddFakeFloorsByLine(size_t line, ffloortype_e ffloorflags, thinkerlist_t *secthinkers) { - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); INT32 s; mtag_t tag = Tag_FGet(&lines[line].tags); size_t sec = sides[*lines[line].sidenum].sector-sectors; line_t* li = lines + line; - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) P_AddFakeFloor(§ors[s], §ors[sec], li, ffloorflags, secthinkers); } @@ -7214,7 +7214,7 @@ void T_Scroll(scroll_t *s) size_t i; INT32 sect; ffloor_t *rover; - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); case sc_side: // scroll wall texture side = sides + s->affectee; @@ -7251,7 +7251,7 @@ void T_Scroll(scroll_t *s) if (!is3dblock) continue; - TAG_ITER_SECTORS(Tag_FGet(&line->tags), sect) + TAG_ITER_SECTORS(0, Tag_FGet(&line->tags), sect) { sector_t *psec; psec = sectors + sect; @@ -7326,7 +7326,7 @@ void T_Scroll(scroll_t *s) if (!is3dblock) continue; - TAG_ITER_SECTORS(Tag_FGet(&line->tags), sect) + TAG_ITER_SECTORS(0, Tag_FGet(&line->tags), sect) { sector_t *psec; psec = sectors + sect; @@ -7466,11 +7466,11 @@ static void P_SpawnScrollers(void) switch (special) { register INT32 s; - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); case 513: // scroll effect ceiling case 533: // scroll and carry objects on ceiling - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) Add_Scroller(sc_ceiling, -dx, dy, control, s, accel, l->flags & ML_NOCLIMB); if (special != 533) break; @@ -7479,13 +7479,13 @@ static void P_SpawnScrollers(void) case 523: // carry objects on ceiling dx = FixedMul(dx, CARRYFACTOR); dy = FixedMul(dy, CARRYFACTOR); - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) Add_Scroller(sc_carry_ceiling, dx, dy, control, s, accel, l->flags & ML_NOCLIMB); break; case 510: // scroll effect floor case 530: // scroll and carry objects on floor - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) Add_Scroller(sc_floor, -dx, dy, control, s, accel, l->flags & ML_NOCLIMB); if (special != 530) break; @@ -7494,7 +7494,7 @@ static void P_SpawnScrollers(void) case 520: // carry objects on floor dx = FixedMul(dx, CARRYFACTOR); dy = FixedMul(dy, CARRYFACTOR); - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) Add_Scroller(sc_carry, dx, dy, control, s, accel, l->flags & ML_NOCLIMB); break; @@ -7502,7 +7502,7 @@ static void P_SpawnScrollers(void) // (same direction and speed as scrolling floors) case 502: { - TAG_ITER_LINES(tag, s) + TAG_ITER_LINES(0, tag, s) if (s != (INT32)i) { if (l->flags & ML_EFFECT2) // use texture offsets instead @@ -7604,9 +7604,9 @@ void T_Disappear(disappear_t *d) ffloor_t *rover; register INT32 s; mtag_t afftag = Tag_FGet(&lines[d->affectee].tags); - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); - TAG_ITER_SECTORS(afftag, s) + TAG_ITER_SECTORS(0, afftag, s) { for (rover = sectors[s].ffloors; rover; rover = rover->next) { @@ -8337,7 +8337,7 @@ static void P_SpawnFriction(void) fixed_t strength; // frontside texture offset controls magnitude fixed_t friction; // friction value to be applied during movement INT32 movefactor; // applied to each player move to simulate inertia - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); for (i = 0; i < numlines; i++, l++) if (l->special == 540) @@ -8363,7 +8363,7 @@ static void P_SpawnFriction(void) else movefactor = FRACUNIT; - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) Add_Friction(friction, movefactor, s, -1); } } @@ -8882,7 +8882,7 @@ static void P_SpawnPushers(void) mtag_t tag; register INT32 s; mobj_t *thing; - TAG_ITER_DECLARECOUNTER; + TAG_ITER_DECLARECOUNTER(0); for (i = 0; i < numlines; i++, l++) { @@ -8890,15 +8890,15 @@ static void P_SpawnPushers(void) switch (l->special) { case 541: // wind - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) Add_Pusher(p_wind, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; case 544: // current - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) Add_Pusher(p_current, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; case 547: // push/pull - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) { thing = P_GetPushThing(s); if (thing) // No MT_P* means no effect @@ -8906,19 +8906,19 @@ static void P_SpawnPushers(void) } break; case 545: // current up - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) Add_Pusher(p_upcurrent, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; case 546: // current down - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) Add_Pusher(p_downcurrent, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; case 542: // wind up - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) Add_Pusher(p_upwind, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; case 543: // wind down - TAG_ITER_SECTORS(tag, s) + TAG_ITER_SECTORS(0, tag, s) Add_Pusher(p_downwind, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); break; } diff --git a/src/taglist.h b/src/taglist.h index f3895eabb..3a724aef3 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -62,13 +62,13 @@ INT32 Tag_FindLineSpecial(const INT16 special, const mtag_t tag); INT32 P_FindSpecialLineFromTag(INT16 special, INT16 tag, INT32 start); // Use this macro to declare the iterator position variable. -#define TAG_ITER_DECLARECOUNTER size_t tag_iterator_pos +#define TAG_ITER_DECLARECOUNTER(level) size_t ICNT_##level -#define TAG_ITER(fn, tag, id) for(tag_iterator_pos = 0; (id = fn(tag, tag_iterator_pos)) >= 0; tag_iterator_pos++) +#define TAG_ITER(level, fn, tag, id) for(ICNT_##level = 0; (id = fn(tag, ICNT_##level)) >= 0; ICNT_##level++) // Use these macros as wrappers for the taglist iterations. -#define TAG_ITER_SECTORS(tag, id) TAG_ITER(Tag_Iterate_Sectors, tag, id) -#define TAG_ITER_LINES(tag, id) TAG_ITER(Tag_Iterate_Lines, tag, id) -#define TAG_ITER_THINGS(tag, id) TAG_ITER(Tag_Iterate_Things, tag, id) +#define TAG_ITER_SECTORS(level, tag, id) TAG_ITER(level, Tag_Iterate_Sectors, tag, id) +#define TAG_ITER_LINES(level, tag, id) TAG_ITER(level, Tag_Iterate_Lines, tag, id) +#define TAG_ITER_THINGS(level, tag, id) TAG_ITER(level, Tag_Iterate_Things, tag, id) #endif //__R_TAGLIST__ From 072e1889e2959d79c316b48126a4ea4b06f12f45 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Thu, 12 Nov 2020 13:59:21 +0100 Subject: [PATCH 72/75] Fix size_t/INT32 compare. --- src/taglist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/taglist.c b/src/taglist.c index a9879e495..e0bb86c97 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -276,7 +276,7 @@ INT32 Tag_Iterate_Things (const mtag_t tag, const size_t p) INT32 Tag_FindLineSpecial(const INT16 special, const mtag_t tag) { - INT32 i; + size_t i; if (tag == MTAG_GLOBAL) { From cc98be4d232323ccb989a9792f3382df366535fe Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sat, 14 Nov 2020 20:25:00 +0100 Subject: [PATCH 73/75] Add documentation for the iterator macros. --- src/taglist.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/src/taglist.h b/src/taglist.h index 3a724aef3..a1dfe479e 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -61,14 +61,68 @@ INT32 Tag_Iterate_Things (const mtag_t tag, const size_t p); INT32 Tag_FindLineSpecial(const INT16 special, const mtag_t tag); INT32 P_FindSpecialLineFromTag(INT16 special, INT16 tag, INT32 start); -// Use this macro to declare the iterator position variable. +// Use this macro to declare an iterator position variable. #define TAG_ITER_DECLARECOUNTER(level) size_t ICNT_##level -#define TAG_ITER(level, fn, tag, id) for(ICNT_##level = 0; (id = fn(tag, ICNT_##level)) >= 0; ICNT_##level++) +#define TAG_ITER(level, fn, tag, return_varname) for(ICNT_##level = 0; (return_varname = fn(tag, ICNT_##level)) >= 0; ICNT_##level++) -// Use these macros as wrappers for the taglist iterations. -#define TAG_ITER_SECTORS(level, tag, id) TAG_ITER(level, Tag_Iterate_Sectors, tag, id) -#define TAG_ITER_LINES(level, tag, id) TAG_ITER(level, Tag_Iterate_Lines, tag, id) -#define TAG_ITER_THINGS(level, tag, id) TAG_ITER(level, Tag_Iterate_Things, tag, id) +// Use these macros as wrappers for a taglist iteration. +#define TAG_ITER_SECTORS(level, tag, return_varname) TAG_ITER(level, Tag_Iterate_Sectors, tag, return_varname) +#define TAG_ITER_LINES(level, tag, return_varname) TAG_ITER(level, Tag_Iterate_Lines, tag, return_varname) +#define TAG_ITER_THINGS(level, tag, return_varname) TAG_ITER(level, Tag_Iterate_Things, tag, return_varname) + +/* ITERATION MACROS +TAG_ITER_DECLARECOUNTER must be used before using the iterators. + +'level': +For each nested iteration, an additional TAG_ITER_DECLARECOUNTER +must be used with a different level number to avoid conflict with +the outer iterations. +Most cases don't have nested iterations and thus the level is just 0. + +'tag': +Pretty much the elements' tag to iterate through. + +'return_varname': +Target variable's name to return the iteration results to. + + +EXAMPLE: +{ + TAG_ITER_DECLARECOUNTER(0); + TAG_ITER_DECLARECOUNTER(1); // For the nested iteration. + + size_t li; + size_t sec; + + INT32 tag1 = 4; + + ... + + TAG_ITER_LINES(0, tag1, li) + { + line_t *line = lines + li; + + ... + + if (something) + { + mtag_t tag2 = 8; + + // Nested iteration; just make sure the level is higher + // and that it has its own counter declared in scope. + TAG_ITER_SECTORS(1, tag2, sec) + { + sector_t *sector = sectors + sec; + + ... + } + } + } +} + +Notes: +If no elements are found for a given tag, the loop inside won't be executed. +*/ #endif //__R_TAGLIST__ From 3a8b2a6fb779b8b1fbc94acad5950b59987b20e4 Mon Sep 17 00:00:00 2001 From: Nev3r Date: Sat, 14 Nov 2020 20:50:34 +0100 Subject: [PATCH 74/75] Better documentation. --- src/taglist.c | 17 ++++++++++++++++- src/taglist.h | 5 ++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/taglist.c b/src/taglist.c index e0bb86c97..b11216b6c 100644 --- a/src/taglist.c +++ b/src/taglist.c @@ -15,10 +15,15 @@ #include "z_zone.h" #include "r_data.h" +// Taggroups are used to list elements of the same tag, for iteration. +// Since elements can now have multiple tags, it means an element may appear +// in several taggroups at the same time. These are built on level load. taggroup_t* tags_sectors[MAXTAGS + 1]; taggroup_t* tags_lines[MAXTAGS + 1]; taggroup_t* tags_mapthings[MAXTAGS + 1]; +/// Adds a tag to a given element's taglist. +/// \warning This does not rebuild the global taggroups, which are used for iteration. void Tag_Add (taglist_t* list, const mtag_t tag) { list->tags = Z_Realloc(list->tags, (list->count + 1) * sizeof(list->tags), PU_LEVEL, NULL); @@ -26,6 +31,7 @@ void Tag_Add (taglist_t* list, const mtag_t tag) } /// Sets the first tag entry in a taglist. +/// Replicates the old way of accessing element->tag. void Tag_FSet (taglist_t* list, const mtag_t tag) { if (!list->count) @@ -38,6 +44,7 @@ void Tag_FSet (taglist_t* list, const mtag_t tag) } /// Gets the first tag entry in a taglist. +/// Replicates the old way of accessing element->tag. mtag_t Tag_FGet (const taglist_t* list) { if (list->count) @@ -46,6 +53,7 @@ mtag_t Tag_FGet (const taglist_t* list) return 0; } +/// Returns true if the given tag exist inside the list. boolean Tag_Find (const taglist_t* list, const mtag_t tag) { size_t i; @@ -56,6 +64,7 @@ boolean Tag_Find (const taglist_t* list, const mtag_t tag) return false; } +/// Returns true if at least one tag is shared between two given lists. boolean Tag_Share (const taglist_t* list1, const taglist_t* list2) { size_t i; @@ -66,6 +75,7 @@ boolean Tag_Share (const taglist_t* list1, const taglist_t* list2) return false; } +/// Returns true if both lists are identical. boolean Tag_Compare (const taglist_t* list1, const taglist_t* list2) { size_t i; @@ -80,7 +90,7 @@ boolean Tag_Compare (const taglist_t* list1, const taglist_t* list2) return true; } - +/// Search for an element inside a global taggroup. size_t Taggroup_Find (const taggroup_t *group, const size_t id) { size_t i; @@ -95,6 +105,7 @@ size_t Taggroup_Find (const taggroup_t *group, const size_t id) return -1; } +/// Add an element to a global taggroup. void Taggroup_Add (taggroup_t *garray[], const mtag_t tag, size_t id) { taggroup_t *group; @@ -135,6 +146,7 @@ void Taggroup_Add (taggroup_t *garray[], const mtag_t tag, size_t id) group->elements[i] = id; } +/// Remove an element from a global taggroup. void Taggroup_Remove (taggroup_t *garray[], const mtag_t tag, size_t id) { taggroup_t *group; @@ -191,6 +203,8 @@ static void Taglist_AddToMapthings (const mtag_t tag, const size_t itemid) Taggroup_Add(tags_mapthings, tag, itemid); } +/// After all taglists have been built for each element (sectors, lines, things), +/// the global taggroups, made for iteration, are built here. void Taglist_InitGlobalTables(void) { size_t i, j; @@ -338,6 +352,7 @@ INT32 P_FindSpecialLineFromTag(INT16 special, INT16 tag, INT32 start) // Ingame list manipulation. +/// Changes the first tag for a given sector, and updates the global taggroups. void Tag_SectorFSet (const size_t id, const mtag_t tag) { sector_t* sec = §ors[id]; diff --git a/src/taglist.h b/src/taglist.h index a1dfe479e..0e6d9f842 100644 --- a/src/taglist.h +++ b/src/taglist.h @@ -20,7 +20,7 @@ typedef INT16 mtag_t; #define MAXTAGS UINT16_MAX #define MTAG_GLOBAL -1 -/// Multitag list. +/// Multitag list. Each taggable element will have its own taglist. typedef struct { mtag_t* tags; @@ -28,16 +28,15 @@ typedef struct } taglist_t; void Tag_Add (taglist_t* list, const mtag_t tag); - void Tag_FSet (taglist_t* list, const mtag_t tag); mtag_t Tag_FGet (const taglist_t* list); boolean Tag_Find (const taglist_t* list, const mtag_t tag); boolean Tag_Share (const taglist_t* list1, const taglist_t* list2); - boolean Tag_Compare (const taglist_t* list1, const taglist_t* list2); void Tag_SectorFSet (const size_t id, const mtag_t tag); +/// Taggroup list. It is essentially just an element id list. typedef struct { size_t *elements; From d3199ac779cce0f05651b117324d6cf87432236d Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 14 Nov 2020 16:18:54 -0800 Subject: [PATCH 75/75] Fix one last instance of printing address diff --- 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 102c9b9a7..d3e91d71a 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1341,7 +1341,7 @@ static void P_LoadSidedefs(UINT8 *data) || (msd->toptexture[0] >= 'A' && msd->toptexture[0] <= 'F')) sd->toptexture = axtoi(msd->toptexture); else - I_Error("Custom FOF (line id %d) needs a value in the linedef's back side upper texture field.", sd->line - lines); + I_Error("Custom FOF (line id %s) needs a value in the linedef's back side upper texture field.", sizeu1(sd->line - lines)); sd->midtexture = R_TextureNumForName(msd->midtexture); sd->bottomtexture = R_TextureNumForName(msd->bottomtexture);