From 6a6a0e8017109fbf1256bccf878277cf6e75403e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 25 Sep 2016 01:28:27 +0200 Subject: [PATCH] - removed some more hubtravel related player start fudging. * do not skip the player_t init when travelling in a hub. The old player may still be needed in some edge cases. This applies only to singleplayer for now. The multiplayer version still needs reviewing. I left it alone because it may shuffle players around which is not wanted when doing hub travelling. * do not spawn two temp players in G_FinishTravel. Instead handle the case where no player_t::mo can be found gracefully by adding a few nullptr checks. This temp player served no real purpose except for having a valid pointer. The actual start position was retrieved from somewhere else. --- src/g_level.cpp | 29 +++++++++++++---------------- src/p_saveg.cpp | 11 ++++------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/g_level.cpp b/src/g_level.cpp index dcf97ba4f..90b31138d 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -1207,29 +1207,23 @@ void G_FinishTravel () pnum = int(pawn->player - players); pawn->ChangeStatNum (STAT_PLAYER); pawndup = pawn->player->mo; - start = NULL; assert (pawn != pawndup); - if (pawndup == NULL) - { // Oh no! there was no start for this player! - start = G_PickPlayerStart(pnum, PPS_FORCERANDOM); - if (start != NULL) pawndup = P_SpawnPlayer(start, pnum, (level.flags2 & LEVEL2_PRERAISEWEAPON) ? SPF_WEAPONFULLYUP : 0); - if (pawndup == NULL) - { - pawn->flags |= MF_NOSECTOR | MF_NOBLOCKMAP; - pawn->Destroy(); - continue; - } - } + start = G_PickPlayerStart(pnum, 0); if (start == NULL) { - start = G_PickPlayerStart(pnum, 0); - if (start == NULL) + if (pawndup != nullptr) { Printf(TEXTCOLOR_RED "No player %d start to travel to!\n", pnum + 1); // Move to the coordinates this player had when they left the level. pawn->SetXYZ(pawndup->Pos()); } + else + { + // Could not find a start for this player at all. This really should never happen but if it does, let's better abort. + DThinker::DestroyThinkersInList(STAT_TRAVELLING); + I_Error ("No player %d start to travel to!\n", pnum + 1); + } } oldpawn = pawndup; @@ -1266,8 +1260,11 @@ void G_FinishTravel () pawn->player->camera = pawn; pawn->player->viewheight = pawn->ViewHeight; pawn->flags2 &= ~MF2_BLASTED; - DObject::StaticPointerSubstitution (oldpawn, pawn); - oldpawn->Destroy(); + if (oldpawn != nullptr) + { + DObject::StaticPointerSubstitution (oldpawn, pawn); + oldpawn->Destroy(); + } if (pawndup != NULL) { pawndup->Destroy(); diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 465760137..2382d3ede 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -537,7 +537,7 @@ void P_SerializeSounds(FSerializer &arc) //========================================================================== void CopyPlayer(player_t *dst, player_t *src, const char *name); -static void ReadOnePlayer(FSerializer &arc, bool skipload); +static void ReadOnePlayer(FSerializer &arc); static void ReadMultiplePlayers(FSerializer &arc, int numPlayers, int numPlayersNow, bool skipload); static void SpawnExtraPlayers(); @@ -594,7 +594,7 @@ void P_SerializePlayers(FSerializer &arc, bool skipload) // first player present, no matter what their name. if (numPlayers == 1) { - ReadOnePlayer(arc, skipload); + ReadOnePlayer(arc); } else { @@ -617,7 +617,7 @@ void P_SerializePlayers(FSerializer &arc, bool skipload) // //========================================================================== -static void ReadOnePlayer(FSerializer &arc, bool skipload) +static void ReadOnePlayer(FSerializer &arc) { int i; const char *name = NULL; @@ -636,10 +636,7 @@ static void ReadOnePlayer(FSerializer &arc, bool skipload) didIt = true; player_t playerTemp; playerTemp.Serialize(arc); - if (!skipload) - { - CopyPlayer(&players[i], &playerTemp, name); - } + CopyPlayer(&players[i], &playerTemp, name); } else {