diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/anim-atlas.cpp | 31 | ||||
-rw-r--r-- | src/anim-atlas.hpp | 8 | ||||
-rw-r--r-- | src/character.cpp | 2 | ||||
-rw-r--r-- | src/entity.cpp | 7 | ||||
-rw-r--r-- | src/entity.hpp | 2 | ||||
-rw-r--r-- | src/tile-atlas.cpp | 7 | ||||
-rw-r--r-- | src/world.cpp | 6 | ||||
-rw-r--r-- | src/world.hpp | 3 |
8 files changed, 35 insertions, 31 deletions
diff --git a/src/anim-atlas.cpp b/src/anim-atlas.cpp index 73ce5995..64bdbdbc 100644 --- a/src/anim-atlas.cpp +++ b/src/anim-atlas.cpp @@ -2,6 +2,7 @@ #include "compat/assert.hpp" #include "shaders/tile.hpp" #include "tile-defs.hpp" +#include "compat/exception.hpp" #include <Corrade/Containers/BitArrayView.h> #include <Corrade/Containers/StridedArrayView.h> #include <Magnum/Math/Color.h> @@ -15,12 +16,12 @@ static constexpr inline auto rot_count = size_t(rotation_COUNT); static_assert(std::size(name_array) == rot_count); static_assert(rot_count == 8); -uint8_t anim_atlas::rotation_to_index(StringView name) noexcept +uint8_t anim_atlas::rotation_to_index(StringView name) { for (uint8_t i = 0; i < rot_count; i++) if (name == StringView{name_array[i]}) return i; - fm_abort("can't parse rotation name '%s'", name.data()); + fm_throw("can't parse rotation name '{}'"_cf, name); } decltype(anim_atlas::_group_indices) anim_atlas::make_group_indices(const anim_def& a) noexcept @@ -35,23 +36,23 @@ decltype(anim_atlas::_group_indices) anim_atlas::make_group_indices(const anim_d } anim_atlas::anim_atlas() noexcept = default; -anim_atlas::anim_atlas(String name, const ImageView2D& image, anim_def info) noexcept : +anim_atlas::anim_atlas(String name, const ImageView2D& image, anim_def info) : _name{std::move(name)}, _bitmask{make_bitmask(image)}, _info{std::move(info)}, _group_indices{make_group_indices(_info)} { - fm_assert(!_info.groups.empty()); + fm_soft_assert(!_info.groups.empty()); const Size<3> size = image.pixels().size(); - fm_assert(size[0]*size[1] == _info.pixel_size.product()); - fm_assert(size[2] >= 3 && size[2] <= 4); + fm_soft_assert(size[0]*size[1] == _info.pixel_size.product()); + fm_soft_assert(size[2] >= 3 && size[2] <= 4); for (const auto pixel_size = _info.pixel_size; const auto& group : _info.groups) for (const auto& fr : group.frames) { - fm_assert(fr.size.product() != 0); - fm_assert(fr.offset < pixel_size); - fm_assert(fr.offset + fr.size <= pixel_size); + fm_soft_assert(fr.size.product() != 0); + fm_soft_assert(fr.offset < pixel_size); + fm_soft_assert(fr.offset + fr.size <= pixel_size); } _tex.setWrapping(GL::SamplerWrapping::ClampToEdge) @@ -71,17 +72,17 @@ StringView anim_atlas::name() const noexcept { return _name; } GL::Texture2D& anim_atlas::texture() noexcept { return _tex; } const anim_def& anim_atlas::info() const noexcept { return _info; } -auto anim_atlas::group(rotation r) const noexcept -> const anim_group& +auto anim_atlas::group(rotation r) const -> const anim_group& { const auto group_idx = _group_indices[size_t(r)]; - fm_assert(group_idx != 0xff); + fm_soft_assert(group_idx != 0xff); return _info.groups[group_idx]; } -auto anim_atlas::frame(rotation r, size_t frame) const noexcept -> const anim_frame& +auto anim_atlas::frame(rotation r, size_t frame) const -> const anim_frame& { const anim_group& g = group(r); - fm_assert(frame < g.frames.size()); + fm_soft_assert(frame < g.frames.size()); return g.frames[frame]; } @@ -136,8 +137,8 @@ void anim_atlas::make_bitmask_(const ImageView2D& tex, BitArray& array) const auto* const data = (const unsigned char*)pixels.data(); auto* const dest = (unsigned char*)array.data(); - fm_assert(tex.pixelSize() == 4); - fm_assert(pixels.stride()[1] == 4); + fm_soft_assert(tex.pixelSize() == 4); + fm_soft_assert(pixels.stride()[1] == 4); for (auto j = 0_uz; j < height; j++) { diff --git a/src/anim-atlas.hpp b/src/anim-atlas.hpp index ff690efd..0a05fe43 100644 --- a/src/anim-atlas.hpp +++ b/src/anim-atlas.hpp @@ -24,7 +24,7 @@ struct anim_atlas final using quad = std::array<Vector3, 4>; anim_atlas() noexcept; - anim_atlas(String name, const ImageView2D& tex, anim_def info) noexcept; + anim_atlas(String name, const ImageView2D& tex, anim_def info); ~anim_atlas() noexcept; anim_atlas(anim_atlas&&) noexcept; @@ -34,8 +34,8 @@ struct anim_atlas final GL::Texture2D& texture() noexcept; const anim_def& info() const noexcept; - const anim_group& group(rotation r) const noexcept; - const anim_frame& frame(rotation r, size_t frame) const noexcept; + const anim_group& group(rotation r) const; + const anim_frame& frame(rotation r, size_t frame) const; texcoords texcoords_for_frame(rotation r, size_t frame, bool mirror) const noexcept; quad frame_quad(const Vector3& center, rotation r, size_t frame) const noexcept; @@ -61,7 +61,7 @@ private: GL::Texture2D _tex; static decltype(_group_indices) make_group_indices(const anim_def& anim) noexcept; - static uint8_t rotation_to_index(StringView name) noexcept; + static uint8_t rotation_to_index(StringView name); }; } // namespace floormat diff --git a/src/character.cpp b/src/character.cpp index 84289f01..f63b35e9 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -150,7 +150,7 @@ character::character(object_id id, struct chunk& c, entity_type type, const char name = "(Unnamed)"_s; if (!atlas) atlas = loader.anim_atlas("npc-walk", loader.ANIM_PATH); - fm_assert(atlas->check_rotation(r)); + fm_soft_assert(atlas->check_rotation(r)); entity::set_bbox_(offset, bbox_offset, Vector2ub(iTILE_SIZE2/2), pass); } diff --git a/src/entity.cpp b/src/entity.cpp index 820d0456..70e0ffb5 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -3,6 +3,7 @@ #include "rotation.inl" #include "anim-atlas.hpp" #include "RTree.hpp" +#include "compat/exception.hpp" #include <algorithm> namespace floormat { @@ -13,7 +14,7 @@ entity_proto::~entity_proto() noexcept = default; entity_proto::entity_proto() = default; entity_proto::entity_proto(const entity_proto&) = default; -entity::entity(object_id id, struct chunk& c, entity_type type, const entity_proto& proto) noexcept : +entity::entity(object_id id, struct chunk& c, entity_type type, const entity_proto& proto) : id{id}, c{&c}, atlas{proto.atlas}, offset{proto.offset}, bbox_offset{proto.bbox_offset}, bbox_size{proto.bbox_size}, delta{proto.delta}, @@ -22,8 +23,8 @@ entity::entity(object_id id, struct chunk& c, entity_type type, const entity_pro fm_assert(type == proto.type); if (atlas) { - fm_assert(atlas->check_rotation(r)); - fm_assert(frame < atlas->info().nframes); + fm_soft_assert(atlas->check_rotation(r)); + fm_soft_assert(frame < atlas->info().nframes); } } diff --git a/src/entity.hpp b/src/entity.hpp index 2ede577b..d8d3c63e 100644 --- a/src/entity.hpp +++ b/src/entity.hpp @@ -73,7 +73,7 @@ struct entity friend struct world; protected: - entity(object_id id, struct chunk& c, entity_type type, const entity_proto& proto) noexcept; + entity(object_id id, struct chunk& c, entity_type type, const entity_proto& proto); void set_bbox_(Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size, pass_mode pass); }; diff --git a/src/tile-atlas.cpp b/src/tile-atlas.cpp index 3438e6a1..f7d29864 100644 --- a/src/tile-atlas.cpp +++ b/src/tile-atlas.cpp @@ -2,6 +2,7 @@ #include "tile-atlas.hpp" #include "compat/assert.hpp" #include "tile-image.hpp" +#include "compat/exception.hpp" #include <limits> #include <Magnum/Math/Color.h> #include <Magnum/ImageView.h> @@ -14,9 +15,9 @@ tile_atlas::tile_atlas(StringView name, const ImageView2D& image, Vector2ub tile name_{name}, size_{image.size()}, dims_{tile_count}, passability{std::move(p)} { constexpr auto variant_max = std::numeric_limits<variant_t>::max(); - fm_assert(num_tiles() <= variant_max); - fm_assert(dims_[0] > 0 && dims_[1] > 0); - fm_assert(size_ % Vector2ui{tile_count} == Vector2ui()); + fm_soft_assert(num_tiles() <= variant_max); + fm_soft_assert(dims_[0] > 0 && dims_[1] > 0); + fm_soft_assert(size_ % Vector2ui{tile_count} == Vector2ui()); tex_.setWrapping(GL::SamplerWrapping::ClampToEdge) .setMagnificationFilter(GL::SamplerFilter::Linear) .setMinificationFilter(GL::SamplerFilter::Linear) diff --git a/src/world.cpp b/src/world.cpp index 7dab8dee..ef85732e 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -8,15 +8,15 @@ world::world(world&& w) noexcept = default; world& world::operator=(world&& w) noexcept { - fm_assert(!w._teardown); - fm_assert(!_teardown); if (&w != this) [[likely]] { + fm_assert(!w._teardown); + fm_assert(!_teardown); _last_collection = w._last_collection; _collect_every = w._collect_every; _unique_id = std::move(w._unique_id); fm_assert(_unique_id); - fm_assert(w._unique_id == nullptr); + fm_debug_assert(w._unique_id == nullptr); _last_chunk = {}; _chunks = std::move(w._chunks); _entities = std::move(w._entities); diff --git a/src/world.hpp b/src/world.hpp index 589bbd67..5d9b8eb6 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -4,6 +4,7 @@ #include "chunk.hpp" #include "global-coords.hpp" #include "entity-type.hpp" +#include "compat/exception.hpp" #include <unordered_map> #include <memory> @@ -109,7 +110,7 @@ std::shared_ptr<T> world::find_entity(object_id id) return ptr; else { - fm_assert(ptr->type == entity_type_<T>::value); + fm_soft_assert(ptr->type == entity_type_<T>::value); return std::static_pointer_cast<T>(std::move(ptr)); } } |