diff --git a/source/games/sw/src/ai.cpp b/source/games/sw/src/ai.cpp index 95f0efa63..965845759 100644 --- a/source/games/sw/src/ai.cpp +++ b/source/games/sw/src/ai.cpp @@ -63,7 +63,7 @@ int Distance(int x1, int y1, int x2, int y2) else min = x2; - return x2 + y2 - DIV2(min); + return x2 + y2 - (min >> 1); } @@ -119,7 +119,7 @@ void DoActorSetSpeed(DSWActor* actor, uint8_t speed) actor->user.speed = speed; if (ActorFlaming(actor)) - actor->spr.xvel = actor->user.Attrib->Speed[speed] + DIV2(actor->user.Attrib->Speed[speed]); + actor->spr.xvel = actor->user.Attrib->Speed[speed] + (actor->user.Attrib->Speed[speed] >> 1); else actor->spr.xvel = actor->user.Attrib->Speed[speed]; } @@ -233,7 +233,7 @@ int CanHitPlayer(DSWActor* actor) // if actor can still see the player int zhs, zhh; - zhs = actor->spr.pos.Z - DIV2(ActorSizeZ(actor)); + zhs = actor->spr.pos.Z - (ActorSizeZ(actor) >> 1); auto targ = actor->user.targetActor; @@ -434,7 +434,7 @@ int DoActorOperate(DSWActor* actor) return false; z[0] = actor->spr.pos.Z - ActorSizeZ(actor) + Z(5); - z[1] = actor->spr.pos.Z - DIV2(ActorSizeZ(actor)); + z[1] = actor->spr.pos.Z - (ActorSizeZ(actor) >> 1); for (i = 0; i < SIZ(z); i++) { diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 9c7372ae1..ea7e1871c 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -953,8 +953,8 @@ void CircleCamera(int *nx, int *ny, int *nz, sectortype** vsect, binangle *nang, vy = -ang.bsin(-4); // lengthen the vector some - vx += DIV2(vx); - vy += DIV2(vy); + vx += vx >> 1; + vy += vy >> 1; vz = q16horiz >> 8; diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 30a370113..b3f854e9a 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -122,6 +122,7 @@ inline int RANDOM(void) return randomseed; } +#define MOD_P2(number,modby) ((number) & ((modby)-1)) #define RANDOM_P2(pwr_of_2) (MOD_P2(RANDOM(),(pwr_of_2))) // @@ -195,6 +196,7 @@ inline int32_t FIXED(int32_t msw, int32_t lsw) #define NORM_Q16ANGLE(ang) ((ang) & 0x7FFFFFF) int StdRandomRange(int range); + #define STD_RANDOM_P2(pwr_of_2) (MOD_P2(rand(),(pwr_of_2))) #define RANDOM_NEG(x,y) ((RANDOM_P2(((x)<<(y))<<1) - (x))<<(y)) diff --git a/source/games/sw/src/jweapon.cpp b/source/games/sw/src/jweapon.cpp index 7849784b7..663dc21e1 100644 --- a/source/games/sw/src/jweapon.cpp +++ b/source/games/sw/src/jweapon.cpp @@ -2213,7 +2213,7 @@ int SpawnShell(DSWActor* actor, int ShellNum) HelpMissileLateral(actorNew,1500); actorNew->spr.ang = NORM_ANGLE(actorNew->spr.ang-128); } - actorNew->spr.ang += (RANDOM_P2(128<<5)>>5) - DIV2(128); + actorNew->spr.ang += (RANDOM_P2(128<<5)>>5) - (128 / 2); actorNew->spr.ang = NORM_ANGLE(actorNew->spr.ang); // Set the shell number @@ -2227,7 +2227,7 @@ int SpawnShell(DSWActor* actor, int ShellNum) actorNew->spr.ang = NORM_ANGLE(actorNew->spr.ang+512); HelpMissileLateral(actorNew,1300); actorNew->spr.ang = NORM_ANGLE(actorNew->spr.ang-128-64); - actorNew->spr.ang += (RANDOM_P2(128<<5)>>5) - DIV2(128); + actorNew->spr.ang += (RANDOM_P2(128<<5)>>5) - (128 / 2); actorNew->spr.ang = NORM_ANGLE(actorNew->spr.ang); // Set the shell number diff --git a/source/games/sw/src/mytypes.h b/source/games/sw/src/mytypes.h index 3a0390a6b..3b1105932 100644 --- a/source/games/sw/src/mytypes.h +++ b/source/games/sw/src/mytypes.h @@ -34,19 +34,6 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms #define ON 1 -/* -=========================== -= -= FAST calculations -= -=========================== -*/ - -#define DIV2(x) ((x) >> 1) -#define MOD_P2(number,modby) ((number) & ((modby)-1)) - - - /* =========================== = diff --git a/source/games/sw/src/panel.cpp b/source/games/sw/src/panel.cpp index 3750adfd0..66b3940b4 100644 --- a/source/games/sw/src/panel.cpp +++ b/source/games/sw/src/panel.cpp @@ -6555,7 +6555,6 @@ void pDisplaySprites(PLAYERp pp, double smoothratio) flags |= (RS_TRANS1); } - //shade = overlay_shade = DIV2(pp->cursector->floorshade + pp->cursector->ceilingshade); shade = overlay_shade = floorshade - 10; if (TEST(psp->PlayerP->Flags, PF_VIEW_FROM_OUTSIDE)) diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index bf6283449..d51af7a51 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -1226,7 +1226,7 @@ DSWActor* DoPickTarget(DSWActor* actor, uint32_t max_delta_ang, int skip_targets // gives a value between 0 and 65535 ang_weight = IntToFixed(max_delta_ang - ts->dang)/max_delta_ang; // gives a value between 0 and 65535 - dist_weight = IntToFixed(DIV2(PICK_DIST) - DIV2(ts->dist))/DIV2(PICK_DIST); + dist_weight = IntToFixed((PICK_DIST / 2) - ((ts->dist) >> 1)) / (PICK_DIST / 2); //weighted average ts->weight = (ang_weight + dist_weight*4)/5; @@ -2618,7 +2618,7 @@ void DoPlayerMoveVehicle(PLAYERp pp) if (vel > 13000) { - vec3_t hit_pos = { DIV2(x[0] + x[1]), DIV2(y[0] + y[1]), pp->cursector->floorz - Z(10) }; + vec3_t hit_pos = { (x[0] + x[1]) >> 1, (y[0] + y[1]) >> 1, pp->cursector->floorz - Z(10) }; hitscan(hit_pos, pp->cursector, { MOVEx(256, pp->angle.ang.asbuild()), MOVEy(256, pp->angle.ang.asbuild()), 0 }, diff --git a/source/games/sw/src/sector.cpp b/source/games/sw/src/sector.cpp index f987ff0ae..396234faa 100644 --- a/source/games/sw/src/sector.cpp +++ b/source/games/sw/src/sector.cpp @@ -599,7 +599,7 @@ void SectorMidPoint(sectortype* sectp, int *xmid, int *ymid, int *zmid) *xmid = xsum / (sectp->wallnum); *ymid = ysum / (sectp->wallnum); - *zmid = DIV2(sectp->floorz + sectp->ceilingz); + *zmid = (sectp->floorz + sectp->ceilingz) >> 1; } @@ -2208,7 +2208,7 @@ void PlayerOperateEnv(PLAYERp pp) z[0] = plActor->spr.pos.Z - ActorSizeZ(plActor) - Z(10); z[1] = plActor->spr.pos.Z; - z[2] = DIV2(z[0] + z[1]); + z[2] = (z[0] + z[1]) >> 1; for (unsigned i = 0; i < SIZ(z); i++) { diff --git a/source/games/sw/src/skull.cpp b/source/games/sw/src/skull.cpp index 57248153c..b681f54b1 100644 --- a/source/games/sw/src/skull.cpp +++ b/source/games/sw/src/skull.cpp @@ -408,7 +408,7 @@ int DoSkullBob(DSWActor* actor) actor->user.Counter = (actor->user.Counter + (ACTORMOVETICS << 3) + (ACTORMOVETICS << 1)) & 2047; actor->spr.pos.Z = actor->user.sz + MulScale(SKULL_BOB_AMT, bsin(actor->user.Counter), 14) + - MulScale(DIV2(SKULL_BOB_AMT), bsin(actor->user.Counter), 14); + MulScale((SKULL_BOB_AMT / 2), bsin(actor->user.Counter), 14); return 0; } @@ -785,7 +785,7 @@ int DoBettyBob(DSWActor* actor) actor->user.Counter = (actor->user.Counter + (ACTORMOVETICS << 3) + (ACTORMOVETICS << 1)) & 2047; actor->spr.pos.Z = actor->user.sz + MulScale(BETTY_BOB_AMT, bsin(actor->user.Counter), 14) + - MulScale(DIV2(BETTY_BOB_AMT), bsin(actor->user.Counter), 14); + MulScale((BETTY_BOB_AMT / 2), bsin(actor->user.Counter), 14); return 0; } diff --git a/source/games/sw/src/sprite.cpp b/source/games/sw/src/sprite.cpp index aa1f8261f..f3a73d603 100644 --- a/source/games/sw/src/sprite.cpp +++ b/source/games/sw/src/sprite.cpp @@ -1564,7 +1564,7 @@ void SpriteSetup(void) { // not used yetv getzsofslopeptr(actor->spr.sector(), actor->spr.pos.X, actor->spr.pos.Y, &cz, &fz); - if (actor->spr.pos.Z > DIV2(cz + fz)) + if (actor->spr.pos.Z > ((cz + fz) >> 1)) { // closer to a floor actor->spr.cstat |= (CSTAT_SPRITE_CLOSE_FLOOR); diff --git a/source/games/sw/src/track.cpp b/source/games/sw/src/track.cpp index ec447c28d..42f2b2c5f 100644 --- a/source/games/sw/src/track.cpp +++ b/source/games/sw/src/track.cpp @@ -3133,7 +3133,7 @@ bool ActorTrackDecide(TRACK_POINTp tpoint, DSWActor* actor) actor->spr.ang = tpoint->ang; z[0] = actor->spr.pos.Z - ActorSizeZ(actor) + Z(5); - z[1] = actor->spr.pos.Z - DIV2(ActorSizeZ(actor)); + z[1] = actor->spr.pos.Z - (ActorSizeZ(actor) >> 1); for (i = 0; i < (int)SIZ(z); i++) { diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index 3778c1218..6884d8d1e 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -3639,14 +3639,14 @@ AutoShrap: hz[Z_TOP] = ActorZOfTop(parentActor); // top hz[Z_BOT] = ActorZOfBottom(parentActor); // bottom - hz[Z_MID] = DIV2(hz[0] + hz[2]); // mid + hz[Z_MID] = (hz[0] + hz[2]) >> 1; // mid for (; p->id; p++) { if (!p->random_disperse) { //dang = (2048 / p->num); - start_ang = NORM_ANGLE(shrap_ang - DIV2(p->ang_range)); + start_ang = NORM_ANGLE(shrap_ang - (p->ang_range >> 1)); dang = (p->ang_range / p->num); } @@ -3657,7 +3657,7 @@ AutoShrap: if (p->random_disperse) { - actor->spr.ang = shrap_ang + (RANDOM_P2(p->ang_range<<5)>>5) - DIV2(p->ang_range); + actor->spr.ang = shrap_ang + (RANDOM_P2(p->ang_range<<5)>>5) - (p->ang_range >> 1); actor->spr.ang = NORM_ANGLE(actor->spr.ang); } else @@ -4064,7 +4064,7 @@ int SpawnBlood(DSWActor* actor, DSWActor* weapActor, short hit_ang, int hit_x, i { if (!p->random_disperse) { - start_ang = NORM_ANGLE(hit_ang - DIV2(p->ang_range)+1024); + start_ang = NORM_ANGLE(hit_ang - (p->ang_range >> 1) + 1024); dang = (p->ang_range / p->num); } @@ -4097,7 +4097,7 @@ int SpawnBlood(DSWActor* actor, DSWActor* weapActor, short hit_ang, int hit_x, i if (p->random_disperse) { - actorNew->spr.ang = hit_ang + (RANDOM_P2(p->ang_range<<5)>>5) - DIV2(p->ang_range); + actorNew->spr.ang = hit_ang + (RANDOM_P2(p->ang_range<<5)>>5) - (p->ang_range >> 1); actorNew->spr.ang = NORM_ANGLE(actorNew->spr.ang); } else @@ -8142,7 +8142,7 @@ bool SlopeBounce(DSWActor* actor, bool *hit_wall) getzsofslopeptr(hit_sector, actor->spr.pos.X, actor->spr.pos.Y, &hiz, &loz); // detect the ceiling and the hit_wall - if (actor->spr.pos.Z < DIV2(hiz+loz)) + if (actor->spr.pos.Z < ((hiz+loz) >> 1)) { if (!TEST(hit_sector->ceilingstat, CSTAT_SECTOR_SLOPE)) slope = 0; @@ -11250,7 +11250,7 @@ void InitSpellRing(PLAYERp pp) ang_diff = 2048 / max_missiles; - ang_start = NORM_ANGLE(pp->angle.ang.asbuild() - DIV2(2048)); + ang_start = NORM_ANGLE(pp->angle.ang.asbuild() - (2048 / 2)); if (!SW_SHAREWARE) PlaySound(DIGI_RFWIZ, pp, v3df_none); @@ -11378,7 +11378,7 @@ int DoSerpRing(DSWActor* actor) actor->user.ID = SKULL_R0; actor->spr.ang = getangle(actor->user.targetActor->spr.pos.X - actor->spr.pos.X, actor->user.targetActor->spr.pos.Y - actor->spr.pos.Y); actor->spr.xvel = dist>>5; - actor->spr.xvel += DIV2(actor->spr.xvel); + actor->spr.xvel += (actor->spr.xvel >> 1); actor->spr.xvel += (RANDOM_P2(128<<8)>>8); actor->user.jump_speed = -800; change_actor_stat(actor, STAT_ENEMY); @@ -11463,7 +11463,7 @@ void InitVulcanBoulder(DSWActor* actor) if (SP_TAG7(actor)) { delta = SP_TAG5(actor); - nang = actor->spr.ang + (RandomRange(delta) - DIV2(delta)); + nang = actor->spr.ang + (RandomRange(delta) - (delta >> 1)); nang = NORM_ANGLE(nang); } else @@ -11531,7 +11531,7 @@ int InitSerpRing(DSWActor* actor) ang_diff = 2048 / max_missiles; - ang_start = NORM_ANGLE(actor->spr.ang - DIV2(2048)); + ang_start = NORM_ANGLE(actor->spr.ang - (2048 / 2)); PlaySound(DIGI_SERPSUMMONHEADS, actor, v3df_none); @@ -13752,7 +13752,7 @@ int InitMicro(PLAYERp pp) actorNew->spr.ang = NORM_ANGLE(actorNew->spr.ang + 512); const int MICRO_LATERAL = 5000; - HelpMissileLateral(actorNew, 1000 + (RandomRange(MICRO_LATERAL) - DIV2(MICRO_LATERAL))); + HelpMissileLateral(actorNew, 1000 + (RandomRange(MICRO_LATERAL) - (MICRO_LATERAL / 2))); actorNew->spr.ang = NORM_ANGLE(actorNew->spr.ang - 512); if (TEST(pp->Flags, PF_DIVING) || SpriteInUnderwaterArea(actorNew)) @@ -13789,7 +13789,7 @@ int InitMicro(PLAYERp pp) } else { - actorNew->spr.ang = NORM_ANGLE(actorNew->spr.ang + (RandomRange(MICRO_ANG) - DIV2(MICRO_ANG)) - 16); + actorNew->spr.ang = NORM_ANGLE(actorNew->spr.ang + (RandomRange(MICRO_ANG) - (MICRO_ANG / 2)) - 16); } actorNew->user.xchange = MOVEx(actorNew->spr.xvel, actorNew->spr.ang); @@ -13909,7 +13909,7 @@ bool WallSpriteInsideSprite(DSWActor* wactor, DSWActor* actor) day = -bcos(wactor->spr.ang) * wactor->spr.xrepeat; xsiz = tileWidth(wactor->spr.picnum); - mid_dist = DIV2(xsiz) + xoff; + mid_dist = (xsiz >> 1) + xoff; // starting from the center find the first point x1 -= MulScale(dax, mid_dist, 16); @@ -15530,7 +15530,7 @@ int InitTurretMicro(DSWActor* actor, PLAYERp pp) } else { - actorNew->spr.ang = NORM_ANGLE(actorNew->spr.ang + (RandomRange(MICRO_ANG) - DIV2(MICRO_ANG)) - 16); + actorNew->spr.ang = NORM_ANGLE(actorNew->spr.ang + (RandomRange(MICRO_ANG) - (MICRO_ANG / 2)) - 16); } actorNew->user.xchange = MOVEx(actorNew->spr.xvel, actorNew->spr.ang);