raze/source/core/iterators.h
Christoph Oelckers 999ec3c95a use validSectorIndex checks where appropriate.
Let’s hope that this sloppiness doesn’t have negative effects with broken maps.

# Conflicts:
#	source/games/sw/src/sprite.cpp

# Conflicts:
#	source/games/duke/src/prediction.cpp
#	source/games/duke/src/render.cpp
2021-12-25 21:28:37 +01:00

84 lines
1.3 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(validSectorIndex(stat));
next = headspritesect[stat];
}
SectIterator(sectortype* sect)
{
assert(sect);
next = headspritesect[sect - sector];
}
void Reset(int stat)
{
assert(validSectorIndex(stat));
next = headspritesect[stat];
}
void Reset(sectortype* sect)
{
assert(sect);
next = headspritesect[sect - sector];
}
int NextIndex()
{
int n = next;
if (n >= 0) next = nextspritesect[next];
return n;
}
int PeekIndex()
{
return next;
}
};