Squashed 'deps/nostalgia/' changes from 161640fa..a75c4a11

a75c4a11 [nfde] Address CMake warning, remove unwanted logging
347a1657 [sample_project] Update type descriptors
fd64bfae [keel] Fix a use after free, cleanup
aaeec20a [nostalgia/player] Fix build
37030f9c [keel] Cleanup pack tool
462f2bca [nostalgia,olympic] Change macro names to comply with broader conventions
dc72500b [glutils] Change macro names to comply with broader conventions
962fe8bc [ox] Change macro names to comply with broader conventions
305eb626 [studio] Fix build
4754359a [ox/std] Cleanup Vec2
dc07f3d5 [studio] Change FilePicker consturctor to take StringParams
fcdcfd10 [ox/std] Run liccor
b74f6a7a [studio,turbine] Run liccor
ac7e5be1 [ox] Remove OxException
ed910c0b [nostalgia/core/studio/tilesheeteditor] Fix access overflow on out of bounds Fill command
345fb038 [ox] Remove OxError
9881253f [glutils] Cleanup OxError
96d27eec [nostalgia,olympic] Cleanup
28ebe93b [ox/std] Make source_location::current only init if valid
e849e7a3 [ox/std] Add source_location
e6777b0a [cityhash] Add install rule
c488c336 [turbine/glfw] Fix mandatoryRefreshPeriodEnd tracking
003f9720 [turbine/glfw] Move MandatoryRefreshPeriod to config.hpp
d85a10af [nostalgia/core/studio] Cleanup
ff05d860 [turbine/glfw] Replace uninterruptedRefreshes with mandatoryRefreshPeriodEnd
76794037 [turbine] Add init wrapper that takes FS path
c51a45e1 [olympic] Cleanup
a6e24ff2 [ox/std] Add CString type alias
e0ec9e0c [nostalgia,olympic] Move olympic::run to global namespace
9a42a9b9 [nfde] Fix Windows warnings
03a05c51 Merge commit '4ccdfc3a6e5bd501968903a01f7d8141b6f88375'
bd91137d [nostalgia,olympic] Fix pack tool build for Windows
2b7d1294 [nostalgia/core/studio] Fix MSVC build

git-subtree-dir: deps/nostalgia
git-subtree-split: a75c4a11d3c555f4d3bed1ea1f70bb29fe49e99c
This commit is contained in:
2024-12-21 20:13:20 -06:00
parent 4ccdfc3a6e
commit dc96270ca5
199 changed files with 2468 additions and 2156 deletions

View File

@@ -17,6 +17,10 @@
#define OLYMPIC_APP_VERSION "dev build"
#endif
#ifndef OLYMPIC_GUI_APP
#define OLYMPIC_GUI_APP 0
#endif
#ifndef OLYMPIC_PROJECT_NAMESPACE
#define OLYMPIC_PROJECT_NAMESPACE project
#endif
@@ -34,23 +38,21 @@
#endif
namespace olympic {
ox::String appVersion = ox::String(OLYMPIC_APP_VERSION);
}
ox::Error run(
ox::StringView project,
ox::StringView appName,
ox::StringView projectDataDir,
ox::SpanView<char const*> argv) noexcept;
}
ox::SpanView<ox::CString> argv) noexcept;
namespace OLYMPIC_PROJECT_NAMESPACE {
void registerKeelModules() noexcept;
void registerStudioModules() noexcept;
}
#ifdef _WIN32
#if defined(_WIN32) && OLYMPIC_GUI_APP
int WinMain() {
auto const argc = __argc;
auto const argv = const_cast<const char**>(__argv);
@@ -64,7 +66,7 @@ int main(int argc, char const**argv) {
#if OLYMPIC_LOAD_STUDIO_MODULES
OLYMPIC_PROJECT_NAMESPACE::registerStudioModules();
#endif
auto const err = olympic::run(
auto const err = run(
OLYMPIC_PROJECT_NAME,
OLYMPIC_APP_NAME,
OLYMPIC_PROJECT_DATADIR,

View File

@@ -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;
}

View File

@@ -155,7 +155,7 @@ class AssetRef: public ox::SignalHandler {
private:
constexpr ox::Error emitUpdated() const noexcept {
updated.emit();
return OxError(0);
return ox::Error(0);
}
};
@@ -205,16 +205,16 @@ 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 OxError(1, "asset is null");
return ox::Error(1, "asset is null");
}
return AssetRef<T>(out->get());
}
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 {
@@ -256,7 +256,7 @@ class AssetManager {
auto &am = m_assetTypeManagers[typeId];
auto const out = dynamic_cast<AssetTypeManager<T>*>(am.get());
if (!out) {
return OxError(1, "no AssetTypeManager for type");
return ox::Error(1, "no AssetTypeManager for type");
}
return out;
}
@@ -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;
}

View File

@@ -25,15 +25,15 @@ 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;
void createUuidMapping(Context &ctx, ox::StringView filePath, ox::UUID const&uuid) noexcept;
void createUuidMapping(Context &ctx, ox::StringViewCR filePath, ox::UUID const&uuid) noexcept;
ox::Error buildUuidMap(Context &ctx) noexcept;
@@ -41,17 +41,17 @@ ox::Result<ox::UUID> pathToUuid(Context &ctx, ox::StringViewCR path) noexcept;
ox::Result<ox::UUID> getUuid(Context &ctx, ox::FileAddress const&fileAddr) noexcept;
ox::Result<ox::UUID> getUuid(Context &ctx, ox::StringView path) noexcept;
ox::Result<ox::UUID> getUuid(Context &ctx, ox::StringViewCR path) noexcept;
ox::Result<ox::CStringView> getPath(Context &ctx, ox::FileAddress const&fileAddr) noexcept;
ox::Result<ox::CStringView> getPath(Context &ctx, ox::CStringView fileId) noexcept;
ox::Result<ox::CStringView> getPath(Context &ctx, ox::CStringViewCR fileId) noexcept;
constexpr ox::Result<ox::UUID> uuidUrlToUuid(ox::StringView uuidUrl) noexcept {
constexpr ox::Result<ox::UUID> uuidUrlToUuid(ox::StringViewCR uuidUrl) noexcept {
return ox::UUID::fromString(substr(uuidUrl, 7));
}
ox::Result<ox::CStringView> uuidUrlToPath(Context &ctx, ox::StringView uuid) noexcept;
ox::Result<ox::CStringView> uuidUrlToPath(Context &ctx, ox::StringViewCR uuid) noexcept;
ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::StringViewCR uuid) noexcept;
@@ -62,15 +62,15 @@ ox::Result<ox::CStringView> uuidToPath(Context &ctx, ox::UUID const&uuid) noexce
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));
return [&ctx](ox::StringViewCR assetId) -> ox::Result<T> {
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);
};
@@ -80,27 +80,34 @@ constexpr auto makeLoader(Context &ctx) {
template<typename T>
ox::Result<keel::AssetRef<T>> readObjFile(
keel::Context &ctx,
ox::StringView assetId,
bool forceLoad) noexcept {
ox::StringViewCR assetId,
bool const forceLoad) noexcept {
static constexpr auto load = [](
keel::Context &ctx,
ox::StringViewCR assetId,
bool forceLoad) -> ox::Result<keel::AssetRef<T>> {
if (forceLoad) {
ctx.assetManager.initTypeManager<T>(detail::makeLoader<T>, ctx);
return ctx.assetManager.loadAsset<T>(assetId);
} else {
auto [cached, err] = ctx.assetManager.getAsset<T>(assetId);
if (err) {
ctx.assetManager.initTypeManager<T>(detail::makeLoader<T>, ctx);
OX_RETURN_ERROR(ctx.assetManager.loadAsset<T>(assetId).moveTo(cached));
}
return cached;
}
};
if (beginsWith(assetId, "uuid://")) {
assetId = substr(assetId, 7);
return load(ctx, substr(assetId, 7), forceLoad);
} else {
auto const [uuid, uuidErr] = getUuid(ctx, assetId);
if (!uuidErr) {
assetId = uuid.toString();
return load(ctx, uuid.toString(), forceLoad);
} else {
return load(ctx, assetId, forceLoad);
}
}
if (forceLoad) {
ctx.assetManager.initTypeManager<T>(detail::makeLoader<T>, ctx);
return ctx.assetManager.loadAsset<T>(assetId);
} else {
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));
}
return cached;
}
}
#else
@@ -110,16 +117,16 @@ 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 OxError(1);
return ox::Error(1);
}
}
#endif
ox::Error reloadAsset(keel::Context &ctx, ox::StringView assetId) noexcept;
ox::Error reloadAsset(keel::Context &ctx, ox::StringViewCR assetId) noexcept;
template<typename T>
ox::Result<keel::AssetRef<T>> readObj(
@@ -139,14 +146,14 @@ 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 OxError(1);
return ox::Error(1);
}
#endif
}
@@ -157,13 +164,13 @@ 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());
}
ox::Error setRomFs(Context &ctx, ox::UPtr<ox::FileSystem> &&fs) noexcept;
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::StringViewCR path) noexcept;
ox::Result<ox::UPtr<ox::FileSystem>> loadRomFs(ox::StringViewCR path) noexcept;
ox::Result<char*> loadRom(ox::StringViewCR path = "") noexcept;

