Skip to content
Snippets Groups Projects
Commit 5df60f8e authored by Nev3r's avatar Nev3r
Browse files

Make use of functions for the tag lists iterations instead of bloated macros.

parent 8495b598
No related branches found
No related tags found
1 merge request!1097UDMF: Multitag support
#include "taglist.h" #include "taglist.h"
#include "z_zone.h" #include "z_zone.h"
#include "r_data.h"
void Tag_Add (taglist_t* list, const UINT16 tag) void Tag_Add (taglist_t* list, const UINT16 tag)
{ {
...@@ -56,3 +57,57 @@ void Taglist_AddToMapthings (const size_t tag, const size_t itemid) ...@@ -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 = Z_Realloc(tagelems->elements, tagelems->count * sizeof(size_t), PU_LEVEL, NULL);
tagelems->elements[tagelems->count - 1] = itemid; 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;
}
#include "doomtype.h"
#ifndef __R_TAGLIST__ #ifndef __R_TAGLIST__
#define __R_TAGLIST__ #define __R_TAGLIST__
#include "doomtype.h"
/// Multitag list. /// Multitag list.
typedef struct typedef struct
{ {
...@@ -27,16 +27,16 @@ taggroup_t* tags_mapthings[MAXTAGS]; ...@@ -27,16 +27,16 @@ taggroup_t* tags_mapthings[MAXTAGS];
void Taglist_AddToSectors (const size_t tag, const size_t itemid); void Taglist_AddToSectors (const size_t tag, const size_t itemid);
void Taglist_AddToLines (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_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_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)\ #define TAG_ITER_SECTORS(tag, id) TAG_ITER(Tag_Iterate_Sectors, tag, id)
if (group[tag] || tag == -1) for(\ #define TAG_ITER_LINES(tag, id) TAG_ITER(Tag_Iterate_Lines, tag, id)
tag != -1 ? (id = group[tag]->elements[kkkk = 0]) : (id = 0);\ #define TAG_ITER_THINGS(tag, id) TAG_ITER(Tag_Iterate_Things, tag, id)
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, numsectors, tag, id) #endif //__R_TAGLIST__
#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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment