[nostalgia] Reorganize Keel components of modules into own directories

This commit is contained in:
Gary Talent 2023-06-17 19:37:34 -05:00
parent ecde759bec
commit 2974fa5863
17 changed files with 183 additions and 18 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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
)

View File

@ -7,9 +7,8 @@
#include <keel/asset.hpp>
#include <keel/module.hpp>
#include <nostalgia/core/gfx.hpp>
#include <nostalgia/core/keelmodule.hpp>
#include <nostalgia/core/palette.hpp>
#include <nostalgia/core/tilesheet.hpp>
#include "typeconv.hpp"

View File

@ -9,7 +9,8 @@
#include <keel/typeconv.hpp>
#include <nostalgia/core/context.hpp>
#include <nostalgia/core/gfx.hpp>
#include <nostalgia/core/palette.hpp>
#include <nostalgia/core/tilesheet.hpp>
namespace nostalgia::core {

View File

@ -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()

View File

@ -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
)

View File

@ -0,0 +1,47 @@
/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <keel/module.hpp>
#include <nostalgia/scene/scenestatic.hpp>
#include "typeconv.hpp"
namespace nostalgia::scene {
class SceneModule: public keel::Module {
private:
SceneDocToSceneStaticConverter sceneDocToSceneStaticConverter;
public:
[[nodiscard]]
ox::Vector<keel::TypeDescGenerator> types() const noexcept override {
return {
keel::generateTypeDesc<SceneDoc>,
keel::generateTypeDesc<SceneStatic>,
};
}
[[nodiscard]]
ox::Vector<const keel::BaseConverter*> converters() const noexcept override {
return {
&sceneDocToSceneStaticConverter,
};
}
[[nodiscard]]
ox::Vector<keel::PackTransform> packTransforms() const noexcept override {
return {
keel::transformRule<SceneDoc, SceneStatic>,
};
}
};
static SceneModule mod;
const keel::Module *keelModule() noexcept {
return &mod;
}
}

View File

@ -0,0 +1,68 @@
/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <nostalgia/core/gfx.hpp>
#include <keel/media.hpp>
#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<core::TileSheet>(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<uint16_t>(mapIdx);
setLayerAttachments(layerIdx, srcTile, dstTile);
++tileIdx;
}
}
++layerIdx;
}
return {};
}
}

View File

@ -0,0 +1,17 @@
/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <keel/typeconv.hpp>
#include <nostalgia/scene/scenestatic.hpp>
namespace nostalgia::scene {
class SceneDocToSceneStaticConverter: public keel::Converter<SceneDoc, SceneStatic> {
ox::Error convert(keel::Context*, SceneDoc *src, SceneStatic *dst) const noexcept final;
};
}

View File

@ -6,8 +6,8 @@
#include <studioapp/studioapp.hpp>
#include <nostalgia/core/studio/studiomodule.hpp>
#include <nostalgia/scene/studio/studiomodule.hpp>
#include <nostalgia/core/studiomodule.hpp>
#include <nostalgia/scene/studiomodule.hpp>
namespace nostalgia {