From bd8ff77fe00700aada3495b4b5c8ac583f1051ef Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 15 Jul 2024 13:56:28 +0200 Subject: [PATCH] more mobj reference fixes + cleanup --- src/g_game.c | 1 - src/lua_script.c | 24 ++++--- src/m_cheat.c | 5 +- src/p_enemy.c | 8 ++- src/p_floor.c | 24 ------- src/p_mobj.c | 71 ++++++++++---------- src/p_polyobj.c | 167 ++++++++++++++++++++--------------------------- src/p_saveg.c | 20 +++--- src/p_spec.c | 53 ++++++++------- src/p_user.c | 20 +++--- 10 files changed, 179 insertions(+), 214 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index c7e13a7fb..d1a3106ae 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -5622,7 +5622,6 @@ void G_ConsGhostTic(INT32 playernum) mobj = (mobj_t *)th; if (mobj->type == (mobjtype_t)type && mobj->x == x && mobj->y == y && mobj->z == z) break; - mobj = NULL; // wasn't this one, keep searching. } if (mobj && mobj->health != health) // Wasn't damaged?! This is desync! Fix it! { diff --git a/src/lua_script.c b/src/lua_script.c index c01e4c99e..5413c007a 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1592,12 +1592,14 @@ void LUA_Archive(void) if (gamestate == GS_LEVEL) { for (th = thinkercap.next; th != &thinkercap; th = th->next) - if (th->function.acp1 == (actionf_p1)P_MobjThinker) - { - // archive function will determine when to skip mobjs, - // and write mobjnum in otherwise. - ArchiveExtVars(th, "mobj"); - } + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + + // archive function will determine when to skip mobjs, + // and write mobjnum in otherwise. + ArchiveExtVars(th, "mobj"); + } } WRITEUINT32(save_p, UINT32_MAX); // end of mobjs marker, replaces mobjnum. @@ -1627,9 +1629,13 @@ void LUA_UnArchive(void) do { mobjnum = READUINT32(save_p); // read a mobjnum for (th = thinkercap.next; th != &thinkercap; th = th->next) - if (th->function.acp1 == (actionf_p1)P_MobjThinker - && ((mobj_t *)th)->mobjnum == mobjnum) // find matching mobj - UnArchiveExtVars(th); // apply variables + { + if (th->function.acp1 != (actionf_p1)P_MobjThinker) + continue; + if (((mobj_t *)th)->mobjnum != mobjnum) // find matching mobj + continue; + UnArchiveExtVars(th); // apply variables + } } while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker. LUAh_NetArchiveHook(NetUnArchive); // call the NetArchive hook in unarchive mode diff --git a/src/m_cheat.c b/src/m_cheat.c index 91ca536c8..abada4be5 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -909,8 +909,9 @@ static mapthing_t *OP_CreateNewMapThing(player_t *player, UINT16 type, boolean c mo = (mobj_t *)th; // get offset from mt, which points to old mapthings, then add new location - if (mo->spawnpoint) - mo->spawnpoint = (mo->spawnpoint - mt) + mapthings; + if (!mo->spawnpoint) + continue; + mo->spawnpoint = (mo->spawnpoint - mt) + mapthings; } } diff --git a/src/p_enemy.c b/src/p_enemy.c index caa85e331..3a032fbf0 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -2418,9 +2418,11 @@ void A_1upThinker(mobj_t *actor) if (closestplayer == -1 || skins[players[closestplayer].skin].spritedef.numframes <= states[S_PLAY_BOX1].frame) { // Closest player not found (no players in game?? may be empty dedicated server!), or does not have correct sprite. actor->frame = 0; - if (actor->tracer) { - P_RemoveMobj(actor->tracer); - P_SetTarget(&actor->target, NULL); + if (actor->tracer) + { + mobj_t *tracer = actor->tracer; + P_SetTarget(&actor->tracer, NULL); + P_RemoveMobj(tracer); } return; } diff --git a/src/p_floor.c b/src/p_floor.c index 27460eda6..bebc9a272 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -1968,32 +1968,8 @@ void T_ThwompSector(levelspecthink_t *thwomp) } else // Not going anywhere, so look for players. { - //thinker_t *th; - //mobj_t *mo; - thwomp->direction = -1; - /* // SRB2kart 170217 - Thwomps are automatic. - // scan the thinkers to find players! - if (!rover || (rover->flags & FF_EXISTS)) - { - // scan the thinkers to find players! - for (th = thinkercap.next; th != &thinkercap; th = th->next) - { - if (th->function.acp1 != (actionf_p1)P_MobjThinker) - continue; - - mo = (mobj_t *)th; - if (mo->type == MT_PLAYER && mo->health && mo->player && !mo->player->spectator - && mo->z <= thwomp->sector->ceilingheight - && P_AproxDistance(thwompx - mo->x, thwompy - mo->y) <= 96*FRACUNIT) - { - thwomp->direction = -1; - break; - } - } - }*/ - thwomp->sector->ceilspeed = 0; thwomp->sector->floorspeed = 0; } diff --git a/src/p_mobj.c b/src/p_mobj.c index ac983fdfd..711bc8b33 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -4114,11 +4114,21 @@ static void P_Boss3Thinker(mobj_t *mobj) continue; mo2 = (mobj_t *)th; - if (mo2->type == MT_BOSS3WAYPOINT && mo2->spawnpoint && mo2->spawnpoint->angle == mobj->threshold) - { - P_SetTarget(&mobj->target, mo2); - break; - } + + if (!mo2) + continue; + + if (mo2->type != MT_BOSS3WAYPOINT) + continue; + + if (!mo2->spawnpoint) + continue; + + if (mo2->spawnpoint->angle != mobj->threshold) + continue; + + P_SetTarget(&mobj->target, mo2); + break; } if (!mobj->target) // Should NEVER happen @@ -10005,28 +10015,19 @@ void P_RemoveMobj(mobj_t *mobj) // killough 11/98: // // Remove any references to other mobjs. - P_SetTarget(&mobj->target, P_SetTarget(&mobj->tracer, NULL)); + P_SetTarget(&mobj->target, NULL); + P_SetTarget(&mobj->tracer, NULL); - // repair hnext chain - { - mobj_t *cachenext = mobj->hnext; + if (mobj->hnext && !P_MobjWasRemoved(mobj->hnext)) + P_SetTarget(&mobj->hnext->hprev, mobj->hprev); + if (mobj->hprev && !P_MobjWasRemoved(mobj->hprev)) + P_SetTarget(&mobj->hprev->hnext, mobj->hnext); - if (mobj->hnext && !P_MobjWasRemoved(mobj->hnext)) - { - P_SetTarget(&mobj->hnext->hprev, mobj->hprev); - P_SetTarget(&mobj->hnext, NULL); - } - - if (mobj->hprev && !P_MobjWasRemoved(mobj->hprev)) - { - P_SetTarget(&mobj->hprev->hnext, cachenext); - P_SetTarget(&mobj->hprev, NULL); - } - } + P_SetTarget(&mobj->hnext, P_SetTarget(&mobj->hprev, NULL)); // clear the reference from the mapthing if (mobj->spawnpoint) - mobj->spawnpoint->mobj = NULL; + P_SetTarget(&mobj->spawnpoint->mobj, NULL); R_RemoveMobjInterpolator(mobj); @@ -11777,11 +11778,12 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) { P_SetTarget(&mobj->hprev, nextmobj); P_SetTarget(&mobj->hprev->hnext, mobj); - //mobj->hprev = nextmobj; - //mobj->hprev->hnext = mobj; } else - mobj->hprev = mobj->hnext = NULL; + { + P_SetTarget(&mobj->hprev, NULL); + P_SetTarget(&mobj->hnext, NULL); + } nextmobj = mobj; } @@ -11807,11 +11809,9 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) mobj->z -= mobj->height/2; // Link all the collision sprites together. - mobj->hnext = NULL; + P_SetTarget(&mobj->hnext, NULL); P_SetTarget(&mobj->hprev, nextmobj); P_SetTarget(&mobj->hprev->hnext, mobj); - //mobj->hprev = nextmobj; - //mobj->hprev->hnext = mobj; nextmobj = mobj; } @@ -11836,11 +11836,9 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) mobj->z -= mobj->height/2; // Link all the collision sprites together. - mobj->hnext = NULL; + P_SetTarget(&mobj->hnext, NULL); P_SetTarget(&mobj->hprev, nextmobj); P_SetTarget(&mobj->hprev->hnext, mobj); - //mobj->hprev = nextmobj; - //mobj->hprev->hnext = mobj; nextmobj = mobj; } @@ -11923,11 +11921,12 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) { P_SetTarget(&mobj->hprev, nextmobj); P_SetTarget(&mobj->hprev->hnext, mobj); - //mobj->hprev = nextmobj; - //mobj->hprev->hnext = mobj; } else - mobj->hprev = mobj->hnext = NULL; + { + P_SetTarget(&mobj->hprev, NULL); + P_SetTarget(&mobj->hnext, NULL); + } nextmobj = mobj; } @@ -11964,11 +11963,9 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) mobj->z -= mobj->height/2; // Link all the collision sprites together. - mobj->hnext = NULL; + P_SetTarget(&mobj->hnext, NULL); P_SetTarget(&mobj->hprev, nextmobj); P_SetTarget(&mobj->hprev->hnext, mobj); - //mobj->hprev = nextmobj; - //mobj->hprev->hnext = mobj; nextmobj = mobj; } diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 9a3376595..bbf934231 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -1826,11 +1826,14 @@ void T_PolyObjWaypoint(polywaypoint_t *th) if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold == th->sequence && mo2->health == th->pointnum) - { - target = mo2; - break; - } + if (mo2->threshold != th->sequence) + continue; + + if (mo2->health != th->pointnum) + continue; + + target = mo2; + break; } if (!target) @@ -1907,23 +1910,23 @@ void T_PolyObjWaypoint(polywaypoint_t *th) if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold == th->sequence) + if (mo2->threshold != th->sequence) + continue; + + if (th->direction == -1) { - if (th->direction == -1) + if (mo2->health == target->health - 1) { - if (mo2->health == target->health - 1) - { - waypoint = mo2; - break; - } + waypoint = mo2; + break; } - else + } + else + { + if (mo2->health == target->health + 1) { - if (mo2->health == target->health + 1) - { - waypoint = mo2; - break; - } + waypoint = mo2; + break; } } } @@ -1946,22 +1949,22 @@ void T_PolyObjWaypoint(polywaypoint_t *th) if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold == th->sequence) + if (mo2->threshold != th->sequence) + continue; + + if (th->direction == -1) { - if (th->direction == -1) + if (waypoint == NULL) + waypoint = mo2; + else if (mo2->health > waypoint->health) + waypoint = mo2; + } + else + { + if (mo2->health == 0) { - if (waypoint == NULL) - waypoint = mo2; - else if (mo2->health > waypoint->health) - waypoint = mo2; - } - else - { - if (mo2->health == 0) - { - waypoint = mo2; - break; - } + waypoint = mo2; + break; } } } @@ -1983,23 +1986,23 @@ void T_PolyObjWaypoint(polywaypoint_t *th) if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold == th->sequence) + if (mo2->threshold != th->sequence) + continue; + + if (th->direction == -1) { - if (th->direction == -1) + if (mo2->health == target->health - 1) { - if (mo2->health == target->health - 1) - { - waypoint = mo2; - break; - } + waypoint = mo2; + break; } - else + } + else + { + if (mo2->health == target->health + 1) { - if (mo2->health == target->health + 1) - { - waypoint = mo2; - break; - } + waypoint = mo2; + break; } } } @@ -2503,31 +2506,31 @@ INT32 EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata) if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold == th->sequence) + if (mo2->threshold != th->sequence) + continue; + + if (th->direction == -1) // highest waypoint # { - if (th->direction == -1) // highest waypoint # + if (mo2->health == 0) + last = mo2; + else { - if (mo2->health == 0) - last = mo2; - else - { - if (first == NULL) - first = mo2; - else if (mo2->health > first->health) - first = mo2; - } - } - else // waypoint 0 - { - if (mo2->health == 0) + if (first == NULL) first = mo2; - else - { - if (last == NULL) - last = mo2; - else if (mo2->health > last->health) - last = mo2; - } + else if (mo2->health > first->health) + first = mo2; + } + } + else // waypoint 0 + { + if (mo2->health == 0) + first = mo2; + else + { + if (last == NULL) + last = mo2; + else if (mo2->health > last->health) + last = mo2; } } } @@ -2564,36 +2567,6 @@ INT32 EV_DoPolyObjWaypoint(polywaypointdata_t *pwdata) // Find the actual target movement waypoint target = first; - /*for (wp = thinkercap.next; wp != &thinkercap; wp = wp->next) - { - if (wp->function.acp1 != (actionf_p1)P_MobjThinker) // Not a mobj thinker - continue; - - mo2 = (mobj_t *)wp; - - if (mo2->type != MT_TUBEWAYPOINT) - continue; - - if (mo2->threshold == th->sequence) - { - if (th->direction == -1) // highest waypoint # - { - if (mo2->health == first->health - 1) - { - target = mo2; - break; - } - } - else // waypoint 0 - { - if (mo2->health == first->health + 1) - { - target = mo2; - break; - } - } - } - }*/ if (!target) { diff --git a/src/p_saveg.c b/src/p_saveg.c index e260321be..be393c51b 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1881,8 +1881,10 @@ mobj_t *P_FindNewPosition(UINT32 oldposition) continue; mobj = (mobj_t *)th; - if (mobj->mobjnum == oldposition) - return mobj; + if (mobj->mobjnum != oldposition) + continue; + + return mobj; } CONS_Debug(DBG_GAMELOGIC, "mobj not found\n"); return NULL; @@ -2881,12 +2883,14 @@ static void P_NetUnArchiveThinkers(void) for (currentthinker = thinkercap.next; currentthinker != &thinkercap; currentthinker = currentthinker->next) { - if (currentthinker->function.acp1 == (actionf_p1)T_ExecutorDelay) - { - delay = (void *)currentthinker; - if ((mobjnum = (UINT32)(size_t)delay->caller)) - delay->caller = P_FindNewPosition(mobjnum); - } + if (currentthinker->function.acp1 != (actionf_p1)T_ExecutorDelay) + continue; + + delay = (void *)currentthinker; + if (!(mobjnum = (UINT32)(size_t)delay->caller)) + continue; + + delay->caller = P_FindNewPosition(mobjnum); } } } diff --git a/src/p_spec.c b/src/p_spec.c index 1a5e02a78..e72cb5371 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3313,7 +3313,7 @@ boolean P_IsFlagAtBase(mobjtype_t flag) { thinker_t *think; mobj_t *mo; - INT32 specialnum = 0; + INT32 specialnum = (flag == MT_REDFLAG) ? 3 : 4; for (think = thinkercap.next; think != &thinkercap; think = think->next) { @@ -3325,11 +3325,6 @@ boolean P_IsFlagAtBase(mobjtype_t flag) if (mo->type != flag) continue; - if (mo->type == MT_REDFLAG) - specialnum = 3; - else if (mo->type == MT_BLUEFLAG) - specialnum = 4; - if (GETSECSPECIAL(mo->subsector->sector->special, 4) == specialnum) return true; else if (mo->subsector->sector->ffloors) // Check the 3D floors @@ -3344,9 +3339,11 @@ boolean P_IsFlagAtBase(mobjtype_t flag) if (GETSECSPECIAL(rover->master->frontsector->special, 4) != specialnum) continue; - if (mo->z <= P_GetSpecialTopZ(mo, sectors + rover->secnum, mo->subsector->sector) - && mo->z >= P_GetSpecialBottomZ(mo, sectors + rover->secnum, mo->subsector->sector)) - return true; + if (!(mo->z <= P_GetSpecialTopZ(mo, sectors + rover->secnum, mo->subsector->sector) + && mo->z >= P_GetSpecialBottomZ(mo, sectors + rover->secnum, mo->subsector->sector))) + continue; + + return true; } } } @@ -3762,8 +3759,11 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers continue; mo2 = (mobj_t *)th; - if (mo2->type == MT_EGGTRAP) - P_KillMobj(mo2, NULL, player->mo); + + if (mo2->type != MT_EGGTRAP) + continue; + + P_KillMobj(mo2, NULL, player->mo); } // clear the special so you can't push the button twice. @@ -4104,12 +4104,15 @@ DoneSection2: mo2 = (mobj_t *)th; - if (mo2->type == MT_TUBEWAYPOINT && mo2->threshold == sequence - && mo2->health == 0) - { - waypoint = mo2; - break; - } + if (mo2->type != MT_TUBEWAYPOINT) + continue; + if (mo2->threshold != sequence) + continue; + if (mo2->health != 0) + continue; + + waypoint = mo2; + break; } if (!waypoint) @@ -4180,13 +4183,15 @@ DoneSection2: mo2 = (mobj_t *)th; - if (mo2->type == MT_TUBEWAYPOINT && mo2->threshold == sequence) - { - if (!waypoint) - waypoint = mo2; - else if (mo2->health > waypoint->health) - waypoint = mo2; - } + if (mo2->type != MT_TUBEWAYPOINT) + continue; + if (mo2->threshold != sequence) + continue; + + if (!waypoint) + waypoint = mo2; + else if (mo2->health > waypoint->health) + waypoint = mo2; } if (!waypoint) diff --git a/src/p_user.c b/src/p_user.c index 74e9ae785..c3dacfa60 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -2629,15 +2629,17 @@ static void P_DoZoomTube(player_t *player) if (mo2->type != MT_TUBEWAYPOINT) continue; - if (mo2->threshold == sequence) - { - if ((reverse && mo2->health == player->mo->tracer->health - 1) - || (!reverse && mo2->health == player->mo->tracer->health + 1)) - { - waypoint = mo2; - break; - } - } + if (mo2->threshold != sequence) + continue; + + if (reverse && mo2->health != player->mo->tracer->health - 1) + continue; + + if (!reverse && mo2->health != player->mo->tracer->health + 1) + continue; + + waypoint = mo2; + break; } if (waypoint)