[olympic/keel] Finish east consting Keel
This commit is contained in:
@@ -11,18 +11,18 @@ namespace keel {
|
||||
|
||||
constexpr auto K1HdrSz = 40;
|
||||
|
||||
ox::Result<ox::UUID> readUuidHeader(const ox::Buffer &buff) noexcept;
|
||||
ox::Result<ox::UUID> readUuidHeader(ox::Buffer const&buff) noexcept;
|
||||
|
||||
ox::Result<ox::UUID> readUuidHeader(const char *buff, std::size_t buffLen) noexcept;
|
||||
|
||||
ox::Error writeUuidHeader(ox::Writer_c auto &writer, const ox::UUID &uuid) noexcept {
|
||||
ox::Error writeUuidHeader(ox::Writer_c auto &writer, ox::UUID const&uuid) noexcept {
|
||||
oxReturnError(write(writer, "K1;"));
|
||||
oxReturnError(uuid.toString(writer));
|
||||
return writer.put(';');
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Result<T> readAsset(const ox::Buffer &buff) noexcept {
|
||||
ox::Result<T> readAsset(ox::Buffer const&buff) noexcept {
|
||||
std::size_t offset = 0;
|
||||
const auto err = readUuidHeader(buff).error;
|
||||
if (!err) {
|
||||
@@ -31,15 +31,15 @@ ox::Result<T> readAsset(const ox::Buffer &buff) noexcept {
|
||||
return ox::readClaw<T>(buff.data() + offset, buff.size() - offset);
|
||||
}
|
||||
|
||||
ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, const ox::Buffer &buff) noexcept;
|
||||
ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::Buffer const&buff) noexcept;
|
||||
|
||||
struct AssetHdr {
|
||||
ox::UUID uuid;
|
||||
ox::ClawHeader clawHdr;
|
||||
};
|
||||
|
||||
ox::Result<AssetHdr> readAssetHeader(const char *buff, std::size_t buffLen) noexcept;
|
||||
ox::Result<AssetHdr> readAssetHeader(char const*buff, std::size_t buffLen) noexcept;
|
||||
|
||||
ox::Result<AssetHdr> readAssetHeader(const ox::Buffer &buff) noexcept;
|
||||
ox::Result<AssetHdr> readAssetHeader(ox::Buffer const&buff) noexcept;
|
||||
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ class AssetContainer {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const T *get() const noexcept {
|
||||
constexpr T const*get() const noexcept {
|
||||
return &m_obj;
|
||||
}
|
||||
|
||||
@@ -78,12 +78,12 @@ class AssetContainer {
|
||||
template<typename T>
|
||||
class AssetRef: public ox::SignalHandler {
|
||||
private:
|
||||
const AssetContainer<T> *m_ctr = nullptr;
|
||||
AssetContainer<T> const*m_ctr = nullptr;
|
||||
|
||||
public:
|
||||
ox::Signal<ox::Error()> updated;
|
||||
|
||||
explicit constexpr AssetRef(const AssetContainer<T> *c = nullptr) noexcept;
|
||||
explicit constexpr AssetRef(AssetContainer<T> const*c = nullptr) noexcept;
|
||||
|
||||
constexpr AssetRef(AssetRef const&h) noexcept;
|
||||
|
||||
@@ -96,18 +96,18 @@ class AssetRef: public ox::SignalHandler {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr const T *get() const noexcept {
|
||||
constexpr T const*get() const noexcept {
|
||||
if (m_ctr) {
|
||||
return m_ctr->get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
constexpr const T &operator*() const noexcept {
|
||||
constexpr T const&operator*() const noexcept {
|
||||
return *m_ctr->get();
|
||||
}
|
||||
|
||||
constexpr const T *operator->() const noexcept {
|
||||
constexpr T const*operator->() const noexcept {
|
||||
return m_ctr->get();
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ class AssetRef: public ox::SignalHandler {
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
constexpr AssetRef<T>::AssetRef(const AssetContainer<T> *c) noexcept: m_ctr(c) {
|
||||
constexpr AssetRef<T>::AssetRef(AssetContainer<T> const*c) noexcept: m_ctr(c) {
|
||||
if (c) {
|
||||
c->updated.connect(this, &AssetRef::emitUpdated);
|
||||
}
|
||||
@@ -219,7 +219,7 @@ class AssetManager {
|
||||
}
|
||||
|
||||
void gc() noexcept final {
|
||||
for (const auto &ack : m_cache.keys()) {
|
||||
for (auto const&ack : m_cache.keys()) {
|
||||
auto &ac = m_cache[ack];
|
||||
if (!ac->references()) {
|
||||
m_cache.erase(ack);
|
||||
@@ -249,7 +249,7 @@ class AssetManager {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Result<AssetRef<T>> setAsset(ox::CRStringView assetId, const T &obj) noexcept {
|
||||
ox::Result<AssetRef<T>> setAsset(ox::CRStringView assetId, T const&obj) noexcept {
|
||||
auto m = getTypeManager<T>();
|
||||
return m->setAsset(assetId, obj);
|
||||
}
|
||||
@@ -265,27 +265,27 @@ class AssetManager {
|
||||
template<typename T>
|
||||
class AssetRef {
|
||||
private:
|
||||
const T *const m_obj = nullptr;
|
||||
T const*const m_obj = nullptr;
|
||||
|
||||
public:
|
||||
constexpr AssetRef() noexcept = default;
|
||||
|
||||
explicit constexpr AssetRef(const T *obj) noexcept: m_obj(obj) {
|
||||
explicit constexpr AssetRef(T const*obj) noexcept: m_obj(obj) {
|
||||
}
|
||||
|
||||
constexpr const T *get() const noexcept {
|
||||
constexpr T const*get() const noexcept {
|
||||
return m_obj;
|
||||
}
|
||||
|
||||
constexpr const T &operator*() const & noexcept {
|
||||
constexpr T const&operator*() const & noexcept {
|
||||
return *m_obj;
|
||||
}
|
||||
|
||||
constexpr const T &&operator*() const && noexcept {
|
||||
constexpr T const&&operator*() const && noexcept {
|
||||
return *m_obj;
|
||||
}
|
||||
|
||||
constexpr const T *operator->() const noexcept {
|
||||
constexpr T const*operator->() const noexcept {
|
||||
return m_obj;
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ class Context {
|
||||
AssetManager assetManager;
|
||||
ox::HashMap<ox::String, ox::UUID> pathToUuid;
|
||||
ox::HashMap<ox::UUIDStr, ox::String> uuidToPath;
|
||||
ox::Vector<const class BaseConverter*> converters;
|
||||
ox::Vector<class BaseConverter const*> converters;
|
||||
ox::Vector<PackTransform> packTransforms;
|
||||
#else
|
||||
std::size_t preloadSectionOffset = 0;
|
||||
|
@@ -81,7 +81,7 @@ ox::Result<keel::AssetRef<T>> readObjNoCache(
|
||||
ox::CRStringView assetId) noexcept {
|
||||
if constexpr(ox::preloadable<T>::value) {
|
||||
oxRequire(addr, getPreloadAddr(ctx, assetId));
|
||||
return keel::AssetRef<T>(std::bit_cast<const T*>(uintptr_t{addr}));
|
||||
return keel::AssetRef<T>(std::bit_cast<T const*>(uintptr_t{addr}));
|
||||
} else {
|
||||
return OxError(1);
|
||||
}
|
||||
@@ -107,7 +107,7 @@ ox::Result<AssetRef<T>> setAsset(keel::Context &ctx, ox::StringView assetId, T c
|
||||
}
|
||||
ox::UUIDStr idStr;
|
||||
if (assetId[0] == '/') {
|
||||
const auto [id, err] = ctx.pathToUuid.at(assetId);
|
||||
auto const [id, err] = ctx.pathToUuid.at(assetId);
|
||||
oxReturnError(err);
|
||||
idStr = id->toString();
|
||||
assetId = idStr;
|
||||
@@ -141,7 +141,7 @@ ox::Result<keel::AssetRef<T>> readObj(
|
||||
#else
|
||||
if constexpr(ox::preloadable<T>::value) {
|
||||
oxRequire(addr, getPreloadAddr(ctx, file));
|
||||
return keel::AssetRef<T>(std::bit_cast<const T*>(uintptr_t{addr}));
|
||||
return keel::AssetRef<T>(std::bit_cast<T const*>(uintptr_t{addr}));
|
||||
} else {
|
||||
return OxError(1);
|
||||
}
|
||||
|
@@ -37,9 +37,9 @@ class Module {
|
||||
virtual ox::Vector<PackTransform> packTransforms() const noexcept;
|
||||
};
|
||||
|
||||
void registerModule(const Module *mod) noexcept;
|
||||
void registerModule(Module const*mod) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
ox::Vector<const keel::Module*> const&modules() noexcept;
|
||||
ox::Vector<keel::Module const*> const&modules() noexcept;
|
||||
|
||||
}
|
||||
|
@@ -66,7 +66,7 @@ struct GbaPlatSpec {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static constexpr std::size_t alignOf(const auto*) noexcept {
|
||||
static constexpr std::size_t alignOf(auto const*) noexcept {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@@ -94,10 +94,10 @@ ox::Error preloadObj(
|
||||
oxOutf("preloading {}\n", path);
|
||||
// preload
|
||||
oxRequire(a, pl.startAlloc(ox::sizeOf<GbaPlatSpec>(&obj)));
|
||||
const auto err = ox::preload<GbaPlatSpec, decltype(obj)>(&pl, &obj);
|
||||
auto const err = ox::preload<GbaPlatSpec, decltype(obj)>(&pl, &obj);
|
||||
oxReturnError(pl.endAlloc());
|
||||
oxReturnError(err);
|
||||
const keel::PreloadPtr p{.preloadAddr = static_cast<uint32_t>(a)};
|
||||
keel::PreloadPtr const p{.preloadAddr = static_cast<uint32_t>(a)};
|
||||
oxReturnError(ox::writeMC(p).moveTo(buff));
|
||||
} else {
|
||||
// strip the Claw header (it is not needed after preloading) and write back out to dest fs
|
||||
@@ -118,11 +118,11 @@ ox::Error preloadDir(
|
||||
// copy
|
||||
oxTracef("pack.preload", "path: {}", path);
|
||||
oxRequire(fileList, romFs.ls(path));
|
||||
for (const auto &name : fileList) {
|
||||
const auto filePath = ox::sfmt("{}{}", path, name);
|
||||
for (auto const&name : fileList) {
|
||||
auto const filePath = ox::sfmt("{}{}", path, name);
|
||||
oxRequire(stat, romFs.stat(filePath));
|
||||
if (stat.fileType == ox::FileType::Directory) {
|
||||
const auto dir = ox::sfmt("{}{}/", path, name);
|
||||
auto const dir = ox::sfmt("{}{}/", path, name);
|
||||
oxReturnError(preloadDir(ts, romFs, pl, dir));
|
||||
} else {
|
||||
oxReturnError(preloadObj(ts, romFs, pl, filePath));
|
||||
@@ -150,7 +150,7 @@ ox::Error appendBinary(ox::Buffer &binBuff, ox::SpanView<char> const&fsBuff, ox:
|
||||
oxReturnError(padbin(w, hdrSize));
|
||||
oxReturnError(w.write(preloadHdr.data(), preloadHdr.bytes()));
|
||||
oxReturnError(pl.offsetPtrs(binBuff.size()));
|
||||
const auto &plBuff = pl.buff();
|
||||
auto const&plBuff = pl.buff();
|
||||
oxReturnError(w.write(plBuff.data(), plBuff.size()));
|
||||
return {};
|
||||
}
|
||||
|
@@ -20,28 +20,6 @@ class Wrap {
|
||||
virtual ~Wrap() = default;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class WrapIndirect: public Wrap {
|
||||
private:
|
||||
T *m_obj = nullptr;
|
||||
|
||||
public:
|
||||
template<typename... Args>
|
||||
constexpr explicit WrapIndirect(Args &&...args): m_obj(ox::forward<Args>(args)...) {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto obj() const noexcept {
|
||||
return &m_obj;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto obj() noexcept {
|
||||
return &m_obj;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class WrapInline: public Wrap {
|
||||
private:
|
||||
@@ -55,8 +33,8 @@ class WrapInline: public Wrap {
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto obj() noexcept {
|
||||
return &m_obj;
|
||||
constexpr T &obj() noexcept {
|
||||
return m_obj;
|
||||
}
|
||||
|
||||
};
|
||||
@@ -67,7 +45,7 @@ constexpr auto makeWrap(Args &&...args) noexcept {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr T *wrapCast(Wrap &ptr) noexcept {
|
||||
constexpr T &wrapCast(Wrap &ptr) noexcept {
|
||||
return static_cast<WrapInline<T>&>(ptr).obj();
|
||||
}
|
||||
|
||||
@@ -89,7 +67,7 @@ class BaseConverter {
|
||||
|
||||
virtual ox::Result<ox::UniquePtr<Wrap>> convertPtrToPtr(keel::Context &ctx, Wrap &src) const noexcept = 0;
|
||||
|
||||
virtual ox::Result<ox::UniquePtr<Wrap>> convertBuffToPtr(keel::Context &ctx, const ox::Buffer &srcBuff) const noexcept = 0;
|
||||
virtual ox::Result<ox::UniquePtr<Wrap>> convertBuffToPtr(keel::Context &ctx, ox::Buffer const&srcBuff) const noexcept = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
inline bool matches(
|
||||
@@ -132,14 +110,14 @@ class Converter: public BaseConverter {
|
||||
|
||||
ox::Result<ox::UniquePtr<Wrap>> convertPtrToPtr(keel::Context &ctx, Wrap &src) const noexcept final {
|
||||
auto dst = makeWrap<DstType>();
|
||||
oxReturnError(convert(ctx, *wrapCast<SrcType>(src), *wrapCast<DstType>(*dst)));
|
||||
oxReturnError(convert(ctx, wrapCast<SrcType>(src), wrapCast<DstType>(*dst)));
|
||||
return ox::Result<ox::UniquePtr<Wrap>>(std::move(dst));
|
||||
}
|
||||
|
||||
ox::Result<ox::UniquePtr<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)));
|
||||
oxReturnError(convert(ctx, src, wrapCast<DstType>(*dst)));
|
||||
return ox::Result<ox::UniquePtr<Wrap>>(std::move(dst));
|
||||
}
|
||||
|
||||
@@ -149,24 +127,24 @@ class Converter: public BaseConverter {
|
||||
};
|
||||
|
||||
ox::Result<ox::UniquePtr<Wrap>> convert(
|
||||
keel::Context &ctx, const ox::Buffer &srcBuffer,
|
||||
keel::Context &ctx, ox::Buffer const&srcBuffer,
|
||||
ox::CRStringView dstTypeName, int dstTypeVersion) noexcept;
|
||||
|
||||
template<typename DstType>
|
||||
ox::Result<DstType> convert(keel::Context &ctx, const ox::Buffer &srcBuffer) noexcept {
|
||||
ox::Result<DstType> convert(keel::Context &ctx, ox::Buffer const&srcBuffer) noexcept {
|
||||
static constexpr auto DstTypeName = ox::requireModelTypeName<DstType>();
|
||||
static constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>();
|
||||
oxRequire(out, convert(ctx, srcBuffer, DstTypeName, DstTypeVersion));
|
||||
return wrapCast<DstType>(out);
|
||||
return std::move(wrapCast<DstType>(out));
|
||||
}
|
||||
|
||||
template<typename DstType>
|
||||
ox::Error convert(keel::Context &ctx, const ox::Buffer &buff, DstType *outObj) noexcept {
|
||||
ox::Error convert(keel::Context &ctx, ox::Buffer 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));
|
||||
*outObj = std::move(*wrapCast<DstType>(*outPtr));
|
||||
return OxError(0);
|
||||
*outObj = std::move(wrapCast<DstType>(*outPtr));
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename DstType>
|
||||
@@ -174,7 +152,7 @@ ox::Result<ox::Buffer> convertBuffToBuff(keel::Context &ctx, const ox::Buffer &s
|
||||
static constexpr auto DstTypeName = ox::requireModelTypeName<DstType>();
|
||||
static constexpr auto DstTypeVersion = ox::requireModelTypeVersion<DstType>();
|
||||
oxRequire(out, convert(ctx, srcBuffer, DstTypeName, DstTypeVersion));
|
||||
return ox::writeClaw<DstType>(*wrapCast<DstType>(*out), fmt);
|
||||
return ox::writeClaw<DstType>(wrapCast<DstType>(*out), fmt);
|
||||
}
|
||||
|
||||
template<typename From, typename To, ox::ClawFormat fmt = ox::ClawFormat::Metal>
|
||||
|
@@ -19,7 +19,7 @@ class TypeStore: public ox::TypeStore {
|
||||
explicit TypeStore(ox::FileSystem &fs, ox::StringView descPath) noexcept;
|
||||
|
||||
protected:
|
||||
ox::Result<ox::UniquePtr<ox::DescriptorType>> loadDescriptor(ox::CRStringView typeId) noexcept override;
|
||||
ox::Result<ox::UPtr<ox::DescriptorType>> loadDescriptor(ox::CRStringView typeId) noexcept override;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user