View File

@@ -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 {};
}

View File

@@ -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;

View File

@@ -14,7 +14,7 @@ constexpr bool valid(auto const&) noexcept {
}
constexpr ox::Error repair(auto const&) noexcept {
return OxError(1, "No repair function for this type");
return ox::Error(1, "No repair function for this type");
}
constexpr ox::Error ensureValid(auto &o) noexcept {

View File

@@ -8,11 +8,11 @@ namespace keel {
ox::Result<ox::UUID> readUuidHeader(ox::BufferView buff) noexcept {
if (buff.size() < K1HdrSz) [[unlikely]] {
return OxError(1, "Insufficient data to contain complete Keel header");
return ox::Error(1, "Insufficient data to contain complete Keel header");
}
constexpr ox::StringView k1Hdr = "K1;";
if (k1Hdr != ox::StringView(buff.data(), k1Hdr.bytes())) [[unlikely]] {
return OxError(2, "No Keel asset header data");
return ox::Error(2, "No Keel asset header data");
}
return ox::UUID::fromString(ox::StringView(&buff[k1Hdr.bytes()], 36));
}
@@ -30,7 +30,7 @@ ox::Result<ox::StringView> readAssetTypeId(ox::BufferView buff) noexcept {
const auto err = readUuidHeader(buff).error;
const auto offset = err ? 0u : K1HdrSz;
if (offset >= buff.size()) [[unlikely]] {
return OxError(1, "Buffer too small for expected data");
return ox::Error(1, "Buffer too small for expected data");
}
return ox::readClawTypeId(buff + offset);
}
@@ -40,10 +40,10 @@ ox::Result<AssetHdr> readAssetHeader(ox::BufferView buff) noexcept {
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");
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;
}

View File

@@ -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;
}

View File

@@ -16,7 +16,7 @@ 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);
return OxError(1, "Could not find ROM file");
return ox::Error(1, "Could not find ROM file");
}
try {
auto const size = file.tellg();
@@ -26,10 +26,10 @@ ox::Result<char*> loadRom(ox::StringViewCR path) noexcept {
return buff;
} catch (std::ios_base::failure const&e) {
oxErrorf("Could not read ROM file due to file IO failure: {}", e.what());
return OxError(2, "Could not read ROM file");
return ox::Error(2, "Could not read ROM file");
} catch (std::bad_alloc const&e) {
oxErrorf("Could not read ROM file due to new failure: {}", e.what());
return OxError(2, "Could not allocate memory for ROM file");
return ox::Error(2, "Could not allocate memory for ROM file");
}
}
@@ -42,25 +42,25 @@ static void clearUuidMap(Context &ctx) noexcept {
ctx.pathToUuid.clear();
}
void createUuidMapping(Context &ctx, ox::StringView filePath, ox::UUID const&uuid) noexcept {
void createUuidMapping(Context &ctx, ox::StringViewCR filePath, ox::UUID const&uuid) noexcept {
ctx.pathToUuid[filePath] = uuid;
ctx.uuidToPath[uuid.toString()] = filePath;
}
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));
}
}
}
@@ -69,26 +69,26 @@ static ox::Error buildUuidMap(Context &ctx, ox::StringViewCR path) noexcept {
ox::Error buildUuidMap(Context &ctx) noexcept {
if (!ctx.rom) {
return OxError(1, "No ROM FS");
return ox::Error(1, "No ROM FS");
}
return buildUuidMap(ctx, "");
}
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 OxError(1, "UUID to path conversion not supported on this platform");
return ox::Error(1, "UUID to path conversion not supported on this platform");
#endif
}
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);
}
ox::Result<ox::UUID> getUuid(Context &ctx, ox::StringView path) noexcept {
ox::Result<ox::UUID> getUuid(Context &ctx, ox::StringViewCR path) noexcept {
if (beginsWith(path, "uuid://")) {
auto const uuid = substr(path, 7);
return ox::UUID::fromString(uuid);
@@ -98,75 +98,73 @@ 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 OxError(1, "UUID to path conversion not supported on this platform");
return ox::Error(1, "UUID to path conversion not supported on this platform");
#endif
} else {
return ox::CStringView{path};
}
}
ox::Result<ox::CStringView> getPath(Context &ctx, ox::CStringView fileId) noexcept {
ox::Result<ox::CStringView> getPath(Context &ctx, ox::CStringViewCR fileId) noexcept {
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 OxError(1, "UUID to path conversion not supported on this platform");
return ox::Error(1, "UUID to path conversion not supported on this platform");
#endif
} else {
return ox::CStringView{fileId};
}
}
ox::Result<ox::CStringView> uuidUrlToPath(Context &ctx, ox::StringView uuid) noexcept {
uuid = substr(uuid, 7);
ox::Result<ox::CStringView> uuidUrlToPath(Context &ctx, ox::StringViewCR uuid) noexcept {
#ifndef OX_BARE_METAL
oxRequireM(out, ctx.uuidToPath.at(uuid));
OX_REQUIRE_M(out, ctx.uuidToPath.at(substr(uuid, 7)));
return ox::CStringView(*out);
#else
return OxError(1, "UUID to path conversion not supported on this platform");
return ox::Error(1, "UUID to path conversion not supported on this platform");
#endif
}
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 OxError(1, "UUID to path conversion not supported on this platform");
return ox::Error(1, "UUID to path conversion not supported on this platform");
#endif
}
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 OxError(1, "UUID to path conversion not supported on this platform");
return ox::Error(1, "UUID to path conversion not supported on this platform");
#endif
}
ox::Error reloadAsset(keel::Context &ctx, ox::StringView assetId) noexcept {
ox::Error reloadAsset(keel::Context &ctx, ox::StringViewCR assetId) noexcept {
ox::UUIDStr uuidStr;
if (beginsWith(assetId, "uuid://")) {
assetId = substr(assetId, 7);
oxRequire(p, keel::uuidToPath(ctx, assetId));
return ctx.assetManager.reloadAsset(substr(assetId, 7));
} else {
auto const [uuid, uuidErr] = getUuid(ctx, assetId);
if (!uuidErr) {
uuidStr = uuid.toString();
assetId = uuidStr;
return ctx.assetManager.reloadAsset(uuidStr);
} else {
return ctx.assetManager.reloadAsset(assetId);
}
}
return ctx.assetManager.reloadAsset(assetId);
}
}
@@ -200,30 +198,30 @@ ox::Result<char*> loadRom(ox::StringViewCR) noexcept {
return current + headerLen;
}
}
return OxError(1);
return ox::Error(1);
}
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;
}
ox::Error reloadAsset(keel::Context&, ox::StringView) noexcept {
return OxError(1, "reloadAsset is unsupported on this platform");
return ox::Error(1, "reloadAsset is unsupported on this platform");
}
}
@@ -238,16 +236,16 @@ ox::Error setRomFs(Context &ctx, ox::UPtr<ox::FileSystem> &&fs) noexcept {
return buildUuidMap(ctx);
}
ox::Result<ox::UniquePtr<ox::FileSystem>> loadRomFs(ox::StringViewCR path) noexcept {
ox::Result<ox::UPtr<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
return {ox::make_unique<ox::PassThroughFS>(path)};
#else
return OxError(2);
return ox::Error(2);
#endif
}
}

