diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-06-25 15:18:46 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-06-25 15:18:46 +0200 |
commit | dad4ae54192bd420aaf7b8816a953c0e42a93dd6 (patch) | |
tree | 152784b004869440ed1e7a4d588163d63d121f8f | |
parent | 8e6ad9cd70156ad47a7ad11ef5d59aa2ac06aea9 (diff) |
.
-rw-r--r-- | atlas.cpp | 18 | ||||
-rw-r--r-- | atlas.hpp | 8 | ||||
-rw-r--r-- | crop-tool/crop-tool.cpp | 4 | ||||
-rw-r--r-- | loader-impl.cpp | 4 | ||||
-rw-r--r-- | loader.hpp | 4 | ||||
-rw-r--r-- | main.cpp | 6 | ||||
-rw-r--r-- | tile.cpp | 8 | ||||
-rw-r--r-- | tile.hpp | 7 |
8 files changed, 23 insertions, 36 deletions
@@ -5,7 +5,7 @@ namespace Magnum::Examples { -atlas_texture::atlas_texture(const ImageView2D& image, Vector2i dims) : +texture_atlas::texture_atlas(const ImageView2D& image, Vector2i dims) : size_{image.size()}, dims_{dims}, tile_size_{size_ / dims} @@ -22,7 +22,7 @@ atlas_texture::atlas_texture(const ImageView2D& image, Vector2i dims) : .setSubImage(0, {}, image); } -std::array<Vector2, 4> atlas_texture::texcoords_for_id(int id_) const +std::array<Vector2, 4> texture_atlas::texcoords_for_id(int id_) const { CORRADE_INTERNAL_ASSERT(id_ >= 0 && id_ < dims_.product()); Vector2i id = { id_ % dims_[0], id_ / dims_[0] }; @@ -37,9 +37,9 @@ std::array<Vector2, 4> atlas_texture::texcoords_for_id(int id_) const }}; } -using vertex_array_type = atlas_texture::vertex_array_type; +using vertex_array_type = texture_atlas::vertex_array_type; -vertex_array_type atlas_texture::floor_quad(Vector3 center, Vector2 size) +vertex_array_type texture_atlas::floor_quad(Vector3 center, Vector2 size) { float x = size[0]*.5f, y = size[1]*.5f; return {{ @@ -50,7 +50,7 @@ vertex_array_type atlas_texture::floor_quad(Vector3 center, Vector2 size) }}; } -vertex_array_type atlas_texture::wall_quad_W(Vector3 center, Vector3 size) +vertex_array_type texture_atlas::wall_quad_W(Vector3 center, Vector3 size) { float x = size[0]*.5f, y = size[1]*.5f, z = size[2]; return {{ @@ -61,7 +61,7 @@ vertex_array_type atlas_texture::wall_quad_W(Vector3 center, Vector3 size) }}; } -vertex_array_type atlas_texture::wall_quad_S(Vector3 center, Vector3 size) +vertex_array_type texture_atlas::wall_quad_S(Vector3 center, Vector3 size) { float x = size[0]*.5f, y = size[1]*.5f, z = size[2]; return {{ @@ -72,7 +72,7 @@ vertex_array_type atlas_texture::wall_quad_S(Vector3 center, Vector3 size) }}; } -vertex_array_type atlas_texture::wall_quad_E(Vector3 center, Vector3 size) +vertex_array_type texture_atlas::wall_quad_E(Vector3 center, Vector3 size) { float x = size[0]*.5f, y = size[1]*.5f, z = size[2]; return {{ @@ -83,7 +83,7 @@ vertex_array_type atlas_texture::wall_quad_E(Vector3 center, Vector3 size) }}; } -vertex_array_type atlas_texture::wall_quad_N(Vector3 center, Vector3 size) +vertex_array_type texture_atlas::wall_quad_N(Vector3 center, Vector3 size) { float x = size[0]*.5f, y = size[1]*.5f, z = size[2]; return {{ @@ -94,7 +94,7 @@ vertex_array_type atlas_texture::wall_quad_N(Vector3 center, Vector3 size) }}; } -std::array<UnsignedShort, 6> atlas_texture::indices(int N) +std::array<UnsignedShort, 6> texture_atlas::indices(int N) { CORRADE_INTERNAL_ASSERT(N >= 0); using u16 = UnsignedShort; @@ -5,11 +5,11 @@ namespace Magnum::Examples { -struct atlas_texture final +struct texture_atlas final { using vertex_array_type = std::array<Vector3, 4>; - atlas_texture(const ImageView2D& img, Vector2i dims); + texture_atlas(const ImageView2D& img, Vector2i dims); std::array<Vector2, 4> texcoords_for_id(int id) const; static vertex_array_type floor_quad(Vector3 center, Vector2 size); static vertex_array_type wall_quad_S(Vector3 center, Vector3 size); @@ -21,8 +21,8 @@ struct atlas_texture final constexpr int size() const { return dims_.product(); } constexpr Vector2i tile_size() const { return tile_size_; } - atlas_texture(const atlas_texture&) = delete; - atlas_texture& operator=(const atlas_texture&) = delete; + texture_atlas(const texture_atlas&) = delete; + texture_atlas& operator=(const texture_atlas&) = delete; private: GL::Texture2D tex_; Vector2i size_, dims_, tile_size_; diff --git a/crop-tool/crop-tool.cpp b/crop-tool/crop-tool.cpp index e948af34..064f004d 100644 --- a/crop-tool/crop-tool.cpp +++ b/crop-tool/crop-tool.cpp @@ -38,7 +38,6 @@ struct options static std::tuple<cv::Vec2i, cv::Vec2i, bool> find_image_bounds(const cv::Mat4b& mat) noexcept { cv::Vec2i start{mat.cols, mat.rows}, end{0, 0}; - bool ok = false; for (int y = 0; y < mat.rows; y++) { const auto* ptr = mat.ptr<cv::Vec4b>(y); @@ -47,7 +46,6 @@ static std::tuple<cv::Vec2i, cv::Vec2i, bool> find_image_bounds(const cv::Mat4b& enum {R, G, B, A}; if (cv::Vec4b px = ptr[x]; px[A] != 0) { - ok = true; start[0] = std::min(x, start[0]); start[1] = std::min(y, start[1]); end[0] = std::max(x+1, end[0]); @@ -55,7 +53,7 @@ static std::tuple<cv::Vec2i, cv::Vec2i, bool> find_image_bounds(const cv::Mat4b& } } } - if (ok) + if (start[0] < end[0] && start[1] < end[1]) return {start, end, true}; else return {{}, {}, false}; diff --git a/loader-impl.cpp b/loader-impl.cpp index 8e7cb081..6d760330 100644 --- a/loader-impl.cpp +++ b/loader-impl.cpp @@ -14,7 +14,7 @@ namespace Magnum::Examples { -using atlas_ptr = std::shared_ptr<atlas_texture>; +using atlas_ptr = std::shared_ptr<texture_atlas>; struct loader_impl final : loader_ { @@ -51,7 +51,7 @@ atlas_ptr loader_impl::tile_atlas(const Containers::StringView& name, Vector2i s if (it != atlas_map.end()) return it->second; auto image = tile_texture(name); - auto atlas = std::make_shared<atlas_texture>(image, size); + auto atlas = std::make_shared<texture_atlas>(image, size); atlas_map[name] = atlas; return atlas; } @@ -9,13 +9,13 @@ namespace Magnum::Examples { -struct atlas_texture; +struct texture_atlas; struct loader_ { virtual std::string shader(const Containers::StringView& filename) = 0; virtual Trade::ImageData2D tile_texture(const Containers::StringView& filename) = 0; - virtual std::shared_ptr<atlas_texture> tile_atlas(const Containers::StringView& filename, Vector2i size) = 0; + virtual std::shared_ptr<texture_atlas> tile_atlas(const Containers::StringView& filename, Vector2i size) = 0; static void destroy(); loader_(const loader_&) = delete; @@ -45,12 +45,12 @@ struct application final : Platform::Application GL::Mesh _mesh, _mesh2; tile_shader _shader; - std::shared_ptr<atlas_texture> atlas = + std::shared_ptr<texture_atlas> atlas = //loader.tile_atlas("../share/game/images/tiles.tga", {8,4}); //loader.tile_atlas("../share/game/images/tiles2.tga", {8,5}); loader.tile_atlas("../share/game/images/metal1.tga", {2, 2}); //loader.tile_atlas("../share/game/images/floor1.tga", {4, 4}); - std::shared_ptr<atlas_texture> atlas2 = + std::shared_ptr<texture_atlas> atlas2 = loader.tile_atlas("../share/game/images/metal2.tga", {2, 2}); std::uint64_t time_ticks = 0, time_freq = SDL_GetPerformanceFrequency(); @@ -114,7 +114,7 @@ application::application(const Arguments& arguments): indices.clear(); { - atlas_texture::vertex_array_type walls[] = { + texture_atlas::vertex_array_type walls[] = { atlas2->wall_quad_W({}, Vector3(X, Y, Z)), atlas2->wall_quad_N({}, Vector3(X, Y, Z)), atlas2->wall_quad_E({}, Vector3(X, Y, Z)), @@ -3,14 +3,6 @@ namespace Magnum::Examples { -chunk::tile_index_array_type chunk::make_tile_indices() noexcept -{ - tile_index_array_type array; - for (unsigned i = 0; i < N*N; i++) - array[i] = (std::uint8_t)i; - return array; -} - world::world() = default; } // namespace Magnum::Examples @@ -14,8 +14,8 @@ namespace Magnum::Examples { struct tile_image final { - std::shared_ptr<atlas_texture> atlas; - int variant = -1; + std::shared_ptr<texture_atlas> atlas; + std::uint8_t variant = 0xff; }; struct tile final @@ -62,8 +62,6 @@ struct chunk final using tile_index_array_type = std::array<index_type, TILE_COUNT>; //static constexpr inline local_coords center = { (index_type)(N/2), (index_type)(N/2) }; - std::array<index_type, TILE_COUNT> indices = make_tile_indices(); - constexpr tile& operator[](local_coords xy); constexpr const tile& operator[](local_coords xy) const; constexpr tile& operator[](std::size_t i); @@ -74,7 +72,6 @@ struct chunk final private: template<typename F, typename Self> constexpr void foreach_tile_(F&& fun); - static std::array<index_type, TILE_COUNT> make_tile_indices() noexcept; std::array<struct tile, TILE_COUNT> tiles = {}; }; |