- big macro mess cleanup.

This commit is contained in:
Christoph Oelckers 2021-12-25 01:58:34 +01:00
parent 297921204f
commit bd3aaea3b2
3 changed files with 42 additions and 52 deletions

View file

@ -773,7 +773,7 @@ int StdRandomRange(int range)
if (range <= 0)
return 0;
rand_num = STD_RANDOM();
rand_num = rand();
if (rand_num == RAND_MAX)
rand_num--;

View file

@ -196,14 +196,28 @@ inline int32_t FIXED(int32_t msw, int32_t lsw)
int StdRandomRange(int range);
#define STD_RANDOM_P2(pwr_of_2) (MOD_P2(rand(),(pwr_of_2)))
#define STD_RANDOM() (rand())
#define RANDOM_NEG(x,y) ((RANDOM_P2(((x)<<(y))<<1) - (x))<<(y))
#define MOVEx(vel,ang) (MulScale(vel, bcos(ang), 14))
#define MOVEy(vel,ang) (MulScale(vel, bsin(ang), 14))
inline int MOVEx(int vel, int ang)
{
return (MulScale(vel, bcos(ang), 14));
}
#define DIST(x1, y1, x2, y2) ksqrt( SQ((x1) - (x2)) + SQ((y1) - (y2)) )
inline int MOVEy(int vel, int ang)
{
return (MulScale(vel, bsin(ang), 14));
}
inline int SQ(int val)
{
return val * val;
}
inline int DIST(int x1, int y1, int x2, int y2)
{
return ksqrt(SQ((x1)-(x2)) + SQ((y1)-(y2)));
}
// Distance macro - tx, ty, tmin are holding vars that must be declared in the routine
// that uses this macro
@ -215,11 +229,6 @@ inline void DISTANCE(int x1, int y1, int x2, int y2, int& dist, int& tx, int& ty
dist = tx + ty - (tmin >> 1);
}
inline int GetSpriteSizeX(const spritetypebase* sp)
{
return MulScale(tileWidth(sp->picnum), sp->xrepeat, 6);
}
inline int GetSpriteSizeY(const spritetypebase* sp)
{
return MulScale(tileHeight(sp->picnum), sp->yrepeat, 6);
@ -231,22 +240,15 @@ inline int GetSpriteSizeZ(const spritetypebase* sp)
}
// Given a z height and sprite return the correct y repeat value
inline int GetRepeatFromHeight(const spritetype* sp, int zh)
{
return zh / (4 * tileHeight(sp->picnum));
}
// Z size of top (TOS) and bottom (BOS) part of sprite
inline int GetSpriteSizeToTop(const spritetypebase* sp)
{
return (DIV2(GetSpriteSizeZ(sp)) + (tileTopOffset(sp->picnum) << 8));
return ((GetSpriteSizeZ(sp) >> 1) + (tileTopOffset(sp->picnum) << 8));
}
inline int GetSpriteSizeToBottom(const spritetypebase* sp)
{
return (DIV2(GetSpriteSizeZ(sp)) - (tileTopOffset(sp->picnum) << 8));
return ((GetSpriteSizeZ(sp) >> 1) - (tileTopOffset(sp->picnum) << 8));
}
// actual Z for TOS and BOS - handles both WYSIWYG and old style
@ -275,37 +277,25 @@ constexpr int PIXZ(int value)
return value >> 8;
}
constexpr int SQ(int val)
{
return val * val;
}
// two vectors
// can determin direction
#define DOT_PRODUCT_2D(x1,y1,x2,y2) (MulScale((x1), (x2), 16) + MulScale((y1), (y2), 16))
constexpr int DOT_PRODUCT_2D(int x1, int y1, int x2, int y2)
{
return (MulScale((x1), (x2), 16) + MulScale((y1), (y2), 16));
}
constexpr int SEC(int value)
{
return ((value) * 120);
}
#define SEC(value) ((value)*120)
#define CEILING_DIST (Z(4))
#define FLOOR_DIST (Z(4))
#define NORM_SPRITE(val) ((val) & (kHitIndexMask))
#define NORM_SECTOR(val) ((val) & (kHitIndexMask))
// overwritesprite flags
#define OVER_SPRITE_MIDDLE (BIT(0))
#define OVER_SPRITE_VIEW_CLIP (BIT(1))
#define OVER_SPRITE_TRANSLUCENT (BIT(2))
#define OVER_SPRITE_XFLIP (BIT(3))
#define OVER_SPRITE_YFLIP (BIT(4))
#undef CLIPMASK0 // defined in build.h
#undef CLIPMASK1
// new define more readable defines
enum
{
CEILING_DIST = (Z(4)),
FLOOR_DIST = (Z(4))
};
// Clip Sprite adjustment
constexpr int CS(int sprite_bit)

