diff options
| -rw-r--r-- | main.cpp | 4 | ||||
| -rw-r--r-- | tile-atlas.cpp | 6 | ||||
| -rw-r--r-- | tile-atlas.hpp | 4 | ||||
| -rw-r--r-- | wall-mesh.cpp | 3 | ||||
| -rw-r--r-- | wall-mesh.hpp | 6 |
5 files changed, 9 insertions, 14 deletions
@@ -85,7 +85,6 @@ chunk app::make_test_chunk() void app::draw_chunk(chunk& c) { - constexpr auto N = TILE_MAX_DIM; _floor_mesh.draw(_shader, c); } @@ -99,6 +98,7 @@ app::app(const Arguments& arguments): //.setSampleCount(4) } { + reset_camera_offset(); #if 0 std::vector<QuadVertex> vertices; vertices.reserve(1024); std::vector<UnsignedShort> indices; indices.reserve(1024); @@ -180,7 +180,7 @@ void app::drawEvent() { void app::do_camera(float dt) { - constexpr float pixels_per_second = 100; + constexpr float pixels_per_second = 512; if (keys[key::camera_up]) camera_offset += Vector2(0, 1) * dt * pixels_per_second; else if (keys[key::camera_down]) diff --git a/tile-atlas.cpp b/tile-atlas.cpp index a716c376..07f59696 100644 --- a/tile-atlas.cpp +++ b/tile-atlas.cpp @@ -6,13 +6,12 @@ namespace Magnum::Examples { tile_atlas::tile_atlas(const ImageView2D& image, Vector2i dims) : size_{image.size()}, - dims_{dims}, - tile_size_{size_ / dims} + dims_{dims} { CORRADE_INTERNAL_ASSERT(dims_[0] > 0 && dims_[1] > 0); - CORRADE_INTERNAL_ASSERT(tile_size_ * dims_ == size_); CORRADE_INTERNAL_ASSERT(size_ % dims_ == Vector2i{}); CORRADE_INTERNAL_ASSERT(dims.product() < 256); + CORRADE_INTERNAL_ASSERT(tile_size() * dims_ == size_); tex_.setWrapping(GL::SamplerWrapping::ClampToEdge) .setMagnificationFilter(GL::SamplerFilter::Nearest) .setMinificationFilter(GL::SamplerFilter::Linear) @@ -23,6 +22,7 @@ tile_atlas::tile_atlas(const ImageView2D& image, Vector2i dims) : std::array<Vector2, 4> tile_atlas::texcoords_for_id(std::size_t id2) const { + const auto tile_size_ = tile_size(); auto id_ = (int)id2; CORRADE_INTERNAL_ASSERT(id_ >= 0 && id_ < dims_.product()); Vector2i id = { id_ % dims_[0], id_ / dims_[0] }; diff --git a/tile-atlas.hpp b/tile-atlas.hpp index f03afa71..757c29a6 100644 --- a/tile-atlas.hpp +++ b/tile-atlas.hpp @@ -19,14 +19,14 @@ struct tile_atlas final static constexpr std::array<UnsignedShort, 6> indices(std::size_t N); GL::Texture2D& texture() { return tex_; } constexpr std::size_t size() const { return (std::size_t)dims_.product(); } - constexpr Vector2i tile_size() const { return tile_size_; } + constexpr Vector2i tile_size() const { return size_ / dims_; } tile_atlas() = default; tile_atlas(const tile_atlas&) = delete; tile_atlas& operator=(const tile_atlas&) = delete; private: GL::Texture2D tex_; - Vector2i size_, dims_, tile_size_; + Vector2i size_, dims_; }; constexpr std::array<UnsignedShort, 6> tile_atlas::indices(std::size_t N) diff --git a/wall-mesh.cpp b/wall-mesh.cpp index ae7cf0c8..9d107fcb 100644 --- a/wall-mesh.cpp +++ b/wall-mesh.cpp @@ -78,8 +78,7 @@ void wall_mesh::draw(tile_shader& shader, chunk& c) decltype(wall_mesh::_index_data) wall_mesh::make_index_array() { - constexpr auto quad_index_count = std::tuple_size_v<decltype(tile_atlas::indices(0))>; - std::array<std::array<UnsignedShort, quad_index_count>, COUNT> array; // NOLINT(cppcoreguidelines-pro-type-member-init) + std::array<std::array<UnsignedShort, 6>, COUNT> array = {}; for (std::size_t i = 0; i < std::size(array); i++) array[i] = tile_atlas::indices(i); diff --git a/wall-mesh.hpp b/wall-mesh.hpp index 02fafc27..1a9bb4e8 100644 --- a/wall-mesh.hpp +++ b/wall-mesh.hpp @@ -16,9 +16,6 @@ struct chunk; struct wall_mesh final { wall_mesh(); - wall_mesh(wall_mesh&&) = delete; - wall_mesh(const wall_mesh&) = delete; - void draw(tile_shader& shader, chunk& c); private: @@ -34,7 +31,6 @@ private: }; using quad = std::array<vertex, 4>; - using index_type = std::array<UnsignedShort, 6>; using vertex_array = std::array<quad, COUNT>; using texture_array = std::array<GL::Texture2D*, COUNT>; @@ -47,7 +43,7 @@ private: GL::Buffer _vertex_buffer{vertex_array{}, Magnum::GL::BufferUsage::StaticDraw}, _index_buffer{_index_data, Magnum::GL::BufferUsage::StaticDraw}; - static const std::array<index_type, COUNT> _index_data; + static const std::array<std::array<UnsignedShort, 6>, COUNT> _index_data; static decltype(_index_data) make_index_array(); }; |
