raze-gles/source/core/iterators.h
Christoph Oelckers c2828fe2e3 fixed undefined end of list behavior of iterators
Also fixed a few warnings
2020-10-18 12:14:05 +02:00

72 lines
1.2 KiB
C++

#pragma once
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;
if (n >= 0) next = nextspritestat[next];
return n;
}
int PeekIndex()
{
return next;
}
// These are only used by one particularly screwy loop in Blood's nnexts.cpp.
static int First(int stat)
{
return headspritestat[stat];
}
static int NextFor(int spr)
{
return nextspritestat[spr];
}
};
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;
if (n >= 0) next = nextspritesect[next];
return n;
}
int PeekIndex()
{
return next;
}
};