From 1c13313ec845d43077bd7e78538358ca4e007f8a Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 20 Mar 2023 06:29:31 +0100 Subject: sort entities by id rather than draw order --- draw/anim.cpp | 9 ++++----- draw/anim.hpp | 7 +++++-- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'draw') diff --git a/draw/anim.cpp b/draw/anim.cpp index 60e9b54c..afdaa344 100644 --- a/draw/anim.cpp +++ b/draw/anim.cpp @@ -48,12 +48,10 @@ void anim_mesh::add_clickable(tile_shader& shader, const Vector2i& win_size, con void anim_mesh::draw(tile_shader& shader, chunk& c) { constexpr auto quad_index_count = 6; - auto [mesh_] = c.ensure_scenery_mesh(); - const auto& es = c.entities(); + + auto [mesh_, es, size] = c.ensure_scenery_mesh(_draw_array); GL::MeshView mesh{mesh_}; [[maybe_unused]] size_t draw_count = 0; - - const auto size = es.size(); const auto max_index = uint32_t(size*quad_index_count - 1); const auto do_draw = [&](size_t from, size_t to, anim_atlas* atlas) { @@ -75,7 +73,8 @@ void anim_mesh::draw(tile_shader& shader, chunk& c) for (auto k = 0_uz; k < size; k++) { - const auto& e = *es[k]; + fm_assert(es[k].e); + const auto& e = *es[k].e; auto& atlas = *e.atlas; if (last && &atlas != last.atlas) { diff --git a/draw/anim.hpp b/draw/anim.hpp index 632a89e3..9f279b38 100644 --- a/draw/anim.hpp +++ b/draw/anim.hpp @@ -1,7 +1,9 @@ #pragma once #include "local-coords.hpp" #include "rotation.hpp" +#include "chunk.hpp" #include +#include #include #include #include @@ -30,6 +32,8 @@ struct anim_mesh final static void add_clickable(tile_shader& shader, const Vector2i& win_size, const std::shared_ptr& s, std::vector& list); private: + static std::array make_index_array(); + struct vertex_data final { Vector3 position; Vector2 texcoords; @@ -37,8 +41,7 @@ private: }; using quad_data = std::array; - static std::array make_index_array(); - + Array _draw_array; GL::Mesh _mesh; GL::Buffer _vertex_buffer{quad_data{}, Magnum::GL::BufferUsage::DynamicDraw}, _index_buffer{make_index_array()}; -- cgit v1.2.3