- Backend update from Raze.

This commit is contained in:
Christoph Oelckers 2022-10-14 20:11:05 +02:00
parent 169053587c
commit c0c9f8e15c
9 changed files with 81 additions and 36 deletions

View file

@ -1742,10 +1742,10 @@ void DAutomap::drawMline (mline_t *ml, const AMColor &color)
const int x2 = f_x + fl.b.x;
const int y2 = f_y + fl.b.y;
if (am_linethickness >= 2) {
twod->AddThickLine(x1, y1, x2, y2, am_linethickness, color.RGB, uint8_t(am_linealpha * 255));
twod->AddThickLine(DVector2(x1, y1), DVector2(x2, y2), am_linethickness, color.RGB, uint8_t(am_linealpha * 255));
} else {
// Use more efficient thin line drawing routine.
twod->AddLine(x1, y1, x2, y2, nullptr, color.RGB, uint8_t(am_linealpha * 255));
twod->AddLine(DVector2(x1, y1), DVector2(x2, y2), nullptr, color.RGB, uint8_t(am_linealpha * 255));
}
}
}

View file

@ -1040,7 +1040,7 @@ void F2DDrawer::ClearScreen(PalEntry color)
//
//==========================================================================
void F2DDrawer::AddLine(double x1, double y1, double x2, double y2, const IntRect* clip, uint32_t color, uint8_t alpha)
void F2DDrawer::AddLine(const DVector2& v1, const DVector2& v2, const IntRect* clip, uint32_t color, uint8_t alpha)
{
PalEntry p = (PalEntry)color;
p.a = alpha;
@ -1064,8 +1064,8 @@ void F2DDrawer::AddLine(double x1, double y1, double x2, double y2, const IntRec
dg.transform = this->transform;
dg.transform.Cells[0][2] += offset.X;
dg.transform.Cells[1][2] += offset.Y;
mVertices[dg.mVertIndex].Set(x1, y1, 0, 0, 0, p);
mVertices[dg.mVertIndex+1].Set(x2, y2, 0, 0, 0, p);
mVertices[dg.mVertIndex].Set(v1.X, v1.Y, 0, 0, 0, p);
mVertices[dg.mVertIndex+1].Set(v2.X, v2.Y, 0, 0, 0, p);
AddCommand(&dg);
}
@ -1075,23 +1075,20 @@ void F2DDrawer::AddLine(double x1, double y1, double x2, double y2, const IntRec
//
//==========================================================================
void F2DDrawer::AddThickLine(int x1, int y1, int x2, int y2, double thickness, uint32_t color, uint8_t alpha)
void F2DDrawer::AddThickLine(const DVector2& v1, const DVector2& v2, double thickness, uint32_t color, uint8_t alpha)
{
PalEntry p = (PalEntry)color;
p.a = alpha;
DVector2 point0(x1, y1);
DVector2 point1(x2, y2);
DVector2 delta = point1 - point0;
DVector2 perp(-delta.Y, delta.X);
DVector2 delta = v2 - v1;
DVector2 perp = delta.Rotated90CCW();
perp.MakeUnit();
perp *= thickness / 2;
DVector2 corner0 = point0 + perp;
DVector2 corner1 = point0 - perp;
DVector2 corner2 = point1 + perp;
DVector2 corner3 = point1 - perp;
DVector2 corner0 = v1 + perp;
DVector2 corner1 = v1 - perp;
DVector2 corner2 = v2 + perp;
DVector2 corner3 = v2 - perp;
RenderCommand dg;

View file

@ -227,8 +227,8 @@ public:
void AddClear(int left, int top, int right, int bottom, int palcolor, uint32_t color);
void AddLine(double x1, double y1, double x2, double y2, const IntRect* clip, uint32_t color, uint8_t alpha = 255);
void AddThickLine(int x1, int y1, int x2, int y2, double thickness, uint32_t color, uint8_t alpha = 255);
void AddLine(const DVector2& v1, const DVector2& v2, const IntRect* clip, uint32_t color, uint8_t alpha = 255);
void AddThickLine(const DVector2& v1, const DVector2& v2, double thickness, uint32_t color, uint8_t alpha = 255);
void AddPixel(int x1, int y1, uint32_t color);
void AddEnableStencil(bool on);

View file

@ -1555,10 +1555,10 @@ void VirtualToRealCoordsInt(F2DDrawer *drawer, int &x, int &y, int &w, int &h,
//
//==========================================================================
static void DrawLine(int x0, int y0, int x1, int y1, uint32_t realcolor, int alpha)
static void DrawLine(const DVector2& v1, const DVector2& v2, uint32_t realcolor, int alpha)
{
if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
twod->AddLine((float)x0, (float)y0, (float)x1, (float)y1, nullptr, realcolor | MAKEARGB(255, 0, 0, 0), alpha);
twod->AddLine(v1, v2, nullptr, realcolor | MAKEARGB(255, 0, 0, 0), alpha);
}
DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawLine, DrawLine)
@ -1570,7 +1570,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawLine, DrawLine)
PARAM_INT(y1);
PARAM_INT(color);
PARAM_INT(alpha);
DrawLine(x0, y0, x1, y1, color, alpha);
DrawLine(DVector2(x0, y0), DVector2(x1, y1), color, alpha);
return 0;
}
@ -1583,15 +1583,15 @@ DEFINE_ACTION_FUNCTION(FCanvas, DrawLine)
PARAM_INT(y1);
PARAM_INT(color);
PARAM_INT(alpha);
self->Drawer.AddLine((float)x0, (float)y0, (float)x1, (float)y1, nullptr, color | MAKEARGB(255, 0, 0, 0), alpha);
self->Drawer.AddLine(DVector2(x0, y0), DVector2(x1, y1), nullptr, color | MAKEARGB(255, 0, 0, 0), alpha);
self->Tex->NeedUpdate();
return 0;
}
static void DrawThickLine(int x0, int y0, int x1, int y1, double thickness, uint32_t realcolor, int alpha)
static void DrawThickLine(const DVector2& v1, const DVector2& v2, double thickness, uint32_t realcolor, int alpha)
{
if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
twod->AddThickLine(x0, y0, x1, y1, thickness, realcolor, alpha);
twod->AddThickLine(v1, v2, thickness, realcolor, alpha);
}
DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawThickLine, DrawThickLine)
@ -1604,7 +1604,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawThickLine, DrawThickLine)
PARAM_FLOAT(thickness);
PARAM_INT(color);
PARAM_INT(alpha);
DrawThickLine(x0, y0, x1, y1, thickness, color, alpha);
DrawThickLine(DVector2(x0, y0), DVector2(x1, y1), thickness, color, alpha);
return 0;
}
@ -1618,7 +1618,7 @@ DEFINE_ACTION_FUNCTION(FCanvas, DrawThickLine)
PARAM_FLOAT(thickness);
PARAM_INT(color);
PARAM_INT(alpha);
self->Drawer.AddThickLine(x0, y0, x1, y1, thickness, color, alpha);
self->Drawer.AddThickLine(DVector2(x0, y0), DVector2(x1, y1), thickness, color, alpha);
self->Tex->NeedUpdate();
return 0;
}

