mirror of
https://github.com/DrBeef/Raze.git
synced 2025-04-04 23:12:58 +00:00
- consolidate the iterators in the backend.
Using a template class that can adapt to the game specific types.
This commit is contained in:
parent
12f6b05cbe
commit
bbb860ccf3
5 changed files with 18 additions and 348 deletions
|
@ -281,8 +281,8 @@ public:
|
|||
{
|
||||
while (index < MAXSPRITES)
|
||||
{
|
||||
auto p = static_cast<TActor*>(actorArray[index++]);
|
||||
if (p->s().statnum != MAXSTATUS) return p;
|
||||
auto p = actorArray[index++];
|
||||
if (p->s().statnum != MAXSTATUS) return static_cast<TActor*>(p);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -168,95 +168,11 @@ extern HitInfo gHitInfo;
|
|||
|
||||
|
||||
// Iterator wrappers that return an actor pointer, not an index.
|
||||
class BloodStatIterator : public StatIterator
|
||||
{
|
||||
public:
|
||||
BloodStatIterator(int stat) : StatIterator(stat)
|
||||
{
|
||||
}
|
||||
|
||||
DBloodActor* Next()
|
||||
{
|
||||
int n = NextIndex();
|
||||
return n >= 0 ? &bloodActors[n] : nullptr;
|
||||
}
|
||||
|
||||
DBloodActor* Peek()
|
||||
{
|
||||
int n = PeekIndex();
|
||||
return n >= 0 ? &bloodActors[n] : nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
class BloodSectIterator : public SectIterator
|
||||
{
|
||||
public:
|
||||
BloodSectIterator(int stat) : SectIterator(stat)
|
||||
{
|
||||
}
|
||||
|
||||
BloodSectIterator(sectortype* stat) : SectIterator(stat)
|
||||
{
|
||||
}
|
||||
|
||||
DBloodActor* Next()
|
||||
{
|
||||
int n = NextIndex();
|
||||
return n >= 0 ? &bloodActors[n] : nullptr;
|
||||
}
|
||||
|
||||
DBloodActor* Peek()
|
||||
{
|
||||
int n = PeekIndex();
|
||||
return n >= 0 ? &bloodActors[n] : nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
// An iterator to iterate over all sprites.
|
||||
class BloodSpriteIterator
|
||||
{
|
||||
BloodStatIterator it;
|
||||
int stat = kStatDecoration;
|
||||
|
||||
public:
|
||||
BloodSpriteIterator() : it(kStatDecoration) {}
|
||||
|
||||
DBloodActor* Next()
|
||||
{
|
||||
while (stat < kStatFree)
|
||||
{
|
||||
auto ac = it.Next();
|
||||
if (ac) return ac;
|
||||
stat++;
|
||||
if (stat < kStatFree) it.Reset(stat);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
// For iterating linearly over map spawned sprites.
|
||||
class BloodLinearSpriteIterator
|
||||
{
|
||||
int index = 0;
|
||||
public:
|
||||
|
||||
void Reset()
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
|
||||
DBloodActor* Next()
|
||||
{
|
||||
while (index < MAXSPRITES)
|
||||
{
|
||||
auto p = &bloodActors[index++];
|
||||
if (p->s().statnum != kStatFree) return p;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
using BloodStatIterator = TStatIterator<DBloodActor>;
|
||||
using BloodSectIterator = TSectIterator<DBloodActor>;
|
||||
using BloodSpriteIterator = TSpriteIterator<DBloodActor>;
|
||||
using BloodLinearSpriteIterator = TLinearSpriteIterator<DBloodActor>;
|
||||
|
||||
inline int DeleteSprite(DBloodActor* nSprite)
|
||||
{
|
||||
|
|
|
@ -5,88 +5,10 @@
|
|||
BEGIN_DUKE_NS
|
||||
|
||||
|
||||
// Iterator wrappers that return an actor pointer, not an index.
|
||||
class DukeStatIterator : public StatIterator
|
||||
{
|
||||
public:
|
||||
DukeStatIterator(int stat) : StatIterator(stat)
|
||||
{
|
||||
}
|
||||
|
||||
DDukeActor *Next()
|
||||
{
|
||||
int n = NextIndex();
|
||||
return n >= 0? &hittype[n] : nullptr;
|
||||
}
|
||||
|
||||
DDukeActor *Peek()
|
||||
{
|
||||
int n = PeekIndex();
|
||||
return n >= 0? &hittype[n] : nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
class DukeSectIterator : public SectIterator
|
||||
{
|
||||
public:
|
||||
DukeSectIterator(int stat) : SectIterator(stat)
|
||||
{
|
||||
}
|
||||
|
||||
DukeSectIterator(sectortype* stat) : SectIterator(stat)
|
||||
{
|
||||
}
|
||||
|
||||
DDukeActor *Next()
|
||||
{
|
||||
int n = NextIndex();
|
||||
return n >= 0? &hittype[n] : nullptr;
|
||||
}
|
||||
|
||||
DDukeActor *Peek()
|
||||
{
|
||||
int n = PeekIndex();
|
||||
return n >= 0? &hittype[n] : nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
// An interator to iterate over all sprites.
|
||||
class DukeSpriteIterator
|
||||
{
|
||||
DukeStatIterator it;
|
||||
int stat = STAT_DEFAULT;
|
||||
|
||||
public:
|
||||
DukeSpriteIterator() : it(STAT_DEFAULT) {}
|
||||
|
||||
DDukeActor* Next()
|
||||
{
|
||||
while (stat < MAXSTATUS)
|
||||
{
|
||||
auto ac = it.Next();
|
||||
if (ac) return ac;
|
||||
stat++;
|
||||
if (stat < MAXSTATUS) it.Reset(stat);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
class DukeLinearSpriteIterator
|
||||
{
|
||||
int index = 0;
|
||||
public:
|
||||
|
||||
DDukeActor* Next()
|
||||
{
|
||||
while (index < MAXSPRITES)
|
||||
{
|
||||
auto p = &hittype[index++];
|
||||
if (p->s->statnum != MAXSTATUS) return p;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
using DukeStatIterator = TStatIterator<DDukeActor>;
|
||||
using DukeSectIterator = TSectIterator<DDukeActor>;
|
||||
using DukeSpriteIterator = TSpriteIterator<DDukeActor>;
|
||||
using DukeLinearSpriteIterator = TLinearSpriteIterator<DDukeActor>;
|
||||
|
||||
inline DDukeActor* player_struct::GetActor()
|
||||
{
|
||||
|
|
|
@ -58,95 +58,10 @@ inline DExhumedActor* DExhumedActor::base() { return exhumedActors; }
|
|||
using HitInfo = THitInfo<DExhumedActor>;
|
||||
using Collision = TCollision<DExhumedActor>;
|
||||
|
||||
// Iterator wrappers that return an actor pointer, not an index.
|
||||
class ExhumedStatIterator : public StatIterator
|
||||
{
|
||||
public:
|
||||
ExhumedStatIterator(int stat) : StatIterator(stat)
|
||||
{
|
||||
}
|
||||
|
||||
DExhumedActor* Next()
|
||||
{
|
||||
int n = NextIndex();
|
||||
return n >= 0 ? &exhumedActors[n] : nullptr;
|
||||
}
|
||||
|
||||
DExhumedActor* Peek()
|
||||
{
|
||||
int n = PeekIndex();
|
||||
return n >= 0 ? &exhumedActors[n] : nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
class ExhumedSectIterator : public SectIterator
|
||||
{
|
||||
public:
|
||||
ExhumedSectIterator(int stat) : SectIterator(stat)
|
||||
{
|
||||
}
|
||||
|
||||
ExhumedSectIterator(sectortype* stat) : SectIterator(stat)
|
||||
{
|
||||
}
|
||||
|
||||
DExhumedActor* Next()
|
||||
{
|
||||
int n = NextIndex();
|
||||
return n >= 0 ? &exhumedActors[n] : nullptr;
|
||||
}
|
||||
|
||||
DExhumedActor* Peek()
|
||||
{
|
||||
int n = PeekIndex();
|
||||
return n >= 0 ? &exhumedActors[n] : nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
// An iterator to iterate over all sprites.
|
||||
class ExhumedSpriteIterator
|
||||
{
|
||||
ExhumedStatIterator it;
|
||||
int stat = 0;
|
||||
|
||||
public:
|
||||
ExhumedSpriteIterator() : it(0) {}
|
||||
|
||||
DExhumedActor* Next()
|
||||
{
|
||||
while (stat < MAXSTATUS)
|
||||
{
|
||||
auto ac = it.Next();
|
||||
if (ac) return ac;
|
||||
stat++;
|
||||
if (stat < MAXSTATUS) it.Reset(stat);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
// For iterating linearly over map spawned sprites.
|
||||
class ExhumedLinearSpriteIterator
|
||||
{
|
||||
int index = 0;
|
||||
public:
|
||||
|
||||
void Reset()
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
|
||||
DExhumedActor* Next()
|
||||
{
|
||||
while (index < MAXSPRITES)
|
||||
{
|
||||
auto p = &exhumedActors[index++];
|
||||
if (p->s().statnum != MAXSTATUS) return p;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
using ExhumedStatIterator = TStatIterator<DExhumedActor>;
|
||||
using ExhumedSectIterator = TSectIterator<DExhumedActor>;
|
||||
using ExhumedSpriteIterator = TSpriteIterator<DExhumedActor>;
|
||||
using ExhumedLinearSpriteIterator = TLinearSpriteIterator<DExhumedActor>;
|
||||
|
||||
|
||||
inline FSerializer& Serialize(FSerializer& arc, const char* keyname, DExhumedActor*& w, DExhumedActor** def)
|
||||
|
|
|
@ -49,93 +49,10 @@ inline DSWActor* DSWActor::base() { return swActors; }
|
|||
// subclassed to add a game specific actor() method
|
||||
|
||||
// Iterator wrappers that return an actor pointer, not an index.
|
||||
class SWStatIterator : public StatIterator
|
||||
{
|
||||
public:
|
||||
SWStatIterator(int stat) : StatIterator(stat)
|
||||
{
|
||||
}
|
||||
|
||||
DSWActor* Next()
|
||||
{
|
||||
int n = NextIndex();
|
||||
return n >= 0 ? &swActors[n] : nullptr;
|
||||
}
|
||||
|
||||
DSWActor* Peek()
|
||||
{
|
||||
int n = PeekIndex();
|
||||
return n >= 0 ? &swActors[n] : nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
class SWSectIterator : public SectIterator
|
||||
{
|
||||
public:
|
||||
SWSectIterator(int stat) : SectIterator(stat)
|
||||
{
|
||||
}
|
||||
|
||||
SWSectIterator(sectortype* stat) : SectIterator(stat)
|
||||
{
|
||||
}
|
||||
|
||||
DSWActor* Next()
|
||||
{
|
||||
int n = NextIndex();
|
||||
return n >= 0 ? &swActors[n] : nullptr;
|
||||
}
|
||||
|
||||
DSWActor* Peek()
|
||||
{
|
||||
int n = PeekIndex();
|
||||
return n >= 0 ? &swActors[n] : nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
// An iterator to iterate over all sprites.
|
||||
class SWSpriteIterator
|
||||
{
|
||||
SWStatIterator it;
|
||||
int stat = 0;
|
||||
|
||||
public:
|
||||
SWSpriteIterator() : it(0) {}
|
||||
|
||||
DSWActor* Next()
|
||||
{
|
||||
while (stat < MAXSTATUS)
|
||||
{
|
||||
auto ac = it.Next();
|
||||
if (ac) return ac;
|
||||
stat++;
|
||||
if (stat < MAXSTATUS) it.Reset(stat);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
// For iterating linearly over map spawned sprites.
|
||||
class SWLinearSpriteIterator
|
||||
{
|
||||
int index = 0;
|
||||
public:
|
||||
|
||||
void Reset()
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
|
||||
DSWActor* Next()
|
||||
{
|
||||
while (index < MAXSPRITES)
|
||||
{
|
||||
auto p = &swActors[index++];
|
||||
if (p->s().statnum != MAXSTATUS) return p;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
using SWStatIterator = TStatIterator<DSWActor>;
|
||||
using SWSectIterator = TSectIterator<DSWActor>;
|
||||
using SWSpriteIterator = TSpriteIterator<DSWActor>;
|
||||
using SWLinearSpriteIterator = TLinearSpriteIterator<DSWActor>;
|
||||
|
||||
|
||||
inline FSerializer& Serialize(FSerializer& arc, const char* keyname, DSWActor*& w, DSWActor** def)
|
||||
|
|
Loading…
Reference in a new issue