[nostalgia] Move pack transforms to modules
This commit is contained in:
parent
b1b2780eb9
commit
05a46c3b07
@ -10,6 +10,7 @@ endif()
|
|||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
NostalgiaAppModules PUBLIC
|
NostalgiaAppModules PUBLIC
|
||||||
NostalgiaCore
|
NostalgiaCore
|
||||||
|
NostalgiaFoundation
|
||||||
)
|
)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
|
@ -2,14 +2,19 @@
|
|||||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <ox/model/model.hpp>
|
||||||
|
|
||||||
#include <nostalgia/foundation/module.hpp>
|
#include <nostalgia/foundation/module.hpp>
|
||||||
|
|
||||||
|
#include "gfx.hpp"
|
||||||
#include "typeconv.hpp"
|
#include "typeconv.hpp"
|
||||||
|
|
||||||
#include "module.hpp"
|
#include "module.hpp"
|
||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
|
CoreModule CoreModule::mod;
|
||||||
|
|
||||||
ox::Vector<foundation::BaseConverter*> CoreModule::converters() const noexcept {
|
ox::Vector<foundation::BaseConverter*> CoreModule::converters() const noexcept {
|
||||||
return {
|
return {
|
||||||
&nostalgiaPaletteToPaletteConverter,
|
&nostalgiaPaletteToPaletteConverter,
|
||||||
@ -18,6 +23,19 @@ ox::Vector<foundation::BaseConverter*> CoreModule::converters() const noexcept {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreModule CoreModule::mod;
|
ox::Vector<foundation::PackTransform> CoreModule::packTransforms() const noexcept {
|
||||||
|
return {
|
||||||
|
// convert tilesheets to CompactTileSheets
|
||||||
|
[](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<TileSheet>() ||
|
||||||
|
typeId == ox::buildTypeId<NostalgiaGraphic>()) {
|
||||||
|
oxReturnError(foundation::convertBuffToBuff<core::CompactTileSheet>(ctx, *buff, ox::ClawFormat::Metal).moveTo(buff));
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ class CoreModule: public foundation::Module {
|
|||||||
static CoreModule mod;
|
static CoreModule mod;
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
ox::Vector<foundation::BaseConverter*> converters() const noexcept override;
|
ox::Vector<foundation::BaseConverter*> converters() const noexcept override;
|
||||||
|
[[nodiscard]]
|
||||||
|
ox::Vector<foundation::PackTransform> packTransforms() const noexcept override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
|
|
||||||
namespace nostalgia::foundation {
|
namespace nostalgia::foundation {
|
||||||
|
|
||||||
|
class Context;
|
||||||
|
using PackTransform = ox::Error(*)(Context*, ox::Buffer *clawData);
|
||||||
|
|
||||||
class Context {
|
class Context {
|
||||||
public:
|
public:
|
||||||
ox::UPtr<ox::FileSystem> rom;
|
ox::UPtr<ox::FileSystem> rom;
|
||||||
@ -19,6 +22,7 @@ class Context {
|
|||||||
#ifndef OX_BARE_METAL
|
#ifndef OX_BARE_METAL
|
||||||
AssetManager assetManager;
|
AssetManager assetManager;
|
||||||
ox::Vector<class BaseConverter*> converters;
|
ox::Vector<class BaseConverter*> converters;
|
||||||
|
ox::Vector<PackTransform> packTransforms;
|
||||||
#else
|
#else
|
||||||
std::size_t preloadSectionOffset = 0;
|
std::size_t preloadSectionOffset = 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -11,18 +11,22 @@
|
|||||||
|
|
||||||
namespace nostalgia::foundation {
|
namespace nostalgia::foundation {
|
||||||
|
|
||||||
template<typename Context = foundation::Context>
|
template<typename Ctx = foundation::Context>
|
||||||
ox::UPtr<Context> init(ox::UPtr<ox::FileSystem> &&fs, ox::CRStringView appName) noexcept {
|
ox::UPtr<Ctx> init(ox::UPtr<ox::FileSystem> &&fs, ox::CRStringView appName) noexcept {
|
||||||
auto ctx = ox::make_unique<Context>();
|
auto ctx = ox::make_unique<Ctx>();
|
||||||
ctx->rom = std::move(fs);
|
ctx->rom = std::move(fs);
|
||||||
ctx->appName = appName;
|
ctx->appName = appName;
|
||||||
auto mods = modules();
|
auto mods = modules();
|
||||||
if (mods) {
|
if (mods) {
|
||||||
for (auto &mod : *mods) {
|
for (auto &mod : *mods) {
|
||||||
// load type converters
|
// register type converters
|
||||||
for (auto c : mod->converters()) {
|
for (auto c : mod->converters()) {
|
||||||
ctx->converters.emplace_back(c);
|
ctx->converters.emplace_back(c);
|
||||||
}
|
}
|
||||||
|
// register pack transforms
|
||||||
|
for (auto c : mod->packTransforms()) {
|
||||||
|
ctx->packTransforms.emplace_back(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ctx;
|
return ctx;
|
||||||
|
@ -6,26 +6,15 @@
|
|||||||
|
|
||||||
namespace nostalgia::foundation {
|
namespace nostalgia::foundation {
|
||||||
|
|
||||||
[[nodiscard]]
|
static ox::Vector<const Module*> mods;
|
||||||
static ox::Vector<const Module*> *moduleRegistry() noexcept {
|
|
||||||
#ifdef OX_BARE_METAL
|
|
||||||
return nullptr;
|
|
||||||
#else
|
|
||||||
static ox::Vector<const Module*> modules;
|
|
||||||
return &modules;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void registerModule(const Module *mod) noexcept {
|
void registerModule(const Module *mod) noexcept {
|
||||||
auto mods = moduleRegistry();
|
mods.emplace_back(mod);
|
||||||
if (mods) {
|
|
||||||
mods->emplace_back(mod);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
const ox::Vector<const Module*> *modules() noexcept {
|
const ox::Vector<const Module*> *modules() noexcept {
|
||||||
return moduleRegistry();
|
return &mods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -33,4 +22,8 @@ ox::Vector<foundation::BaseConverter*> Module::converters() const noexcept {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ox::Vector<PackTransform> Module::packTransforms() const noexcept {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ class Module {
|
|||||||
constexpr virtual ~Module() noexcept = default;
|
constexpr virtual ~Module() noexcept = default;
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
virtual ox::Vector<foundation::BaseConverter*> converters() const noexcept;
|
virtual ox::Vector<foundation::BaseConverter*> converters() const noexcept;
|
||||||
|
[[nodiscard]]
|
||||||
|
virtual ox::Vector<PackTransform> packTransforms() const noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
void registerModule(const Module *mod) noexcept;
|
void registerModule(const Module *mod) noexcept;
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#include <ox/model/modelvalue.hpp>
|
#include <ox/model/modelvalue.hpp>
|
||||||
|
|
||||||
#include <nostalgia/core/gfx.hpp>
|
#include <nostalgia/core/gfx.hpp>
|
||||||
#include <nostalgia/core/typeconv.hpp>
|
|
||||||
#include <nostalgia/core/typestore.hpp>
|
#include <nostalgia/core/typestore.hpp>
|
||||||
#include <nostalgia/foundation/media.hpp>
|
#include <nostalgia/foundation/media.hpp>
|
||||||
|
|
||||||
@ -42,7 +41,7 @@ static ox::Error pathToInode(ox::FileSystem *dest, ox::ModelObject *obj) noexcep
|
|||||||
* @param buff buffer holding file
|
* @param buff buffer holding file
|
||||||
* @return error
|
* @return error
|
||||||
*/
|
*/
|
||||||
static ox::Error transformObj(ox::FileSystem *dest, ox::ModelObject *obj) noexcept {
|
static ox::Error transformFileAddresses(ox::FileSystem *dest, ox::ModelObject *obj) noexcept {
|
||||||
for (auto &f : *obj) {
|
for (auto &f : *obj) {
|
||||||
auto &v = f->value;
|
auto &v = f->value;
|
||||||
if (v.type() != ox::ModelValue::Type::Object) {
|
if (v.type() != ox::ModelValue::Type::Object) {
|
||||||
@ -52,31 +51,30 @@ static ox::Error transformObj(ox::FileSystem *dest, ox::ModelObject *obj) noexce
|
|||||||
if (o.typeName() == "net.drinkingtea.ox.FileAddress" && o.typeVersion() == 1) {
|
if (o.typeName() == "net.drinkingtea.ox.FileAddress" && o.typeVersion() == 1) {
|
||||||
oxReturnError(pathToInode(dest, &o));
|
oxReturnError(pathToInode(dest, &o));
|
||||||
} else {
|
} else {
|
||||||
oxReturnError(transformObj(dest, &o));
|
oxReturnError(transformFileAddresses(dest, &o));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static ox::Error doTransformations(foundation::Context *ctx, core::TypeStore *ts, ox::FileSystem *dest, ox::CRStringView filePath) noexcept {
|
static ox::Error doTransformations(foundation::Context *ctx, core::TypeStore *ts, ox::FileSystem *dest, ox::CRStringView filePath) noexcept {
|
||||||
if (endsWith(filePath, ".ng") || endsWith(filePath, ".npal")) {
|
// load file
|
||||||
// load file
|
oxRequire(s, dest->stat(filePath));
|
||||||
oxRequire(s, dest->stat(filePath));
|
// do transformations
|
||||||
oxRequireM(buff, dest->read(s.inode));
|
oxRequireM(buff, dest->read(s.inode));
|
||||||
if (endsWith(filePath, ".ng")) {
|
for (auto tr : ctx->packTransforms) {
|
||||||
oxReturnError(foundation::convertBuffToBuff<core::CompactTileSheet>(ctx, buff, ox::ClawFormat::Metal).moveTo(&buff));
|
oxReturnError(tr(ctx, &buff));
|
||||||
}
|
|
||||||
oxRequireM(obj, ox::readClaw(ts, buff));
|
|
||||||
// do transformations
|
|
||||||
oxReturnError(transformObj(dest, &obj));
|
|
||||||
oxReturnError(ox::writeClaw(&obj).moveTo(&buff));
|
|
||||||
// write file to dest
|
|
||||||
oxReturnError(dest->write(s.inode, buff.data(), buff.size()));
|
|
||||||
}
|
}
|
||||||
|
// transform FileAddresses
|
||||||
|
oxRequireM(obj, ox::readClaw(ts, buff));
|
||||||
|
oxReturnError(transformFileAddresses(dest, &obj));
|
||||||
|
oxReturnError(ox::writeClaw(&obj).moveTo(&buff));
|
||||||
|
// write file to dest
|
||||||
|
oxReturnError(dest->write(s.inode, buff.data(), buff.size()));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// claw file transformations are broken out because path to inode
|
// claw file transformations are broken out from copy because path to inode
|
||||||
// transformations need to be done after the copy to the new FS is complete
|
// transformations need to be done after the copy to the new FS is complete
|
||||||
static ox::Error transformClaw(foundation::Context *ctx, core::TypeStore *ts, ox::FileSystem *dest, ox::CRStringView path) noexcept {
|
static ox::Error transformClaw(foundation::Context *ctx, core::TypeStore *ts, ox::FileSystem *dest, ox::CRStringView path) noexcept {
|
||||||
// copy
|
// copy
|
||||||
|
Loading…
Reference in New Issue
Block a user