From cf593c2d3000cb6a4cc1f4bfd2ac4946258afb6b Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 8 Jun 2026 09:44:19 +0200 Subject: [PATCH] cleanup p_spec/p_setup a bit --- src/p_setup.c | 26 ++++++------ src/p_spec.c | 114 ++++++++++++++++++++++++++++++++++---------------- src/sounds.c | 2 +- 3 files changed, 91 insertions(+), 51 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 6483e00ef..6f894b828 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1218,14 +1218,14 @@ static void P_LoadSideChangeMusic(boolean firstside, mapsidedef_t *msd, side_t * if (msd->bottomtexture[0] != '-' || msd->bottomtexture[1] != '\0') { - memcpy(process,msd->bottomtexture,8); + memcpy(process, msd->bottomtexture, 8); process[8] = '\0'; sd->bottomtexture = get_number(process); } if (!(msd->midtexture[0] == '-' && msd->midtexture[1] == '\0') || msd->midtexture[1] != '\0') { - memcpy(process,msd->midtexture,8); + memcpy(process, msd->midtexture, 8); process[8] = '\0'; sd->midtexture = get_number(process); } @@ -1235,7 +1235,7 @@ static void P_LoadSideChangeMusic(boolean firstside, mapsidedef_t *msd, side_t * if (firstside || msd->toptexture[0] != '-' || msd->toptexture[1] != '\0') { - memcpy(process,msd->toptexture,8); + memcpy(process, msd->toptexture, 8); process[8] = '\0'; // If they type in O_ or D_ and their music name, just shrug, @@ -1275,7 +1275,7 @@ static void P_LoadSidedefs(void *data) // Colormaps! switch (sd->special) { - case 63: // variable colormap via 242 linedef + case 63: // variable colormap via 242 linedef case 606: //SoM: 4/4/2000: Just colormap transfer // SoM: R_CreateColormap will only create a colormap in software mode... // Perhaps we should just call it instead of doing the calculations here. @@ -1291,21 +1291,21 @@ static void P_LoadSidedefs(void *data) if (msd->toptexture[0] != '-' || msd->toptexture[1] != '\0') { char process[8+1]; - memcpy(process,msd->toptexture,8); + memcpy(process, msd->toptexture, 8); process[8] = '\0'; sd->toptexture = get_number(process); } break; } - case 9: // Mace parameters - case 14: // Bustable block parameters - case 15: // Fan particle spawner parameters + case 9: // Mace parameters + case 14: // Bustable block parameters + case 15: // Fan particle spawner parameters case 425: // Calls P_SetMobjState on calling mobj case 434: // Custom Power case 442: // Calls P_SetMobjState on mobjs of a given type in the tagged sectors { char process[8*3+1]; - memset(process,0,8*3+1); + memset(process, 0, 8*3+1); sd->toptexture = sd->midtexture = sd->bottomtexture = 0; if (msd->toptexture[0] == '-' && msd->toptexture[1] == '\0') break; @@ -1322,7 +1322,7 @@ static void P_LoadSidedefs(void *data) case 443: // Calls a named Lua function { char process[8*3+1]; - memset(process,0,8*3+1); + memset(process, 0, 8*3+1); sd->toptexture = sd->midtexture = sd->bottomtexture = 0; if (msd->toptexture[0] == '-' && msd->toptexture[1] == '\0') break; @@ -2934,7 +2934,7 @@ static size_t sreplaces = 0, mreplaces = 0, digmreplaces = 0; static boolean P_CheckSoundReplacements(UINT16 wadnum, char *name, size_t i) { size_t j; - lumpnum_t lumpnum = (i|(wadnum<<16)); + lumpnum_t lumpnum = (i | (wadnum<<16)); if (name[0] == 'D') { @@ -2942,8 +2942,8 @@ static boolean P_CheckSoundReplacements(UINT16 wadnum, char *name, size_t i) { for (j = 1; j < NUMSFX; j++) { - if (S_sfx[j].name && !strnicmp(S_sfx[j].name, name + 2, 6) - && (S_sfx[j].lumpnum != lumpnum) && (S_sfx[j].lumpnum != LUMPERROR)) + if ((S_sfx[j].lumpnum != lumpnum) && (S_sfx[j].lumpnum != LUMPERROR) && + S_sfx[j].name && !strnicmp(S_sfx[j].name, name + 2, 6)) { // the sound will be reloaded when needed, // since sfx->data will be NULL diff --git a/src/p_spec.c b/src/p_spec.c index c4b94f676..34a883d11 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1338,6 +1338,7 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller else if (secspecial == 7) // SRB2Kart: reusing for Race Lap executor { UINT8 lap; + INT32 targlap; if (actor && actor->player && triggerline->flags & ML_EFFECT4) { @@ -1348,19 +1349,21 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller lap = P_FindLowestLap(); } + targlap = (INT32)(sides[triggerline->sidenum[0]].textureoffset >> FRACBITS); + if (triggerline->flags & ML_NOCLIMB) // Need higher than or equal to { - if (lap < (sides[triggerline->sidenum[0]].textureoffset >> FRACBITS)) + if (lap < targlap) return false; } else if (triggerline->flags & ML_BLOCKMONSTERS) // Need lower than or equal to { - if (lap > (sides[triggerline->sidenum[0]].textureoffset >> FRACBITS)) + if (lap > targlap) return false; } else // Need equal to { - if (lap != (sides[triggerline->sidenum[0]].textureoffset >> FRACBITS)) + if (lap != targlap) return false; } @@ -1452,6 +1455,7 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller if (triggerline->flags & ML_EFFECT5) // disregard order for efficiency { for (i = 0; i < linecnt; i++) + { if (ctlsector->lines[i]->special >= 400 && ctlsector->lines[i]->special < 500) { @@ -1460,6 +1464,7 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller else P_ProcessLineSpecial(ctlsector->lines[i], actor, caller); } + } } else // walk around the sector in a defined order { @@ -1467,11 +1472,13 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller size_t j, masterlineindex = (size_t)-1; for (i = 0; i < linecnt; i++) + { if (ctlsector->lines[i] == triggerline) { masterlineindex = i; break; } + } #ifdef PARANOIA if (masterlineindex == (size_t)-1) @@ -1490,11 +1497,13 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller { if (i == j) continue; + if (ctlsector->lines[i]->v1 == ctlsector->lines[j]->v2) { i = j; break; } + if (ctlsector->lines[i]->v1 == ctlsector->lines[j]->v1) { i = j; @@ -1502,6 +1511,7 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller break; } } + if (j == linecnt) { const size_t vertexei = (size_t)(ctlsector->lines[i]->v1 - vertexes); @@ -1516,11 +1526,13 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller { if (i == j) continue; + if (ctlsector->lines[i]->v2 == ctlsector->lines[j]->v1) { i = j; break; } + if (ctlsector->lines[i]->v2 == ctlsector->lines[j]->v2) { i = j; @@ -2423,7 +2435,8 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) P_SetPlayerMobjState(mo, S_KART_STND1); // SRB2kart - was S_PLAY_STND // Reset bot too. - if (bot) { + if (bot) + { if (line->flags & ML_NOCLIMB) P_SetOrigin(bot, mo->x, mo->y, mo->z); bot->momx = bot->momy = bot->momz = 1; @@ -2506,6 +2519,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) P_SetTarget(&dummy->target, bot); A_CustomPower(dummy); } + P_RemoveMobj(dummy); } break; @@ -2569,11 +2583,15 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (mo && mo->player) { UINT16 fractime = (UINT16)(sides[line->sidenum[0]].textureoffset>>FRACBITS); + if (fractime < 1) fractime = 1; //instantly wears off upon leaving + if (line->flags & ML_NOCLIMB) fractime |= 1<<15; //more crazy &ing, as if music stuff wasn't enough + mo->player->powers[pw_nocontrol] = fractime; + if (bot) bot->player->powers[pw_nocontrol] = fractime; } @@ -2583,8 +2601,10 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (mo) { mo->destscale = FixedDiv(P_AproxDistance(line->dx, line->dy), 100<destscale < FRACUNIT/100) mo->destscale = FRACUNIT/100; + if (mo->player && bot) bot->destscale = mo->destscale; } @@ -2669,9 +2689,11 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { boolean tryagain; sec = sectors + secnum; + do { tryagain = false; for (thing = sec->thinglist; thing; thing = thing->snext) + { if (thing->type == type) { if (state != NUMSTATES) @@ -2688,6 +2710,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; } } + } } while (tryagain); } break; @@ -3263,6 +3286,7 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers case 3: // Linedef executor requires all players present // Trigger Linedef Exec (Floor Touch, All Players) /// \todo check continues for proper splitscreen support? for (i = 0; i < MAXPLAYERS; i++) + { if (playeringame[i] && !players[i].bot && players[i].mo && (gametype != GT_COOP || players[i].lives > 0)) { if (roversector) @@ -3316,6 +3340,7 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers goto DoneSection2; } } + } /* FALLTHRU */ case 4: // Linedef executor that doesn't require touching floor // Trigger Linedef Exec (Anywhere in Sector) case 5: // Linedef executor // Trigger Linedef Exec (Floor Touch) @@ -3451,8 +3476,10 @@ DoneSection2: angle_t lineangle; fixed_t linespeed; - lineangle = lines[i].angle; - linespeed = P_AproxDistance(lines[i].v2->x-lines[i].v1->x, lines[i].v2->y-lines[i].v1->y); + const line_t *line = &lines[i]; + + lineangle = line->angle; + linespeed = P_AproxDistance(line->v2->x-line->v1->x, line->v2->y-line->v1->y); player->mo->angle = lineangle; @@ -3466,7 +3493,7 @@ DoneSection2: P_ForceLocalAngle(player, player->mo->angle); } - if (!(lines[i].flags & ML_EFFECT4)) + if (!(line->flags & ML_EFFECT4)) { P_UnsetThingPosition(player->mo); if (roversector) // make FOF speed pads work @@ -3537,21 +3564,25 @@ DoneSection2: P_DoPlayerExit(player); P_SetupSignExit(player); - // important: use sector->tag on next line instead of player->mo->subsector->tag - // this part is different from in P_PlayerThink, this is what was causing - // FOF custom exits not to work. - lineindex = P_FindSpecialLineFromTag(2, sector->tag, -1); - if (gametype == GT_COOP && lineindex != -1) // Custom exit! + if (gametype == GT_COOP) { - // Special goodies with the block monsters flag depending on emeralds collected - if ((lines[lineindex].flags & ML_BLOCKMONSTERS) && ALL7EMERALDS(emeralds)) - nextmapoverride = (INT16)(lines[lineindex].frontsector->ceilingheight>>FRACBITS); - else - nextmapoverride = (INT16)(lines[lineindex].frontsector->floorheight>>FRACBITS); + // important: use sector->tag on next line instead of player->mo->subsector->tag + // this part is different from in P_PlayerThink, this is what was causing + // FOF custom exits not to work. + lineindex = P_FindSpecialLineFromTag(2, sector->tag, -1); - if (lines[lineindex].flags & ML_NOCLIMB) - skipstats = true; + if (lineindex != -1) // Custom exit!) + { + // Special goodies with the block monsters flag depending on emeralds collected + if ((lines[lineindex].flags & ML_BLOCKMONSTERS) && ALL7EMERALDS(emeralds)) + nextmapoverride = (INT16)(lines[lineindex].frontsector->ceilingheight>>FRACBITS); + else + nextmapoverride = (INT16)(lines[lineindex].frontsector->floorheight>>FRACBITS); + + if (lines[lineindex].flags & ML_NOCLIMB) + skipstats = true; + } } } break; @@ -3658,7 +3689,6 @@ DoneSection2: mobj_t *waypoint = NULL; mobj_t *mo2; - if (player->mo->tracer && player->mo->tracer->type == MT_TUBEWAYPOINT) break; @@ -4523,27 +4553,13 @@ void P_PlayerInSpecialSector(player_t *player) #undef TELEPORTED -/** Animate planes, scroll walls, etc. and keeps track of level timelimit and exits if time is up. - * - * \sa P_CheckTimeLimit, P_CheckPointLimit - */ -void P_UpdateSpecials(void) +static void P_UpdateAnimFlats(void) { anim_t *anim; INT32 i; size_t j; levelflat_t *foundflats; // for flat animation - // LEVEL TIMER - P_CheckTimeLimit(); - - // POINT LIMIT - P_CheckPointLimit(); - - // Dynamic slopeness - if (!midgamejoin) // run here when not joined midgame to prevent any potential issues that may arise - P_RunDynamicSlopes(); - // ANIMATE TEXTURES for (anim = anims; anim < lastanim; anim++) { @@ -4573,15 +4589,38 @@ void P_UpdateSpecials(void) } } +/** Animate planes, scroll walls, etc. and keeps track of level timelimit and exits if time is up. + * + * \sa P_CheckTimeLimit, P_CheckPointLimit + */ +void P_UpdateSpecials(void) +{ + // LEVEL TIMER + P_CheckTimeLimit(); + + // POINT LIMIT + P_CheckPointLimit(); + + // Dynamic slopeness + // we run this here only when not joined midrace + // for vanilla compat reasons :chaosleep: + if (!midgamejoin) + P_RunDynamicSlopes(); + + P_UpdateAnimFlats(); +} + static inline ffloor_t *P_GetFFloorBySec(sector_t *sec, sector_t *sec2) { ffloor_t *rover; if (!sec->ffloors) return NULL; + for (rover = sec->ffloors; rover; rover = rover->next) if (rover->secnum == (size_t)(sec2 - sectors)) return rover; + return NULL; } @@ -4632,6 +4671,7 @@ static ffloor_t *P_AddFakeFloor(sector_t *sec, sector_t *sec2, line_t *master, f if (sec == sec2) return NULL; //Don't need a fake floor on a control sector. + if ((ffloor = (P_GetFFloorBySec(sec, sec2)))) return ffloor; // If this ffloor already exists, return it @@ -7032,9 +7072,9 @@ static void Add_Pusher(pushertype_e type, fixed_t x_mag, fixed_t y_mag, mobj_t * // "The right triangle of the square of the length of the hypotenuse is equal to the sum of the squares of the lengths of the other two sides." // "Bah! Stupid brains! Don't you know anything besides the Pythagorean Theorem?" - Earthworm Jim if (type == p_downcurrent || type == p_upcurrent || type == p_upwind || type == p_downwind) - p->magnitude = P_AproxDistance(p->x_mag,p->y_mag)<<(FRACBITS-PUSH_FACTOR); + p->magnitude = P_AproxDistance(p->x_mag, p->y_mag)<<(FRACBITS-PUSH_FACTOR); else - p->magnitude = P_AproxDistance(p->x_mag,p->y_mag); + p->magnitude = P_AproxDistance(p->x_mag, p->y_mag); if (source) // point source exist? { diff --git a/src/sounds.c b/src/sounds.c index 611539abe..3769bf65b 100644 --- a/src/sounds.c +++ b/src/sounds.c @@ -975,7 +975,7 @@ sfxinfo_t S_sfx[NUMSFX] = char freeslotnames[sfx_freeslot0 + NUMSFXFREESLOTS + NUMSKINSFXSLOTS][7] = {}; // Prepare free sfx slots to add sfx at run time -void S_InitRuntimeSounds (void) +void S_InitRuntimeSounds(void) { sfxenum_t i; INT32 value;