diff options
-rw-r--r-- | draw/anim.cpp | 2 | ||||
-rw-r--r-- | draw/anim.hpp | 3 | ||||
-rw-r--r-- | serialize/world-reader.cpp | 6 | ||||
-rw-r--r-- | src/chunk-collision.cpp | 2 | ||||
-rw-r--r-- | src/chunk-scenery.cpp | 13 | ||||
-rw-r--r-- | src/chunk-scenery.hpp | 9 | ||||
-rw-r--r-- | src/chunk.hpp | 9 |
7 files changed, 33 insertions, 11 deletions
diff --git a/draw/anim.cpp b/draw/anim.cpp index b99b02e3..b24dffa7 100644 --- a/draw/anim.cpp +++ b/draw/anim.cpp @@ -59,7 +59,7 @@ void anim_mesh::draw(tile_shader& shader, const Vector2i& win_size, chunk& c, st { constexpr auto quad_index_count = 6; - auto [mesh_, es, size] = c.ensure_scenery_mesh(_draw_array); + auto [mesh_, es, size] = c.ensure_scenery_mesh({ _draw_array, _draw_vertexes, _draw_indexes }); GL::MeshView mesh{mesh_}; const auto max_index = uint32_t(size*quad_index_count - 1); diff --git a/draw/anim.hpp b/draw/anim.hpp index eaa191f5..da484d6c 100644 --- a/draw/anim.hpp +++ b/draw/anim.hpp @@ -44,6 +44,9 @@ private: using quad_data = std::array<vertex_data, 4>; Array<chunk::entity_draw_order> _draw_array; + std::vector<std::array<uint16_t, 6>> _draw_indexes; + std::vector<std::array<chunk::vertex, 4>> _draw_vertexes; + GL::Mesh _mesh; GL::Buffer _vertex_buffer{quad_data{}, Magnum::GL::BufferUsage::DynamicDraw}, _index_buffer{make_index_array()}; diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp index c481a7e6..69f7c58e 100644 --- a/serialize/world-reader.cpp +++ b/serialize/world-reader.cpp @@ -38,6 +38,10 @@ private: std::vector<std::shared_ptr<tile_atlas>> atlases; world* _world; uint16_t PROTO = proto_version; + + Array<chunk::entity_draw_order> draw_array; + std::vector<std::array<chunk::vertex, 4>> draw_vertexes; + std::vector<std::array<UnsignedShort, 6>> draw_indexes; }; reader_state::reader_state(world& world) noexcept : _world{&world} {} @@ -317,7 +321,7 @@ void reader_state::read_chunks(reader_t& s) c.sort_entities(); c.ensure_ground_mesh(); c.ensure_wall_mesh(); - c.ensure_scenery_mesh(array); + c.ensure_scenery_mesh({ draw_array, draw_vertexes, draw_indexes }); c.ensure_passability(); } } diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp index dfb0fdd6..2c612576 100644 --- a/src/chunk-collision.cpp +++ b/src/chunk-collision.cpp @@ -155,7 +155,7 @@ void chunk::_replace_bbox(const bbox& x0, const bbox& x1, bool b0, bool b1) bool chunk::can_place_entity(const entity_proto& proto, local_coords pos) { - (void)ensure_scenery_mesh({}); + (void)ensure_scenery_mesh(); const auto center = Vector2(pos)*TILE_SIZE2 + Vector2(proto.offset) + Vector2(proto.bbox_offset), min = center - Vector2(proto.bbox_size/2), max = min + Vector2(proto.bbox_size); diff --git a/src/chunk-scenery.cpp b/src/chunk-scenery.cpp index f2c1c80a..bbb26709 100644 --- a/src/chunk-scenery.cpp +++ b/src/chunk-scenery.cpp @@ -9,9 +9,12 @@ namespace floormat { -auto chunk::ensure_scenery_mesh(Array<entity_draw_order>&& array) noexcept -> scenery_mesh_tuple +auto chunk::ensure_scenery_mesh() noexcept -> scenery_mesh_tuple { - return ensure_scenery_mesh(static_cast<Array<entity_draw_order>&>(array)); + Array<entity_draw_order> array; + std::vector<std::array<vertex, 4>> scenery_vertexes; + std::vector<std::array<UnsignedShort, 6>> scenery_indexes; + return ensure_scenery_mesh({array, scenery_vertexes, scenery_indexes}); } bool chunk::topo_sort_data::intersects(const topo_sort_data& o) const @@ -124,12 +127,15 @@ auto chunk::make_topo_sort_data(entity& e, uint32_t mesh_idx) -> topo_sort_data return data; } -auto chunk::ensure_scenery_mesh(Array<entity_draw_order>& array) noexcept -> scenery_mesh_tuple +auto chunk::ensure_scenery_mesh(scenery_scratch_buffers buffers) noexcept -> scenery_mesh_tuple { fm_assert(_entities_sorted); if (_scenery_modified) { + auto& scenery_vertexes = buffers.scenery_vertexes; + auto& scenery_indexes = buffers.scenery_indexes; + _scenery_modified = false; const auto count = fm_begin( @@ -173,6 +179,7 @@ auto chunk::ensure_scenery_mesh(Array<entity_draw_order>& array) noexcept -> sce } const auto size = _entities.size(); + auto& array = buffers.array; ensure_scenery_draw_array(array); uint32_t j = 0; for (uint32_t i = 0; const auto& e : _entities) diff --git a/src/chunk-scenery.hpp b/src/chunk-scenery.hpp index 1363479b..5657b536 100644 --- a/src/chunk-scenery.hpp +++ b/src/chunk-scenery.hpp @@ -19,6 +19,7 @@ struct chunk::topo_sort_data bool intersects(const topo_sort_data& other) const; }; + struct chunk::entity_draw_order { entity *e; @@ -26,10 +27,18 @@ struct chunk::entity_draw_order float ord; topo_sort_data data; }; + struct chunk::scenery_mesh_tuple { GL::Mesh& mesh; ArrayView<entity_draw_order> array; size_t size; }; +struct chunk::scenery_scratch_buffers +{ + Array<entity_draw_order>& array; + std::vector<std::array<vertex, 4>>& scenery_vertexes; + std::vector<std::array<UnsignedShort, 6>>& scenery_indexes; +}; + } // namespace floormat diff --git a/src/chunk.hpp b/src/chunk.hpp index c98ae9a3..b1d445ef 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -84,6 +84,7 @@ struct chunk final struct topo_sort_data; struct entity_draw_order; struct scenery_mesh_tuple; + struct scenery_scratch_buffers; struct vertex { Vector3 position; @@ -97,8 +98,9 @@ struct chunk final tile_atlas* ground_atlas_at(size_t i) const noexcept; wall_mesh_tuple ensure_wall_mesh() noexcept; tile_atlas* wall_atlas_at(size_t i) const noexcept; - scenery_mesh_tuple ensure_scenery_mesh(Array<entity_draw_order>&& array) noexcept; - scenery_mesh_tuple ensure_scenery_mesh(Array<entity_draw_order>& array) noexcept; + + scenery_mesh_tuple ensure_scenery_mesh(scenery_scratch_buffers buffers) noexcept; + scenery_mesh_tuple ensure_scenery_mesh() noexcept; void ensure_passability() noexcept; RTree* rtree() noexcept; @@ -121,9 +123,6 @@ private: std::array<variant_t, TILE_COUNT*2> _wall_variants = {}; std::vector<std::shared_ptr<entity>> _entities; - std::vector<std::array<UnsignedShort, 6>> scenery_indexes; // todo move to anim_mesh - std::vector<std::array<vertex, 4>> scenery_vertexes; // same - struct world* _world; GL::Mesh ground_mesh{NoCreate}, wall_mesh{NoCreate}, scenery_mesh{NoCreate}; |