From 2d8397d2891e447642cae81cdef5550defbd4238 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 5 Oct 2024 13:11:23 +0200 Subject: [PATCH] as_poly() to eliminate dynamic_cast --- celldrawer.cpp | 2 +- drawing.cpp | 6 ++++-- graph.cpp | 4 ++-- mapeditor.cpp | 2 +- screenshot.cpp | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/celldrawer.cpp b/celldrawer.cpp index 6d08f926..562457d1 100644 --- a/celldrawer.cpp +++ b/celldrawer.cpp @@ -2385,7 +2385,7 @@ void celldrawer::draw_wall_full() { if(rosedist(c2) < rd) placeSidewall(c, i, SIDE_WALL, V, rcol); for(int i=t; i(&*(ptds[i])); + auto p = ptds[i]->as_poly(); if(p) p->prio = PPR::TRANSPARENT_WALL; } } diff --git a/drawing.cpp b/drawing.cpp index e0f794a2..171db6a3 100644 --- a/drawing.cpp +++ b/drawing.cpp @@ -62,6 +62,7 @@ struct drawqueueitem { virtual ~drawqueueitem() = default; /** \brief When minimizing OpenGL calls, we need to group items of the same color, etc. together. This value is used as an extra sorting key. */ virtual color_t outline_group() = 0; + virtual dqi_poly* as_poly() { return nullptr; } }; /** \brief Drawqueueitem used to draw polygons. The majority of drawqueueitems fall here. */ @@ -96,6 +97,7 @@ struct dqi_poly : drawqueueitem { #endif void draw_back() override; color_t outline_group() override { return outline; } + virtual dqi_poly* as_poly() { return this; } }; /** \brief Drawqueueitem used to draw lines */ @@ -2476,7 +2478,7 @@ EX void draw_main() { } for(auto& ptd: ptds) if(ptd->prio == PPR::OUTCIRCLE) { - auto c = dynamic_cast (&*ptd); + auto c = ptd->as_poly(); if(c) { c->color = 0; c->outline = 0; } } @@ -2637,7 +2639,7 @@ EX void drawqueue() { int pp = int(p); if(qp0[pp] == qp[pp]) continue; auto get_z = [&] (const unique_ptr& p) -> ld { - auto d = dynamic_cast (&*p); + auto d = p->as_poly(); if(!d) return 0; hyperpoint h = Hypc; diff --git a/graph.cpp b/graph.cpp index 0def196a..23d8882e 100644 --- a/graph.cpp +++ b/graph.cpp @@ -3921,7 +3921,7 @@ EX void pushdown(cell *c, int& q, const shiftmatrix &V, double down, bool rezoom #if MAXMDIM >= 4 if(GDIM == 3) { for(int i=q; i (&*ptds[q++]); + auto pp = ptds[q++]->as_poly(); if(!pp) continue; auto& ptd = *pp; ptd.V = ptd.V * lzpush(+down); @@ -3942,7 +3942,7 @@ EX void pushdown(cell *c, int& q, const shiftmatrix &V, double down, bool rezoom } while(q < isize(ptds)) { - auto pp = dynamic_cast (&*ptds[q++]); + auto pp = ptds[q++]->as_poly(); if(!pp) continue; auto& ptd = *pp; diff --git a/mapeditor.cpp b/mapeditor.cpp index 99ec1074..633320bf 100644 --- a/mapeditor.cpp +++ b/mapeditor.cpp @@ -2654,7 +2654,7 @@ EX namespace mapeditor { initShape(sg, id); for(int i=0; i (&*ptds[i]); + auto pp = ptds[i]->as_poly(); if(!pp) continue; auto& ptd = *pp; diff --git a/screenshot.cpp b/screenshot.cpp index 879e878b..02f703f3 100644 --- a/screenshot.cpp +++ b/screenshot.cpp @@ -502,7 +502,7 @@ EX always_false in; EX void render() { #if MAXMDIM >= 4 for(auto& p: ptds) { - auto p2 = dynamic_cast(&*p); + auto p2 = p->as_poly(); if(p2) prepare(*p2); } @@ -524,7 +524,7 @@ EX always_false in; #endif for(auto& p: ptds) { - auto p2 = dynamic_cast(&*p); + auto p2 = p->as_poly(); if(p2) polygon(*p2); }