summaryrefslogtreecommitdiffhomepage
path: root/src/chunk-render.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/chunk-render.cpp')
-rw-r--r--src/chunk-render.cpp87
1 files changed, 0 insertions, 87 deletions
diff --git a/src/chunk-render.cpp b/src/chunk-render.cpp
index be3d64c4..94200239 100644
--- a/src/chunk-render.cpp
+++ b/src/chunk-render.cpp
@@ -1,8 +1,6 @@
#include "chunk.hpp"
#include "tile-atlas.hpp"
#include "shaders/tile.hpp"
-#include "entity.hpp"
-#include "anim-atlas.hpp"
#include <algorithm>
#include <Corrade/Containers/ArrayViewStl.h>
#include <Magnum/GL/Buffer.h>
@@ -104,93 +102,8 @@ auto chunk::ensure_wall_mesh() noexcept -> wall_mesh_tuple
return { wall_mesh, wall_indexes, count };
}
-void chunk::ensure_scenery_draw_array(Array<draw_entity>& array)
-{
- const size_t len_ = _entities.size();
-
- if (len_ <= array.size())
- return;
-
- size_t len;
-
- if (len_ > 1 << 17)
- len = len_;
- else
- len = std::bit_ceil(len_);
-
- array = Array<draw_entity>{len};
-}
-
-auto chunk::ensure_scenery_mesh(Array<draw_entity>&& array) noexcept -> scenery_mesh_tuple
-{
- return ensure_scenery_mesh(static_cast<Array<draw_entity>&>(array));
-}
-auto chunk::ensure_scenery_mesh(Array<draw_entity>& array) noexcept -> scenery_mesh_tuple
-{
- constexpr auto entity_ord_lessp = [](const auto& a, const auto& b) {
- return a.ord < b.ord;
- };
-
- fm_assert(_entities_sorted);
-
- const auto size = _entities.size();
- ensure_scenery_draw_array(array);
- for (auto i = 0uz; const auto& e : _entities)
- array[i++] = { e.get(), e->ordinal() };
- std::sort(array.begin(), array.begin() + size, entity_ord_lessp);
- const auto es = ArrayView<draw_entity>{array, size};
-
- if (_scenery_modified)
- {
- _scenery_modified = false;
-
- const auto count = fm_begin(
- size_t ret = 0;
- for (const auto& [e, ord] : es)
- ret += !e->is_dynamic();
- return ret;
- );
-
- scenery_indexes.clear();
- scenery_indexes.reserve(count);
- scenery_vertexes.clear();
- scenery_vertexes.reserve(count);
-
- for (const auto& [e, ord] : es)
- {
- if (e->is_dynamic())
- continue;
-
- const auto i = scenery_indexes.size();
- scenery_indexes.emplace_back();
- scenery_indexes.back() = tile_atlas::indices(i);
- const auto& atlas = e->atlas;
- const auto& fr = *e;
- const auto pos = e->coord.local();
- const auto coord = Vector3(pos) * TILE_SIZE + Vector3(Vector2(fr.offset), 0);
- const auto quad = atlas->frame_quad(coord, fr.r, fr.frame);
- const auto& group = atlas->group(fr.r);
- const auto texcoords = atlas->texcoords_for_frame(fr.r, fr.frame, !group.mirror_from.isEmpty());
- const float depth = tile_shader::depth_value(pos, tile_shader::scenery_depth_offset);
- scenery_vertexes.emplace_back();
- auto& v = scenery_vertexes.back();
- for (auto j = 0uz; j < 4; j++)
- v[j] = { quad[j], texcoords[j], depth };
- }
-
- GL::Mesh mesh{GL::MeshPrimitive::Triangles};
- mesh.addVertexBuffer(GL::Buffer{scenery_vertexes}, 0, tile_shader::Position{}, tile_shader::TextureCoordinates{}, tile_shader::Depth{})
- .setIndexBuffer(GL::Buffer{scenery_indexes}, 0, GL::MeshIndexType::UnsignedShort)
- .setCount(int32_t(6 * count));
- scenery_mesh = Utility::move(mesh);
- }
-
- fm_assert(!size || es);
-
- return { scenery_mesh, es, size };
-}
} // namespace floormat