View file

@ -14806,7 +14806,7 @@ int InitEnemyRocket(DSWActor* actor)
nx = actor->spr.pos.X;
ny = actor->spr.pos.Y;
nz = actor->spr.pos.Z - DIV2(ActorSizeZ(actor))-Z(8);
nz = actor->spr.pos.Z - (ActorSizeZ(actor) >> 1)-Z(8);
// Spawn a shot
auto actorNew = SpawnActor(STAT_MISSILE, BOLT_THINMAN_R2, &s_Rocket[0][0], actor->spr.sector(),
@ -14889,7 +14889,7 @@ int InitEnemyRail(DSWActor* actor)
nx = actor->spr.pos.X;
ny = actor->spr.pos.Y;
nz = actor->spr.pos.Z - DIV2(ActorSizeZ(actor))-Z(8);
nz = actor->spr.pos.Z - (ActorSizeZ(actor) >> 1)-Z(8);
// Spawn a shot
// Inserting and setting up variables
@ -14973,7 +14973,7 @@ int InitZillaRocket(DSWActor* actor)
{
nx = actor->spr.pos.X;
ny = actor->spr.pos.Y;
nz = actor->spr.pos.Z - DIV2(ActorSizeZ(actor))-Z(8);
nz = actor->spr.pos.Z - (ActorSizeZ(actor) >> 1)-Z(8);
// Spawn a shot
auto actorNew = SpawnActor(STAT_MISSILE, BOLT_THINMAN_R2, &s_Rocket[0][0], actor->spr.sector(),
@ -15132,7 +15132,7 @@ int InitSkelSpell(DSWActor* actor)
nx = actor->spr.pos.X;
ny = actor->spr.pos.Y;
nz = actor->spr.pos.Z - DIV2(ActorSizeZ(actor));
nz = actor->spr.pos.Z - (ActorSizeZ(actor) >> 1);
// Spawn a shot
auto actorNew = SpawnActor(STAT_MISSILE, ELECTRO_ENEMY, s_Electro, actor->spr.sector(),
@ -17435,7 +17435,7 @@ int InitEnemyFireball(DSWActor* actor)
//dist = Distance(actorNew->spr.pos.X, actorNew->spr.pos.Y, tsp->pos.X, tsp->pos.Y);
// Determine target Z value
targ_z = tsp->pos.Z - DIV2(Z(ActorSizeY(actor)));
targ_z = tsp->pos.Z - (Z(ActorSizeY(actor)) >> 1);
// (velocity * difference between the target and the throwing star) /
// distance
@ -18433,8 +18433,8 @@ DSWActor* QueueWallBlood(DSWActor* actor, short ang)
return nullptr; // No blood underwater!
daz = Z(RANDOM_P2(128))<<3;
daz -= DIV2(Z(128)<<3);
dang = (ang+(RANDOM_P2(128<<5) >> 5)) - DIV2(128);
daz -= (Z(128)<<2);
dang = (ang+(RANDOM_P2(128<<5) >> 5)) - (64);
FAFhitscan(actor->spr.pos.X, actor->spr.pos.Y, actor->spr.pos.Z - Z(30), actor->spr.sector(), // Start position
bcos(dang), // X vector of 3D ang