- eliminate all use of integer coordinates in the sector geometry creation code.

This eliminates the last small remnants of texture twitching in SW as well.
This commit is contained in:
Christoph Oelckers 2022-08-19 19:01:21 +02:00
parent 3a9f9988f4
commit 32e1f07b60
3 changed files with 25 additions and 24 deletions

View file

@ -73,29 +73,30 @@ struct sectionbuildsector
TArray<sectionbuild> sections;
};
static bool cmpLess(int a, int b)
static bool cmpLess(double a, double b)
{
return a < b;
}
static bool cmpGreater(int a, int b)
static bool cmpGreater(double a, double b)
{
return a > b;
}
static int sgn(int v)
static int sgn(double v)
{
return (v > 0) - (v < 0);
// Don't try to be smart here - the compiler won't like it.
return (v > 0)? 1: (v < 0)? -1 : 0;
}
static int dist(const vec2_t& a, const vec2_t& b)
static int dist(const DVector2& a, const DVector2& b)
{
// We only need to know if it's 1 or higher, so this is enough.
return abs(a.X - b.X) + abs(a.Y - b.Y);
return fabs(a.X - b.X) + fabs(a.Y - b.Y);
}
using cmp = bool(*)(int, int);
using cmp = bool(*)(double, double);
//==========================================================================
//
@ -103,7 +104,7 @@ using cmp = bool(*)(int, int);
//
//==========================================================================
void StripLoop(TArray<vec2_t>& points)
void StripLoop(TArray<DVector2>& points)
{
for (int p = 0; p < (int)points.Size(); p++)
{
@ -126,7 +127,7 @@ void StripLoop(TArray<vec2_t>& points)
}
else if ((points[prev].X == points[p].X && points[next].X == points[p].X && sgn(points[next].Y - points[p].Y) == sgn(points[prev].Y - points[p].Y)) ||
(points[prev].Y == points[p].Y && points[next].Y == points[p].Y && sgn(points[next].X - points[p].X) == sgn(points[prev].X - points[p].X)) ||
dist(points[prev], points[next]) <= 1) // if the two points are extremely close together, we may also ignore the intermediate point.
dist(points[prev], points[next]) <= 1/256.) // if the two points are extremely close together, we may also ignore the intermediate point.
{
// both connections exit the point into the same direction. Here it is sufficient to just delete it so that the neighboring ones connect directly.
points.Delete(p);
@ -144,11 +145,11 @@ void StripLoop(TArray<vec2_t>& points)
//
//==========================================================================
int GetWindingOrder(TArray<vec2_t>& poly, cmp comp1 = cmpLess, cmp comp2 = cmpGreater)
int GetWindingOrder(TArray<DVector2>& poly, cmp comp1 = cmpLess, cmp comp2 = cmpGreater)
{
int n = poly.Size();
int minx = poly[0].X;
int miny = poly[0].Y;
double minx = poly[0].X;
double miny = poly[0].Y;
int m = 0;
for (int i = 0; i < n; i++)
@ -186,11 +187,11 @@ int GetWindingOrder(TArray<int>& poly)
{
// This is more complicated than it should be due to how doors are designed in Build.
// Overlapping and backtracking lines are quite common and need to be removed from the data before determining the winding order.
TArray<vec2_t> points(poly.Size(), true);
TArray<DVector2> points(poly.Size(), true);
int i = 0;
for (auto& index : poly)
{
points[i++] = wall[index].wall_int_pos();
points[i++] = wall[index].pos;
}
StripLoop(points);
if (points.Size() == 0) return 1; // Sector has no dimension. We must accept this as valid here.

View file

@ -19,8 +19,8 @@ struct SectionLine
int wall;
int partner;
vec2_t v1() const { return ::wall[startpoint].wall_int_pos(); }
vec2_t v2() const { return ::wall[endpoint].wall_int_pos(); }
DVector2 v1() const { return ::wall[startpoint].pos; }
DVector2 v2() const { return ::wall[endpoint].pos; }
walltype* wallp() const { return &::wall[wall]; }
SectionLine* partnerLine() const;
@ -53,7 +53,7 @@ extern TArray<Section> sections;
extern TArrayView<TArrayView<int>> sectionsPerSector;
void hw_CreateSections();
using Outline = TArray<TArray<vec2_t>>;
using Outline = TArray<TArray<DVector2>>;
using Point = std::pair<float, float>;
using FOutline = std::vector<std::vector<Point>>; // Data type was chosen so it can be passed directly into Earcut.
Outline BuildOutline(Section* section);

View file

@ -232,8 +232,8 @@ static int OutlineToFloat(Outline& outl, FOutline& polygon)
count += outl[i].Size();
for (unsigned j = 0; j < outl[i].Size(); j++)
{
float X = (outl[i][j].X) * inttoworld;
float Y = (outl[i][j].Y) * -inttoworld;
float X = outl[i][j].X;
float Y = -(outl[i][j].Y);
if (fabs(X) > 32768.f || fabs(Y) > 32768.f)
{
// If we get here there's some fuckery going around with the coordinates. Let's better abort and wait for things to realign.
@ -437,9 +437,9 @@ void SectionGeometry::CreatePlaneMesh(Section* section, int plane, const FVector
auto texture = tileGetTexture(plane ? sectorp->ceilingpicnum : sectorp->floorpicnum);
auto& sdata = data[section->index];
auto& entry = sdata.planes[plane];
int fz = sectorp->int_floorz(), cz = sectorp->int_ceilingz();
sectorp->set_int_floorz(0, true);
sectorp->set_int_ceilingz(0, true);
double fz = sectorp->floorz, cz = sectorp->ceilingz;
sectorp->setfloorz(0, true);
sectorp->setceilingz(0, true);
UVCalculator uvcalc(sectorp, plane, texture, offset);
@ -456,8 +456,8 @@ void SectionGeometry::CreatePlaneMesh(Section* section, int plane, const FVector
PlanesAtPoint(sectorp, pt.X, -pt.Y, plane ? &pt.Z : nullptr, !plane ? &pt.Z : nullptr);
tc = uvcalc.GetUV(pt.X, -pt.Y, pt.Z);
}
sectorp->set_int_floorz(fz, true);
sectorp->set_int_ceilingz(cz, true);
sectorp->setfloorz(fz, true);
sectorp->setceilingz(cz, true);
entry.normal = CalcNormal(sectorp, plane);
}