- use EventObject for OBJECTS_TO_TRACK.

This commit is contained in:
Christoph Oelckers 2021-11-23 19:48:14 +01:00
parent dbbca2972a
commit f07fafea9c
5 changed files with 19 additions and 33 deletions

View file

@ -742,7 +742,7 @@ void callbackCondition(DBloodActor* actor, int)
TRCONDITION const* pCond = &gCondition[pXSprite->sysData1];
for (unsigned i = 0; i < pCond->length; i++) {
EVENT evn;
evn.target.fromElements(pCond->obj[i].type, pCond->obj[i].index_, pCond->obj[i].actor);
evn.target = pCond->obj[i].obj;
evn.cmd = pCond->obj[i].cmd;
evn.funcID = kCallbackCondition;
useCondition(actor, evn);

View file

@ -670,21 +670,21 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, EventObject& w, Ev
{
DBloodActor* a = arc.isWriting()? w.actor() : nullptr;
arc("actor", a);
if (arc.isReading()) w = a;
if (arc.isReading()) w = EventObject(a);
break;
}
case 1:
{
auto s = arc.isWriting()? w.sector() : nullptr;
arc("sector", s);
if (arc.isReading()) w = s;
if (arc.isReading()) w = EventObject(s);
break;
}
case 2:
{
auto s = arc.isWriting()? w.wall() : nullptr;
arc("wall", s);
if (arc.isReading()) w = s;
if (arc.isReading()) w = EventObject(s);
break;
}
}

View file

@ -47,10 +47,6 @@ public:
explicit EventObject(sectortype *sect) { index = (sectnum(sect) << 8) | Sector; }
explicit EventObject(walltype* wall) { index = (wallnum(wall) << 8) | Wall; }
EventObject& operator=(DBloodActor* actor_) { ActorP = actor_; assert(isActor()); /* GC:WriteBarrier(actor);*/ return *this; }
EventObject& operator=(sectortype *sect) { index = (sectnum(sect) << 8) | Sector; return *this; }
EventObject& operator=(walltype* wall) { index = (wallnum(wall) << 8) | Wall; return *this; }
bool isActor() const { return (index&7) == Actor; }
bool isSector() const { return (index&7) == Sector; }
bool isWall() const { return (index&7) == Wall; }
@ -66,6 +62,7 @@ public:
FString description() const;
// refactoring helper
/*
[[deprecated]] void fromElements(int type, int index, DBloodActor* act)
{
if (type == 0) *this = &::wall[index];
@ -73,6 +70,7 @@ public:
else if (type == 3) *this = act;
else assert(false);
}
*/
};

View file

@ -495,9 +495,7 @@ void nnExtResetGlobals()
TRCONDITION* pCond = &gCondition[i];
for (unsigned k = 0; k < kMaxTracedObjects; k++)
{
pCond->obj[k].actor = nullptr;
pCond->obj[k].index_ = pCond->obj[k].cmd = 0;
pCond->obj[k].type = -1;
pCond->obj[k].obj = EventObject(nullptr);
}
pCond->actor = nullptr;
pCond->length = 0;
@ -839,9 +837,7 @@ void nnExtInitModernStuff()
if (count >= kMaxTracedObjects)
condError(iactor, "Max(%d) objects to track reached for condition #%d, RXID: %d!");
pCond->obj[count].type = OBJ_SPRITE;
pCond->obj[count].index_ = 0;
pCond->obj[count].actor = iactor2;
pCond->obj[count].obj = EventObject(iactor2);
pCond->obj[count++].cmd = (uint8_t)pXSpr->command;
}
@ -851,9 +847,7 @@ void nnExtInitModernStuff()
else if (count >= kMaxTracedObjects)
condError(iactor, "Max(%d) objects to track reached for condition #%d, RXID: %d!");
pCond->obj[count].type = OBJ_SECTOR;
pCond->obj[count].actor = nullptr;
pCond->obj[count].index_ = sectnum(&sect);
pCond->obj[count].obj = EventObject(&sect);
pCond->obj[count++].cmd = sect.xs().command;
}
@ -871,9 +865,7 @@ void nnExtInitModernStuff()
if (count >= kMaxTracedObjects)
condError(iactor, "Max(%d) objects to track reached for condition #%d, RXID: %d!");
pCond->obj[count].type = OBJ_WALL;
pCond->obj[count].index_ = wallnum(&wal);
pCond->obj[count].actor = nullptr;
pCond->obj[count].obj = EventObject(&wal);
pCond->obj[count++].cmd = wal.xw().command;
}
@ -1114,7 +1106,7 @@ void nnExtProcessSuperSprites()
if (pXCond->data1 >= kCondGameBase && pXCond->data1 < kCondGameMax)
{
EVENT evn;
evn.target = pCond->actor;
evn.target = EventObject(pCond->actor);
evn.cmd = (int8_t)pXCond->command;
evn.funcID = kCallbackMax;
useCondition(pCond->actor, evn);
@ -1125,7 +1117,7 @@ void nnExtProcessSuperSprites()
for (unsigned k = 0; k < pCond->length; k++)
{
EVENT evn;
evn.target.fromElements(pCond->obj[k].type, pCond->obj[k].index_, pCond->obj[k].actor);
evn.target = pCond->obj[k].obj;
evn.cmd = pCond->obj[k].cmd;
evn.funcID = kCallbackMax;
useCondition(pCond->actor, evn);
@ -2129,9 +2121,8 @@ void trPlayerCtrlLink(DBloodActor* sourceactor, PLAYER* pPlayer, bool checkCondi
// search for player control sprite and replace it with actual player sprite
for (unsigned k = 0; k < pCond->length; k++)
{
if (pCond->obj[k].type != OBJ_SPRITE || pCond->obj[k].actor != sourceactor) continue;
pCond->obj[k].actor = pPlayer->actor;
pCond->obj[k].index_ = 0;
if (!pCond->obj[k].obj.isActor() || pCond->obj[k].obj.actor() != sourceactor) continue;
pCond->obj[k].obj = EventObject(pPlayer->actor);
pCond->obj[k].cmd = (uint8_t)pPlayer->pXSprite->command;
break;
}
@ -4649,8 +4640,8 @@ void condUpdateObjectIndex(DBloodActor* oldActor, DBloodActor* newActor)
TRCONDITION* pCond = &gCondition[i];
for (unsigned k = 0; k < pCond->length; k++)
{
if (pCond->obj[k].type != OBJ_SPRITE || pCond->obj[k].actor != oldActor) continue;
pCond->obj[k].actor = newActor;
if (!pCond->obj[k].obj.isActor() || pCond->obj[k].obj.actor() != oldActor) continue;
pCond->obj[k].obj = EventObject(newActor);
break;
}
}
@ -9219,9 +9210,8 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, OBJECTS_TO_TRACK&
if (arc.isReading()) w = {};
if (arc.BeginObject(keyname))
{
arc("type", w.type, &nul.type)
("index", w.index_, &nul.index_)
("xrepeat", w.cmd, &nul.cmd)
arc("obj", w.obj, &nul.obj)
("cmd", w.cmd, &nul.cmd)
.EndObject();
}
return arc;

View file

@ -235,10 +235,8 @@ struct TRPLAYERCTRL { // this one for controlling the player using triggers (mov
};
struct OBJECTS_TO_TRACK {
int8_t type;
uint8_t cmd;
unsigned int index_;
DBloodActor* actor;
EventObject obj;
};
struct TRCONDITION {