[nostalgia,olympic] Change macro names to comply with broader conventions
This commit is contained in:
@ -16,8 +16,8 @@ constexpr auto K1HdrSz = 40;
|
||||
ox::Result<ox::UUID> readUuidHeader(ox::BufferView buff) noexcept;
|
||||
|
||||
ox::Error writeUuidHeader(ox::Writer_c auto &writer, ox::UUID const&uuid) noexcept {
|
||||
oxReturnError(write(writer, "K1;"));
|
||||
oxReturnError(uuid.toString(writer));
|
||||
OX_RETURN_ERROR(write(writer, "K1;"));
|
||||
OX_RETURN_ERROR(uuid.toString(writer));
|
||||
return writer.put(';');
|
||||
}
|
||||
|
||||
@ -29,8 +29,8 @@ ox::Result<T> readAsset(ox::BufferView buff) noexcept {
|
||||
offset = K1HdrSz; // the size of K1 headers
|
||||
}
|
||||
auto out = ox::readClaw<T>(buff + offset);
|
||||
oxReturnError(out);
|
||||
oxReturnError(ensureValid(out.value));
|
||||
OX_RETURN_ERROR(out);
|
||||
OX_RETURN_ERROR(ensureValid(out.value));
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -205,7 +205,7 @@ class AssetManager {
|
||||
AssetTypeManager(Loader loader) noexcept: m_loader(loader) {}
|
||||
|
||||
ox::Result<AssetRef<T>> getAsset(ox::StringView const assetId) const noexcept {
|
||||
oxRequire(out, m_cache.at(assetId));
|
||||
OX_REQUIRE(out, m_cache.at(assetId));
|
||||
if (!out || !*out) {
|
||||
return ox::Error(1, "asset is null");
|
||||
}
|
||||
@ -214,7 +214,7 @@ class AssetManager {
|
||||
|
||||
ox::Result<AssetRef<T>> loadAsset(ox::StringView const assetId) noexcept {
|
||||
auto &p = m_cache[assetId];
|
||||
oxRequireM(obj, m_loader(assetId));
|
||||
OX_REQUIRE_M(obj, m_loader(assetId));
|
||||
if (!p) {
|
||||
p = ox::make_unique<AssetContainer<T>>(std::move(obj));
|
||||
} else {
|
||||
@ -226,7 +226,7 @@ class AssetManager {
|
||||
|
||||
ox::Error reloadAsset(ox::StringView const assetId) noexcept {
|
||||
auto &p = m_cache[assetId];
|
||||
oxRequireM(obj, m_loader(assetId));
|
||||
OX_REQUIRE_M(obj, m_loader(assetId));
|
||||
if (!p) {
|
||||
p = ox::make_unique<AssetContainer<T>>(std::move(obj));
|
||||
} else {
|
||||
@ -274,7 +274,7 @@ class AssetManager {
|
||||
|
||||
template<typename T>
|
||||
ox::Result<AssetRef<T>> getAsset(ox::StringView assetId) noexcept {
|
||||
oxRequire(m, getTypeManager<T>());
|
||||
OX_REQUIRE(m, getTypeManager<T>());
|
||||
return m->getAsset(assetId);
|
||||
}
|
||||
|
||||
@ -285,8 +285,8 @@ class AssetManager {
|
||||
|
||||
template<typename T>
|
||||
ox::Result<AssetRef<T>> loadAsset(ox::StringView assetId) noexcept {
|
||||
oxRequire(m, getTypeManager<T>());
|
||||
oxRequire(out, m->loadAsset(assetId));
|
||||
OX_REQUIRE(m, getTypeManager<T>());
|
||||
OX_REQUIRE(out, m->loadAsset(assetId));
|
||||
m_fileUpdated[assetId].connect(m, &AssetTypeManager<T>::reloadAsset);
|
||||
return out;
|
||||
}
|
||||
|
@ -25,9 +25,9 @@ struct PreloadPtr {
|
||||
uint64_t preloadAddr = 0;
|
||||
};
|
||||
|
||||
oxModelBegin(PreloadPtr)
|
||||
oxModelField(preloadAddr)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(PreloadPtr)
|
||||
OX_MODEL_FIELD(preloadAddr)
|
||||
OX_MODEL_END()
|
||||
|
||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::FileAddress const&addr) noexcept;
|
||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::StringViewCR path) noexcept;
|
||||
@ -63,14 +63,14 @@ namespace detail {
|
||||
template<typename T>
|
||||
constexpr auto makeLoader(Context &ctx) {
|
||||
return [&ctx](ox::StringView assetId) -> ox::Result<T> {
|
||||
oxRequire(p, ctx.uuidToPath.at(assetId));
|
||||
oxRequire(buff, ctx.rom->read(*p));
|
||||
OX_REQUIRE(p, ctx.uuidToPath.at(assetId));
|
||||
OX_REQUIRE(buff, ctx.rom->read(*p));
|
||||
auto [obj, err] = readAsset<T>(buff);
|
||||
if (err) {
|
||||
if (err != ox::Error_ClawTypeVersionMismatch && err != ox::Error_ClawTypeMismatch) {
|
||||
return err;
|
||||
}
|
||||
oxReturnError(convert<T>(ctx, buff, &obj));
|
||||
OX_RETURN_ERROR(convert<T>(ctx, buff, &obj));
|
||||
}
|
||||
return std::move(obj);
|
||||
};
|
||||
@ -97,7 +97,7 @@ ox::Result<keel::AssetRef<T>> readObjFile(
|
||||
auto [cached, err] = ctx.assetManager.getAsset<T>(assetId);
|
||||
if (err) {
|
||||
ctx.assetManager.initTypeManager<T>(detail::makeLoader<T>, ctx);
|
||||
oxReturnError(ctx.assetManager.loadAsset<T>(assetId).moveTo(cached));
|
||||
OX_RETURN_ERROR(ctx.assetManager.loadAsset<T>(assetId).moveTo(cached));
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
@ -110,7 +110,7 @@ ox::Result<keel::AssetRef<T>> readObjNoCache(
|
||||
keel::Context &ctx,
|
||||
ox::StringViewCR assetId) noexcept {
|
||||
if constexpr(ox::preloadable<T>::value) {
|
||||
oxRequire(addr, getPreloadAddr(ctx, assetId));
|
||||
OX_REQUIRE(addr, getPreloadAddr(ctx, assetId));
|
||||
return keel::AssetRef<T>(std::bit_cast<T const*>(uintptr_t{addr}));
|
||||
} else {
|
||||
return ox::Error(1);
|
||||
@ -139,11 +139,11 @@ ox::Result<keel::AssetRef<T>> readObj(
|
||||
ox::FileAddress const&file,
|
||||
[[maybe_unused]] bool forceLoad = false) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
oxRequire(assetId, file.getPath());
|
||||
OX_REQUIRE(assetId, file.getPath());
|
||||
return readObj<T>(ctx, ox::StringView(assetId), forceLoad);
|
||||
#else
|
||||
if constexpr(ox::preloadable<T>::value) {
|
||||
oxRequire(addr, getPreloadAddr(ctx, file));
|
||||
OX_REQUIRE(addr, getPreloadAddr(ctx, file));
|
||||
return keel::AssetRef<T>(std::bit_cast<T const*>(uintptr_t{addr}));
|
||||
} else {
|
||||
return ox::Error(1);
|
||||
@ -157,7 +157,7 @@ ox::Error writeObj(
|
||||
ox::FileAddress const&file,
|
||||
T const&obj,
|
||||
ox::ClawFormat fmt = ox::ClawFormat::Metal) noexcept {
|
||||
oxRequire(objBuff, ox::writeClaw(obj, fmt));
|
||||
OX_REQUIRE(objBuff, ox::writeClaw(obj, fmt));
|
||||
return ctx.rom->write(file, objBuff.data(), objBuff.size());
|
||||
}
|
||||
|
||||
|
@ -20,11 +20,11 @@ struct ManifestEntry {
|
||||
ox::String type;
|
||||
};
|
||||
|
||||
oxModelBegin(ManifestEntry)
|
||||
oxModelField(inode)
|
||||
oxModelField(preloaded)
|
||||
oxModelField(type)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(ManifestEntry)
|
||||
OX_MODEL_FIELD(inode)
|
||||
OX_MODEL_FIELD(preloaded)
|
||||
OX_MODEL_FIELD(type)
|
||||
OX_MODEL_END()
|
||||
|
||||
struct Manifest {
|
||||
static constexpr auto TypeName = "net.drinkingtea.keel.Manifest";
|
||||
@ -32,9 +32,9 @@ struct Manifest {
|
||||
ox::HashMap<ox::String, ManifestEntry> files;
|
||||
};
|
||||
|
||||
oxModelBegin(Manifest)
|
||||
oxModelField(files)
|
||||
oxModelEnd()
|
||||
OX_MODEL_BEGIN(Manifest)
|
||||
OX_MODEL_FIELD(files)
|
||||
OX_MODEL_END()
|
||||
|
||||
|
||||
class Context;
|
||||
@ -113,24 +113,24 @@ ox::Error preloadObj(
|
||||
ox::Preloader<PlatSpec> &pl,
|
||||
ox::StringView const path) noexcept {
|
||||
// load file
|
||||
oxRequireM(buff, romFs.read(path));
|
||||
oxRequireM(obj, keel::readAsset(ts, buff));
|
||||
OX_REQUIRE_M(buff, romFs.read(path));
|
||||
OX_REQUIRE_M(obj, keel::readAsset(ts, buff));
|
||||
if (obj.type()->preloadable) {
|
||||
// preload
|
||||
auto const size = ox::sizeOf<GbaPlatSpec>(&obj);
|
||||
auto const alignment = ox::alignOf<GbaPlatSpec>(obj);
|
||||
oxRequire(a, pl.startAlloc(size, alignment));
|
||||
OX_REQUIRE(a, pl.startAlloc(size, alignment));
|
||||
auto const err = ox::preload<GbaPlatSpec, ox::ModelObject>(&pl, &obj);
|
||||
oxReturnError(pl.endAlloc());
|
||||
oxReturnError(err);
|
||||
OX_RETURN_ERROR(pl.endAlloc());
|
||||
OX_RETURN_ERROR(err);
|
||||
keel::PreloadPtr const p{.preloadAddr = a};
|
||||
oxReturnError(ox::writeMC(p).moveTo(buff));
|
||||
OX_RETURN_ERROR(ox::writeMC(p).moveTo(buff));
|
||||
oxOutf("preloaded {} as a {} @ {} to {}\n", path, obj.type()->typeName, a, a + size);
|
||||
} else {
|
||||
// strip the Claw header (it is not needed after preloading) and write back out to dest fs
|
||||
oxReturnError(ox::writeMC(obj).moveTo(buff));
|
||||
OX_RETURN_ERROR(ox::writeMC(obj).moveTo(buff));
|
||||
}
|
||||
oxReturnError(romFs.write(path, buff.data(), buff.size()));
|
||||
OX_RETURN_ERROR(romFs.write(path, buff.data(), buff.size()));
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -145,13 +145,13 @@ ox::Error preloadDir(
|
||||
ox::StringViewCR path) noexcept {
|
||||
// copy
|
||||
oxTracef("pack.preload", "path: {}", path);
|
||||
oxRequire(fileList, romFs.ls(path));
|
||||
OX_REQUIRE(fileList, romFs.ls(path));
|
||||
for (auto const&name : fileList) {
|
||||
auto const filePath = ox::sfmt("{}{}", path, name);
|
||||
oxRequire(stat, romFs.stat(filePath));
|
||||
OX_REQUIRE(stat, romFs.stat(filePath));
|
||||
if (stat.fileType == ox::FileType::Directory) {
|
||||
auto const dir = ox::sfmt("{}{}/", path, name);
|
||||
oxReturnError(preloadDir(manifest, ts, romFs, pl, dir));
|
||||
OX_RETURN_ERROR(preloadDir(manifest, ts, romFs, pl, dir));
|
||||
} else {
|
||||
auto const err = preloadObj(ts, romFs, pl, filePath);
|
||||
if (err) {
|
||||
@ -177,14 +177,14 @@ ox::Error appendBinary(ox::Buffer &binBuff, ox::SpanView<char> const&fsBuff, ox:
|
||||
static_assert(mediaHdr.bytes() == hdrSize);
|
||||
static_assert(preloadHdr.bytes() == hdrSize);
|
||||
ox::BufferWriter w(&binBuff);
|
||||
oxReturnError(padbin(w, hdrSize));
|
||||
oxReturnError(w.write(mediaHdr.data(), mediaHdr.bytes()));
|
||||
oxReturnError(w.write(fsBuff.data(), fsBuff.size()));
|
||||
oxReturnError(padbin(w, hdrSize));
|
||||
oxReturnError(w.write(preloadHdr.data(), preloadHdr.bytes()));
|
||||
oxReturnError(pl.offsetPtrs(binBuff.size()));
|
||||
OX_RETURN_ERROR(padbin(w, hdrSize));
|
||||
OX_RETURN_ERROR(w.write(mediaHdr.data(), mediaHdr.bytes()));
|
||||
OX_RETURN_ERROR(w.write(fsBuff.data(), fsBuff.size()));
|
||||
OX_RETURN_ERROR(padbin(w, hdrSize));
|
||||
OX_RETURN_ERROR(w.write(preloadHdr.data(), preloadHdr.bytes()));
|
||||
OX_RETURN_ERROR(pl.offsetPtrs(binBuff.size()));
|
||||
auto const&plBuff = pl.buff();
|
||||
oxReturnError(w.write(plBuff.data(), plBuff.size()));
|
||||
OX_RETURN_ERROR(w.write(plBuff.data(), plBuff.size()));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -110,15 +110,15 @@ class Converter: public BaseConverter {
|
||||
ox::Result<ox::UPtr<Wrap>> convertPtrToPtr(
|
||||
keel::Context &ctx, Wrap &src) const noexcept final {
|
||||
auto dst = makeWrap<DstType>();
|
||||
oxReturnError(convert(ctx, wrapCast<SrcType>(src), wrapCast<DstType>(*dst)));
|
||||
OX_RETURN_ERROR(convert(ctx, wrapCast<SrcType>(src), wrapCast<DstType>(*dst)));
|
||||
return {std::move(dst)};
|
||||
}
|
||||
|
||||
ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
|
||||
keel::Context &ctx, ox::BufferView const&srcBuff) const noexcept final {
|
||||
oxRequireM(src, readAsset<SrcType>(srcBuff));
|
||||
OX_REQUIRE_M(src, readAsset<SrcType>(srcBuff));
|
||||
auto dst = makeWrap<DstType>();
|
||||
oxReturnError(convert(ctx, src, wrapCast<DstType>(*dst)));
|
||||
OX_RETURN_ERROR(convert(ctx, src, wrapCast<DstType>(*dst)));
|
||||
return {std::move(dst)};
|
||||
}
|
||||
|
||||
@ -137,7 +137,7 @@ template<typename DstType>
|
||||
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));
|
||||
OX_REQUIRE(out, convert(ctx, srcBuffer, DstTypeName, DstTypeVersion));
|
||||
return std::move(wrapCast<DstType>(out));
|
||||
}
|
||||
|
||||
@ -145,7 +145,7 @@ template<typename DstType>
|
||||
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));
|
||||
OX_REQUIRE(outPtr, convert(ctx, buff, DstTypeName, DstTypeVersion));
|
||||
*outObj = std::move(wrapCast<DstType>(*outPtr));
|
||||
return {};
|
||||
}
|
||||
@ -155,14 +155,14 @@ ox::Result<ox::Buffer> convertBuffToBuff(
|
||||
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));
|
||||
OX_REQUIRE(out, convert(ctx, srcBuffer, DstTypeName, DstTypeVersion));
|
||||
return ox::writeClaw<DstType>(wrapCast<DstType>(*out), fmt);
|
||||
}
|
||||
|
||||
template<typename From, typename To, ox::ClawFormat fmt = ox::ClawFormat::Metal>
|
||||
ox::Result<bool> transformRule(keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) noexcept {
|
||||
if (typeId == ox::ModelTypeId_v<From>) {
|
||||
oxReturnError(keel::convertBuffToBuff<To>(ctx, buff, fmt).moveTo(buff));
|
||||
OX_RETURN_ERROR(keel::convertBuffToBuff<To>(ctx, buff, fmt).moveTo(buff));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -43,7 +43,7 @@ ox::Result<AssetHdr> readAssetHeader(ox::BufferView buff) noexcept {
|
||||
return ox::Error(1, "Buffer too small for expected data");
|
||||
}
|
||||
buff += offset;
|
||||
oxReturnError(ox::readClawHeader(buff).moveTo(out.value.clawHdr));
|
||||
OX_RETURN_ERROR(ox::readClawHeader(buff).moveTo(out.value.clawHdr));
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ ox::Error init(
|
||||
|
||||
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));
|
||||
OX_RETURN_ERROR(keel::init(*ctx, std::move(fs), appName));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
@ -48,19 +48,19 @@ void createUuidMapping(Context &ctx, ox::StringView filePath, ox::UUID const&uui
|
||||
}
|
||||
|
||||
static ox::Error buildUuidMap(Context &ctx, ox::StringViewCR path) noexcept {
|
||||
oxRequire(files, ctx.rom->ls(path));
|
||||
OX_REQUIRE(files, ctx.rom->ls(path));
|
||||
for (auto const&f : files) {
|
||||
oxRequireM(filePath, ox::join("/", ox::Array<ox::StringView, 2>{path, f}));
|
||||
oxRequire(stat, ctx.rom->stat(filePath));
|
||||
OX_REQUIRE_M(filePath, ox::join("/", ox::Array<ox::StringView, 2>{path, f}));
|
||||
OX_REQUIRE(stat, ctx.rom->stat(filePath));
|
||||
if (stat.fileType == ox::FileType::NormalFile) {
|
||||
oxRequire(data, ctx.rom->read(filePath));
|
||||
OX_REQUIRE(data, ctx.rom->read(filePath));
|
||||
auto const [hdr, err] = readAssetHeader(data);
|
||||
if (!err) {
|
||||
createUuidMapping(ctx, filePath, hdr.uuid);
|
||||
}
|
||||
} else if (stat.fileType == ox::FileType::Directory) {
|
||||
if (!beginsWith(f, ".")) {
|
||||
oxReturnError(buildUuidMap(ctx, filePath));
|
||||
OX_RETURN_ERROR(buildUuidMap(ctx, filePath));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -76,7 +76,7 @@ ox::Error buildUuidMap(Context &ctx) noexcept {
|
||||
|
||||
ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::StringViewCR path) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
oxRequire(out, ctx.pathToUuid.at(path));
|
||||
OX_REQUIRE(out, ctx.pathToUuid.at(path));
|
||||
return *out;
|
||||
#else
|
||||
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
||||
@ -84,7 +84,7 @@ ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::StringViewCR path) noexcept {
|
||||
}
|
||||
|
||||
ox::Result<ox::UUID> getUuid(Context &ctx, ox::FileAddress const&fileAddr) noexcept {
|
||||
oxRequire(path, fileAddr.getPath());
|
||||
OX_REQUIRE(path, fileAddr.getPath());
|
||||
return getUuid(ctx, path);
|
||||
}
|
||||
|
||||
@ -98,11 +98,11 @@ ox::Result<ox::UUID> getUuid(Context &ctx, ox::StringView path) noexcept {
|
||||
}
|
||||
|
||||
ox::Result<ox::CStringView> getPath(Context &ctx, ox::FileAddress const&fileAddr) noexcept {
|
||||
oxRequire(path, fileAddr.getPath());
|
||||
OX_REQUIRE(path, fileAddr.getPath());
|
||||
if (beginsWith(path, "uuid://")) {
|
||||
auto const uuid = substr(path, 7);
|
||||
#ifndef OX_BARE_METAL
|
||||
oxRequireM(out, ctx.uuidToPath.at(uuid));
|
||||
OX_REQUIRE_M(out, ctx.uuidToPath.at(uuid));
|
||||
return ox::CStringView{*out};
|
||||
#else
|
||||
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
||||
@ -116,7 +116,7 @@ ox::Result<ox::CStringView> getPath(Context &ctx, ox::CStringView fileId) noexce
|
||||
if (beginsWith(fileId, "uuid://")) {
|
||||
auto const uuid = substr(fileId, 7);
|
||||
#ifndef OX_BARE_METAL
|
||||
oxRequireM(out, ctx.uuidToPath.at(uuid));
|
||||
OX_REQUIRE_M(out, ctx.uuidToPath.at(uuid));
|
||||
return ox::CStringView{*out};
|
||||
#else
|
||||
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
||||
@ -129,7 +129,7 @@ ox::Result<ox::CStringView> getPath(Context &ctx, ox::CStringView fileId) noexce
|
||||
ox::Result<ox::CStringView> uuidUrlToPath(Context &ctx, ox::StringView uuid) noexcept {
|
||||
uuid = substr(uuid, 7);
|
||||
#ifndef OX_BARE_METAL
|
||||
oxRequireM(out, ctx.uuidToPath.at(uuid));
|
||||
OX_REQUIRE_M(out, ctx.uuidToPath.at(uuid));
|
||||
return ox::CStringView(*out);
|
||||
#else
|
||||
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
||||
@ -138,7 +138,7 @@ ox::Result<ox::CStringView> uuidUrlToPath(Context &ctx, ox::StringView uuid) noe
|
||||
|
||||
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::StringViewCR uuid) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
oxRequireM(out, ctx.uuidToPath.at(uuid));
|
||||
OX_REQUIRE_M(out, ctx.uuidToPath.at(uuid));
|
||||
return ox::CStringView(*out);
|
||||
#else
|
||||
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
||||
@ -147,7 +147,7 @@ ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::StringViewCR uuid) noex
|
||||
|
||||
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::UUID const&uuid) noexcept {
|
||||
#ifndef OX_BARE_METAL
|
||||
oxRequireM(out, ctx.uuidToPath.at(uuid.toString()));
|
||||
OX_REQUIRE_M(out, ctx.uuidToPath.at(uuid.toString()));
|
||||
return ox::CStringView(*out);
|
||||
#else
|
||||
return ox::Error(1, "UUID to path conversion not supported on this platform");
|
||||
@ -158,7 +158,7 @@ ox::Error reloadAsset(keel::Context &ctx, ox::StringView assetId) noexcept {
|
||||
ox::UUIDStr uuidStr;
|
||||
if (beginsWith(assetId, "uuid://")) {
|
||||
assetId = substr(assetId, 7);
|
||||
oxRequire(p, keel::uuidToPath(ctx, assetId));
|
||||
OX_REQUIRE(p, keel::uuidToPath(ctx, assetId));
|
||||
} else {
|
||||
auto const [uuid, uuidErr] = getUuid(ctx, assetId);
|
||||
if (!uuidErr) {
|
||||
@ -207,18 +207,18 @@ void unloadRom(char*) 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).directAccess(path));
|
||||
OX_REQUIRE(stat, ctx.rom->stat(path));
|
||||
OX_REQUIRE(buff, static_cast<ox::MemFS&>(*ctx.rom).directAccess(path));
|
||||
PreloadPtr p;
|
||||
oxReturnError(ox::readMC({buff, static_cast<std::size_t>(stat.size)}, p));
|
||||
OX_RETURN_ERROR(ox::readMC({buff, static_cast<std::size_t>(stat.size)}, p));
|
||||
return static_cast<std::size_t>(p.preloadAddr) + ctx.preloadSectionOffset;
|
||||
}
|
||||
|
||||
ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::FileAddress const&addr) noexcept {
|
||||
oxRequire(stat, ctx.rom->stat(addr));
|
||||
oxRequire(buff, static_cast<ox::MemFS&>(*ctx.rom).directAccess(addr));
|
||||
OX_REQUIRE(stat, ctx.rom->stat(addr));
|
||||
OX_REQUIRE(buff, static_cast<ox::MemFS&>(*ctx.rom).directAccess(addr));
|
||||
PreloadPtr p;
|
||||
oxReturnError(ox::readMC({buff, static_cast<std::size_t>(stat.size)}, p));
|
||||
OX_RETURN_ERROR(ox::readMC({buff, static_cast<std::size_t>(stat.size)}, p));
|
||||
return static_cast<std::size_t>(p.preloadAddr) + ctx.preloadSectionOffset;
|
||||
}
|
||||
|
||||
@ -241,7 +241,7 @@ ox::Error setRomFs(Context &ctx, ox::UPtr<ox::FileSystem> &&fs) 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));
|
||||
OX_REQUIRE(rom, loadRom(path));
|
||||
return {ox::make_unique<ox::FileSystem32>(rom, 32 * ox::units::MB, unloadRom)};
|
||||
} else {
|
||||
#ifdef OX_HAS_PASSTHROUGHFS
|
||||
|
@ -43,7 +43,7 @@ static ox::Result<ox::Buffer> readFileBuff(ox::StringView path) noexcept {
|
||||
static ox::Error generateTypes(ox::TypeStore &ts) noexcept {
|
||||
for (auto const mod : keel::modules()) {
|
||||
for (auto gen : mod->types()) {
|
||||
oxReturnError(gen(ts));
|
||||
OX_RETURN_ERROR(gen(ts));
|
||||
}
|
||||
}
|
||||
return {};
|
||||
@ -55,29 +55,29 @@ static ox::Error pack(
|
||||
ox::StringView argManifest,
|
||||
ox::StringView projectDataDir) noexcept {
|
||||
ox::Buffer dstBuff(32 * ox::units::MB);
|
||||
oxReturnError(ox::FileSystem32::format(dstBuff.data(), dstBuff.size()));
|
||||
OX_RETURN_ERROR(ox::FileSystem32::format(dstBuff.data(), dstBuff.size()));
|
||||
ox::FileSystem32 dst(dstBuff);
|
||||
oxRequire(ctx, keel::init(ox::make_unique<ox::PassThroughFS>(argSrc), "keel-pack"));
|
||||
OX_REQUIRE(ctx, keel::init(ox::make_unique<ox::PassThroughFS>(argSrc), "keel-pack"));
|
||||
keel::TypeStore ts(*ctx->rom, ox::sfmt("{}/type_descriptors", projectDataDir));
|
||||
oxReturnError(generateTypes(ts));
|
||||
OX_RETURN_ERROR(generateTypes(ts));
|
||||
keel::Manifest manifest;
|
||||
oxReturnError(keel::pack(manifest, *ctx, ts, dst));
|
||||
oxRequireM(pl, keel::GbaPreloader::make());
|
||||
oxReturnError(preload(manifest, ts, dst, *pl));
|
||||
oxReturnError(dst.resize());
|
||||
OX_RETURN_ERROR(keel::pack(manifest, *ctx, ts, dst));
|
||||
OX_REQUIRE_M(pl, keel::GbaPreloader::make());
|
||||
OX_RETURN_ERROR(preload(manifest, ts, dst, *pl));
|
||||
OX_RETURN_ERROR(dst.resize());
|
||||
// resize buffer
|
||||
oxRequire(dstSize, dst.size());
|
||||
OX_REQUIRE(dstSize, dst.size());
|
||||
dstBuff.resize(dstSize);
|
||||
// concatenate ROM segments
|
||||
oxRequireM(romBuff, readFileBuff(argRomBin));
|
||||
OX_REQUIRE_M(romBuff, readFileBuff(argRomBin));
|
||||
oxOutf("Input exe size: {} bytes\n", romBuff.size());
|
||||
oxOutf("Dest FS size: {} bytes\n", dstSize);
|
||||
oxOutf("Preload buff size: {} bytes\n", pl->buff().size());
|
||||
oxReturnError(appendBinary(romBuff, dstBuff, *pl));
|
||||
OX_RETURN_ERROR(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()}));
|
||||
OX_RETURN_ERROR(writeFileBuff(argRomBin, romBuff));
|
||||
OX_REQUIRE(manifestJson, ox::writeOCString(manifest));
|
||||
OX_RETURN_ERROR(writeFileBuff(argManifest, {manifestJson.data(), manifestJson.len()}));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -15,19 +15,19 @@ static ox::Error pathToInode(
|
||||
ox::FileSystem &dest,
|
||||
ox::ModelObject &obj) noexcept {
|
||||
auto &o = obj;
|
||||
oxRequire(typeVal, o.at("type"));
|
||||
OX_REQUIRE(typeVal, o.at("type"));
|
||||
auto const type = static_cast<ox::FileAddressType>(typeVal->get<int8_t>());
|
||||
oxRequire(dataVal, o.at("data"));
|
||||
OX_REQUIRE(dataVal, o.at("data"));
|
||||
auto &data = dataVal->get<ox::ModelUnion>();
|
||||
ox::String path;
|
||||
switch (type) {
|
||||
case ox::FileAddressType::Path: {
|
||||
oxRequire(pathVal, data.at("path"));
|
||||
OX_REQUIRE(pathVal, data.at("path"));
|
||||
path = pathVal->get<ox::String>();
|
||||
break;
|
||||
}
|
||||
case ox::FileAddressType::ConstPath: {
|
||||
oxRequire(pathVal, data.at("constPath"));
|
||||
OX_REQUIRE(pathVal, data.at("constPath"));
|
||||
path = pathVal->get<ox::String>();
|
||||
break;
|
||||
}
|
||||
@ -37,10 +37,10 @@ static ox::Error pathToInode(
|
||||
}
|
||||
if (beginsWith(path, "uuid://")) {
|
||||
auto const uuid = ox::substr(path, 7);
|
||||
oxReturnError(keel::uuidToPath(ctx, uuid).to<ox::String>().moveTo(path));
|
||||
OX_RETURN_ERROR(keel::uuidToPath(ctx, uuid).to<ox::String>().moveTo(path));
|
||||
}
|
||||
oxRequire(s, dest.stat(path));
|
||||
oxReturnError(typeVal->set(static_cast<int8_t>(ox::FileAddressType::Inode)));
|
||||
OX_REQUIRE(s, dest.stat(path));
|
||||
OX_RETURN_ERROR(typeVal->set(static_cast<int8_t>(ox::FileAddressType::Inode)));
|
||||
oxOutf("\tpath to inode: {} => {}\n", path, s.inode);
|
||||
return data.set(2, s.inode);
|
||||
}
|
||||
@ -69,7 +69,7 @@ static ox::Error transformFileAddressesVec(
|
||||
ox::FileSystem &dest,
|
||||
ox::ModelValueVector &v) noexcept {
|
||||
for (auto &f : v) {
|
||||
oxReturnError(transformFileAddresses(ctx, dest, f));
|
||||
OX_RETURN_ERROR(transformFileAddresses(ctx, dest, f));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@ -87,7 +87,7 @@ static ox::Error transformFileAddressesObj(
|
||||
}
|
||||
for (auto &f : obj) {
|
||||
auto &v = f->value;
|
||||
oxReturnError(transformFileAddresses(ctx, dest, v));
|
||||
OX_RETURN_ERROR(transformFileAddresses(ctx, dest, v));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@ -96,12 +96,12 @@ static ox::Error performPackTransforms(
|
||||
ManifestEntry &entry,
|
||||
Context &ctx,
|
||||
ox::Buffer &clawData) noexcept {
|
||||
oxRequireM(typeId, readAssetTypeId(clawData));
|
||||
OX_REQUIRE_M(typeId, readAssetTypeId(clawData));
|
||||
for (auto const tr : packTransforms(ctx)) {
|
||||
bool changed{};
|
||||
oxReturnError(tr(ctx, clawData, typeId).moveTo(changed));
|
||||
OX_RETURN_ERROR(tr(ctx, clawData, typeId).moveTo(changed));
|
||||
if (changed) {
|
||||
oxReturnError(readAssetTypeId(clawData).moveTo(typeId));
|
||||
OX_RETURN_ERROR(readAssetTypeId(clawData).moveTo(typeId));
|
||||
}
|
||||
}
|
||||
entry.type = ox::String{typeId};
|
||||
@ -115,17 +115,17 @@ static ox::Error doTransformations(
|
||||
ox::FileSystem &dest,
|
||||
ox::StringViewCR filePath) noexcept {
|
||||
// load file
|
||||
oxRequire(s, dest.stat(filePath));
|
||||
OX_REQUIRE(s, dest.stat(filePath));
|
||||
// do transformations
|
||||
oxRequireM(buff, dest.read(s.inode));
|
||||
oxReturnError(keel::performPackTransforms(manifest.files[filePath], ctx, buff));
|
||||
OX_REQUIRE_M(buff, dest.read(s.inode));
|
||||
OX_RETURN_ERROR(keel::performPackTransforms(manifest.files[filePath], ctx, buff));
|
||||
// transform FileAddresses
|
||||
oxRequireM(obj, keel::readAsset(ts, buff));
|
||||
OX_REQUIRE_M(obj, keel::readAsset(ts, buff));
|
||||
oxOutf("transforming {}\n", filePath);
|
||||
oxReturnError(transformFileAddressesObj(ctx, dest, obj));
|
||||
oxReturnError(ox::writeClaw(obj).moveTo(buff));
|
||||
OX_RETURN_ERROR(transformFileAddressesObj(ctx, dest, obj));
|
||||
OX_RETURN_ERROR(ox::writeClaw(obj).moveTo(buff));
|
||||
// write file to dest
|
||||
oxReturnError(dest.write(s.inode, buff));
|
||||
OX_RETURN_ERROR(dest.write(s.inode, buff));
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -139,13 +139,13 @@ static ox::Error transformClaw(
|
||||
ox::StringViewCR path) noexcept {
|
||||
// copy
|
||||
oxTracef("pack.transformClaw", "path: {}", path);
|
||||
oxRequire(fileList, dest.ls(path));
|
||||
OX_REQUIRE(fileList, dest.ls(path));
|
||||
for (auto const&name : fileList) {
|
||||
auto const filePath = ox::sfmt("{}{}", path, name);
|
||||
oxRequire(stat, dest.stat(filePath));
|
||||
OX_REQUIRE(stat, dest.stat(filePath));
|
||||
if (stat.fileType == ox::FileType::Directory) {
|
||||
auto const dir = ox::sfmt("{}{}/", path, name);
|
||||
oxReturnError(transformClaw(manifest, ctx, ts, dest, dir));
|
||||
OX_RETURN_ERROR(transformClaw(manifest, ctx, ts, dest, dir));
|
||||
} else {
|
||||
auto const err = doTransformations(manifest, ctx, ts, dest, filePath);
|
||||
if (err) {
|
||||
@ -166,28 +166,28 @@ static ox::Error copy(
|
||||
oxOutf("{}copying directory: {}\n", logPrefix, path);
|
||||
auto const childLogPrefix = ox::sfmt("{}\t", logPrefix);
|
||||
// copy
|
||||
oxRequire(fileList, src.ls(path));
|
||||
OX_REQUIRE(fileList, src.ls(path));
|
||||
for (auto const&name : fileList) {
|
||||
auto const currentFile = ox::sfmt("{}{}", path, name);
|
||||
if (beginsWith(name, ".")) {
|
||||
continue;
|
||||
}
|
||||
oxRequire(srcStat, src.stat(currentFile));
|
||||
OX_REQUIRE(srcStat, src.stat(currentFile));
|
||||
if (srcStat.fileType == ox::FileType::Directory) {
|
||||
oxReturnError(dest.mkdir(currentFile, true));
|
||||
oxReturnError(copy(manifest, src, dest, currentFile + '/', childLogPrefix));
|
||||
OX_RETURN_ERROR(dest.mkdir(currentFile, true));
|
||||
OX_RETURN_ERROR(copy(manifest, src, dest, currentFile + '/', childLogPrefix));
|
||||
} else {
|
||||
// load file
|
||||
oxOutf("{}copying file: {}...", childLogPrefix, currentFile);
|
||||
ox::StringView status = "failed";
|
||||
oxDefer [&status] {
|
||||
OX_DEFER [&status] {
|
||||
oxOutf(" {}\n", status);
|
||||
};
|
||||
oxRequireM(buff, src.read(currentFile));
|
||||
OX_REQUIRE_M(buff, src.read(currentFile));
|
||||
// write file to dest
|
||||
oxReturnError(dest.write(currentFile, buff));
|
||||
OX_RETURN_ERROR(dest.write(currentFile, buff));
|
||||
status = "OK";
|
||||
oxRequire(dstStat, dest.stat(currentFile));
|
||||
OX_REQUIRE(dstStat, dest.stat(currentFile));
|
||||
manifest.files[currentFile] = {
|
||||
.inode = dstStat.inode,
|
||||
.type = ox::String{keel::readAssetTypeId(buff).or_value({})},
|
||||
@ -202,9 +202,9 @@ ox::Error pack(
|
||||
keel::Context &ctx,
|
||||
ox::TypeStore &ts,
|
||||
ox::FileSystem &dest) noexcept {
|
||||
oxReturnError(copy(manifest, *ctx.rom, dest, "/"));
|
||||
OX_RETURN_ERROR(copy(manifest, *ctx.rom, dest, "/"));
|
||||
oxOut("Doing transforms\n");
|
||||
oxReturnError(transformClaw(manifest, ctx, ts, dest, "/"));
|
||||
OX_RETURN_ERROR(transformClaw(manifest, ctx, ts, dest, "/"));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ ox::Result<ox::UPtr<Wrap>> convert(
|
||||
ox::BufferView const&srcBuffer,
|
||||
ox::StringViewCR dstTypeName,
|
||||
int dstTypeVersion) noexcept {
|
||||
oxRequire(hdr, readAssetHeader(srcBuffer));
|
||||
OX_REQUIRE(hdr, readAssetHeader(srcBuffer));
|
||||
return convert(
|
||||
ctx,
|
||||
converters(ctx),
|
||||
|
@ -13,9 +13,9 @@ TypeStore::TypeStore(ox::FileSystem &fs, ox::StringView descPath) noexcept:
|
||||
|
||||
ox::Result<ox::UPtr<ox::DescriptorType>> TypeStore::loadDescriptor(ox::StringView const typeId) noexcept {
|
||||
auto const path = ox::sfmt("{}/{}", m_descPath, typeId);
|
||||
oxRequire(buff, m_fs.read(path));
|
||||
OX_REQUIRE(buff, m_fs.read(path));
|
||||
auto dt = ox::make_unique<ox::DescriptorType>();
|
||||
oxReturnError(ox::readClaw<ox::DescriptorType>(buff, *dt));
|
||||
OX_RETURN_ERROR(ox::readClaw<ox::DescriptorType>(buff, *dt));
|
||||
return dt;
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,10 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
|
||||
[]() -> ox::Error {
|
||||
constexpr ox::StringView uuidStr = "8d814442-f46e-4cc3-8edc-ca3c01cc86db";
|
||||
constexpr ox::StringView hdr = "K1;8d814442-f46e-4cc3-8edc-ca3c01cc86db;";
|
||||
oxRequire(uuid, ox::UUID::fromString(uuidStr));
|
||||
OX_REQUIRE(uuid, ox::UUID::fromString(uuidStr));
|
||||
ox::Array<char, hdr.len()> buff;
|
||||
ox::CharBuffWriter bw(buff);
|
||||
oxReturnError(keel::writeUuidHeader(bw, uuid));
|
||||
OX_RETURN_ERROR(keel::writeUuidHeader(bw, uuid));
|
||||
oxExpect(ox::StringView(buff.data(), buff.size()), hdr);
|
||||
return {};
|
||||
}
|
||||
|
Reference in New Issue
Block a user