- replaced the assignment operator in player_t with a named function.

This didn't behave like an assignment operator so it shouldn't be one, especially since the two places where it got called need different functionality.
This commit is contained in:
Christoph Oelckers 2019-03-03 12:12:17 +01:00 committed by drfrag
parent f78e8cb71c
commit bc10c3e5bb
3 changed files with 13 additions and 11 deletions

View file

@ -282,7 +282,8 @@ class player_t
public:
player_t() = default;
~player_t();
player_t &operator= (const player_t &p);
player_t &operator= (const player_t &p) = delete;
void CopyFrom(player_t &src, bool copyPSP);
void Serialize(FSerializer &arc);
size_t PropagateMark();

View file

@ -841,8 +841,7 @@ void CopyPlayer(player_t *dst, player_t *src, const char *name)
bool attackdown = dst->attackdown;
bool usedown = dst->usedown;
*dst = *src; // To avoid memory leaks at this point the userinfo in src must be empty which is taken care of by the TransferFrom call above.
dst->CopyFrom(*src, true); // To avoid memory leaks at this point the userinfo in src must be empty which is taken care of by the TransferFrom call above.
dst->cheats |= chasecam;
@ -885,9 +884,6 @@ void CopyPlayer(player_t *dst, player_t *src, const char *name)
pspr = pspr->Next;
}
// Don't let the psprites be destroyed when src is destroyed.
src->psprites = nullptr;
// These 2 variables may not be overwritten.
dst->attackdown = attackdown;
dst->usedown = usedown;

View file

@ -307,7 +307,7 @@ player_t::~player_t()
DestroyPSprites();
}
player_t &player_t::operator=(const player_t &p)
void player_t::CopyFrom(player_t &p, bool copyPSP)
{
mo = p.mo;
playerstate = p.playerstate;
@ -360,7 +360,6 @@ player_t &player_t::operator=(const player_t &p)
extralight = p.extralight;
fixedcolormap = p.fixedcolormap;
fixedlightlevel = p.fixedlightlevel;
psprites = p.psprites;
morphTics = p.morphTics;
MorphedPlayerClass = p.MorphedPlayerClass;
MorphStyle = p.MorphStyle;
@ -394,7 +393,13 @@ player_t &player_t::operator=(const player_t &p)
ConversationFaceTalker = p.ConversationFaceTalker;
MUSINFOactor = p.MUSINFOactor;
MUSINFOtics = p.MUSINFOtics;
return *this;
if (copyPSP)
{
// This needs to transfer ownership completely.
psprites = p.psprites;
p.psprites = nullptr;
}
else psprites = nullptr;
}
size_t player_t::PropagateMark()
@ -1396,7 +1401,7 @@ void P_PredictPlayer (player_t *player)
}
// Save original values for restoration later
PredictionPlayerBackup = *player;
PredictionPlayerBackup.CopyFrom(*player, false);
auto act = player->mo;
PredictionActor = player->mo;
@ -1521,7 +1526,7 @@ void P_UnPredictPlayer ()
int inventorytics = player->inventorytics;
const bool settings_controller = player->settings_controller;
*player = PredictionPlayerBackup;
player->CopyFrom(PredictionPlayerBackup, false);
player->settings_controller = settings_controller;
// Restore the camera instead of using the backup's copy, because spynext/prev