- binaryangle.h: Remove lookangle class and replace use with binangle.

* Added in fca846272e to deal with signed adjustments but its just not needed.
* Made better use of `binangle`/`fixedhoriz` class getters and setters than before as well.
This commit is contained in:
Mitchell Richters 2021-04-11 15:43:11 +10:00
parent a5ed7ba8a3
commit f254eeb465
20 changed files with 115 additions and 287 deletions

View file

@ -59,7 +59,6 @@ enum
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
constexpr double BAngRadian = pi::pi() * (1. / 1024.); constexpr double BAngRadian = pi::pi() * (1. / 1024.);
constexpr double BRadAngScale = 1. / BAngRadian;
constexpr double BAngToDegree = 360. / 2048.; constexpr double BAngToDegree = 360. / 2048.;
extern int16_t sintable[2048]; extern int16_t sintable[2048];
@ -108,134 +107,6 @@ inline constexpr int64_t BAngToBAM(int ang)
} }
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
class lookangle
{
int32_t value;
constexpr lookangle(int32_t v) : value(v) {}
friend constexpr lookangle bamlook(int32_t v);
friend constexpr lookangle q16look(int32_t v);
friend constexpr lookangle buildlook(int32_t v);
friend lookangle buildflook(double v);
friend lookangle radlook(double v);
friend lookangle deglook(double v);
friend FSerializer &Serialize(FSerializer &arc, const char *key, lookangle &obj, lookangle *defval);
friend class binangle;
public:
lookangle() = default;
lookangle(const lookangle &other) = default;
// This class intentionally makes no allowances for implicit type conversions because those would render it ineffective.
constexpr short asbuild() const { return value >> 21; }
constexpr double asbuildf() const { return value * (1. / BAMUNIT); }
constexpr fixed_t asq16() const { return value >> 5; }
constexpr double asrad() const { return value * (pi::pi() / 0x80000000u); }
constexpr double asdeg() const { return AngleToFloat(value); }
constexpr int32_t asbam() const { return value; }
double fsin() const { return g_sin(asrad()); }
double fcos() const { return g_cos(asrad()); }
double ftan() const { return g_tan(asrad()); }
int bsin(const int8_t& shift = 0) const { return ::bsin(asbuild(), shift); }
int bcos(const int8_t& shift = 0) const { return ::bcos(asbuild(), shift); }
bool operator< (lookangle other) const
{
return value < other.value;
}
bool operator> (lookangle other) const
{
return value > other.value;
}
bool operator<= (lookangle other) const
{
return value <= other.value;
}
bool operator>= (lookangle other) const
{
return value >= other.value;
}
constexpr bool operator== (lookangle other) const
{
return value == other.value;
}
constexpr bool operator!= (lookangle other) const
{
return value != other.value;
}
constexpr lookangle &operator+= (lookangle other)
{
value += other.value;
return *this;
}
constexpr lookangle &operator-= (lookangle other)
{
value -= other.value;
return *this;
}
constexpr lookangle operator+ (lookangle other) const
{
return lookangle(value + other.value);
}
constexpr lookangle operator- (lookangle other) const
{
return lookangle(value - other.value);
}
constexpr lookangle &operator<<= (const uint8_t shift)
{
value <<= shift;
return *this;
}
constexpr lookangle &operator>>= (const uint8_t shift)
{
value >>= shift;
return *this;
}
constexpr lookangle operator<< (const uint8_t shift) const
{
return lookangle(value << shift);
}
constexpr lookangle operator>> (const uint8_t shift) const
{
return lookangle(value >> shift);
}
};
inline constexpr lookangle bamlook(int32_t v) { return lookangle(v); }
inline constexpr lookangle q16look(int32_t v) { return lookangle(v << 5); }
inline constexpr lookangle buildlook(int32_t v) { return lookangle(v << BAMBITS); }
inline lookangle buildflook(double v) { return lookangle(xs_CRoundToInt(v * BAMUNIT)); }
inline lookangle radlook(double v) { return lookangle(xs_CRoundToInt(v * (0x80000000u / pi::pi()))); }
inline lookangle deglook(double v) { return lookangle(FloatToAngle(v)); }
inline FSerializer &Serialize(FSerializer &arc, const char *key, lookangle &obj, lookangle *defval)
{
return Serialize(arc, key, obj.value, defval ? &defval->value : nullptr);
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// //
@ -261,12 +132,17 @@ public:
binangle() = default; binangle() = default;
binangle(const binangle &other) = default; binangle(const binangle &other) = default;
// This class intentionally makes no allowances for implicit type conversions because those would render it ineffective. // This class intentionally makes no allowances for implicit type conversions because those would render it ineffective.
constexpr int32_t tosigned() const { return value > BAngToBAM(1024) ? int64_t(value) - BAngToBAM(2048) : value; }
constexpr short asbuild() const { return value >> 21; } constexpr short asbuild() const { return value >> 21; }
constexpr double asbuildf() const { return value * (1. / BAMUNIT); } constexpr double asbuildf() const { return value * (1. / BAMUNIT); }
constexpr fixed_t asq16() const { return value >> 5; } constexpr fixed_t asq16() const { return value >> 5; }
constexpr uint32_t asbam() const { return value; }
constexpr double asrad() const { return value * (pi::pi() / 0x80000000u); } constexpr double asrad() const { return value * (pi::pi() / 0x80000000u); }
constexpr double asdeg() const { return AngleToFloat(value); } constexpr double asdeg() const { return AngleToFloat(value); }
constexpr uint32_t asbam() const { return value; } constexpr short signedbuild() const { return tosigned() >> 21; }
constexpr double signedbuildf() const { return tosigned() * (1. / BAMUNIT); }
constexpr fixed_t signedq16() const { return tosigned() >> 5; }
constexpr int32_t signedbam() const { return tosigned(); }
double fsin() const { return g_sin(asrad()); } double fsin() const { return g_sin(asrad()); }
double fcos() const { return g_cos(asrad()); } double fcos() const { return g_cos(asrad()); }
@ -306,28 +182,6 @@ public:
return binangle(value - other.value); return binangle(value - other.value);
} }
constexpr binangle &operator+= (lookangle other)
{
value += other.value;
return *this;
}
constexpr binangle &operator-= (lookangle other)
{
value -= other.value;
return *this;
}
constexpr binangle operator+ (lookangle other) const
{
return binangle(value + other.value);
}
constexpr binangle operator- (lookangle other) const
{
return binangle(value - other.value);
}
constexpr binangle &operator<<= (const uint8_t shift) constexpr binangle &operator<<= (const uint8_t shift)
{ {
value <<= shift; value <<= shift;

View file

@ -78,7 +78,7 @@ fixed_t getincangleq16(fixed_t a, fixed_t na)
return na-a; return na-a;
} }
lookangle getincanglebam(binangle a, binangle na) binangle getincanglebam(binangle a, binangle na)
{ {
int64_t cura = a.asbam() & 0xFFFFFFFF; int64_t cura = a.asbam() & 0xFFFFFFFF;
int64_t newa = na.asbam() & 0xFFFFFFFF; int64_t newa = na.asbam() & 0xFFFFFFFF;
@ -89,7 +89,7 @@ lookangle getincanglebam(binangle a, binangle na)
if(cura > BAngToBAM(1024)) cura -= BAngToBAM(2048); if(cura > BAngToBAM(1024)) cura -= BAngToBAM(2048);
} }
return bamlook(newa-cura); return bamang(newa-cura);
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -318,10 +318,10 @@ void sethorizon(PlayerHorizon* horizon, float const horz, ESyncBits* actions, do
// return to center if conditions met. // return to center if conditions met.
if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN))) if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN)))
{ {
if (abs(horizon->horiz.asq16()) > FloatToFixed(0.25)) if (abs(horizon->horiz.asq16()) > (FRACUNIT >> 2))
{ {
// move horiz back to 0 // move horiz back to 0
horizon->horiz -= q16horiz(xs_CRoundToInt(scaleAdjust * horizon->horiz.asq16() * (10. / GameTicRate))); horizon->horiz -= buildfhoriz(scaleAdjust * horizon->horiz.asbuildf() * (10. / GameTicRate));
} }
else else
{ {
@ -346,63 +346,63 @@ void sethorizon(PlayerHorizon* horizon, float const horz, ESyncBits* actions, do
void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double const scaleAdjust) void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double const scaleAdjust)
{ {
// return q16rotscrnang to 0 and set to 0 if less than a quarter of a unit // return q16rotscrnang to 0 and set to 0 if less than a quarter of a unit
angle->rotscrnang -= bamlook(xs_CRoundToInt(scaleAdjust * angle->rotscrnang.asbam() * (15. / GameTicRate))); angle->rotscrnang -= buildfang(scaleAdjust * angle->rotscrnang.signedbuildf() * (15. / GameTicRate));
if (abs(angle->rotscrnang.asbam()) < (BAMUNIT >> 2)) angle->rotscrnang = bamlook(0); if (abs(angle->rotscrnang.signedbam()) < (BAMUNIT >> 2)) angle->rotscrnang = bamang(0);
// return q16look_ang to 0 and set to 0 if less than a quarter of a unit // return q16look_ang to 0 and set to 0 if less than a quarter of a unit
angle->look_ang -= bamlook(xs_CRoundToInt(scaleAdjust * angle->look_ang.asbam() * (7.5 / GameTicRate))); angle->look_ang -= buildfang(scaleAdjust * angle->look_ang.signedbuildf() * (7.5 / GameTicRate));
if (abs(angle->look_ang.asbam()) < (BAMUNIT >> 2)) angle->look_ang = bamlook(0); if (abs(angle->look_ang.signedbam()) < (BAMUNIT >> 2)) angle->look_ang = bamang(0);
if (*actions & SB_LOOK_LEFT) if (*actions & SB_LOOK_LEFT)
{ {
// start looking left // start looking left
angle->look_ang -= bamlook(xs_CRoundToInt(scaleAdjust * (4560. / GameTicRate) * BAMUNIT)); angle->look_ang += buildfang(scaleAdjust * -(4560. / GameTicRate));
angle->rotscrnang += bamlook(xs_CRoundToInt(scaleAdjust * (720. / GameTicRate) * BAMUNIT)); angle->rotscrnang += buildfang(scaleAdjust * (720. / GameTicRate));
} }
if (*actions & SB_LOOK_RIGHT) if (*actions & SB_LOOK_RIGHT)
{ {
// start looking right // start looking right
angle->look_ang += bamlook(xs_CRoundToInt(scaleAdjust * (4560. / GameTicRate) * BAMUNIT)); angle->look_ang += buildfang(scaleAdjust * (4560. / GameTicRate));
angle->rotscrnang -= bamlook(xs_CRoundToInt(scaleAdjust * (720. / GameTicRate) * BAMUNIT)); angle->rotscrnang += buildfang(scaleAdjust * -(720. / GameTicRate));
} }
if (!angle->targetset()) if (!angle->targetset())
{ {
if (*actions & SB_TURNAROUND) if (*actions & SB_TURNAROUND)
{ {
if (angle->spin.asbam() == 0) if (angle->spin == 0)
{ {
// currently not spinning, so start a spin // currently not spinning, so start a spin
angle->spin = buildlook(-1024); angle->spin = -1024.;
} }
*actions &= ~SB_TURNAROUND; *actions &= ~SB_TURNAROUND;
} }
if (angle->spin.asbam() < 0) if (angle->spin < 0)
{ {
// return spin to 0 // return spin to 0
lookangle add = bamlook(xs_CRoundToUInt(scaleAdjust * ((!(*actions & SB_CROUCH) ? 3840. : 1920.) / GameTicRate) * BAMUNIT)); double add = scaleAdjust * ((!(*actions & SB_CROUCH) ? 3840. : 1920.) / GameTicRate);
angle->spin += add; angle->spin += add;
if (angle->spin.asbam() > 0) if (angle->spin > 0)
{ {
// Don't overshoot our target. With variable factor this is possible. // Don't overshoot our target. With variable factor this is possible.
add -= angle->spin; add -= angle->spin;
angle->spin = bamlook(0); angle->spin = 0;
} }
angle->ang += bamang(add.asbam()); angle->ang += buildfang(add);
} }
if (avel) if (avel)
{ {
// add player's input // add player's input
angle->ang += degang(avel); angle->ang += degang(avel);
angle->spin = bamlook(0); angle->spin = 0;
} }
} }
else else
{ {
angle->spin = bamlook(0); angle->spin = 0;
} }
} }

View file

@ -9,7 +9,16 @@
int getincangle(int a, int na); int getincangle(int a, int na);
double getincanglef(double a, double na); double getincanglef(double a, double na);
fixed_t getincangleq16(fixed_t a, fixed_t na); fixed_t getincangleq16(fixed_t a, fixed_t na);
lookangle getincanglebam(binangle a, binangle na); binangle getincanglebam(binangle a, binangle na);
inline binangle interpolatedbamang(binangle oang, binangle ang, double const smoothratio)
{
double const ratio = smoothratio * (1. / FRACUNIT);
uint32_t const dang = UINT32_MAX >> 1;
int64_t const prev = oang.asbam();
int64_t const curr = ang.asbam();
return bamang(prev + xs_CRoundToUInt(ratio * (((curr + dang - prev) & 0xFFFFFFFF) - dang)));
}
struct PlayerHorizon struct PlayerHorizon
{ {
@ -29,7 +38,12 @@ struct PlayerHorizon
void addadjustment(double value) void addadjustment(double value)
{ {
__addadjustment(q16horiz(FloatToFixed(value))); __addadjustment(buildfhoriz(value));
}
void addadjustment(fixedhoriz value)
{
__addadjustment(value);
} }
void resetadjustment() void resetadjustment()
@ -37,11 +51,6 @@ struct PlayerHorizon
adjustment = 0; adjustment = 0;
} }
void settarget(int value, bool backup = false)
{
__settarget(buildhoriz(clamp(value, FixedToInt(gi->playerHorizMin()), FixedToInt(gi->playerHorizMax()))), backup);
}
void settarget(double value, bool backup = false) void settarget(double value, bool backup = false)
{ {
__settarget(buildfhoriz(clamp(value, FixedToFloat(gi->playerHorizMin()), FixedToFloat(gi->playerHorizMax()))), backup); __settarget(buildfhoriz(clamp(value, FixedToFloat(gi->playerHorizMin()), FixedToFloat(gi->playerHorizMax()))), backup);
@ -61,11 +70,11 @@ struct PlayerHorizon
{ {
if (targetset()) if (targetset())
{ {
auto delta = (target - horiz).asq16(); auto delta = (target - horiz).asbuildf();
if (abs(delta) > FRACUNIT) if (abs(delta) > 1)
{ {
horiz += q16horiz(xs_CRoundToInt(scaleAdjust * delta)); horiz += buildfhoriz(scaleAdjust * delta);
} }
else else
{ {
@ -75,7 +84,7 @@ struct PlayerHorizon
} }
else if (adjustment) else if (adjustment)
{ {
horiz += q16horiz(xs_CRoundToInt(scaleAdjust * adjustment)); horiz += buildfhoriz(scaleAdjust * adjustment);
} }
} }
@ -105,7 +114,7 @@ private:
{ {
if (!SyncInput()) if (!SyncInput())
{ {
adjustment += value.asq16(); adjustment += value.asbuildf();
} }
else else
{ {
@ -113,7 +122,7 @@ private:
} }
} }
void __settarget(fixedhoriz value, bool backup = false) void __settarget(fixedhoriz value, bool backup)
{ {
if (!SyncInput() && !backup) if (!SyncInput() && !backup)
{ {
@ -130,8 +139,8 @@ private:
struct PlayerAngle struct PlayerAngle
{ {
binangle ang, oang; binangle ang, oang, look_ang, olook_ang, rotscrnang, orotscrnang;
lookangle look_ang, olook_ang, rotscrnang, orotscrnang, spin; double spin;
void backup() void backup()
{ {
@ -147,24 +156,14 @@ struct PlayerAngle
rotscrnang = orotscrnang; rotscrnang = orotscrnang;
} }
void addadjustment(int value)
{
__addadjustment(buildlook(value));
}
void addadjustment(double value) void addadjustment(double value)
{ {
__addadjustment(buildflook(value)); __addadjustment(buildfang(value));
}
void addadjustment(lookangle value)
{
__addadjustment(value);
} }
void addadjustment(binangle value) void addadjustment(binangle value)
{ {
__addadjustment(bamlook(value.asbam())); __addadjustment(value);
} }
void resetadjustment() void resetadjustment()
@ -172,14 +171,9 @@ struct PlayerAngle
adjustment = 0; adjustment = 0;
} }
void settarget(int value, bool backup = false)
{
__settarget(buildang(value & 2047), backup);
}
void settarget(double value, bool backup = false) void settarget(double value, bool backup = false)
{ {
__settarget(buildfang(fmod(value, 2048)), backup); __settarget(buildfang(value), backup);
} }
void settarget(binangle value, bool backup = false) void settarget(binangle value, bool backup = false)
@ -196,11 +190,11 @@ struct PlayerAngle
{ {
if (targetset()) if (targetset())
{ {
auto delta = getincanglebam(ang, target).asbam(); auto delta = getincanglebam(ang, target).signedbuildf();
if (delta > BAMUNIT) if (abs(delta) > 1)
{ {
ang += bamang(xs_CRoundToUInt(scaleAdjust * delta)); ang += buildfang(scaleAdjust * delta);
} }
else else
{ {
@ -210,7 +204,7 @@ struct PlayerAngle
} }
else if (adjustment) else if (adjustment)
{ {
ang += bamang(xs_CRoundToUInt(scaleAdjust * adjustment)); ang += buildfang(scaleAdjust * adjustment);
} }
} }
@ -226,39 +220,33 @@ struct PlayerAngle
binangle interpolatedsum(double const smoothratio) binangle interpolatedsum(double const smoothratio)
{ {
double const ratio = smoothratio * (1. / FRACUNIT); return interpolatedbamang(osum(), sum(), smoothratio);
uint32_t const dang = UINT32_MAX >> 1;
int64_t const prev = osum().asbam();
int64_t const curr = sum().asbam();
return bamang(prev + xs_CRoundToUInt(ratio * (((curr + dang - prev) & 0xFFFFFFFF) - dang)));
} }
lookangle interpolatedlookang(double const smoothratio) binangle interpolatedlookang(double const smoothratio)
{ {
double const ratio = smoothratio * (1. / FRACUNIT); return interpolatedbamang(olook_ang, look_ang, smoothratio);
return bamlook(olook_ang.asbam() + xs_CRoundToInt(ratio * (look_ang - olook_ang).asbam()));
} }
lookangle interpolatedrotscrn(double const smoothratio) binangle interpolatedrotscrn(double const smoothratio)
{ {
double const ratio = smoothratio * (1. / FRACUNIT); return interpolatedbamang(orotscrnang, rotscrnang, smoothratio);
return bamlook(orotscrnang.asbam() + xs_CRoundToInt(ratio * (rotscrnang - orotscrnang).asbam()));
} }
double look_anghalf(double const smoothratio) double look_anghalf(double const smoothratio)
{ {
return (!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).asbam() * (0.5 / BAMUNIT); // Used within draw code for weapon and crosshair when looking left/right. return (!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).signedbuildf() * 0.5; // Used within draw code for weapon and crosshair when looking left/right.
} }
private: private:
binangle target; binangle target;
double adjustment; double adjustment;
void __addadjustment(lookangle value) void __addadjustment(binangle value)
{ {
if (!SyncInput()) if (!SyncInput())
{ {
adjustment += value.asbam(); adjustment += value.asbuildf();
} }
else else
{ {
@ -266,7 +254,7 @@ private:
} }
} }
void __settarget(binangle value, bool backup = false) void __settarget(binangle value, bool backup)
{ {
if (!SyncInput() && !backup) if (!SyncInput() && !backup)
{ {

View file

@ -175,7 +175,7 @@ void RenderViewpoint(FRenderViewpoint& mainvp, IntRect* bounds, float fov, float
// //
//=========================================================================== //===========================================================================
FRenderViewpoint SetupViewpoint(spritetype* cam, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, lookangle rollang) FRenderViewpoint SetupViewpoint(spritetype* cam, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, binangle rollang)
{ {
FRenderViewpoint r_viewpoint{}; FRenderViewpoint r_viewpoint{};
r_viewpoint.CameraSprite = cam; r_viewpoint.CameraSprite = cam;
@ -275,7 +275,7 @@ static void CheckTimer(FRenderState &state, uint64_t ShaderStartTime)
void animatecamsprite(double s); void animatecamsprite(double s);
void render_drawrooms(spritetype* playersprite, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, lookangle rollang) void render_drawrooms(spritetype* playersprite, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, binangle rollang)
{ {
checkRotatedWalls(); checkRotatedWalls();
@ -328,7 +328,7 @@ void render_drawrooms(spritetype* playersprite, const vec3_t& position, int sect
All.Unclock(); All.Unclock();
} }
void render_camtex(spritetype* playersprite, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, lookangle rollang, FGameTexture* camtex, IntRect& rect, double smoothratio) void render_camtex(spritetype* playersprite, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, binangle rollang, FGameTexture* camtex, IntRect& rect, double smoothratio)
{ {
int16_t sect = sectnum; int16_t sect = sectnum;
updatesector(position.x, position.y, &sect); updatesector(position.x, position.y, &sect);

View file

@ -4,8 +4,8 @@
class FSerializer; class FSerializer;
struct IntRect; struct IntRect;
void render_drawrooms(spritetype* playersprite, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, lookangle rollang); void render_drawrooms(spritetype* playersprite, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, binangle rollang);
void render_camtex(spritetype* playersprite, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, lookangle rollang, FGameTexture* camtex, IntRect& rect, double smoothratio); void render_camtex(spritetype* playersprite, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, binangle rollang, FGameTexture* camtex, IntRect& rect, double smoothratio);
struct PortalDesc struct PortalDesc
{ {

View file

@ -547,16 +547,6 @@ inline fixed_t interpolateangfix16(fixed_t a, fixed_t b, int c)
return a+MulScale(((b-a+0x4000000)&0x7ffffff)-0x4000000, c, 16); return a+MulScale(((b-a+0x4000000)&0x7ffffff)-0x4000000, c, 16);
} }
inline binangle interpolateangbin(uint32_t a, uint32_t b, double c)
{
return bamang(xs_CRoundToUInt(a + MulScaleF(b - a, c, 16)));
}
inline lookangle interpolateanglook(int32_t a, int32_t b, double c)
{
return bamlook(xs_CRoundToUInt(a + MulScaleF(b - a, c, 16)));
}
inline char Chance(int a1) inline char Chance(int a1)
{ {
return wrand() < (a1>>1); return wrand() < (a1>>1);

View file

@ -700,7 +700,7 @@ void playerStart(int nPlayer, int bNewLevel)
pPlayer->restTime = 0; pPlayer->restTime = 0;
pPlayer->kickPower = 0; pPlayer->kickPower = 0;
pPlayer->laughCount = 0; pPlayer->laughCount = 0;
pPlayer->angle.spin = buildlook(0); pPlayer->angle.spin = 0;
pPlayer->posture = 0; pPlayer->posture = 0;
pPlayer->voodooTarget = -1; pPlayer->voodooTarget = -1;
pPlayer->voodooTargets = 0; pPlayer->voodooTargets = 0;

View file

@ -166,9 +166,9 @@ static void fakeProcessInput(PLAYER *pPlayer, InputPacket *pInput)
if (pInput->avel) if (pInput->avel)
predict.angle = degang(pInput->avel); predict.angle = degang(pInput->avel);
if (pInput->actions & SB_TURNAROUND) if (pInput->actions & SB_TURNAROUND)
if (!predict.spin.asbuild()) if (!predict.spin)
predict.spin = buildlook(-1024); predict.spin = -1024;
if (predict.spin.asbuild() < 0) if (predict.spin < 0)
{ {
int speed; int speed;
if (predict.at48 == 1) if (predict.at48 == 1)
@ -176,7 +176,7 @@ static void fakeProcessInput(PLAYER *pPlayer, InputPacket *pInput)
else else
speed = 128; speed = 128;
predict.spin = buildlook(min(predict.spin.asbuild()+speed, 0)); predict.spin = min(int(predict.spin) + speed, 0);
predict.angle += buildang(speed); predict.angle += buildang(speed);
} }

View file

@ -458,7 +458,7 @@ static void DrawMap(spritetype* pSprite)
setViewport(hud_size); setViewport(hud_size);
} }
void SetupView(int &cX, int& cY, int& cZ, binangle& cA, fixedhoriz& cH, int& nSectnum, double& zDelta, double& shakeX, double& shakeY, lookangle& rotscrnang) void SetupView(int &cX, int& cY, int& cZ, binangle& cA, fixedhoriz& cH, int& nSectnum, double& zDelta, double& shakeX, double& shakeY, binangle& rotscrnang)
{ {
int bobWidth, bobHeight; int bobWidth, bobHeight;
@ -483,15 +483,15 @@ void SetupView(int &cX, int& cY, int& cZ, binangle& cA, fixedhoriz& cH, int& nSe
} }
else else
{ {
uint32_t oang = predictOld.angle.asbam() + predictOld.look_ang.asbam(); auto oang = predictOld.angle + predictOld.look_ang;
uint32_t ang = predict.angle.asbam() + predict.look_ang.asbam(); auto ang = predict.angle + predict.look_ang;
cA = interpolateangbin(oang, ang, gInterpolate); cA = interpolatedbamang(oang, ang, gInterpolate);
fixed_t ohoriz = (predictOld.horiz + predictOld.horizoff).asq16(); fixed_t ohoriz = (predictOld.horiz + predictOld.horizoff).asq16();
fixed_t horiz = (predict.horiz + predict.horizoff).asq16(); fixed_t horiz = (predict.horiz + predict.horizoff).asq16();
cH = q16horiz(interpolate(ohoriz, horiz, gInterpolate)); cH = q16horiz(interpolate(ohoriz, horiz, gInterpolate));
rotscrnang = interpolateanglook(predictOld.rotscrnang.asbam(), predict.rotscrnang.asbam(), gInterpolate); rotscrnang = interpolatedbamang(predictOld.rotscrnang, predict.rotscrnang, gInterpolate);
} }
} }
else else
@ -685,7 +685,7 @@ void viewDrawScreen(bool sceneonly)
int nSectnum; int nSectnum;
double zDelta; double zDelta;
double shakeX, shakeY; double shakeX, shakeY;
lookangle rotscrnang; binangle rotscrnang;
SetupView(cX, cY, cZ, cA, cH, nSectnum, zDelta, shakeX, shakeY, rotscrnang); SetupView(cX, cY, cZ, cA, cH, nSectnum, zDelta, shakeX, shakeY, rotscrnang);
int tilt = interpolateang(gScreenTiltO, gScreenTilt, gInterpolate); int tilt = interpolateang(gScreenTiltO, gScreenTilt, gInterpolate);
@ -697,7 +697,7 @@ void viewDrawScreen(bool sceneonly)
uint8_t otherview = powerupCheck(gView, kPwUpCrystalBall) > 0; uint8_t otherview = powerupCheck(gView, kPwUpCrystalBall) > 0;
if (tilt || bDelirium) if (tilt || bDelirium)
{ {
rotscrnang = buildlook(tilt); rotscrnang = buildang(tilt);
} }
else if (otherview && gNetPlayers > 1) else if (otherview && gNetPlayers > 1)
{ {

View file

@ -50,7 +50,7 @@ struct VIEW {
int at40; int at40;
int at44; int at44;
int at48; // posture int at48; // posture
lookangle spin; // spin double spin; // spin
int x; // x int x; // x
int y; // y int y; // y
int z; // z int z; // z
@ -66,8 +66,8 @@ struct VIEW {
char at72; // underwater char at72; // underwater
short at73; // sprite flags short at73; // sprite flags
SPRITEHIT at75; SPRITEHIT at75;
lookangle look_ang; binangle look_ang;
lookangle rotscrnang; binangle rotscrnang;
}; };
extern VIEW gPrevView[kMaxPlayers]; extern VIEW gPrevView[kMaxPlayers];

View file

@ -484,7 +484,7 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor,
break; break;
case PLAYER_LOOK_ANG: case PLAYER_LOOK_ANG:
if (bSet) ps[iPlayer].angle.look_ang = buildlook(lValue); if (bSet) ps[iPlayer].angle.look_ang = buildang(lValue);
else SetGameVarID(lVar2, ps[iPlayer].angle.look_ang.asbuild(), sActor, sPlayer); else SetGameVarID(lVar2, ps[iPlayer].angle.look_ang.asbuild(), sActor, sPlayer);
break; break;
@ -645,8 +645,8 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor,
break; break;
case PLAYER_ONE_EIGHTY_COUNT: case PLAYER_ONE_EIGHTY_COUNT:
if (bSet) ps[iPlayer].angle.spin = buildlook(lValue); if (bSet) ps[iPlayer].angle.spin = lValue;
else SetGameVarID(lVar2, ps[iPlayer].angle.spin.asbuild(), sActor, sPlayer); else SetGameVarID(lVar2, ps[iPlayer].angle.spin, sActor, sPlayer);
break; break;
case PLAYER_CHEAT_PHASE: case PLAYER_CHEAT_PHASE:
@ -705,7 +705,7 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor,
break; break;
case PLAYER_ROTSCRNANG: case PLAYER_ROTSCRNANG:
if (bSet) ps[iPlayer].angle.rotscrnang = buildlook(lValue); if (bSet) ps[iPlayer].angle.rotscrnang = buildang(lValue);
else SetGameVarID(lVar2, ps[iPlayer].angle.rotscrnang.asbuild(), sActor, sPlayer); else SetGameVarID(lVar2, ps[iPlayer].angle.rotscrnang.asbuild(), sActor, sPlayer);
break; break;
@ -2267,7 +2267,7 @@ int ParseState::parse(void)
ps[g_p].weapreccnt = 0; ps[g_p].weapreccnt = 0;
ps[g_p].ftq = 0; ps[g_p].ftq = 0;
ps[g_p].posxv = ps[g_p].posyv = 0; ps[g_p].posxv = ps[g_p].posyv = 0;
if (!isRR()) ps[g_p].angle.orotscrnang = ps[g_p].angle.rotscrnang = buildlook(0); if (!isRR()) ps[g_p].angle.orotscrnang = ps[g_p].angle.rotscrnang = buildang(0);
ps[g_p].falling_counter = 0; ps[g_p].falling_counter = 0;

View file

@ -477,7 +477,7 @@ void hud_input(int plnum)
} }
} }
if (PlayerInput(plnum, SB_TURNAROUND) && p->angle.spin.asbam() == 0 && p->on_crane == nullptr) if (PlayerInput(plnum, SB_TURNAROUND) && p->angle.spin == 0 && p->on_crane == nullptr)
{ {
SetGameVarID(g_iReturnVarID, 0, nullptr, plnum); SetGameVarID(g_iReturnVarID, 0, nullptr, plnum);
OnEvent(EVENT_TURNAROUND, plnum, nullptr, -1); OnEvent(EVENT_TURNAROUND, plnum, nullptr, -1);

View file

@ -121,7 +121,7 @@ void forceplayerangle(int snum)
p->horizon.addadjustment(64); p->horizon.addadjustment(64);
p->sync.actions |= SB_CENTERVIEW; p->sync.actions |= SB_CENTERVIEW;
p->angle.rotscrnang = p->angle.look_ang = buildlook(n >> 1); p->angle.rotscrnang = p->angle.look_ang = buildang(n >> 1);
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -630,7 +630,7 @@ void playerisdead(int snum, int psectlotag, int fz, int cz)
pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 128L, (4 << 8), (20 << 8), CLIPMASK0); pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 128L, (4 << 8), (20 << 8), CLIPMASK0);
if (fz > cz + (16 << 8) && s->pal != 1) if (fz > cz + (16 << 8) && s->pal != 1)
p->angle.rotscrnang = buildlook(p->dead_flag + ((fz + p->posz) >> 7)); p->angle.rotscrnang = buildang(p->dead_flag + ((fz + p->posz) >> 7));
p->on_warping_sector = 0; p->on_warping_sector = 0;
@ -741,16 +741,16 @@ void player_struct::apply_seasick(double factor)
if (SeaSick < 250) if (SeaSick < 250)
{ {
if (SeaSick >= 180) if (SeaSick >= 180)
angle.rotscrnang += bamlook(xs_CRoundToUInt(24 * factor * BAMUNIT)); angle.rotscrnang += bamang(xs_CRoundToUInt(24 * factor * BAMUNIT));
else if (SeaSick >= 130) else if (SeaSick >= 130)
angle.rotscrnang -= bamlook(xs_CRoundToUInt(24 * factor * BAMUNIT)); angle.rotscrnang -= bamang(xs_CRoundToUInt(24 * factor * BAMUNIT));
else if (SeaSick >= 70) else if (SeaSick >= 70)
angle.rotscrnang += bamlook(xs_CRoundToUInt(24 * factor * BAMUNIT)); angle.rotscrnang += bamang(xs_CRoundToUInt(24 * factor * BAMUNIT));
else if (SeaSick >= 20) else if (SeaSick >= 20)
angle.rotscrnang -= bamlook(xs_CRoundToUInt(24 * factor * BAMUNIT)); angle.rotscrnang -= bamang(xs_CRoundToUInt(24 * factor * BAMUNIT));
} }
if (SeaSick < 250) if (SeaSick < 250)
angle.look_ang = bamlook(xs_CRoundToUInt(((krand() & 255) - 128) * factor * BAMUNIT)); angle.look_ang = bamang(xs_CRoundToUInt(((krand() & 255) - 128) * factor * BAMUNIT));
} }
} }

View file

@ -1773,7 +1773,7 @@ static void onMotorcycle(int snum, ESyncBits &actions)
if (p->MotoSpeed >= 20 && p->on_ground == 1 && (p->vehTurnLeft || p->vehTurnRight)) if (p->MotoSpeed >= 20 && p->on_ground == 1 && (p->vehTurnLeft || p->vehTurnRight))
{ {
velAdjustment = p->vehTurnLeft ? -10 : 10; velAdjustment = p->vehTurnLeft ? -10 : 10;
auto angAdjustment = buildlook(velAdjustment < 0 ? 350 : -350); auto angAdjustment = buildang(velAdjustment < 0 ? 350 : -350);
if (p->moto_on_mud || p->moto_on_oil || !p->NotOnWater) if (p->moto_on_mud || p->moto_on_oil || !p->NotOnWater)
{ {
@ -2040,7 +2040,7 @@ static void onBoat(int snum, ESyncBits &actions)
{ {
int currSpeed = p->MotoSpeed * 4.; int currSpeed = p->MotoSpeed * 4.;
short velAdjustment = p->vehTurnLeft ? -10 : 10; short velAdjustment = p->vehTurnLeft ? -10 : 10;
auto angAdjustment = buildlook(velAdjustment < 0 ? 350 : -350); auto angAdjustment = buildang(velAdjustment < 0 ? 350 : -350);
if (p->moto_do_bump) if (p->moto_do_bump)
{ {

View file

@ -140,8 +140,8 @@ void resetplayerstats(int snum)
p->jetpack_on = 0; p->jetpack_on = 0;
p->holoduke_on = nullptr; p->holoduke_on = nullptr;
p->angle.olook_ang = p->angle.look_ang = buildlook(512 - ((currentLevel->levelNumber & 1) << 10)); p->angle.olook_ang = p->angle.look_ang = buildang(512 - ((currentLevel->levelNumber & 1) << 10));
p->angle.orotscrnang = p->angle.rotscrnang = buildlook(0); p->angle.orotscrnang = p->angle.rotscrnang = buildang(0);
p->newOwner =nullptr; p->newOwner =nullptr;
p->jumping_counter = 0; p->jumping_counter = 0;
@ -152,7 +152,7 @@ void resetplayerstats(int snum)
p->fric.x = 0; p->fric.x = 0;
p->fric.y = 0; p->fric.y = 0;
p->somethingonplayer =nullptr; p->somethingonplayer =nullptr;
p->angle.spin = bamlook(0); p->angle.spin = 0;
p->on_crane = nullptr; p->on_crane = nullptr;

View file

@ -67,7 +67,7 @@ BEGIN_DUKE_NS
/*static*/ int tempsectorpicnum[MAXSECTORS]; /*static*/ int tempsectorpicnum[MAXSECTORS];
//short tempcursectnum; //short tempcursectnum;
void renderView(spritetype* playersprite, int sectnum, int x, int y, int z, binangle a, fixedhoriz h, lookangle rotscrnang, int smoothratio) void renderView(spritetype* playersprite, int sectnum, int x, int y, int z, binangle a, fixedhoriz h, binangle rotscrnang, int smoothratio)
{ {
if (!testnewrenderer) if (!testnewrenderer)
{ {
@ -126,7 +126,7 @@ void GameInterface::UpdateCameras(double smoothratio)
} }
else else
{ {
render_camtex(camera, camera->pos, camera->sectnum, ang, buildhoriz(camera->shade), buildlook(0), tex, rect, smoothratio); render_camtex(camera, camera->pos, camera->sectnum, ang, buildhoriz(camera->shade), buildang(0), tex, rect, smoothratio);
} }
display_mirror = 0; display_mirror = 0;
}); });
@ -256,8 +256,7 @@ void displayrooms(int snum, double smoothratio)
{ {
int cposx, cposy, cposz, fz, cz; int cposx, cposy, cposz, fz, cz;
short sect; short sect;
binangle cang; binangle cang, rotscrnang;
lookangle rotscrnang;
fixedhoriz choriz; fixedhoriz choriz;
struct player_struct* p; struct player_struct* p;
int tiltcs = 0; // JBF 20030807 int tiltcs = 0; // JBF 20030807
@ -301,7 +300,7 @@ void displayrooms(int snum, double smoothratio)
cang = buildfang(ud.cameraactor->tempang + MulScaleF(((s->ang + 1024 - ud.cameraactor->tempang) & 2047) - 1024, smoothratio, 16)); cang = buildfang(ud.cameraactor->tempang + MulScaleF(((s->ang + 1024 - ud.cameraactor->tempang) & 2047) - 1024, smoothratio, 16));
auto bh = buildhoriz(s->yvel); auto bh = buildhoriz(s->yvel);
renderView(s, s->sectnum, s->x, s->y, s->z - (4 << 8), cang, bh, buildlook(0), smoothratio); renderView(s, s->sectnum, s->x, s->y, s->z - (4 << 8), cang, bh, buildang(0), smoothratio);
} }
else else
{ {
@ -365,7 +364,7 @@ void displayrooms(int snum, double smoothratio)
cposy = spr->pos.y; cposy = spr->pos.y;
cposz = spr->pos.z; cposz = spr->pos.z;
sect = spr->sectnum; sect = spr->sectnum;
rotscrnang = buildlook(0); rotscrnang = buildang(0);
smoothratio = MaxSmoothRatio; smoothratio = MaxSmoothRatio;
viewer = spr; viewer = spr;
} }

View file

@ -207,9 +207,8 @@ void DrawView(double smoothRatio, bool sceneonly)
int playerY; int playerY;
int playerZ; int playerZ;
short nSector; short nSector;
binangle nAngle; binangle nAngle, rotscrnang;
fixedhoriz pan; fixedhoriz pan;
lookangle rotscrnang;
fixed_t dang = IntToFixed(1024); fixed_t dang = IntToFixed(1024);
@ -231,7 +230,7 @@ void DrawView(double smoothRatio, bool sceneonly)
playerZ = sprite[nSprite].z; playerZ = sprite[nSprite].z;
nSector = sprite[nSprite].sectnum; nSector = sprite[nSprite].sectnum;
nAngle = buildang(sprite[nSprite].ang); nAngle = buildang(sprite[nSprite].ang);
rotscrnang = buildlook(0); rotscrnang = buildang(0);
SetGreenPal(); SetGreenPal();

View file

@ -1468,8 +1468,7 @@ drawscreen(PLAYERp pp, double smoothratio)
{ {
extern bool CameraTestMode; extern bool CameraTestMode;
int tx, ty, tz; int tx, ty, tz;
lookangle trotscrnang; binangle tang, trotscrnang;
binangle tang;
fixedhoriz thoriz; fixedhoriz thoriz;
short tsectnum; short tsectnum;
short i,j; short i,j;

View file

@ -481,7 +481,7 @@ void drawroomstotile(int daposx, int daposy, int daposz,
} }
else else
{ {
render_camtex(nullptr, { daposx, daposy, daposz }, dacursectnum, ang, horiz, buildlook(0), tileGetTexture(tilenume), rect, smoothratio); render_camtex(nullptr, { daposx, daposy, daposz }, dacursectnum, ang, horiz, buildang(0), tileGetTexture(tilenume), rect, smoothratio);
} }
}); });

View file

@ -1606,8 +1606,7 @@ DoPlayerTurnVehicleRect(PLAYERp pp, int *x, int *y, int *ox, int *oy)
void void
DoPlayerTurnTurret(PLAYERp pp, float avel) DoPlayerTurnTurret(PLAYERp pp, float avel)
{ {
lookangle diff; binangle new_ang, diff;
binangle new_ang;
SECTOR_OBJECTp sop = pp->sop; SECTOR_OBJECTp sop = pp->sop;
if (sop->drive_angspeed) if (sop->drive_angspeed)