[nostalgia] Add module for Scene
This commit is contained in:
parent
ccf47c0e4b
commit
78798f69af
@ -11,6 +11,7 @@ target_link_libraries(
|
||||
NostalgiaAppModules PUBLIC
|
||||
NostalgiaCore
|
||||
NostalgiaFoundation
|
||||
NostalgiaScene
|
||||
)
|
||||
|
||||
install(
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <nostalgia/foundation/module.hpp>
|
||||
|
||||
#include <nostalgia/core/module.hpp>
|
||||
#include <nostalgia/scene/scenemodule.hpp>
|
||||
|
||||
namespace nostalgia {
|
||||
|
||||
@ -15,8 +16,9 @@ void loadModules() noexcept {
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
const ox::Array<foundation::Module*, 1> mods = {
|
||||
const ox::Array<foundation::Module*, 2> mods = {
|
||||
&core::CoreModule::mod,
|
||||
&scene::SceneModule::mod,
|
||||
};
|
||||
for (const auto m : mods) {
|
||||
foundation::registerModule(m);
|
||||
|
@ -151,5 +151,15 @@ ox::Result<ox::Buffer> convertBuffToBuff(foundation::Context *ctx, const ox::Buf
|
||||
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 {};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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<Tile>;
|
||||
using TileMapRow = ox::Vector<TileDoc>;
|
||||
using TileMapLayer = ox::Vector<TileMapRow>;
|
||||
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 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)
|
||||
|
25
src/nostalgia/scene/scenemodule.cpp
Normal file
25
src/nostalgia/scene/scenemodule.cpp
Normal 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>,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
25
src/nostalgia/scene/scenemodule.hpp
Normal file
25
src/nostalgia/scene/scenemodule.hpp
Normal 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;
|
||||
};
|
||||
|
||||
}
|
15
src/nostalgia/scene/typeconv.cpp
Normal file
15
src/nostalgia/scene/typeconv.cpp
Normal 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 {};
|
||||
}
|
||||
|
||||
}
|
17
src/nostalgia/scene/typeconv.hpp
Normal file
17
src/nostalgia/scene/typeconv.hpp
Normal 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;
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user