- moved around some pieces of code to make sharing with Raze easier.

This commit is contained in:
Christoph Oelckers 2020-04-11 19:22:16 +02:00
commit cf51508ce6
21 changed files with 96 additions and 74 deletions

View file

@ -1558,6 +1558,8 @@ struct FTranslatedLineTarget
};
void StaticPointerSubstitution(AActor* old, AActor* notOld);
#define S_FREETARGMOBJ 1
#endif // __P_MOBJ_H__

View file

@ -148,7 +148,7 @@ enum
// The VM cannot deal with this as an invalid pointer because it performs a read barrier on every object pointer read.
// This doesn't have to point to a valid weapon, though, because WP_NOCHANGE is never dereferenced, but it must point to a valid object
// and the class descriptor just works fine for that.
extern AActor *WP_NOCHANGE;
extern DObject *WP_NOCHANGE;
// [GRB] Custom player classes

View file

@ -2523,7 +2523,7 @@ void FParser::SF_PlayerWeapon()
{
wp->Destroy();
// If the weapon is active pick a replacement. Legacy didn't do this!
if (Level->Players[playernum]->PendingWeapon==wp) Level->Players[playernum]->PendingWeapon=WP_NOCHANGE;
if (Level->Players[playernum]->PendingWeapon==wp) Level->Players[playernum]->PendingWeapon=(AActor*)WP_NOCHANGE;
if (Level->Players[playernum]->ReadyWeapon==wp)
{
Level->Players[playernum]->ReadyWeapon=nullptr;

View file

@ -7,6 +7,7 @@
struct sector_t;
class AActor;
class PClass;
struct FState;
enum dirtype_t

View file

@ -4922,6 +4922,62 @@ EXTERN_CVAR(Float, fov)
extern bool demonew;
//==========================================================================
//
// This once was the main method for pointer cleanup, but
// nowadays its only use is swapping out PlayerPawns.
// This requires pointer fixing throughout all objects and a few
// global variables, but it only needs to look at pointers that
// can point to a player.
//
//==========================================================================
void StaticPointerSubstitution(AActor* old, AActor* notOld)
{
DObject* probe;
size_t changed = 0;
int i;
if (old == nullptr) return;
// This is only allowed to replace players. For everything else the results are undefined.
if (!old->IsKindOf(NAME_PlayerPawn) || (notOld != nullptr && !notOld->IsKindOf(NAME_PlayerPawn))) return;
// Go through all objects.
i = 0; DObject* last = 0;
for (probe = GC::Root; probe != NULL; probe = probe->ObjNext)
{
i++;
changed += probe->PointerSubstitution(old, notOld);
last = probe;
}
// Go through players.
for (i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i])
{
AActor* replacement = notOld;
auto& p = players[i];
if (p.mo == old) p.mo = replacement, changed++;
if (p.poisoner.ForceGet() == old) p.poisoner = replacement, changed++;
if (p.attacker.ForceGet() == old) p.attacker = replacement, changed++;
if (p.camera.ForceGet() == old) p.camera = replacement, changed++;
if (p.ConversationNPC.ForceGet() == old) p.ConversationNPC = replacement, changed++;
if (p.ConversationPC.ForceGet() == old) p.ConversationPC = replacement, changed++;
}
}
// Go through sectors. Only the level this actor belongs to is relevant.
for (auto& sec : old->Level->sectors)
{
if (sec.SoundTarget == old) sec.SoundTarget = notOld;
}
}
AActor *FLevelLocals::SpawnPlayer (FPlayerStart *mthing, int playernum, int flags)
{
player_t *p;
@ -5184,7 +5240,7 @@ AActor *FLevelLocals::SpawnPlayer (FPlayerStart *mthing, int playernum, int flag
if (sec.SoundTarget == oldactor) sec.SoundTarget = nullptr;
}
DObject::StaticPointerSubstitution (oldactor, p->mo);
StaticPointerSubstitution (oldactor, p->mo);
localEventManager->PlayerRespawned(PlayerNum(p));
Behaviors.StartTypedScripts (SCRIPT_Respawn, p->mo, true);

View file

@ -996,7 +996,7 @@ void P_SetupPsprites(player_t *player, bool startweaponup)
player->DestroyPSprites();
// Spawn the ready weapon
player->PendingWeapon = !startweaponup ? player->ReadyWeapon : WP_NOCHANGE;
player->PendingWeapon = !startweaponup ? player->ReadyWeapon : (AActor*)WP_NOCHANGE;
P_BringUpWeapon (player);
}

View file

@ -40,6 +40,7 @@
#define WEAPONTOP 32.
#define WEAPON_FUDGE_Y 0.375
struct FTranslatedLineTarget;
struct FState;
//
// Overlay psprites are scaled shapes