From 8867dc959eab5e03ff6af7765c2fd2e6a550d3f2 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 20 Sep 2025 16:29:55 +0200 Subject: [PATCH] dedupe and cleanup nights hoops spawn most of the actual spawn is split into P_SpawnNiGHTSHoop, which takes arguments to determine if to spawn just a hoop or its collision detectors (if you wonder why this takes a mobj pointer to pointer is due to collision detector need the former hoops last mobj to link into) - also actually fixes midgame join crash (hoop hnext was directly nulled instead of using p_settarget) - added some extra safety checks - reduced the amounts of r_pointinsubsector calls for things that used to go through this function --- src/m_cheat.c | 15 ++- src/p_inter.c | 17 ++- src/p_mobj.c | 346 +++++++++++++++++--------------------------------- src/p_mobj.h | 2 +- src/p_saveg.c | 2 +- src/p_setup.c | 5 +- 6 files changed, 140 insertions(+), 247 deletions(-) diff --git a/src/m_cheat.c b/src/m_cheat.c index d4120368d..85caaa234 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -830,18 +830,18 @@ void OP_NightsObjectplace(player_t *player) mt->options = (UINT16)((player->mo->z - fheight)>>FRACBITS); mt->angle = (INT16)(mt->angle+(INT16)((FixedInt(FixedDiv(temp*FRACUNIT, 360*(FRACUNIT/256))))<<8)); - P_SpawnHoopsAndRings(mt); + P_SpawnHoops(mt); } // This places a ring! - if (cmd->buttons & BT_BACKWARD) + /*if (cmd->buttons & BT_BACKWARD) { player->pflags |= PF_ATTACKDOWN; if (!OP_HeightOkay(player, false)) return; mt = OP_CreateNewMapThing(player, (UINT16)mobjinfo[MT_RING].doomednum, false); - P_SpawnHoopsAndRings(mt); + //P_SpawnHoopsAndRings(mt); } // This places a wing item! @@ -852,8 +852,8 @@ void OP_NightsObjectplace(player_t *player) return; mt = OP_CreateNewMapThing(player, (UINT16)mobjinfo[MT_NIGHTSWING].doomednum, false); - P_SpawnHoopsAndRings(mt); - } + //P_SpawnHoopsAndRings(mt); + }*/ // This places a custom object as defined in the console cv_mapthingnum. if (cmd->buttons & BT_BRAKE) @@ -891,7 +891,7 @@ void OP_NightsObjectplace(player_t *player) || mt->type == 1705 || mt->type == 1713 // NiGHTS Hoops || mt->type == 1800) // Mario Coin { - P_SpawnHoopsAndRings(mt); + P_SpawnHoops(mt); } else P_SpawnMapThing(mt); @@ -1022,7 +1022,8 @@ void OP_ObjectplaceMovement(player_t *player) || mt->type == 1705 || mt->type == 1713 // NiGHTS Hoops || mt->type == 1800) // Mario Coin { - P_SpawnHoopsAndRings(mt); + // NiGHTS hoops only + P_SpawnHoops(mt); } else P_SpawnMapThing(mt); diff --git a/src/p_inter.c b/src/p_inter.c index 7746459f5..6eb6779a0 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -890,16 +890,19 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) break; case MT_HOOPCOLLIDE: // This produces a kind of 'domino effect' with the hoop's pieces. - for (; !P_MobjWasRemoved(special->hprev); special = special->hprev); // Move to the first sprite in the hoop + for (; special->hprev != NULL; special = special->hprev); // Move to the first sprite in the hoop i = 0; - for (; !P_MobjWasRemoved(special->hnext) && special->type == MT_HOOP; special = special->hnext) + for (; special->hnext != NULL && special->type == MT_HOOP; special = special->hnext) { - special->fuse = 11; - special->movedir = i; - special->extravalue1 = special->target->extravalue1; - special->extravalue2 = special->target->extravalue2; - special->target->threshold = 4242; + if (!P_MobjWasRemoved(special->target)) + { + special->fuse = 11; + special->movedir = i; + special->extravalue1 = special->target->extravalue1; + special->extravalue2 = special->target->extravalue2; + special->target->threshold = 4242; + } i++; } // Make the collision detectors disappear. diff --git a/src/p_mobj.c b/src/p_mobj.c index 186d04046..3d437b1c5 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -11805,228 +11805,141 @@ ML_NOCLIMB : Direction not controllable mthing->mobj = mobj; } -void P_SpawnHoopsAndRings(mapthing_t *mthing) +static void P_SpawnNiGHTSHoop(fixed_t x, fixed_t y, fixed_t z, fixed_t hoopsize, fixed_t hoopplacement, angle_t closestangle, INT16 spewangle, mobj_t *hoopcenter, mobj_t **nextmobj, mobjtype_t type) { - mobj_t *mobj = NULL; - INT32 /*r,*/ i; - fixed_t x, y, z, finalx, finaly, finalz; - sector_t *sec; + INT32 i; + angle_t fa; TVector v, *res; - angle_t closestangle, fa; + mobj_t *mobj = NULL; + + for (i = 0; i < hoopsize; i++) + { + fa = i*(FINEANGLES/hoopsize); + v[0] = FixedMul(FINECOSINE(fa), hoopplacement); + v[1] = 0; + v[2] = FixedMul(FINESINE(fa), hoopplacement); + v[3] = FRACUNIT; + + res = VectorMatrixMultiply(v, *RotateXMatrix(FixedAngle(spewangle))); + M_Memcpy(&v, res, sizeof (v)); + res = VectorMatrixMultiply(v, *RotateZMatrix(closestangle)); + M_Memcpy(&v, res, sizeof (v)); + + mobj = P_SpawnMobj(x + v[0], y + v[1], z + v[2], type); + + if (P_MobjWasRemoved(mobj)) + continue; + + mobj->z -= mobj->height/2; + + if (hoopcenter) + { + P_SetTarget(&mobj->target, hoopcenter); // Link the sprite to the center. + + mobj->fuse = 0; + + // Link all the sprites in the hoop together + if (nextmobj && *nextmobj) + { + P_SetTarget(&mobj->hprev, *nextmobj); + P_SetTarget(&mobj->hprev->hnext, mobj); + } + else + P_SetTarget(&mobj->hprev, P_SetTarget(&mobj->hnext, NULL)); + } + else + { + // Link all the collision sprites together. + P_SetTarget(&mobj->hnext, NULL); + P_SetTarget(&mobj->hprev, *nextmobj); + P_SetTarget(&mobj->hprev->hnext, mobj); + } + + *nextmobj = mobj; + } +} + +void P_SpawnHoops(mapthing_t *mthing) +{ + fixed_t x, y, z; + fixed_t spewangle; + fixed_t sizefactor; + fixed_t hoopsize, hoopplacement; + sector_t *sec; + angle_t closestangle; + + mobj_t *hoopcenter; + mobj_t *nextmobj = NULL; + + // srb2kart - no rings or ring-like objects in R1 + if (mthing->type != 1705 && mthing->type != 1713) + return; x = mthing->x << FRACBITS; y = mthing->y << FRACBITS; sec = R_PointInSubsector(x, y)->sector; - // NiGHTS hoop! - if (mthing->type == 1705) - { - mobj_t *nextmobj = NULL; - mobj_t *hoopcenter; - INT16 spewangle; - + // Save our flags! + if (mthing->type == 1713) + z = (mthing->options >> ZSHIFT) << FRACBITS; + else z = mthing->options << FRACBITS; - hoopcenter = P_SpawnMobj(x, y, z, MT_HOOPCENTER); - hoopcenter->spawnpoint = mthing; + hoopcenter = P_SpawnMobj(x, y, z, MT_HOOPCENTER); - z += P_GetSectorFloorZAt(sec, x, y); - - hoopcenter->z = z - hoopcenter->height/2; - - P_UnsetThingPosition(hoopcenter); - hoopcenter->x = x; - hoopcenter->y = y; - P_SetThingPosition(hoopcenter); - - // Scale 0-255 to 0-359 =( - closestangle = FixedAngle(FixedMul((mthing->angle>>8)*FRACUNIT, - 360*(FRACUNIT/256))); - - hoopcenter->movedir = FixedInt(FixedMul((mthing->angle&255)*FRACUNIT, - 360*(FRACUNIT/256))); - hoopcenter->movecount = FixedInt(AngleFixed(closestangle)); - - // For the hoop when it flies away - hoopcenter->extravalue1 = 32; - hoopcenter->extravalue2 = 8 * FRACUNIT; - - spewangle = (INT16)hoopcenter->movedir; - - // Create the hoop! - for (i = 0; i < 32; i++) - { - fa = i*(FINEANGLES/32); - v[0] = FixedMul(FINECOSINE(fa),96*FRACUNIT); - v[1] = 0; - v[2] = FixedMul(FINESINE(fa),96*FRACUNIT); - v[3] = FRACUNIT; - - res = VectorMatrixMultiply(v, *RotateXMatrix(FixedAngle(spewangle*FRACUNIT))); - M_Memcpy(&v, res, sizeof (v)); - res = VectorMatrixMultiply(v, *RotateZMatrix(closestangle)); - M_Memcpy(&v, res, sizeof (v)); - - finalx = x + v[0]; - finaly = y + v[1]; - finalz = z + v[2]; - - mobj = P_SpawnMobj(finalx, finaly, finalz, MT_HOOP); - - mobj->z -= mobj->height/2; - - P_SetTarget(&mobj->target, hoopcenter); // Link the sprite to the center. - mobj->fuse = 0; - - // Link all the sprites in the hoop together - if (nextmobj) - { - P_SetTarget(&mobj->hprev, nextmobj); - P_SetTarget(&mobj->hprev->hnext, mobj); - } - else - mobj->hprev = mobj->hnext = NULL; - - nextmobj = mobj; - } - - // Create the collision detectors! - for (i = 0; i < 16; i++) - { - fa = i*FINEANGLES/16; - v[0] = FixedMul(FINECOSINE(fa),32*FRACUNIT); - v[1] = 0; - v[2] = FixedMul(FINESINE(fa),32*FRACUNIT); - v[3] = FRACUNIT; - res = VectorMatrixMultiply(v, *RotateXMatrix(FixedAngle(spewangle*FRACUNIT))); - M_Memcpy(&v, res, sizeof (v)); - res = VectorMatrixMultiply(v, *RotateZMatrix(closestangle)); - M_Memcpy(&v, res, sizeof (v)); - - finalx = x + v[0]; - finaly = y + v[1]; - finalz = z + v[2]; - - mobj = P_SpawnMobj(finalx, finaly, finalz, MT_HOOPCOLLIDE); - mobj->z -= mobj->height/2; - - // Link all the collision sprites together. - mobj->hnext = NULL; - P_SetTarget(&mobj->hprev, nextmobj); - P_SetTarget(&mobj->hprev->hnext, mobj); - - nextmobj = mobj; - } - // Create the collision detectors! - for (i = 0; i < 16; i++) - { - fa = i*FINEANGLES/16; - v[0] = FixedMul(FINECOSINE(fa),64*FRACUNIT); - v[1] = 0; - v[2] = FixedMul(FINESINE(fa),64*FRACUNIT); - v[3] = FRACUNIT; - res = VectorMatrixMultiply(v, *RotateXMatrix(FixedAngle(spewangle*FRACUNIT))); - M_Memcpy(&v, res, sizeof (v)); - res = VectorMatrixMultiply(v, *RotateZMatrix(closestangle)); - M_Memcpy(&v, res, sizeof (v)); - - finalx = x + v[0]; - finaly = y + v[1]; - finalz = z + v[2]; - - mobj = P_SpawnMobj(finalx, finaly, finalz, MT_HOOPCOLLIDE); - mobj->z -= mobj->height/2; - - // Link all the collision sprites together. - mobj->hnext = NULL; - P_SetTarget(&mobj->hprev, nextmobj); - P_SetTarget(&mobj->hprev->hnext, mobj); - - nextmobj = mobj; - } + if (P_MobjWasRemoved(hoopcenter)) return; - } - // CUSTOMIZABLE NiGHTS hoop! - else if (mthing->type == 1713) + + hoopcenter->spawnpoint = mthing; + + z += P_GetSectorFloorZAt(sec, x, y); + + hoopcenter->z -= hoopcenter->height/2; + + P_UnsetThingPosition(hoopcenter); + hoopcenter->x = x; + hoopcenter->y = y; + P_SetThingPosition(hoopcenter); + + // Scale 0-255 to 0-359 =( + closestangle = FixedAngle(FixedMul((mthing->angle >> 8)*FRACUNIT, 360*(FRACUNIT/256))); + + hoopcenter->movedir = FixedInt(FixedMul((mthing->angle & 255)*FRACUNIT, 360*(FRACUNIT/256))); + hoopcenter->movecount = FixedInt(AngleFixed(closestangle)); + + spewangle = (fixed_t)((INT16)hoopcenter->movedir * FRACUNIT); + + if (mthing->type == 1713) // CUSTOMIZABLE NiGHTS hoop! { - mobj_t *nextmobj = NULL; - mobj_t *hoopcenter; - INT16 spewangle; - INT32 hoopsize; - INT32 hoopplacement; - - // Save our flags! - z = (mthing->options>>ZSHIFT) << FRACBITS; - - hoopcenter = P_SpawnMobj(x, y, z, MT_HOOPCENTER); - hoopcenter->spawnpoint = mthing; - - z += P_GetSectorFloorZAt(sec, x, y); - hoopcenter->z = z - hoopcenter->height/2; - - P_UnsetThingPosition(hoopcenter); - hoopcenter->x = x; - hoopcenter->y = y; - P_SetThingPosition(hoopcenter); - - // Scale 0-255 to 0-359 =( - closestangle = FixedAngle(FixedMul((mthing->angle>>8)*FRACUNIT, - 360*(FRACUNIT/256))); - - hoopcenter->movedir = FixedInt(FixedMul((mthing->angle&255)*FRACUNIT, - 360*(FRACUNIT/256))); - hoopcenter->movecount = FixedInt(AngleFixed(closestangle)); - - spewangle = (INT16)hoopcenter->movedir; - // Super happy fun time // For each flag add 4 fracunits to the size // Default (0 flags) is 8 fracunits hoopsize = 8 + (4 * (mthing->options & 0xF)); - hoopplacement = hoopsize * (4*FRACUNIT); + sizefactor = 4*FRACUNIT; + hoopplacement = hoopsize * sizefactor; // For the hoop when it flies away hoopcenter->extravalue1 = hoopsize; hoopcenter->extravalue2 = FixedDiv(hoopplacement, 12*FRACUNIT); + } + else // NiGHTS hoop! + { + hoopsize = 32; + sizefactor = 32*FRACUNIT; + hoopplacement = 96*FRACUNIT; - // Create the hoop! - for (i = 0; i < hoopsize; i++) - { - fa = i*(FINEANGLES/hoopsize); - v[0] = FixedMul(FINECOSINE(fa), hoopplacement); - v[1] = 0; - v[2] = FixedMul(FINESINE(fa), hoopplacement); - v[3] = FRACUNIT; + // For the hoop when it flies away + hoopcenter->extravalue1 = hoopsize; + hoopcenter->extravalue2 = 8 * FRACUNIT; + } - res = VectorMatrixMultiply(v, *RotateXMatrix(FixedAngle(spewangle*FRACUNIT))); - M_Memcpy(&v, res, sizeof (v)); - res = VectorMatrixMultiply(v, *RotateZMatrix(closestangle)); - M_Memcpy(&v, res, sizeof (v)); + // Create the hoop! + P_SpawnNiGHTSHoop(x, y, z, hoopsize, hoopplacement, closestangle, spewangle, hoopcenter, &nextmobj, MT_HOOP); - finalx = x + v[0]; - finaly = y + v[1]; - finalz = z + v[2]; - - mobj = P_SpawnMobj(finalx, finaly, finalz, MT_HOOP); - - mobj->z -= mobj->height/2; - P_SetTarget(&mobj->target, hoopcenter); // Link the sprite to the center. - mobj->fuse = 0; - - // Link all the sprites in the hoop together - if (nextmobj) - { - P_SetTarget(&mobj->hprev, nextmobj); - P_SetTarget(&mobj->hprev->hnext, mobj); - } - else - mobj->hprev = mobj->hnext = NULL; - - nextmobj = mobj; - } - - // Create the collision detectors! + // Create the collision detectors! + if (mthing->type == 1713) + { // Create them until the size is less than 8 // But always create at least ONE set of collision detectors do @@ -12036,39 +11949,16 @@ void P_SpawnHoopsAndRings(mapthing_t *mthing) else hoopsize /= 2; - hoopplacement = hoopsize * (4*FRACUNIT); + hoopplacement = hoopsize * sizefactor; - for (i = 0; i < hoopsize; i++) - { - fa = i*FINEANGLES/hoopsize; - v[0] = FixedMul(FINECOSINE(fa), hoopplacement); - v[1] = 0; - v[2] = FixedMul(FINESINE(fa), hoopplacement); - v[3] = FRACUNIT; - res = VectorMatrixMultiply(v, *RotateXMatrix(FixedAngle(spewangle*FRACUNIT))); - M_Memcpy(&v, res, sizeof (v)); - res = VectorMatrixMultiply(v, *RotateZMatrix(closestangle)); - M_Memcpy(&v, res, sizeof (v)); - - finalx = x + v[0]; - finaly = y + v[1]; - finalz = z + v[2]; - - mobj = P_SpawnMobj(finalx, finaly, finalz, MT_HOOPCOLLIDE); - mobj->z -= mobj->height/2; - - // Link all the collision sprites together. - mobj->hnext = NULL; - P_SetTarget(&mobj->hprev, nextmobj); - P_SetTarget(&mobj->hprev->hnext, mobj); - - nextmobj = mobj; - } + P_SpawnNiGHTSHoop(x, y, z, hoopsize, hoopplacement, closestangle, spewangle, NULL, &nextmobj, MT_HOOPCOLLIDE); } while (hoopsize >= 8); - - return; } - else return; // srb2kart - no rings or ring-like objects in R1 + else + { + P_SpawnNiGHTSHoop(x, y, z, hoopsize/2, sizefactor, closestangle, spewangle, NULL, &nextmobj, MT_HOOPCOLLIDE); + P_SpawnNiGHTSHoop(x, y, z, hoopsize/2, sizefactor*2, closestangle, spewangle, NULL, &nextmobj, MT_HOOPCOLLIDE); + } } // diff --git a/src/p_mobj.h b/src/p_mobj.h index 2db5ba120..1123faf5b 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -501,7 +501,7 @@ void P_MovePlayerToStarpost(INT32 playernum); void P_AfterPlayerSpawn(INT32 playernum); void P_SpawnMapThing(mapthing_t *mthing); -void P_SpawnHoopsAndRings(mapthing_t *mthing); +void P_SpawnHoops(mapthing_t *mthing); void P_SpawnHoopOfSomething(fixed_t x, fixed_t y, fixed_t z, fixed_t radius, INT32 number, mobjtype_t type, angle_t rotangle); void P_SpawnPrecipitation(void); void P_SpawnParaloop(fixed_t x, fixed_t y, fixed_t z, fixed_t radius, INT32 number, mobjtype_t type, statenum_t nstate, angle_t rotangle, boolean spawncenter); diff --git a/src/p_saveg.c b/src/p_saveg.c index 6f4e67854..cb6d46062 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -2007,7 +2007,7 @@ static void LoadMobjThinker(savebuffer_t *save, actionf_p1 thinker) if (mapthings[spawnpointnum].type == 1705 || mapthings[spawnpointnum].type == 1713) // NiGHTS Hoop special case { - P_SpawnHoopsAndRings(&mapthings[spawnpointnum]); + P_SpawnHoops(&mapthings[spawnpointnum]); return; } diff --git a/src/p_setup.c b/src/p_setup.c index 892f44992..861e1c5ea 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -948,10 +948,9 @@ static void P_SpawnMapThings(void) mt->mobj = NULL; // Z for objects Tails 05-26-2002 - mt->z = (INT16)(R_PointInSubsector(mt->x << FRACBITS, mt->y << FRACBITS) - ->sector->floorheight>>FRACBITS); + mt->z = (INT16)(R_PointInSubsector(mt->x << FRACBITS, mt->y << FRACBITS)->sector->floorheight>>FRACBITS); - P_SpawnHoopsAndRings(mt); + P_SpawnHoops(mt); } } }