diff --git a/source/core/rendering/hw_sections.cpp b/source/core/rendering/hw_sections.cpp index e31e732fd..a7e0168e9 100644 --- a/source/core/rendering/hw_sections.cpp +++ b/source/core/rendering/hw_sections.cpp @@ -73,29 +73,30 @@ struct sectionbuildsector TArray 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& points) +void StripLoop(TArray& points) { for (int p = 0; p < (int)points.Size(); p++) { @@ -126,7 +127,7 @@ void StripLoop(TArray& 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& points) // //========================================================================== -int GetWindingOrder(TArray& poly, cmp comp1 = cmpLess, cmp comp2 = cmpGreater) +int GetWindingOrder(TArray& 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& 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 points(poly.Size(), true); + TArray 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. diff --git a/source/core/rendering/hw_sections.h b/source/core/rendering/hw_sections.h index 4737baf26..dc66f302d 100644 --- a/source/core/rendering/hw_sections.h +++ b/source/core/rendering/hw_sections.h @@ -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
sections; extern TArrayView> sectionsPerSector; void hw_CreateSections(); -using Outline = TArray>; +using Outline = TArray>; using Point = std::pair; using FOutline = std::vector>; // Data type was chosen so it can be passed directly into Earcut. Outline BuildOutline(Section* section); diff --git a/source/core/sectorgeometry.cpp b/source/core/sectorgeometry.cpp index a1d4e21cb..a53a23488 100644 --- a/source/core/sectorgeometry.cpp +++ b/source/core/sectorgeometry.cpp @@ -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); }