summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editor/tile-editor.cpp3
-rw-r--r--loader/atlas.cpp4
-rw-r--r--serialize/tile-atlas.cpp2
-rw-r--r--serialize/world-reader.cpp4
-rw-r--r--src/anim-atlas.cpp31
-rw-r--r--src/anim-atlas.hpp8
-rw-r--r--src/character.cpp2
-rw-r--r--src/entity.cpp7
-rw-r--r--src/entity.hpp2
-rw-r--r--src/tile-atlas.cpp7
-rw-r--r--src/world.cpp6
-rw-r--r--src/world.hpp3
-rw-r--r--test/serializer.cpp2
13 files changed, 44 insertions, 37 deletions
diff --git a/editor/tile-editor.cpp b/editor/tile-editor.cpp
index 4de40ab6..68fc0930 100644
--- a/editor/tile-editor.cpp
+++ b/editor/tile-editor.cpp
@@ -4,6 +4,7 @@
#include "keys.hpp"
#include "loader/loader.hpp"
#include "random.hpp"
+#include "compat/exception.hpp"
#include <Corrade/Containers/PairStl.h>
#include <Corrade/Utility/Path.h>
@@ -47,7 +48,7 @@ std::shared_ptr<tile_atlas> tile_editor::atlas(StringView str)
if (auto ptr = maybe_atlas(str))
return ptr;
else
- fm_abort("no such atlas: %s", str.cbegin());
+ fm_throw("no such atlas: {}"_cf, str);
}
StringView tile_editor::name() const noexcept { return _name; }
diff --git a/loader/atlas.cpp b/loader/atlas.cpp
index a87d4ec1..0a5afd7b 100644
--- a/loader/atlas.cpp
+++ b/loader/atlas.cpp
@@ -44,10 +44,10 @@ ArrayView<String> loader_impl::anim_atlas_list()
std::shared_ptr<anim_atlas> loader_impl::anim_atlas(StringView name, StringView dir) noexcept(false)
{
- fm_assert(dir && dir[dir.size()-1] == '/');
+ fm_soft_assert(dir && dir[dir.size()-1] == '/');
char path_buf[FILENAME_MAX];
name = Path::splitExtension(name).first();
- fm_assert(dir.size() + name.size() + 1 + 1 < FILENAME_MAX);
+ fm_soft_assert(dir.size() + name.size() + 1 + 1 < FILENAME_MAX);
std::memcpy(path_buf, dir.data(), dir.size());
path_buf[dir.size()] = '/';
std::memcpy(&path_buf[dir.size() + 1], name.data(), name.size());
diff --git a/serialize/tile-atlas.cpp b/serialize/tile-atlas.cpp
index b56239c6..29a456dc 100644
--- a/serialize/tile-atlas.cpp
+++ b/serialize/tile-atlas.cpp
@@ -54,7 +54,7 @@ void adl_serializer<std::shared_ptr<tile_atlas>>::from_json(const json& j, std::
{
int m = p2 ? int(*p2) : -1;
const auto name = val->name();
- fm_throw("atlas {} wrong pass mode {} should be {}"_cf, StringView{name.data(), name.size()}, m, uint8_t(*p));
+ fm_throw("atlas {} wrong pass mode {} should be {}"_cf, name, m, uint8_t(*p));
}
}
}
diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp
index 0a99f74f..61c3984c 100644
--- a/serialize/world-reader.cpp
+++ b/serialize/world-reader.cpp
@@ -61,7 +61,7 @@ bool read_entity_flags(binary_reader<T>& s, U& e)
uint8_t flags; flags << s;
e.pass = pass_mode(flags & pass_mask);
if (e.type != tag)
- fm_abort("invalid entity type '%d'", (int)e.type);
+ fm_throw("invalid entity type '{}'"_cf, (int)e.type);
if constexpr(tag == entity_type::scenery)
{
e.active = !!(flags & 1 << 2);
@@ -368,7 +368,7 @@ world world::deserialize(StringView filename)
FILE_raii f = ::fopen(filename.data(), "rb");
if (!f)
{
- fm_throw("fopen(\"{}\", \"r\"): {}"_cf, filename.data(), get_error_string(errbuf));
+ fm_throw("fopen(\"{}\", \"r\"): {}"_cf, filename, get_error_string(errbuf));
}
if (int ret = ::fseek(f, 0, SEEK_END); ret != 0)
fm_throw("fseek(SEEK_END): {}"_cf, get_error_string(errbuf));
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));
}
}
diff --git a/test/serializer.cpp b/test/serializer.cpp
index 87f11b4a..5a520dbb 100644
--- a/test/serializer.cpp
+++ b/test/serializer.cpp
@@ -106,12 +106,14 @@ void test_serializer(StringView input, StringView tmp)
void test_app::test_serializer_1()
{
+ fm_assert(Path::exists("../CMakeCache.txt"));
constexpr auto tmp_filename = "../test/test-serializer1.dat"_s;
test_serializer({}, tmp_filename);
}
void test_app::test_serializer_2()
{
+ fm_assert(Path::exists("../CMakeCache.txt"));
constexpr auto tmp_filename = "../test/test-serializer2.dat"_s;
constexpr auto dir = "../test/save/"_s;
using LF = Path::ListFlag;