mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-02-27 14:10:47 +00:00
Make use of functions for the tag lists iterations instead of bloated macros.
This commit is contained in:
parent
8495b59890
commit
5df60f8e15
2 changed files with 66 additions and 11 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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__
|
||||
|
|
Loading…
Reference in a new issue