diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-06-06 18:56:06 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-06-06 19:03:25 +0200 |
commit | bb9857892d514c8906dbcde101117caf1922776b (patch) | |
tree | 3a69c07bfbe0c61f4bc53c6c200ba66aae83e0f4 /src/tile-bbox.hpp | |
parent | c489a322b944da55dabd18db60a46e5f314c5d5d (diff) |
b
Diffstat (limited to 'src/tile-bbox.hpp')
-rw-r--r-- | src/tile-bbox.hpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/tile-bbox.hpp b/src/tile-bbox.hpp index 49163c5f..755004d2 100644 --- a/src/tile-bbox.hpp +++ b/src/tile-bbox.hpp @@ -2,16 +2,17 @@ #include "tile-constants.hpp" #include "src/local-coords.hpp" #include <Corrade/Containers/Pair.h> -#include <Magnum/Magnum.h> +#include <Magnum/DimensionTraits.h> #include <Magnum/Math/Vector2.h> namespace floormat { +template<typename T = float> constexpr Vector2 tile_start(size_t k) { - constexpr auto half_tile = Vector2(tile_size_xy)/2; + constexpr auto half_tile = VectorTypeFor<2,T>(tile_size_xy/2); const local_coords coord{k}; - return TILE_SIZE2 * Vector2(coord) - half_tile; + return TILE_SIZE2 * VectorTypeFor<2,T>(coord) - half_tile; } constexpr Pair<Vector2i, Vector2i> scenery_tile(local_coords local, Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size) @@ -22,28 +23,32 @@ constexpr Pair<Vector2i, Vector2i> scenery_tile(local_coords local, Vector2b off return { min, min + size, }; } -constexpr Pair<Vector2, Vector2> whole_tile(size_t k) +template<typename T = float> +constexpr Pair<VectorTypeFor<2,T>, VectorTypeFor<2,T>> whole_tile(size_t k) { - auto min = tile_start(k); + auto min = tile_start<T>(k); return { min, min + TILE_SIZE2, }; } -constexpr Pair<Vector2, Vector2> wall_north(size_t k, float wall_depth) +template<typename T = float> +constexpr Pair<VectorTypeFor<2,T>, VectorTypeFor<2,T>> wall_north(size_t k, float wall_depth) { - auto min = tile_start(k) - Vector2{0, wall_depth}; - return { min, min + Vector2{TILE_SIZE2.x(), wall_depth} }; + auto min = tile_start<T>(k) - VectorTypeFor<2,T>{0, wall_depth}; + return { min, min + VectorTypeFor<2,T>{TILE_SIZE2.x(), wall_depth} }; } -constexpr Pair<Vector2, Vector2> wall_west(size_t k, float wall_depth) +template<typename T = float> +constexpr Pair<VectorTypeFor<2,T>, VectorTypeFor<2,T>> wall_west(size_t k, float wall_depth) { - auto min = tile_start(k) - Vector2{wall_depth, 0}; - return { min, min + Vector2{wall_depth, TILE_SIZE2.y()} }; + auto min = tile_start<T>(k) - VectorTypeFor<2,T>{wall_depth, 0}; + return { min, min + VectorTypeFor<2,T>{wall_depth, TILE_SIZE2.y()} }; } -constexpr Pair<Vector2, Vector2> wall_pillar(size_t k, float wall_depth) +template<typename T = float> +constexpr Pair<VectorTypeFor<2,T>, VectorTypeFor<2,T>> wall_pillar(size_t k, float wall_depth) { - auto min = tile_start(k) - Vector2{wall_depth, 0}; - return { min - Vector2{0, wall_depth}, min + Vector2{wall_depth, TILE_SIZE2.y()} }; + auto min = tile_start<T>(k) - VectorTypeFor<2,T>{wall_depth, 0}; + return { min - VectorTypeFor<2,T>{0, wall_depth}, min + VectorTypeFor<2,T>{wall_depth, TILE_SIZE2.y()} }; } } // namespace floormat |