diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-07-22 18:56:19 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-07-22 21:17:41 +0200 |
commit | 125cb3c0feb94e51b830957fb44ccc709b6afa61 (patch) | |
tree | 9dfc68af6c2c010a31ff9d3418ccab2f221da448 /src/chunk.hpp | |
parent | 391e513ab8100b4ef0ab783354640fcff2be6c36 (diff) |
src/chunk: move big arrays to separate heap allocation
Diffstat (limited to 'src/chunk.hpp')
-rw-r--r-- | src/chunk.hpp | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/chunk.hpp b/src/chunk.hpp index 505e335d..a41ed9a0 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -5,7 +5,7 @@ #include "src/RTree.h" #include <type_traits> #include <array> -#include <memory> +#include <Corrade/Containers/Pointer.h> #include <Magnum/GL/Mesh.h> namespace Corrade::Containers { template<typename T, typename D> class Array; } @@ -94,6 +94,8 @@ struct chunk final using RTree = ::RTree<object_id, float, 2, float>; + void ensure_alloc_ground(); + void ensure_alloc_walls(); ground_mesh_tuple ensure_ground_mesh() noexcept; tile_atlas* ground_atlas_at(size_t i) const noexcept; wall_mesh_tuple ensure_wall_mesh() noexcept; @@ -115,12 +117,20 @@ struct chunk final const std::vector<std::shared_ptr<entity>>& entities() const; private: - std::array<std::shared_ptr<tile_atlas>, TILE_COUNT> _ground_atlases; - std::array<uint8_t, TILE_COUNT> ground_indexes = {}; - std::array<variant_t, TILE_COUNT> _ground_variants = {}; - std::array<std::shared_ptr<tile_atlas>, TILE_COUNT*2> _wall_atlases; // todo make into vector - std::array<uint16_t, TILE_COUNT*2> wall_indexes = {}; - std::array<variant_t, TILE_COUNT*2> _wall_variants = {}; + struct ground_stuff { + std::array<std::shared_ptr<tile_atlas>, TILE_COUNT> _ground_atlases; + std::array<uint8_t, TILE_COUNT> ground_indexes = {}; + std::array<variant_t, TILE_COUNT> _ground_variants = {}; + }; + + struct wall_stuff { + std::array<std::shared_ptr<tile_atlas>, TILE_COUNT*2> _wall_atlases; // todo make into vector + std::array<uint16_t, TILE_COUNT*2> wall_indexes = {}; + std::array<variant_t, TILE_COUNT*2> _wall_variants = {}; + }; + + Pointer<ground_stuff> _ground; + Pointer<wall_stuff> _walls; std::vector<std::shared_ptr<entity>> _entities; struct world* _world; |