- added sprite iterator classes.

The code base currently contains roughly 600 iterator loops directly referencing Build's global variables.
That state of things is not refactorable - these iterator wrappers are supposed to get rid of these explicit references.
This commit is contained in:
Christoph Oelckers 2020-10-14 00:05:25 +02:00
parent bca29ed402
commit b6149f88f7

View file

@ -995,4 +995,66 @@ extern void(*PolymostProcessVoxels_Callback)(void);
#endif
class StatIterator
{
int next;
public:
StatIterator(int stat)
{
assert(stat >= 0 && stat < MAXSTATUS);
next = headspritestat[stat];
}
void Reset(int stat)
{
assert(stat >= 0 && stat < MAXSTATUS);
next = headspritestat[stat];
}
int NextIndex()
{
int n = next;
next = nextspritestat[next];
return n;
}
spritetype *Next()
{
int n = next;
next = nextspritestat[next];
return n < 0? nullptr : &sprite[n];
}
};
class SectIterator
{
int next;
public:
SectIterator(int stat)
{
assert(stat >= 0 && stat < MAXSECTORS);
next = headspritesect[stat];
}
void Reset(int stat)
{
assert(stat >= 0 && stat < MAXSECTORS);
next = headspritesect[stat];
}
int NextIndex()
{
int n = next;
next = nextspritesect[next];
return n;
}
spritetype *Next()
{
int n = next;
next = nextspritestat[next];
return n < 0? nullptr : &sprite[n];
}
};
#endif // build_h_