diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-01 16:35:03 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-01 16:35:03 +0100 |
commit | 704e9bd3ac58484a5209e186798076f1cbd432ef (patch) | |
tree | 511479ebd088d5c9524803c6f3fe4641009b58bc /draw | |
parent | 7ff1f0911e0b0c314d6e639887b705d6fc0d78aa (diff) |
wip
Diffstat (limited to 'draw')
-rw-r--r-- | draw/floor.cpp | 12 | ||||
-rw-r--r-- | draw/floor.hpp | 6 | ||||
-rw-r--r-- | draw/wall.cpp | 11 | ||||
-rw-r--r-- | draw/wall.hpp | 8 |
4 files changed, 19 insertions, 18 deletions
diff --git a/draw/floor.cpp b/draw/floor.cpp index 444ee127..861336c7 100644 --- a/draw/floor.cpp +++ b/draw/floor.cpp @@ -17,11 +17,11 @@ floor_mesh::floor_mesh() .setIndexBuffer(_index_buffer, 0, GL::MeshIndexType::UnsignedShort); } -void floor_mesh::set_tile(quad_data& data, tile& x) +void floor_mesh::set_tile(quad_data& data, tile_ref& x) { - if (x.ground) + if (auto ground = x.ground(); ground) { - auto texcoords = x.ground.atlas->texcoords_for_id(x.ground.variant); + auto texcoords = ground.atlas->texcoords_for_id(ground.variant); for (size_t i = 0; i < 4; i++) data[i] = { texcoords[i] }; } @@ -34,7 +34,7 @@ void floor_mesh::draw(tile_shader& shader, chunk& c) { //_vertex_buffer.setData({nullptr, sizeof(quad_data) * TILE_COUNT}, Magnum::GL::BufferUsage::DynamicDraw); // orphan the buffer std::array<quad_data, TILE_COUNT> data; - for (auto& [x, idx, pt] : c) { + for (auto [x, idx, pt] : c) { set_tile(data[idx], x); } _vertex_buffer.setSubData(0, data); @@ -57,8 +57,8 @@ void floor_mesh::draw(tile_shader& shader, chunk& c) last_pos = i; }; - for (auto& [x, i, pt] : c) - do_draw(i, x.ground.atlas.get()); + for (auto [x, i, pt] : c) + do_draw(i, x.ground_atlas().get()); do_draw(TILE_COUNT, nullptr); } diff --git a/draw/floor.hpp b/draw/floor.hpp index 4a273dfc..4ece92eb 100644 --- a/draw/floor.hpp +++ b/draw/floor.hpp @@ -10,10 +10,10 @@ namespace floormat { -struct tile_shader; -struct chunk; struct tile_ref; struct tile_proto; +struct tile_shader; +struct chunk; struct floor_mesh final { @@ -34,7 +34,7 @@ private: GL::Buffer _vertex_buffer{std::array<quad_data, TILE_COUNT>{}, Magnum::GL::BufferUsage::DynamicDraw}, _index_buffer{make_index_array()}, _positions_buffer{make_position_array()}; - static void set_tile(quad_data& data, tile& x); + static void set_tile(quad_data& data, tile_ref& x); }; } // namespace floormat diff --git a/draw/wall.cpp b/draw/wall.cpp index 4602453d..18462e2c 100644 --- a/draw/wall.cpp +++ b/draw/wall.cpp @@ -2,6 +2,7 @@ #include "tile-atlas.hpp" #include "shaders/tile.hpp" #include "chunk.hpp" +#include "tile-image.hpp" #include <Magnum/GL/Texture.h> #include <Magnum/GL/MeshView.h> @@ -18,7 +19,7 @@ wall_mesh::wall_mesh() CORRADE_INTERNAL_ASSERT(_mesh.isIndexed()); } -void wall_mesh::add_wall(vertex_array& data, texture_array& textures, tile_image& img, std::size_t pos) +void wall_mesh::add_wall(vertex_array& data, texture_array& textures, const tile_image_ref& img, std::size_t pos) { CORRADE_INTERNAL_ASSERT(pos < data.size()); auto texcoords = img.atlas->texcoords_for_id(img.variant); @@ -29,11 +30,11 @@ void wall_mesh::add_wall(vertex_array& data, texture_array& textures, tile_image } } -void wall_mesh::maybe_add_tile(vertex_array& data, texture_array& textures, tile& x, std::size_t pos) +void wall_mesh::maybe_add_tile(vertex_array& data, texture_array& textures, tile_ref x, std::size_t pos) { - if (auto& wall = x.wall_north; wall.atlas) + if (auto wall = x.wall_north(); wall.atlas) add_wall(data, textures, wall, pos * 2 + 0); - if (auto& wall = x.wall_west; wall.atlas) + if (auto wall = x.wall_west(); wall.atlas) add_wall(data, textures, wall, pos * 2 + 1); } @@ -43,7 +44,7 @@ void wall_mesh::draw(tile_shader& shader, chunk& c) texture_array textures = {}; { vertex_array data; - for (auto& [x, idx, pt] : c) { + for (auto [x, idx, pt] : c) { maybe_add_tile(data, textures, x, idx); } _vertex_buffer.setSubData(0, data); diff --git a/draw/wall.hpp b/draw/wall.hpp index 06d99842..ad1eafad 100644 --- a/draw/wall.hpp +++ b/draw/wall.hpp @@ -10,10 +10,10 @@ namespace floormat { -struct tile; -struct tile_image; struct tile_shader; struct chunk; +struct tile_ref; +struct tile_image_ref; struct wall_mesh final { @@ -31,8 +31,8 @@ private: using vertex_array = std::array<quad, COUNT>; using texture_array = std::array<GL::Texture2D*, COUNT>; - static void maybe_add_tile(vertex_array& data, texture_array& textures, tile& x, std::size_t pos); - static void add_wall(vertex_array& data, texture_array& textures, tile_image& img, std::size_t pos); + static void maybe_add_tile(vertex_array& data, texture_array& textures, tile_ref x, std::size_t pos); + static void add_wall(vertex_array& data, texture_array& textures, const tile_image_ref& img, std::size_t pos); GL::Mesh _mesh; GL::Buffer _vertex_buffer{vertex_array{}, Magnum::GL::BufferUsage::DynamicDraw}, |