#pragma once #include "tile.hpp" #include "tile-iterator.hpp" #include "scenery.hpp" #include #include #include #include #include "RTree.h" namespace floormat { struct anim_atlas; enum class collision : std::uint8_t { view, shoot, move, }; enum class collision_type : std::uint8_t { none, entity, scenery, geometry, }; struct collision_data final { std::uint64_t tag : 2; std::uint64_t pass : 2; std::uint64_t data : 60; }; struct chunk final { friend struct tile_ref; tile_ref operator[](std::size_t idx) noexcept; tile_proto operator[](std::size_t idx) const noexcept; tile_ref operator[](local_coords xy) noexcept; tile_proto operator[](local_coords xy) const noexcept; using iterator = tile_iterator; using const_iterator = tile_const_iterator; iterator begin() noexcept; iterator end() noexcept; const_iterator cbegin() const noexcept; const_iterator cend() const noexcept; const_iterator begin() const noexcept; const_iterator end() const noexcept; bool empty(bool force = false) const noexcept; chunk() noexcept; ~chunk() noexcept; chunk(const chunk&) = delete; chunk& operator=(const chunk&) = delete; chunk(chunk&&) noexcept; chunk& operator=(chunk&&) noexcept; void mark_ground_modified() noexcept; void mark_walls_modified() noexcept; void mark_scenery_modified(bool collision_too = true) noexcept; void mark_passability_modified() noexcept; void mark_modified() noexcept; bool is_passability_modified() const noexcept; bool is_scenery_modified() const noexcept; struct ground_mesh_tuple final { GL::Mesh& mesh; const ArrayView ids; const std::size_t size; }; struct wall_mesh_tuple final { GL::Mesh& mesh; const ArrayView ids; const std::size_t size; }; struct scenery_mesh_tuple final { GL::Mesh& mesh; const ArrayView ids; const std::size_t size; }; ground_mesh_tuple ensure_ground_mesh() noexcept; tile_atlas* ground_atlas_at(std::size_t i) const noexcept; wall_mesh_tuple ensure_wall_mesh() noexcept; tile_atlas* wall_atlas_at(std::size_t i) const noexcept; scenery_mesh_tuple ensure_scenery_mesh() noexcept; std::shared_ptr& scenery_atlas_at(std::size_t i) noexcept; scenery& scenery_at(std::size_t i) noexcept; void ensure_passability() noexcept; using RTree = ::RTree; const RTree* rtree() const noexcept; RTree* rtree() noexcept; template requires requires(F fun) { fun(); } void with_scenery_update(std::size_t idx, F&& fun); private: std::array, TILE_COUNT> _ground_atlases; std::array ground_indexes = {}; std::array _ground_variants = {}; std::array, TILE_COUNT*2> _wall_atlases; std::array wall_indexes = {}; std::array _wall_variants = {}; std::array, TILE_COUNT> _scenery_atlases; std::array scenery_indexes = {}; std::array _scenery_variants = {}; GL::Mesh ground_mesh{NoCreate}, wall_mesh{NoCreate}, scenery_mesh{NoCreate}; RTree _rtree; mutable bool _maybe_empty : 1 = true, _ground_modified : 1 = true, _walls_modified : 1 = true, _scenery_modified : 1 = true, _pass_modified : 1 = true; struct bbox final // NOLINT(cppcoreguidelines-pro-type-member-init) { std::uint64_t id; Vector2i start, end; bool operator==(const bbox& other) const noexcept; }; bool _bbox_for_scenery(std::size_t i, bbox& value) noexcept; void _remove_bbox(const bbox& x); void _add_bbox(const bbox& x); void _replace_bbox(const bbox& x0, const bbox& x, bool b0, bool b); }; } // namespace floormat