From d125ca6f0a95be16cc036899e00093be3ebf0a5f Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 1 Jun 2026 11:13:07 +0200 Subject: [PATCH] bunch of smaller optimizations and cleanups mostly avoiding needless work as per usual --- src/k_kart.c | 64 ++++++++++++++------ src/p_enemy.c | 12 ++-- src/p_floor.c | 17 ++++-- src/p_inter.c | 2 +- src/p_local.h | 1 - src/p_slopes.c | 2 + src/p_spec.c | 154 ++++++++++++++++++++++++++++++------------------- src/p_user.c | 37 +++++++----- 8 files changed, 186 insertions(+), 103 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index e58e0ad7c..50cde3525 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -1943,6 +1943,7 @@ void K_RespawnChecker(player_t *player) void K_KartMoveAnimation(player_t *player) { ticcmd_t *cmd = &player->cmd; + // Standing frames - S_KART_STND1 S_KART_STND1_L S_KART_STND1_R if (player->speed == 0) { @@ -2148,16 +2149,22 @@ static void K_HandleDelayedHitByEm(player_t *player) void K_MomentumToFacing(player_t *player) { - angle_t dangle = player->mo->angle - R_PointToAngle2(0, 0, player->mo->momx, player->mo->momy); - - if (dangle > ANGLE_180) - dangle = InvAngle(dangle); - // If you aren't on the ground or are moving in too different of a direction don't do this if (player->mo->eflags & MFE_JUSTHITFLOOR) ; // Just hit floor ALWAYS redirects - else if (!P_IsObjectOnGround(player->mo) || dangle > ANGLE_90) - return; + else + { + if (!P_IsObjectOnGround(player->mo)) + return; + + angle_t dangle = player->mo->angle - R_PointToAngle2(0, 0, player->mo->momx, player->mo->momy); + + if (dangle > ANGLE_180) + dangle = InvAngle(dangle); + + if (dangle > ANGLE_90) + return; + } P_Thrust(player->mo, player->mo->angle, player->speed - FixedMul(player->speed, player->mo->friction)); player->mo->momx = FixedMul(player->mo->momx - player->cmomx, player->mo->friction) + player->cmomx; @@ -2538,6 +2545,7 @@ void K_SpinPlayer(player_t *player, mobj_t *source, INT32 type, mobj_t *inflicto if (!player->kartstuff[k_bumper]) { player->kartstuff[k_comebacktimer] = comebacktime; + if (player->kartstuff[k_comebackmode] == 2) { mobj_t *poof = P_SpawnMobj(player->mo->x, player->mo->y, player->mo->z, MT_EXPLODE); @@ -2553,9 +2561,12 @@ void K_SpinPlayer(player_t *player, mobj_t *source, INT32 type, mobj_t *inflicto if (player->kartstuff[k_spinouttype] <= 0) // type 0 is spinout, type 1 is wipeout, type 2 is spb { + const fixed_t spd = K_GetKartSpeed(player, true)/4; + // At spinout, player speed is increased to 1/4 their regular speed, moving them forward - if (player->speed < K_GetKartSpeed(player, true)/4) - P_InstaThrust(player->mo, player->mo->angle, FixedMul(K_GetKartSpeed(player, true)/4, player->mo->scale)); + if (player->speed < spd) + P_InstaThrust(player->mo, player->mo->angle, FixedMul(spd, player->mo->scale)); + S_StartSound(player->mo, sfx_slip); } @@ -2566,10 +2577,12 @@ void K_SpinPlayer(player_t *player, mobj_t *source, INT32 type, mobj_t *inflicto P_SetPlayerMobjState(player->mo, S_KART_SPIN); player->kartstuff[k_instashield] = 15; + if (cv_kartdebughuddrop.value && !modeattacking) K_DropItems(player); else K_DropHnextList(player); + return; } @@ -4025,6 +4038,7 @@ static mobj_t *K_ThrowKartItem(player_t *player, boolean missile, mobjtype_t map // this is the small graphic effect that plops in you when you throw an item: throwmo = P_SpawnMobj(player->mo->x, player->mo->y, player->mo->z + player->mo->height/2, MT_FIREDITEM); P_SetTarget(&throwmo->target, player->mo); + // Ditto: if (player->mo->eflags & MFE_VERTICALFLIP) { @@ -4068,6 +4082,7 @@ static mobj_t *K_ThrowKartItem(player_t *player, boolean missile, mobjtype_t map // floorz and ceilingz aren't properly set to account for FOFs and Polyobjects on spawn // This should set it for FOFs P_SetOrigin(mo, mo->x, mo->y, mo->z); // however, THIS can fuck up your day. just absolutely ruin you. + if (P_MobjWasRemoved(mo)) return NULL; @@ -4378,8 +4393,10 @@ static void K_DoShrink(player_t *user) { players[i].mo->scalespeed = mapobjectscale/TICRATE; players[i].mo->destscale = (6*mapobjectscale)/8; + if (cv_kartdebugshrink.value && !modeattacking && !players[i].bot) players[i].mo->destscale = (6*players[i].mo->destscale)/8; + S_StartSound(players[i].mo, sfx_kc59); } } @@ -4628,6 +4645,7 @@ void K_DropHnextList(player_t *player) // we need this here too because this is done in afterthink - pointers are cleaned up at the START of each tic... P_SetTarget(&player->mo->hnext, NULL); player->kartstuff[k_bananadrag] = 0; + if (player->kartstuff[k_eggmanheld]) player->kartstuff[k_eggmanheld] = 0; else if (player->kartstuff[k_itemheld] @@ -4711,6 +4729,7 @@ void K_DropRocketSneaker(player_t *player) leftshoe = false; } + P_SetTarget(&player->mo->hnext, NULL); player->kartstuff[k_rocketsneakertimer] = 0; } @@ -4925,6 +4944,7 @@ static void K_MoveHeldObjects(player_t *player) player->kartstuff[k_itemamount] = player->kartstuff[k_itemheld] = 0; player->kartstuff[k_itemtype] = KITEM_NONE; } + return; } @@ -4941,6 +4961,7 @@ static void K_MoveHeldObjects(player_t *player) player->kartstuff[k_itemamount] = player->kartstuff[k_itemheld] = 0; player->kartstuff[k_itemtype] = KITEM_NONE; } + return; } @@ -4956,7 +4977,6 @@ static void K_MoveHeldObjects(player_t *player) while (!P_MobjWasRemoved(cur)) { - const fixed_t radius = FixedHypot(player->mo->radius, player->mo->radius) + FixedHypot(cur->radius, cur->radius); // mobj's distance from its Target, or Radius. fixed_t z; if (!cur->health) @@ -4965,6 +4985,8 @@ static void K_MoveHeldObjects(player_t *player) continue; } + const fixed_t radius = FixedHypot(player->mo->radius, player->mo->radius) + FixedHypot(cur->radius, cur->radius); // mobj's distance from its Target, or Radius. + cur->color = player->skincolor; cur->angle -= ANGLE_90; @@ -5036,7 +5058,6 @@ static void K_MoveHeldObjects(player_t *player) while (!P_MobjWasRemoved(cur)) { - const fixed_t radius = FixedHypot(targ->radius, targ->radius) + FixedHypot(cur->radius, cur->radius); angle_t ang; fixed_t targx, targy, targz; fixed_t speed, dist; @@ -5049,6 +5070,8 @@ static void K_MoveHeldObjects(player_t *player) continue; } + const fixed_t radius = FixedHypot(targ->radius, targ->radius) + FixedHypot(cur->radius, cur->radius); + if (cur->extravalue1 < radius) cur->extravalue1 += FixedMul(P_AproxDistance(cur->extravalue1, radius), FRACUNIT/12); if (cur->extravalue1 > radius) @@ -5127,11 +5150,10 @@ static void K_MoveHeldObjects(player_t *player) while (!P_MobjWasRemoved(cur)) { - const fixed_t radius = FixedHypot(player->mo->radius, player->mo->radius) + FixedHypot(cur->radius, cur->radius); - boolean vibrate = ((leveltime & 1) && !cur->tracer); angle_t angoffset; fixed_t targx, targy, targz; - + const boolean vibrate = ((leveltime & 1) && !cur->tracer); + cur->flags &= ~MF_NOCLIPTHING; if (player->kartstuff[k_rocketsneakertimer] <= TICRATE && (leveltime & 1)) @@ -5151,6 +5173,8 @@ static void K_MoveHeldObjects(player_t *player) continue; } + const fixed_t radius = FixedHypot(player->mo->radius, player->mo->radius) + FixedHypot(cur->radius, cur->radius); + if (cur->extravalue1 < radius) cur->extravalue1 += FixedMul(P_AproxDistance(cur->extravalue1, radius), FRACUNIT/12); if (cur->extravalue1 > radius) @@ -5187,7 +5211,6 @@ static void K_MoveHeldObjects(player_t *player) targz = (player->mo->z + (player->mo->height/2)) + sine; if (player->mo->eflags & MFE_VERTICALFLIP) targz += (player->mo->height/2 - 32*player->mo->scale)*6; - } if (!P_MobjWasRemoved(cur->tracer)) @@ -5264,9 +5287,11 @@ player_t *K_FindJawzTarget(mobj_t *actor, player_t *source) // Don't go for people who are behind you if (thisang > ANGLE_67h) continue; + // Don't pay attention to people who aren't above your position if (player->kartstuff[k_position] >= source->kartstuff[k_position]) continue; + if ((best == -1) || (player->kartstuff[k_position] > best)) { wtarg = player; @@ -5588,6 +5613,8 @@ FUNCINLINE static ATTRINLINE void K_SpawnNormalSpeedLines(player_t *player, bool */ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) { + const boolean onground = P_IsObjectOnGround(player->mo); + K_UpdateOffroad(player); K_UpdateEngineSounds(player, cmd); // Thanks, VAda! @@ -5704,7 +5731,7 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) if (player->kartstuff[k_spinouttimer]) { - if ((P_IsObjectOnGround(player->mo) || ((player->kartstuff[k_spinouttype]+1)/2 == 1)) // spinouttype 1 and 2 - explosion and spb + if ((onground || ((player->kartstuff[k_spinouttype]+1)/2 == 1)) // spinouttype 1 and 2 - explosion and spb && (player->kartstuff[k_sneakertimer] == 0)) { player->kartstuff[k_spinouttimer]--; @@ -5803,7 +5830,7 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) if (G_BattleGametype() && player->kartstuff[k_bumper] > 0) player->kartstuff[k_wanted]++; - if (P_IsObjectOnGround(player->mo)) + if (onground) player->kartstuff[k_waterskip] = 0; if (player->kartstuff[k_instashield]) @@ -5847,7 +5874,7 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) if (player->kartstuff[k_comebacktimer]) player->kartstuff[k_comebackmode] = 0; - if (P_IsObjectOnGround(player->mo) && player->kartstuff[k_pogospring]) + if (onground && player->kartstuff[k_pogospring]) { if (P_MobjFlip(player->mo)*player->mo->momz <= 0) player->kartstuff[k_pogospring] = 0; @@ -7629,6 +7656,7 @@ void K_CheckSpectateStatus(void) { UINT8 oldrespawnlist[MAXPLAYERS]; memcpy(oldrespawnlist, respawnlist, numjoiners); + for (i = 0; i < numjoiners; i++) { UINT8 pos = 0; diff --git a/src/p_enemy.c b/src/p_enemy.c index 15410747a..1502f5ff3 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -328,7 +328,7 @@ void P_NewChaseDir(mobj_t *actor) else d[1] = DI_NODIR; - if (twodlevel || actor->flags2 & MF2_TWOD) + if (UNLIKELY(twodlevel || actor->flags2 & MF2_TWOD)) d[2] = DI_NODIR; if (deltay < -FixedMul(10*FRACUNIT, actor->scale)) d[2] = DI_SOUTH; @@ -872,7 +872,7 @@ void A_PointyThink(void *thing) TVector v; TVector *res; angle_t fa; - fixed_t radius = FixedMul(actor->info->radius*actor->info->reactiontime, actor->scale); + fixed_t radius; boolean firsttime = true; INT32 sign; @@ -930,6 +930,8 @@ void A_PointyThink(void *thing) if (!actor->tracer) // For some reason we do not have spike balls... return; + radius = FixedMul(actor->info->radius*actor->info->reactiontime, actor->scale); + // Position spike balls relative to the value of 'lastlook'. ball = actor->tracer; @@ -2759,9 +2761,11 @@ void A_Invincibility(void *thing) if (P_IsLocalPlayer(player) && !player->powers[pw_super]) { S_StopMusic(); - if (mariomode) + + if (UNLIKELY(mariomode)) G_GhostAddColor((INT32) (player - players), GHC_INVINCIBLE); - S_ChangeMusicInternal((mariomode) ? "minvnc" : "invinc", false); + + S_ChangeMusicInternal((UNLIKELY(mariomode)) ? "minvnc" : "invinc", false); } } diff --git a/src/p_floor.c b/src/p_floor.c index ef42b02a3..3c4128777 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -1107,14 +1107,13 @@ void T_SpikeSector(levelspecthink_t *spikes) if (affectsec == spikes->sector) // Applied to an actual sector { - fixed_t affectfloor = P_GetSpecialBottomZ(thing, affectsec, affectsec); - fixed_t affectceil = P_GetSpecialTopZ(thing, affectsec, affectsec); - if (affectsec->flags & SF_FLIPSPECIAL_FLOOR) { if (!(thing->eflags & MFE_VERTICALFLIP) && thing->momz > 0) continue; + fixed_t affectfloor = P_GetSpecialBottomZ(thing, affectsec, affectsec); + if (thing->z == affectfloor) dothepain = true; } @@ -1124,19 +1123,21 @@ void T_SpikeSector(levelspecthink_t *spikes) if ((thing->eflags & MFE_VERTICALFLIP) && thing->momz < 0) continue; + fixed_t affectceil = P_GetSpecialTopZ(thing, affectsec, affectsec); + if (thing->z + thing->height == affectceil) dothepain = true; } } else { - fixed_t affectfloor = P_GetSpecialBottomZ(thing, affectsec, spikes->sector); - fixed_t affectceil = P_GetSpecialTopZ(thing, affectsec, spikes->sector); if (affectsec->flags & SF_FLIPSPECIAL_FLOOR) { if (!(thing->eflags & MFE_VERTICALFLIP) && thing->momz > 0) continue; + fixed_t affectceil = P_GetSpecialTopZ(thing, affectsec, spikes->sector); + if (thing->z == affectceil) dothepain = true; } @@ -1146,6 +1147,8 @@ void T_SpikeSector(levelspecthink_t *spikes) if ((thing->eflags & MFE_VERTICALFLIP) && thing->momz < 0) continue; + fixed_t affectfloor = P_GetSpecialBottomZ(thing, affectsec, spikes->sector); + if (thing->z + thing->height == affectfloor) dothepain = true; } @@ -1652,6 +1655,7 @@ wegotit: static mobj_t *SearchMarioNode(msecnode_t *node) { mobj_t *thing = NULL; + for (; node; node = node->m_thinglist_next) { // Things which should NEVER be ejected from a MarioBlock, by type. @@ -2079,11 +2083,12 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) continue; topheight = P_GetSpecialTopZ(players[j].mo, sec, targetsec); - bottomheight = P_GetSpecialBottomZ(players[j].mo, sec, targetsec); if (players[j].mo->z > topheight) continue; + bottomheight = P_GetSpecialBottomZ(players[j].mo, sec, targetsec); + if (players[j].mo->z + players[j].mo->height < bottomheight) continue; diff --git a/src/p_inter.c b/src/p_inter.c index 7564a60cc..30cf829a1 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -1624,7 +1624,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source) // Drop stuff. // This determines the kind of object spawned // during the death frame of a thing. - if (!mariomode // Don't show birds, etc. in Mario Mode Tails 12-23-2001 + if (LIKELY(!mariomode) // Don't show birds, etc. in Mario Mode Tails 12-23-2001 && target->flags & MF_ENEMY) { if (cv_soniccd.value) diff --git a/src/p_local.h b/src/p_local.h index 3ee18eab3..ae925d8b4 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -99,7 +99,6 @@ typedef struct camera_s // Hold up/down to pan the camera vertically SINT8 dpad_y_held; - // Camera demobjerization // Info for drawing: position. fixed_t x, y, z; diff --git a/src/p_slopes.c b/src/p_slopes.c index ac3a56c17..6334b2e45 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -664,8 +664,10 @@ static pslope_t *P_NewVertexSlope(INT16 tag1, INT16 tag2, INT16 tag3, UINT8 flag for (i = 0; i < 3; i++) { mt = ret->vertices[i]; + if (!mt) // If a vertex wasn't found, it's game over. There's nothing you can do to recover (except maybe try and kill the slope instead - TODO?) I_Error("P_NewVertexSlope: Slope vertex %s (for linedef tag %d) not found!", sizeu1(i), tag1); + if (mt->extrainfo) mt->z = mt->options; else diff --git a/src/p_spec.c b/src/p_spec.c index e37e26d54..64f5ef6ed 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1234,7 +1234,6 @@ static void P_AddExecutorDelay(line_t *line, mobj_t *mobj, sector_t *sector) boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller) { sector_t *ctlsector; - fixed_t dist = P_AproxDistance(triggerline->dx, triggerline->dy)>>FRACBITS; size_t i, linecnt, sectori; INT16 specialtype = triggerline->special; fromlapexec = false; @@ -1272,6 +1271,8 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller rings = actor->health-1; } + const fixed_t dist = P_AproxDistance(triggerline->dx, triggerline->dy)>>FRACBITS; + if (triggerline->flags & ML_NOCLIMB) { if (rings > dist) @@ -1293,7 +1294,6 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller msecnode_t *node; mobj_t *mo; INT32 numpush = 0; - INT32 numneeded = dist; if (!caller) return false; // we need a calling sector to find pushables in, silly! @@ -1308,6 +1308,8 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller node = node->m_thinglist_next; } + const fixed_t numneeded = P_AproxDistance(triggerline->dx, triggerline->dy)>>FRACBITS; + if (triggerline->flags & ML_NOCLIMB) // Need at least or more { if (numpush < numneeded) @@ -3385,14 +3387,16 @@ DoneSection2: { const fixed_t hscale = mapobjectscale + (mapobjectscale - player->mo->scale); const fixed_t minspeed = 24*hscale; - angle_t pushangle = FixedHypot(player->mo->momx, player->mo->momy) ? R_PointToAngle2(0, 0, player->mo->momx, player->mo->momy) : player->mo->angle; - // if we have no speed for SOME REASON, use the player's angle, otherwise we'd be forcefully thrusted to what I can only assume is angle 0 if (player->mo->eflags & MFE_SPRUNG) break; if (player->speed < minspeed) // Push forward to prevent getting stuck + { + // if we have no speed for SOME REASON, use the player's angle, otherwise we'd be forcefully thrusted to what I can only assume is angle 0 + const angle_t pushangle = FixedHypot(player->mo->momx, player->mo->momy) ? R_PointToAngle2(0, 0, player->mo->momx, player->mo->momy) : player->mo->angle; P_InstaThrust(player->mo, pushangle, minspeed); + } player->kartstuff[k_pogospring] = 1; K_DoPogoSpring(player->mo, 0, 1); @@ -3408,16 +3412,22 @@ DoneSection2: const fixed_t hscale = mapobjectscale + (mapobjectscale - player->mo->scale); const fixed_t minspeed = 24*hscale; const fixed_t maxspeed = 28*hscale; - angle_t pushangle = FixedHypot(player->mo->momx, player->mo->momy) ? R_PointToAngle2(0, 0, player->mo->momx, player->mo->momy) : player->mo->angle; - // if we have no speed for SOME REASON, use the player's angle, otherwise we'd be forcefully thrusted to what I can only assume is angle 0 if (player->mo->eflags & MFE_SPRUNG) break; if (player->speed > maxspeed) // Prevent overshooting jumps + { + // if we have no speed for SOME REASON, use the player's angle, otherwise we'd be forcefully thrusted to what I can only assume is angle 0 + const angle_t pushangle = FixedHypot(player->mo->momx, player->mo->momy) ? R_PointToAngle2(0, 0, player->mo->momx, player->mo->momy) : player->mo->angle; P_InstaThrust(player->mo, pushangle, maxspeed); + } else if (player->speed < minspeed) // Push forward to prevent getting stuck + { + // if we have no speed for SOME REASON, use the player's angle, otherwise we'd be forcefully thrusted to what I can only assume is angle 0 + const angle_t pushangle = FixedHypot(player->mo->momx, player->mo->momy) ? R_PointToAngle2(0, 0, player->mo->momx, player->mo->momy) : player->mo->angle; P_InstaThrust(player->mo, pushangle, minspeed); + } player->kartstuff[k_pogospring] = 2; K_DoPogoSpring(player->mo, 0, 1); @@ -3645,7 +3655,7 @@ DoneSection2: thinker_t *th; mobj_t *waypoint = NULL; mobj_t *mo2; - angle_t an; + if (player->mo->tracer && player->mo->tracer->type == MT_TUBEWAYPOINT) break; @@ -3693,10 +3703,13 @@ DoneSection2: CONS_Debug(DBG_GAMELOGIC, "Waypoint %d found in sequence %d - speed = %d\n", waypoint->health, sequence, speed); } - an = R_PointToAngle2(player->mo->x, player->mo->y, waypoint->x, waypoint->y) - player->mo->angle; + if (!(lines[lineindex].flags & ML_EFFECT4)) + { + const angle_t an = R_PointToAngle2(player->mo->x, player->mo->y, waypoint->x, waypoint->y) - player->mo->angle; - if (an > ANGLE_90 && an < ANGLE_270 && !(lines[lineindex].flags & ML_EFFECT4)) - break; // behind back + if (an > ANGLE_90 && an < ANGLE_270) + break; // behind back + } P_SetTarget(&player->mo->tracer, waypoint); player->speed = speed; @@ -3718,7 +3731,6 @@ DoneSection2: thinker_t *th; mobj_t *waypoint = NULL; mobj_t *mo2; - angle_t an; if (player->mo->tracer && player->mo->tracer->type == MT_TUBEWAYPOINT) break; @@ -3766,10 +3778,13 @@ DoneSection2: CONS_Debug(DBG_GAMELOGIC, "Waypoint %d found in sequence %d - speed = %d\n", waypoint->health, sequence, speed); } - an = R_PointToAngle2(player->mo->x, player->mo->y, waypoint->x, waypoint->y) - player->mo->angle; + if (!(lines[lineindex].flags & ML_EFFECT4)) + { + const angle_t an = R_PointToAngle2(player->mo->x, player->mo->y, waypoint->x, waypoint->y) - player->mo->angle; - if (an > ANGLE_90 && an < ANGLE_270 && !(lines[lineindex].flags & ML_EFFECT4)) - break; // behind back + if (an > ANGLE_90 && an < ANGLE_270) + break; // behind back + } P_SetTarget(&player->mo->tracer, waypoint); player->speed = speed; @@ -3783,10 +3798,13 @@ DoneSection2: case 10: // Finish Line // SRB2kart - 150117 - if (G_RaceGametype() && (player->starpostnum >= (numstarposts - (numstarposts/2)) || player->exiting)) + if (!G_RaceGametype()) + break; + + if (player->starpostnum >= (numstarposts - (numstarposts/2)) || player->exiting) player->kartstuff[k_starpostwp] = player->kartstuff[k_waypoint] = 0; // - if (G_RaceGametype() && !player->exiting) + if (!player->exiting) { if (player->starpostnum >= (numstarposts - (numstarposts/2))) // srb2kart: must have touched *enough* starposts (was originally "(player->starpostnum == numstarposts)") { @@ -5164,11 +5182,18 @@ void T_LaserFlash(laserthink_t *flash) if (thing->health <= 0) continue; + // thing is neither shootable nor an egg guard shield + if (!(thing->flags & MF_SHOOTABLE) && (thing->type != MT_EGGSHIELD)) + continue; + top = P_GetSpecialTopZ(thing, sourcesec, sector); + + if (thing->z >= top) + continue; + bottom = P_GetSpecialBottomZ(thing, sourcesec, sector); - if (thing->z >= top - || thing->z + thing->height <= bottom) + if (thing->z + thing->height <= bottom) continue; if (thing->flags & MF_SHOOTABLE) @@ -5262,7 +5287,7 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate) continue; // Process Section 1 - switch(GETSECSPECIAL(sector->special, 1)) + switch (GETSECSPECIAL(sector->special, 1)) { case 5: // Spikes P_AddSpikeThinker(sector, (INT32)(sector-sectors)); @@ -5274,7 +5299,7 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate) } // Process Section 2 - switch(GETSECSPECIAL(sector->special, 2)) + switch (GETSECSPECIAL(sector->special, 2)) { case 10: // Time for special stage sstimer = (sector->floorheight>>FRACBITS) * TICRATE + 6; // Time to finish @@ -5287,7 +5312,7 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate) } // Process Section 4 - switch(GETSECSPECIAL(sector->special, 4)) + switch (GETSECSPECIAL(sector->special, 4)) { case 10: // Circuit finish line if (G_RaceGametype()) @@ -5323,11 +5348,13 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate) // Allocate each list, and then zero the count so we can use it to track // the end of the list as we add the thinkers for (i = 0; i < numsectors; i++) - if(secthinkers[i].count > 0) + { + if (secthinkers[i].count > 0) { secthinkers[i].thinkers = Z_Malloc(secthinkers[i].count * sizeof(thinker_t *), PU_STATIC, NULL); secthinkers[i].count = 0; } + } // Finally, populate the lists. for (th = thinkercap.next; th != &thinkercap; th = th->next) @@ -6427,15 +6454,19 @@ void T_Scroll(scroll_t *s) if (thing->flags2 & MF2_PUSHED) // Already pushed this tic by an exclusive pusher. continue; - height = P_GetSpecialBottomZ(thing, sec, psec); - if (!(thing->flags & MF_NOCLIP)) // Thing must be clipped - if (!(thing->flags & MF_NOGRAVITY || thing->z+thing->height != height)) // Thing must a) be non-floating and have z+height == height { - // Move objects only if on floor - // non-floating, and clipped. - P_DoScrollMove(thing, dx, dy, s->exclusive); + height = P_GetSpecialBottomZ(thing, sec, psec); + + if (!(thing->flags & MF_NOGRAVITY || thing->z+thing->height != height)) // Thing must a) be non-floating and have z+height == height + { + // Move objects only if on floor + // non-floating, and clipped. + P_DoScrollMove(thing, dx, dy, s->exclusive); + } + } + } // end of for loop through touching_thinglist } // end of loop through sectors } @@ -6449,14 +6480,16 @@ void T_Scroll(scroll_t *s) if (thing->flags2 & MF2_PUSHED) continue; - height = P_GetSpecialBottomZ(thing, sec, sec); - - if (!(thing->flags & MF_NOCLIP) && - (!(thing->flags & MF_NOGRAVITY || thing->z > height))) + if (!(thing->flags & MF_NOCLIP)) // Thing must be clipped { - // Move objects only if on floor or underwater, - // non-floating, and clipped. - P_DoScrollMove(thing, dx, dy, s->exclusive); + height = P_GetSpecialBottomZ(thing, sec, sec); + + if (!(thing->flags & MF_NOGRAVITY || thing->z > height)) + { + // Move objects only if on floor or underwater, + // non-floating, and clipped. + P_DoScrollMove(thing, dx, dy, s->exclusive); + } } } } @@ -6502,14 +6535,16 @@ void T_Scroll(scroll_t *s) if (thing->flags2 & MF2_PUSHED) continue; - height = P_GetSpecialTopZ(thing, sec, psec); - if (!(thing->flags & MF_NOCLIP)) // Thing must be clipped - if (!(thing->flags & MF_NOGRAVITY || thing->z != height))// Thing must a) be non-floating and have z == height { - // Move objects only if on floor or underwater, - // non-floating, and clipped. - P_DoScrollMove(thing, dx, dy, s->exclusive); + height = P_GetSpecialTopZ(thing, sec, psec); + + if (!(thing->flags & MF_NOGRAVITY || thing->z != height))// Thing must a) be non-floating and have z == height + { + // Move objects only if on floor or underwater, + // non-floating, and clipped. + P_DoScrollMove(thing, dx, dy, s->exclusive); + } } } // end of for loop through touching_thinglist } // end of loop through sectors @@ -6524,14 +6559,16 @@ void T_Scroll(scroll_t *s) if (thing->flags2 & MF2_PUSHED) continue; - height = P_GetSpecialTopZ(thing, sec, sec); - - if (!(thing->flags & MF_NOCLIP) && - (!(thing->flags & MF_NOGRAVITY || thing->z+thing->height < height))) + if (!(thing->flags & MF_NOCLIP)) // Thing must be clipped { - // Move objects only if on floor or underwater, - // non-floating, and clipped. - P_DoScrollMove(thing, dx, dy, s->exclusive); + height = P_GetSpecialTopZ(thing, sec, sec); + + if (!(thing->flags & MF_NOGRAVITY || thing->z+thing->height < height)) + { + // Move objects only if on floor or underwater, + // non-floating, and clipped. + P_DoScrollMove(thing, dx, dy, s->exclusive); + } } } } @@ -6994,6 +7031,7 @@ static void Add_Pusher(pushertype_e type, fixed_t x_mag, fixed_t y_mag, mobj_t * p->magnitude = P_AproxDistance(p->x_mag,p->y_mag)<<(FRACBITS-PUSH_FACTOR); else p->magnitude = P_AproxDistance(p->x_mag,p->y_mag); + if (source) // point source exist? { // where force goes to zero @@ -7044,15 +7082,14 @@ static inline boolean PIT_PushThing(mobj_t *thing) // don't fade wrt Z if health & 2 (mapthing has multi flag) if (tmpusher->source->health & 2) - dist = P_AproxDistance(thing->x - sx,thing->y - sy); + dist = P_AproxDistance(thing->x - sx, thing->y - sy); else { // Make sure the Z is in range if (thing->z < sz - tmpusher->radius || thing->z > sz + tmpusher->radius) return false; - dist = P_AproxDistance(P_AproxDistance(thing->x - sx, thing->y - sy), - thing->z - sz); + dist = P_AproxDistance(P_AproxDistance(thing->x - sx, thing->y - sy), thing->z - sz); } speed = (tmpusher->magnitude - ((dist>>FRACBITS)>>1))<<(FRACBITS - PUSH_FACTOR - 1); @@ -7215,7 +7252,6 @@ void T_Pusher(pusher_t *p) if (p->type == p_push) { - // Seek out all pushable things within the force radius of this // point pusher. Crosses sectors, so use blockmap. @@ -7462,16 +7498,17 @@ static void P_SpawnPushers(void) mobj_t *thing; for (i = 0; i < numlines; i++, l++) + { switch (l->special) { case 541: // wind for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) Add_Pusher(p_wind, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); - break; + break; case 544: // current for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) Add_Pusher(p_current, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); - break; + break; case 547: // push/pull for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) { @@ -7483,20 +7520,21 @@ static void P_SpawnPushers(void) case 545: // current up for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) Add_Pusher(p_upcurrent, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); - break; + break; case 546: // current down for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) Add_Pusher(p_downcurrent, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); - break; + break; case 542: // wind up for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) Add_Pusher(p_upwind, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); - break; + break; case 543: // wind down for (s = -1; (s = P_FindSectorFromLineTag(l, s)) >= 0 ;) Add_Pusher(p_downwind, l->dx, l->dy, NULL, s, -1, l->flags & ML_NOCLIMB, l->flags & ML_EFFECT4); - break; + break; } + } } void P_StartQuake(tic_t time, fixed_t intensity, fixed_t radius) diff --git a/src/p_user.c b/src/p_user.c index 9df7d2735..f435b60da 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1122,22 +1122,26 @@ void P_SpawnShieldOrb(player_t *player) P_SetTarget(&ov->target, shieldobj); P_SetMobjState(ov, shieldobj->info->seestate); } + if (shieldobj->info->meleestate) { ov = P_SpawnMobj(shieldobj->x, shieldobj->y, shieldobj->z, MT_OVERLAY); P_SetTarget(&ov->target, shieldobj); P_SetMobjState(ov, shieldobj->info->meleestate); } + if (shieldobj->info->missilestate) { ov = P_SpawnMobj(shieldobj->x, shieldobj->y, shieldobj->z, MT_OVERLAY); P_SetTarget(&ov->target, shieldobj); P_SetMobjState(ov, shieldobj->info->missilestate); } + if (player->powers[pw_shield] & SH_FORCE) { //Copy and pasted from P_ShieldLook in p_mobj.c shieldobj->movecount = (player->powers[pw_shield] & 0xFF); + if (shieldobj->movecount < 1) { if (shieldobj->info->painstate) @@ -1569,10 +1573,12 @@ static void P_CheckBouncySectors(player_t *player) newmom = -8*FRACUNIT; } - if (newmom > P_GetPlayerHeight(player)/2) - newmom = P_GetPlayerHeight(player)/2; - else if (newmom < -P_GetPlayerHeight(player)/2) - newmom = -P_GetPlayerHeight(player)/2; + const fixed_t halfpheight = P_GetPlayerHeight(player)/2; + + if (newmom > halfpheight) + newmom = halfpheight; + else if (newmom < -halfpheight) + newmom = -halfpheight; momentum.z = newmom*2; @@ -1835,6 +1841,9 @@ void P_Telekinesis(player_t *player, fixed_t thrust, fixed_t range) if (!((mo2->flags & MF_SHOOTABLE && mo2->flags & MF_ENEMY) || mo2->type == MT_EGGGUARD || mo2->player)) continue; + if (mo2->health <= 0) + continue; + dist = P_AproxDistance(P_AproxDistance(player->mo->x-mo2->x, player->mo->y-mo2->y), player->mo->z-mo2->z); if (range < dist) @@ -1843,15 +1852,12 @@ void P_Telekinesis(player_t *player, fixed_t thrust, fixed_t range) if (!P_CheckSight(player->mo, mo2)) continue; // if your psychic powers can't "see" it don't bother - if (mo2->health > 0) - { - an = R_PointToAngle2(player->mo->x, player->mo->y, mo2->x, mo2->y); + an = R_PointToAngle2(player->mo->x, player->mo->y, mo2->x, mo2->y); - P_Thrust(mo2, an, thrust); + P_Thrust(mo2, an, thrust); - if (mo2->type == MT_GOLDBUZZ || mo2->type == MT_REDBUZZ) - mo2->tics += 8; - } + if (mo2->type == MT_GOLDBUZZ || mo2->type == MT_REDBUZZ) + mo2->tics += 8; } //P_SpawnThokMobj(player); @@ -2736,16 +2742,16 @@ boolean P_LookForEnemies(player_t *player) || ((mo->z+mo->height < player->mo->z+player->mo->height-FixedMul(MAXSTEPMOVE, mapobjectscale)) && (player->mo->eflags & MFE_VERTICALFLIP))) // Reverse gravity check - Flame. continue; // Don't home upwards! - if (P_AproxDistance(P_AproxDistance(player->mo->x-mo->x, player->mo->y-mo->y), - player->mo->z-mo->z) > FixedMul(RING_DIST, player->mo->scale)) + const fixed_t modist = P_AproxDistance(P_AproxDistance(player->mo->x-mo->x, player->mo->y-mo->y), player->mo->z-mo->z); + + if (modist > FixedMul(RING_DIST, player->mo->scale)) continue; // out of range if (UNLIKELY((twodlevel || player->mo->flags2 & MF2_TWOD) && abs(player->mo->y-mo->y) > player->mo->radius)) continue; // not in your 2d plane - if (closestmo && P_AproxDistance(P_AproxDistance(player->mo->x-mo->x, player->mo->y-mo->y), - player->mo->z-mo->z) > P_AproxDistance(P_AproxDistance(player->mo->x-closestmo->x, + if (closestmo && modist > P_AproxDistance(P_AproxDistance(player->mo->x-closestmo->x, player->mo->y-closestmo->y), player->mo->z-closestmo->z)) continue; @@ -4580,6 +4586,7 @@ void P_PlayerThink(player_t *player) { short int i; mo->flags |= MF_NOCLIPHEIGHT; + for (i = 0; i < 32; i++) { // Debug drawing