summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/anim.cpp5
-rw-r--r--src/anim.hpp2
-rw-r--r--src/chunk-collision.cpp3
-rw-r--r--src/chunk-walls.cpp5
-rw-r--r--src/critter.cpp6
-rw-r--r--src/light-falloff.hpp3
-rw-r--r--src/object.hpp4
-rw-r--r--src/pass-mode.hpp3
-rw-r--r--src/rotation.hpp2
-rw-r--r--src/scenery.cpp15
-rw-r--r--src/scenery.hpp2
-rw-r--r--src/wall-atlas.cpp6
12 files changed, 26 insertions, 30 deletions
diff --git a/src/anim.cpp b/src/anim.cpp
index cf2317bc..717b3ee6 100644
--- a/src/anim.cpp
+++ b/src/anim.cpp
@@ -8,10 +8,11 @@ Vector2 anim_scale::scale_to_(Vector2ui image_size) const
{
fm_soft_assert(image_size.product() > 0);
Vector2 ret;
+ if (type >= anim_scale_type::COUNT) [[unlikely]]
+ fm_throw("invalid anim_scale_type '{}'"_cf, (unsigned)type);
switch (type)
{
- default:
- fm_throw("invalid anim_scale_type '{}'"_cf, (unsigned)type);
+ case anim_scale_type::COUNT: std::unreachable();
case anim_scale_type::invalid:
fm_throw("anim_scale is invalid"_cf);
case anim_scale_type::fixed:
diff --git a/src/anim.hpp b/src/anim.hpp
index e22d1e6b..e850097f 100644
--- a/src/anim.hpp
+++ b/src/anim.hpp
@@ -29,7 +29,7 @@ struct anim_group final
Vector3b offset{};
};
-enum class anim_scale_type : unsigned char { invalid, ratio, fixed, };
+enum class anim_scale_type : unsigned char { invalid, ratio, fixed, COUNT, };
struct anim_scale final
{
diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp
index 567be0ad..a7df3032 100644
--- a/src/chunk-collision.cpp
+++ b/src/chunk-collision.cpp
@@ -138,9 +138,10 @@ bool chunk::can_place_object(const object_proto& proto, local_coords pos)
{
(void)ensure_scenery_mesh();
+ fm_assert(proto.pass < pass_mode::COUNT);
switch (proto.pass)
{
- default:
+ case pass_mode::COUNT: std::unreachable();
case pass_mode::blocked:
case pass_mode::see_through:
break;
diff --git a/src/chunk-walls.cpp b/src/chunk-walls.cpp
index 13f42ead..c1214cb4 100644
--- a/src/chunk-walls.cpp
+++ b/src/chunk-walls.cpp
@@ -41,11 +41,11 @@ constexpr Quads::quad get_quad(Direction_ D, Group_ G, float depth)
constexpr float X = half_tile.x(), Y = half_tile.y(), Z = TILE_SIZE.z();
const bool is_west = D == Wall::Direction_::W;
+ fm_assert(G < Group_::COUNT);
switch (G)
{
using enum Group_;
- default:
- fm_abort("invalid wall_atlas group '%d'", (int)G);
+ case COUNT: std::unreachable();
case wall:
if (!is_west)
return {{
@@ -107,6 +107,7 @@ constexpr Quads::quad get_quad(Direction_ D, Group_ G, float depth)
{-X, -Y, Z },
}};
}
+ std::unreachable();
}
Array<Quads::indexes> make_indexes_()
diff --git a/src/critter.cpp b/src/critter.cpp
index d7fc8627..0fb3e406 100644
--- a/src/critter.cpp
+++ b/src/critter.cpp
@@ -26,7 +26,6 @@ constexpr auto arrows_to_dir(bool left, bool right, bool up, bool down)
switch (bits)
{
- default: std::unreachable(); // -Wswitch-default
using enum rotation;
case L | U: return W;
case L | D: return S;
@@ -47,6 +46,7 @@ constexpr auto arrows_to_dir(bool left, bool right, bool up, bool down)
case L|R:
return rotation{rotation_COUNT};
}
+ std::unreachable();
}
#if 0
static_assert(arrows_to_dir(true, false, false, false) == rotation::SW);
@@ -93,10 +93,8 @@ constexpr std::array<rotation, 3> rotation_to_similar(rotation r)
case SW: return { SW, S, W };
case W: return { W, SW, NW };
case NW: return { NW, W, N };
- default:
- std::unreachable();
- fm_assert(false);
}
+ std::unreachable();
}
template<rotation r> constexpr uint8_t get_length_axis()
diff --git a/src/light-falloff.hpp b/src/light-falloff.hpp
index f814cc5f..849ad92b 100644
--- a/src/light-falloff.hpp
+++ b/src/light-falloff.hpp
@@ -3,10 +3,9 @@
namespace floormat {
enum class light_falloff : uint8_t {
- constant = 1, linear = 0, quadratic = 2,
+ constant = 1, linear = 0, quadratic = 2, COUNT,
};
-constexpr inline light_falloff light_falloff_COUNT{3};
constexpr inline uint8_t light_falloff_BITS = 3;
constexpr inline uint8_t light_falloff_MASK = (1 << light_falloff_BITS)-1;
diff --git a/src/object.hpp b/src/object.hpp
index 4d2279e1..4c535340 100644
--- a/src/object.hpp
+++ b/src/object.hpp
@@ -24,8 +24,8 @@ struct object_proto
uint32_t delta = 0;
uint16_t frame = 0;
object_type type : 3 = object_type::none;
- rotation r : rotation_BITS = rotation::N;
- pass_mode pass : pass_mode_BITS = pass_mode::see_through; // todo move to struct scenery, add inherit bit
+ rotation r = rotation::N;
+ pass_mode pass = pass_mode::see_through; // todo move to struct scenery, add inherit bit
object_proto& operator=(const object_proto&);
object_proto();
diff --git a/src/pass-mode.hpp b/src/pass-mode.hpp
index 0bf8d867..60708a47 100644
--- a/src/pass-mode.hpp
+++ b/src/pass-mode.hpp
@@ -2,8 +2,7 @@
namespace floormat {
-enum class pass_mode : unsigned char { blocked, see_through, shoot_through, pass, };
-constexpr inline pass_mode pass_mode_COUNT{4};
+enum class pass_mode : unsigned char { blocked, see_through, shoot_through, pass, COUNT };
constexpr inline unsigned char pass_mode_BITS = 2;
} // namespace floormat
diff --git a/src/rotation.hpp b/src/rotation.hpp
index 471007c3..99f8c4a3 100644
--- a/src/rotation.hpp
+++ b/src/rotation.hpp
@@ -8,6 +8,6 @@ enum class rotation : unsigned char {
constexpr inline size_t rotation_BITS = 3;
constexpr inline size_t rotation_MASK = (1 << rotation_BITS)-1;
-constexpr inline rotation rotation_COUNT = rotation{1 << rotation_BITS};
+constexpr inline rotation rotation_COUNT = rotation{1 << rotation_BITS}; // todo! remove
} // namespace floormat
diff --git a/src/scenery.cpp b/src/scenery.cpp
index c5575f6a..484a84e9 100644
--- a/src/scenery.cpp
+++ b/src/scenery.cpp
@@ -181,14 +181,11 @@ bool scenery_proto::operator==(const object_proto& e0) const
return false;
return std::visit(
- [](const auto& a, const auto& b) {
- if constexpr(std::is_same_v< std::decay_t<decltype(a)>, std::decay_t<decltype(b)> >)
+ [](const auto& a, const auto& b) -> bool {
+ if constexpr(std::is_same_v<std::decay_t<decltype(a)>, std::decay_t<decltype(b)>>)
return a == b;
else
- {
- std::unreachable();
- return false;
- }
+ fm_assert(false);
},
subtype, sc.subtype
);
@@ -229,13 +226,13 @@ scenery_variants scenery::subtype_from_scenery_type(object_id id, class chunk& c
{
switch (type)
{
+ case scenery_type::none:
+ case scenery_type::COUNT:
+ break;
case scenery_type::generic:
return generic_scenery{id, c, {}};
case scenery_type::door:
return door_scenery{id, c, {}};
- case scenery_type::none:
- default:
- break;
}
fm_throw("invalid scenery type"_cf, (int)type);
}
diff --git a/src/scenery.hpp b/src/scenery.hpp
index e668f7a2..c7d2a92a 100644
--- a/src/scenery.hpp
+++ b/src/scenery.hpp
@@ -16,7 +16,7 @@ class anim_atlas;
class world;
enum class scenery_type : unsigned char {
- none, generic, door,
+ none, generic, door, COUNT,
};
struct generic_scenery_proto
diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp
index d82aace3..8ea687e4 100644
--- a/src/wall-atlas.cpp
+++ b/src/wall-atlas.cpp
@@ -95,10 +95,10 @@ Vector2ui wall_atlas::expected_size(unsigned depth, Group_ group)
case side:
case corner:
return { depth, size.z() };
- default:
- std::unreachable();
- fm_assert(false);
+ case COUNT:
+ break;
}
+ fm_assert(false);
}
wall_atlas::wall_atlas(wall_atlas_def def, String path, const ImageView2D& img)