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);