From f614e661d2001a5ca789fa59a7fd5976e94a9f2e Mon Sep 17 00:00:00 2001 From: orng Date: Sat, 28 Mar 2026 13:34:20 -0500 Subject: [PATCH] refactor: remove `PolygonArray` --- Minecraft.Client/Rendering/Cube.cpp | 35 ++++++++++---------------- Minecraft.Client/Rendering/Cube.h | 2 +- Minecraft.Client/Rendering/Polygon.h | 1 + Minecraft.World/Util/ArrayWithLength.h | 1 - 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/Minecraft.Client/Rendering/Cube.cpp b/Minecraft.Client/Rendering/Cube.cpp index 07222aa43..67222bf94 100644 --- a/Minecraft.Client/Rendering/Cube.cpp +++ b/Minecraft.Client/Rendering/Cube.cpp @@ -20,16 +20,8 @@ Cube::Cube(ModelPart* modelPart, int xTexOffs, int yTexOffs, float x0, float y0, vertices({Vertex{0, 0, 0, 0, 0}, Vertex{0, 0, 0, 0, 0}, Vertex{0, 0, 0, 0, 0}, Vertex{0, 0, 0, 0, 0}, Vertex{0, 0, 0, 0, 0}, Vertex{0, 0, 0, 0, 0}, - Vertex{0, 0, 0, 0, 0}, Vertex{0, 0, 0, 0, 0}}) { - // this->x0 = x0; - // this->y0 = y0; - // this->z0 = z0; - // this->x1 = x0 + w; - // this->y1 = y0 + h; - // this->z1 = z0 + d; - - polygons = PolygonArray(6); - + Vertex{0, 0, 0, 0, 0}, Vertex{0, 0, 0, 0, 0}}), + polygons({}) { float x1 = x0 + w; float y1 = y0 + h; float z1 = z0 + d; @@ -69,55 +61,54 @@ Cube::Cube(ModelPart* modelPart, int xTexOffs, int yTexOffs, float x0, float y0, // 4J - added ability to mask individual faces int faceCount = 0; if (faceMask & 1) - polygons[faceCount++] = new _Polygon( + polygons[faceCount++] = _Polygon( std::array{l1, u1, u2, l2}, xTexOffs + d + w, yTexOffs + d, xTexOffs + d + w + d, yTexOffs + d + h, modelPart->xTexSize, modelPart->yTexSize); // Right if (faceMask & 2) - polygons[faceCount++] = new _Polygon( + polygons[faceCount++] = _Polygon( std::array{u0, l0, l3, u3}, xTexOffs + 0, yTexOffs + d, xTexOffs + d, yTexOffs + d + h, modelPart->xTexSize, modelPart->yTexSize); // Left if (faceMask & 4) - polygons[faceCount++] = new _Polygon( + polygons[faceCount++] = _Polygon( std::array{l1, l0, u0, u1}, xTexOffs + d, yTexOffs + 0, xTexOffs + d + w, yTexOffs + d, modelPart->xTexSize, modelPart->yTexSize); // Up if (bFlipPoly3UVs) { if (faceMask & 8) - polygons[faceCount++] = new _Polygon( + polygons[faceCount++] = _Polygon( std::array{u2, u3, l3, l2}, xTexOffs + d + w, yTexOffs + 0, xTexOffs + d + w + w, yTexOffs + d, modelPart->xTexSize, modelPart->yTexSize); // Down } else { if (faceMask & 8) - polygons[faceCount++] = new _Polygon( + polygons[faceCount++] = _Polygon( std::array{u2, u3, l3, l2}, xTexOffs + d + w, yTexOffs + d, xTexOffs + d + w + w, yTexOffs + 0, modelPart->xTexSize, modelPart->yTexSize); // Down } if (faceMask & 16) - polygons[faceCount++] = new _Polygon( + polygons[faceCount++] = _Polygon( std::array{u1, u0, u3, u2}, xTexOffs + d, yTexOffs + d, xTexOffs + d + w, yTexOffs + d + h, modelPart->xTexSize, modelPart->yTexSize); // Front if (faceMask & 32) - polygons[faceCount++] = new _Polygon( + polygons[faceCount++] = _Polygon( std::array{l0, l1, l2, l3}, xTexOffs + d + w + d, yTexOffs + d, xTexOffs + d + w + d + w, yTexOffs + d + h, modelPart->xTexSize, modelPart->yTexSize); // Back - polygons.length = faceCount; if (modelPart->bMirror) { - for (unsigned int i = 0; i < polygons.length; i++) - polygons[i]->mirror(); + for (unsigned int i = 0; i < polygons.size(); i++) + polygons[i].mirror(); } } void Cube::render(Tesselator* t, float scale) { - for (int i = 0; i < polygons.length; i++) { - polygons[i]->render(t, scale); + for (int i = 0; i < polygons.size(); i++) { + polygons[i].render(t, scale); } } diff --git a/Minecraft.Client/Rendering/Cube.h b/Minecraft.Client/Rendering/Cube.h index 1debdc556..1a3974275 100644 --- a/Minecraft.Client/Rendering/Cube.h +++ b/Minecraft.Client/Rendering/Cube.h @@ -9,7 +9,7 @@ class Model; class Cube { private: std::array vertices; - PolygonArray polygons; + std::array<_Polygon, 6> polygons; public: const float x0, y0, z0, x1, y1, z1; diff --git a/Minecraft.Client/Rendering/Polygon.h b/Minecraft.Client/Rendering/Polygon.h index 77c4a90a5..a9ecf5638 100644 --- a/Minecraft.Client/Rendering/Polygon.h +++ b/Minecraft.Client/Rendering/Polygon.h @@ -15,6 +15,7 @@ private: bool _flipNormal; public: + _Polygon() = default; _Polygon(std::span vertices); _Polygon(std::span vertices, int u0, int v0, int u1, int v1, float xTexSize, float yTexSize); diff --git a/Minecraft.World/Util/ArrayWithLength.h b/Minecraft.World/Util/ArrayWithLength.h index 8f3668342..c476a372f 100644 --- a/Minecraft.World/Util/ArrayWithLength.h +++ b/Minecraft.World/Util/ArrayWithLength.h @@ -114,7 +114,6 @@ typedef arrayWithLength TileArray; typedef arrayWithLength StatArray; typedef arrayWithLength MobCategoryArray; typedef arrayWithLength FileArray; -typedef arrayWithLength<_Polygon*> PolygonArray; typedef arrayWithLength ServerLevelArray; typedef arrayWithLength MultiPlayerLevelArray; typedef arrayWithLength LevelArray;