summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-06-11 10:56:22 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-06-11 10:56:22 +0200
commit954c223d3276ae312274e9f0a3c47396b8cf9d60 (patch)
treed9b54e3f210bcc073e44a4809298a650a94fdb52
parentb0925a6a5e16dce10cb9b5bd99b62f96b2953441 (diff)
.
-rw-r--r--CMakeLists.txt2
-rw-r--r--anim/CMakeLists.txt9
-rw-r--r--anim/atlas.cpp (renamed from crop-tool/atlas.cpp)0
-rw-r--r--anim/atlas.hpp (renamed from crop-tool/atlas.hpp)2
-rw-r--r--anim/serialize.cpp (renamed from crop-tool/serialize.cpp)2
-rw-r--r--anim/serialize.hpp (renamed from crop-tool/serialize.hpp)0
-rw-r--r--crop-tool/CMakeLists.txt12
-rw-r--r--crop-tool/crop-tool.cpp58
-rw-r--r--doc/atlas.json18
9 files changed, 58 insertions, 45 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ac9065fb..d5245256 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -53,7 +53,9 @@ if(NOT BOOTSTRAP_DEPENDS)
find_package(MagnumPlugins QUIET REQUIRED)
find_package(MagnumIntegration QUIET REQUIRED COMPONENTS Glm)
+ include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
add_subdirectory(crop-tool)
+ add_subdirectory(anim)
corrade_add_resource(game_RESOURCES resources.conf)
file(GLOB sources "*.cpp" CONFIGURE_ARGS)
diff --git a/anim/CMakeLists.txt b/anim/CMakeLists.txt
new file mode 100644
index 00000000..ae4bc542
--- /dev/null
+++ b/anim/CMakeLists.txt
@@ -0,0 +1,9 @@
+find_package(OpenCV QUIET REQUIRED COMPONENTS core imgcodecs imgproc)
+
+file(GLOB sources "*.cpp" CONFIGURE_ARGS)
+set(self "${PROJECT_NAME}-anim")
+add_library(${self} STATIC ${sources})
+
+target_include_directories(${self} SYSTEM PRIVATE ${OpenCV_INCLUDE_DIRS})
+target_link_libraries(${self} opencv_imgproc opencv_imgcodecs opencv_core)
+target_link_libraries(${self} Magnum::Magnum)
diff --git a/crop-tool/atlas.cpp b/anim/atlas.cpp
index ca05cd15..ca05cd15 100644
--- a/crop-tool/atlas.cpp
+++ b/anim/atlas.cpp
diff --git a/crop-tool/atlas.hpp b/anim/atlas.hpp
index 675b6ff9..dd6efabc 100644
--- a/crop-tool/atlas.hpp
+++ b/anim/atlas.hpp
@@ -11,7 +11,7 @@ namespace std::filesystem { class path; }
struct anim_atlas_entry
{
anim_frame* frame;
- const cv::Mat4b mat;
+ cv::Mat4b mat;
};
struct anim_atlas_row
diff --git a/crop-tool/serialize.cpp b/anim/serialize.cpp
index acefe436..2a0b5a45 100644
--- a/crop-tool/serialize.cpp
+++ b/anim/serialize.cpp
@@ -68,6 +68,7 @@ void adl_serializer<Magnum::Vector2i>::from_json(const json& j, Magnum::Vector2i
j.at("y").get_to(x[1]);
}
+#if 0
void adl_serializer<anim_direction>::to_json(json& j, anim_direction x)
{
j = anim_group::direction_to_string(x);
@@ -77,6 +78,7 @@ void adl_serializer<anim_direction>::from_json(const json& j, anim_direction& x)
{
x = anim_group::string_to_direction(j);
}
+#endif
} // namespace nlohmann
diff --git a/crop-tool/serialize.hpp b/anim/serialize.hpp
index 10fd9e18..10fd9e18 100644
--- a/crop-tool/serialize.hpp
+++ b/anim/serialize.hpp
diff --git a/crop-tool/CMakeLists.txt b/crop-tool/CMakeLists.txt
index cc38c51b..974a07e9 100644
--- a/crop-tool/CMakeLists.txt
+++ b/crop-tool/CMakeLists.txt
@@ -1,6 +1,8 @@
-find_package(OpenCV QUIET REQUIRED COMPONENTS core imgcodecs imgproc highgui)
+find_package(OpenCV QUIET REQUIRED COMPONENTS core imgcodecs imgproc)
+set(self "${PROJECT_NAME}-crop-tool")
file(GLOB sources "*.cpp" CONFIGURE_ARGS)
-add_executable(crop-tool ${sources})
-target_include_directories(crop-tool SYSTEM PRIVATE ${OpenCV_INCLUDE_DIRS})
-target_link_libraries(crop-tool opencv_highgui opencv_imgproc opencv_imgcodecs opencv_core)
-target_link_libraries(crop-tool Corrade::Utility Magnum::Trade)
+
+add_executable(${self} ${sources})
+target_include_directories(${self} SYSTEM PRIVATE ${OpenCV_INCLUDE_DIRS})
+target_link_libraries(${self} Corrade::Utility)
+target_link_libraries(${self} game-anim)
diff --git a/crop-tool/crop-tool.cpp b/crop-tool/crop-tool.cpp
index 35089dd6..099ebfa1 100644
--- a/crop-tool/crop-tool.cpp
+++ b/crop-tool/crop-tool.cpp
@@ -1,13 +1,12 @@
#include "../defs.hpp"
-#include "atlas.hpp"
-#include "serialize.hpp"
+#include "anim/atlas.hpp"
+#include "anim/serialize.hpp"
#include <Corrade/Utility/Arguments.h>
#include <Corrade/Utility/Debug.h>
#include <Corrade/Utility/DebugStl.h>
#include <opencv2/core/mat.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/imgproc/imgproc.hpp>
-#include <opencv2/highgui.hpp>
#include <optional>
#include <tuple>
#include <filesystem>
@@ -35,9 +34,10 @@ using Corrade::Utility::Debug;
using std::filesystem::path;
-struct options_ {
- std::optional<unsigned> width, height;
- std::optional<double> scale;
+struct options
+{
+ unsigned width = 0, height = 0;
+ double scale = 0;
path input_dir, output_dir;
};
@@ -71,7 +71,7 @@ static std::tuple<cv::Vec2i, cv::Vec2i, bool> find_image_bounds(const path& path
}
[[nodiscard]]
-static bool load_file(anim_group& group, options_& opts, anim_atlas& atlas, const path& filename)
+static bool load_file(anim_group& group, options& opts, anim_atlas& atlas, const path& filename)
{
auto mat = progn(
cv::Mat mat_ = cv::imread(filename.string(), cv::IMREAD_UNCHANGED);
@@ -93,18 +93,18 @@ static bool load_file(anim_group& group, options_& opts, anim_atlas& atlas, cons
cv::Size size{end - start}, dest_size;
- if (!opts.scale)
+ if (opts.scale == 0.0)
{
+ ASSERT(opts.width || opts.height);
if (opts.width)
- opts.scale = (double)*opts.width / size.width;
- else if (opts.height)
- opts.scale = (double)*opts.height / size.height;
+ opts.scale = (double)opts.width / size.width;
else
- std::abort();
+ opts.scale = (double)opts.height / size.height;
+ ASSERT(opts.scale > 1e-6);
}
- dest_size = {(int)std::round(*opts.scale * size.width),
- (int)std::round(*opts.scale * size.height)};
+ dest_size = {(int)std::round(opts.scale * size.width),
+ (int)std::round(opts.scale * size.height)};
if (size.width < dest_size.width || size.height < dest_size.height)
{
@@ -122,19 +122,17 @@ static bool load_file(anim_group& group, options_& opts, anim_atlas& atlas, cons
}
#endif
Magnum::Vector2i ground = {
- (int)std::round((group.ground[0] - start[0]) * *opts.scale),
- (int)std::round((group.ground[1] - start[1]) * *opts.scale),
+ (int)std::round((group.ground[0] - start[0]) * opts.scale),
+ (int)std::round((group.ground[1] - start[1]) * opts.scale),
};
- auto offset = atlas.offset();
-
- group.frames.push_back({ground, offset, {dest_size.width, dest_size.height}});
+ group.frames.push_back({ground, atlas.offset(), {dest_size.width, dest_size.height}});
atlas.add_entry({&group.frames.back(), std::move(mat)});
return true;
}
[[nodiscard]]
-static bool load_directory(anim_group& group, options_& opts, anim_atlas& atlas, const path& input_dir)
+static bool load_directory(anim_group& group, options& opts, anim_atlas& atlas, const path& input_dir)
{
if (std::error_code ec{}; !std::filesystem::exists(input_dir/".", ec))
{
@@ -184,7 +182,7 @@ static char* fix_argv0(char* argv0)
return argv0;
}
-static std::tuple<options_, int> parse_cmdline(int argc, const char* const* argv)
+static std::tuple<options, int> parse_cmdline(int argc, const char* const* argv)
{
Corrade::Utility::Arguments args{};
args.addOption('o', "output")
@@ -192,23 +190,23 @@ static std::tuple<options_, int> parse_cmdline(int argc, const char* const* argv
.addOption('W', "width", "")
.addOption('H', "height", "");
args.parse(argc, argv);
- options_ options;
+ options opts;
if (unsigned w = args.value<unsigned>("width"); w != 0)
- options.width = w;
+ opts.width = w;
if (unsigned h = args.value<unsigned>("height"); h != 0)
- options.height = h;
- if (!(!options.width ^ !options.height))
+ opts.height = h;
+ if (!(!opts.width ^ !opts.height))
{
Error{} << "exactly one of --width, --height must be given";
goto usage;
}
- options.output_dir = args.value<std::string>("output");
- options.input_dir = args.value<std::string>("directory");
+ opts.output_dir = args.value<std::string>("output");
+ opts.input_dir = args.value<std::string>("directory");
- if (options.output_dir.empty())
- options.output_dir = options.input_dir;
+ if (opts.output_dir.empty())
+ opts.output_dir = opts.input_dir;
- return {options, 0};
+ return { opts, 0};
usage:
Error{Error::Flag::NoNewlineAtTheEnd} << Corrade::Containers::StringView{args.usage()};
return {{}, EX_USAGE};
diff --git a/doc/atlas.json b/doc/atlas.json
index 53f9722c..c5b05b15 100644
--- a/doc/atlas.json
+++ b/doc/atlas.json
@@ -2,16 +2,16 @@
"name": "character",
"nframes": 24,
"actionframe": 0,
- "fps": 1,
+ "fps": 24,
"groups": [
- { "direction": "N", "frames": [], "ground": {"x":484, "y":488} },
- { "direction": "NE", "frames": [], "ground": {"x": 0, "y": 0} },
- { "direction": "E", "frames": [], "ground": {"x": 0, "y": 0} },
- { "direction": "SE", "frames": [], "ground": {"x": 0, "y": 0} },
- { "direction": "S", "frames": [], "ground": {"x": 0, "y": 0} },
- { "direction": "SW", "frames": [], "ground": {"x": 0, "y": 0} },
- { "direction": "W", "frames": [], "ground": {"x": 0, "y": 0} },
- { "direction": "NW", "frames": [], "ground": {"x": 0, "y": 0} }
+ { "name": "n", "frames": [], "ground": {"x":484, "y":488} },
+ { "name": "ne", "frames": [], "ground": {"x": 0, "y": 0} },
+ { "name": "e", "frames": [], "ground": {"x": 0, "y": 0} },
+ { "name": "se", "frames": [], "ground": {"x": 0, "y": 0} },
+ { "name": "s", "frames": [], "ground": {"x": 0, "y": 0} },
+ { "name": "sw", "frames": [], "ground": {"x": 0, "y": 0} },
+ { "name": "w", "frames": [], "ground": {"x": 0, "y": 0} },
+ { "name": "nw", "frames": [], "ground": {"x": 0, "y": 0} }
]
}