Cleaner reference handling for the following extern-scope netsynced mobj_t*.

- `skyboxcenterpnts` and `skyboxviewpnts`
    - P_InitSkyboxPoint`, which calls `P_SetTarget`
- `waypoint->mobj`
    - Make sure NULL before using `P_SetTarget` on
- `tubewaypoints`
    - Use `P_SetTarget`
    - Use `UINT32_MAX` for the invalid mobjnum, since 0 is a valid one.
- `waypointcap` and `kitemcap`
    - NULL before reset

Our international nightmare is over.
This commit is contained in:
toaster 2023-01-05 23:32:12 +00:00
parent 2786c2095e
commit 724c9b774e
5 changed files with 39 additions and 24 deletions

View file

@ -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

View file

@ -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:

View file

@ -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++)
{

View file

@ -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;
}

View file

@ -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