From f81aada04116c76864ba7918ca7644552dd3a36d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 31 Aug 2022 00:41:34 +0200 Subject: [PATCH] - lightened the number of references to user.change by 1/3rd The less, the better for refactoring --- source/games/sw/src/game.h | 7 +++ source/games/sw/src/jweapon.cpp | 81 ++++++++++++--------------- source/games/sw/src/weapon.cpp | 98 ++++++++++++++++----------------- 3 files changed, 89 insertions(+), 97 deletions(-) diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 5d755391a..3dc927074 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -940,6 +940,13 @@ struct USER int int_ceiling_dist() const { return ceiling_dist * zworldtoint; } int int_floor_dist() const { return floor_dist * zworldtoint; } + + // frequently repeated patterns + void clearChange() { change.X = change.Y = change.Z = 0; } + void clearChangeXY() { change.X = change.Y = 0; } + void addCounterToChange() { change.Z += Counter; } + void invertChangeZ() { change.Z = -change.Z; } + // // Variables that can be used by actors and Player diff --git a/source/games/sw/src/jweapon.cpp b/source/games/sw/src/jweapon.cpp index c00d384fd..106989525 100644 --- a/source/games/sw/src/jweapon.cpp +++ b/source/games/sw/src/jweapon.cpp @@ -305,9 +305,7 @@ void SpawnMidSplash(DSWActor* actor) if (RANDOM_P2(1024) < 512) actorNew->spr.cstat |= (CSTAT_SPRITE_XFLIP); - actorNew->user.change.X = 0; - actorNew->user.change.Y = 0; - actorNew->user.change.Z = 0; + actorNew->user.clearChange(); if (actor->user.Flags & (SPR_UNDERWATER)) actorNew->user.Flags |= (SPR_UNDERWATER); @@ -327,9 +325,7 @@ void SpawnFloorSplash(DSWActor* actor) if (RANDOM_P2(1024) < 512) actorNew->spr.cstat |= (CSTAT_SPRITE_XFLIP); - actorNew->user.change.X = 0; - actorNew->user.change.Y = 0; - actorNew->user.change.Z = 0; + actorNew->user.clearChange(); if (actor->user.Flags & (SPR_UNDERWATER)) actorNew->user.Flags |= (SPR_UNDERWATER); @@ -345,12 +341,12 @@ int DoBloodSpray(DSWActor* actor) ScaleSpriteVector(actor, 50000); actor->user.Counter += 20; // These are STAT_SKIIP4 now, so * 2 - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); } else { actor->user.Counter += 20; - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); } if (actor->spr.xvel <= 2) @@ -398,7 +394,7 @@ int DoBloodSpray(DSWActor* actor) } else { - actor->user.change.X = actor->user.change.Y = 0; + actor->user.clearChangeXY(); SpawnMidSplash(actor); QueueWallBlood(actor, hitActor->int_ang()); KillActor(actor); @@ -442,7 +438,8 @@ int DoBloodSpray(DSWActor* actor) return 0; } - actor->spr.xvel = actor->spr.yvel = actor->user.change.X = actor->user.change.Y = 0; + actor->spr.xvel = actor->spr.yvel = 0; + actor->user.clearChangeXY(); actor->spr.xrepeat = actor->spr.yrepeat = 70 - RandomRange(25); actor->spr.pos.XY() = bldActor->spr.pos.XY(); @@ -491,7 +488,7 @@ int DoBloodSpray(DSWActor* actor) else #endif { - actor->user.change.X = actor->user.change.Y = 0; + actor->user.clearChangeXY(); SpawnFloorSplash(actor); KillActor(actor); return true; @@ -500,7 +497,7 @@ int DoBloodSpray(DSWActor* actor) else // hit something above { - actor->user.change.Z = -actor->user.change.Z; + actor->user.invertChangeZ(); ScaleSpriteVector(actor, 32000); // was 22000 } break; @@ -529,9 +526,7 @@ int DoBloodSpray(DSWActor* actor) if (RANDOM_P2(1024) < 512) actorNew->spr.cstat |= (CSTAT_SPRITE_YFLIP); - actorNew->user.change.X = actor->user.change.X; - actorNew->user.change.Y = actor->user.change.Y; - actorNew->user.change.Z = actor->user.change.Z; + actorNew->user.change = actor->user.change; ScaleSpriteVector(actorNew, 20000); @@ -550,12 +545,12 @@ int DoPhosphorus(DSWActor* actor) ScaleSpriteVector(actor, 50000); actor->user.Counter += 20*2; - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); } else { actor->user.Counter += 20*2; - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); } actor->user.coll = move_missile(actor, actor->user.change.X, actor->user.change.Y, actor->user.change.Z, @@ -595,7 +590,7 @@ int DoPhosphorus(DSWActor* actor) SpawnFireballFlames(actor, hitActor); DoFlamesDamageTest(actor); } - actor->user.change.X = actor->user.change.Y = 0; + actor->user.clearChangeXY(); KillActor(actor); return true; } @@ -654,7 +649,7 @@ int DoPhosphorus(DSWActor* actor) } else { - actor->user.change.X = actor->user.change.Y = 0; + actor->user.clearChangeXY(); SpawnFireballExp(actor); KillActor(actor); return true; @@ -685,13 +680,13 @@ int DoPhosphorus(DSWActor* actor) actor->user.Flags |= (SPR_BOUNCE); actor->user.coll.setNone(); actor->user.Counter = 0; - actor->user.change.Z = -actor->user.change.Z; + actor->user.invertChangeZ(); ScaleSpriteVector(actor, 32000); // Was 18000 actor->user.change.Z /= 6; } else { - actor->user.change.X = actor->user.change.Y = 0; + actor->user.clearChangeXY(); SpawnFireballExp(actor); KillActor(actor); return true; @@ -700,7 +695,7 @@ int DoPhosphorus(DSWActor* actor) else // hit something above { - actor->user.change.Z = -actor->user.change.Z; + actor->user.invertChangeZ(); ScaleSpriteVector(actor, 32000); // was 22000 } } @@ -731,9 +726,7 @@ int DoPhosphorus(DSWActor* actor) if (RANDOM_P2(1024) < 512) actorNew->spr.cstat |= (CSTAT_SPRITE_YFLIP); - actorNew->user.change.X = actor->user.change.X; - actorNew->user.change.Y = actor->user.change.Y; - actorNew->user.change.Z = actor->user.change.Z; + actorNew->user.change = actor->user.change; actorNew->user.spal = actorNew->spr.pal = PALETTE_PLAYER3; // RED @@ -753,12 +746,12 @@ int DoChemBomb(DSWActor* actor) ScaleSpriteVector(actor, 50000); actor->user.Counter += 20; - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); } else { actor->user.Counter += 20; - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); } actor->user.coll = move_missile(actor, actor->user.change.X, actor->user.change.Y, actor->user.change.Z, @@ -798,7 +791,7 @@ int DoChemBomb(DSWActor* actor) PlaySound(DIGI_GASPOP, actor, v3df_dontpan | v3df_doppler); PlaySound(DIGI_CHEMGAS, actor, v3df_dontpan | v3df_doppler); } - actor->user.change.X = actor->user.change.Y = 0; + actor->user.clearChangeXY(); actor->user.WaitTics -= (MISSILEMOVETICS * 2); if (actor->user.WaitTics <= 0) KillActor(actor); @@ -868,7 +861,7 @@ int DoChemBomb(DSWActor* actor) PlaySound(DIGI_CHEMGAS, actor, v3df_dontpan | v3df_doppler); } SpawnRadiationCloud(actor); - actor->user.change.X = actor->user.change.Y = 0; + actor->user.clearChangeXY(); actor->user.WaitTics -= (MISSILEMOVETICS * 2); if (actor->user.WaitTics <= 0) KillActor(actor); @@ -902,7 +895,7 @@ int DoChemBomb(DSWActor* actor) actor->user.Flags |= (SPR_BOUNCE); actor->user.coll.setNone(); actor->user.Counter = 0; - actor->user.change.Z = -actor->user.change.Z; + actor->user.invertChangeZ(); ScaleSpriteVector(actor, 32000); // Was 18000 actor->user.change.Z /= 6; } @@ -915,7 +908,7 @@ int DoChemBomb(DSWActor* actor) PlaySound(DIGI_CHEMGAS, actor, v3df_dontpan | v3df_doppler); } SpawnRadiationCloud(actor); - actor->user.change.X = actor->user.change.Y = 0; + actor->user.clearChangeXY(); actor->user.WaitTics -= (MISSILEMOVETICS * 2); if (actor->user.WaitTics <= 0) KillActor(actor); @@ -925,7 +918,7 @@ int DoChemBomb(DSWActor* actor) else // hit something above { - actor->user.change.Z = -actor->user.change.Z; + actor->user.invertChangeZ(); ScaleSpriteVector(actor, 32000); // was 22000 } } @@ -949,10 +942,8 @@ int DoChemBomb(DSWActor* actor) // actorNew->spr.cstat |= (CSTAT_SPRITE_YCENTER|CSTAT_SPRITE_TRANSLUCENT); actorNew->spr.cstat &= ~(CSTAT_SPRITE_BLOCK | CSTAT_SPRITE_BLOCK_HITSCAN); - actorNew->user.change.X = actor->user.change.X; - actorNew->user.change.Y = actor->user.change.Y; - actorNew->user.change.Z = actor->user.change.Z; - + actorNew->user.change = actor->user.change; + actorNew->user.spal = actorNew->spr.pal = PALETTE_PLAYER6; ScaleSpriteVector(actorNew, 20000); @@ -981,12 +972,12 @@ int DoCaltrops(DSWActor* actor) ScaleSpriteVector(actor, 50000); actor->user.Counter += 20; - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); } else { actor->user.Counter += 70; - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); } actor->user.coll = move_missile(actor, actor->user.change.X, actor->user.change.Y, actor->user.change.Z, @@ -1017,7 +1008,7 @@ int DoCaltrops(DSWActor* actor) else { // fall to the ground - actor->user.change.X = actor->user.change.Y = 0; + actor->user.clearChangeXY(); } @@ -1073,7 +1064,7 @@ int DoCaltrops(DSWActor* actor) } else { - actor->user.change.X = actor->user.change.Y = 0; + actor->user.clearChangeXY(); actor->spr.extra |= (SPRX_BREAKABLE); actor->spr.cstat |= (CSTAT_SPRITE_BREAKABLE); ChangeState(actor, s_CaltropsStick); @@ -1106,12 +1097,12 @@ int DoCaltrops(DSWActor* actor) actor->user.Flags |= (SPR_BOUNCE); actor->user.coll.setNone(); actor->user.Counter = 0; - actor->user.change.Z = -actor->user.change.Z; + actor->user.invertChangeZ(); ScaleSpriteVector(actor, 1000); // Was 18000 } else { - actor->user.change.X = actor->user.change.Y = 0; + actor->user.clearChangeXY(); actor->spr.extra |= (SPRX_BREAKABLE); actor->spr.cstat |= (CSTAT_SPRITE_BREAKABLE); ChangeState(actor, s_CaltropsStick); @@ -1121,7 +1112,7 @@ int DoCaltrops(DSWActor* actor) else // hit something above { - actor->user.change.Z = -actor->user.change.Z; + actor->user.invertChangeZ(); ScaleSpriteVector(actor, 1000); // was 22000 } } @@ -1359,9 +1350,7 @@ int InitChemBomb(DSWActor* actor) if (actor->user.ID == MUSHROOM_CLOUD || actor->user.ID == 3121 || actor->user.ID == SUMO_RUN_R0) // 3121 == GRENADE_EXP { - actorNew->user.change.X = 0; - actorNew->user.change.Y = 0; - actorNew->user.change.Z = 0; + actorNew->user.clearChange(); actorNew->spr.xvel = actorNew->spr.yvel = actorNew->spr.zvel = 0; // Smoke will come out for this many seconds actorNew->user.WaitTics = 40*120; diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index 4521e9893..bf3b88636 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -56,6 +56,10 @@ void SpawnZombie2(DSWActor*); Collision move_ground_missile(DSWActor* actor, int xchange, int ychange, int ceildist, int flordist, uint32_t cliptype, int numtics); void DoPlayerBeginDie(PLAYER*); void VehicleSetSmoke(SECTOR_OBJECT* sop, ANIMATOR* animator); + +void ScaleSpriteVector(DSWActor* actor, int scalex, int scaley, int scalez); +void ScaleSpriteVector(DSWActor* actor, int scale); + ANIMATOR DoBettyBeginDeath; ANIMATOR DoSkullBeginDeath; ANIMATOR DoRipperGrow; @@ -7416,7 +7420,7 @@ int DoStar(DSWActor* actor) if (vel < 800) { actor->user.Counter += 50; - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); } } @@ -7512,13 +7516,12 @@ int DoStar(DSWActor* actor) break; // will be killed below - actor != 0 // 32000 to 96000 - actor->user.change.X = MulScale(actor->user.change.X, 64000 + (RandomRange(64000) - 32000), 16); - actor->user.change.Y = MulScale(actor->user.change.Y, 64000 + (RandomRange(64000) - 32000), 16); - - if (actor->spr.pos.Z > ((actor->user.hiz + actor->user.loz) * 0.5)) - actor->user.change.Z = MulScale(actor->user.change.Z, 50000, 16); // floor - else - actor->user.change.Z = MulScale(actor->user.change.Z, 40000, 16); // ceiling + int xscale = 64000 + (RandomRange(64000) - 32000); + int yscale = 64000 + (RandomRange(64000) - 32000); + int zscale; + if (actor->spr.pos.Z > ((actor->user.hiz + actor->user.loz) * 0.5)) zscale = 50000; // floor + else zscale = 40000; // ceiling + ScaleSpriteVector(actor, xscale, yscale, zscale); if (SlopeBounce(actor, &did_hit_wall)) { @@ -7552,16 +7555,14 @@ int DoStar(DSWActor* actor) actor->user.Flags |= (SPR_BOUNCE); actor->user.motion_blur_num = 0; actor->user.coll.setNone(); - actor->user.change.Z = -actor->user.change.Z; + actor->user.invertChangeZ(); // 32000 to 96000 - actor->user.change.X = MulScale(actor->user.change.X, 64000 + (RandomRange(64000) - 32000), 16); - actor->user.change.Y = MulScale(actor->user.change.Y, 64000 + (RandomRange(64000) - 32000), 16); - if (actor->spr.pos.Z > ((actor->user.hiz + actor->user.loz) * 0.5)) - actor->user.change.Z = MulScale(actor->user.change.Z, 50000, 16); // floor - else - actor->user.change.Z = MulScale(actor->user.change.Z, 40000, 16); // ceiling - + xscale = 64000 + (RandomRange(64000) - 32000); + yscale = 64000 + (RandomRange(64000) - 32000); + if (actor->spr.pos.Z > ((actor->user.hiz + actor->user.loz) * 0.5)) zscale = 50000; // floor + else zscale = 40000; // ceiling + ScaleSpriteVector(actor, xscale, yscale, zscale); break; } } @@ -8087,11 +8088,16 @@ int DoEelFire(DSWActor* actor) } +void ScaleSpriteVector(DSWActor* actor, int scalex, int scaley, int scalez) +{ + actor->user.change.X = MulScale(actor->user.change.X, scalex, 16); + actor->user.change.Y = MulScale(actor->user.change.Y, scaley, 16); + actor->user.change.Z = MulScale(actor->user.change.Z, scalez, 16); +} + void ScaleSpriteVector(DSWActor* actor, int scale) { - actor->user.change.X = MulScale(actor->user.change.X, scale, 16); - actor->user.change.Y = MulScale(actor->user.change.Y, scale, 16); - actor->user.change.Z = MulScale(actor->user.change.Z, scale, 16); + ScaleSpriteVector(actor, scale, scale, scale); } void WallBounce(DSWActor* actor, short ang) @@ -8202,12 +8208,12 @@ int DoGrenade(DSWActor* actor) ScaleSpriteVector(actor, 50000); actor->user.Counter += 20; - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); } else { actor->user.Counter += 20; - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); } actor->user.coll = move_missile(actor, actor->user.change.X, actor->user.change.Y, actor->user.change.Z, @@ -8354,7 +8360,7 @@ int DoGrenade(DSWActor* actor) actor->user.Flags |= (SPR_BOUNCE); actor->user.coll.setNone(); actor->user.Counter = 0; - actor->user.change.Z = -actor->user.change.Z; + actor->user.invertChangeZ(); ScaleSpriteVector(actor, 40000); // 18000 actor->user.change.Z /= 4; PlaySound(DIGI_40MMBNCE, actor, v3df_dontpan); @@ -8377,7 +8383,7 @@ int DoGrenade(DSWActor* actor) else // hit something above { - actor->user.change.Z = -actor->user.change.Z; + actor->user.invertChangeZ(); ScaleSpriteVector(actor, 22000); PlaySound(DIGI_40MMBNCE, actor, v3df_dontpan); } @@ -8422,7 +8428,7 @@ int DoGrenade(DSWActor* actor) int DoVulcanBoulder(DSWActor* actor) { actor->user.Counter += 40; - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); actor->user.coll = move_missile(actor, actor->user.change.X, actor->user.change.Y, actor->user.change.Z, actor->user.int_ceiling_dist(), actor->user.int_floor_dist(), CLIPMASK_MISSILE, MISSILEMOVETICS); @@ -8505,9 +8511,7 @@ int DoVulcanBoulder(DSWActor* actor) if (actor->spr.pos.Z > ((actor->user.hiz + actor->user.loz) * 0.5)) { // hit a floor - actor->user.change.X = MulScale(actor->user.change.X, 30000, 16); - actor->user.change.Y = MulScale(actor->user.change.Y, 30000, 16); - actor->user.change.Z = MulScale(actor->user.change.Z, 12000, 16); + ScaleSpriteVector(actor, 30000, 30000, 12000); actor->user.coll.setNone(); actor->user.Counter = 0; @@ -8532,21 +8536,19 @@ int DoVulcanBoulder(DSWActor* actor) actor->user.coll.setNone(); actor->user.Counter = 0; - actor->user.change.X = MulScale(actor->user.change.X, 20000, 16); - actor->user.change.Y = MulScale(actor->user.change.Y, 20000, 16); - actor->user.change.Z = MulScale(actor->user.change.Z, 32000, 16); + ScaleSpriteVector(actor, 20000, 20000, 32000); // limit to a reasonable bounce value if (actor->user.change.Z > Z(24)) actor->user.change.Z = Z(24); - actor->user.change.Z = -actor->user.change.Z; + actor->user.invertChangeZ(); } else // hit unsloped ceiling { - actor->user.change.Z = -actor->user.change.Z; + actor->user.invertChangeZ(); ScaleSpriteVector(actor, 30000); } } @@ -8782,13 +8784,13 @@ int DoMine(DSWActor* actor) ScaleSpriteVector(actor, 50000); actor->user.Counter += 20; - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); } else { //actor->user.Counter += 75; actor->user.Counter += 40; - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); } actor->user.coll = move_missile(actor, actor->user.change.X, actor->user.change.Y, actor->user.change.Z, @@ -9249,9 +9251,7 @@ int DoRail(DSWActor* actor) actorNew->spr.cstat |= (CSTAT_SPRITE_YCENTER); actorNew->spr.cstat &= ~(CSTAT_SPRITE_BLOCK|CSTAT_SPRITE_BLOCK_HITSCAN); - actorNew->user.change.X = actor->user.change.X; - actorNew->user.change.Y = actor->user.change.Y; - actorNew->user.change.Z = actor->user.change.Z; + actorNew->user.change = actor->user.change; ScaleSpriteVector(actorNew, 1500); @@ -9342,9 +9342,7 @@ int DoRocket(DSWActor* actor) actorNew->spr.cstat |= (CSTAT_SPRITE_YCENTER); actorNew->spr.cstat &= ~(CSTAT_SPRITE_BLOCK|CSTAT_SPRITE_BLOCK_HITSCAN); - actorNew->user.change.X = actor->user.change.X; - actorNew->user.change.Y = actor->user.change.Y; - actorNew->user.change.Z = actor->user.change.Z; + actorNew->user.change = actor->user.change; ScaleSpriteVector(actorNew, 20000); @@ -9431,9 +9429,7 @@ int DoMicro(DSWActor* actor) actorNew->spr.cstat |= (CSTAT_SPRITE_YCENTER); actorNew->spr.cstat &= ~(CSTAT_SPRITE_BLOCK|CSTAT_SPRITE_BLOCK_HITSCAN); - actorNew->user.change.X = actor->user.change.X; - actorNew->user.change.Y = actor->user.change.Y; - actorNew->user.change.Z = actor->user.change.Z; + actorNew->user.change = actor->user.change; ScaleSpriteVector(actorNew, 20000); @@ -17714,12 +17710,12 @@ int DoShrapVelocity(DSWActor* actor) ScaleSpriteVector(actor, 20000); actor->user.Counter += 8*4; // These are MoveSkip4 now - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); } else { actor->user.Counter += 60*4; - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); } actor->user.coll = move_missile(actor, actor->user.change.X, actor->user.change.Y, actor->user.change.Z, @@ -17814,7 +17810,7 @@ int DoShrapVelocity(DSWActor* actor) actor->user.Flags |= (SPR_BOUNCE); actor->user.coll.setNone(); actor->user.Counter = 0; - actor->user.change.Z = -actor->user.change.Z; + actor->user.invertChangeZ(); ScaleSpriteVector(actor, 18000); switch (actor->user.ID) { @@ -17838,7 +17834,7 @@ int DoShrapVelocity(DSWActor* actor) else // hit something above { - actor->user.change.Z = -actor->user.change.Z; + actor->user.invertChangeZ(); ScaleSpriteVector(actor, 22000); } } @@ -18026,12 +18022,12 @@ int DoItemFly(DSWActor* actor) ScaleSpriteVector(actor, 50000); actor->user.Counter += 20*2; - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); } else { actor->user.Counter += 60*2; - actor->user.change.Z += actor->user.Counter; + actor->user.addCounterToChange(); } actor->user.coll = move_missile(actor, actor->user.change.X, actor->user.change.Y, actor->user.change.Z, @@ -18078,13 +18074,13 @@ int DoItemFly(DSWActor* actor) actor->spr.pos.Z = actor->user.loz; actor->user.Counter = 0; actor->spr.xvel = 0; - actor->user.change.Z = actor->user.change.X = actor->user.change.Y = 0; + actor->user.clearChange(); return false; } else // hit something above { - actor->user.change.Z = -actor->user.change.Z; + actor->user.invertChangeZ(); ScaleSpriteVector(actor, 22000); } break;