Skip to content

Commit ea33d03

Browse files
committed
use static vector
1 parent 1e61199 commit ea33d03

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

gframe/drawing.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,24 +195,20 @@ void Game::DrawSelectionLine(irr::video::S3DVertex* vec, bool stipple, irr::vide
195195
bool projected;
196196
};
197197
ProjectedEdge projectedEdges[4];
198-
irr::f32 totalProjectedLen = 0.0f;
199198
for(int i = 0; i < 4; ++i) {
200199
auto& edge = projectedEdges[i];
201200
edge.projected = projectPoint(wp[edgeStart[i]], edge.start) && projectPoint(wp[edgeEnd[i]], edge.end);
202201
edge.screenLen = 1.0f;
203-
if(edge.projected) {
202+
if(edge.projected)
204203
edge.screenLen = std::sqrt((edge.start.screen - edge.end.screen).getLengthSQ());
205-
totalProjectedLen += edge.screenLen;
206-
}
207204
}
208-
const size_t estimatedSegments = static_cast<size_t>(totalProjectedLen * 0.5f) + 4;
209-
size_t reserveVertices = estimatedSegments * THICK_LINE_VERTICES_PER_SEGMENT;
210-
if(reserveVertices > MAX_THICK_LINE_BATCH_VERTICES)
211-
reserveVertices = MAX_THICK_LINE_BATCH_VERTICES;
212-
std::vector<irr::video::S3DVertex> vertices;
213-
std::vector<irr::u16> indices;
214-
vertices.reserve(reserveVertices);
215-
indices.reserve((reserveVertices / THICK_LINE_VERTICES_PER_SEGMENT) * THICK_LINE_INDICES_PER_SEGMENT);
205+
constexpr size_t RESERVED_THICK_LINE_SEGMENTS = 128;
206+
static std::vector<irr::video::S3DVertex> vertices;
207+
static std::vector<irr::u16> indices;
208+
vertices.clear();
209+
indices.clear();
210+
vertices.reserve(RESERVED_THICK_LINE_SEGMENTS * THICK_LINE_VERTICES_PER_SEGMENT);
211+
indices.reserve(RESERVED_THICK_LINE_SEGMENTS * THICK_LINE_INDICES_PER_SEGMENT);
216212
const auto drawBatch = [&]() {
217213
if(indices.empty())
218214
return;

0 commit comments

Comments
 (0)