2021-10-29 18:49:57 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// included by game.h
|
|
|
|
|
|
|
|
BEGIN_SW_NS
|
|
|
|
|
|
|
|
|
2021-11-25 21:33:55 +00:00
|
|
|
class DSWActor : public DCoreActor
|
2021-10-29 18:49:57 +00:00
|
|
|
{
|
|
|
|
DSWActor* base();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2021-11-19 23:18:23 +00:00
|
|
|
bool hasUser;
|
|
|
|
USER user;
|
2021-11-24 19:11:50 +00:00
|
|
|
walltype* tempwall; // transient, to replace a hack using a 16 bit sprite field.
|
2021-11-19 23:18:23 +00:00
|
|
|
|
2021-11-25 21:33:55 +00:00
|
|
|
DSWActor()
|
|
|
|
{
|
|
|
|
index = (int(this - base()));
|
|
|
|
}
|
2021-10-29 18:49:57 +00:00
|
|
|
DSWActor& operator=(const DSWActor& other) = default;
|
|
|
|
|
|
|
|
void Clear()
|
|
|
|
{
|
2021-11-17 16:01:10 +00:00
|
|
|
clearUser();
|
2021-10-29 18:49:57 +00:00
|
|
|
}
|
2021-11-19 23:18:23 +00:00
|
|
|
bool hasU() { return hasUser; }
|
2021-11-06 09:40:57 +00:00
|
|
|
|
2021-11-17 16:01:10 +00:00
|
|
|
|
2021-11-19 23:18:23 +00:00
|
|
|
USER* u() { return &user; }
|
2021-10-31 22:01:00 +00:00
|
|
|
USER* allocUser()
|
|
|
|
{
|
2021-11-19 23:18:23 +00:00
|
|
|
hasUser = true;
|
2021-11-06 09:40:57 +00:00
|
|
|
return u();
|
2021-10-31 22:01:00 +00:00
|
|
|
}
|
2021-10-29 18:49:57 +00:00
|
|
|
|
2021-11-01 22:26:13 +00:00
|
|
|
void clearUser()
|
|
|
|
{
|
2021-11-19 23:18:23 +00:00
|
|
|
hasUser = false;
|
|
|
|
user.Clear();
|
2021-11-01 22:26:13 +00:00
|
|
|
}
|
2021-10-29 18:49:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern DSWActor swActors[MAXSPRITES];
|
|
|
|
|
|
|
|
inline DSWActor* DSWActor::base() { return swActors; }
|
|
|
|
|
2021-11-26 00:01:16 +00:00
|
|
|
// subclassed to add a game specific actor() method
|
|
|
|
|
2021-10-29 18:49:57 +00:00
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-11-11 19:20:00 +00:00
|
|
|
SWSectIterator(sectortype* stat) : SectIterator(stat)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-10-29 18:49:57 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
inline FSerializer& Serialize(FSerializer& arc, const char* keyname, DSWActor*& w, DSWActor** def)
|
|
|
|
{
|
|
|
|
int index = w? int(w - swActors) : -1;
|
|
|
|
Serialize(arc, keyname, index, nullptr);
|
|
|
|
if (arc.isReading()) w = index == -1? nullptr : &swActors[index];
|
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
2021-10-31 10:52:18 +00:00
|
|
|
inline void ChangeActorSect(DSWActor* actor, int sect)
|
|
|
|
{
|
|
|
|
changespritesect(actor->GetSpriteIndex(), sect);
|
|
|
|
}
|
2021-10-29 18:49:57 +00:00
|
|
|
|
2021-11-24 20:45:03 +00:00
|
|
|
inline void ChangeActorSect(DSWActor* actor, sectortype* sect)
|
|
|
|
{
|
|
|
|
changespritesect(actor->GetSpriteIndex(), sectnum(sect));
|
|
|
|
}
|
|
|
|
|
2021-10-31 15:55:24 +00:00
|
|
|
inline int SetActorZ(DSWActor* actor, const vec3_t* newpos)
|
|
|
|
{
|
|
|
|
return setspritez(actor->GetSpriteIndex(), newpos);
|
|
|
|
}
|
|
|
|
|
2021-11-04 23:00:47 +00:00
|
|
|
inline int SetActor(DSWActor* actor, const vec3_t* newpos)
|
|
|
|
{
|
|
|
|
return setsprite(actor->GetSpriteIndex(), newpos);
|
|
|
|
}
|
|
|
|
|
2021-10-29 18:49:57 +00:00
|
|
|
END_SW_NS
|