View File

@@ -17,7 +17,7 @@ static ox::Error writeFileBuff(ox::StringView path, ox::BufferView const buff) n
std::ofstream f(std::string(toStdStringView(path)), std::ios::binary);
f.write(buff.data(), static_cast<intptr_t>(buff.size()));
} catch (std::fstream::failure const&) {
return OxError(2, "failed to write file");
return ox::Error(2, "failed to write file");
}
return {};
}
@@ -26,7 +26,7 @@ static ox::Result<ox::Buffer> readFileBuff(ox::StringView path) noexcept {
std::ifstream file(std::string(toStdStringView(path)), std::ios::binary | std::ios::ate);
if (!file.good()) {
oxErrorf("Could not find OxFS file: {}", path);
return OxError(1, "Could not find OxFS file");
return ox::Error(1, "Could not find OxFS file");
}
try {
auto const size = static_cast<std::size_t>(file.tellg());
@@ -36,14 +36,14 @@ static ox::Result<ox::Buffer> readFileBuff(ox::StringView path) noexcept {
return buff;
} catch (std::ios_base::failure const&e) {
oxErrorf("Could not read OxFS file: {}", e.what());
return OxError(2, "Could not read OxFS file");
return ox::Error(2, "Could not read OxFS file");
}
}
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,56 +55,48 @@ 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 {};
}
static ox::Error run(ox::SpanView<char const*> argv, ox::StringView projectDataDir) noexcept {
ox::Error run(
[[maybe_unused]] ox::StringView project,
[[maybe_unused]] ox::StringView appName,
ox::StringView projectDataDir,
ox::SpanView<ox::CString> argv) noexcept {
ox::ClArgs const args(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");
return ox::Error(1, "must specify a source directory");
}
if (argRomBin == "") {
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 ox::Error(1, "must specify a path for preload file");
}
return pack(argSrc, argRomBin, argManifest, projectDataDir);
}
namespace olympic {
ox::Error run(
[[maybe_unused]] ox::StringView project,
[[maybe_unused]] ox::StringView appName,
ox::StringView projectDataDir,
ox::SpanView<char const*> argv) noexcept {
return ::run(argv, projectDataDir);
}
}

View File

@@ -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 {};
}

View File

@@ -18,7 +18,7 @@ static ox::Result<BaseConverter const*> findConverter(
return c;
}
}
return OxError(1, "Could not find converter");
return ox::Error(1, "Could not find converter");
};
static ox::Result<ox::UPtr<Wrap>> convert(
@@ -47,7 +47,7 @@ static ox::Result<ox::UPtr<Wrap>> convert(
return subConverter->convertPtrToPtr(ctx, *intermediate);
}
}
return OxError(1, "Could not convert between types");
return ox::Error(1, "Could not convert between types");
}
ox::Result<ox::UPtr<Wrap>> convert(
@@ -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),

View File

@@ -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;
}

View File

@@ -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 {};
}

View File

@@ -12,6 +12,7 @@ add_library(
)
target_compile_definitions(
StudioAppLib PUBLIC
OLYMPIC_GUI_APP=1
OLYMPIC_LOAD_STUDIO_MODULES=1
OLYMPIC_APP_NAME="Studio"
)

View File

