From 78798f69aff8b290c10582f40c9ebb4f043483d6 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 3 Feb 2023 23:07:31 -0600 Subject: [PATCH] [nostalgia] Add module for Scene --- src/nostalgia/appmodules/CMakeLists.txt | 1 + src/nostalgia/appmodules/appmodules.cpp | 4 +++- src/nostalgia/foundation/typeconv.hpp | 10 ++++++++++ src/nostalgia/scene/CMakeLists.txt | 4 ++++ src/nostalgia/scene/scene.hpp | 20 ++++++++++---------- src/nostalgia/scene/scenemodule.cpp | 25 +++++++++++++++++++++++++ src/nostalgia/scene/scenemodule.hpp | 25 +++++++++++++++++++++++++ src/nostalgia/scene/typeconv.cpp | 15 +++++++++++++++ src/nostalgia/scene/typeconv.hpp | 17 +++++++++++++++++ 9 files changed, 110 insertions(+), 11 deletions(-) create mode 100644 src/nostalgia/scene/scenemodule.cpp create mode 100644 src/nostalgia/scene/scenemodule.hpp create mode 100644 src/nostalgia/scene/typeconv.cpp create mode 100644 src/nostalgia/scene/typeconv.hpp diff --git a/src/nostalgia/appmodules/CMakeLists.txt b/src/nostalgia/appmodules/CMakeLists.txt index 5394d5b3..7201886a 100644 --- a/src/nostalgia/appmodules/CMakeLists.txt +++ b/src/nostalgia/appmodules/CMakeLists.txt @@ -11,6 +11,7 @@ target_link_libraries( NostalgiaAppModules PUBLIC NostalgiaCore NostalgiaFoundation + NostalgiaScene ) install( diff --git a/src/nostalgia/appmodules/appmodules.cpp b/src/nostalgia/appmodules/appmodules.cpp index 98d17a33..f63385c5 100644 --- a/src/nostalgia/appmodules/appmodules.cpp +++ b/src/nostalgia/appmodules/appmodules.cpp @@ -7,6 +7,7 @@ #include #include +#include namespace nostalgia { @@ -15,8 +16,9 @@ void loadModules() noexcept { if (done) { return; } - const ox::Array mods = { + const ox::Array mods = { &core::CoreModule::mod, + &scene::SceneModule::mod, }; for (const auto m : mods) { foundation::registerModule(m); diff --git a/src/nostalgia/foundation/typeconv.hpp b/src/nostalgia/foundation/typeconv.hpp index c998e3f0..92bcc3de 100644 --- a/src/nostalgia/foundation/typeconv.hpp +++ b/src/nostalgia/foundation/typeconv.hpp @@ -151,5 +151,15 @@ ox::Result convertBuffToBuff(foundation::Context *ctx, const ox::Buf return ox::writeClaw(wrapCast(out.get()), fmt); } +template +auto transformRule(foundation::Context *ctx, ox::Buffer *buff) -> ox::Error { + oxRequire(hdr, ox::readClawHeader(*buff)); + const auto typeId = ox::buildTypeId(hdr.typeName, hdr.typeVersion); + if (typeId == ox::buildTypeId()) { + oxReturnError(foundation::convertBuffToBuff(ctx, *buff, fmt).moveTo(buff)); + } + return {}; +}; + } diff --git a/src/nostalgia/scene/CMakeLists.txt b/src/nostalgia/scene/CMakeLists.txt index 295efd0a..128036b0 100644 --- a/src/nostalgia/scene/CMakeLists.txt +++ b/src/nostalgia/scene/CMakeLists.txt @@ -2,6 +2,8 @@ add_library( NostalgiaScene scene.cpp + scenemodule.cpp + typeconv.cpp ) target_link_libraries( @@ -12,6 +14,8 @@ target_link_libraries( install( FILES scene.hpp + scenemodule.hpp + typeconv.hpp DESTINATION include/nostalgia/scene ) diff --git a/src/nostalgia/scene/scene.hpp b/src/nostalgia/scene/scene.hpp index 80ebea72..64ffbf56 100644 --- a/src/nostalgia/scene/scene.hpp +++ b/src/nostalgia/scene/scene.hpp @@ -11,9 +11,9 @@ namespace nostalgia::scene { -struct Tile { +struct TileDoc { - constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.Tile"; + constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.TileDoc"; constexpr static auto TypeVersion = 1; constexpr static auto Preloadable = true; @@ -22,18 +22,18 @@ struct Tile { }; -oxModelBegin(Tile) +oxModelBegin(TileDoc) oxModelFieldRename(sheet_idx, sheetIdx); oxModelField(type); oxModelEnd() -struct Scene { +struct SceneDoc { - using TileMapRow = ox::Vector; + using TileMapRow = ox::Vector; using TileMapLayer = ox::Vector; using TileMap = ox::Vector; - constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.Scene"; + constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.SceneDoc"; constexpr static auto TypeVersion = 1; constexpr static auto Preloadable = true; @@ -43,15 +43,15 @@ struct Scene { }; -oxModelBegin(Scene) +oxModelBegin(SceneDoc) oxModelField(tilesheet) oxModelField(palette) oxModelField(tiles) oxModelEnd() -struct SceneInstance { +struct Scene { - constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.SceneInstance"; + constexpr static auto TypeName = "net.drinkingtea.nostalgia.scene.Scene"; constexpr static auto TypeVersion = 1; constexpr static auto Preloadable = true; @@ -96,7 +96,7 @@ struct SceneInstance { }; -oxModelBegin(SceneInstance) +oxModelBegin(Scene) oxModelField(layers) oxModelField(columns) oxModelField(rows) diff --git a/src/nostalgia/scene/scenemodule.cpp b/src/nostalgia/scene/scenemodule.cpp new file mode 100644 index 00000000..328c263f --- /dev/null +++ b/src/nostalgia/scene/scenemodule.cpp @@ -0,0 +1,25 @@ +/* + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#include + +#include "scenemodule.hpp" + +namespace nostalgia::scene { + +SceneModule SceneModule::mod; + +ox::Vector SceneModule::converters() const noexcept { + return { + &sceneToSceneInstaceConverter, + }; +} + +ox::Vector SceneModule::packTransforms() const noexcept { + return { + foundation::transformRule, + }; +} + +} diff --git a/src/nostalgia/scene/scenemodule.hpp b/src/nostalgia/scene/scenemodule.hpp new file mode 100644 index 00000000..9c6e62fa --- /dev/null +++ b/src/nostalgia/scene/scenemodule.hpp @@ -0,0 +1,25 @@ +/* + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#pragma once + +#include + +#include "typeconv.hpp" + +namespace nostalgia::scene { + +class SceneModule: public foundation::Module { + private: + mutable SceneDocToSceneConverter sceneToSceneInstaceConverter; + + public: + static SceneModule mod; + [[nodiscard]] + ox::Vector converters() const noexcept override; + [[nodiscard]] + ox::Vector packTransforms() const noexcept override; +}; + +} diff --git a/src/nostalgia/scene/typeconv.cpp b/src/nostalgia/scene/typeconv.cpp new file mode 100644 index 00000000..3dbf4e10 --- /dev/null +++ b/src/nostalgia/scene/typeconv.cpp @@ -0,0 +1,15 @@ +/* + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#include "typeconv.hpp" + +namespace nostalgia::scene { + +// Type converters + +ox::Error SceneDocToSceneConverter::convert(foundation::Context*, SceneDoc *, Scene *) noexcept { + return {}; +} + +} diff --git a/src/nostalgia/scene/typeconv.hpp b/src/nostalgia/scene/typeconv.hpp new file mode 100644 index 00000000..d10fa917 --- /dev/null +++ b/src/nostalgia/scene/typeconv.hpp @@ -0,0 +1,17 @@ +/* + * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. + */ + +#pragma once + +#include + +#include "scene.hpp" + +namespace nostalgia::scene { + +struct SceneDocToSceneConverter: public foundation::Converter { + ox::Error convert(foundation::Context*, SceneDoc *src, Scene *dst) noexcept final; +}; + +}