diff --git a/src/dsectoreffect.cpp b/src/dsectoreffect.cpp index b55e8113f..dff75e848 100644 --- a/src/dsectoreffect.cpp +++ b/src/dsectoreffect.cpp @@ -61,6 +61,7 @@ void DSectorEffect::Destroy() } DSectorEffect::DSectorEffect (sector_t *sector) + : DThinker(STAT_SECTOREFFECT) { m_Sector = sector; } 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/m_swap.h b/src/m_swap.h index fc1ba9cc4..230e95598 100644 --- a/src/m_swap.h +++ b/src/m_swap.h @@ -47,6 +47,11 @@ inline short LittleShort(int x) return OSSwapLittleToHostInt16((uint16_t)x); } +inline unsigned short LittleShort(unsigned int x) +{ + return OSSwapLittleToHostInt16((uint16_t)x); +} + inline int LittleLong(int x) { return OSSwapLittleToHostInt32((uint32_t)x); @@ -57,6 +62,16 @@ inline unsigned int LittleLong(unsigned int x) return OSSwapLittleToHostInt32(x); } +inline int LittleLong(long x) +{ + return OSSwapLittleToHostInt32((uint32_t)x); +} + +inline unsigned int LittleLong(unsigned long x) +{ + return OSSwapLittleToHostInt32((uint32_t)x); +} + inline short BigShort(short x) { return (short)OSSwapBigToHostInt16((uint16_t)x); diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index ece959b80..9ee6358f6 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -71,6 +71,7 @@ #include "p_spec.h" #include "p_checkposition.h" #include "serializer.h" +#include "r_utility.h" // MACROS ------------------------------------------------------------------ @@ -1041,11 +1042,11 @@ bool AActor::IsInsideVisibleAngles() const if (players[consoleplayer].camera == nullptr) return true; - DAngle anglestart = VisibleStartAngle.Normalized180(); - DAngle angleend = VisibleEndAngle.Normalized180(); - DAngle pitchstart = VisibleStartPitch.Normalized180(); - DAngle pitchend = VisibleEndPitch.Normalized180(); - + DAngle anglestart = VisibleStartAngle; + DAngle angleend = VisibleEndAngle; + DAngle pitchstart = VisibleStartPitch; + DAngle pitchend = VisibleEndPitch; + if (anglestart > angleend) { DAngle temp = anglestart; @@ -1053,28 +1054,26 @@ bool AActor::IsInsideVisibleAngles() const angleend = temp; } - if (pitchstart > angleend) + if (pitchstart > pitchend) { DAngle temp = pitchstart; pitchstart = pitchend; pitchend = temp; } + - player_t* pPlayer = players[consoleplayer].camera->player; + AActor *mo = players[consoleplayer].camera; - if (pPlayer && pPlayer->mo) + if (mo != nullptr) { - AActor *mo = pPlayer->mo; - DVector3 diffang = Vec3To(mo); + + DVector3 diffang = ViewPos - Pos(); DAngle to = diffang.Angle(); if (!(renderflags & RF_ABSMASKANGLE)) to = deltaangle(Angles.Yaw, to); - // Note that this check is inversed due to only being able to vectorize - // from one way (this actor to the player). It still means to pass - // if the player is within the visible angles. - if ((to <= anglestart || to >= angleend)) + if ((to >= anglestart && to <= angleend)) { to = diffang.Pitch(); if (!(renderflags & RF_ABSMASKPITCH)) diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 170273b43..24e5ff9ee 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -642,6 +642,11 @@ static void ReadOnePlayer(FSerializer &arc, bool skipload) { CopyPlayer(&players[i], &playerTemp, name); } + else + { + // we need the player actor, so that G_FinishTravel can destroy it later. + players[i].mo = playerTemp.mo; + } } else { @@ -755,6 +760,13 @@ static void ReadMultiplePlayers(FSerializer &arc, int numPlayers, int numPlayers } } } + else + { + for (i = 0; i < MAXPLAYERS; ++i) + { + players[i].mo = playertemp[i].mo; + } + } delete[] tempPlayerUsed; delete[] playertemp; diff --git a/src/serializer.cpp b/src/serializer.cpp index a23459ced..445a3b22b 100644 --- a/src/serializer.cpp +++ b/src/serializer.cpp @@ -1294,7 +1294,7 @@ FSerializer &SerializePointer(FSerializer &arc, const char *key, T *&value, T ** assert(base != nullptr); if (arc.isReading() || !arc.w->inObject() || defval == nullptr || value != *defval) { - ptrdiff_t vv = value == nullptr ? -1 : value - base; + int64_t vv = value == nullptr ? -1 : value - base; Serialize(arc, key, vv, nullptr); value = vv < 0 ? nullptr : base + vv; } diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index 8ada05aa6..927e3e537 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -1437,7 +1437,7 @@ DEFINE_PROPERTY(spriterotation, F, Actor) DEFINE_PROPERTY(visibleangles, Ff, Actor) { PROP_DOUBLE_PARM(visstart, 0); - PROP_DOUBLE_PARM(visend, 0); + PROP_DOUBLE_PARM(visend, 1); defaults->VisibleStartAngle = visstart; defaults->VisibleEndAngle = visend; } @@ -1448,7 +1448,7 @@ DEFINE_PROPERTY(visibleangles, Ff, Actor) DEFINE_PROPERTY(visiblepitch, Ff, Actor) { PROP_DOUBLE_PARM(visstart, 0); - PROP_DOUBLE_PARM(visend, 0); + PROP_DOUBLE_PARM(visend, 1); defaults->VisibleStartPitch = visstart; defaults->VisibleEndPitch = visend; }