From 86a3bf1248f143cb5202f8691ee363a453434329 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 12 Feb 2023 23:37:58 -0600 Subject: [PATCH] [nostalgia] Make assets loadable through UUID references --- sample_project/Palettes/Charset.npal | Bin 53 -> 94 bytes sample_project/Palettes/Chester.npal | 2 +- sample_project/Palettes/Dirt.npal | 2 +- sample_project/Palettes/Logo.npal | 2 +- sample_project/Scenes/Chester.nscn | Bin 1207 -> 1268 bytes sample_project/TileSheets/Charset.ng | Bin 908 -> 949 bytes sample_project/TileSheets/Chester.ng | Bin 255 -> 296 bytes sample_project/TileSheets/Dirt.ng | Bin 106 -> 147 bytes sample_project/TileSheets/Logo.ng | Bin 199 -> 241 bytes sample_project/TileSheets/NS_Logo.ng | Bin 164 -> 205 bytes src/nostalgia/foundation/context.hpp | 1 - src/nostalgia/foundation/media.hpp | 12 ++++++++---- src/nostalgia/tools/pack/pack.cpp | 28 +++++++++++++++------------ 13 files changed, 27 insertions(+), 20 deletions(-) diff --git a/sample_project/Palettes/Charset.npal b/sample_project/Palettes/Charset.npal index 4a1ca05d50e1c135029b134394720602fe55b6f0..14f5f59a0697afd3faf564ba31b5c30341889b13 100644 GIT binary patch delta 47 zcmXqw)9^F2HnFfYO-wSd&`mN=OVKqkHa6F_Fif@7O|&pDG&VFdOEot#ww_?h$OQlw CD+@pX delta 5 Mcmazuov2|700id&f&c&j diff --git a/sample_project/Palettes/Chester.npal b/sample_project/Palettes/Chester.npal index e818a266..77a2e047 100644 --- a/sample_project/Palettes/Chester.npal +++ b/sample_project/Palettes/Chester.npal @@ -1 +1 @@ -M2;net.drinkingtea.nostalgia.core.Palette;1;ûÿ³Ö \ No newline at end of file +N1;14fc3dd8-42ff-4bf9-81f1-a010cc5ac251;M2;net.drinkingtea.nostalgia.core.Palette;1;ûÿ³Ö diff --git a/sample_project/Palettes/Dirt.npal b/sample_project/Palettes/Dirt.npal index 8be698b1..4e80b693 100644 --- a/sample_project/Palettes/Dirt.npal +++ b/sample_project/Palettes/Dirt.npal @@ -1 +1 @@ -M2;net.drinkingtea.nostalgia.core.Palette;1;ûÿ³Ö \ No newline at end of file +N1;0f75977f-1c52-45f8-9793-52ea2dc200a0;M2;net.drinkingtea.nostalgia.core.Palette;1;ûÿ³Ö diff --git a/sample_project/Palettes/Logo.npal b/sample_project/Palettes/Logo.npal index cdf83857..ec33e96e 100644 --- a/sample_project/Palettes/Logo.npal +++ b/sample_project/Palettes/Logo.npal @@ -1 +1 @@ -M2;net.drinkingtea.nostalgia.core.Palette;1;PÛ{³ÖCˆ \ No newline at end of file +N1;c79f21e2-f74f-4ad9-90ed-32b0ef7da6ed;M2;net.drinkingtea.nostalgia.core.Palette;1;PÛ{³ÖCˆ diff --git a/sample_project/Scenes/Chester.nscn b/sample_project/Scenes/Chester.nscn index 535b35f0e8d00a67ba9ea22c2d376de983d5b7a4..7b0ee09846bf0bb759baec9ee8dd006684511e42 100644 GIT binary patch delta 95 zcmV~$K@ET~3%uaY<^CUS2_B&c;0!ECApl4CVj; diff --git a/sample_project/TileSheets/Charset.ng b/sample_project/TileSheets/Charset.ng index 105b95fef0240129e6e886816f188e96d59d3969..48914c0bf693251f5ad495057fd10ae78d2e548d 100644 GIT binary patch delta 50 zcmeBS-^#AxXJ~C^o@SnyW@M(DW@2QbYm$~?s%w#yXsK&%W|?AWX<%kxkz!=Mp@*4~ F3jkAc4C4R* delta 8 PcmdnW-ow68qlXy)4Wk0M diff --git a/sample_project/TileSheets/Chester.ng b/sample_project/TileSheets/Chester.ng index 2759e89c26204e0834306bc1685c53497588a6c1..963a9e85a52f11582ac7b1623a3888a4129920c7 100644 GIT binary patch delta 49 zcmey*xPnQ;&(PY`%*;I5+|*LnJSovo*Tmc)QP;x4%s|)ND9ym!$RH)z)FRn>!hc3C E07ioiA^-pY delta 7 OcmZ3%^q+B}#(w||tOH{J diff --git a/sample_project/TileSheets/Dirt.ng b/sample_project/TileSheets/Dirt.ng index 8fa39b5381605c2c65fb8bef96ce8b9a72602af1..6d80ec4db447fb1b13b018f74f1fc8c2b28955dd 100644 GIT binary patch delta 48 zcmd0r%&6gKXl;;WVV0O|ma3a%nP{wQVs4zOn`oSDplg(pmTY2_l4Nd?nr1yAi;)We DMHLNF delta 6 NcmbQtm^D!&3jha_0wMqa diff --git a/sample_project/TileSheets/Logo.ng b/sample_project/TileSheets/Logo.ng index 7e1e5450f9154b85523523a3c3c555161a1b36da..fdd2cabb23d00e4be2a68a04161544791b8d6ebb 100644 GIT binary patch delta 58 zcmX@k_>ob=&(PY!(k#(D#mH3GG9}qa*TgK*KsU)GB~dro%+km>$t)$&z%a>rf)1;( NH9rT_M1$#!Tmak44 pathToUuid; ox::HashMap uuidToPath; ox::Vector converters; diff --git a/src/nostalgia/foundation/media.hpp b/src/nostalgia/foundation/media.hpp index 1f50dbcf..716517fe 100644 --- a/src/nostalgia/foundation/media.hpp +++ b/src/nostalgia/foundation/media.hpp @@ -37,7 +37,7 @@ ox::Result getPreloadAddr(foundation::Context *ctx, ox::CRStringVie template ox::Result> readObjFile( foundation::Context *ctx, - ox::CRStringView assetId, + ox::StringView assetId, bool forceLoad) noexcept { constexpr auto readConvert = [](Context *ctx, const ox::Buffer &buff) -> ox::Result { auto [obj, err] = readAsset(buff); @@ -50,20 +50,24 @@ ox::Result> readObjFile( return std::move(obj); }; ox::StringView path; - if (ctx->useUuids) { + ox::UUIDStr uuidStr; + if (beginsWith(assetId, "uuid://")) { + assetId = assetId.substr(7); path = ctx->uuidToPath[assetId]; } else { path = assetId; + uuidStr = ctx->pathToUuid[path].toString(); + assetId = uuidStr; } if (forceLoad) { - oxRequire(buff, ctx->rom->read(assetId)); + oxRequire(buff, ctx->rom->read(path)); oxRequire(obj, readConvert(ctx, buff)); oxRequire(cached, ctx->assetManager.setAsset(assetId, obj)); return cached; } else { auto [cached, err] = ctx->assetManager.getAsset(assetId); if (err) { - oxRequire(buff, ctx->rom->read(assetId)); + oxRequire(buff, ctx->rom->read(path)); oxRequire(obj, readConvert(ctx, buff)); oxReturnError(ctx->assetManager.setAsset(assetId, obj).moveTo(&cached)); } diff --git a/src/nostalgia/tools/pack/pack.cpp b/src/nostalgia/tools/pack/pack.cpp index 6d2fd9ef..7bf0c649 100644 --- a/src/nostalgia/tools/pack/pack.cpp +++ b/src/nostalgia/tools/pack/pack.cpp @@ -13,7 +13,7 @@ namespace nostalgia { -static ox::Error pathToInode(ox::FileSystem *dest, ox::ModelObject *obj) noexcept { +static ox::Error pathToInode(foundation::Context *ctx, ox::FileSystem *dest, ox::ModelObject *obj) noexcept { auto &o = *obj; auto type = static_cast(o["type"].get()); auto &data = o["data"].get(); @@ -29,28 +29,32 @@ static ox::Error pathToInode(ox::FileSystem *dest, ox::ModelObject *obj) noexcep case ox::FileAddressType::None: return {}; } + if (beginsWith(path, "uuid://")) { + const auto uuid = ox::StringView(path).substr(7); + path = ctx->uuidToPath[uuid]; + } oxRequire(s, dest->stat(path)); oxReturnError(o["type"].set(static_cast(ox::FileAddressType::Inode))); return data.set(2, s.inode); } -static ox::Error transformFileAddressesObj(ox::FileSystem *dest, ox::ModelObject *obj) noexcept; -static ox::Error transformFileAddressesVec(ox::FileSystem *dest, ox::ModelValueVector *v) noexcept; +static ox::Error transformFileAddressesObj(foundation::Context *ctx, ox::FileSystem *dest, ox::ModelObject *obj) noexcept; +static ox::Error transformFileAddressesVec(foundation::Context *ctx, ox::FileSystem *dest, ox::ModelValueVector *v) noexcept; -static ox::Error transformFileAddresses(ox::FileSystem *dest, ox::ModelValue *v) noexcept { +static ox::Error transformFileAddresses(foundation::Context *ctx, ox::FileSystem *dest, ox::ModelValue *v) noexcept { if (v->type() == ox::ModelValue::Type::Object) { auto &obj = v->get(); - return transformFileAddressesObj(dest, &obj); + return transformFileAddressesObj(ctx, dest, &obj); } else if (v->type() == ox::ModelValue::Type::Vector) { auto &vec = v->get(); - return transformFileAddressesVec(dest, &vec); + return transformFileAddressesVec(ctx, dest, &vec); } return {}; } -static ox::Error transformFileAddressesVec(ox::FileSystem *dest, ox::ModelValueVector *v) noexcept { +static ox::Error transformFileAddressesVec(foundation::Context *ctx, ox::FileSystem *dest, ox::ModelValueVector *v) noexcept { for (auto &f : *v) { - oxReturnError(transformFileAddresses(dest, &f)); + oxReturnError(transformFileAddresses(ctx, dest, &f)); } return {}; } @@ -59,13 +63,13 @@ static ox::Error transformFileAddressesVec(ox::FileSystem *dest, ox::ModelValueV * Convert path references in Claw data to inodes to save space * @return error */ -static ox::Error transformFileAddressesObj(ox::FileSystem *dest, ox::ModelObject *obj) noexcept { +static ox::Error transformFileAddressesObj(foundation::Context *ctx, ox::FileSystem *dest, ox::ModelObject *obj) noexcept { if (obj->typeName() == "net.drinkingtea.ox.FileAddress" && obj->typeVersion() == 1) { - return pathToInode(dest, obj); + return pathToInode(ctx, dest, obj); } for (auto &f : *obj) { auto &v = f->value; - oxReturnError(transformFileAddresses(dest, &v)); + oxReturnError(transformFileAddresses(ctx, dest, &v)); } return {}; } @@ -80,7 +84,7 @@ static ox::Error doTransformations(foundation::Context *ctx, ox::TypeStore *ts, } // transform FileAddresses oxRequireM(obj, foundation::readAsset(ts, buff)); - oxReturnError(transformFileAddressesObj(dest, &obj)); + oxReturnError(transformFileAddressesObj(ctx, dest, &obj)); oxReturnError(ox::writeClaw(&obj).moveTo(&buff)); // write file to dest oxReturnError(dest->write(s.inode, buff.data(), buff.size()));