summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-04-09 22:46:17 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-04-09 22:46:17 +0200
commita5d5ad64ff97201e2ccf83c1d79008190906ebcd (patch)
treeebde66821202c21d339d2164c14abc0518c8e7f2 /src
parentc04906db429b7c626a753d49e2d64c51135c6039 (diff)
move scenery draw scratch buffers to central place
Diffstat (limited to 'src')
-rw-r--r--src/chunk-collision.cpp2
-rw-r--r--src/chunk-scenery.cpp13
-rw-r--r--src/chunk-scenery.hpp9
-rw-r--r--src/chunk.hpp9
4 files changed, 24 insertions, 9 deletions
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};