diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2023-02-25 21:47:56 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-02-25 21:56:16 +0100 |
| commit | c9431f34e543dc0e6bf564e4ada9574072e92918 (patch) | |
| tree | 926ed08d8e15a93e946b2adfab725383092e86e5 /src | |
| parent | 6a4ac0dc015106801d79cc258b06f896ea0e2716 (diff) | |
convert to magnum vectors and use shorter syntax
Diffstat (limited to 'src')
| -rw-r--r-- | src/camera-offset.cpp | 2 | ||||
| -rw-r--r-- | src/chunk-collision.cpp | 4 | ||||
| -rw-r--r-- | src/chunk-render.cpp | 6 | ||||
| -rw-r--r-- | src/global-coords.hpp | 4 | ||||
| -rw-r--r-- | src/local-coords.hpp | 9 |
5 files changed, 16 insertions, 9 deletions
diff --git a/src/camera-offset.cpp b/src/camera-offset.cpp index 1c77659c..15401bb0 100644 --- a/src/camera-offset.cpp +++ b/src/camera-offset.cpp @@ -13,7 +13,7 @@ with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chun fm_assert(shader.depth_offset() == 0.f); constexpr auto chunk_size = TILE_MAX_DIM20d*dTILE_SIZE; - const auto offset = _camera + tile_shader::project(Vector3d(c.x, c.y, 0) * chunk_size); + const auto offset = _camera + tile_shader::project(Vector3d(Vector2d(c), 0) * chunk_size); const auto len_x = (float)(last.x - first.x), cx = (float)(c.x - first.x), cy = (float)(c.y - first.y); const float depth_offset = shader.depth_tile_size*(cy*TILE_MAX_DIM*len_x*TILE_MAX_DIM + cx*TILE_MAX_DIM); diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp index de4f484e..d41c02c8 100644 --- a/src/chunk-collision.cpp +++ b/src/chunk-collision.cpp @@ -15,13 +15,13 @@ constexpr Vector2 tile_start(std::size_t k) { constexpr auto half_tile = Vector2(TILE_SIZE2)/2; const local_coords coord{k}; - return TILE_SIZE2 * Vector2(coord.x, coord.y) - half_tile; + return TILE_SIZE2 * Vector2(coord) - half_tile; } constexpr Pair<Vector2, Vector2> scenery_tile(std::size_t k, const scenery& sc) { const local_coords coord{k}; - auto center = TILE_SIZE2 * Vector2(coord.x, coord.y) + Vector2(sc.offset) + Vector2(sc.bbox_offset); + auto center = TILE_SIZE2 * Vector2(coord) + Vector2(sc.offset) + Vector2(sc.bbox_offset); auto start = center - Vector2(sc.bbox_size); auto size = Vector2(sc.bbox_size)*2; return { start, start + size, }; diff --git a/src/chunk-render.cpp b/src/chunk-render.cpp index d00424df..48425f72 100644 --- a/src/chunk-render.cpp +++ b/src/chunk-render.cpp @@ -45,7 +45,7 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple const std::uint8_t i = ground_indexes[k]; const auto& atlas = _ground_atlases[i]; const local_coords pos{i}; - const auto quad = atlas->floor_quad(Vector3(pos.x, pos.y, 0) * TILE_SIZE, TILE_SIZE2); + const auto quad = atlas->floor_quad(Vector3(Vector2(pos), 0) * TILE_SIZE, TILE_SIZE2); const auto texcoords = atlas->texcoords_for_id(_ground_variants[i]); const float depth = tile_shader::depth_value(pos); auto& v = vertexes[k]; @@ -88,7 +88,7 @@ auto chunk::ensure_wall_mesh() noexcept -> wall_mesh_tuple const auto& atlas = _wall_atlases[i]; const auto& variant = _wall_variants[i]; const local_coords pos{i / 2u}; - const auto center = Vector3(pos.x, pos.y, 0) * TILE_SIZE; + const auto center = Vector3(Vector2(pos), 0) * TILE_SIZE; const auto quad = i & 1 ? atlas->wall_quad_W(center, TILE_SIZE) : atlas->wall_quad_N(center, TILE_SIZE); const float depth = tile_shader::depth_value(pos); const auto texcoords = atlas->texcoords_for_id(variant); @@ -133,7 +133,7 @@ auto chunk::ensure_scenery_mesh() noexcept -> scenery_mesh_tuple const local_coords pos{i}; const auto& atlas = _scenery_atlases[i]; const auto& fr = _scenery_variants[i]; - const auto coord = Vector3(pos.x, pos.y, 0) * TILE_SIZE + Vector3(Vector2(fr.offset), 0); + const auto coord = Vector3(Vector2(pos), 0) * 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()); diff --git a/src/global-coords.hpp b/src/global-coords.hpp index 709b2a3a..1dc99af7 100644 --- a/src/global-coords.hpp +++ b/src/global-coords.hpp @@ -11,6 +11,10 @@ struct chunk_coords final { constexpr bool operator==(const chunk_coords& other) const noexcept = default; constexpr Vector2i operator-(chunk_coords other) const noexcept; + + template<typename T> + requires (std::is_floating_point_v<T> || std::is_integral_v<T> && (sizeof(T) > sizeof(x) || std::is_same_v<T, std::decay_t<decltype(x)>>)) + explicit constexpr operator Math::Vector2<T>() const noexcept { return Math::Vector2<T>(T(x), T(y)); } }; constexpr Vector2i chunk_coords::operator-(chunk_coords other) const noexcept diff --git a/src/local-coords.hpp b/src/local-coords.hpp index 30fb3617..f53c87ee 100644 --- a/src/local-coords.hpp +++ b/src/local-coords.hpp @@ -2,6 +2,7 @@ #include "compat/assert.hpp" #include "tile-defs.hpp" #include <concepts> +#include <Magnum/Math/Vector2.h> namespace floormat { @@ -9,10 +10,12 @@ struct local_coords final { std::uint8_t x : 4 = 0, y : 4 = 0; explicit constexpr local_coords(std::size_t idx) noexcept; constexpr local_coords() noexcept = default; - template<std::integral T> requires (sizeof(T) <= sizeof(std::size_t)) + template<typename T> requires (std::is_integral_v<T> && sizeof(T) <= sizeof(std::size_t)) constexpr local_coords(T x, T y) noexcept; constexpr local_coords(std::uint8_t x, std::uint8_t y) noexcept : x{x}, y{y} {} constexpr std::uint8_t to_index() const noexcept { return y*TILE_MAX_DIM + x; } + + template<typename T> explicit constexpr operator Math::Vector2<T>() const noexcept { return Math::Vector2<T>(T(x), T(y)); } }; constexpr local_coords::local_coords(std::size_t index) noexcept : @@ -22,8 +25,8 @@ constexpr local_coords::local_coords(std::size_t index) noexcept : fm_assert(index < TILE_COUNT); } -template<std::integral T> -requires (sizeof(T) <= sizeof(std::size_t)) +template<typename T> +requires (std::is_integral_v<T> && sizeof(T) <= sizeof(std::size_t)) constexpr local_coords::local_coords(T x, T y) noexcept : x{(std::uint8_t)x}, y{(std::uint8_t)y} { |
