- 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]; TRCONDITION const* pCond = &gCondition[pXSprite->sysData1];
for (unsigned i = 0; i < pCond->length; i++) { for (unsigned i = 0; i < pCond->length; i++) {
EVENT evn; 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.cmd = pCond->obj[i].cmd;
evn.funcID = kCallbackCondition; evn.funcID = kCallbackCondition;
useCondition(actor, evn); 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; DBloodActor* a = arc.isWriting()? w.actor() : nullptr;
arc("actor", a); arc("actor", a);
if (arc.isReading()) w = a; if (arc.isReading()) w = EventObject(a);
break; break;
} }
case 1: case 1:
{ {
auto s = arc.isWriting()? w.sector() : nullptr; auto s = arc.isWriting()? w.sector() : nullptr;
arc("sector", s); arc("sector", s);
if (arc.isReading()) w = s; if (arc.isReading()) w = EventObject(s);
break; break;
} }
case 2: case 2:
{ {
auto s = arc.isWriting()? w.wall() : nullptr; auto s = arc.isWriting()? w.wall() : nullptr;
arc("wall", s); arc("wall", s);
if (arc.isReading()) w = s; if (arc.isReading()) w = EventObject(s);
break; break;
} }
} }

View file

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

View file

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

View file

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