diff --git a/src/k_waypoint.c b/src/k_waypoint.c index d53a4bbd3..cf70c1dcd 100644 --- a/src/k_waypoint.c +++ b/src/k_waypoint.c @@ -1949,6 +1949,7 @@ static waypoint_t *K_MakeWaypoint(mobj_t *const mobj) madewaypoint = &waypointheap[numwaypoints]; numwaypoints++; + madewaypoint->mobj = NULL; P_SetTarget(&madewaypoint->mobj, mobj); // Don't allow a waypoint that has its next ID set to itself to work diff --git a/src/p_mobj.c b/src/p_mobj.c index 230454a6c..e8fb3c30e 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -12557,6 +12557,21 @@ static mobj_t *P_MakeSoftwareCorona(mobj_t *mo, INT32 height) return corona; } +void P_InitSkyboxPoint(mobj_t *mobj, mapthing_t *mthing) +{ + mtag_t tag = Tag_FGet(&mthing->tags); + if (tag < 0 || tag > 15) + { + CONS_Debug(DBG_GAMELOGIC, "P_InitSkyboxPoint: Skybox ID %d of mapthing %s is not between 0 and 15!\n", tag, sizeu1((size_t)(mthing - mapthings))); + return; + } + + if (mthing->args[0]) + P_SetTarget(&skyboxcenterpnts[tag], mobj); + else + P_SetTarget(&skyboxviewpnts[tag], mobj); +} + static boolean P_MapAlreadyHasStarPost(mobj_t *mobj) { thinker_t *th; @@ -12602,17 +12617,7 @@ static boolean P_SetupSpawnedMapThing(mapthing_t *mthing, mobj_t *mobj, boolean } case MT_SKYBOX: { - mtag_t tag = Tag_FGet(&mthing->tags); - if (tag < 0 || tag > 15) - { - CONS_Debug(DBG_GAMELOGIC, "P_SetupSpawnedMapThing: Skybox ID %d of mapthing %s is not between 0 and 15!\n", tag, sizeu1((size_t)(mthing - mapthings))); - break; - } - - if (mthing->args[0]) - skyboxcenterpnts[tag] = mobj; - else - skyboxviewpnts[tag] = mobj; + P_InitSkyboxPoint(mobj, mthing); break; } case MT_EGGSTATUE: diff --git a/src/p_saveg.c b/src/p_saveg.c index 1fd515a1f..8accfa309 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1070,7 +1070,12 @@ static void P_NetArchiveTubeWaypoints(savebuffer_t *save) { WRITEUINT16(save->p, numtubewaypoints[i]); for (j = 0; j < numtubewaypoints[i]; j++) - WRITEUINT32(save->p, tubewaypoints[i][j] ? tubewaypoints[i][j]->mobjnum : 0); + { + if (tubewaypoints[i][j]) + WRITEUINT32(save->p, tubewaypoints[i][j]->mobjnum); + else + WRITEUINT32(save->p, UINT32_MAX); + } } } @@ -1085,7 +1090,9 @@ static void P_NetUnArchiveTubeWaypoints(savebuffer_t *save) for (j = 0; j < numtubewaypoints[i]; j++) { mobjnum = READUINT32(save->p); - tubewaypoints[i][j] = (mobjnum == 0) ? NULL : P_FindNewPosition(mobjnum); + tubewaypoints[i][j] = NULL; + if (mobjnum != UINT32_MAX) + P_SetTarget(&tubewaypoints[i][j], P_FindNewPosition(mobjnum)); } } } @@ -3068,6 +3075,7 @@ static void P_NetUnArchiveWaypoints(savebuffer_t *save) for (i = 0U; i < numArchiveWaypoints; i++) { waypoint = K_GetWaypointFromIndex(i); temp = READUINT32(save->p); + waypoint->mobj = NULL; if (!P_SetTarget(&waypoint->mobj, P_FindNewPosition(temp))) { CONS_Debug(DBG_GAMELOGIC, "waypoint mobj not found for %d\n", i); } @@ -3453,17 +3461,9 @@ static thinker_t* LoadMobjThinker(savebuffer_t *save, actionf_p1 thinker) mobj->player->viewz = mobj->player->mo->z + mobj->player->viewheight; } - if (mobj->type == MT_SKYBOX) + if (mobj->type == MT_SKYBOX && mobj->spawnpoint) { - mtag_t tag = mobj->movedir; - if (tag < 0 || tag > 15) - { - CONS_Debug(DBG_GAMELOGIC, "LoadMobjThinker: Skybox ID %d of netloaded object is not between 0 and 15!\n", tag); - } - else if (mobj->flags2 & MF2_AMBUSH) - skyboxcenterpnts[tag] = mobj; - else - skyboxviewpnts[tag] = mobj; + P_InitSkyboxPoint(mobj, mobj->spawnpoint); } if (diff2 & MD2_WAYPOINTCAP) @@ -4105,6 +4105,13 @@ static void P_NetUnArchiveThinkers(savebuffer_t *save) iquetail = iquehead = 0; P_InitThinkers(); + // Oh my god don't blast random memory with our reference counts. + waypointcap = kitemcap = NULL; + for (i = 0; i <= 15; i++) + { + skyboxcenterpnts[i] = skyboxviewpnts[i] = NULL; + } + // clear sector thinker pointers so they don't point to non-existant thinkers for all of eternity for (i = 0; i < numsectors; i++) { diff --git a/src/p_setup.c b/src/p_setup.c index 42ff2f33d..d77a27971 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -184,7 +184,7 @@ UINT16 numtubewaypoints[NUMTUBEWAYPOINTSEQUENCES]; void P_AddTubeWaypoint(UINT8 sequence, UINT8 id, mobj_t *waypoint) { - tubewaypoints[sequence][id] = waypoint; + P_SetTarget(&tubewaypoints[sequence][id], waypoint); if (id >= numtubewaypoints[sequence]) numtubewaypoints[sequence] = id + 1; } diff --git a/src/p_spec.h b/src/p_spec.h index 1982892d0..6f4d36f87 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -24,6 +24,8 @@ extern "C" { extern mobj_t *skyboxviewpnts[16]; // array of MT_SKYBOX viewpoint mobjs extern mobj_t *skyboxcenterpnts[16]; // array of MT_SKYBOX centerpoint mobjs +void P_InitSkyboxPoint(mobj_t *mobj, mapthing_t *mthing); + // Amount (dx, dy) vector linedef is shifted right to get scroll amount #define SCROLL_SHIFT 5