From 2974fa586366c4fcb055dec6389195c220800960 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 17 Jun 2023 19:37:34 -0500 Subject: [PATCH] [nostalgia] Reorganize Keel components of modules into own directories --- src/nostalgia/modules/CMakeLists.txt | 4 +- .../core/{studio => }/studiomodule.hpp | 0 src/nostalgia/modules/core/src/CMakeLists.txt | 10 +-- .../modules/core/src/keel/CMakeLists.txt | 24 +++++++ .../core/src/{ => keel}/keelmodule.cpp | 5 +- .../modules/core/src/{ => keel}/typeconv.cpp | 0 .../modules/core/src/{ => keel}/typeconv.hpp | 3 +- .../scene/{studio => }/studiomodule.hpp | 0 .../modules/scene/src/CMakeLists.txt | 3 +- .../modules/scene/src/keel/CMakeLists.txt | 16 +++++ .../scene/src/{ => keel}/keelmodule.cpp | 0 .../modules/scene/src/{ => keel}/typeconv.cpp | 0 .../modules/scene/src/{ => keel}/typeconv.hpp | 0 .../modules/scene/src/studio/keelmodule.cpp | 47 +++++++++++++ .../modules/scene/src/studio/typeconv.cpp | 68 +++++++++++++++++++ .../modules/scene/src/studio/typeconv.hpp | 17 +++++ src/nostalgia/modules/studiomodules.cpp | 4 +- 17 files changed, 183 insertions(+), 18 deletions(-) rename src/nostalgia/modules/core/include/nostalgia/core/{studio => }/studiomodule.hpp (100%) create mode 100644 src/nostalgia/modules/core/src/keel/CMakeLists.txt rename src/nostalgia/modules/core/src/{ => keel}/keelmodule.cpp (96%) rename src/nostalgia/modules/core/src/{ => keel}/typeconv.cpp (100%) rename src/nostalgia/modules/core/src/{ => keel}/typeconv.hpp (93%) rename src/nostalgia/modules/scene/include/nostalgia/scene/{studio => }/studiomodule.hpp (100%) create mode 100644 src/nostalgia/modules/scene/src/keel/CMakeLists.txt rename src/nostalgia/modules/scene/src/{ => keel}/keelmodule.cpp (100%) rename src/nostalgia/modules/scene/src/{ => keel}/typeconv.cpp (100%) rename src/nostalgia/modules/scene/src/{ => keel}/typeconv.hpp (100%) create mode 100644 src/nostalgia/modules/scene/src/studio/keelmodule.cpp create mode 100644 src/nostalgia/modules/scene/src/studio/typeconv.cpp create mode 100644 src/nostalgia/modules/scene/src/studio/typeconv.hpp diff --git a/src/nostalgia/modules/CMakeLists.txt b/src/nostalgia/modules/CMakeLists.txt index 5ebb0a62..67f85354 100644 --- a/src/nostalgia/modules/CMakeLists.txt +++ b/src/nostalgia/modules/CMakeLists.txt @@ -13,8 +13,8 @@ add_library( target_link_libraries( NostalgiaKeelModules PUBLIC Keel - NostalgiaCore - NostalgiaScene + NostalgiaCore-Keel + NostalgiaScene-Keel ) if(NOT MSVC) target_compile_options(NostalgiaKeelModules PRIVATE -Wsign-conversion) diff --git a/src/nostalgia/modules/core/include/nostalgia/core/studio/studiomodule.hpp b/src/nostalgia/modules/core/include/nostalgia/core/studiomodule.hpp similarity index 100% rename from src/nostalgia/modules/core/include/nostalgia/core/studio/studiomodule.hpp rename to src/nostalgia/modules/core/include/nostalgia/core/studiomodule.hpp diff --git a/src/nostalgia/modules/core/src/CMakeLists.txt b/src/nostalgia/modules/core/src/CMakeLists.txt index ff2cda79..1a676eb9 100644 --- a/src/nostalgia/modules/core/src/CMakeLists.txt +++ b/src/nostalgia/modules/core/src/CMakeLists.txt @@ -1,8 +1,6 @@ add_library( NostalgiaCore gfx.cpp - keelmodule.cpp - typeconv.cpp ) if(TURBINE_BUILD_TYPE STREQUAL "GBA") @@ -11,11 +9,6 @@ else() add_subdirectory(opengl) endif() -if(NOT MSVC) - target_compile_options(NostalgiaCore PUBLIC -Wsign-conversion) - target_compile_options(NostalgiaCore PRIVATE -Wconversion) -endif() - target_include_directories( NostalgiaCore PUBLIC ../include @@ -26,6 +19,7 @@ target_link_libraries( Turbine ) +add_subdirectory(keel) if(NOSTALGIA_BUILD_STUDIO) add_subdirectory(studio) endif() @@ -36,4 +30,4 @@ install( DESTINATION LIBRARY DESTINATION lib ARCHIVE DESTINATION lib -) \ No newline at end of file +) diff --git a/src/nostalgia/modules/core/src/keel/CMakeLists.txt b/src/nostalgia/modules/core/src/keel/CMakeLists.txt new file mode 100644 index 00000000..54800fd8 --- /dev/null +++ b/src/nostalgia/modules/core/src/keel/CMakeLists.txt @@ -0,0 +1,24 @@ +add_library( + NostalgiaCore-Keel + keelmodule.cpp + typeconv.cpp +) + +target_include_directories( + NostalgiaCore-Keel PUBLIC + ../include +) + +target_link_libraries( + NostalgiaCore-Keel PUBLIC + Keel + NostalgiaCore +) + +install( + TARGETS + NostalgiaCore-Keel + DESTINATION + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) diff --git a/src/nostalgia/modules/core/src/keelmodule.cpp b/src/nostalgia/modules/core/src/keel/keelmodule.cpp similarity index 96% rename from src/nostalgia/modules/core/src/keelmodule.cpp rename to src/nostalgia/modules/core/src/keel/keelmodule.cpp index c2519cde..1d9ed584 100644 --- a/src/nostalgia/modules/core/src/keelmodule.cpp +++ b/src/nostalgia/modules/core/src/keel/keelmodule.cpp @@ -7,9 +7,8 @@ #include #include -#include - -#include +#include +#include #include "typeconv.hpp" diff --git a/src/nostalgia/modules/core/src/typeconv.cpp b/src/nostalgia/modules/core/src/keel/typeconv.cpp similarity index 100% rename from src/nostalgia/modules/core/src/typeconv.cpp rename to src/nostalgia/modules/core/src/keel/typeconv.cpp diff --git a/src/nostalgia/modules/core/src/typeconv.hpp b/src/nostalgia/modules/core/src/keel/typeconv.hpp similarity index 93% rename from src/nostalgia/modules/core/src/typeconv.hpp rename to src/nostalgia/modules/core/src/keel/typeconv.hpp index f818133d..0aa4c5a7 100644 --- a/src/nostalgia/modules/core/src/typeconv.hpp +++ b/src/nostalgia/modules/core/src/keel/typeconv.hpp @@ -9,7 +9,8 @@ #include #include -#include +#include +#include namespace nostalgia::core { diff --git a/src/nostalgia/modules/scene/include/nostalgia/scene/studio/studiomodule.hpp b/src/nostalgia/modules/scene/include/nostalgia/scene/studiomodule.hpp similarity index 100% rename from src/nostalgia/modules/scene/include/nostalgia/scene/studio/studiomodule.hpp rename to src/nostalgia/modules/scene/include/nostalgia/scene/studiomodule.hpp diff --git a/src/nostalgia/modules/scene/src/CMakeLists.txt b/src/nostalgia/modules/scene/src/CMakeLists.txt index 2b0e31a4..a5e0a1d6 100644 --- a/src/nostalgia/modules/scene/src/CMakeLists.txt +++ b/src/nostalgia/modules/scene/src/CMakeLists.txt @@ -3,8 +3,6 @@ add_library( NostalgiaScene scene.cpp scenestatic.cpp - keelmodule.cpp - typeconv.cpp ) target_include_directories( @@ -17,6 +15,7 @@ target_link_libraries( NostalgiaCore ) +add_subdirectory(keel) if(NOSTALGIA_BUILD_STUDIO) add_subdirectory(studio) endif() diff --git a/src/nostalgia/modules/scene/src/keel/CMakeLists.txt b/src/nostalgia/modules/scene/src/keel/CMakeLists.txt new file mode 100644 index 00000000..af64e7ef --- /dev/null +++ b/src/nostalgia/modules/scene/src/keel/CMakeLists.txt @@ -0,0 +1,16 @@ +add_library( + NostalgiaScene-Keel + keelmodule.cpp + typeconv.cpp +) + +target_include_directories( + NostalgiaScene-Keel PUBLIC + ../include +) + +target_link_libraries( + NostalgiaScene-Keel PUBLIC + Keel + NostalgiaScene +) diff --git a/src/nostalgia/modules/scene/src/keelmodule.cpp b/src/nostalgia/modules/scene/src/keel/keelmodule.cpp similarity index 100% rename from src/nostalgia/modules/scene/src/keelmodule.cpp rename to src/nostalgia/modules/scene/src/keel/keelmodule.cpp diff --git a/src/nostalgia/modules/scene/src/typeconv.cpp b/src/nostalgia/modules/scene/src/keel/typeconv.cpp similarity index 100% rename from src/nostalgia/modules/scene/src/typeconv.cpp rename to src/nostalgia/modules/scene/src/keel/typeconv.cpp diff --git a/src/nostalgia/modules/scene/src/typeconv.hpp b/src/nostalgia/modules/scene/src/keel/typeconv.hpp similarity index 100% rename from src/nostalgia/modules/scene/src/typeconv.hpp rename to src/nostalgia/modules/scene/src/keel/typeconv.hpp diff --git a/src/nostalgia/modules/scene/src/studio/keelmodule.cpp b/src/nostalgia/modules/scene/src/studio/keelmodule.cpp new file mode 100644 index 00000000..29d0744a --- /dev/null +++ b/src/nostalgia/modules/scene/src/studio/keelmodule.cpp @@ -0,0 +1,47 @@ +/* + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#include + +#include + +#include "typeconv.hpp" + +namespace nostalgia::scene { + +class SceneModule: public keel::Module { + private: + SceneDocToSceneStaticConverter sceneDocToSceneStaticConverter; + + public: + [[nodiscard]] + ox::Vector types() const noexcept override { + return { + keel::generateTypeDesc, + keel::generateTypeDesc, + }; + } + + [[nodiscard]] + ox::Vector converters() const noexcept override { + return { + &sceneDocToSceneStaticConverter, + }; + } + + [[nodiscard]] + ox::Vector packTransforms() const noexcept override { + return { + keel::transformRule, + }; + } + +}; + +static SceneModule mod; +const keel::Module *keelModule() noexcept { + return &mod; +} + +} diff --git a/src/nostalgia/modules/scene/src/studio/typeconv.cpp b/src/nostalgia/modules/scene/src/studio/typeconv.cpp new file mode 100644 index 00000000..d600d4ff --- /dev/null +++ b/src/nostalgia/modules/scene/src/studio/typeconv.cpp @@ -0,0 +1,68 @@ +/* + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#include +#include + +#include "typeconv.hpp" + +namespace nostalgia::scene { + +[[nodiscard]] +constexpr unsigned adjustLayerAttachment(unsigned layer, unsigned attachment) noexcept { + if (attachment == 0) { + return layer; + } else { + return attachment - 1; + } +} + +constexpr void setLayerAttachments(unsigned layer, const TileDoc &srcTile, SceneStatic::Tile &dstTile) noexcept { + setTopEdge( + dstTile.layerAttachments, + adjustLayerAttachment(layer, srcTile.layerAttachments[0])); + setBottomEdge( + dstTile.layerAttachments, + adjustLayerAttachment(layer, srcTile.layerAttachments[1])); + setLeftEdge( + dstTile.layerAttachments, + adjustLayerAttachment(layer, srcTile.layerAttachments[2])); + setRightEdge( + dstTile.layerAttachments, + adjustLayerAttachment(layer, srcTile.layerAttachments[3])); +} + +ox::Error SceneDocToSceneStaticConverter::convert( + keel::Context *ctx, + SceneDoc *src, + SceneStatic *dst) const noexcept { + oxRequire(ts, keel::readObj(ctx, src->tilesheet)); + const auto layerCnt = src->tiles.size(); + dst->setLayerCnt(layerCnt); + dst->tilesheet = ox::FileAddress(src->tilesheet); + dst->palettes.reserve(src->palettes.size()); + for (const auto &pal : src->palettes) { + dst->palettes.emplace_back(pal); + } + for (auto layerIdx = 0u; const auto &layer : src->tiles) { + const auto layerDim = src->size(layerIdx); + auto dstLayer = dst->layer(layerIdx); + dstLayer.setDimensions(layerDim); + for (auto tileIdx = 0u; const auto &row : layer) { + for (const auto &srcTile : row) { + auto dstTile = dstLayer.tile(tileIdx); + dstTile.tileType = srcTile.type; + oxRequire(path, srcTile.getSubsheetPath(*ts)); + oxRequire(mapIdx, ts->getTileOffset(path)); + dstTile.tileMapIdx = static_cast(mapIdx); + setLayerAttachments(layerIdx, srcTile, dstTile); + ++tileIdx; + } + } + ++layerIdx; + } + return {}; +} + +} diff --git a/src/nostalgia/modules/scene/src/studio/typeconv.hpp b/src/nostalgia/modules/scene/src/studio/typeconv.hpp new file mode 100644 index 00000000..e9a2342e --- /dev/null +++ b/src/nostalgia/modules/scene/src/studio/typeconv.hpp @@ -0,0 +1,17 @@ +/* + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#pragma once + +#include + +#include + +namespace nostalgia::scene { + +class SceneDocToSceneStaticConverter: public keel::Converter { + ox::Error convert(keel::Context*, SceneDoc *src, SceneStatic *dst) const noexcept final; +}; + +} diff --git a/src/nostalgia/modules/studiomodules.cpp b/src/nostalgia/modules/studiomodules.cpp index f22c7c23..e376d67c 100644 --- a/src/nostalgia/modules/studiomodules.cpp +++ b/src/nostalgia/modules/studiomodules.cpp @@ -6,8 +6,8 @@ #include -#include -#include +#include +#include namespace nostalgia {