From f9426716075e5a8961053f1aded5ccb5468fd3f5 Mon Sep 17 00:00:00 2001 From: toaster Date: Thu, 28 Jun 2018 01:20:19 +0100 Subject: [PATCH] First substantial commit! * PRETTY SURE I fixed that bastardacious issue with multiple shield items disappearing at once. Done via introducing lastlook to store the updated count. * Fix an issue with incorrect scale setting for shield items. * Clean up a bunch of weird shit with regards to setting of hnext/hprev chains. (Why does the player go on the opposite end to the direction you enter the chain from...) * Repair hnext chain on mobjremoval as well. May or may not remove the need for overlay/shadow thinkers; too tired/excited to dig into that atm. --- src/k_kart.c | 71 ++++++++++++++++++---------------------------------- src/p_mobj.c | 20 +++++++++++++-- 2 files changed, 42 insertions(+), 49 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 72447698..aa18c863 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -2085,9 +2085,9 @@ void K_DriftDustHandling(mobj_t *spawner) static mobj_t *K_FindLastTrailMobj(player_t *player) { - mobj_t *trail = player->mo->hnext; + mobj_t *trail; - if (!player || !trail) + if (!player || !(trail = player->mo) || !player->mo->hnext) return NULL; while (trail->hnext && !P_MobjWasRemoved(trail->hnext)) @@ -2493,20 +2493,19 @@ void K_RepairOrbitChain(mobj_t *orbit) // Then recount to make sure item amount is correct if (orbit->target && orbit->target->player) { - mobj_t *cur = NULL; - mobj_t *prev = NULL; INT32 num = 0; - if (orbit->target->hnext) - cur = orbit->target->hnext; + mobj_t *cur = orbit->target->hnext; + mobj_t *prev = NULL; - while (cur && !P_MobjWasRemoved(cur) && cur != orbit->target->player->mo) + while (cur && !P_MobjWasRemoved(cur)) { - num++; prev = cur; cur = cur->hnext; - if (num > orbit->target->player->kartstuff[k_itemamount]) + if (++num > orbit->target->player->kartstuff[k_itemamount]) P_RemoveMobj(prev); + else + prev->movedir = num; } if (orbit->target->player->kartstuff[k_itemamount] != num) @@ -2529,7 +2528,7 @@ static void K_MoveHeldObjects(player_t *player) { mobj_t *cur = player->mo->hnext; - while (cur && !P_MobjWasRemoved(cur) && cur != player->mo) + while (cur && !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; @@ -2544,7 +2543,7 @@ static void K_MoveHeldObjects(player_t *player) cur->eflags &= ~MFE_VERTICALFLIP; // Shrink your items if the player shrunk too. - cur->scale = player->mo->scale; + P_SetScale(cur, (cur->destscale = player->mo->scale)); if (P_MobjFlip(cur) > 0) z = player->mo->z; @@ -2586,7 +2585,7 @@ static void K_MoveHeldObjects(player_t *player) mobj_t *cur = player->mo->hnext; mobj_t *targ = player->mo; - while (cur && !P_MobjWasRemoved(cur) && cur != player->mo) + while (cur && !P_MobjWasRemoved(cur)) { const fixed_t spacing = FixedMul(3*cur->info->radius/2, player->mo->scale); angle_t ang; @@ -3285,7 +3284,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground) fixed_t newy; INT32 moloop; mobj_t *mo; - mobj_t *prev = NULL; + mobj_t *prev = player->mo; //K_PlayTauntSound(player->mo); player->kartstuff[k_itemheld] = 1; @@ -3301,14 +3300,8 @@ void K_MoveKartPlayer(player_t *player, boolean onground) mo->movecount = player->kartstuff[k_itemamount]; mo->lastlook = moloop+1; P_SetTarget(&mo->target, player->mo); - if (moloop > 0) - { - P_SetTarget(&mo->hprev, prev); - if (prev != NULL) - P_SetTarget(&prev->hnext, mo); - } - else - P_SetTarget(&player->mo->hnext, mo); + P_SetTarget(&mo->hprev, prev); + P_SetTarget(&prev->hnext, mo); prev = mo; } } @@ -3353,8 +3346,8 @@ void K_MoveKartPlayer(player_t *player, boolean onground) fixed_t newx; fixed_t newy; INT32 moloop; - mobj_t *mo; - mobj_t *prev = NULL; + mobj_t *mo = NULL; + mobj_t *prev = player->mo; //K_PlayTauntSound(player->mo); player->kartstuff[k_itemheld] = 1; @@ -3370,18 +3363,10 @@ void K_MoveKartPlayer(player_t *player, boolean onground) mo->angle = newangle; mo->threshold = 10; mo->movecount = player->kartstuff[k_itemamount]; - mo->lastlook = moloop+1; + mo->movedir = mo->lastlook = moloop+1; P_SetTarget(&mo->target, player->mo); - if (moloop > 0) - { - P_SetTarget(&mo->hprev, prev); - if (prev != NULL) - P_SetTarget(&prev->hnext, mo); - } - else - P_SetTarget(&player->mo->hnext, mo); - if (moloop == player->kartstuff[k_itemamount]-1) // Complete loop for orbit items - P_SetTarget(&mo->hnext, player->mo); + P_SetTarget(&mo->hprev, prev); + P_SetTarget(&prev->hnext, mo); prev = mo; } } @@ -3403,8 +3388,8 @@ void K_MoveKartPlayer(player_t *player, boolean onground) fixed_t newx; fixed_t newy; INT32 moloop; - mobj_t *mo; - mobj_t *prev = NULL; + mobj_t *mo = NULL; + mobj_t *prev = player->mo; //K_PlayTauntSound(player->mo); player->kartstuff[k_itemheld] = 1; @@ -3420,18 +3405,10 @@ void K_MoveKartPlayer(player_t *player, boolean onground) mo->angle = newangle; mo->threshold = 10; mo->movecount = player->kartstuff[k_itemamount]; - mo->lastlook = moloop+1; + mo->movedir = mo->lastlook = moloop+1; P_SetTarget(&mo->target, player->mo); - if (moloop > 0) - { - P_SetTarget(&mo->hprev, prev); - if (prev != NULL) - P_SetTarget(&prev->hnext, mo); - } - else - P_SetTarget(&player->mo->hnext, mo); - if (moloop == player->kartstuff[k_itemamount]-1) // Complete loop for orbit items - P_SetTarget(&mo->hnext, player->mo); + P_SetTarget(&mo->hprev, prev); + P_SetTarget(&prev->hnext, mo); prev = mo; } } diff --git a/src/p_mobj.c b/src/p_mobj.c index 44683b64..a89961a0 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6700,7 +6700,7 @@ void P_MobjThinker(mobj_t *mobj) // Was this so hard? if ((mobj->type == MT_GREENSHIELD && mobj->target->player->kartstuff[k_itemtype] != KITEM_ORBINAUT) || (mobj->type == MT_JAWZ_SHIELD && mobj->target->player->kartstuff[k_itemtype] != KITEM_JAWZ) - || (mobj->lastlook > 0 && mobj->target->player->kartstuff[k_itemamount] < mobj->lastlook) + || (mobj->movedir > 0 && mobj->target->player->kartstuff[k_itemamount] < mobj->movedir) || (!mobj->target->player->kartstuff[k_itemheld])) { P_RemoveMobj(mobj); @@ -9276,7 +9276,23 @@ void P_RemoveMobj(mobj_t *mobj) // // Remove any references to other mobjs. P_SetTarget(&mobj->target, P_SetTarget(&mobj->tracer, NULL)); - P_SetTarget(&mobj->hprev, P_SetTarget(&mobj->hnext, NULL)); + + // repair hnext chain + { + mobj_t *cachenext = 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); + } + } // free block // DBG: set everything in mobj_t to 0xFF instead of leaving it. debug memory error.