From 6d59551afdac6bf20c5add5f6a86c169c9db431f Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Sun, 1 Apr 2018 20:54:19 +0100 Subject: [PATCH 1/8] Mace optimisation! * Handle all chain objects as a hnext/hprev chain. * When removing mobjs with hnext/hprev, "repair the chain" (make the h links meet). * Fix hidden slings, which I accidentially broke when I revamped maces the first time. * Kill MF2_MACEROTATE. Not needed for anything anymore. * P_MaceRotate now available to Lua to make up for it. * Related: Made modifying hnext/hprev using Lua safer, so it keeps the reference counts in play. --- src/dehacked.c | 1 - src/info.c | 14 +-- src/lua_baselib.c | 14 +++ src/lua_mobjlib.c | 16 ++- src/p_enemy.c | 11 +- src/p_local.h | 2 + src/p_mobj.c | 260 +++++++++++++++++++++++++++++----------------- src/p_mobj.h | 2 - 8 files changed, 209 insertions(+), 111 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index c172549e1..ced71f079 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -6515,7 +6515,6 @@ static const char *const MOBJFLAG2_LIST[] = { "AMBUSH", // Alternate behaviour typically set by MTF_AMBUSH "LINKDRAW", // Draw vissprite of mobj immediately before/after tracer's vissprite (dependent on dispoffset and position) "SHIELD", // Thinker calls P_AddShield/P_ShieldLook (must be partnered with MF_SCENERY to use) - "MACEROTATE", // Thinker calls P_MaceRotate around tracer NULL }; diff --git a/src/info.c b/src/info.c index acb12379a..f11d88af8 100644 --- a/src/info.c +++ b/src/info.c @@ -9011,7 +9011,7 @@ mobjinfo_t mobjinfo[NUMMOBJTYPES] = 10000, // mass 0, // damage sfx_None, // activesound - MF_NOBLOCKMAP|MF_NOSECTOR|MF_NOCLIP|MF_NOGRAVITY|MF_NOCLIPHEIGHT, // flags + MF_NOBLOCKMAP|MF_NOSECTOR|MF_NOCLIP|MF_NOGRAVITY|MF_NOCLIPHEIGHT|MF_SCENERY, // flags S_NULL // raisestate }, @@ -9038,7 +9038,7 @@ mobjinfo_t mobjinfo[NUMMOBJTYPES] = 10000, // mass 0, // damage sfx_None, // activesound - MF_NOBLOCKMAP|MF_NOSECTOR|MF_NOCLIP|MF_NOGRAVITY|MF_NOCLIPHEIGHT, // flags + MF_NOBLOCKMAP|MF_NOSECTOR|MF_NOCLIP|MF_NOGRAVITY|MF_NOCLIPHEIGHT|MF_SCENERY, // flags S_NULL // raisestate }, @@ -9065,7 +9065,7 @@ mobjinfo_t mobjinfo[NUMMOBJTYPES] = 10000, // mass 0, // damage sfx_None, // activesound - MF_NOBLOCKMAP|MF_NOSECTOR|MF_NOCLIP|MF_NOGRAVITY|MF_NOCLIPHEIGHT, // flags + MF_NOBLOCKMAP|MF_NOSECTOR|MF_NOCLIP|MF_NOGRAVITY|MF_NOCLIPHEIGHT|MF_SCENERY, // flags S_NULL // raisestate }, @@ -9092,7 +9092,7 @@ mobjinfo_t mobjinfo[NUMMOBJTYPES] = 10000, // mass 0, // damage sfx_None, // activesound - MF_NOBLOCKMAP|MF_NOSECTOR|MF_NOCLIP|MF_NOGRAVITY|MF_NOCLIPHEIGHT, // flags + MF_NOBLOCKMAP|MF_NOSECTOR|MF_NOCLIP|MF_NOGRAVITY|MF_NOCLIPHEIGHT|MF_SCENERY, // flags S_NULL // raisestate }, @@ -9119,7 +9119,7 @@ mobjinfo_t mobjinfo[NUMMOBJTYPES] = 0, // mass 0, // damage sfx_None, // activesound - MF_NOBLOCKMAP|MF_NOCLIP|MF_NOGRAVITY|MF_NOCLIPHEIGHT, // flags + MF_NOBLOCKMAP|MF_NOCLIP|MF_NOGRAVITY|MF_NOCLIPHEIGHT|MF_SCENERY, // flags S_NULL // raisestate }, @@ -9146,7 +9146,7 @@ mobjinfo_t mobjinfo[NUMMOBJTYPES] = 200, // mass 0, // damage sfx_None, // activesound - MF_NOBLOCKMAP|MF_NOSECTOR|MF_NOCLIP|MF_NOGRAVITY|MF_NOCLIPHEIGHT, // flags + MF_NOBLOCKMAP|MF_NOSECTOR|MF_NOCLIP|MF_NOGRAVITY|MF_NOCLIPHEIGHT|MF_SCENERY, // flags S_NULL // raisestate }, @@ -9173,7 +9173,7 @@ mobjinfo_t mobjinfo[NUMMOBJTYPES] = 200, // mass 0, // damage sfx_None, // activesound - MF_NOBLOCKMAP|MF_NOSECTOR|MF_NOCLIP|MF_NOGRAVITY|MF_NOCLIPHEIGHT, // flags + MF_NOBLOCKMAP|MF_NOSECTOR|MF_NOCLIP|MF_NOGRAVITY|MF_NOCLIPHEIGHT|MF_SCENERY, // flags S_NULL // raisestate }, diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 9d65a5832..4040e271d 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -776,6 +776,19 @@ static int lib_pCanRunOnWater(lua_State *L) return 1; } +static int lib_pMaceRotate(lua_State *L) +{ + mobj_t *center = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); + INT32 baserot = luaL_checkinteger(L, 2); + INT32 baseprevrot = luaL_checkinteger(L, 3); + NOHUD + INLEVEL + if (!center) + return LUA_ErrInvalid(L, "mobj_t"); + P_MaceRotate(center, baserot, baseprevrot); + return 0; +} + // P_USER //////////// @@ -2526,6 +2539,7 @@ static luaL_Reg lib[] = { {"P_CheckDeathPitCollide",lib_pCheckDeathPitCollide}, {"P_CheckSolidLava",lib_pCheckSolidLava}, {"P_CanRunOnWater",lib_pCanRunOnWater}, + {"P_MaceRotate",lib_pMaceRotate}, // p_user {"P_GetPlayerHeight",lib_pGetPlayerHeight}, diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index d384b75d1..1583bd3c4 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -530,10 +530,22 @@ static int mobj_set(lua_State *L) case mobj_bprev: return UNIMPLEMENTED; case mobj_hnext: - mo->hnext = luaL_checkudata(L, 3, META_MOBJ); + if (lua_isnil(L, 3)) + P_SetTarget(&mo->hnext, NULL); + else + { + mobj_t *hnext = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ)); + P_SetTarget(&mo->hnext, hnext); + } break; case mobj_hprev: - mo->hprev = luaL_checkudata(L, 3, META_MOBJ); + if (lua_isnil(L, 3)) + P_SetTarget(&mo->hprev, NULL); + else + { + mobj_t *hprev = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ)); + P_SetTarget(&mo->hprev, hprev); + } break; case mobj_type: // yeah sure, we'll let you change the mobj's type. { diff --git a/src/p_enemy.c b/src/p_enemy.c index 9acc8430e..a8ce7869c 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -4917,6 +4917,7 @@ void A_SlingAppear(mobj_t *actor) boolean firsttime = true; UINT8 mlength = 4; mobj_t *spawnee; + mobj_t *hprev = actor; #ifdef HAVE_BLUA if (LUA_CallAction("A_SlingAppear", actor)) return; @@ -4927,7 +4928,6 @@ void A_SlingAppear(mobj_t *actor) P_SetThingPosition(actor); actor->lastlook = 128; actor->movecount = actor->lastlook; - actor->health = actor->angle>>ANGLETOFINESHIFT; actor->threshold = 0; actor->movefactor = actor->threshold; actor->friction = 128; @@ -4936,10 +4936,13 @@ void A_SlingAppear(mobj_t *actor) { spawnee = P_SpawnMobj(actor->x, actor->y, actor->z, MT_SMALLMACECHAIN); - P_SetTarget(&spawnee->target, actor); + P_SetTarget(&spawnee->tracer, actor); + P_SetTarget(&spawnee->hprev, hprev); + P_SetTarget(&hprev->hnext, spawnee); + hprev = spawnee; - spawnee->threshold = 0; - spawnee->reactiontime = mlength; + spawnee->flags |= MF_NOCLIP|MF_NOCLIPHEIGHT; + spawnee->movecount = mlength; if (firsttime) { diff --git a/src/p_local.h b/src/p_local.h index 54ae37ed2..49d3ed614 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -280,6 +280,8 @@ mobj_t *P_GetClosestAxis(mobj_t *source); boolean P_CanRunOnWater(player_t *player, ffloor_t *rover); +void P_MaceRotate(mobj_t *center, INT32 baserot, INT32 baseprevrot); + void P_FlashPal(player_t *pl, UINT16 type, UINT16 duration); #define PAL_WHITE 1 #define PAL_MIXUP 2 diff --git a/src/p_mobj.c b/src/p_mobj.c index 8695d57e4..2e78c098e 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6176,98 +6176,149 @@ static void P_NightsItemChase(mobj_t *thing) // // P_MaceRotate -// Spins an object around its target, or, swings it from side to side. +// Spins a hnext-chain of objects around its centerpoint, side to side or periodically. // -static void P_MaceRotate(mobj_t *mobj) +void P_MaceRotate(mobj_t *center, INT32 baserot, INT32 baseprevrot) { - TVector v; + TVector unit, baseuo, unitoffset; TVector *res; - fixed_t radius, dist; + fixed_t radius, dist, wah; angle_t fa; - INT32 prevswing; - boolean donetwice = false; + //boolean donetwice = false; + boolean dosound = false; + mobj_t *mobj = center->hnext, *hnext = NULL; // Tracer was removed. - if (!mobj->health) + /*if (!mobj->health) return; else if (!mobj->tracer) { P_KillMobj(mobj, NULL, NULL, 0); return; - } + }*/ - mobj->momx = mobj->momy = mobj->momz = 0; + INT32 rot = (baserot &= FINEMASK); + INT32 prevrot = (baseprevrot &= FINEMASK); - prevswing = mobj->threshold; - mobj->threshold += mobj->tracer->lastlook; - mobj->threshold &= FINEMASK; + INT32 lastthreshold = FINEMASK; // needs to never be equal at start of loop + fixed_t lastfriction = INT32_MIN; // ditto; almost certainly never, but... - dist = ((mobj->info->speed) ? mobj->info->speed : mobjinfo[MT_SMALLMACECHAIN].speed); + fixed_t movefac = unitoffset[0] = unitoffset[1] = unitoffset[2] = 0; - // Radius of the link's rotation. - radius = FixedMul(dist * mobj->movecount, mobj->tracer->scale) + mobj->tracer->extravalue1; + baseuo[3] = 0; -maceretry: - - fa = (FixedAngle(mobj->tracer->movefactor*FRACUNIT) >> ANGLETOFINESHIFT); - radius = FixedMul(FINECOSINE(fa), radius); - v[1] = -FixedMul(FINESINE(fa), radius) - + FixedMul(dist * mobj->movefactor, mobj->tracer->scale); - v[3] = FRACUNIT; - - // Swinging Chain. - if (mobj->tracer->flags2 & MF2_STRONGBOX) + while (mobj) { - fixed_t swingmagnitude = FixedMul(FINECOSINE(mobj->threshold), mobj->tracer->lastlook << FRACBITS); - prevswing = FINECOSINE(prevswing); + mobj->momx = mobj->momy = mobj->momz = 0; - if (!donetwice - && (mobj->flags2 & MF2_BOSSNOTRAP) // at the end of the chain and can play a sound - && ((prevswing > 0) != (swingmagnitude > 0))) // just passed its lowest point + if (mobj->threshold != lastthreshold + || mobj->friction != lastfriction) + { + rot = (baserot + mobj->threshold) & FINEMASK; + prevrot = (baseprevrot + mobj->threshold) & FINEMASK; + + fa = (FixedAngle(center->movefactor*FRACUNIT) >> ANGLETOFINESHIFT); // mpinch + radius = FINECOSINE(fa); + unit[1] = -FixedMul(FINESINE(fa), radius); + unit[3] = center->scale; + + // Swinging Chain. + if (center->flags2 & MF2_STRONGBOX) + { + fixed_t swingmag = FixedMul(FINECOSINE(rot), center->lastlook << FRACBITS); + fixed_t prevswingmag = FINECOSINE(prevrot); + + if ((prevswingmag > 0) != (swingmag > 0)) // just passed its lowest point + dosound = true; + //S_StartSound(mobj, mobj->info->activesound); + + fa = ((FixedAngle(swingmag) >> ANGLETOFINESHIFT) + mobj->friction) & FINEMASK; + + unit[0] = FixedMul(FINESINE(fa), -radius); + unit[2] = FixedMul(FINECOSINE(fa), -radius); + } + // Rotating Chain. + else + { + angle_t prevfa = (prevrot + mobj->friction) & FINEMASK; + fa = (rot + mobj->friction) & FINEMASK; + + if (!(prevfa > (FINEMASK/2)) && (fa > (FINEMASK/2))) // completed a full swing + dosound = true; + + unit[0] = FixedMul(FINECOSINE(fa), radius); + unit[2] = FixedMul(FINESINE(fa), radius); + } + + // Calculate the angle matrixes for the link. + res = VectorMatrixMultiply(unit, *RotateXMatrix(center->threshold << ANGLETOFINESHIFT)); + M_Memcpy(&unit, res, sizeof(unit)); + res = VectorMatrixMultiply(unit, *RotateZMatrix(center->angle)); + M_Memcpy(&unit, res, sizeof(unit)); + } + + if (dosound && (mobj->flags2 & MF2_BOSSNOTRAP)) + { S_StartSound(mobj, mobj->info->activesound); + dosound = false; + } - fa = ((FixedAngle(swingmagnitude) >> ANGLETOFINESHIFT) + mobj->friction) & FINEMASK; + dist = ((mobj->info->speed) ? mobj->info->speed : mobjinfo[MT_SMALLMACECHAIN].speed); - v[0] = FixedMul(FINESINE(fa), -radius); - v[2] = FixedMul(FINECOSINE(fa), -radius); - } - // Rotating Chain. - else - { - prevswing = (prevswing + mobj->friction) & FINEMASK; - fa = (mobj->threshold + mobj->friction) & FINEMASK; + if (dist*mobj->movefactor != movefac) + { + if (!baseuo[3]) + { + baseuo[1] = FRACUNIT; + baseuo[3] = center->scale; + baseuo[0] = baseuo[2] = 0; - if (!donetwice - && (mobj->flags2 & MF2_BOSSNOTRAP) // at the end of the chain and can play a sound - && (!(prevswing > (FINEMASK/2)) && (fa > (FINEMASK/2)))) // completed a full swing - S_StartSound(mobj, mobj->info->activesound); + res = VectorMatrixMultiply(baseuo, *RotateXMatrix(center->threshold << ANGLETOFINESHIFT)); + M_Memcpy(&baseuo, res, sizeof(unit)); + res = VectorMatrixMultiply(baseuo, *RotateZMatrix(center->angle)); + M_Memcpy(&baseuo, res, sizeof(unit)); - v[0] = FixedMul(FINECOSINE(fa), radius); - v[2] = FixedMul(FINESINE(fa), radius); + lastthreshold = mobj->threshold; + lastfriction = mobj->friction; + } + + if (mobj->movefactor) + { + movefac = dist*mobj->movefactor; + unitoffset[0] = FixedMul(movefac, baseuo[0]); + unitoffset[1] = FixedMul(movefac, baseuo[1]); + unitoffset[2] = FixedMul(movefac, baseuo[2]); + } + else + movefac = unitoffset[0] = unitoffset[1] = unitoffset[2] = 0; + } + + //maceretry: + + hnext = mobj->hnext; // just in case the mobj is removed + + P_UnsetThingPosition(mobj); + + // Radius of the link's rotation. + wah = (dist * mobj->movecount) + center->extravalue1; + + // Add on the appropriate distances to the center's co-ordinates. + mobj->x = center->x + FixedMul(unit[0], wah) + unitoffset[0]; + mobj->y = center->y + FixedMul(unit[1], wah) + unitoffset[1]; + mobj->z = center->z + FixedMul(unit[2], wah) + unitoffset[2]; + + // Cut the height to align the link with the axis. + if (mobj->type == MT_SMALLMACECHAIN || mobj->type == MT_BIGMACECHAIN) + mobj->z -= P_MobjFlip(mobj)*mobj->height/4; + else + mobj->z -= P_MobjFlip(mobj)*mobj->height/2; + + P_SetThingPosition(mobj); + + mobj = hnext; } - // Calculate the angle matrixes for the link. - res = VectorMatrixMultiply(v, *RotateXMatrix(mobj->tracer->threshold << ANGLETOFINESHIFT)); - M_Memcpy(&v, res, sizeof(v)); - res = VectorMatrixMultiply(v, *RotateZMatrix(mobj->tracer->health << ANGLETOFINESHIFT)); - M_Memcpy(&v, res, sizeof(v)); - - // Cut the height to align the link with the axis. - if (mobj->type == MT_SMALLMACECHAIN || mobj->type == MT_BIGMACECHAIN) - v[2] -= P_MobjFlip(mobj)*mobj->height/4; - else - v[2] -= P_MobjFlip(mobj)*mobj->height/2; - - P_UnsetThingPosition(mobj); - - // Add on the appropriate distances to the center's co-ordinates. - mobj->x = mobj->tracer->x + v[0]; - mobj->y = mobj->tracer->y + v[1]; - mobj->z = mobj->tracer->z + v[2]; - - P_SetThingPosition(mobj); - - if (donetwice || P_MobjWasRemoved(mobj)) + /*if (donetwice || P_MobjWasRemoved(mobj)) return; if (mobj->flags & (MF_NOCLIP|MF_NOCLIPHEIGHT)) @@ -6293,7 +6344,7 @@ maceretry: radius = FixedMul(radius, dist); donetwice = true; dist = ((mobj->info->speed) ? mobj->info->speed : mobjinfo[MT_SMALLMACECHAIN].speed); - goto maceretry; + goto maceretry;*/ } static boolean P_ShieldLook(mobj_t *thing, shieldtype_t shield) @@ -6664,13 +6715,6 @@ void P_MobjThinker(mobj_t *mobj) } } - if (mobj->flags2 & MF2_MACEROTATE) - { - P_MaceRotate(mobj); - if (P_MobjWasRemoved(mobj)) - return; - } - // Special thinker for scenery objects if (mobj->flags & MF_SCENERY) { @@ -6687,6 +6731,29 @@ void P_MobjThinker(mobj_t *mobj) switch (mobj->type) { + case MT_CHAINPOINT: + case MT_CHAINMACEPOINT: + if (leveltime & 1) + { + if (mobj->lastlook > mobj->movecount) + mobj->lastlook--; + /* + if (mobj->threshold > mobj->movefactor) + mobj->threshold -= FRACUNIT; + else if (mobj->threshold < mobj->movefactor) + mobj->threshold += FRACUNIT;*/ + } + /* FALLTHRU */ + case MT_MACEPOINT: + case MT_SPRINGBALLPOINT: + case MT_FIREBARPOINT: + case MT_CUSTOMMACEPOINT: + case MT_HIDDEN_SLING: + // The following was pretty good, but liked breaking whenever mobj->lastlook changed. + //P_MaceRotate(mobj, ((leveltime + 1) * mobj->lastlook), (leveltime * mobj->lastlook)); + P_MaceRotate(mobj, mobj->movedir + mobj->lastlook, mobj->movedir); + mobj->movedir = (mobj->movedir + mobj->lastlook) & FINEMASK; + break; case MT_HOOP: if (mobj->fuse > 1) P_MoveHoop(mobj); @@ -7337,19 +7404,6 @@ void P_MobjThinker(mobj_t *mobj) } } break; - case MT_CHAINPOINT: - case MT_CHAINMACEPOINT: - if (leveltime & 1) - { - if (mobj->lastlook > mobj->movecount) - mobj->lastlook--; -/* - if (mobj->threshold > mobj->movefactor) - mobj->threshold -= FRACUNIT; - else if (mobj->threshold < mobj->movefactor) - mobj->threshold += FRACUNIT;*/ - } - break; case MT_EGGCAPSULE: if (!mobj->reactiontime) { @@ -8615,6 +8669,13 @@ void P_RemoveMobj(mobj_t *mobj) // Remove any references to other mobjs. P_SetTarget(&mobj->target, P_SetTarget(&mobj->tracer, NULL)); + if (mobj->hnext) + P_SetTarget(&mobj->hnext->hprev, mobj->hprev); + if (mobj->hprev) + P_SetTarget(&mobj->hprev->hnext, mobj->hnext); + + P_SetTarget(&mobj->hnext, P_SetTarget(&mobj->hprev, NULL)); + // free block // DBG: set everything in mobj_t to 0xFF instead of leaving it. debug memory error. if (mobj->flags & MF_NOTHINK && !mobj->thinker.next) @@ -9301,6 +9362,7 @@ void P_SpawnMapThing(mapthing_t *mthing) mobj_t *mobj; fixed_t x, y, z; subsector_t *ss; + boolean doangle = true; if (!mthing->type) return; // Ignore type-0 things as NOPs @@ -9710,7 +9772,7 @@ void P_SpawnMapThing(mapthing_t *mthing) angle_t mspokeangle; mobjtype_t chainlink, macetype, firsttype, linktype; boolean mdoall = true; - mobj_t *spawnee; + mobj_t *spawnee, *hprev; mobjflag_t mflagsapply; mobjflag2_t mflags2apply; mobjeflag_t meflagsapply; @@ -9748,7 +9810,7 @@ ML_EFFECT4 : Don't clip inside the ground mspeed = abs(lines[line].dy >> (FRACBITS - 4)); mphase = (sides[lines[line].sidenum[0]].textureoffset >> FRACBITS) % 360; if ((mmaxspeed = sides[lines[line].sidenum[0]].rowoffset >> (FRACBITS - 4)) < mspeed) - mmaxspeed = mspeed << 1; + mmaxspeed = mspeed; mpitch = (lines[line].frontsector->floorheight >> FRACBITS) % 360; myaw = (lines[line].frontsector->ceilingheight >> FRACBITS) % 360; @@ -9787,10 +9849,12 @@ ML_EFFECT4 : Don't clip inside the ground mobj->lastlook = mspeed; mobj->movecount = mobj->lastlook; - mobj->health = (FixedAngle(myaw*FRACUNIT)>>ANGLETOFINESHIFT); + mobj->angle = FixedAngle(myaw*FRACUNIT); + doangle = false; mobj->threshold = (FixedAngle(mpitch*FRACUNIT)>>ANGLETOFINESHIFT); mobj->friction = mmaxspeed; mobj->movefactor = mpinch; + mobj->movedir = 0; // Mobjtype selection switch(mobj->type) @@ -9857,7 +9921,7 @@ ML_EFFECT4 : Don't clip inside the ground mmin = mnumspokes; // Make the links the same type as the end - repeated below - if ((mobj->type != MT_CHAINPOINT) && ((lines[line].flags & ML_EFFECT2) != (mobj->type == MT_FIREBARPOINT))) // exclusive or + if ((mobj->type != MT_CHAINPOINT) && (((lines[line].flags & ML_EFFECT2) == ML_EFFECT2) != (mobj->type == MT_FIREBARPOINT))) // exclusive or { linktype = macetype; radiusfactor = 2; // Double the radius. @@ -9866,7 +9930,7 @@ ML_EFFECT4 : Don't clip inside the ground radiusfactor = (((linktype = chainlink) == MT_NULL) ? 2 : 1); mflagsapply = ((lines[line].flags & ML_EFFECT4) ? 0 : (MF_NOCLIP|MF_NOCLIPHEIGHT)); - mflags2apply = (MF2_MACEROTATE|((mthing->options & MTF_OBJECTFLIP) ? MF2_OBJECTFLIP : 0)); + mflags2apply = ((mthing->options & MTF_OBJECTFLIP) ? MF2_OBJECTFLIP : 0); meflagsapply = ((mthing->options & MTF_OBJECTFLIP) ? MFE_VERTICALFLIP : 0); msound = ((firsttype == chainlink) ? 0 : (mwidth & 1)); @@ -9875,6 +9939,8 @@ ML_EFFECT4 : Don't clip inside the ground mphase = (FixedAngle(mphase*FRACUNIT)>>ANGLETOFINESHIFT); mroll = (FixedAngle(mroll*FRACUNIT)>>ANGLETOFINESHIFT); + hprev = mobj; + #define makemace(mobjtype, dist, moreflags2) P_SpawnMobj(mobj->x, mobj->y, mobj->z, mobjtype);\ P_SetTarget(&spawnee->tracer, mobj);\ spawnee->threshold = mphase;\ @@ -9884,7 +9950,10 @@ ML_EFFECT4 : Don't clip inside the ground spawnee->angle = myaw;\ spawnee->flags |= (MF_NOGRAVITY|mflagsapply);\ spawnee->flags2 |= (mflags2apply|moreflags2);\ - spawnee->eflags |= meflagsapply + spawnee->eflags |= meflagsapply;\ + P_SetTarget(&hprev->hnext, spawnee);\ + P_SetTarget(&spawnee->hprev, hprev);\ + hprev = spawnee domaceagain: mnumspokesset = mnumspokes; @@ -10264,7 +10333,8 @@ domaceagain: } } - mobj->angle = FixedAngle(mthing->angle*FRACUNIT); + if (doangle) + mobj->angle = FixedAngle(mthing->angle*FRACUNIT); if ((mthing->options & MTF_AMBUSH) && (mthing->options & MTF_OBJECTSPECIAL) diff --git a/src/p_mobj.h b/src/p_mobj.h index c6e1bfbf2..ec25855d8 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -194,8 +194,6 @@ typedef enum MF2_AMBUSH = 1<<27, // Alternate behaviour typically set by MTF_AMBUSH MF2_LINKDRAW = 1<<28, // Draw vissprite of mobj immediately before/after tracer's vissprite (dependent on dispoffset and position) MF2_SHIELD = 1<<29, // Thinker calls P_AddShield/P_ShieldLook (must be partnered with MF_SCENERY to use) - MF2_MACEROTATE = 1<<30, // Thinker calls P_MaceRotate around tracer - // free: to and including 1<<31 } mobjflag2_t; typedef enum From 97ddb8881d5a5af40097f8f8480200c91262a60e Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Sun, 1 Apr 2018 22:05:59 +0100 Subject: [PATCH 2/8] * Remove ability to change speed of chains. * Fix ability to turn chains (still disabled by default, just at least want the option...) * Replace max speed setting with a "minimum chainlink distance" setting - if greater than zero, that many chains will not be spawned from the center outwards. Doesn't affect the head of the chain at all, since otherwise what's the point? :V --- src/p_mobj.c | 32 +++++++++----------------------- src/p_user.c | 13 +------------ 2 files changed, 10 insertions(+), 35 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 2e78c098e..17775b0ef 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6731,21 +6731,10 @@ void P_MobjThinker(mobj_t *mobj) switch (mobj->type) { - case MT_CHAINPOINT: - case MT_CHAINMACEPOINT: - if (leveltime & 1) - { - if (mobj->lastlook > mobj->movecount) - mobj->lastlook--; - /* - if (mobj->threshold > mobj->movefactor) - mobj->threshold -= FRACUNIT; - else if (mobj->threshold < mobj->movefactor) - mobj->threshold += FRACUNIT;*/ - } - /* FALLTHRU */ case MT_MACEPOINT: + case MT_CHAINMACEPOINT: case MT_SPRINGBALLPOINT: + case MT_CHAINPOINT: case MT_FIREBARPOINT: case MT_CUSTOMMACEPOINT: case MT_HIDDEN_SLING: @@ -9768,7 +9757,7 @@ void P_SpawnMapThing(mapthing_t *mthing) case MT_FIREBARPOINT: case MT_CUSTOMMACEPOINT: { - fixed_t mlength, mlengthset, mspeed, mphase, myaw, mpitch, mmaxspeed, mnumspokes, mnumspokesset, mpinch, mroll, mnumnospokes, mwidth, mmin, msound, radiusfactor; + fixed_t mlength, mlengthset, mspeed, mphase, myaw, mpitch, mminlength, mnumspokes, mnumspokesset, mpinch, mroll, mnumnospokes, mwidth, mmin, msound, radiusfactor; angle_t mspokeangle; mobjtype_t chainlink, macetype, firsttype, linktype; boolean mdoall = true; @@ -9809,8 +9798,8 @@ ML_EFFECT4 : Don't clip inside the ground mlength = abs(lines[line].dx >> FRACBITS); mspeed = abs(lines[line].dy >> (FRACBITS - 4)); mphase = (sides[lines[line].sidenum[0]].textureoffset >> FRACBITS) % 360; - if ((mmaxspeed = sides[lines[line].sidenum[0]].rowoffset >> (FRACBITS - 4)) < mspeed) - mmaxspeed = mspeed; + if ((mminlength = sides[lines[line].sidenum[0]].rowoffset>>FRACBITS) < 0) + mminlength = 0; mpitch = (lines[line].frontsector->floorheight >> FRACBITS) % 360; myaw = (lines[line].frontsector->ceilingheight >> FRACBITS) % 360; @@ -9829,18 +9818,16 @@ ML_EFFECT4 : Don't clip inside the ground mpinch = mroll = mnumnospokes = mwidth = 0; CONS_Debug(DBG_GAMELOGIC, "Mace/Chain (mapthing #%s):\n" - "Length is %d\n" + "Length is %d (minus %d)\n" "Speed is %d\n" "Phase is %d\n" "Yaw is %d\n" "Pitch is %d\n" - "Max. speed is %d\n" - "No. of spokes is %d\n" + "No. of spokes is %d (%d antispokes)\n" "Pinch is %d\n" "Roll is %d\n" - "No. of antispokes is %d\n" "Width is %d\n", - sizeu1(mthingi), mlength, mspeed, mphase, myaw, mpitch, mmaxspeed, mnumspokes, mpinch, mroll, mnumnospokes, mwidth); + sizeu1(mthingi), mlength, mminlength, mspeed, mphase, myaw, mpitch, mnumspokes, mnumnospokes, mpinch, mroll, mwidth); if (mnumnospokes > 0 && (mnumnospokes < mnumspokes)) mnumnospokes = mnumspokes/mnumnospokes; @@ -9852,7 +9839,6 @@ ML_EFFECT4 : Don't clip inside the ground mobj->angle = FixedAngle(myaw*FRACUNIT); doangle = false; mobj->threshold = (FixedAngle(mpitch*FRACUNIT)>>ANGLETOFINESHIFT); - mobj->friction = mmaxspeed; mobj->movefactor = mpinch; mobj->movedir = 0; @@ -10011,7 +9997,7 @@ domaceagain: continue; // The rest of the links - while (mlengthset > 0) + while (mlengthset > mminlength) { spawnee = makemace(linktype, radiusfactor*(mlengthset--), 0); } } diff --git a/src/p_user.c b/src/p_user.c index f422e9b65..c0fd01000 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -10421,21 +10421,10 @@ void P_PlayerAfterThink(player_t *player) player->secondjump = 0; player->pflags &= ~PF_THOKKED; - if (cmd->forwardmove > 0) - { - if ((player->mo->tracer->tracer->lastlook += 2) > player->mo->tracer->tracer->friction) - player->mo->tracer->tracer->lastlook = player->mo->tracer->tracer->friction; - } - else if (cmd->forwardmove < 0) - { - if ((player->mo->tracer->tracer->lastlook -= 2) < player->mo->tracer->tracer->movecount) - player->mo->tracer->tracer->lastlook = player->mo->tracer->tracer->movecount; - } - if ((player->mo->tracer->tracer->flags & MF_SLIDEME) // Noclimb on chain parameters gives this && !(twodlevel || player->mo->flags2 & MF2_TWOD)) // why on earth would you want to turn them in 2D mode? { - player->mo->tracer->tracer->health += cmd->sidemove; + player->mo->tracer->tracer->angle += cmd->sidemove<mo->angle += cmd->sidemove< ANGLE_MAX if (!demoplayback || P_AnalogMove(player)) From 5ac70bbb7e286c1908ed5056af530940ef1c00d8 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 2 Apr 2018 01:08:31 +0100 Subject: [PATCH 3/8] * Fix multispoke mace/chainbars having problems. * Completely rework how mace/chainbars are spawned to reduce the number of matrix multiplications required EVEN FURTHER! * Reimplement the maceretry solidity stuff (effect 4). * Flip the mminlength stuff so that existing dev maps don't break badly. * Fix hacky chainbar grabbing. * Tweak height of tinychain a smidge. --- src/info.c | 2 +- src/p_inter.c | 4 +- src/p_mobj.c | 197 ++++++++++++++++++++++++++++---------------------- 3 files changed, 112 insertions(+), 91 deletions(-) diff --git a/src/info.c b/src/info.c index f11d88af8..673c18ac6 100644 --- a/src/info.c +++ b/src/info.c @@ -9195,7 +9195,7 @@ mobjinfo_t mobjinfo[NUMMOBJTYPES] = sfx_None, // deathsound 24*FRACUNIT, // speed 24*FRACUNIT, // radius - 48*FRACUNIT, // height + 32*FRACUNIT, // height 0, // display offset 100, // mass 1, // damage diff --git a/src/p_inter.c b/src/p_inter.c index 4c9e231fe..82187f533 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -1503,10 +1503,10 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) if (player->powers[pw_flashing]) return; - if (special->movefactor && special->tracer && (angle_t)special->tracer->health != ANGLE_90 && (angle_t)special->tracer->health != ANGLE_270) + if (special->movefactor && special->tracer && (angle_t)special->tracer->angle != ANGLE_90 && (angle_t)special->tracer->angle != ANGLE_270) { // I don't expect you to understand this, Mr Bond... angle_t ang = R_PointToAngle2(special->x, special->y, toucher->x, toucher->y) - special->tracer->threshold; - if ((special->movefactor > 0) == ((angle_t)special->tracer->health > ANGLE_90 && (angle_t)special->tracer->health < ANGLE_270)) + if ((special->movefactor > 0) == ((angle_t)special->tracer->angle > ANGLE_90 && (angle_t)special->tracer->angle < ANGLE_270)) ang += ANGLE_180; if (ang < ANGLE_180) return; // I expect you to die. diff --git a/src/p_mobj.c b/src/p_mobj.c index 17775b0ef..f98943d84 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6182,33 +6182,28 @@ void P_MaceRotate(mobj_t *center, INT32 baserot, INT32 baseprevrot) { TVector unit, baseuo, unitoffset; TVector *res; - fixed_t radius, dist, wah; + fixed_t radius, dist, mag, zstore; angle_t fa; - //boolean donetwice = false; + boolean donetwice = false; boolean dosound = false; mobj_t *mobj = center->hnext, *hnext = NULL; - // Tracer was removed. - /*if (!mobj->health) - return; - else if (!mobj->tracer) - { - P_KillMobj(mobj, NULL, NULL, 0); - return; - }*/ - INT32 rot = (baserot &= FINEMASK); INT32 prevrot = (baseprevrot &= FINEMASK); INT32 lastthreshold = FINEMASK; // needs to never be equal at start of loop fixed_t lastfriction = INT32_MIN; // ditto; almost certainly never, but... - fixed_t movefac = unitoffset[0] = unitoffset[1] = unitoffset[2] = 0; - - baseuo[3] = 0; + fixed_t movefac = unitoffset[0] = unitoffset[1] = unitoffset[2] = baseuo[3] = 0; while (mobj) { + if (!mobj->health) + { + mobj = mobj->hnext; + continue; + } + mobj->momx = mobj->momy = mobj->momz = 0; if (mobj->threshold != lastthreshold @@ -6255,6 +6250,9 @@ void P_MaceRotate(mobj_t *center, INT32 baserot, INT32 baseprevrot) M_Memcpy(&unit, res, sizeof(unit)); res = VectorMatrixMultiply(unit, *RotateZMatrix(center->angle)); M_Memcpy(&unit, res, sizeof(unit)); + + lastthreshold = mobj->threshold; + lastfriction = mobj->friction; } if (dosound && (mobj->flags2 & MF2_BOSSNOTRAP)) @@ -6277,9 +6275,6 @@ void P_MaceRotate(mobj_t *center, INT32 baserot, INT32 baseprevrot) M_Memcpy(&baseuo, res, sizeof(unit)); res = VectorMatrixMultiply(baseuo, *RotateZMatrix(center->angle)); M_Memcpy(&baseuo, res, sizeof(unit)); - - lastthreshold = mobj->threshold; - lastfriction = mobj->friction; } if (mobj->movefactor) @@ -6293,58 +6288,78 @@ void P_MaceRotate(mobj_t *center, INT32 baserot, INT32 baseprevrot) movefac = unitoffset[0] = unitoffset[1] = unitoffset[2] = 0; } - //maceretry: - hnext = mobj->hnext; // just in case the mobj is removed + // Radius of the link's rotation. + mag = (dist * mobj->movecount) + mobj->extravalue1; + +maceretry: P_UnsetThingPosition(mobj); - // Radius of the link's rotation. - wah = (dist * mobj->movecount) + center->extravalue1; + mobj->x = center->x; + mobj->y = center->y; + mobj->z = center->z; // Add on the appropriate distances to the center's co-ordinates. - mobj->x = center->x + FixedMul(unit[0], wah) + unitoffset[0]; - mobj->y = center->y + FixedMul(unit[1], wah) + unitoffset[1]; - mobj->z = center->z + FixedMul(unit[2], wah) + unitoffset[2]; + if (mag) + { + zstore = FixedMul(unit[2], mag); + mobj->x += FixedMul(unit[0], mag); + mobj->y += FixedMul(unit[1], mag); + } + else + zstore = 0; + zstore += unitoffset[2]; + + mobj->x += unitoffset[0]; + mobj->y += unitoffset[1]; // Cut the height to align the link with the axis. if (mobj->type == MT_SMALLMACECHAIN || mobj->type == MT_BIGMACECHAIN) - mobj->z -= P_MobjFlip(mobj)*mobj->height/4; + zstore -= P_MobjFlip(mobj)*mobj->height/4; else - mobj->z -= P_MobjFlip(mobj)*mobj->height/2; + zstore -= P_MobjFlip(mobj)*mobj->height/2; + + mobj->z += zstore; + +#if 0 // toaster's testing flashie! + if (!mobj->threshold && !mobj->friction && !(leveltime & TICRATE)) // I had a brainfart and the flashing isn't exactly what I expected it to be, but it's actually much more useful. + mobj->flags2 ^= MF2_DONTDRAW; +#endif P_SetThingPosition(mobj); + if (!mag || donetwice || P_MobjWasRemoved(mobj)) + goto cont; + + if (mobj->flags & (MF_NOCLIP|MF_NOCLIPHEIGHT)) + goto cont; + + if ((fa = ((mobj->tracer->threshold & (FINEMASK/2)) << ANGLETOFINESHIFT)) > ANGLE_45 && fa < ANGLE_135) // only move towards center when the motion is towards/away from the ground, rather than alongside it + goto cont; + + if (mobj->subsector->sector->ffloors) + P_AdjustMobjFloorZ_FFloors(mobj, mobj->subsector->sector, 2); + + // Variable reuse + if (mobj->floorz > mobj->z) + dist = (mobj->floorz - mobj->tracer->z); + else if (mobj->ceilingz < mobj->z) + dist = (mobj->ceilingz - mobj->tracer->z); + else + goto cont; + + if ((dist = FixedDiv(dist, zstore)) > FRACUNIT) + goto cont; + + mag = FixedMul(mag, dist); + donetwice = true; + dist = ((mobj->info->speed) ? mobj->info->speed : mobjinfo[MT_SMALLMACECHAIN].speed); + goto maceretry; + +cont: mobj = hnext; } - - /*if (donetwice || P_MobjWasRemoved(mobj)) - return; - - if (mobj->flags & (MF_NOCLIP|MF_NOCLIPHEIGHT)) - return; - - if ((fa = ((mobj->tracer->threshold & (FINEMASK/2)) << ANGLETOFINESHIFT)) > ANGLE_45 && fa < ANGLE_135) // only move towards center when the motion is towards/away from the ground, rather than alongside it - return; - - if (mobj->subsector->sector->ffloors) - P_AdjustMobjFloorZ_FFloors(mobj, mobj->subsector->sector, 2); - - // Variable reuse - if (mobj->floorz > mobj->z) - dist = (mobj->floorz - mobj->tracer->z); - else if (mobj->ceilingz < mobj->z) - dist = (mobj->ceilingz - mobj->tracer->z); - else - return; - - if ((dist = FixedDiv(dist, v[2])) > FRACUNIT) - return; - - radius = FixedMul(radius, dist); - donetwice = true; - dist = ((mobj->info->speed) ? mobj->info->speed : mobjinfo[MT_SMALLMACECHAIN].speed); - goto maceretry;*/ } static boolean P_ShieldLook(mobj_t *thing, shieldtype_t shield) @@ -9757,10 +9772,10 @@ void P_SpawnMapThing(mapthing_t *mthing) case MT_FIREBARPOINT: case MT_CUSTOMMACEPOINT: { - fixed_t mlength, mlengthset, mspeed, mphase, myaw, mpitch, mminlength, mnumspokes, mnumspokesset, mpinch, mroll, mnumnospokes, mwidth, mmin, msound, radiusfactor; + fixed_t mlength, mlengthmax, mlengthset, mspeed, mphase, myaw, mpitch, mminlength, mnumspokes, mpinch, mroll, mnumnospokes, mwidth, mwidthset, mmin, msound, radiusfactor; angle_t mspokeangle; mobjtype_t chainlink, macetype, firsttype, linktype; - boolean mdoall = true; + boolean mdoall = true, mdocenter; mobj_t *spawnee, *hprev; mobjflag_t mflagsapply; mobjflag2_t mflags2apply; @@ -9798,7 +9813,7 @@ ML_EFFECT4 : Don't clip inside the ground mlength = abs(lines[line].dx >> FRACBITS); mspeed = abs(lines[line].dy >> (FRACBITS - 4)); mphase = (sides[lines[line].sidenum[0]].textureoffset >> FRACBITS) % 360; - if ((mminlength = sides[lines[line].sidenum[0]].rowoffset>>FRACBITS) < 0) + if ((mminlength = -sides[lines[line].sidenum[0]].rowoffset>>FRACBITS) < 0) mminlength = 0; mpitch = (lines[line].frontsector->floorheight >> FRACBITS) % 360; myaw = (lines[line].frontsector->ceilingheight >> FRACBITS) % 360; @@ -9931,7 +9946,7 @@ ML_EFFECT4 : Don't clip inside the ground P_SetTarget(&spawnee->tracer, mobj);\ spawnee->threshold = mphase;\ spawnee->friction = mroll;\ - spawnee->movefactor = mwidth;\ + spawnee->movefactor = mwidthset;\ spawnee->movecount = dist;\ spawnee->angle = myaw;\ spawnee->flags |= (MF_NOGRAVITY|mflagsapply);\ @@ -9941,14 +9956,10 @@ ML_EFFECT4 : Don't clip inside the ground P_SetTarget(&spawnee->hprev, hprev);\ hprev = spawnee -domaceagain: - mnumspokesset = mnumspokes; - - if (mdoall && lines[line].flags & ML_EFFECT3) // Innermost mace/link - { spawnee = makemace(macetype, 0, MF2_AMBUSH); } + mdocenter = (lines[line].flags & ML_EFFECT3); // The actual spawning of spokes - while (mnumspokesset-- > 0) + while (mnumspokes-- > 0) { // Offsets if (lines[line].flags & ML_EFFECT1) // Swinging @@ -9956,13 +9967,13 @@ domaceagain: else // Spinning mphase = (mphase - mspokeangle) & FINEMASK; - if (mnumnospokes && !(mnumspokesset % mnumnospokes)) // Skipping a "missing" spoke + if (mnumnospokes && !(mnumspokes % mnumnospokes)) // Skipping a "missing" spoke { if (mobj->type != MT_CHAINMACEPOINT) continue; firsttype = linktype = chainlink; - mlengthset = 1 + (mlength - 1)*radiusfactor; + mlengthmax = 1 + (mlength - 1)*radiusfactor; radiusfactor = 1; } else @@ -9984,34 +9995,44 @@ domaceagain: firsttype = macetype; } - mlengthset = mlength; + mlengthmax = mlength; } - // Outermost mace/link - spawnee = makemace(firsttype, radiusfactor*(mlengthset--), MF2_AMBUSH); + mwidthset = mwidth; + mdoall = true; + while (1) + { + mlengthset = mlengthmax; - if (mspeed && (mwidth == msound) && !(mthing->options & MTF_OBJECTSPECIAL) && mnumspokesset <= mmin) // Can it make a sound? - spawnee->flags2 |= MF2_BOSSNOTRAP; + if (mdocenter) // Innermost mace/link + { + spawnee = makemace(macetype, 0, 0); + } - if (!mdoall || !linktype) - continue; + // Outermost mace/link + spawnee = makemace(firsttype, radiusfactor*(mlengthset--), MF2_AMBUSH); - // The rest of the links - while (mlengthset > mminlength) - { spawnee = makemace(linktype, radiusfactor*(mlengthset--), 0); } - } + if (mspeed && (mwidthset == msound) && !(mthing->options & MTF_OBJECTSPECIAL) && mnumspokes <= mmin) // Can it make a sound? + spawnee->flags2 |= MF2_BOSSNOTRAP; - if (mwidth > 0) - { - mwidth *= -1; - goto domaceagain; - } - else if (mwidth != 0) - { - if ((mwidth = -(mwidth + ((firsttype == chainlink) ? 1 : 2))) < 0) - break; - mdoall = false; - goto domaceagain; + if (mdoall && linktype) + { + // The rest of the links + while (mlengthset > mminlength) + { + spawnee = makemace(linktype, radiusfactor*(mlengthset--), 0); + } + } + + if (mwidthset > 0) + mwidthset *= -1; + else if (!mwidthset + || ((mwidthset = -(mwidthset + ((firsttype == chainlink) ? 1 : 2))) < 0)) + break; + else + mdocenter = mdoall = false; + + } } #undef makemace From 0102da824e462a344ef38c8a868bbe51a3eaea78 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 2 Apr 2018 01:20:32 +0100 Subject: [PATCH 4/8] Make the h-chain repairing safer. --- src/p_mobj.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index f98943d84..4e1356d61 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -8673,9 +8673,9 @@ void P_RemoveMobj(mobj_t *mobj) // Remove any references to other mobjs. P_SetTarget(&mobj->target, P_SetTarget(&mobj->tracer, NULL)); - if (mobj->hnext) + if (mobj->hnext && !P_MobjWasRemoved(mobj->hnext)) P_SetTarget(&mobj->hnext->hprev, mobj->hprev); - if (mobj->hprev) + if (mobj->hprev && !P_MobjWasRemoved(mobj->hprev)) P_SetTarget(&mobj->hprev->hnext, mobj->hnext); P_SetTarget(&mobj->hnext, P_SetTarget(&mobj->hprev, NULL)); From 4051ae8915525d850b754ee12e3e6895ffdfa509 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 2 Apr 2018 21:36:12 +0100 Subject: [PATCH 5/8] * Revamp mace creation again to potentially serve as the foundation for further optimisation (and also not rely on a while (1) loop, which easily went wrong several times whilst I was making changes to it). * Fix minor typoes and other small tweaks in the P_MaceRotate function, which I'm probably about to rewrite again anyways... --- src/p_mobj.c | 123 +++++++++++++++++++++++++++------------------------ 1 file changed, 64 insertions(+), 59 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 4e1356d61..63d3aa666 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6184,8 +6184,7 @@ void P_MaceRotate(mobj_t *center, INT32 baserot, INT32 baseprevrot) TVector *res; fixed_t radius, dist, mag, zstore; angle_t fa; - boolean donetwice = false; - boolean dosound = false; + boolean donetwice, dosound = false; mobj_t *mobj = center->hnext, *hnext = NULL; INT32 rot = (baserot &= FINEMASK); @@ -6268,13 +6267,13 @@ void P_MaceRotate(mobj_t *center, INT32 baserot, INT32 baseprevrot) if (!baseuo[3]) { baseuo[1] = FRACUNIT; - baseuo[3] = center->scale; baseuo[0] = baseuo[2] = 0; + baseuo[3] = center->scale; res = VectorMatrixMultiply(baseuo, *RotateXMatrix(center->threshold << ANGLETOFINESHIFT)); - M_Memcpy(&baseuo, res, sizeof(unit)); + M_Memcpy(&baseuo, res, sizeof(baseuo)); res = VectorMatrixMultiply(baseuo, *RotateZMatrix(center->angle)); - M_Memcpy(&baseuo, res, sizeof(unit)); + M_Memcpy(&baseuo, res, sizeof(baseuo)); } if (mobj->movefactor) @@ -6293,6 +6292,7 @@ void P_MaceRotate(mobj_t *center, INT32 baserot, INT32 baseprevrot) // Radius of the link's rotation. mag = (dist * mobj->movecount) + mobj->extravalue1; + donetwice = false; maceretry: P_UnsetThingPosition(mobj); @@ -6303,13 +6303,12 @@ maceretry: // Add on the appropriate distances to the center's co-ordinates. if (mag) { - zstore = FixedMul(unit[2], mag); mobj->x += FixedMul(unit[0], mag); mobj->y += FixedMul(unit[1], mag); + zstore = FixedMul(unit[2], mag) + unitoffset[2]; } else - zstore = 0; - zstore += unitoffset[2]; + zstore = unitoffset[2]; mobj->x += unitoffset[0]; mobj->y += unitoffset[1]; @@ -6323,7 +6322,7 @@ maceretry: mobj->z += zstore; #if 0 // toaster's testing flashie! - if (!mobj->threshold && !mobj->friction && !(leveltime & TICRATE)) // I had a brainfart and the flashing isn't exactly what I expected it to be, but it's actually much more useful. + if (!donetwice && mobj->movefactor != -5 && !(leveltime & TICRATE)) // I had a brainfart and the flashing isn't exactly what I expected it to be, but it's actually much more useful. mobj->flags2 ^= MF2_DONTDRAW; #endif @@ -9772,11 +9771,11 @@ void P_SpawnMapThing(mapthing_t *mthing) case MT_FIREBARPOINT: case MT_CUSTOMMACEPOINT: { - fixed_t mlength, mlengthmax, mlengthset, mspeed, mphase, myaw, mpitch, mminlength, mnumspokes, mpinch, mroll, mnumnospokes, mwidth, mwidthset, mmin, msound, radiusfactor; + fixed_t mlength, mmaxlength, mlengthset, mspeed, mphase, myaw, mpitch, mminlength, mnumspokes, mpinch, mroll, mnumnospokes, mwidth, mwidthset, mmin, msound, radiusfactor; angle_t mspokeangle; mobjtype_t chainlink, macetype, firsttype, linktype; - boolean mdoall = true, mdocenter; - mobj_t *spawnee, *hprev; + boolean mdosound, mdocenter; + mobj_t *spawnee = NULL, *hprev = mobj; mobjflag_t mflagsapply; mobjflag2_t mflags2apply; mobjeflag_t meflagsapply; @@ -9815,6 +9814,8 @@ ML_EFFECT4 : Don't clip inside the ground mphase = (sides[lines[line].sidenum[0]].textureoffset >> FRACBITS) % 360; if ((mminlength = -sides[lines[line].sidenum[0]].rowoffset>>FRACBITS) < 0) mminlength = 0; + else if (mminlength > mlength-1) + mminlength = mlength-1; mpitch = (lines[line].frontsector->floorheight >> FRACBITS) % 360; myaw = (lines[line].frontsector->ceilingheight >> FRACBITS) % 360; @@ -9940,22 +9941,23 @@ ML_EFFECT4 : Don't clip inside the ground mphase = (FixedAngle(mphase*FRACUNIT)>>ANGLETOFINESHIFT); mroll = (FixedAngle(mroll*FRACUNIT)>>ANGLETOFINESHIFT); - hprev = mobj; - -#define makemace(mobjtype, dist, moreflags2) P_SpawnMobj(mobj->x, mobj->y, mobj->z, mobjtype);\ - P_SetTarget(&spawnee->tracer, mobj);\ - spawnee->threshold = mphase;\ - spawnee->friction = mroll;\ - spawnee->movefactor = mwidthset;\ - spawnee->movecount = dist;\ - spawnee->angle = myaw;\ - spawnee->flags |= (MF_NOGRAVITY|mflagsapply);\ - spawnee->flags2 |= (mflags2apply|moreflags2);\ - spawnee->eflags |= meflagsapply;\ - P_SetTarget(&hprev->hnext, spawnee);\ - P_SetTarget(&spawnee->hprev, hprev);\ - hprev = spawnee +#define makemace(mobjtype, dist, moreflags2) {\ + spawnee = P_SpawnMobj(mobj->x, mobj->y, mobj->z, mobjtype);\ + P_SetTarget(&spawnee->tracer, mobj);\ + spawnee->threshold = mphase;\ + spawnee->friction = mroll;\ + spawnee->movefactor = mwidthset;\ + spawnee->movecount = dist;\ + spawnee->angle = myaw;\ + spawnee->flags |= (MF_NOGRAVITY|mflagsapply);\ + spawnee->flags2 |= (mflags2apply|moreflags2);\ + spawnee->eflags |= meflagsapply;\ + P_SetTarget(&hprev->hnext, spawnee);\ + P_SetTarget(&spawnee->hprev, hprev);\ + hprev = spawnee;\ +} + mdosound = (mspeed && !(mthing->options & MTF_OBJECTSPECIAL)); mdocenter = (lines[line].flags & ML_EFFECT3); // The actual spawning of spokes @@ -9973,7 +9975,7 @@ ML_EFFECT4 : Don't clip inside the ground continue; firsttype = linktype = chainlink; - mlengthmax = 1 + (mlength - 1)*radiusfactor; + mmaxlength = 1 + (mlength - 1)*radiusfactor; radiusfactor = 1; } else @@ -9995,43 +9997,46 @@ ML_EFFECT4 : Don't clip inside the ground firsttype = macetype; } - mlengthmax = mlength; + mmaxlength = mlength; } mwidthset = mwidth; - mdoall = true; - while (1) + //fixed_t base = 0; + mlengthset = mminlength; + + if (mdocenter) // Innermost mace/link + makemace(macetype, 0, 0); + + //base = mlengthset*((mobjinfo[macetype].speed) ? mobjinfo[macetype].speed : mobjinfo[MT_SMALLMACECHAIN].speed); + + while ((++mlengthset) < mmaxlength) + makemace(linktype, radiusfactor*mlengthset, 0); + + // Outermost mace/link + makemace(firsttype, radiusfactor*mlengthset, MF2_AMBUSH); + + if (!mwidth) { - mlengthset = mlengthmax; + if (mdosound && mnumspokes <= mmin) // Can it make a sound? + spawnee->flags2 |= MF2_BOSSNOTRAP; + } + else + { + while ((mwidthset -= ((firsttype == chainlink) ? 1 : 2)) > -mwidth) + { + makemace(firsttype, radiusfactor*mlengthset, MF2_AMBUSH); + if (mdosound && (mwidthset == msound) && mnumspokes <= mmin) // Can it make a sound? + spawnee->flags2 |= MF2_BOSSNOTRAP; + } + + // Outermost mace/link again! + makemace(firsttype, radiusfactor*(mlengthset--), MF2_AMBUSH); + + while (mlengthset > mminlength) + makemace(linktype, radiusfactor*(mlengthset--), 0); if (mdocenter) // Innermost mace/link - { - spawnee = makemace(macetype, 0, 0); - } - - // Outermost mace/link - spawnee = makemace(firsttype, radiusfactor*(mlengthset--), MF2_AMBUSH); - - if (mspeed && (mwidthset == msound) && !(mthing->options & MTF_OBJECTSPECIAL) && mnumspokes <= mmin) // Can it make a sound? - spawnee->flags2 |= MF2_BOSSNOTRAP; - - if (mdoall && linktype) - { - // The rest of the links - while (mlengthset > mminlength) - { - spawnee = makemace(linktype, radiusfactor*(mlengthset--), 0); - } - } - - if (mwidthset > 0) - mwidthset *= -1; - else if (!mwidthset - || ((mwidthset = -(mwidthset + ((firsttype == chainlink) ? 1 : 2))) < 0)) - break; - else - mdocenter = mdoall = false; - + makemace(macetype, 0, 0); } } From 156cc031ea22d59296644c7f5d2c836746ad0937 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Tue, 3 Apr 2018 01:10:10 +0100 Subject: [PATCH 6/8] * Optimise them even further... AGAIN! Using an offset-based system rather than a multiplication-based one... * Again, tweak the spawning code to take maximum advantage of these gains. * Fix potential crashes with MT_NULL mace/chain types supplied. * #ifdef out the height-clipping code. It needs more TLC than I can give it right now, and the existing behaviour is less obviously broken (sadly enough). * Fix chainmace points, which were apparently broken without anyone realising. --- src/p_mobj.c | 203 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 129 insertions(+), 74 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 63d3aa666..286357964 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6180,11 +6180,11 @@ static void P_NightsItemChase(mobj_t *thing) // void P_MaceRotate(mobj_t *center, INT32 baserot, INT32 baseprevrot) { - TVector unit, baseuo, unitoffset; + TVector unit_lengthways, unit_sideways, pos_lengthways, pos_sideways; TVector *res; - fixed_t radius, dist, mag, zstore; + fixed_t radius, dist, zstore; angle_t fa; - boolean donetwice, dosound = false; + boolean dosound = false; mobj_t *mobj = center->hnext, *hnext = NULL; INT32 rot = (baserot &= FINEMASK); @@ -6193,7 +6193,7 @@ void P_MaceRotate(mobj_t *center, INT32 baserot, INT32 baseprevrot) INT32 lastthreshold = FINEMASK; // needs to never be equal at start of loop fixed_t lastfriction = INT32_MIN; // ditto; almost certainly never, but... - fixed_t movefac = unitoffset[0] = unitoffset[1] = unitoffset[2] = baseuo[3] = 0; + dist = pos_sideways[0] = pos_sideways[1] = pos_sideways[2] = pos_sideways[3] = unit_sideways[3] = pos_lengthways[0] = pos_lengthways[1] = pos_lengthways[2] = pos_lengthways[3] = 0; while (mobj) { @@ -6211,10 +6211,15 @@ void P_MaceRotate(mobj_t *center, INT32 baserot, INT32 baseprevrot) rot = (baserot + mobj->threshold) & FINEMASK; prevrot = (baseprevrot + mobj->threshold) & FINEMASK; - fa = (FixedAngle(center->movefactor*FRACUNIT) >> ANGLETOFINESHIFT); // mpinch - radius = FINECOSINE(fa); - unit[1] = -FixedMul(FINESINE(fa), radius); - unit[3] = center->scale; + pos_lengthways[0] = pos_lengthways[1] = pos_lengthways[2] = pos_lengthways[3] = 0; + + dist = ((mobj->info->speed) ? mobj->info->speed : mobjinfo[MT_SMALLMACECHAIN].speed); + dist = ((center->scale == FRACUNIT) ? dist : FixedMul(dist, center->scale)); + + fa = (FixedAngle(center->movefactor*FRACUNIT) >> ANGLETOFINESHIFT); + radius = FixedMul(dist, FINECOSINE(fa)); + unit_lengthways[1] = -FixedMul(dist, FINESINE(fa)); + unit_lengthways[3] = FRACUNIT; // Swinging Chain. if (center->flags2 & MF2_STRONGBOX) @@ -6224,12 +6229,11 @@ void P_MaceRotate(mobj_t *center, INT32 baserot, INT32 baseprevrot) if ((prevswingmag > 0) != (swingmag > 0)) // just passed its lowest point dosound = true; - //S_StartSound(mobj, mobj->info->activesound); fa = ((FixedAngle(swingmag) >> ANGLETOFINESHIFT) + mobj->friction) & FINEMASK; - unit[0] = FixedMul(FINESINE(fa), -radius); - unit[2] = FixedMul(FINECOSINE(fa), -radius); + unit_lengthways[0] = FixedMul(FINESINE(fa), -radius); + unit_lengthways[2] = FixedMul(FINECOSINE(fa), -radius); } // Rotating Chain. else @@ -6240,15 +6244,15 @@ void P_MaceRotate(mobj_t *center, INT32 baserot, INT32 baseprevrot) if (!(prevfa > (FINEMASK/2)) && (fa > (FINEMASK/2))) // completed a full swing dosound = true; - unit[0] = FixedMul(FINECOSINE(fa), radius); - unit[2] = FixedMul(FINESINE(fa), radius); + unit_lengthways[0] = FixedMul(FINECOSINE(fa), radius); + unit_lengthways[2] = FixedMul(FINESINE(fa), radius); } // Calculate the angle matrixes for the link. - res = VectorMatrixMultiply(unit, *RotateXMatrix(center->threshold << ANGLETOFINESHIFT)); - M_Memcpy(&unit, res, sizeof(unit)); - res = VectorMatrixMultiply(unit, *RotateZMatrix(center->angle)); - M_Memcpy(&unit, res, sizeof(unit)); + res = VectorMatrixMultiply(unit_lengthways, *RotateXMatrix(center->threshold << ANGLETOFINESHIFT)); + M_Memcpy(&unit_lengthways, res, sizeof(unit_lengthways)); + res = VectorMatrixMultiply(unit_lengthways, *RotateZMatrix(center->angle)); + M_Memcpy(&unit_lengthways, res, sizeof(unit_lengthways)); lastthreshold = mobj->threshold; lastfriction = mobj->friction; @@ -6260,40 +6264,65 @@ void P_MaceRotate(mobj_t *center, INT32 baserot, INT32 baseprevrot) dosound = false; } - dist = ((mobj->info->speed) ? mobj->info->speed : mobjinfo[MT_SMALLMACECHAIN].speed); - - if (dist*mobj->movefactor != movefac) + if (pos_sideways[3] != mobj->movefactor) { - if (!baseuo[3]) + if (!unit_sideways[3]) { - baseuo[1] = FRACUNIT; - baseuo[0] = baseuo[2] = 0; - baseuo[3] = center->scale; + unit_sideways[1] = dist; + unit_sideways[0] = unit_sideways[2] = 0; + unit_sideways[3] = FRACUNIT; - res = VectorMatrixMultiply(baseuo, *RotateXMatrix(center->threshold << ANGLETOFINESHIFT)); - M_Memcpy(&baseuo, res, sizeof(baseuo)); - res = VectorMatrixMultiply(baseuo, *RotateZMatrix(center->angle)); - M_Memcpy(&baseuo, res, sizeof(baseuo)); + res = VectorMatrixMultiply(unit_sideways, *RotateXMatrix(center->threshold << ANGLETOFINESHIFT)); + M_Memcpy(&unit_sideways, res, sizeof(unit_sideways)); + res = VectorMatrixMultiply(unit_sideways, *RotateZMatrix(center->angle)); + M_Memcpy(&unit_sideways, res, sizeof(unit_sideways)); } - if (mobj->movefactor) + if (pos_sideways[3] > mobj->movefactor) { - movefac = dist*mobj->movefactor; - unitoffset[0] = FixedMul(movefac, baseuo[0]); - unitoffset[1] = FixedMul(movefac, baseuo[1]); - unitoffset[2] = FixedMul(movefac, baseuo[2]); + do + { + pos_sideways[0] -= unit_sideways[0]; + pos_sideways[1] -= unit_sideways[1]; + pos_sideways[2] -= unit_sideways[2]; + } + while ((--pos_sideways[3]) != mobj->movefactor); } else - movefac = unitoffset[0] = unitoffset[1] = unitoffset[2] = 0; + { + do + { + pos_sideways[0] += unit_sideways[0]; + pos_sideways[1] += unit_sideways[1]; + pos_sideways[2] += unit_sideways[2]; + } + while ((++pos_sideways[3]) != mobj->movefactor); + } } hnext = mobj->hnext; // just in case the mobj is removed - // Radius of the link's rotation. - mag = (dist * mobj->movecount) + mobj->extravalue1; + if (pos_lengthways[3] > mobj->movecount) + { + do + { + pos_lengthways[0] -= unit_lengthways[0]; + pos_lengthways[1] -= unit_lengthways[1]; + pos_lengthways[2] -= unit_lengthways[2]; + } + while ((--pos_lengthways[3]) != mobj->movecount); + } + else if (pos_lengthways[3] < mobj->movecount) + { + do + { + pos_lengthways[0] += unit_lengthways[0]; + pos_lengthways[1] += unit_lengthways[1]; + pos_lengthways[2] += unit_lengthways[2]; + } + while ((++pos_lengthways[3]) != mobj->movecount); + } - donetwice = false; -maceretry: P_UnsetThingPosition(mobj); mobj->x = center->x; @@ -6301,17 +6330,17 @@ maceretry: mobj->z = center->z; // Add on the appropriate distances to the center's co-ordinates. - if (mag) + if (pos_lengthways[3]) { - mobj->x += FixedMul(unit[0], mag); - mobj->y += FixedMul(unit[1], mag); - zstore = FixedMul(unit[2], mag) + unitoffset[2]; + mobj->x += pos_lengthways[0]; + mobj->y += pos_lengthways[1]; + zstore = pos_lengthways[2] + pos_sideways[2]; } else - zstore = unitoffset[2]; + zstore = pos_sideways[2]; - mobj->x += unitoffset[0]; - mobj->y += unitoffset[1]; + mobj->x += pos_sideways[0]; + mobj->y += pos_sideways[1]; // Cut the height to align the link with the axis. if (mobj->type == MT_SMALLMACECHAIN || mobj->type == MT_BIGMACECHAIN) @@ -6322,41 +6351,40 @@ maceretry: mobj->z += zstore; #if 0 // toaster's testing flashie! - if (!donetwice && mobj->movefactor != -5 && !(leveltime & TICRATE)) // I had a brainfart and the flashing isn't exactly what I expected it to be, but it's actually much more useful. + if (!(mobj->movecount & 1) && !(leveltime & TICRATE)) // I had a brainfart and the flashing isn't exactly what I expected it to be, but it's actually much more useful. mobj->flags2 ^= MF2_DONTDRAW; #endif P_SetThingPosition(mobj); - if (!mag || donetwice || P_MobjWasRemoved(mobj)) +#if 0 // toaster's height-clipping dealie! + if (!pos_lengthways[3] || P_MobjWasRemoved(mobj) || (mobj->flags & MF_NOCLIPHEIGHT)) goto cont; - if (mobj->flags & (MF_NOCLIP|MF_NOCLIPHEIGHT)) - goto cont; - - if ((fa = ((mobj->tracer->threshold & (FINEMASK/2)) << ANGLETOFINESHIFT)) > ANGLE_45 && fa < ANGLE_135) // only move towards center when the motion is towards/away from the ground, rather than alongside it + if ((fa = ((center->threshold & (FINEMASK/2)) << ANGLETOFINESHIFT)) > ANGLE_45 && fa < ANGLE_135) // only move towards center when the motion is towards/away from the ground, rather than alongside it goto cont; if (mobj->subsector->sector->ffloors) P_AdjustMobjFloorZ_FFloors(mobj, mobj->subsector->sector, 2); - // Variable reuse if (mobj->floorz > mobj->z) - dist = (mobj->floorz - mobj->tracer->z); + zstore = (mobj->floorz - zstore); else if (mobj->ceilingz < mobj->z) - dist = (mobj->ceilingz - mobj->tracer->z); + zstore = (mobj->ceilingz - mobj->height - zstore); else goto cont; - if ((dist = FixedDiv(dist, zstore)) > FRACUNIT) - goto cont; + zstore = FixedDiv(zstore, dist); // Still needs work... scaling factor is wrong! - mag = FixedMul(mag, dist); - donetwice = true; - dist = ((mobj->info->speed) ? mobj->info->speed : mobjinfo[MT_SMALLMACECHAIN].speed); - goto maceretry; + P_UnsetThingPosition(mobj); + + mobj->x -= FixedMul(unit_lengthways[0], zstore); + mobj->y -= FixedMul(unit_lengthways[1], zstore); + + P_SetThingPosition(mobj); cont: +#endif mobj = hnext; } } @@ -9771,7 +9799,7 @@ void P_SpawnMapThing(mapthing_t *mthing) case MT_FIREBARPOINT: case MT_CUSTOMMACEPOINT: { - fixed_t mlength, mmaxlength, mlengthset, mspeed, mphase, myaw, mpitch, mminlength, mnumspokes, mpinch, mroll, mnumnospokes, mwidth, mwidthset, mmin, msound, radiusfactor; + fixed_t mlength, mmaxlength, mlengthset, mspeed, mphase, myaw, mpitch, mminlength, mnumspokes, mpinch, mroll, mnumnospokes, mwidth, mwidthset, mmin, msound, radiusfactor, widthfactor; angle_t mspokeangle; mobjtype_t chainlink, macetype, firsttype, linktype; boolean mdosound, mdocenter; @@ -9848,7 +9876,7 @@ ML_EFFECT4 : Don't clip inside the ground if (mnumnospokes > 0 && (mnumnospokes < mnumspokes)) mnumnospokes = mnumspokes/mnumnospokes; else - mnumnospokes = ((mobj->type == MT_CHAINMACEPOINT) ? (mnumspokes - 1) : 0); + mnumnospokes = ((mobj->type == MT_CHAINMACEPOINT) ? (mnumspokes) : 0); mobj->lastlook = mspeed; mobj->movecount = mobj->lastlook; @@ -9894,7 +9922,7 @@ ML_EFFECT4 : Don't clip inside the ground break; } - if (!macetype) + if (!macetype && !chainlink) break; if (mobj->type != MT_CHAINPOINT) @@ -9958,7 +9986,7 @@ ML_EFFECT4 : Don't clip inside the ground } mdosound = (mspeed && !(mthing->options & MTF_OBJECTSPECIAL)); - mdocenter = (lines[line].flags & ML_EFFECT3); + mdocenter = (macetype && (lines[line].flags & ML_EFFECT3)); // The actual spawning of spokes while (mnumspokes-- > 0) @@ -9999,6 +10027,7 @@ ML_EFFECT4 : Don't clip inside the ground mmaxlength = mlength; } + widthfactor = ((firsttype == chainlink) ? 1 : 2); mwidthset = mwidth; //fixed_t base = 0; @@ -10009,11 +10038,18 @@ ML_EFFECT4 : Don't clip inside the ground //base = mlengthset*((mobjinfo[macetype].speed) ? mobjinfo[macetype].speed : mobjinfo[MT_SMALLMACECHAIN].speed); - while ((++mlengthset) < mmaxlength) - makemace(linktype, radiusfactor*mlengthset, 0); + // Out from the center... + if (linktype) + { + while ((++mlengthset) < mmaxlength) + makemace(linktype, radiusfactor*mlengthset, 0); + } + else + mlengthset = mmaxlength; // Outermost mace/link - makemace(firsttype, radiusfactor*mlengthset, MF2_AMBUSH); + if (firsttype) + makemace(firsttype, radiusfactor*mlengthset, MF2_AMBUSH); if (!mwidth) { @@ -10022,18 +10058,37 @@ ML_EFFECT4 : Don't clip inside the ground } else { - while ((mwidthset -= ((firsttype == chainlink) ? 1 : 2)) > -mwidth) + // Across the bar! + if (!firsttype) + mwidthset = -mwidth; + else if (mwidth > 0) { - makemace(firsttype, radiusfactor*mlengthset, MF2_AMBUSH); - if (mdosound && (mwidthset == msound) && mnumspokes <= mmin) // Can it make a sound? - spawnee->flags2 |= MF2_BOSSNOTRAP; + while ((mwidthset -= widthfactor) > -mwidth) + { + makemace(firsttype, radiusfactor*mlengthset, MF2_AMBUSH); + if (mdosound && (mwidthset == msound) && mnumspokes <= mmin) // Can it make a sound? + spawnee->flags2 |= MF2_BOSSNOTRAP; + } } + else + { + while ((mwidthset += widthfactor) < -mwidth) + { + makemace(firsttype, radiusfactor*mlengthset, MF2_AMBUSH); + if (mdosound && (mwidthset == msound) && mnumspokes <= mmin) // Can it make a sound? + spawnee->flags2 |= MF2_BOSSNOTRAP; + } + } + mwidth = -mwidth; // Outermost mace/link again! - makemace(firsttype, radiusfactor*(mlengthset--), MF2_AMBUSH); + if (firsttype) + makemace(firsttype, radiusfactor*(mlengthset--), MF2_AMBUSH); - while (mlengthset > mminlength) - makemace(linktype, radiusfactor*(mlengthset--), 0); + // ...and then back into the center! + if (linktype) + while (mlengthset > mminlength) + makemace(linktype, radiusfactor*(mlengthset--), 0); if (mdocenter) // Innermost mace/link makemace(macetype, 0, 0); From 4f3f647f5b31266445307a470a3f771bfe567721 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Tue, 3 Apr 2018 01:46:42 +0100 Subject: [PATCH 7/8] A minor assortment of changes. --- src/p_inter.c | 6 +++--- src/p_mobj.c | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/p_inter.c b/src/p_inter.c index 82187f533..88fa7d57b 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -1503,10 +1503,10 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) if (player->powers[pw_flashing]) return; - if (special->movefactor && special->tracer && (angle_t)special->tracer->angle != ANGLE_90 && (angle_t)special->tracer->angle != ANGLE_270) + if (special->movefactor && special->tracer && special->tracer->angle != ANGLE_90 && special->tracer->angle != ANGLE_270) { // I don't expect you to understand this, Mr Bond... - angle_t ang = R_PointToAngle2(special->x, special->y, toucher->x, toucher->y) - special->tracer->threshold; - if ((special->movefactor > 0) == ((angle_t)special->tracer->angle > ANGLE_90 && (angle_t)special->tracer->angle < ANGLE_270)) + angle_t ang = R_PointToAngle2(special->x, special->y, toucher->x, toucher->y) - special->tracer->angle; + if ((special->movefactor > 0) == (special->tracer->angle > ANGLE_90 && special->tracer->angle < ANGLE_270)) ang += ANGLE_180; if (ang < ANGLE_180) return; // I expect you to die. diff --git a/src/p_mobj.c b/src/p_mobj.c index 286357964..3660f1e5e 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -9959,6 +9959,8 @@ ML_EFFECT4 : Don't clip inside the ground else radiusfactor = (((linktype = chainlink) == MT_NULL) ? 2 : 1); + widthfactor = ((firsttype == chainlink) ? 1 : 2); + mflagsapply = ((lines[line].flags & ML_EFFECT4) ? 0 : (MF_NOCLIP|MF_NOCLIPHEIGHT)); mflags2apply = ((mthing->options & MTF_OBJECTFLIP) ? MF2_OBJECTFLIP : 0); meflagsapply = ((mthing->options & MTF_OBJECTFLIP) ? MFE_VERTICALFLIP : 0); @@ -10004,7 +10006,7 @@ ML_EFFECT4 : Don't clip inside the ground firsttype = linktype = chainlink; mmaxlength = 1 + (mlength - 1)*radiusfactor; - radiusfactor = 1; + radiusfactor = widthfactor = 1; } else { @@ -10023,21 +10025,18 @@ ML_EFFECT4 : Don't clip inside the ground } firsttype = macetype; + widthfactor = 2; } mmaxlength = mlength; } - widthfactor = ((firsttype == chainlink) ? 1 : 2); mwidthset = mwidth; - //fixed_t base = 0; mlengthset = mminlength; if (mdocenter) // Innermost mace/link makemace(macetype, 0, 0); - //base = mlengthset*((mobjinfo[macetype].speed) ? mobjinfo[macetype].speed : mobjinfo[MT_SMALLMACECHAIN].speed); - // Out from the center... if (linktype) { From 790e334d19692498466ca2ce30fdd1cc8fc817fa Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Sat, 7 Apr 2018 23:10:34 +0100 Subject: [PATCH 8/8] comment goof --- src/p_mobj.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/p_mobj.h b/src/p_mobj.h index ec25855d8..f6ebd3cad 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -194,6 +194,7 @@ typedef enum MF2_AMBUSH = 1<<27, // Alternate behaviour typically set by MTF_AMBUSH MF2_LINKDRAW = 1<<28, // Draw vissprite of mobj immediately before/after tracer's vissprite (dependent on dispoffset and position) MF2_SHIELD = 1<<29, // Thinker calls P_AddShield/P_ShieldLook (must be partnered with MF_SCENERY to use) + // free: to and including 1<<31 } mobjflag2_t; typedef enum