[olympic,nostalgia] Cleanup
All checks were successful
Build / build (push) Successful in 2m31s

This commit is contained in:
Gary Talent 2024-05-08 23:35:34 -05:00
parent 63486c23d4
commit 331f721292
12 changed files with 116 additions and 105 deletions

View File

@ -196,7 +196,7 @@ static ox::Error loadTileSheetSet(
.targetBpp = static_cast<unsigned>(set.bpp),
.setEntry = &entry,
};
oxReturnError(ox::readMC(ts, static_cast<std::size_t>(tsStat.size), &target));
oxReturnError(ox::readMC({ts, static_cast<std::size_t>(tsStat.size)}, target));
tileWriteIdx += target.tileWriteIdx;
}
return {};
@ -215,7 +215,7 @@ ox::Error loadBgTileSheet(
.defaultPalette = {},
.tileMap = MEM_BG_TILES[cbb].data(),
};
oxReturnError(ox::readMC(ts, static_cast<std::size_t>(tsStat.size), &target));
oxReturnError(ox::readMC({ts, static_cast<std::size_t>(tsStat.size)}, target));
// update bpp of all bgs with the updated cbb
const auto bpp = ctx.cbbData[cbb].bpp;
teagba::iterateBgCtl([bpp, cbb](volatile BgCtl &bgCtl) {
@ -267,7 +267,7 @@ ox::Error loadSpriteTileSheet(
.defaultPalette = {},
.tileMap = MEM_SPRITE_TILES,
};
oxReturnError(ox::readMC(ts, static_cast<std::size_t>(tsStat.size), &target));
oxReturnError(ox::readMC({ts, static_cast<std::size_t>(tsStat.size)}, target));
if (loadDefaultPalette && target.defaultPalette) {
oxReturnError(loadSpritePalette(ctx, target.defaultPalette));
}

View File

@ -58,27 +58,21 @@ static class: public keel::Module {
ox::Vector<keel::PackTransform> packTransforms() const noexcept final {
return {
// convert tilesheets to CompactTileSheets
[](keel::Context &ctx, ox::Buffer &buff) -> ox::Error {
oxRequire(hdr, keel::readAssetHeader(buff));
auto const typeId = ox::buildTypeId(
hdr.clawHdr.typeName, hdr.clawHdr.typeVersion, hdr.clawHdr.typeParams);
[](keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) -> ox::Error {
if (typeId == ox::ModelTypeId_v<TileSheetV1> ||
typeId == ox::ModelTypeId_v<TileSheetV2> ||
typeId == ox::ModelTypeId_v<TileSheetV3> ||
typeId == ox::ModelTypeId_v<TileSheetV4>) {
oxReturnError(keel::convertBuffToBuff<CompactTileSheet>(
ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
return keel::convertBuffToBuff<CompactTileSheet>(
ctx, buff, ox::ClawFormat::Metal).moveTo(buff);
}
return {};
},
[](keel::Context &ctx, ox::Buffer &buff) -> ox::Error {
oxRequire(hdr, keel::readAssetHeader(buff));
auto const typeId = ox::buildTypeId(
hdr.clawHdr.typeName, hdr.clawHdr.typeVersion, hdr.clawHdr.typeParams);
[](keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) -> ox::Error {
if (typeId == ox::ModelTypeId_v<NostalgiaPalette> ||
typeId == ox::ModelTypeId_v<PaletteV1>) {
oxReturnError(keel::convertBuffToBuff<Palette>(
ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
return keel::convertBuffToBuff<Palette>(
ctx, buff, ox::ClawFormat::Metal).moveTo(buff);
}
return {};
},

View File

@ -11,9 +11,7 @@ namespace keel {
constexpr auto K1HdrSz = 40;
ox::Result<ox::UUID> readUuidHeader(ox::Buffer const&buff) noexcept;
ox::Result<ox::UUID> readUuidHeader(const char *buff, std::size_t buffLen) noexcept;
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;"));
@ -22,24 +20,24 @@ ox::Error writeUuidHeader(ox::Writer_c auto &writer, ox::UUID const&uuid) noexce
}
template<typename T>
ox::Result<T> readAsset(ox::Buffer const&buff) noexcept {
ox::Result<T> readAsset(ox::BufferView buff) noexcept {
std::size_t offset = 0;
const auto err = readUuidHeader(buff).error;
if (!err) {
offset = K1HdrSz; // the size of K1 headers
}
return ox::readClaw<T>(buff.data() + offset, buff.size() - offset);
return ox::readClaw<T>(buff + offset);
}
ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::Buffer const&buff) noexcept;
ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView buff) noexcept;
struct AssetHdr {
ox::UUID uuid;
ox::ClawHeader clawHdr;
};
ox::Result<AssetHdr> readAssetHeader(char const*buff, std::size_t buffLen) noexcept;
ox::Result<ox::StringView> readAssetTypeId(ox::BufferView buff) noexcept;
ox::Result<AssetHdr> readAssetHeader(ox::Buffer const&buff) noexcept;
ox::Result<AssetHdr> readAssetHeader(ox::BufferView buff) noexcept;
}

View File

@ -12,7 +12,7 @@
namespace keel {
class Context;
using PackTransform = ox::Error(*)(Context&, ox::Buffer &clawData);
using PackTransform = ox::Error(*)(Context&, ox::Buffer &clawData, ox::StringView);
class Context {
public:
@ -36,4 +36,22 @@ class Context {
constexpr virtual ~Context() noexcept = default;
};
constexpr ox::SpanView<PackTransform> packTransforms(
[[maybe_unused]] Context const&ctx) noexcept {
#ifndef OX_BARE_METAL
return ctx.packTransforms;
#else
return {};
#endif
}
constexpr ox::SpanView<class BaseConverter const*> converters(
[[maybe_unused]] Context const&ctx) noexcept {
#ifndef OX_BARE_METAL
return ctx.converters;
#else
return {};
#endif
}
}

View File

@ -40,7 +40,7 @@ class WrapInline: public Wrap {
};
template<typename T, typename... Args>
constexpr auto makeWrap(Args &&...args) noexcept {
constexpr ox::UPtr<Wrap> makeWrap(Args &&...args) noexcept {
return ox::make_unique<WrapInline<T>>(ox::forward<Args>(args)...);
}
@ -65,9 +65,10 @@ class BaseConverter {
[[nodiscard]]
virtual bool dstMatches(ox::CRStringView dstTypeName, int dstTypeVersion) const noexcept = 0;
virtual ox::Result<ox::UniquePtr<Wrap>> convertPtrToPtr(keel::Context &ctx, Wrap &src) const noexcept = 0;
virtual ox::Result<ox::UPtr<Wrap>> convertPtrToPtr(keel::Context &ctx, Wrap &src) const noexcept = 0;
virtual ox::Result<ox::UniquePtr<Wrap>> convertBuffToPtr(keel::Context &ctx, ox::Buffer const&srcBuff) const noexcept = 0;
virtual ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
keel::Context &ctx, ox::Buffer const&srcBuff) const noexcept = 0;
[[nodiscard]]
inline bool matches(
@ -84,12 +85,12 @@ class Converter: public BaseConverter {
public:
[[nodiscard]]
ox::StringView srcTypeName() const noexcept final {
return ox::requireModelTypeName<SrcType>();
return ox::ModelTypeName_v<SrcType>;
}
[[nodiscard]]
int srcTypeVersion() const noexcept final {
return ox::requireModelTypeVersion<SrcType>();
return ox::ModelTypeVersion_v<SrcType>;
}
[[nodiscard]]
@ -108,17 +109,19 @@ class Converter: public BaseConverter {
&& dstTypeVersion == DstTypeVersion;
}
ox::Result<ox::UniquePtr<Wrap>> convertPtrToPtr(keel::Context &ctx, Wrap &src) const noexcept final {
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)));
return ox::Result<ox::UniquePtr<Wrap>>(std::move(dst));
return {std::move(dst)};
}
ox::Result<ox::UniquePtr<Wrap>> convertBuffToPtr(keel::Context &ctx, ox::Buffer const&srcBuff) const noexcept final {
ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
keel::Context &ctx, ox::Buffer const&srcBuff) const noexcept final {
oxRequireM(src, readAsset<SrcType>(srcBuff));
auto dst = makeWrap<DstType>();
oxReturnError(convert(ctx, src, wrapCast<DstType>(*dst)));
return ox::Result<ox::UniquePtr<Wrap>>(std::move(dst));
return {std::move(dst)};
}
protected:
@ -126,9 +129,11 @@ class Converter: public BaseConverter {
};
ox::Result<ox::UniquePtr<Wrap>> convert(
keel::Context &ctx, ox::Buffer const&srcBuffer,
ox::CRStringView dstTypeName, int dstTypeVersion) noexcept;
ox::Result<ox::UPtr<Wrap>> convert(
keel::Context &ctx,
ox::Buffer const&srcBuffer,
ox::CRStringView dstTypeName,
int dstTypeVersion) noexcept;
template<typename DstType>
ox::Result<DstType> convert(keel::Context &ctx, ox::Buffer const&srcBuffer) noexcept {
@ -148,7 +153,8 @@ 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 {
ox::Result<ox::Buffer> convertBuffToBuff(
keel::Context &ctx, ox::Buffer 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));
@ -156,10 +162,7 @@ ox::Result<ox::Buffer> convertBuffToBuff(keel::Context &ctx, ox::Buffer const&sr
}
template<typename From, typename To, ox::ClawFormat fmt = ox::ClawFormat::Metal>
auto transformRule(keel::Context &ctx, ox::Buffer &buff) noexcept -> ox::Error {
oxRequire(hdr, readAssetHeader(buff));
const auto typeId = ox::buildTypeId(
hdr.clawHdr.typeName, hdr.clawHdr.typeVersion, hdr.clawHdr.typeParams);
auto transformRule(keel::Context &ctx, ox::Buffer &buff, ox::StringView typeId) noexcept -> ox::Error {
if (typeId == ox::ModelTypeId_v<From>) {
oxReturnError(keel::convertBuffToBuff<To>(ctx, buff, fmt).moveTo(buff));
}

View File

@ -19,7 +19,7 @@ class TypeStore: public ox::TypeStore {
explicit TypeStore(ox::FileSystem &fs, ox::StringView descPath) noexcept;
protected:
ox::Result<ox::UPtr<ox::DescriptorType>> loadDescriptor(ox::CRStringView typeId) noexcept override;
ox::Result<ox::UPtr<ox::DescriptorType>> loadDescriptor(ox::StringView typeId) noexcept override;
};
}

View File

@ -6,41 +6,45 @@
namespace keel {
ox::Result<ox::UUID> readUuidHeader(ox::Buffer const&buff) noexcept {
return readUuidHeader(buff.data(), buff.size());
}
ox::Result<ox::UUID> readUuidHeader(char const*buff, std::size_t buffLen) noexcept {
if (buffLen < K1HdrSz) {
ox::Result<ox::UUID> readUuidHeader(ox::BufferView buff) noexcept {
if (buff.size() < K1HdrSz) [[unlikely]] {
return OxError(1, "Insufficient data to contain complete Keel header");
}
constexpr ox::StringView k1Hdr = "K1;";
if (k1Hdr != ox::StringView(buff, k1Hdr.bytes())) {
if (k1Hdr != ox::StringView(buff.data(), k1Hdr.bytes())) [[unlikely]] {
return OxError(2, "No Keel asset header data");
}
return ox::UUID::fromString(ox::StringView(buff + k1Hdr.bytes(), 36));
return ox::UUID::fromString(ox::StringView(buff.data() + k1Hdr.bytes(), 36));
}
ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::Buffer const&buff) noexcept {
ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView buff) noexcept {
std::size_t offset = 0;
if (!readUuidHeader(buff).error) {
offset = K1HdrSz;
}
return ox::readClaw(ts, buff.data() + offset, buff.size() - offset);
buff += offset;
return ox::readClaw(ts, buff);
}
ox::Result<AssetHdr> readAssetHeader(char const*buff, std::size_t buffLen) noexcept {
AssetHdr out;
const auto err = readUuidHeader(buff, buffLen).moveTo(out.uuid);
ox::Result<ox::StringView> readAssetTypeId(ox::BufferView buff) noexcept {
const auto err = readUuidHeader(buff).error;
const auto offset = err ? 0u : K1HdrSz;
buff = buff + offset;
buffLen = buffLen - offset;
oxReturnError(ox::readClawHeader(buff, buffLen).moveTo(out.clawHdr));
if (offset >= buff.size()) [[unlikely]] {
return OxError(1, "Buffer too small for expected data");
}
return ox::readClawTypeId(buff + offset);
}
ox::Result<AssetHdr> readAssetHeader(ox::BufferView buff) noexcept {
ox::Result<AssetHdr> out;
const auto err = readUuidHeader(buff).moveTo(out.value.uuid);
const auto offset = err ? 0u : K1HdrSz;
if (offset >= buff.size()) [[unlikely]] {
return OxError(1, "Buffer too small for expected data");
}
buff += offset;
oxReturnError(ox::readClawHeader(buff).moveTo(out.value.clawHdr));
return out;
}
ox::Result<AssetHdr> readAssetHeader(ox::Buffer const&buff) noexcept {
return readAssetHeader(buff.data(), buff.size());
}
}

View File

@ -102,14 +102,11 @@ ox::Result<ox::String> uuidToPath(Context &ctx, ox::UUID const&uuid) noexcept {
}
ox::Error performPackTransforms(Context &ctx, ox::Buffer &clawData) noexcept {
#ifndef OX_BARE_METAL
for (auto tr : ctx.packTransforms) {
oxReturnError(tr(ctx, clawData));
oxRequire(typeId, readAssetTypeId(clawData).to<ox::String>());
for (auto const tr : packTransforms(ctx)) {
oxReturnError(tr(ctx, clawData, typeId));
}
return {};
#else
return OxError(1, "Transformations not supported on this platform");
#endif
}
}
@ -153,7 +150,7 @@ ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::CRStringView path
oxRequire(stat, ctx.rom->stat(path));
oxRequire(buff, static_cast<ox::MemFS*>(ctx.rom.get())->directAccess(path));
PreloadPtr p;
oxReturnError(ox::readMC(buff, static_cast<std::size_t>(stat.size), &p));
oxReturnError(ox::readMC({buff, static_cast<std::size_t>(stat.size)}, p));
return static_cast<std::size_t>(p.preloadAddr) + ctx.preloadSectionOffset;
}
@ -161,7 +158,7 @@ ox::Result<std::size_t> getPreloadAddr(keel::Context &ctx, ox::FileAddress const
oxRequire(stat, ctx.rom->stat(file));
oxRequire(buff, static_cast<ox::MemFS*>(ctx.rom.get())->directAccess(file));
PreloadPtr p;
oxReturnError(ox::readMC(buff, static_cast<std::size_t>(stat.size), &p));
oxReturnError(ox::readMC({buff, static_cast<std::size_t>(stat.size)}, p));
return static_cast<std::size_t>(p.preloadAddr) + ctx.preloadSectionOffset;
}

View File

@ -10,13 +10,13 @@
namespace keel {
[[nodiscard]]
static ox::Result<const BaseConverter*> findConverter(
ox::Vector<const BaseConverter*> const&converters,
static ox::Result<BaseConverter const*> findConverter(
ox::SpanView<BaseConverter const*> const&converters,
ox::CRStringView srcTypeName,
int srcTypeVersion,
ox::CRStringView dstTypeName,
int dstTypeVersion) noexcept {
for (auto &c : converters) {
for (auto const&c : converters) {
if (c->matches(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion)) {
return c;
}
@ -24,21 +24,22 @@ static ox::Result<const BaseConverter*> findConverter(
return OxError(1, "Could not find converter");
};
static ox::Result<ox::UniquePtr<Wrap>> convert(
[[maybe_unused]] keel::Context &ctx,
ox::Vector<const BaseConverter*> const&converters,
[[maybe_unused]] ox::Buffer const&srcBuffer,
[[maybe_unused]] ox::CRStringView srcTypeName,
[[maybe_unused]] int srcTypeVersion,
[[maybe_unused]] ox::CRStringView dstTypeName,
[[maybe_unused]] int dstTypeVersion) noexcept {
static ox::Result<ox::UPtr<Wrap>> convert(
keel::Context &ctx,
ox::SpanView<BaseConverter const*> const&converters,
ox::Buffer const&srcBuffer,
ox::CRStringView srcTypeName,
int srcTypeVersion,
ox::CRStringView dstTypeName,
int dstTypeVersion) noexcept {
// look for direct converter
auto [c, err] = findConverter(converters, srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion);
auto [c, err] = findConverter(
converters, srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion);
if (!err) {
return c->convertBuffToPtr(ctx, srcBuffer);
}
// try to chain multiple converters
for (const auto &subConverter : converters) {
for (auto const&subConverter : converters) {
if (!subConverter->dstMatches(dstTypeName, dstTypeVersion)) {
continue;
}
@ -52,24 +53,20 @@ static ox::Result<ox::UniquePtr<Wrap>> convert(
return OxError(1, "Could not convert between types");
}
ox::Result<ox::UniquePtr<Wrap>> convert(
[[maybe_unused]] keel::Context &ctx,
[[maybe_unused]] ox::Buffer const&srcBuffer,
[[maybe_unused]] ox::CRStringView dstTypeName,
[[maybe_unused]] int dstTypeVersion) noexcept {
#ifndef OX_BARE_METAL
ox::Result<ox::UPtr<Wrap>> convert(
keel::Context &ctx,
ox::Buffer const&srcBuffer,
ox::CRStringView dstTypeName,
int dstTypeVersion) noexcept {
oxRequire(hdr, readAssetHeader(srcBuffer));
return convert(
ctx,
ctx.converters,
converters(ctx),
srcBuffer,
hdr.clawHdr.typeName,
hdr.clawHdr.typeVersion,
dstTypeName,
dstTypeVersion);
#else
return OxError(1, "Operation not supported on this platform");
#endif
}
}

View File

@ -11,11 +11,11 @@ TypeStore::TypeStore(ox::FileSystem &fs, ox::StringView descPath) noexcept:
m_descPath(descPath) {
}
ox::Result<ox::UPtr<ox::DescriptorType>> TypeStore::loadDescriptor(ox::CRStringView typeId) noexcept {
auto path = ox::sfmt("{}/{}", m_descPath, typeId);
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));
auto dt = ox::make_unique<ox::DescriptorType>();
oxReturnError(ox::readClaw<ox::DescriptorType>(buff, dt.get()));
oxReturnError(ox::readClaw<ox::DescriptorType>(buff, *dt));
return dt;
}

View File

@ -68,7 +68,7 @@ static ox::Error run(
static_cast<uint64_t>(time << 1)
});
// run app
auto const err = runApp(appName, projectDataDir, ox::UniquePtr<ox::FileSystem>(nullptr));
auto const err = runApp(appName, projectDataDir, ox::UPtr<ox::FileSystem>(nullptr));
oxAssert(err, "Something went wrong...");
return err;
}