Squashed 'deps/nostalgia/' changes from 5f10edd3..0daf938f
0daf938f [nostalgia/core/studio] Cleanup, make all number keys after num colors jump to last b90ab27a [nostalgia/core/studio] Fix Palette Color Name input to properly take focus c711f435 [nostalgia/core/studio] Fix PaletteEditor 0 key shortcut 84cb03d8 [nostalgia/core/studio] Cleanup 945a55f9 [studio] Fix Project to cut off correct end of OC data 2173b12c [nostalgia/core/studio] Give PaletteEditor keyboard shortcuts aa970b1f [keel,studio] Cleanup 6ad79b30 [ox] Cleanup a7cf2673 [studio] Remove null terminator from OC output 1a9f0d49 [ox] Rename CRString to StringCR a1b5b565 [olympic,nostalgia] Rename CRStringView to StringViewCR 256be6da [glutils] Rename CRStringView to StringViewCR cc10631b [ox] Rename CRStringView to StringViewCR 829dc029 [keel] Fix Linux build e8a1ff06 [ox/oc] Fix Linux build bdfb5e97 [nostalgia/core] Cleanup 396fecab [ox/oc] Add option for writeOC to return a string 5373b63c [keel,studio] Removing null terminator from JSON file output 8b655c40 [ox/std] Add HashMap::values 92d85d11 Merge commit '9f5f3e26efed6cd27f2a8ff0746f018d75986934' 118fef61 [buildcore] Remove python -m prefix from mypy command 8769305d [nostalgia] Allow disabling of BUILD_SHARED_LIBS c5999050 [nostalgia] Add support for partial tilesheet loading da23c930 [ox/std] Add oxModelFwdDecl macro for broken Apple Clang 3ae1d6c8 [ox/std] Make operator[] in Array and Vector nodiscard a7af6c66 [keel] Cleanup 0cc6757c [keel] Add manifest to pack output 3b8eaef3 [keel] Move vald and repair funcs to their own file, make conversion to validation b7990ed2 [keel] Make pack file copy logging nest for dir level 71313ed8 [ox/std] Cleanup 10531b6e [keel] Cleanup dfbc298d [keel] Add pack file copy status to logging 76760daf [ox/std] Cleanup Defer 5834b9c9 [ox/std] Cleanup logging output 2a584905 [ox/fs] More cleanup and bug fix from previous cleanup 702b166b [ox/fs] Cleanup 8dd837b3 [nostalgia/core] Add a valid function for CompactTileSheet 1d262597 [keel] Make default repair return a no repair error 712299fa [studio] Cleanup c45efa60 [ox/std] Make Result copyTo and moveTo able to convert git-subtree-dir: deps/nostalgia git-subtree-split: 0daf938f765b3a3ce8ba7fb292572a6a5a004634
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
#include <ox/std/hashmap.hpp>
|
||||
#include <ox/std/utility.hpp>
|
||||
|
||||
#include "validation.hpp"
|
||||
|
||||
namespace keel {
|
||||
|
||||
class AssetManager;
|
||||
@@ -21,17 +23,6 @@ class AssetManager;
|
||||
template<typename T>
|
||||
class AssetRef;
|
||||
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool valid(auto const&) noexcept {
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Error repair(auto const&) noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
#ifndef OX_BARE_METAL
|
||||
template<typename T>
|
||||
class AssetContainer {
|
||||
@@ -226,9 +217,7 @@ class AssetManager {
|
||||
ox::Result<AssetRef<T>> loadAsset(ox::StringView const assetId) noexcept {
|
||||
auto &p = m_cache[assetId];
|
||||
oxRequireM(obj, m_loader(assetId));
|
||||
if (!valid(obj) && repair(obj)) {
|
||||
return OxError(1, "asset is invalid state and could not be repaired");
|
||||
}
|
||||
oxReturnError(ensureValid(obj));
|
||||
if (!p) {
|
||||
p = ox::make_unique<AssetContainer<T>>(std::move(obj));
|
||||
} else {
|
||||
|
@@ -17,10 +17,10 @@ namespace keel {
|
||||
ox::Error init(
|
||||
keel::Context &ctx,
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::CRStringView appName) noexcept;
|
||||
ox::StringViewCR appName) noexcept;
|
||||
|
||||
ox::Result<ox::UPtr<Context>> init(
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::CRStringView appName) noexcept;
|
||||
ox::StringViewCR appName) noexcept;
|
||||
|
||||
}
|
||||
|
@@ -30,14 +30,14 @@ oxModelBegin(PreloadPtr)
|
||||
oxModelEnd()
|
||||
|
||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::FileAddress const&file) noexcept;
|
||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::CRStringView file) noexcept;
|
||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::StringViewCR file) noexcept;
|
||||
|
||||
|
||||
void createUuidMapping(Context &ctx, ox::StringView filePath, ox::UUID const&uuid) noexcept;
|
||||
|
||||
ox::Error buildUuidMap(Context &ctx) noexcept;
|
||||
|
||||
ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::CRStringView path) noexcept;
|
||||
ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::StringViewCR path) noexcept;
|
||||
|
||||
ox::Result<ox::UUID> getUuid(Context &ctx, ox::FileAddress const&fileAddr) noexcept;
|
||||
|
||||
@@ -53,12 +53,10 @@ constexpr ox::Result<ox::UUID> uuidUrlToUuid(ox::StringView uuidUrl) noexcept {
|
||||
|
||||
ox::Result<ox::CStringView> uuidUrlToPath(Context &ctx, ox::StringView uuid) noexcept;
|
||||
|
||||
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::CRStringView uuid) noexcept;
|
||||
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::StringViewCR uuid) noexcept;
|
||||
|
||||
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::UUID const&uuid) noexcept;
|
||||
|
||||
ox::Error performPackTransforms(Context &ctx, ox::Buffer &clawData) noexcept;
|
||||
|
||||
#ifndef OX_BARE_METAL
|
||||
|
||||
namespace detail {
|
||||
@@ -116,7 +114,7 @@ ox::Result<keel::AssetRef<T>> readObjFile(
|
||||
template<typename T>
|
||||
ox::Result<keel::AssetRef<T>> readObjNoCache(
|
||||
keel::Context &ctx,
|
||||
ox::CRStringView assetId) noexcept {
|
||||
ox::StringViewCR assetId) noexcept {
|
||||
if constexpr(ox::preloadable<T>::value) {
|
||||
oxRequire(addr, getPreloadAddr(ctx, assetId));
|
||||
return keel::AssetRef<T>(std::bit_cast<T const*>(uintptr_t{addr}));
|
||||
@@ -132,7 +130,7 @@ ox::Error reloadAsset(keel::Context &ctx, ox::StringView assetId) noexcept;
|
||||
template<typename T>
|
||||
ox::Result<keel::AssetRef<T>> readObj(
|
||||
keel::Context &ctx,
|
||||
ox::CRStringView assetId,
|
||||
ox::StringViewCR assetId,
|
||||
[[maybe_unused]] bool forceLoad = false) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
return readObjFile<T>(ctx, assetId, forceLoad);
|
||||
@@ -171,9 +169,9 @@ ox::Error writeObj(
|
||||
|
||||
ox::Error setRomFs(Context &ctx, ox::UPtr<ox::FileSystem> &&fs) noexcept;
|
||||
|
||||
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::CRStringView path) noexcept;
|
||||
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::StringViewCR path) noexcept;
|
||||
|
||||
ox::Result<char*> loadRom(ox::CRStringView path = "") noexcept;
|
||||
ox::Result<char*> loadRom(ox::StringViewCR path = "") noexcept;
|
||||
|
||||
void unloadRom(char*) noexcept;
|
||||
|
||||
|
@@ -15,7 +15,7 @@ using TypeDescGenerator = ox::Error(*)(ox::TypeStore&);
|
||||
|
||||
template<typename T>
|
||||
ox::Error generateTypeDesc(ox::TypeStore &ts) noexcept {
|
||||
return ox::buildTypeDef<T>(&ts).error;
|
||||
return ox::buildTypeDef<T>(ts).error;
|
||||
}
|
||||
|
||||
class Module {
|
||||
|
@@ -12,6 +12,31 @@
|
||||
|
||||
namespace keel {
|
||||
|
||||
struct ManifestEntry {
|
||||
static constexpr auto TypeName = "net.drinkingtea.keel.ManifestEntry";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
uint64_t inode{};
|
||||
bool preloaded{};
|
||||
ox::String type;
|
||||
};
|
||||
|
||||
oxModelBegin(ManifestEntry)
|
||||
oxModelField(inode)
|
||||
oxModelField(preloaded)
|
||||
oxModelField(type)
|
||||
oxModelEnd()
|
||||
|
||||
struct Manifest {
|
||||
static constexpr auto TypeName = "net.drinkingtea.keel.Manifest";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
ox::HashMap<ox::String, ManifestEntry> files;
|
||||
};
|
||||
|
||||
oxModelBegin(Manifest)
|
||||
oxModelField(files)
|
||||
oxModelEnd()
|
||||
|
||||
|
||||
class Context;
|
||||
|
||||
struct GbaPlatSpec {
|
||||
@@ -113,10 +138,11 @@ ox::Error preloadObj(
|
||||
// transformations need to be done after the copy to the new FS is complete
|
||||
template<typename PlatSpec>
|
||||
ox::Error preloadDir(
|
||||
Manifest &manifest,
|
||||
ox::TypeStore &ts,
|
||||
ox::FileSystem &romFs,
|
||||
ox::Preloader<PlatSpec> &pl,
|
||||
ox::CRStringView path) noexcept {
|
||||
ox::StringViewCR path) noexcept {
|
||||
// copy
|
||||
oxTracef("pack.preload", "path: {}", path);
|
||||
oxRequire(fileList, romFs.ls(path));
|
||||
@@ -125,13 +151,14 @@ ox::Error preloadDir(
|
||||
oxRequire(stat, romFs.stat(filePath));
|
||||
if (stat.fileType == ox::FileType::Directory) {
|
||||
auto const dir = ox::sfmt("{}{}/", path, name);
|
||||
oxReturnError(preloadDir(ts, romFs, pl, dir));
|
||||
oxReturnError(preloadDir(manifest, ts, romFs, pl, dir));
|
||||
} else {
|
||||
auto const err = preloadObj(ts, romFs, pl, filePath);
|
||||
if (err) {
|
||||
oxErrf("\033[31;1;1mCould not preload {}:\n\t{}\n", filePath, toStr(err));
|
||||
return err;
|
||||
}
|
||||
manifest.files[filePath].preloaded = true;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
@@ -162,11 +189,15 @@ ox::Error appendBinary(ox::Buffer &binBuff, ox::SpanView<char> const&fsBuff, ox:
|
||||
}
|
||||
|
||||
template<typename PlatSpec>
|
||||
ox::Error preload(ox::TypeStore &ts, ox::FileSystem &src, ox::Preloader<PlatSpec> &pl) noexcept {
|
||||
ox::Error preload(
|
||||
Manifest &manifest,
|
||||
ox::TypeStore &ts,
|
||||
ox::FileSystem &src,
|
||||
ox::Preloader<PlatSpec> &pl) noexcept {
|
||||
oxOut("Preloading\n");
|
||||
return detail::preloadDir(ts, src, pl, "/");
|
||||
return detail::preloadDir(manifest, ts, src, pl, "/");
|
||||
}
|
||||
|
||||
ox::Error pack(keel::Context &ctx, ox::TypeStore &ts, ox::FileSystem &dest) noexcept;
|
||||
ox::Error pack(Manifest &manifest, keel::Context &ctx, ox::TypeStore &ts, ox::FileSystem &dest) noexcept;
|
||||
|
||||
}
|
||||
|
@@ -51,29 +51,29 @@ constexpr T &wrapCast(Wrap &ptr) noexcept {
|
||||
|
||||
class BaseConverter {
|
||||
public:
|
||||
virtual ~BaseConverter() noexcept = default;
|
||||
constexpr virtual ~BaseConverter() noexcept = default;
|
||||
|
||||
[[nodiscard]]
|
||||
virtual ox::StringView srcTypeName() const noexcept = 0;
|
||||
constexpr virtual ox::StringView srcTypeName() const noexcept = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
virtual int srcTypeVersion() const noexcept = 0;
|
||||
constexpr virtual int srcTypeVersion() const noexcept = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
virtual bool srcMatches(ox::CRStringView pSrcTypeName, int pSrcTypeVersion) const noexcept = 0;
|
||||
constexpr virtual bool srcMatches(ox::StringViewCR pSrcTypeName, int pSrcTypeVersion) const noexcept = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
virtual bool dstMatches(ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept = 0;
|
||||
constexpr virtual bool dstMatches(ox::StringViewCR dstTypeName, int dstTypeVersion) const noexcept = 0;
|
||||
|
||||
virtual ox::Result<ox::UPtr<Wrap>> convertPtrToPtr(keel::Context &ctx, Wrap &src) const noexcept = 0;
|
||||
|
||||
virtual ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
|
||||
keel::Context &ctx, ox::Buffer const&srcBuff) const noexcept = 0;
|
||||
keel::Context &ctx, ox::BufferView const&srcBuff) const noexcept = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
inline bool matches(
|
||||
ox::CRStringView srcTypeName, int srcTypeVersion,
|
||||
ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept {
|
||||
constexpr bool matches(
|
||||
ox::StringViewCR srcTypeName, int srcTypeVersion,
|
||||
ox::StringViewCR dstTypeName, int dstTypeVersion) const noexcept {
|
||||
return srcMatches(srcTypeName, srcTypeVersion)
|
||||
&& dstMatches(dstTypeName, dstTypeVersion);
|
||||
}
|
||||
@@ -84,17 +84,17 @@ template<typename SrcType, typename DstType>
|
||||
class Converter: public BaseConverter {
|
||||
public:
|
||||
[[nodiscard]]
|
||||
ox::StringView srcTypeName() const noexcept final {
|
||||
constexpr ox::StringView srcTypeName() const noexcept final {
|
||||
return ox::ModelTypeName_v<SrcType>;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
int srcTypeVersion() const noexcept final {
|
||||
constexpr int srcTypeVersion() const noexcept final {
|
||||
return ox::ModelTypeVersion_v<SrcType>;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool srcMatches(ox::CRStringView pSrcTypeName, int pSrcTypeVersion) const noexcept final {
|
||||
constexpr bool srcMatches(ox::StringViewCR pSrcTypeName, int pSrcTypeVersion) const noexcept final {
|
||||
constexpr auto SrcTypeName = ox::requireModelTypeName<SrcType>();
|
||||
constexpr auto SrcTypeVersion = ox::requireModelTypeVersion<SrcType>();
|
||||
return pSrcTypeName == SrcTypeName
|
||||
@@ -102,8 +102,8 @@ class Converter: public BaseConverter {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool dstMatches(ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept final {
|
||||
constexpr auto DstTypeName = ox::StringView(ox::requireModelTypeName<DstType>());
|
||||
constexpr bool dstMatches(ox::StringViewCR dstTypeName, int dstTypeVersion) const noexcept final {
|
||||
constexpr auto DstTypeName = ox::StringView{ox::requireModelTypeName<DstType>()};
|
||||
constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>();
|
||||
return dstTypeName == DstTypeName
|
||||
&& dstTypeVersion == DstTypeVersion;
|
||||
@@ -117,8 +117,9 @@ class Converter: public BaseConverter {
|
||||
}
|
||||
|
||||
ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
|
||||
keel::Context &ctx, ox::Buffer const&srcBuff) const noexcept final {
|
||||
keel::Context &ctx, ox::BufferView const&srcBuff) const noexcept final {
|
||||
oxRequireM(src, readAsset<SrcType>(srcBuff));
|
||||
oxReturnError(ensureValid(src));
|
||||
auto dst = makeWrap<DstType>();
|
||||
oxReturnError(convert(ctx, src, wrapCast<DstType>(*dst)));
|
||||
return {std::move(dst)};
|
||||
@@ -131,12 +132,12 @@ class Converter: public BaseConverter {
|
||||
|
||||
ox::Result<ox::UPtr<Wrap>> convert(
|
||||
keel::Context &ctx,
|
||||
ox::Buffer const&srcBuffer,
|
||||
ox::CRStringView dstTypeName,
|
||||
ox::BufferView const&srcBuffer,
|
||||
ox::StringViewCR dstTypeName,
|
||||
int dstTypeVersion) noexcept;
|
||||
|
||||
template<typename DstType>
|
||||
ox::Result<DstType> convert(keel::Context &ctx, ox::Buffer const&srcBuffer) noexcept {
|
||||
ox::Result<DstType> convert(keel::Context &ctx, ox::BufferView const&srcBuffer) noexcept {
|
||||
static constexpr auto DstTypeName = ox::requireModelTypeName<DstType>();
|
||||
static constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>();
|
||||
oxRequire(out, convert(ctx, srcBuffer, DstTypeName, DstTypeVersion));
|
||||
@@ -144,7 +145,7 @@ ox::Result<DstType> convert(keel::Context &ctx, ox::Buffer const&srcBuffer) noex
|
||||
}
|
||||
|
||||
template<typename DstType>
|
||||
ox::Error convert(keel::Context &ctx, ox::Buffer const&buff, DstType *outObj) noexcept {
|
||||
ox::Error convert(keel::Context &ctx, ox::BufferView const&buff, DstType *outObj) noexcept {
|
||||
static constexpr auto DstTypeName = ox::requireModelTypeName<DstType>();
|
||||
static constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>();
|
||||
oxRequire(outPtr, convert(ctx, buff, DstTypeName, DstTypeVersion));
|
||||
@@ -154,7 +155,7 @@ ox::Error convert(keel::Context &ctx, ox::Buffer const&buff, DstType *outObj) no
|
||||
|
||||
template<typename DstType>
|
||||
ox::Result<ox::Buffer> convertBuffToBuff(
|
||||
keel::Context &ctx, ox::Buffer const&srcBuffer, ox::ClawFormat fmt) noexcept {
|
||||
keel::Context &ctx, ox::BufferView const&srcBuffer, ox::ClawFormat fmt) noexcept {
|
||||
static constexpr auto DstTypeName = ox::requireModelTypeName<DstType>();
|
||||
static constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>();
|
||||
oxRequire(out, convert(ctx, srcBuffer, DstTypeName, DstTypeVersion));
|
||||
|
27
src/olympic/keel/include/keel/validation.hpp
Normal file
27
src/olympic/keel/include/keel/validation.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/error.hpp>
|
||||
|
||||
namespace keel {
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool valid(auto const&) noexcept {
|
||||
return true;
|
||||
}
|
||||
|
||||
constexpr ox::Error repair(auto const&) noexcept {
|
||||
return OxError(1, "No repair function for this type");
|
||||
}
|
||||
|
||||
constexpr ox::Error ensureValid(auto &o) noexcept {
|
||||
if (!valid(o)) {
|
||||
return repair(o);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
@@ -9,7 +9,7 @@ namespace keel {
|
||||
ox::Error init(
|
||||
keel::Context &ctx,
|
||||
ox::UPtr<ox::FileSystem> &&fs,
|
||||
ox::CRStringView appName) noexcept {
|
||||
ox::StringViewCR appName) noexcept {
|
||||
ctx.appName = appName;
|
||||
std::ignore = setRomFs(ctx, std::move(fs));
|
||||
#ifndef OX_BARE_METAL
|
||||
@@ -28,7 +28,7 @@ ox::Error init(
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Result<ox::UPtr<Context>> init(ox::UPtr<ox::FileSystem> &&fs, ox::CRStringView appName) noexcept {
|
||||
ox::Result<ox::UPtr<Context>> init(ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept {
|
||||
auto ctx = ox::make_unique<Context>();
|
||||
oxReturnError(keel::init(*ctx, std::move(fs), appName));
|
||||
return ctx;
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace keel {
|
||||
|
||||
ox::Result<char*> loadRom(ox::CRStringView path) noexcept {
|
||||
ox::Result<char*> loadRom(ox::StringViewCR path) noexcept {
|
||||
std::ifstream file(std::string(toStdStringView(path)), std::ios::binary | std::ios::ate);
|
||||
if (!file.good()) {
|
||||
oxErrorf("Could not find ROM file: {}", path);
|
||||
@@ -47,7 +47,7 @@ void createUuidMapping(Context &ctx, ox::StringView filePath, ox::UUID const&uui
|
||||
ctx.uuidToPath[uuid.toString()] = filePath;
|
||||
}
|
||||
|
||||
static ox::Error buildUuidMap(Context &ctx, ox::CRStringView path) noexcept {
|
||||
static ox::Error buildUuidMap(Context &ctx, ox::StringViewCR path) noexcept {
|
||||
oxRequire(files, ctx.rom->ls(path));
|
||||
for (auto const&f : files) {
|
||||
oxRequireM(filePath, ox::join("/", ox::Array<ox::StringView, 2>{path, f}));
|
||||
@@ -74,7 +74,7 @@ ox::Error buildUuidMap(Context &ctx) noexcept {
|
||||
return buildUuidMap(ctx, "");
|
||||
}
|
||||
|
||||
ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::CRStringView path) noexcept {
|
||||
ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::StringViewCR path) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
oxRequire(out, ctx.pathToUuid.at(path));
|
||||
return *out;
|
||||
@@ -136,7 +136,7 @@ ox::Result<ox::CStringView> uuidUrlToPath(Context &ctx, ox::StringView uuid) noe
|
||||
#endif
|
||||
}
|
||||
|
||||
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::CRStringView uuid) noexcept {
|
||||
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::StringViewCR uuid) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
oxRequireM(out, ctx.uuidToPath.at(uuid));
|
||||
return ox::CStringView(*out);
|
||||
@@ -154,18 +154,6 @@ ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::UUID const&uuid) noexce
|
||||
#endif
|
||||
}
|
||||
|
||||
ox::Error performPackTransforms(Context &ctx, ox::Buffer &clawData) noexcept {
|
||||
oxRequireM(typeId, readAssetTypeId(clawData));
|
||||
for (auto const tr : packTransforms(ctx)) {
|
||||
bool changed{};
|
||||
oxReturnError(tr(ctx, clawData, typeId).moveTo(changed));
|
||||
if (changed) {
|
||||
oxReturnError(readAssetTypeId(clawData).moveTo(typeId));
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error reloadAsset(keel::Context &ctx, ox::StringView assetId) noexcept {
|
||||
ox::UUIDStr uuidStr;
|
||||
if (beginsWith(assetId, "uuid://")) {
|
||||
@@ -198,7 +186,7 @@ ox::Error buildUuidMap(Context&) noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Result<char*> loadRom(ox::CRStringView) noexcept {
|
||||
ox::Result<char*> loadRom(ox::StringViewCR) noexcept {
|
||||
// put the header in the wrong order to prevent mistaking this code for the
|
||||
// media section
|
||||
constexpr auto headerP2 = "R_______________";
|
||||
@@ -218,7 +206,7 @@ ox::Result<char*> loadRom(ox::CRStringView) noexcept {
|
||||
void unloadRom(char*) noexcept {
|
||||
}
|
||||
|
||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::CRStringView path) noexcept {
|
||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::StringViewCR path) noexcept {
|
||||
oxRequire(stat, ctx.rom->stat(path));
|
||||
oxRequire(buff, static_cast<ox::MemFS*>(ctx.rom.get())->directAccess(path));
|
||||
PreloadPtr p;
|
||||
@@ -250,7 +238,7 @@ ox::Error setRomFs(Context &ctx, ox::UPtr<ox::FileSystem> &&fs) noexcept {
|
||||
return buildUuidMap(ctx);
|
||||
}
|
||||
|
||||
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::CRStringView path) noexcept {
|
||||
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::StringViewCR path) noexcept {
|
||||
auto const lastDot = ox::lastIndexOf(path, '.');
|
||||
if (!lastDot.error && substr(path, lastDot.value) == ".oxfs") {
|
||||
oxRequire(rom, loadRom(path));
|
||||
|
@@ -8,6 +8,7 @@
|
||||
#include <ox/fs/fs.hpp>
|
||||
#include <ox/logconn/def.hpp>
|
||||
#include <ox/logconn/logconn.hpp>
|
||||
#include <ox/oc/write.hpp>
|
||||
|
||||
#include <keel/keel.hpp>
|
||||
|
||||
@@ -48,16 +49,21 @@ static ox::Error generateTypes(ox::TypeStore &ts) noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
static ox::Error pack(ox::StringView argSrc, ox::StringView argRomBin, ox::StringView projectDataDir) noexcept {
|
||||
static ox::Error pack(
|
||||
ox::StringView argSrc,
|
||||
ox::StringView argRomBin,
|
||||
ox::StringView argManifest,
|
||||
ox::StringView projectDataDir) noexcept {
|
||||
ox::Buffer dstBuff(32 * ox::units::MB);
|
||||
oxReturnError(ox::FileSystem32::format(dstBuff.data(), dstBuff.size()));
|
||||
ox::FileSystem32 dst(dstBuff);
|
||||
oxRequire(ctx, keel::init(ox::make_unique<ox::PassThroughFS>(argSrc), "keel-pack"));
|
||||
keel::TypeStore ts(*ctx->rom, ox::sfmt("{}/type_descriptors", projectDataDir));
|
||||
oxReturnError(generateTypes(ts));
|
||||
oxReturnError(keel::pack(*ctx, ts, dst));
|
||||
keel::Manifest manifest;
|
||||
oxReturnError(keel::pack(manifest, *ctx, ts, dst));
|
||||
oxRequireM(pl, keel::GbaPreloader::make());
|
||||
oxReturnError(preload(ts, dst, *pl));
|
||||
oxReturnError(preload(manifest, ts, dst, *pl));
|
||||
oxReturnError(dst.resize());
|
||||
// resize buffer
|
||||
oxRequire(dstSize, dst.size());
|
||||
@@ -70,6 +76,8 @@ static ox::Error pack(ox::StringView argSrc, ox::StringView argRomBin, ox::Strin
|
||||
oxReturnError(appendBinary(romBuff, dstBuff, *pl));
|
||||
oxOutf("Final ROM buff size: {} bytes\n", romBuff.size());
|
||||
oxReturnError(writeFileBuff(argRomBin, romBuff));
|
||||
oxRequire(manifestJson, ox::writeOCString(manifest));
|
||||
oxReturnError(writeFileBuff(argManifest, {manifestJson.data(), manifestJson.len()}));
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -77,6 +85,7 @@ static ox::Error run(int argc, char const**argv, ox::StringView projectDataDir)
|
||||
ox::ClArgs const args(argc, argv);
|
||||
auto const argSrc = args.getString("src", "");
|
||||
auto const argRomBin = args.getString("rom-bin", "");
|
||||
auto const argManifest = args.getString("manifest", "");
|
||||
if (argSrc == "") {
|
||||
oxErr("\033[31;1;1merror:\033[0m must specify a source directory\n");
|
||||
return OxError(1, "must specify a source directory");
|
||||
@@ -85,7 +94,7 @@ static ox::Error run(int argc, char const**argv, ox::StringView projectDataDir)
|
||||
oxErr("\033[31;1;1merror:\033[0m must specify a path for ROM file\n");
|
||||
return OxError(1, "must specify a path for preload file");
|
||||
}
|
||||
return pack(argSrc, argRomBin, projectDataDir);
|
||||
return pack(argSrc, argRomBin, argManifest, projectDataDir);
|
||||
}
|
||||
|
||||
namespace olympic {
|
||||
|
@@ -6,13 +6,14 @@
|
||||
#include <ox/model/modelvalue.hpp>
|
||||
|
||||
#include <keel/media.hpp>
|
||||
|
||||
#include <keel/pack.hpp>
|
||||
|
||||
namespace keel {
|
||||
|
||||
static ox::Error pathToInode(
|
||||
keel::Context &ctx, ox::FileSystem &dest, ox::ModelObject &obj) noexcept {
|
||||
keel::Context &ctx,
|
||||
ox::FileSystem &dest,
|
||||
ox::ModelObject &obj) noexcept {
|
||||
auto &o = obj;
|
||||
auto type = static_cast<ox::FileAddressType>(o.at("type").unwrap()->get<int8_t>());
|
||||
auto &data = o.at("data").unwrap()->get<ox::ModelUnion>();
|
||||
@@ -85,16 +86,33 @@ static ox::Error transformFileAddressesObj(
|
||||
return {};
|
||||
}
|
||||
|
||||
static ox::Error performPackTransforms(
|
||||
ManifestEntry &entry,
|
||||
Context &ctx,
|
||||
ox::Buffer &clawData) noexcept {
|
||||
oxRequireM(typeId, readAssetTypeId(clawData));
|
||||
for (auto const tr : packTransforms(ctx)) {
|
||||
bool changed{};
|
||||
oxReturnError(tr(ctx, clawData, typeId).moveTo(changed));
|
||||
if (changed) {
|
||||
oxReturnError(readAssetTypeId(clawData).moveTo(typeId));
|
||||
}
|
||||
}
|
||||
entry.type = ox::String{typeId};
|
||||
return {};
|
||||
}
|
||||
|
||||
static ox::Error doTransformations(
|
||||
Manifest &manifest,
|
||||
keel::Context &ctx,
|
||||
ox::TypeStore &ts,
|
||||
ox::FileSystem &dest,
|
||||
ox::CRStringView filePath) noexcept {
|
||||
ox::StringViewCR filePath) noexcept {
|
||||
// load file
|
||||
oxRequire(s, dest.stat(filePath));
|
||||
// do transformations
|
||||
oxRequireM(buff, dest.read(s.inode));
|
||||
oxReturnError(keel::performPackTransforms(ctx, buff));
|
||||
oxReturnError(keel::performPackTransforms(manifest.files[filePath], ctx, buff));
|
||||
// transform FileAddresses
|
||||
oxRequireM(obj, keel::readAsset(ts, buff));
|
||||
oxOutf("transforming {}\n", filePath);
|
||||
@@ -108,10 +126,11 @@ static ox::Error doTransformations(
|
||||
// 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
|
||||
static ox::Error transformClaw(
|
||||
Manifest &manifest,
|
||||
keel::Context &ctx,
|
||||
ox::TypeStore &ts,
|
||||
ox::FileSystem &dest,
|
||||
ox::CRStringView path) noexcept {
|
||||
ox::StringViewCR path) noexcept {
|
||||
// copy
|
||||
oxTracef("pack.transformClaw", "path: {}", path);
|
||||
oxRequire(fileList, dest.ls(path));
|
||||
@@ -120,9 +139,9 @@ static ox::Error transformClaw(
|
||||
oxRequire(stat, dest.stat(filePath));
|
||||
if (stat.fileType == ox::FileType::Directory) {
|
||||
auto const dir = ox::sfmt("{}{}/", path, name);
|
||||
oxReturnError(transformClaw(ctx, ts, dest, dir));
|
||||
oxReturnError(transformClaw(manifest, ctx, ts, dest, dir));
|
||||
} else {
|
||||
auto const err = doTransformations(ctx, ts, dest, filePath);
|
||||
auto const err = doTransformations(manifest, ctx, ts, dest, filePath);
|
||||
if (err) {
|
||||
oxErrf("\033[31;1;1mCould not do transformations for {}:\n\t{}\n", filePath, toStr(err));
|
||||
return err;
|
||||
@@ -133,10 +152,13 @@ static ox::Error transformClaw(
|
||||
}
|
||||
|
||||
static ox::Error copy(
|
||||
Manifest &manifest,
|
||||
ox::FileSystem &src,
|
||||
ox::FileSystem &dest,
|
||||
ox::CRStringView path) noexcept {
|
||||
oxOutf("copying directory: {}\n", path);
|
||||
ox::StringViewCR path,
|
||||
ox::StringViewCR logPrefix = "") noexcept {
|
||||
oxOutf("{}copying directory: {}\n", logPrefix, path);
|
||||
auto const childLogPrefix = ox::sfmt("{}\t", logPrefix);
|
||||
// copy
|
||||
oxRequire(fileList, src.ls(path));
|
||||
for (auto const&name : fileList) {
|
||||
@@ -147,27 +169,36 @@ static ox::Error copy(
|
||||
oxRequire(stat, src.stat(currentFile));
|
||||
if (stat.fileType == ox::FileType::Directory) {
|
||||
oxReturnError(dest.mkdir(currentFile, true));
|
||||
oxReturnError(copy(src, dest, currentFile + '/'));
|
||||
oxReturnError(copy(manifest, src, dest, currentFile + '/', childLogPrefix));
|
||||
} else {
|
||||
// load file
|
||||
oxOutf("copying file: {}\n", currentFile);
|
||||
oxOutf("{}copying file: {}...", childLogPrefix, currentFile);
|
||||
ox::StringView status = "failed";
|
||||
oxDefer [&status] {
|
||||
oxOutf(" {}\n", status);
|
||||
};
|
||||
oxRequireM(buff, src.read(currentFile));
|
||||
// write file to dest
|
||||
oxReturnError(dest.write(currentFile, buff));
|
||||
status = "OK";
|
||||
oxRequire(stat, dest.stat(currentFile));
|
||||
manifest.files[currentFile] = {
|
||||
.inode = stat.inode,
|
||||
.type = ox::String{keel::readAssetTypeId(buff).or_value({})},
|
||||
};
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
static ox::Error copyFS(ox::FileSystem &src, ox::FileSystem &dest) noexcept {
|
||||
oxReturnError(copy(src, dest, "/"));
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error pack(keel::Context &ctx, ox::TypeStore &ts, ox::FileSystem &dest) noexcept {
|
||||
oxReturnError(copyFS(*ctx.rom, dest));
|
||||
ox::Error pack(
|
||||
Manifest &manifest,
|
||||
keel::Context &ctx,
|
||||
ox::TypeStore &ts,
|
||||
ox::FileSystem &dest) noexcept {
|
||||
oxReturnError(copy(manifest, *ctx.rom, dest, "/"));
|
||||
oxOut("Doing transforms\n");
|
||||
oxReturnError(transformClaw(ctx, ts, dest, "/"));
|
||||
oxReturnError(transformClaw(manifest, ctx, ts, dest, "/"));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@@ -9,12 +9,11 @@
|
||||
|
||||
namespace keel {
|
||||
|
||||
[[nodiscard]]
|
||||
static ox::Result<BaseConverter const*> findConverter(
|
||||
ox::SpanView<BaseConverter const*> const&converters,
|
||||
ox::CRStringView srcTypeName,
|
||||
ox::StringViewCR srcTypeName,
|
||||
int srcTypeVersion,
|
||||
ox::CRStringView dstTypeName,
|
||||
ox::StringViewCR dstTypeName,
|
||||
int dstTypeVersion) noexcept {
|
||||
for (auto const&c : converters) {
|
||||
if (c->matches(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion)) {
|
||||
@@ -27,10 +26,10 @@ static ox::Result<BaseConverter const*> findConverter(
|
||||
static ox::Result<ox::UPtr<Wrap>> convert(
|
||||
keel::Context &ctx,
|
||||
ox::SpanView<BaseConverter const*> const&converters,
|
||||
ox::Buffer const&srcBuffer,
|
||||
ox::CRStringView srcTypeName,
|
||||
ox::BufferView const&srcBuffer,
|
||||
ox::StringViewCR srcTypeName,
|
||||
int srcTypeVersion,
|
||||
ox::CRStringView dstTypeName,
|
||||
ox::StringViewCR dstTypeName,
|
||||
int dstTypeVersion) noexcept {
|
||||
// look for direct converter
|
||||
auto [c, err] = findConverter(
|
||||
@@ -55,8 +54,8 @@ static ox::Result<ox::UPtr<Wrap>> convert(
|
||||
|
||||
ox::Result<ox::UPtr<Wrap>> convert(
|
||||
keel::Context &ctx,
|
||||
ox::Buffer const&srcBuffer,
|
||||
ox::CRStringView dstTypeName,
|
||||
ox::BufferView const&srcBuffer,
|
||||
ox::StringViewCR dstTypeName,
|
||||
int dstTypeVersion) noexcept {
|
||||
oxRequire(hdr, readAssetHeader(srcBuffer));
|
||||
return convert(
|
||||
|
Reference in New Issue
Block a user