Squashed 'deps/nostalgia/' changes from 791b7746..a3d6a58c

a3d6a58c [nostalgia/core/studio] Fix library cpp file ownership
e598e7fe [nostalgia,keel] Add ability to types Obj to Obj
ba9e720f [ox/model] Fix ModelTypeName_v to use requireModelTypeName
8e816a26 [nostalgia/core/studio] Cleanup, fix possible TileSheet fill tool failure
5b9929ab [keel] Add detail to preload logging
ceb54b3f [nostalgia/core/opengl] Cleanup
87644447 [nostalgia/core] Add clearCbb functions
ce9a0b1f [nostalgia/core/opengl] Cleanup memcpys
f7a468ea [ox/std] Add spancpy
861d177a [studio] Cleanup
3936756b [nostalgia/developer-handbook] Update error handling to reflect the enablement of exceptions for GBA build
3e78ec3f [studio] Cleanup
3c3d53b4 [studio] Ensure Editor tabs do first draw immediately, fix shift key being missed with tab shortcuts
151d7c57 [nostalgia/core/gba] Fix partial tilesheet loading overrun
4e4d8d2c [nostalgia/core/gba] Make panic use standard abort call
03d1fd28 [ox/std] Add and integrate standard abort call
6701decc [gbabuildcore] Enable exceptions
6cff5266 [teagba] Add symbols needed for enabling exceptions
dd50bd02 [studio] Remap toggle explorer keyboard shortcut, add Ctrl+1-0 mappings for jumping between tabs
55a16602 [nostalgia/core] Fix TileSheet validation/repair to ensure pixels gets cleared if there are subsheets
ed365dfe [studio] Fix new project menu to return an appropriately sized string for name
23a09e4a [nostalgia/core/studio] Fix SubSheet editor to return an appropriately sized string
b69e7ebb [nostalgia/core/studio/tilesheeteditor] Fix select all not to go beyond end
418d6e3f [nostalgia/core/studio] Fix crash that occurs when a non-leaf node subsheet is selected
c44d8678 [nostalgia/core/studio] Fix tile insert to correct input when inserting past the last tile
eb4cd710 [nostalgia/core/studio] Fix tile insert to work on last tile
d259770f Merge commit '4ea4a61d542777a270c4e2c283e0e986fc9eec9c'
80bad608 [keel] Fix reloadAsset
2bce9a2b [ox/std] Add non-const SmallMap::pairs

git-subtree-dir: deps/nostalgia
git-subtree-split: a3d6a58cc898f88434e8901aacb579c819fac3e6
This commit is contained in:
2025-01-17 21:58:18 -06:00
parent 4ea4a61d54
commit 50b1ed33df
39 changed files with 558 additions and 274 deletions

View File

