[nostalgia] Add module for Scene

This commit is contained in:
Gary Talent 2023-02-03 23:07:31 -06:00
parent ccf47c0e4b
commit 78798f69af
9 changed files with 110 additions and 11 deletions

View File

@ -11,6 +11,7 @@ target_link_libraries(
NostalgiaAppModules PUBLIC NostalgiaAppModules PUBLIC
NostalgiaCore NostalgiaCore
NostalgiaFoundation NostalgiaFoundation
NostalgiaScene
) )
install( install(

View File

@ -7,6 +7,7 @@
#include <nostalgia/foundation/module.hpp> #include <nostalgia/foundation/module.hpp>
#include <nostalgia/core/module.hpp> #include <nostalgia/core/module.hpp>
#include <nostalgia/scene/scenemodule.hpp>
namespace nostalgia { namespace nostalgia {
@ -15,8 +16,9 @@ void loadModules() noexcept {
if (done) { if (done) {
return; return;
} }
const ox::Array<foundation::Module*, 1> mods = { const ox::Array<foundation::Module*, 2> mods = {
&core::CoreModule::mod, &core::CoreModule::mod,
&scene::SceneModule::mod,
}; };
for (const auto m : mods) { for (const auto m : mods) {
foundation::registerModule(m); foundation::registerModule(m);

View File

@ -151,5 +151,15 @@ ox::Result<ox::Buffer> convertBuffToBuff(foundation::Context *ctx, const ox::Buf
return ox::writeClaw<DstType>(wrapCast<DstType>(out.get()), fmt); return ox::writeClaw<DstType>(wrapCast<DstType>(out.get()), fmt);
} }
template<typename From, typename To, ox::ClawFormat fmt = ox::ClawFormat::Metal>
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<From>()) {
oxReturnError(foundation::convertBuffToBuff<To>(ctx, *buff, fmt).moveTo(buff));
}
return {};
};
} }

View File

@ -2,6 +2,8 @@
add_library( add_library(
NostalgiaScene NostalgiaScene
scene.cpp scene.cpp
scenemodule.cpp
typeconv.cpp
) )
target_link_libraries( target_link_libraries(
@ -12,6 +14,8 @@ target_link_libraries(
install( install(
FILES FILES
scene.hpp scene.hpp
scenemodule.hpp
typeconv.hpp
DESTINATION DESTINATION
include/nostalgia/scene include/nostalgia/scene
) )

View File

@ -11,9 +11,9 @@
namespace nostalgia::scene { 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 TypeVersion = 1;
constexpr static auto Preloadable = true; constexpr static auto Preloadable = true;
@ -22,18 +22,18 @@ struct Tile {
}; };
oxModelBegin(Tile) oxModelBegin(TileDoc)
oxModelFieldRename(sheet_idx, sheetIdx); oxModelFieldRename(sheet_idx, sheetIdx);
oxModelField(type); oxModelField(type);
oxModelEnd() oxModelEnd()
struct Scene { struct SceneDoc {
using TileMapRow = ox::Vector<Tile>; using TileMapRow = ox::Vector<TileDoc>;
using TileMapLayer = ox::Vector<TileMapRow>; using TileMapLayer = ox::Vector<TileMapRow>;
using TileMap = ox::Vector<TileMapLayer>; using TileMap = ox::Vector<TileMapLayer>;
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 TypeVersion = 1;
constexpr static auto Preloadable = true; constexpr static auto Preloadable = true;
@ -43,15 +43,15 @@ struct Scene {
}; };
oxModelBegin(Scene) oxModelBegin(SceneDoc)
oxModelField(tilesheet) oxModelField(tilesheet)
oxModelField(palette) oxModelField(palette)
oxModelField(tiles) oxModelField(tiles)
oxModelEnd() 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 TypeVersion = 1;
constexpr static auto Preloadable = true; constexpr static auto Preloadable = true;
@ -96,7 +96,7 @@ struct SceneInstance {
}; };
oxModelBegin(SceneInstance) oxModelBegin(Scene)
oxModelField(layers) oxModelField(layers)
oxModelField(columns) oxModelField(columns)
oxModelField(rows) oxModelField(rows)

View File

@ -0,0 +1,25 @@
/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <ox/model/model.hpp>
#include "scenemodule.hpp"
namespace nostalgia::scene {
SceneModule SceneModule::mod;
ox::Vector<foundation::BaseConverter*> SceneModule::converters() const noexcept {
return {
&sceneToSceneInstaceConverter,
};
}
ox::Vector<foundation::PackTransform> SceneModule::packTransforms() const noexcept {
return {
foundation::transformRule<SceneDoc, Scene>,
};
}
}

View File

@ -0,0 +1,25 @@
/*
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <nostalgia/foundation/module.hpp>
#include "typeconv.hpp"
namespace nostalgia::scene {
class SceneModule: public foundation::Module {
private:
mutable SceneDocToSceneConverter sceneToSceneInstaceConverter;
public:
static SceneModule mod;
[[nodiscard]]
ox::Vector<foundation::BaseConverter*> converters() const noexcept override;
[[nodiscard]]
ox::Vector<foundation::PackTransform> packTransforms() const noexcept override;
};
}

View File

@ -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 {};
}
}

View File

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