diff --git a/src/screen_trunner.cc b/src/screen_trunner.cc index 24f5530..bef1e76 100644 --- a/src/screen_trunner.cc +++ b/src/screen_trunner.cc @@ -247,7 +247,7 @@ post_check_click: if (surface_reset_anim_timer > SURFACE_RESET_TIME) { flags.reset(0); } else { - for (auto &tri : surface_triangles) { + for (auto &tri : *surface_triangles) { tri.update(dt); } } @@ -335,9 +335,9 @@ bool TRunnerScreen::draw() { unsigned char alpha = ((1.0F - surface_reset_anim_timer / SURFACE_RESET_TIME_TRI_DRAW) * 255.0F); - surface_triangles.at(x * 2 + y * SURFACE_UNIT_WIDTH * 2) + surface_triangles->at(x * 2 + y * SURFACE_UNIT_WIDTH * 2) .draw(Color{color.r, color.g, color.b, alpha}); - surface_triangles.at(x * 2 + 1 + y * SURFACE_UNIT_WIDTH * 2) + surface_triangles->at(x * 2 + 1 + y * SURFACE_UNIT_WIDTH * 2) .draw(Color{color.r, color.g, color.b, alpha}); } } diff --git a/src/screen_trunner.h b/src/screen_trunner.h index 8b46042..ab27884 100644 --- a/src/screen_trunner.h +++ b/src/screen_trunner.h @@ -6,6 +6,7 @@ // standard library includes #include #include +#include #include // third party includes @@ -62,8 +63,6 @@ class TRunnerScreen : public Screen { SURFACE_UNIT_WIDTH * SURFACE_UNIT_HEIGHT> surface; std::array surface_bbs; - std::array - surface_triangles; std::array walkers; Camera3D camera; @@ -79,6 +78,9 @@ class TRunnerScreen : public Screen { Vector3 camera_pos; Vector3 camera_target; Vector3 mouse_hit; + std::unique_ptr > + surface_triangles; unsigned int idx_hit; std::optional controlled_walker_idx; const int left_text_width; diff --git a/src/surface_triangle.h b/src/surface_triangle.h index b13539e..1b09d13 100644 --- a/src/surface_triangle.h +++ b/src/surface_triangle.h @@ -3,6 +3,7 @@ // standard library includes #include +#include // third party includes #include @@ -29,10 +30,11 @@ struct SurfaceTriangle { }; template -extern std::array surface_to_triangles( - const std::array &surface, - const std::size_t width) { - std::array triangles; +extern std::unique_ptr > +surface_to_triangles(const std::array &surface, + const std::size_t width) { + std::unique_ptr > triangles = + std::make_unique >(); for (std::size_t idx = 0; idx < ASize; ++idx) { std::size_t x = idx % width; @@ -44,20 +46,20 @@ extern std::array surface_to_triangles( std::size_t toffset = x * 2 + y * width * 2; if (!surface[idx].has_value()) { - triangles.at(toffset) = SurfaceTriangle(); - triangles.at(toffset + 1) = SurfaceTriangle(); + triangles->at(toffset) = SurfaceTriangle(); + triangles->at(toffset + 1) = SurfaceTriangle(); continue; } const auto &surface_unit = surface[idx].value(); - triangles.at(toffset) = SurfaceTriangle( + triangles->at(toffset) = SurfaceTriangle( Vector3{0.5F, surface_unit.ne, -0.5F}, Vector3{-0.5F, surface_unit.nw, -0.5F}, Vector3{-0.5F, surface_unit.sw, 0.5F}, Vector3{posx, (surface_unit.ne + surface_unit.nw + surface_unit.sw) / 3.0F, posz}); - triangles.at(toffset + 1) = SurfaceTriangle( + triangles->at(toffset + 1) = SurfaceTriangle( Vector3{0.5F, surface_unit.ne, -0.5F}, Vector3{-0.5F, surface_unit.sw, 0.5F}, Vector3{0.5F, surface_unit.se, 0.5F},