@@ -12,7 +12,7 @@
namespace keel {
class Context;
using PackTransform = ox::Result<bool>(*)(Context&, ox::Buffer &clawData, ox::StringView);
using PackTransform = ox::Result<bool>(*)(Context&, ox::Buffer &clawData, ox::StringViewCR);
class Context {
public:

View File

@@ -70,7 +70,7 @@ constexpr auto makeLoader(Context &ctx) {
if (err != ox::Error_ClawTypeVersionMismatch && err != ox::Error_ClawTypeMismatch) {
return err;
}
OX_RETURN_ERROR(convert<T>(ctx, buff, &obj));
OX_RETURN_ERROR(convert<T>(ctx, buff, obj));
}
return std::move(obj);
};

View File

@@ -125,7 +125,9 @@ ox::Error preloadObj(
OX_RETURN_ERROR(err);
keel::PreloadPtr const p{.preloadAddr = a};
OX_RETURN_ERROR(ox::writeMC(p).moveTo(buff));
oxOutf("preloaded {} as a {} @ {} to {}\n", path, obj.type()->typeName, a, a + size);
auto const&pbufSz = pl.buff().size();
oxOutf("preloaded {} as a {} @ {} to {} / {}, total size: {}\n",
path, obj.type()->typeName, a, a + size, pbufSz - 1, pbufSz - a);
} else {
// strip the Claw header (it is not needed after preloading) and write back out to dest fs
OX_RETURN_ERROR(ox::writeMC(obj).moveTo(buff));

View File

@@ -16,10 +16,43 @@ namespace keel {
class Wrap {
public:
virtual ~Wrap() = default;
[[nodiscard]]
virtual ox::CStringView typeName() const noexcept = 0;
[[nodiscard]]
virtual int typeVersion() const noexcept = 0;
};
template<typename T>
class WrapInline: public Wrap {
class WrapT: public Wrap {
public:
[[nodiscard]]
virtual constexpr T &obj() noexcept = 0;
};
template<typename T>
class WrapRef final: public WrapT<T> {
private:
T &m_obj;
public:
constexpr explicit WrapRef(T &obj): m_obj{obj} {}
ox::CStringView typeName() const noexcept override {
return ox::ModelTypeName_v<T>;
}
int typeVersion() const noexcept override {
return ox::ModelTypeVersion_v<T>;
}
constexpr T &obj() noexcept override {
return m_obj;
}
};
template<typename T>
class WrapInline final: public WrapT<T> {
private:
T m_obj;
@@ -30,8 +63,15 @@ class WrapInline: public Wrap {
constexpr explicit WrapInline(Args &&...args): m_obj(ox::forward<Args>(args)...) {
}
[[nodiscard]]
constexpr T &obj() noexcept {
ox::CStringView typeName() const noexcept override {
return ox::ModelTypeName_v<T>;
}
int typeVersion() const noexcept override {
return ox::ModelTypeVersion_v<T>;
}
constexpr T &obj() noexcept override {
return m_obj;
}
@@ -44,7 +84,7 @@ constexpr ox::UPtr<Wrap> makeWrap(Args &&...args) noexcept {
template<typename T>
constexpr T &wrapCast(Wrap &ptr) noexcept {
return static_cast<WrapInline<T>&>(ptr).obj();
return static_cast<WrapT<T>&>(ptr).obj();
}
class BaseConverter {
@@ -70,10 +110,10 @@ class BaseConverter {
[[nodiscard]]
constexpr bool matches(
ox::StringViewCR srcTypeName, int srcTypeVersion,
ox::StringViewCR dstTypeName, int dstTypeVersion) const noexcept {
ox::StringViewCR srcTypeName, int const srcTypeVersion,
ox::StringViewCR dstTypeName, int const dstTypeVersion) const noexcept {
return srcMatches(srcTypeName, srcTypeVersion)
&& dstMatches(dstTypeName, dstTypeVersion);
&& dstMatches(dstTypeName, dstTypeVersion);
}
};
@@ -109,17 +149,17 @@ class Converter: public BaseConverter {
ox::Result<ox::UPtr<Wrap>> convertPtrToPtr(
keel::Context &ctx, Wrap &src) const noexcept final {
auto dst = makeWrap<DstType>();
OX_RETURN_ERROR(convert(ctx, wrapCast<SrcType>(src), wrapCast<DstType>(*dst)));
return {std::move(dst)};
ox::Result<ox::UPtr<Wrap>> dst{makeWrap<DstType>()};
OX_RETURN_ERROR(convert(ctx, wrapCast<SrcType>(src), wrapCast<DstType>(*dst.value)));
return dst;
}
ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
keel::Context &ctx, ox::BufferView const&srcBuff) const noexcept final {
OX_REQUIRE_M(src, readAsset<SrcType>(srcBuff));
auto dst = makeWrap<DstType>();
OX_RETURN_ERROR(convert(ctx, src, wrapCast<DstType>(*dst)));
return {std::move(dst)};
ox::Result<ox::UPtr<Wrap>> dst{makeWrap<DstType>()};
OX_RETURN_ERROR(convert(ctx, src, wrapCast<DstType>(*dst.value)));
return dst;
}
protected:
@@ -133,34 +173,57 @@ ox::Result<ox::UPtr<Wrap>> convert(
ox::StringViewCR dstTypeName,
int dstTypeVersion) noexcept;
ox::Result<ox::UPtr<Wrap>> convert(
keel::Context &ctx,
Wrap &src,
ox::StringViewCR dstTypeName,
int dstTypeVersion) noexcept;
ox::Result<ox::UPtr<Wrap>> convert(
keel::Context &ctx,
auto &src,
ox::StringViewCR dstTypeName,
int const dstTypeVersion) noexcept {
return convert(ctx, WrapRef{src}, dstTypeName, dstTypeVersion);
}
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>();
OX_REQUIRE(out, convert(ctx, srcBuffer, DstTypeName, DstTypeVersion));
ox::Result<DstType> convertObjToObj(
keel::Context &ctx,
auto &src) noexcept {
OX_REQUIRE_M(out, convert(ctx, WrapRef{src}, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
return std::move(wrapCast(*out));
}
template<typename DstType>
ox::Result<DstType> convert(keel::Context &ctx, ox::BufferView const&src) noexcept {
OX_REQUIRE(out, convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
return std::move(wrapCast<DstType>(out));
}
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>();
OX_REQUIRE(outPtr, convert(ctx, buff, DstTypeName, DstTypeVersion));
*outObj = std::move(wrapCast<DstType>(*outPtr));
ox::Error convert(keel::Context &ctx, ox::BufferView const&buff, DstType &outObj) noexcept {
OX_REQUIRE(out, convert(ctx, buff, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
outObj = std::move(wrapCast<DstType>(*out));
return {};
}
template<typename DstType>
ox::Error convertObjToObj(keel::Context &ctx, auto &src, DstType &outObj) noexcept {
OX_REQUIRE(outPtr, convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
outObj = std::move(wrapCast<DstType>(*outPtr));
return {};
}
template<typename DstType>
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>();
OX_REQUIRE(out, convert(ctx, srcBuffer, DstTypeName, DstTypeVersion));
keel::Context &ctx, ox::BufferView const&src, ox::ClawFormat const fmt) noexcept {
OX_REQUIRE(out, convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
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 {
ox::Result<bool> transformRule(keel::Context &ctx, ox::Buffer &buff, ox::StringViewCR typeId) noexcept {
if (typeId == ox::ModelTypeId_v<From>) {
OX_RETURN_ERROR(keel::convertBuffToBuff<To>(ctx, buff, fmt).moveTo(buff));
return true;
@@ -168,5 +231,4 @@ ox::Result<bool> transformRule(keel::Context &ctx, ox::Buffer &buff, ox::StringV
return false;
};
}

View File

@@ -154,13 +154,12 @@ ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::UUID const&uuid) noexce
}
ox::Error reloadAsset(keel::Context &ctx, ox::StringViewCR assetId) noexcept {
ox::UUIDStr uuidStr;
if (beginsWith(assetId, "uuid://")) {
return ctx.assetManager.reloadAsset(substr(assetId, 7));
} else {
auto const [uuid, uuidErr] = getUuid(ctx, assetId);
auto const [uuid, uuidErr] = getUuid(ctx, assetId);
if (!uuidErr) {
return ctx.assetManager.reloadAsset(uuidStr);
return ctx.assetManager.reloadAsset(uuid.toString());
} else {
return ctx.assetManager.reloadAsset(assetId);
}

View File

@@ -10,30 +10,38 @@ namespace keel {
static ox::Result<BaseConverter const*> findConverter(
ox::SpanView<BaseConverter const*> const&converters,
ox::StringViewCR srcTypeName,
int srcTypeVersion,
int const srcTypeVersion,
ox::StringViewCR dstTypeName,
int dstTypeVersion) noexcept {
int const dstTypeVersion) noexcept {
for (auto const&c : converters) {
if (c->matches(srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion)) {
return c;
}
}
return ox::Error(1, "Could not find converter");
return ox::Error{1, "Could not find converter"};
};
static ox::Result<ox::UPtr<Wrap>> convert(BaseConverter const&c, Context &ctx, ox::BufferView const&src) noexcept {
return c.convertBuffToPtr(ctx, src);
}
static ox::Result<ox::UPtr<Wrap>> convert(BaseConverter const&c, Context &ctx, Wrap &src) noexcept {
return c.convertPtrToPtr(ctx, src);
}
static ox::Result<ox::UPtr<Wrap>> convert(
keel::Context &ctx,
Context &ctx,
ox::SpanView<BaseConverter const*> const&converters,
ox::BufferView const&srcBuffer,
auto &src,
ox::StringViewCR srcTypeName,
int srcTypeVersion,
int const srcTypeVersion,
ox::StringViewCR dstTypeName,
int dstTypeVersion) noexcept {
int const dstTypeVersion) noexcept {
// look for direct converter
auto [c, err] = findConverter(
auto const [c, err] = findConverter(
converters, srcTypeName, srcTypeVersion, dstTypeName, dstTypeVersion);
if (!err) {
return c->convertBuffToPtr(ctx, srcBuffer);
return convert(*c, ctx, src);
}
// try to chain multiple converters
for (auto const&subConverter : converters) {
@@ -41,20 +49,20 @@ static ox::Result<ox::UPtr<Wrap>> convert(
continue;
}
const auto [intermediate, chainErr] =
convert(ctx, converters, srcBuffer, srcTypeName, srcTypeVersion,
convert(ctx, converters, src, srcTypeName, srcTypeVersion,
subConverter->srcTypeName(), subConverter->srcTypeVersion());
if (!chainErr) {
return subConverter->convertPtrToPtr(ctx, *intermediate);
}
}
return ox::Error(1, "Could not convert between types");
return ox::Error{1, "Could not convert between types"};
}
ox::Result<ox::UPtr<Wrap>> convert(
keel::Context &ctx,
Context &ctx,
ox::BufferView const&srcBuffer,
ox::StringViewCR dstTypeName,
int dstTypeVersion) noexcept {
int const dstTypeVersion) noexcept {
OX_REQUIRE(hdr, readAssetHeader(srcBuffer));
return convert(
ctx,
@@ -66,4 +74,19 @@ ox::Result<ox::UPtr<Wrap>> convert(
dstTypeVersion);
}
ox::Result<ox::UPtr<Wrap>> convert(
Context &ctx,
Wrap &src,
ox::StringViewCR dstTypeName,
int const dstTypeVersion) noexcept {
return convert(
ctx,
converters(ctx),
src,
src.typeName(),
src.typeVersion(),
dstTypeName,
dstTypeVersion);
}
}