@@ -37,7 +37,7 @@ static ox::Error runApp(
ox::StringViewCR appName,
ox::StringViewCR projectDataDir,
ox::UPtr<ox::FileSystem> &&fs) noexcept {
oxRequireM(ctx, turbine::init(std::move(fs), appName));
OX_REQUIRE_M(ctx, turbine::init(std::move(fs), appName));
turbine::setWindowTitle(*ctx, keelCtx(*ctx).appName);
turbine::setKeyEventHandler(*ctx, keyEventHandler);
turbine::setRefreshWithin(*ctx, 0);
@@ -67,14 +67,10 @@ static ox::Error run(
}
namespace olympic {
ox::Error run(
ox::StringView project,
ox::StringView appName,
ox::StringView projectDataDir,
ox::SpanView<char const*> args) noexcept {
ox::SpanView<ox::CString> args) noexcept {
return studio::run(ox::sfmt("{} {}", project, appName), projectDataDir, args);
}
}

View File

@@ -118,12 +118,12 @@ void NewMenu::drawLastPageButtons(studio::StudioContext &sctx) noexcept {
void NewMenu::finish(studio::StudioContext &sctx) noexcept {
if (m_itemName.len() == 0) {
oxLogError(OxError(1, "New file error: no file name"));
oxLogError(ox::Error(1, "New file error: no file name"));
return;
}
auto const&typeMaker = *m_types[static_cast<std::size_t>(m_selectedType)];
if (sctx.project->exists(typeMaker.itemPath(m_itemName))) {
oxLogError(OxError(1, "New file error: file already exists"));
oxLogError(ox::Error(1, "New file error: file already exists"));
return;
}
auto const [path, err] = typeMaker.write(sctx, m_itemName);

View File

@@ -16,16 +16,16 @@ static ox::Result<ox::UniquePtr<ProjectTreeModel>> buildProjectTreeModel(
ox::StringView path,
ProjectTreeModel *parent) noexcept {
auto const fs = explorer.romFs();
oxRequire(stat, fs->stat(path));
OX_REQUIRE(stat, fs->stat(path));
auto out = ox::make_unique<ProjectTreeModel>(explorer, ox::String(name), parent);
if (stat.fileType == ox::FileType::Directory) {
oxRequireM(children, fs->ls(path));
OX_REQUIRE_M(children, fs->ls(path));
std::sort(children.begin(), children.end());
ox::Vector<ox::UniquePtr<ProjectTreeModel>> outChildren;
for (auto const&childName : children) {
if (childName[0] != '.') {
auto const childPath = ox::sfmt("{}/{}", path, childName);
oxRequireM(child, buildProjectTreeModel(explorer, childName, childPath, out.get()));
OX_REQUIRE_M(child, buildProjectTreeModel(explorer, childName, childPath, out.get()));
outChildren.emplace_back(std::move(child));
}
}
@@ -52,9 +52,9 @@ void ProjectExplorer::setModel(ox::UPtr<ProjectTreeModel> &&model) noexcept {
}
ox::Error ProjectExplorer::refreshProjectTreeModel(ox::StringViewCR) noexcept {
oxRequireM(model, buildProjectTreeModel(*this, "Project", "/", nullptr));
OX_REQUIRE_M(model, buildProjectTreeModel(*this, "Project", "/", nullptr));
setModel(std::move(model));
return OxError(0);
return ox::Error(0);
}
}

View File

@@ -36,12 +36,12 @@ struct StudioConfig {
bool showProjectExplorer = true;
};
oxModelBegin(StudioConfig)
oxModelFieldRename(activeTabItemName, active_tab_item_name)
oxModelFieldRename(projectPath, project_path)
oxModelFieldRename(openFiles, open_files)
oxModelFieldRename(showProjectExplorer, show_project_explorer)
oxModelEnd()
OX_MODEL_BEGIN(StudioConfig)
OX_MODEL_FIELD_RENAME(activeTabItemName, active_tab_item_name)
OX_MODEL_FIELD_RENAME(projectPath, project_path)
OX_MODEL_FIELD_RENAME(openFiles, open_files)
OX_MODEL_FIELD_RENAME(showProjectExplorer, show_project_explorer)
OX_MODEL_END()
StudioUI::StudioUI(turbine::Context &ctx, ox::StringParam projectDataDir) noexcept:
m_sctx(*this, ctx),
@@ -222,7 +222,7 @@ void StudioUI::drawTabs() noexcept {
m_activeEditor = nullptr;
}
try {
oxThrowError(m_editors.erase(it).moveTo(it));
OX_THROW_ERROR(m_editors.erase(it).moveTo(it));
} catch (ox::Exception const&ex) {
oxErrf("Editor tab deletion failed: {} ({}:{})\n", ex.what(), ex.file, ex.line);
} catch (std::exception const&ex) {
@@ -323,15 +323,15 @@ void StudioUI::handleKeyInput() noexcept {
ox::Error StudioUI::createOpenProject(ox::StringViewCR path) noexcept {
std::error_code ec;
std::filesystem::create_directories(toStdStringView(path), ec);
oxReturnError(OxError(ec.value() != 0, "Could not create project directory"));
oxReturnError(openProjectPath(path));
OX_RETURN_ERROR(ox::Error(ec.value() != 0, "Could not create project directory"));
OX_RETURN_ERROR(openProjectPath(path));
return m_project->writeTypeStore();
}
ox::Error StudioUI::openProjectPath(ox::StringParam path) noexcept {
oxRequireM(fs, keel::loadRomFs(path.view()));
oxReturnError(keel::setRomFs(keelCtx(m_ctx), std::move(fs)));
oxReturnError(
OX_REQUIRE_M(fs, keel::loadRomFs(path.view()));
OX_RETURN_ERROR(keel::setRomFs(keelCtx(m_ctx), std::move(fs)));
OX_RETURN_ERROR(
ox::make_unique_catch<studio::Project>(keelCtx(m_ctx), std::move(path), m_projectDataDir)
.moveTo(m_project));
auto const sctx = applicationData<studio::StudioContext>(m_ctx);
@@ -354,7 +354,7 @@ ox::Error StudioUI::openFile(ox::StringViewCR path) noexcept {
ox::Error StudioUI::openFileActiveTab(ox::StringViewCR path, bool makeActiveTab) noexcept {
if (!m_project) {
return OxError(1, "No project open to open a file from");
return ox::Error(1, "No project open to open a file from");
}
if (m_openFiles.contains(path)) {
for (auto &e : m_editors) {
@@ -366,7 +366,7 @@ ox::Error StudioUI::openFileActiveTab(ox::StringViewCR path, bool makeActiveTab)
}
return {};
}
oxRequire(ext, studio::fileExt(path));
OX_REQUIRE(ext, studio::fileExt(path));
// create Editor
BaseEditor *editor = nullptr;
auto const err = m_editorMakers.contains(ext) ?

View File

@@ -60,11 +60,11 @@ ox::Error writeConfig(keel::Context &ctx, ox::StringViewCR name, T const&data) n
//oxErrf("Could not create config directory: {} - {}\n", path, toStr(err));
return err;
}
oxRequireM(buff, ox::writeOC(data));
OX_REQUIRE_M(buff, ox::writeOC(data));
*buff.back().value = '\n';
if (auto const err = fs.write(path, buff.data(), buff.size())) {
//oxErrf("Could not read config file: {} - {}\n", path, toStr(err));
return OxError(2, "Could not read config file");
return ox::Error(2, "Could not read config file");
}
return {};
}

View File

@@ -24,18 +24,18 @@ constexpr ImTextureID toImTextureID(ox::Unsigned_c auto id) noexcept
}
template<typename T>
ox::Result<T> getDragDropPayload(ox::CStringView name) noexcept {
ox::Result<T> getDragDropPayload(ox::CStringViewCR name) noexcept {
auto const payload = ImGui::AcceptDragDropPayload(name.c_str());
if (!payload) {
return OxError(1, "No drag/drop payload");
return ox::Error(1, "No drag/drop payload");
}
return ox::readClaw<T>({
reinterpret_cast<char const*>(payload->Data),
static_cast<size_t>(payload->DataSize)});
}
ox::Error setDragDropPayload(ox::CStringView name, auto const&obj) noexcept {
oxRequire(buff, ox::writeClaw(obj, ox::ClawFormat::Metal));
ox::Error setDragDropPayload(ox::CStringViewCR name, auto const&obj) noexcept {
OX_REQUIRE(buff, ox::writeClaw(obj, ox::ClawFormat::Metal));
ImGui::SetDragDropPayload(name.c_str(), buff.data(), buff.size());
return {};
}
@@ -88,7 +88,7 @@ class DragDropTarget {
}
};
inline auto dragDropTarget(auto const&cb) noexcept {
auto dragDropTarget(auto const&cb) noexcept {
if constexpr(ox::is_same_v<decltype(cb()), ox::Error>) {
if (ig::DragDropTarget const tgt; tgt) [[unlikely]] {
return cb();
@@ -104,7 +104,7 @@ inline auto dragDropTarget(auto const&cb) noexcept {
class ChildStackItem {
public:
explicit ChildStackItem(ox::CStringView id, ImVec2 const&sz = {}) noexcept;
explicit ChildStackItem(ox::CStringViewCR id, ImVec2 const&sz = {}) noexcept;
~ChildStackItem() noexcept;
};
@@ -112,7 +112,7 @@ class IDStackItem {
public:
explicit IDStackItem(int id) noexcept;
explicit IDStackItem(const char *id) noexcept;
explicit IDStackItem(ox::CStringView id) noexcept;
explicit IDStackItem(ox::CStringViewCR id) noexcept;
~IDStackItem() noexcept;
};
@@ -126,7 +126,7 @@ class IndentStackItem {
void centerNextWindow(turbine::Context &ctx) noexcept;
bool PushButton(ox::CStringView lbl, ImVec2 const&btnSz = BtnSz) noexcept;
bool PushButton(ox::CStringViewCR lbl, ImVec2 const&btnSz = BtnSz) noexcept;
template<typename Str>
struct TextInput {
@@ -180,7 +180,7 @@ PopupResponse PopupControlsOkCancel(float popupWidth, bool &popupOpen);
PopupResponse PopupControlsOkCancel(bool &popupOpen);
[[nodiscard]]
bool BeginPopup(turbine::Context &ctx, ox::CStringView popupName, bool &show, ImVec2 const&sz = {285, 0});
bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show, ImVec2 const&sz = {285, 0});
/**
*
@@ -199,19 +199,19 @@ bool ComboBox(ox::CStringView lbl, ox::Span<const ox::String> list, size_t &sele
* @return true if new value selected, false otherwise
*/
bool ComboBox(
ox::CStringView lbl,
ox::CStringViewCR lbl,
std::function<ox::CStringView(size_t)> const&f,
size_t strCnt,
size_t &selectedIdx) noexcept;
bool FileComboBox(
ox::CStringView lbl,
studio::StudioContext &sctx,
ox::StringView fileExt,
ox::CStringViewCR lbl,
StudioContext &sctx,
ox::StringViewCR fileExt,
size_t &selectedIdx) noexcept;
bool ListBox(
ox::CStringView name,
ox::CStringViewCR name,
std::function<ox::CStringView(size_t)> const&f,
size_t strCnt,
size_t &selIdx) noexcept;
@@ -223,7 +223,7 @@ bool ListBox(
* @param selIdx
* @return true if new value selected, false otherwise
*/
bool ListBox(ox::CStringView name, ox::Span<const ox::String> const&list, size_t &selIdx) noexcept;
bool ListBox(ox::CStringViewCR name, ox::SpanView<ox::String> const&list, size_t &selIdx) noexcept;
class FilePicker {
private:
@@ -237,8 +237,8 @@ class FilePicker {
FilePicker(
studio::StudioContext &sctx,
ox::String title,
ox::String fileExt,
ox::StringParam title,
ox::StringParam fileExt,
ImVec2 const&size = {}) noexcept;
void draw() noexcept;

View File

@@ -79,7 +79,7 @@ class ItemMakerT: public ItemMaker {
ox::Result<ox::String> write(studio::StudioContext &sctx, ox::StringView const pName) const noexcept override {
auto const path = itemPath(pName);
createUuidMapping(keelCtx(sctx.tctx), path, ox::UUID::generate().unwrap());
oxReturnError(sctx.project->writeObj(path, m_item, m_fmt));
OX_RETURN_ERROR(sctx.project->writeObj(path, m_item, m_fmt));
return path;
}
};

View File

@@ -31,7 +31,7 @@ enum class ProjectEvent {
constexpr ox::Result<ox::StringView> fileExt(ox::StringViewCR path) noexcept {
auto const extStart = ox::find(path.crbegin(), path.crend(), '.').offset();
if (!extStart) {
return OxError(1, "file path does not have valid extension");
return ox::Error(1, "file path does not have valid extension");
}
return substr(path, extStart + 1);
}
@@ -130,39 +130,39 @@ class Project {
template<typename T>
ox::Error Project::writeObj(ox::StringViewCR path, T const&obj, ox::ClawFormat fmt) noexcept {
oxRequireM(buff, ox::writeClaw(obj, fmt));
OX_REQUIRE_M(buff, ox::writeClaw(obj, fmt));
if (fmt == ox::ClawFormat::Organic) {
buff.pop_back();
}
// write to FS
oxReturnError(mkdir(parentDir(path)));
oxReturnError(writeBuff(path, buff));
OX_RETURN_ERROR(mkdir(parentDir(path)));
OX_RETURN_ERROR(writeBuff(path, buff));
// write type descriptor
if (m_typeStore.get<T>().error) {
oxReturnError(ox::buildTypeDef(m_typeStore, obj));
OX_RETURN_ERROR(ox::buildTypeDef(m_typeStore, obj));
}
oxRequire(desc, m_typeStore.get<T>());
OX_REQUIRE(desc, m_typeStore.get<T>());
auto const descPath = ox::sfmt("{}/{}", m_typeDescPath, buildTypeId(*desc));
auto const descExists = m_fs.exists(descPath);
if (!descExists) {
oxReturnError(writeTypeStore());
OX_RETURN_ERROR(writeTypeStore());
}
oxReturnError(keel::reloadAsset(m_ctx, path));
oxRequire(uuid, pathToUuid(m_ctx, path));
OX_RETURN_ERROR(keel::reloadAsset(m_ctx, path));
OX_REQUIRE(uuid, pathToUuid(m_ctx, path));
fileUpdated.emit(path, uuid);
return {};
}
template<typename T>
ox::Error Project::writeObj(ox::StringViewCR path, T const&obj) noexcept {
oxRequire(ext, fileExt(path));
OX_REQUIRE(ext, fileExt(path));
auto const fmt = m_typeFmt[ext].or_value(ox::ClawFormat::Metal);
return writeObj(path, obj, fmt);
}
template<typename T>
ox::Result<T> Project::loadObj(ox::StringViewCR path) const noexcept {
oxRequire(buff, loadBuff(path));
OX_REQUIRE(buff, loadBuff(path));
if constexpr(ox::is_same_v<T, ox::ModelObject>) {
return keel::readAsset(m_typeStore, buff);
} else {
@@ -180,7 +180,7 @@ ox::Error Project::subscribe(ProjectEvent e, ox::SignalHandler *tgt, Functor &&s
break;
case ProjectEvent::FileRecognized:
{
oxRequire(files, listFiles());
OX_REQUIRE(files, listFiles());
for (auto const&f : files) {
slot(f);
}

View File

@@ -1,3 +1,6 @@
/*
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
@@ -30,7 +33,7 @@ constexpr auto iterateSelection(studio::Selection const&sel, auto const&cb) {
for (auto x = sel.a.x; x <= sel.b.x; ++x) {
for (auto y = sel.a.y; y <= sel.b.y; ++y) {
if constexpr(retErr) {
oxReturnError(cb(x, y));
OX_RETURN_ERROR(cb(x, y));
} else {
cb(x, y);
}
@@ -46,7 +49,7 @@ constexpr auto iterateSelectionRows(studio::Selection const&sel, auto const&cb)
for (auto y = sel.a.y; y <= sel.b.y; ++y) {
for (auto x = sel.a.x; x <= sel.b.x; ++x) {
if constexpr(retErr) {
oxReturnError(cb(x, y));
OX_RETURN_ERROR(cb(x, y));
} else {
cb(x, y);
}

View File

@@ -31,9 +31,9 @@ OX_ALLOW_UNSAFE_BUFFERS_END
return out;
}
case NFD_CANCEL:
return OxError(1, "Operation cancelled");
return ox::Error(1, "Operation cancelled");
default:
return OxError(2, NFD::GetError());
return ox::Error(2, NFD::GetError());
}
}

View File

@@ -10,7 +10,7 @@
namespace studio::ig {
ChildStackItem::ChildStackItem(ox::CStringView id, ImVec2 const&sz) noexcept {
ChildStackItem::ChildStackItem(ox::CStringViewCR id, ImVec2 const&sz) noexcept {
ImGui::BeginChild(id.c_str(), sz);
}
@@ -26,7 +26,7 @@ IDStackItem::IDStackItem(const char *id) noexcept {
ImGui::PushID(id);
}
IDStackItem::IDStackItem(ox::CStringView id) noexcept: IDStackItem(id.c_str()) {}
IDStackItem::IDStackItem(ox::CStringViewCR id) noexcept: IDStackItem(id.c_str()) {}
IDStackItem::~IDStackItem() noexcept {
ImGui::PopID();
@@ -50,7 +50,7 @@ void centerNextWindow(turbine::Context &ctx) noexcept {
ImGui::SetNextWindowPos(ImVec2(screenW / mod, screenH / mod), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
}
bool PushButton(ox::CStringView lbl, ImVec2 const&btnSz) noexcept {
bool PushButton(ox::CStringViewCR lbl, ImVec2 const&btnSz) noexcept {
return ImGui::Button(lbl.c_str(), btnSz);
}
@@ -77,7 +77,7 @@ PopupResponse PopupControlsOkCancel(bool &popupOpen) {
return PopupControlsOkCancel(ImGui::GetContentRegionAvail().x + 17, popupOpen);
}
bool BeginPopup(turbine::Context &ctx, ox::CStringView popupName, bool &show, ImVec2 const&sz) {
bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show, ImVec2 const&sz) {
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
centerNextWindow(ctx);
ImGui::OpenPopup(popupName.c_str());
@@ -105,7 +105,7 @@ bool ComboBox(
}
bool ComboBox(
ox::CStringView lbl,
ox::CStringViewCR lbl,
std::function<ox::CStringView(size_t)> const&f,
size_t strCnt,
size_t &selectedIdx) noexcept {
@@ -125,16 +125,16 @@ bool ComboBox(
}
bool FileComboBox(
ox::CStringView lbl,
ox::CStringViewCR lbl,
StudioContext &sctx,
ox::StringView fileExt,
ox::StringViewCR fileExt,
size_t &selectedIdx) noexcept {
auto const&list = sctx.project->fileList(fileExt);
return ComboBox(lbl, list, selectedIdx);
}
bool ListBox(
ox::CStringView name,
ox::CStringViewCR name,
std::function<ox::CStringView(size_t)> const&f,
size_t strCnt,
size_t &selIdx) noexcept {
@@ -155,7 +155,7 @@ bool ListBox(
return out;
}
bool ListBox(ox::CStringView name, ox::Span<const ox::String> const&list, size_t &selIdx) noexcept {
bool ListBox(ox::CStringViewCR name, ox::SpanView<ox::String> const&list, size_t &selIdx) noexcept {
return ListBox(name, [list](size_t i) -> ox::CStringView {
return list[i];
}, list.size(), selIdx);
@@ -164,8 +164,8 @@ bool ListBox(ox::CStringView name, ox::Span<const ox::String> const&list, size_t
FilePicker::FilePicker(
StudioContext &sctx,
ox::String title,
ox::String fileExt,
ox::StringParam title,
ox::StringParam fileExt,
ImVec2 const&size) noexcept:
m_sctx(sctx),
m_title(std::move(title)),

View File

@@ -36,7 +36,7 @@ Project::Project(keel::Context &ctx, ox::String path, ox::StringViewCR projectDa
oxTracef("studio", "Project: {}", m_path);
generateTypes(m_typeStore);
if (ox::defines::Debug) {
oxThrowError(writeTypeStore());
OX_THROW_ERROR(writeTypeStore());
}
buildFileIndex();
}
@@ -44,7 +44,7 @@ Project::Project(keel::Context &ctx, ox::String path, ox::StringViewCR projectDa
ox::Error Project::create() noexcept {
std::error_code ec;
std::filesystem::create_directory(m_path.toStdString(), ec);
return OxError(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: mkdir failed");
return ox::Error(static_cast<ox::ErrorCode>(ec.value()), "PassThroughFS: mkdir failed");
}
ox::String const&Project::projectPath() const noexcept {
@@ -58,11 +58,11 @@ ox::FileSystem &Project::romFs() noexcept {
ox::Error Project::mkdir(ox::StringViewCR path) const noexcept {
auto const [stat, err] = m_fs.stat(path);
if (err) {
oxReturnError(m_fs.mkdir(path, true));
OX_RETURN_ERROR(m_fs.mkdir(path, true));
fileUpdated.emit(path, {});
}
return stat.fileType == ox::FileType::Directory ?
ox::Error{} : OxError(1, "path exists as normal file");
ox::Error{} : ox::Error(1, "path exists as normal file");
}
ox::Result<ox::FileStat> Project::stat(ox::StringViewCR path) const noexcept {
@@ -79,12 +79,12 @@ ox::Vector<ox::String> const&Project::fileList(ox::StringViewCR ext) noexcept {
ox::Error Project::writeTypeStore() noexcept {
// write all descriptors because we don't know which types T depends on
oxReturnError(mkdir(m_typeDescPath));
OX_RETURN_ERROR(mkdir(m_typeDescPath));
for (auto const &t: m_typeStore.typeList()) {
oxRequire(typeOut, ox::writeClaw(*t, ox::ClawFormat::Organic));
OX_REQUIRE(typeOut, ox::writeClaw(*t, ox::ClawFormat::Organic));
// write to FS
auto const typePath = ox::sfmt("{}/{}", m_typeDescPath, buildTypeId(*t));
oxReturnError(writeBuff(typePath, {typeOut.data(), typeOut.size() - 1}));
OX_RETURN_ERROR(writeBuff(typePath, {typeOut.data(), typeOut.size() - 1}));
}
return {};
}
@@ -119,11 +119,11 @@ ox::Error Project::writeBuff(ox::StringViewCR path, ox::BufferView const&buff) n
ox::BufferWriter writer(&outBuff);
auto const [uuid, err] = pathToUuid(m_ctx, path);
if (!err) {
oxReturnError(keel::writeUuidHeader(writer, uuid));
OX_RETURN_ERROR(keel::writeUuidHeader(writer, uuid));
}
oxReturnError(writer.write(buff.data(), buff.size()));
OX_RETURN_ERROR(writer.write(buff.data(), buff.size()));
auto const newFile = m_fs.stat(path).error != 0;
oxReturnError(m_fs.write(path, outBuff.data(), outBuff.size(), ox::FileType::NormalFile));
OX_RETURN_ERROR(m_fs.write(path, outBuff.data(), outBuff.size(), ox::FileType::NormalFile));
if (newFile) {
fileAdded.emit(path);
indexFile(path);
@@ -138,16 +138,16 @@ ox::Result<ox::Buffer> Project::loadBuff(ox::StringViewCR path) const noexcept {
}
ox::Error Project::lsProcDir(ox::Vector<ox::String> *paths, ox::StringViewCR path) const noexcept {
oxRequire(files, m_fs.ls(path));
OX_REQUIRE(files, m_fs.ls(path));
for (auto const&name : files) {
auto fullPath = ox::sfmt("{}/{}", path, name);
oxRequire(stat, m_fs.stat(ox::StringView(fullPath)));
OX_REQUIRE(stat, m_fs.stat(ox::StringView(fullPath)));
switch (stat.fileType) {
case ox::FileType::NormalFile:
paths->emplace_back(std::move(fullPath));
break;
case ox::FileType::Directory:
oxReturnError(lsProcDir(paths, fullPath));
OX_RETURN_ERROR(lsProcDir(paths, fullPath));
break;
case ox::FileType::None:
break;
@@ -158,7 +158,7 @@ ox::Error Project::lsProcDir(ox::Vector<ox::String> *paths, ox::StringViewCR pat
ox::Result<ox::Vector<ox::String>> Project::listFiles(ox::StringViewCR path) const noexcept {
ox::Vector<ox::String> paths;
oxReturnError(lsProcDir(&paths, path));
OX_RETURN_ERROR(lsProcDir(&paths, path));
return paths;
}

View File

@@ -1,3 +1,6 @@
/*
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <studio/undocommand.hpp>

View File

@@ -10,7 +10,7 @@ ox::Error UndoStack::push(ox::UPtr<UndoCommand> &&cmd) noexcept {
for (auto const i = m_stackIdx; i < m_stack.size();) {
std::ignore = m_stack.erase(i);
}
oxReturnError(cmd->redo());
OX_RETURN_ERROR(cmd->redo());
redoTriggered.emit(cmd.get());
changeTriggered.emit(cmd.get());
if (m_stack.empty() || !(*m_stack.back().value)->mergeWith(*cmd)) {
@@ -27,7 +27,7 @@ ox::Error UndoStack::push(ox::UPtr<UndoCommand> &&cmd) noexcept {
ox::Error UndoStack::redo() noexcept {
if (m_stackIdx < m_stack.size()) {
auto &c = m_stack[m_stackIdx];
oxReturnError(c->redo());
OX_RETURN_ERROR(c->redo());
++m_stackIdx;
redoTriggered.emit(c.get());
changeTriggered.emit(c.get());
@@ -38,7 +38,7 @@ ox::Error UndoStack::redo() noexcept {
ox::Error UndoStack::undo() noexcept {
if (m_stackIdx) {
auto &c = m_stack[--m_stackIdx];
oxReturnError(c->undo());
OX_RETURN_ERROR(c->undo());
undoTriggered.emit(c.get());
changeTriggered.emit(c.get());
}

View File

@@ -38,7 +38,7 @@ ox::Result<BaseClipboardObject*> getClipboardData(Context &ctx, ox::StringView t
template<typename T>
ox::Result<T*> getClipboardObject(Context &ctx) noexcept {
oxRequire(p, getClipboardData(ctx, ox::ModelTypeId_v<T>));
OX_REQUIRE(p, getClipboardData(ctx, ox::ModelTypeId_v<T>));
return dynamic_cast<T*>(p);
}

View File

@@ -18,6 +18,8 @@ using TimeMs = uint64_t;
ox::Result<ContextUPtr> init(ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept;
ox::Result<ContextUPtr> init(ox::StringViewCR fsPath, ox::StringViewCR appName) noexcept;
ox::Error run(Context &ctx) noexcept;
// Returns the number of milliseconds that have passed since the start of the

View File

@@ -18,6 +18,11 @@ target_include_directories(
../include
)
target_sources(
Turbine PUBLIC
turbine.cpp
)
target_link_libraries(
Turbine PUBLIC
Keel

View File

@@ -44,7 +44,7 @@ ox::Bounds getWindowBounds(Context&) noexcept {
}
ox::Error setWindowBounds(Context&, ox::Bounds const&) noexcept {
return OxError(1, "setWindowBounds not supported on GBA");
return ox::Error(1, "setWindowBounds not supported on GBA");
}
}

View File

@@ -55,17 +55,17 @@ OX_ALLOW_UNSAFE_BUFFERS_BEGIN
}
}
OX_ALLOW_UNSAFE_BUFFERS_END
return OxError(1);
return ox::Error(1);
}
ox::Result<ContextUPtr> init(
ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept {
auto ctx = ox::make_unique<Context>();
oxReturnError(keel::init(ctx->keelCtx, std::move(fs), appName));
OX_RETURN_ERROR(keel::init(ctx->keelCtx, std::move(fs), appName));
#ifdef OX_BARE_METAL
oxReturnError(findPreloadSection().moveTo(ctx->keelCtx.preloadSectionOffset));
OX_RETURN_ERROR(findPreloadSection().moveTo(ctx->keelCtx.preloadSectionOffset));
#endif
oxReturnError(initGfx(*ctx));
OX_RETURN_ERROR(initGfx(*ctx));
initTimer();
initIrq();
return ox::UPtr<turbine::Context, ContextDeleter>(std::move(ctx));

View File

@@ -30,7 +30,7 @@ ox::Result<BaseClipboardObject*> getClipboardData(Context &ctx, ox::StringView t
if (ctx.clipboard && ctx.clipboard->typeId() == typeId) {
return ctx.clipboard.get();
}
return OxError(1);
return ox::Error(1);
}
}

View File

@@ -4,8 +4,11 @@
#pragma once
#include <turbine/turbine.hpp>
namespace turbine::config {
constexpr bool GlFpsPrint = TURBINE_GL_FPS_PRINT;
inline constexpr bool GlFpsPrint = TURBINE_GL_FPS_PRINT;
inline constexpr TimeMs MandatoryRefreshPeriod = 168;
}

View File

@@ -20,7 +20,7 @@ class Context {
ox::AnyPtr applicationData;
// GLFW impl data ////////////////////////////////////////////////////////
int uninterruptedRefreshes = 3;
TimeMs mandatoryRefreshPeriodEnd{};
ox::UPtr<BaseClipboardObject> clipboard;
struct GLFWwindow *window = nullptr;
int refreshWithinMs = 0;

View File

@@ -9,6 +9,8 @@
#include <imgui_impl_opengl3.h>
#endif
#include "config.hpp"
#include <ox/std/span.hpp>
#include "context.hpp"
@@ -62,10 +64,13 @@ static void handleKeyPress(Context &ctx, int key, bool down) noexcept {
return map;
}();
auto const eventHandler = keyEventHandler(ctx);
auto const k = keyMap[static_cast<std::size_t>(key)];
setKeyDownStatus(ctx, k, down);
if (eventHandler) {
eventHandler(ctx, k, down);
auto const keyIdx = static_cast<std::size_t>(key);
if (keyIdx < keyMap.size()) {
auto const k = keyMap[keyIdx];
setKeyDownStatus(ctx, k, down);
if (eventHandler) {
eventHandler(ctx, k, down);
}
}
}
@@ -73,17 +78,17 @@ static void handleGlfwCursorPosEvent(GLFWwindow*, double, double) noexcept {
}
static void handleGlfwMouseButtonEvent(GLFWwindow *window, int, int, int) noexcept {
auto const ctx = static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx->uninterruptedRefreshes = 25;
auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx.mandatoryRefreshPeriodEnd = ticksMs(ctx) + config::MandatoryRefreshPeriod;
}
static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept {
auto const ctx = static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx->uninterruptedRefreshes = 25;
auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx.mandatoryRefreshPeriodEnd = ticksMs(ctx) + config::MandatoryRefreshPeriod;
if (action == GLFW_PRESS) {
handleKeyPress(*ctx, key, true);
handleKeyPress(ctx, key, true);
} else if (action == GLFW_RELEASE) {
handleKeyPress(*ctx, key, false);
handleKeyPress(ctx, key, false);
}
}
@@ -199,7 +204,7 @@ ox::Error initGfx(Context &ctx) noexcept {
ctx.window = glfwCreateWindow(240 * Scale, 160 * Scale, ctx.keelCtx.appName.c_str(), nullptr, nullptr);
//ctx.window = glfwCreateWindow(876, 743, ctx.keelCtx.appName.c_str(), nullptr, nullptr);
if (ctx.window == nullptr) {
return OxError(1, "Could not open GLFW window");
return ox::Error(1, "Could not open GLFW window");
}
glfwSetCursorPosCallback(ctx.window, handleGlfwCursorPosEvent);
glfwSetMouseButtonCallback(ctx.window, handleGlfwMouseButtonEvent);
@@ -207,7 +212,7 @@ ox::Error initGfx(Context &ctx) noexcept {
glfwSetWindowUserPointer(ctx.window, &ctx);
glfwMakeContextCurrent(ctx.window);
if (!gladLoadGLES2Loader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress))) {
return OxError(2, "Could not init Glad");
return ox::Error(2, "Could not init Glad");
}
#if TURBINE_USE_IMGUI
IMGUI_CHECKVERSION();

View File

@@ -43,12 +43,12 @@ static void draw(GLFWwindow *window, int, int) noexcept {
ox::Result<ContextUPtr> init(
ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept {
auto ctx = ox::make_unique<Context>();
oxReturnError(keel::init(ctx->keelCtx, std::move(fs), appName));
OX_RETURN_ERROR(keel::init(ctx->keelCtx, std::move(fs), appName));
using namespace std::chrono;
ctx->startTime = static_cast<TimeMs>(
duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count());
glfwInit();
oxReturnError(initGfx(*ctx));
OX_RETURN_ERROR(initGfx(*ctx));
glfwSetWindowSizeCallback(ctx->window, draw);
return ox::UPtr<Context, ContextDeleter>(ctx.release());
}
@@ -88,12 +88,8 @@ ox::Error run(Context &ctx) noexcept {
tickFps(ctx, ticks);
draw(ctx);
auto const realSleepTime = ox::min(static_cast<uint64_t>(ctx.refreshWithinMs), sleepTime);
if (realSleepTime) {
if (ctx.uninterruptedRefreshes) {
--ctx.uninterruptedRefreshes;
} else {
glfwWaitEventsTimeout(static_cast<double>(realSleepTime) / 1000);
}
if (realSleepTime && ctx.mandatoryRefreshPeriodEnd <= ticks) {
glfwWaitEventsTimeout(static_cast<double>(realSleepTime) / 1000);
}
}
shutdown(ctx);

View File

@@ -0,0 +1,16 @@
/*
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <keel/keel.hpp>
#include <turbine/turbine.hpp>
namespace turbine {
ox::Result<ContextUPtr> init(ox::StringViewCR fsPath, ox::StringViewCR appName) noexcept {
OX_REQUIRE_M(fs, keel::loadRomFs(fsPath));
return init(std::move(fs), appName);
}
}