summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editor/tile-editor.cpp1
-rw-r--r--editor/tile-editor.hpp4
-rw-r--r--loader/loader-impl.cpp6
-rw-r--r--serialize/anim.cpp1
-rw-r--r--serialize/anim.hpp6
-rw-r--r--serialize/magnum-vector2i.hpp5
-rw-r--r--serialize/string.cpp39
-rw-r--r--serialize/string.hpp27
-rw-r--r--serialize/tile-atlas.cpp3
-rw-r--r--src/tile-atlas.cpp3
-rw-r--r--src/tile-atlas.hpp3
11 files changed, 16 insertions, 82 deletions
diff --git a/editor/tile-editor.cpp b/editor/tile-editor.cpp
index 87d869b8..2d833443 100644
--- a/editor/tile-editor.cpp
+++ b/editor/tile-editor.cpp
@@ -6,6 +6,7 @@
#include "random.hpp"
#include "serialize/json-helper.hpp"
#include "serialize/tile-atlas.hpp"
+#include <Corrade/Containers/StringStlHash.h>
namespace floormat {
diff --git a/editor/tile-editor.hpp b/editor/tile-editor.hpp
index 9593139c..5c90ff3d 100644
--- a/editor/tile-editor.hpp
+++ b/editor/tile-editor.hpp
@@ -6,7 +6,7 @@
#include <memory>
#include <vector>
#include <map>
-#include <Corrade/Containers/String.h>
+#include <Corrade/Containers/StringView.h>
namespace floormat {
@@ -25,7 +25,7 @@ private:
};
String _name;
- std::map<std::string, std::shared_ptr<tile_atlas>> _atlases;
+ std::map<StringView, std::shared_ptr<tile_atlas>> _atlases;
tile_image_proto _selected_tile;
tuple _permutation;
selection_mode _selection_mode = sel_none;
diff --git a/loader/loader-impl.cpp b/loader/loader-impl.cpp
index 7299d69b..fe1f2f12 100644
--- a/loader/loader-impl.cpp
+++ b/loader/loader-impl.cpp
@@ -85,7 +85,7 @@ std::shared_ptr<tile_atlas> loader_impl::tile_atlas(StringView name, Vector2ub s
template<std::size_t N>
Trade::ImageData2D loader_impl::texture(const char(&prefix)[N], StringView filename_)
{
- fm_assert(N == 1 || prefix[N-2] == '/');
+ fm_assert(N <= 2 || prefix[N-2] == '/');
fm_assert(filename_.size() < 4096);
fm_assert(filename_.find('\\') == filename_.end());
fm_assert(filename_.find('\0') == filename_.end());
@@ -95,7 +95,7 @@ Trade::ImageData2D loader_impl::texture(const char(&prefix)[N], StringView filen
char* const filename = (char*)alloca(filename_.size() + N + max_extension_length);
const std::size_t len = fm_begin(
std::size_t off = N-1;
- if (N > 1)
+ if constexpr(N > 1)
std::memcpy(filename, prefix, off);
std::memcpy(filename + off, filename_.cbegin(), filename_.size());
return off + filename_.size();
@@ -139,7 +139,7 @@ std::shared_ptr<anim_atlas> loader_impl::anim_atlas(StringView name)
p.replace_extension({});
auto tex = texture("", path);
- fm_assert(!anim_info.anim_name.isEmpty() && !anim_info.object_name.isEmpty());
+ fm_assert(!anim_info.anim_name.empty() && !anim_info.object_name.empty());
fm_assert(anim_info.pixel_size.product() > 0);
fm_assert(!anim_info.groups.empty());
fm_assert(anim_info.nframes > 0);
diff --git a/serialize/anim.cpp b/serialize/anim.cpp
index 9cafbfc0..79608de0 100644
--- a/serialize/anim.cpp
+++ b/serialize/anim.cpp
@@ -1,6 +1,5 @@
#include "serialize/magnum-vector2i.hpp"
#include "serialize/anim.hpp"
-#include "serialize/string.hpp"
namespace floormat::Serialize {
diff --git a/serialize/anim.hpp b/serialize/anim.hpp
index 9d6db66c..fa6b6d22 100644
--- a/serialize/anim.hpp
+++ b/serialize/anim.hpp
@@ -1,7 +1,7 @@
#pragma once
#include <vector>
-#include <Corrade/Containers/String.h>
+#include <string>
#include <Magnum/Magnum.h>
#include <Magnum/Math/Vector2.h>
#include <nlohmann/json_fwd.hpp>
@@ -22,7 +22,7 @@ enum class anim_direction : unsigned char
struct anim_group final
{
- String name;
+ std::string name;
std::vector<anim_frame> frames;
Vector2ui ground;
};
@@ -31,7 +31,7 @@ struct anim final
{
static constexpr int default_fps = 24;
- String object_name, anim_name;
+ std::string object_name, anim_name;
std::vector<anim_group> groups;
Vector2ui pixel_size;
std::size_t nframes = 0, width = 0, height = 0, fps = default_fps, actionframe = 0;
diff --git a/serialize/magnum-vector2i.hpp b/serialize/magnum-vector2i.hpp
index 7b78d73f..d1074b55 100644
--- a/serialize/magnum-vector2i.hpp
+++ b/serialize/magnum-vector2i.hpp
@@ -1,8 +1,7 @@
#include "compat/assert.hpp"
-#include "serialize/string.hpp"
#include <cstdio>
+#include <string>
#include <Magnum/Math/Vector2.h>
-#include <Corrade/Containers/StringView.h>
#include <nlohmann/json.hpp>
namespace nlohmann {
@@ -21,7 +20,7 @@ struct adl_serializer<Magnum::Math::Vector2<t>> final
}
static void from_json(const json& j, Magnum::Math::Vector2<t>& val)
{
- Corrade::Containers::StringView str = j;
+ std::string str = j;
using type = std::conditional_t<std::is_signed_v<t>, std::intmax_t, std::uintmax_t>;
constexpr auto format_string = std::is_signed_v<t> ? "%jd x %jd%n" : "%ju x %ju%n";
type x = 0, y = 0;
diff --git a/serialize/string.cpp b/serialize/string.cpp
deleted file mode 100644
index 0c0fa74e..00000000
--- a/serialize/string.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "string.hpp"
-#include <Corrade/Containers/String.h>
-#include <string_view>
-#include <nlohmann/json.hpp>
-
-using String = Corrade::Containers::String;
-using StringView = Corrade::Containers::StringView;
-
-namespace nlohmann {
-
-void adl_serializer<String>::to_json(json& j, const String& val)
-{
- using nlohmann::to_json;
- to_json(j, std::string_view { val.cbegin(), val.cend() });
-}
-
-void adl_serializer<String>::from_json(const json& j, String& val)
-{
- using nlohmann::from_json;
- std::string_view str;
- from_json(j, str);
- val = { str.cbegin(), str.size() };
-}
-
-void adl_serializer<StringView>::to_json(json& j, const StringView& val)
-{
- using nlohmann::to_json;
- to_json(j, std::string_view { val.cbegin(), val.cend() });
-}
-
-void adl_serializer<StringView>::from_json(const json& j, StringView& val)
-{
- using nlohmann::from_json;
- std::string_view str;
- from_json(j, str);
- val = { str.cbegin(), str.size() };
-}
-
-} // namespace nlohmann
diff --git a/serialize/string.hpp b/serialize/string.hpp
deleted file mode 100644
index 66e448a4..00000000
--- a/serialize/string.hpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#pragma once
-
-#include <nlohmann/json_fwd.hpp>
-
-namespace Corrade::Containers {
-
-template<typename T> class BasicStringView;
-class String;
-using StringView = BasicStringView<const char>;
-
-} // namespace Corrade::Containers
-
-namespace nlohmann {
-
-template<>
-struct adl_serializer<Corrade::Containers::String> {
- static void to_json(json& j, const Corrade::Containers::String& val);
- static void from_json(const json& j, Corrade::Containers::String& val);
-};
-
-template<>
-struct adl_serializer<Corrade::Containers::StringView> {
- static void to_json(json& j, const Corrade::Containers::StringView& val);
- static void from_json(const json& j, Corrade::Containers::StringView& val);
-};
-
-} // namespace nlohmann
diff --git a/serialize/tile-atlas.cpp b/serialize/tile-atlas.cpp
index 711d5fdd..8caaedd3 100644
--- a/serialize/tile-atlas.cpp
+++ b/serialize/tile-atlas.cpp
@@ -1,7 +1,6 @@
#include "src/tile-atlas.hpp"
#include "serialize/tile-atlas.hpp"
#include "serialize/magnum-vector2i.hpp"
-#include "serialize/string.hpp"
#include "loader.hpp"
#include <tuple>
@@ -11,7 +10,7 @@ using namespace floormat;
namespace nlohmann {
-using proxy_atlas = std::tuple<StringView, Vector2ub>;
+using proxy_atlas = std::tuple<std::string, Vector2ub>;
void adl_serializer<std::shared_ptr<tile_atlas>>::to_json(json& j, const std::shared_ptr<const tile_atlas>& x)
{
diff --git a/src/tile-atlas.cpp b/src/tile-atlas.cpp
index 11c3e6ae..7960c859 100644
--- a/src/tile-atlas.cpp
+++ b/src/tile-atlas.cpp
@@ -1,8 +1,9 @@
+
#include "tile-atlas.hpp"
#include "compat/assert.hpp"
#include "tile-image.hpp"
#include <limits>
-#include <Corrade/Containers/StringView.h>
+#include <Corrade/Containers/StringStl.h>
#include <Magnum/Math/Color.h>
#include <Magnum/ImageView.h>
#include <Magnum/GL/TextureFormat.h>
diff --git a/src/tile-atlas.hpp b/src/tile-atlas.hpp
index 026d2073..5856f3bb 100644
--- a/src/tile-atlas.hpp
+++ b/src/tile-atlas.hpp
@@ -3,6 +3,7 @@
#include <Magnum/Magnum.h>
#include <Magnum/GL/Texture.h>
#include <array>
+#include <string>
#include <memory>
namespace floormat {
@@ -31,7 +32,7 @@ private:
std::unique_ptr<const texcoords[]> texcoords_;
GL::Texture2D tex_;
- String name_;
+ std::string name_;
Vector2ui size_;
Vector2ub dims_;
};