Compare commits

..

No commits in common. "5169a607cf009b6a75dfc418e2f779eae3f0eef9" and "ee63a4a1e40ce03069c20ba558bbff6e79fa1142" have entirely different histories.

4 changed files with 42 additions and 45 deletions

View File

@ -36,7 +36,7 @@ ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView buff) no
return ox::readClaw(ts, buff); return ox::readClaw(ts, buff);
} }
ox::Result<ox::StringView> readAssetTypeId(ox::BufferView const buff) noexcept { ox::Result<ox::StringView> readAssetTypeId(ox::BufferView buff) noexcept {
const auto err = readUuidHeader(buff).error; const auto err = readUuidHeader(buff).error;
const auto offset = err ? 0u : K1HdrSz; const auto offset = err ? 0u : K1HdrSz;
if (offset >= buff.size()) [[unlikely]] { if (offset >= buff.size()) [[unlikely]] {

View File

@ -6,11 +6,13 @@
#include <ox/clargs/clargs.hpp> #include <ox/clargs/clargs.hpp>
#include <ox/fs/fs.hpp> #include <ox/fs/fs.hpp>
#include <ox/logconn/def.hpp>
#include <ox/logconn/logconn.hpp>
#include <ox/oc/write.hpp> #include <ox/oc/write.hpp>
#include <keel/keel.hpp> #include <keel/keel.hpp>
static ox::Error writeFileBuff(ox::StringViewCR path, ox::BufferView const &buff) noexcept { static ox::Error writeFileBuff(ox::StringView path, ox::BufferView const buff) noexcept {
try { try {
std::ofstream f(std::string(toStdStringView(path)), std::ios::binary); std::ofstream f(std::string(toStdStringView(path)), std::ios::binary);
f.write(buff.data(), static_cast<intptr_t>(buff.size())); f.write(buff.data(), static_cast<intptr_t>(buff.size()));
@ -20,7 +22,7 @@ static ox::Error writeFileBuff(ox::StringViewCR path, ox::BufferView const &buff
return {}; return {};
} }
static ox::Result<ox::Buffer> readFileBuff(ox::StringViewCR path) noexcept { static ox::Result<ox::Buffer> readFileBuff(ox::StringView path) noexcept {
std::ifstream file(std::string(toStdStringView(path)), std::ios::binary | std::ios::ate); std::ifstream file(std::string(toStdStringView(path)), std::ios::binary | std::ios::ate);
if (!file.good()) { if (!file.good()) {
oxErrorf("Could not find OxFS file: {}", path); oxErrorf("Could not find OxFS file: {}", path);
@ -40,7 +42,7 @@ static ox::Result<ox::Buffer> readFileBuff(ox::StringViewCR path) noexcept {
static ox::Error generateTypes(ox::TypeStore &ts) noexcept { static ox::Error generateTypes(ox::TypeStore &ts) noexcept {
for (auto const mod : keel::modules()) { for (auto const mod : keel::modules()) {
for (auto const gen : mod->types()) { for (auto gen : mod->types()) {
OX_RETURN_ERROR(gen(ts)); OX_RETURN_ERROR(gen(ts));
} }
} }
@ -48,10 +50,10 @@ static ox::Error generateTypes(ox::TypeStore &ts) noexcept {
} }
static ox::Error pack( static ox::Error pack(
ox::StringViewCR argSrc, ox::StringView argSrc,
ox::StringViewCR argRomBin, ox::StringView argRomBin,
ox::StringViewCR argManifest, ox::StringView argManifest,
ox::StringViewCR projectDataDir) noexcept { ox::StringView projectDataDir) noexcept {
ox::Buffer dstBuff(32 * ox::units::MB); ox::Buffer dstBuff(32 * ox::units::MB);
OX_RETURN_ERROR(ox::FileSystem32::format(dstBuff.data(), dstBuff.size())); OX_RETURN_ERROR(ox::FileSystem32::format(dstBuff.data(), dstBuff.size()));
ox::FileSystem32 dst(dstBuff); ox::FileSystem32 dst(dstBuff);
@ -80,10 +82,10 @@ static ox::Error pack(
} }
ox::Error run( ox::Error run(
[[maybe_unused]] ox::StringView const project, [[maybe_unused]] ox::StringView project,
[[maybe_unused]] ox::StringView const appName, [[maybe_unused]] ox::StringView appName,
ox::StringView const projectDataDir, ox::StringView projectDataDir,
ox::SpanView<ox::CString> const argv) noexcept { ox::SpanView<ox::CString> argv) noexcept {
ox::ClArgs const args(argv); ox::ClArgs const args(argv);
auto const argSrc = args.getString("src", ""); auto const argSrc = args.getString("src", "");
auto const argRomBin = args.getString("rom-bin", ""); auto const argRomBin = args.getString("rom-bin", "");

View File

@ -11,12 +11,13 @@
namespace keel { namespace keel {
static ox::Error pathToInode( static ox::Error pathToInode(
Context &ctx, keel::Context &ctx,
ox::FileSystem const &dest, ox::FileSystem &dest,
ox::ModelObject &obj) noexcept { ox::ModelObject &obj) noexcept {
OX_REQUIRE(typeVal, obj.at("type")); auto &o = obj;
OX_REQUIRE(typeVal, o.at("type"));
auto const type = static_cast<ox::FileAddressType>(typeVal->get<int8_t>()); auto const type = static_cast<ox::FileAddressType>(typeVal->get<int8_t>());
OX_REQUIRE(dataVal, obj.at("data")); OX_REQUIRE(dataVal, o.at("data"));
auto &data = dataVal->get<ox::ModelUnion>(); auto &data = dataVal->get<ox::ModelUnion>();
ox::String path; ox::String path;
switch (type) { switch (type) {
@ -46,17 +47,13 @@ static ox::Error pathToInode(
} }
static ox::Error transformFileAddressesObj( static ox::Error transformFileAddressesObj(
Context &ctx, keel::Context &ctx, ox::FileSystem &dest, ox::ModelObject &obj) noexcept;
ox::FileSystem const &dest,
ox::ModelObject &obj) noexcept;
static ox::Error transformFileAddressesVec( static ox::Error transformFileAddressesVec(
Context &ctx, keel::Context &ctx, ox::FileSystem &dest, ox::ModelValueVector &v) noexcept;
ox::FileSystem const &dest,
ox::ModelValueVector &v) noexcept;
static ox::Error transformFileAddresses( static ox::Error transformFileAddresses(
Context &ctx, keel::Context &ctx,
ox::FileSystem const &dest, ox::FileSystem &dest,
ox::ModelValue &v) noexcept { ox::ModelValue &v) noexcept {
if (v.type() == ox::ModelValue::Type::Object) { if (v.type() == ox::ModelValue::Type::Object) {
auto &obj = v.get<ox::ModelObject>(); auto &obj = v.get<ox::ModelObject>();
@ -69,8 +66,8 @@ static ox::Error transformFileAddresses(
} }
static ox::Error transformFileAddressesVec( static ox::Error transformFileAddressesVec(
Context &ctx, keel::Context &ctx,
ox::FileSystem const &dest, ox::FileSystem &dest,
ox::ModelValueVector &v) noexcept { ox::ModelValueVector &v) noexcept {
for (auto &f : v) { for (auto &f : v) {
OX_RETURN_ERROR(transformFileAddresses(ctx, dest, f)); OX_RETURN_ERROR(transformFileAddresses(ctx, dest, f));
@ -83,13 +80,13 @@ static ox::Error transformFileAddressesVec(
* @return error * @return error
*/ */
static ox::Error transformFileAddressesObj( static ox::Error transformFileAddressesObj(
Context &ctx, keel::Context &ctx,
ox::FileSystem const &dest, ox::FileSystem &dest,
ox::ModelObject &obj) noexcept { ox::ModelObject &obj) noexcept {
if (obj.typeName() == "net.drinkingtea.ox.FileAddress" && obj.typeVersion() == 1) { if (obj.typeName() == "net.drinkingtea.ox.FileAddress" && obj.typeVersion() == 1) {
return pathToInode(ctx, dest, obj); return pathToInode(ctx, dest, obj);
} }
for (auto const &f : obj) { for (auto &f : obj) {
auto &v = f->value; auto &v = f->value;
OX_RETURN_ERROR(transformFileAddresses(ctx, dest, v)); OX_RETURN_ERROR(transformFileAddresses(ctx, dest, v));
} }
@ -114,7 +111,7 @@ static ox::Error performPackTransforms(
static ox::Error doTransformations( static ox::Error doTransformations(
Manifest &manifest, Manifest &manifest,
Context &ctx, keel::Context &ctx,
ox::TypeStore &ts, ox::TypeStore &ts,
ox::FileSystem &dest, ox::FileSystem &dest,
ox::StringViewCR filePath) noexcept { ox::StringViewCR filePath) noexcept {
@ -137,7 +134,7 @@ static ox::Error doTransformations(
// transformations need to be done after the copy to the new FS is complete // transformations need to be done after the copy to the new FS is complete
static ox::Error transformClaw( static ox::Error transformClaw(
Manifest &manifest, Manifest &manifest,
Context &ctx, keel::Context &ctx,
ox::TypeStore &ts, ox::TypeStore &ts,
ox::FileSystem &dest, ox::FileSystem &dest,
ox::StringViewCR path) noexcept { ox::StringViewCR path) noexcept {
@ -203,7 +200,7 @@ static ox::Error copy(
ox::Error pack( ox::Error pack(
Manifest &manifest, Manifest &manifest,
Context &ctx, keel::Context &ctx,
ox::TypeStore &ts, ox::TypeStore &ts,
ox::FileSystem &dest) noexcept { ox::FileSystem &dest) noexcept {
OX_RETURN_ERROR(copy(manifest, *ctx.rom, dest, "/")); OX_RETURN_ERROR(copy(manifest, *ctx.rom, dest, "/"));

View File

@ -247,20 +247,18 @@ static ox::Result<IconData> toGlfwImgPixels(ox::SpanView<uint8_t> const &iconPng
} }
ox::Error setWindowIcon(Context &ctx, ox::SpanView<ox::SpanView<uint8_t>> const &iconPngs) noexcept { ox::Error setWindowIcon(Context &ctx, ox::SpanView<ox::SpanView<uint8_t>> const &iconPngs) noexcept {
if constexpr(ox::defines::OS != ox::OS::Darwin) { ox::Vector<IconData, 8> src;
ox::Vector<IconData, 8> src; ox::Vector<GLFWimage, 8> imgs;
ox::Vector<GLFWimage, 8> imgs; for (auto const &iconPng : iconPngs) {
for (auto const &iconPng : iconPngs) { OX_RETURN_ERROR(toGlfwImgPixels(iconPng).moveTo(src.emplace_back()));
OX_RETURN_ERROR(toGlfwImgPixels(iconPng).moveTo(src.emplace_back())); auto &icon = *src.back().unwrap();
auto &icon = *src.back().unwrap(); imgs.emplace_back(GLFWimage{
imgs.emplace_back(GLFWimage{ .width = icon.w,
.width = icon.w, .height = icon.h,
.height = icon.h, .pixels = icon.pixels.data(),
.pixels = icon.pixels.data(), });
});
}
glfwSetWindowIcon(ctx.window, static_cast<int>(imgs.size()), imgs.data());
} }
glfwSetWindowIcon(ctx.window, static_cast<int>(imgs.size()), imgs.data());
return {}; return {};
} }