View file

@ -302,6 +302,7 @@ const char *GetSampleTypeName(SampleType type)
{
case SampleType_UInt8: return "Unsigned 8-bit";
case SampleType_Int16: return "Signed 16-bit";
default: break;
}
return "(invalid sample type)";
}

View file

@ -986,7 +986,7 @@ bool IsAbsPath(const char *name)
if (IsSeperator(name[0])) return true;
#ifdef _WIN32
/* [A-Za-z]: (for Windows) */
if (isalpha(name[0]) && name[1] == ':') return true;
if (isalpha((uint8_t)name[0]) && name[1] == ':') return true;
#endif /* _WIN32 */
return 0;
}

View file

@ -15,24 +15,28 @@ __forceinline constexpr int64_t DivScaleL(int64_t a, int64_t b, int shift) { ret
#include "xs_Float.h"
template<int b = 16>
inline fixed_t FloatToFixed(double f)
{
return xs_Fix<16>::ToFix(f);
return xs_Fix<b>::ToFix(f);
}
template<int b = 16>
inline constexpr fixed_t IntToFixed(int32_t f)
{
return f << FRACBITS;
return f << b;
}
template<int b = 16>
inline constexpr double FixedToFloat(fixed_t f)
{
return f * (1/65536.);
return f * (1. / (1 << b));
}
template<int b = 16>
inline constexpr int32_t FixedToInt(fixed_t f)
{
return (f + FRACUNIT/2) >> FRACBITS;
return (f + (1 << (b-1))) >> b;
}
inline unsigned FloatToAngle(double f)

View file

@ -47,6 +47,7 @@
#include "xs_Float.h"
#include "math/cmath.h"
#include "basics.h"
#include "cmdlib.h"
#define EQUAL_EPSILON (1/65536.)
@ -275,7 +276,7 @@ struct TVector2
TAngle<vec_t> Angle() const;
// Returns a rotated vector. angle is in degrees.
TVector2 Rotated (double angle)
TVector2 Rotated (double angle) const
{
double cosval = g_cosdeg (angle);
double sinval = g_sindeg (angle);
@ -284,13 +285,19 @@ struct TVector2
// Returns a rotated vector. angle is in degrees.
template<class T>
TVector2 Rotated(TAngle<T> angle)
TVector2 Rotated(TAngle<T> angle) const
{
double cosval = angle.Cos();
double sinval = angle.Sin();
return TVector2(X*cosval - Y*sinval, Y*cosval + X*sinval);
}
// Returns a rotated vector. angle is in degrees.
TVector2 Rotated(const double cosval, const double sinval) const
{
return TVector2(X*cosval - Y*sinval, Y*cosval + X*sinval);
}
// Returns a vector rotated 90 degrees clockwise.
TVector2 Rotated90CW()
{
@ -1385,8 +1392,7 @@ public:
int Sgn() const
{
const auto normalized = (signed int)BAMs();
return (normalized > 0) - (normalized < 0);
return ::Sgn(int(BAMs()));
}
};
@ -1414,6 +1420,12 @@ inline TAngle<T> absangle(const TAngle<T> &a1, const TAngle<T> &a2)
return fabs((a1 - a2).Normalized180());
}
template<class T>
inline TAngle<T> clamp(const TAngle<T> &angle, const TAngle<T> &min, const TAngle<T> &max)
{
return TAngle<T>::fromDeg(clamp(angle.Degrees(), min.Degrees(), max.Degrees()));
}
inline TAngle<double> VecToAngle(double x, double y)
{
return TAngle<double>::fromRad(g_atan2(y, x));
@ -1449,6 +1461,36 @@ TAngle<T> TVector3<T>::Pitch() const
return -VecToAngle(TVector2<T>(X, Y).Length(), Z);
}
template<class T>
inline TVector2<T> clamp(const TVector2<T> &vec, const TVector2<T> &min, const TVector2<T> &max)
{
return TVector2<T>(clamp(vec.X, min.X, max.X), clamp(vec.Y, min.Y, max.Y));
}
template<class T>
inline TVector2<T> interpolatedvec2(const TVector2<T> &ovec, const TVector2<T> &vec, const double scale)
{
return ovec + ((vec - ovec) * scale);
}
template<class T>
inline TVector3<T> interpolatedvec3(const TVector3<T> &ovec, const TVector3<T> &vec, const double scale)
{
return ovec + ((vec - ovec) * scale);
}
template<class T>
inline TVector4<T> interpolatedvec4(const TVector4<T> &ovec, const TVector4<T> &vec, const double scale)
{
return ovec + ((vec - ovec) * scale);
}
template<class T>
inline TAngle<T> interpolatedangle(const TAngle<T> &oang, const TAngle<T> &ang, const double scale)
{
return oang + (deltaangle(oang, ang) * scale);
}
// Much of this is copied from TVector3. Is all that functionality really appropriate?
template<class vec_t>
struct TRotator
@ -1458,7 +1500,6 @@ struct TRotator
Angle Pitch; // up/down
Angle Yaw; // left/right
Angle Roll; // rotation about the forward axis.
Angle CamRoll; // Roll specific to actor cameras. Used by quakes.
TRotator() = default;
@ -1635,7 +1676,9 @@ typedef TAngle<double> DAngle;
constexpr DAngle nullAngle = DAngle::fromDeg(0.);
constexpr FAngle nullFAngle = FAngle::fromDeg(0.);
constexpr DAngle DAngle22_5 = DAngle::fromDeg(22.5);
constexpr DAngle DAngle45 = DAngle::fromDeg(45);
constexpr DAngle DAngle60 = DAngle::fromDeg(60);
constexpr DAngle DAngle90 = DAngle::fromDeg(90);
constexpr DAngle DAngle180 = DAngle::fromDeg(180);
constexpr DAngle DAngle270 = DAngle::fromDeg(270);