summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-06 07:11:48 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-06 07:11:48 +0200
commit66ee29df9c19e35b4c126e12e48bc144fe72eb22 (patch)
treec5d8a80cb917a1e33d8efdf6ffc653694e67c759
parent9b2b5c5fd5880f35e2e952bb89fc709f4b814364 (diff)
a
-rw-r--r--CMakeLists.txt31
-rw-r--r--anim-crop-tool/CMakeLists.txt2
-rw-r--r--main/CMakeLists.txt8
-rw-r--r--main/loader-impl.cpp (renamed from loader-impl.cpp)0
-rw-r--r--main/main.cpp (renamed from main.cpp)2
-rw-r--r--serialize/CMakeLists.txt5
-rw-r--r--serialize/tile-atlas.cpp42
-rw-r--r--serialize/tile-atlas.hpp27
-rw-r--r--tile-atlas.hpp4
9 files changed, 76 insertions, 45 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5e5ef563..dc24f387 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -55,28 +55,25 @@ if(NOT BOOTSTRAP_DEPENDS)
find_package(MagnumPlugins QUIET REQUIRED)
find_package(MagnumIntegration QUIET REQUIRED COMPONENTS Glm)
- include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
-
include_directories(.)
- add_subdirectory(anim-crop-tool)
- add_subdirectory(serialize)
-
- corrade_add_resource(game_RESOURCES resources.conf)
file(GLOB sources "*.cpp" "shaders/*.cpp" "serialize/*.cpp" CONFIGURE_ARGS)
-
- add_executable(${PROJECT_NAME} WIN32 "${sources}" "${game_RESOURCES}")
- target_link_libraries(${PROJECT_NAME} PRIVATE
- Magnum::Application
- Magnum::GL
- Magnum::Magnum
- Magnum::Shaders
- Magnum::Trade
- MagnumIntegration::Glm
- nlohmann_json::nlohmann_json
- )
+ add_library(${PROJECT_NAME} STATIC "${sources}")
+ target_link_libraries(
+ ${PROJECT_NAME} PUBLIC
+ Magnum::GL
+ Magnum::Magnum
+ Magnum::Shaders
+ nlohmann_json::nlohmann_json
+ )
target_include_directories(${PROJECT_NAME} PRIVATE ${GLM_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME} PRIVATE magnum-integration/src)
+
+ add_subdirectory(main)
+ add_subdirectory(anim-crop-tool)
+
+ install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
+ install(DIRECTORY images DESTINATION /src)
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
install(DIRECTORY images DESTINATION "share/${PROJECT_NAME}")
endif()
diff --git a/anim-crop-tool/CMakeLists.txt b/anim-crop-tool/CMakeLists.txt
index 76304068..6e7863e6 100644
--- a/anim-crop-tool/CMakeLists.txt
+++ b/anim-crop-tool/CMakeLists.txt
@@ -3,8 +3,8 @@ set(self "${PROJECT_NAME}-anim-crop-tool")
include_directories(SYSTEM PRIVATE ${OpenCV_INCLUDE_DIRS})
link_libraries(Corrade::Utility Magnum::Magnum)
-link_libraries("${PROJECT_NAME}-serialize")
link_libraries(opencv_imgproc opencv_imgcodecs opencv_core)
+link_libraries(${PROJECT_NAME})
file(GLOB sources "*.cpp" CONFIGURE_ARGS)
add_executable(${self} ${sources})
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
new file mode 100644
index 00000000..cb3b1f2c
--- /dev/null
+++ b/main/CMakeLists.txt
@@ -0,0 +1,8 @@
+set(self "${PROJECT_NAME}-main")
+file(GLOB sources "*.cpp" CONFIGURE_ARGS)
+
+link_libraries(${PROJECT_NAME}
+ Magnum::Application Magnum::Trade MagnumIntegration::Glm)
+corrade_add_resource(res ../resources.conf)
+add_executable(${self} WIN32 "${sources}" "${res}")
+set_property(TARGET ${self} PROPERTY OUTPUT_NAME "${PROJECT_NAME}")
diff --git a/loader-impl.cpp b/main/loader-impl.cpp
index 24d43fdb..24d43fdb 100644
--- a/loader-impl.cpp
+++ b/main/loader-impl.cpp
diff --git a/main.cpp b/main/main.cpp
index 208579fb..f58228c6 100644
--- a/main.cpp
+++ b/main/main.cpp
@@ -16,8 +16,6 @@
#include <Magnum/Trade/AbstractImporter.h>
#include <Magnum/Timeline.h>
-#include "serialize/tile-atlas.hpp" //test
-
namespace Magnum::Examples {
template<typename enum_type>
diff --git a/serialize/CMakeLists.txt b/serialize/CMakeLists.txt
deleted file mode 100644
index e695aff2..00000000
--- a/serialize/CMakeLists.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-find_package(nlohmann_json QUIET REQUIRED)
-set(self "${PROJECT_NAME}-serialize")
-link_libraries(Magnum::Magnum nlohmann_json::nlohmann_json)
-file(GLOB sources "*.cpp" CONFIGURE_ARGS)
-add_library(${self} STATIC ${sources})
diff --git a/serialize/tile-atlas.cpp b/serialize/tile-atlas.cpp
new file mode 100644
index 00000000..0f03e6b2
--- /dev/null
+++ b/serialize/tile-atlas.cpp
@@ -0,0 +1,42 @@
+#include "../tile-atlas.hpp"
+#include "serialize/tile-atlas.hpp"
+#include "serialize/magnum-vector.hpp"
+#include "loader.hpp"
+
+#include <nlohmann/json.hpp>
+
+namespace Magnum::Examples::Serialize {
+
+struct proxy_atlas final {
+ std::string name;
+ Vector2i size;
+};
+
+NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(proxy_atlas, name, size)
+
+} // namespace Magnum::Examples::Serialize
+
+namespace nlohmann {
+
+using namespace Magnum::Examples;
+using namespace Magnum::Examples::Serialize;
+
+using shared_atlas = std::shared_ptr<Magnum::Examples::tile_atlas>;
+
+void adl_serializer<shared_atlas>::to_json(json& j, const shared_atlas& x)
+{
+ if (!x)
+ j = nullptr;
+ else {
+ using nlohmann::to_json;
+ to_json(j, proxy_atlas{x->name(), x->dimensions()});
+ }
+}
+
+void adl_serializer<shared_atlas>::from_json(const json& j, shared_atlas& x)
+{
+ proxy_atlas proxy = j;
+ x = loader.tile_atlas(proxy.name, proxy.size);
+}
+
+} // namespace nlohmann
diff --git a/serialize/tile-atlas.hpp b/serialize/tile-atlas.hpp
index af279251..c49b8a72 100644
--- a/serialize/tile-atlas.hpp
+++ b/serialize/tile-atlas.hpp
@@ -1,27 +1,16 @@
#pragma once
-#include "../tile-atlas.hpp"
-#include <nlohmann/json.hpp>
+#include "loader.hpp"
+#include <memory>
+#include <nlohmann/json_fwd.hpp>
+
+namespace Magnum::Examples { struct tile_atlas; }
namespace nlohmann {
template<>
-struct adl_serializer<Magnum::Examples::tile_atlas> final {
- static void to_json(json& j, const Magnum::Examples::tile_atlas& x);
- static void from_json(const json& j, Magnum::Examples::tile_atlas& x);
+struct adl_serializer<std::shared_ptr<Magnum::Examples::tile_atlas>> final {
+ static void to_json(json& j, const std::shared_ptr<Magnum::Examples::tile_atlas>& x);
+ static void from_json(const json& j, std::shared_ptr<Magnum::Examples::tile_atlas>& x);
};
-void adl_serializer<Magnum::Examples::tile_atlas>::to_json(json& j, const Magnum::Examples::tile_atlas& x)
-{
-}
-
-void adl_serializer<Magnum::Examples::tile_atlas>::from_json(const json& j, Magnum::Examples::tile_atlas& x)
-{
-}
-
} // namespace nlohmann
-
-namespace Magnum::Examples::Serialize {
-
-
-
-} // namespace Magnum::Examples::Serialize
diff --git a/tile-atlas.hpp b/tile-atlas.hpp
index 3416314c..f2cacf09 100644
--- a/tile-atlas.hpp
+++ b/tile-atlas.hpp
@@ -11,7 +11,8 @@ struct tile_atlas final
{
using quad = std::array<Vector3, 4>;
- tile_atlas(const Containers::StringView& name, const ImageView2D& img, Vector2i dims);
+ tile_atlas(const Containers::StringView& name, const ImageView2D& img, Vector2i dimensions);
+
std::array<Vector2, 4> texcoords_for_id(std::size_t id) const;
static constexpr quad floor_quad(Vector3 center, Vector2 size);
static constexpr quad wall_quad_N(Vector3 center, Vector3 size);
@@ -19,6 +20,7 @@ struct tile_atlas final
static constexpr std::array<UnsignedShort, 6> indices(std::size_t N);
std::size_t size() const { return (std::size_t)dims_.product(); }
Vector2i tile_size() const { return size_ / dims_; }
+ Vector2i dimensions() const { return dims_; }
GL::Texture2D& texture() { return tex_; }
std::string name() const { return name_; }