summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-11-22 21:38:29 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-11-22 21:38:29 +0100
commit8ea6924dda8d452bd870302a2c4e96f437ee5443 (patch)
treecbcbf3724a891013923266542688d278fff49c03
parent9bde31b07ada8aa5a3a2d30ffa904c38c3c0e09a (diff)
flush
-rw-r--r--compat/assert.hpp9
-rw-r--r--loader/atlas.cpp4
-rw-r--r--serialize/wall-atlas.cpp9
-rw-r--r--src/wall-atlas.cpp4
-rw-r--r--test/wall-atlas.cpp5
-rw-r--r--userconfig-sthalik@Windows-GNU.cmake3
-rw-r--r--wall-tileset-tool/main.cpp1
7 files changed, 25 insertions, 10 deletions
diff --git a/compat/assert.hpp b/compat/assert.hpp
index cce97d8e..683b9e72 100644
--- a/compat/assert.hpp
+++ b/compat/assert.hpp
@@ -92,11 +92,12 @@
{ \
if (a != b) [[unlikely]] \
{ \
- DBG_nospace << __FILE__ << ":" << __LINE__ << ": " \
- << Debug::color(Debug::Color::Red) \
+ DBG_nospace << Debug::color(Debug::Color::Red) \
<< "fatal:" \
- << Debug::resetColor \
- << " assertion failed: " << #__VA_ARGS__; \
+ << Debug::resetColor << " " \
+ << "Equality assertion failed at " \
+ << __FILE__ << ":" << __LINE__ << ":"; \
+ DBG_nospace << #__VA_ARGS__; \
DBG_nospace << " expected: " << a; \
DBG_nospace << " actual: " << b; \
fm_EMIT_ABORT(); \
diff --git a/loader/atlas.cpp b/loader/atlas.cpp
index acc1d069..e811e61e 100644
--- a/loader/atlas.cpp
+++ b/loader/atlas.cpp
@@ -28,7 +28,9 @@ StringView loader_::make_atlas_path(char(&buf)[FILENAME_MAX], StringView dir, St
bool loader_::check_atlas_name(StringView str) noexcept
{
- if (!str || str[0] == '.' || str[0] == '/')
+ constexpr auto first_char =
+ "_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"_s;
+ if (!str || !first_char.find(str[0]))
return false;
if (str.findAny("\\\"'\n\r\t\a\033\0|$!%{}#^*?<>&;:^"_s) || str.find("/."_s))
return false;
diff --git a/serialize/wall-atlas.cpp b/serialize/wall-atlas.cpp
index 82210f57..c045678b 100644
--- a/serialize/wall-atlas.cpp
+++ b/serialize/wall-atlas.cpp
@@ -53,6 +53,7 @@ wall_atlas_def wall_atlas_def::deserialize(StringView filename)
const auto jroot = json_helper::from_json_(filename);
atlas.header = read_info_header(jroot);
+ fm_soft_assert(loader.check_atlas_name(atlas.header.name));
atlas.frames = read_all_frames(jroot);
auto [dirs, dir_indexes] = read_all_directions(jroot);
fm_soft_assert(!dirs.isEmpty());
@@ -158,9 +159,9 @@ Group read_group_metadata(const json& jgroup)
if (jgroup.contains("pixel-size"))
val.pixel_size = jgroup["pixel-size"];
if (jgroup.contains("tint-mult"))
- val.tint_mult = Vector4(jgroup["tint-mult"]);
+ val.tint_mult = static_cast<Vector4>(jgroup["tint-mult"]);
if (jgroup.contains("tint-add"))
- val.tint_add = Vector3(jgroup["tint-add"]);
+ val.tint_add = static_cast<Vector3>(jgroup["tint-add"]);
if (jgroup.contains("from-rotation") && !jgroup["from-rotation"].is_null())
val.from_rotation = (uint8_t)direction_index_from_name(std::string{ jgroup["from-rotation"] });
if (jgroup.contains("mirrored"))
@@ -249,8 +250,8 @@ void write_group_metadata(json& jgroup, const Group& val)
jgroup["count"] = val.count;
jgroup["pixel-size"] = val.pixel_size;
- jgroup["tint-mult"] = Vector4(val.tint_mult);
- jgroup["tint-add"] = Vector3(val.tint_add);
+ jgroup["tint-mult"] = static_cast<Vector4>(val.tint_mult);
+ jgroup["tint-add"] = static_cast<Vector3>(val.tint_add);
if (val.from_rotation != group_defaults.from_rotation)
jgroup["from-rotation"] = direction_index_to_name(val.from_rotation);
else
diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp
index 9c700548..9c544896 100644
--- a/src/wall-atlas.cpp
+++ b/src/wall-atlas.cpp
@@ -22,7 +22,9 @@ void wall_atlas::validate(const wall_atlas& a, const ImageView2D& img) noexcept(
for (const auto& frame : a.raw_frame_array())
{
fm_soft_assert(frame.offset < Vector2ui{(unsigned)width, (unsigned)height});
- // todo check frame offset + size
+ fm_soft_assert(frame.offset.y() + iTILE_SIZE.z() <= height);
+ fm_soft_assert(frame.offset.x() < iTILE_SIZE2.x());
+ // todo check frame offset + size based on wall_atlas::expected_size()
}
const auto frame_count = a.raw_frame_array().size();
diff --git a/test/wall-atlas.cpp b/test/wall-atlas.cpp
index 188eb760..2c65a0e5 100644
--- a/test/wall-atlas.cpp
+++ b/test/wall-atlas.cpp
@@ -107,6 +107,11 @@ void test_read_groups(StringView filename)
void test_expected_size()
{
fm_assert_equal(Vector2i{64, 192}, wall_atlas::expected_size(42, Tag::wall));
+ fm_assert_equal(Vector2i{42, 192}, wall_atlas::expected_size(42, Tag::side));
+ fm_assert_equal(Vector2i{32, 192}, wall_atlas::expected_size(42, Tag::corner_L));
+ fm_assert_equal(Vector2i{32, 192}, wall_atlas::expected_size(42, Tag::corner_R));
+ // swapped in atlas.json during reading and writing, rotated in atlas image file
+ fm_assert_equal(Vector2i{42, 192}, wall_atlas::expected_size(42, Tag::top));
}
} // namespace
diff --git a/userconfig-sthalik@Windows-GNU.cmake b/userconfig-sthalik@Windows-GNU.cmake
index 2e160d9e..18d8693b 100644
--- a/userconfig-sthalik@Windows-GNU.cmake
+++ b/userconfig-sthalik@Windows-GNU.cmake
@@ -18,6 +18,9 @@ set(OpenCV_DIR "f:/dev/opentrack-depends/opencv/build-gcc/install" CACHE PATH ""
if(CMAKE_BUILD_TYPE STREQUAL "DEBUG")
add_definitions(-D_GLIBCXX_ASSERTIONS)
+ add_definitions(-D_GLIBCXX_USE_DEPRECATED=0 -D_GLIBCXX_USE_CXX11_ABI)
+ # todo recompile opencv
+ #add_definitions(-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_GLIBCXX_DEBUG_BACKTRACE)
endif()
set(FLOORMAT_SUBMODULE-SDL2 1)
diff --git a/wall-tileset-tool/main.cpp b/wall-tileset-tool/main.cpp
index c04d4988..b61e28ae 100644
--- a/wall-tileset-tool/main.cpp
+++ b/wall-tileset-tool/main.cpp
@@ -33,6 +33,7 @@ struct options
std::shared_ptr<wall_atlas> read_from_file(StringView filename)
{
using namespace floormat::Wall::detail;
+ auto def = wall_atlas_def::deserialize(filename);
const auto jroot = json_helper::from_json_(filename);
auto header = read_info_header(jroot);