Squashed 'deps/nostalgia/' changes from 3c7652ef..161640fa

161640fa [nostalgia] Cleanup
e42126c9 [nostalgia/core] Improve TileSheet validation, add repair
36942cca [nostalgia,olympic] Replace SpanView with Span<const T>
b14f1d50 [ox] Replace SpanView with Span<const T>
1bf4f246 [applib] Make run take args as a SpanView
edda8e01 [ox/clargs] Add constructor that takes a SpanView
3308b4dd [ox/std] Add missing + and += operators to Span
27f4703a [teagba] Suppress warnings for unsafe buffers
6af00d9a [nostalgia] Enable warnings for unsafe buffers
86b9f931 [olympic] Enable warnings for unsafe buffers
a0ed1b3f [ox/std] Fix Span raw array constructor
8dad624b [studio/applib] Cleanup
dc6605fd [keel] Add missing error checking to pack
c78d3cf6 [ox] Add more unsafe buffer exceptions
cee4f65d [ox/std] Replace an unsafe buffer
cd3eeeef [ox/fs] Suppress unsafe buffer warnings
287d42f2 [ox/clargs] Cleanup
dbbaaa46 [ox/clargs] Enable unsafe buffer warnings
9b8a8c4e [ox/std] Enable unsafe buffer warnings
e44fa288 [cityhash] Add pragmas to ignore unsafe buffer warnings
e13c6e81 [ox/std] Remove raw char* CharBufferWriter constructor
cb55b31a [ox/std] Cleanup
ab3f9e16 [ox/std] Make Span access check message consistent with other messages
8f25ef96 [ox/std] Make CharBufferWriter constructor take a Span
e13eebaf [ox/std] Cleanup an unsafe buffer
114f5c66 [ox/std] Add overflow checking to SpanIterator
df44fe23 [keel] Cleanup
72f4db3d [nostalgia/core/studio] Fix paste command to never paste beyond target dimensions
8a9ff971 [nostalgia/core] Fix resizeSubsheet to work for both growing and shrinking
5a8da59d [keel] Fix readAsset to actually return asset
afa3a13d [keel] Cleanup
6522cf8a [keel] Add ensureValid call to readAsset
f772e48b [ox] Add Vector/Array/Span overflow checking
13bfe881 [nostalgia/core] Fix resizeSubsheet array overflow
50254754 Merge commit '9e11019b87ba27d1dac9e097dc212a126e404218'
bfe890ae [ox] Fix typo in docs
ab5bc1ad [ox/std] Remove oxRequireT and oxRequireMT
abf7548a [nostalgia/core] Add missing include
e2682b5e [studio/modlib] Add missing include
792ad414 [nostalgia] Remove .vs dir

git-subtree-dir: deps/nostalgia
git-subtree-split: 161640fa11986677dc2e1da6ffd4575e38ab31ad
This commit is contained in:
2024-12-04 19:55:17 -06:00
parent 9e11019b87
commit 4ccdfc3a6e
101 changed files with 842 additions and 731 deletions

View File

@@ -7,6 +7,8 @@
#include <ox/claw/claw.hpp>
#include <ox/fs/fs.hpp>
#include "validation.hpp"
namespace keel {
constexpr auto K1HdrSz = 40;
@@ -26,7 +28,10 @@ ox::Result<T> readAsset(ox::BufferView buff) noexcept {
if (!err) {
offset = K1HdrSz; // the size of K1 headers
}
return ox::readClaw<T>(buff + offset);
auto out = ox::readClaw<T>(buff + offset);
oxReturnError(out);
oxReturnError(ensureValid(out.value));
return out;
}
ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView buff) noexcept;

View File

@@ -14,8 +14,6 @@
#include <ox/std/hashmap.hpp>
#include <ox/std/utility.hpp>
#include "validation.hpp"
namespace keel {
class AssetManager;
@@ -190,7 +188,7 @@ class AssetManager {
private:
class AssetTypeManagerBase: public ox::SignalHandler {
public:
virtual ~AssetTypeManagerBase() = default;
~AssetTypeManagerBase() override = default;
virtual void gc() noexcept = 0;
};
@@ -217,7 +215,6 @@ class AssetManager {
ox::Result<AssetRef<T>> loadAsset(ox::StringView const assetId) noexcept {
auto &p = m_cache[assetId];
oxRequireM(obj, m_loader(assetId));
oxReturnError(ensureValid(obj));
if (!p) {
p = ox::make_unique<AssetContainer<T>>(std::move(obj));
} else {

View File

@@ -63,10 +63,8 @@ namespace detail {
template<typename T>
constexpr auto makeLoader(Context &ctx) {
return [&ctx](ox::StringView assetId) -> ox::Result<T> {
ox::StringView path;
oxRequire(p, ctx.uuidToPath.at(assetId));
path = *p;
oxRequire(buff, ctx.rom->read(path));
oxRequire(buff, ctx.rom->read(*p));
auto [obj, err] = readAsset<T>(buff);
if (err) {
if (err != ox::Error_ClawTypeVersionMismatch && err != ox::Error_ClawTypeMismatch) {
@@ -84,21 +82,17 @@ ox::Result<keel::AssetRef<T>> readObjFile(
keel::Context &ctx,
ox::StringView assetId,
bool forceLoad) noexcept {
ox::UUIDStr uuidStr;
if (beginsWith(assetId, "uuid://")) {
assetId = substr(assetId, 7);
oxRequire(p, keel::uuidToPath(ctx, assetId));
} else {
auto const [uuid, uuidErr] = getUuid(ctx, assetId);
if (!uuidErr) {
uuidStr = uuid.toString();
assetId = uuidStr;
assetId = uuid.toString();
}
}
if (forceLoad) {
ctx.assetManager.initTypeManager<T>(detail::makeLoader<T>, ctx);
oxRequire(cached, ctx.assetManager.loadAsset<T>(assetId));
return cached;
return ctx.assetManager.loadAsset<T>(assetId);
} else {
auto [cached, err] = ctx.assetManager.getAsset<T>(assetId);
if (err) {

View File

@@ -7,8 +7,6 @@
#include <ox/std/def.hpp>
#include <ox/std/error.hpp>
#include <ox/std/string.hpp>
#include <ox/claw/read.hpp>
#include <ox/claw/write.hpp>
#include "asset.hpp"
#include "context.hpp"
@@ -119,7 +117,6 @@ class Converter: public BaseConverter {
ox::Result<ox::UPtr<Wrap>> convertBuffToPtr(
keel::Context &ctx, ox::BufferView const&srcBuff) const noexcept final {
oxRequireM(src, readAsset<SrcType>(srcBuff));
oxReturnError(ensureValid(src));
auto dst = makeWrap<DstType>();
oxReturnError(convert(ctx, src, wrapCast<DstType>(*dst)));
return {std::move(dst)};

View File

@@ -14,7 +14,7 @@ ox::Result<ox::UUID> readUuidHeader(ox::BufferView buff) noexcept {
if (k1Hdr != ox::StringView(buff.data(), k1Hdr.bytes())) [[unlikely]] {
return OxError(2, "No Keel asset header data");
}
return ox::UUID::fromString(ox::StringView(buff.data() + k1Hdr.bytes(), 36));
return ox::UUID::fromString(ox::StringView(&buff[k1Hdr.bytes()], 36));
}
ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView buff) noexcept {

View File

@@ -9,7 +9,9 @@ namespace keel {
static ox::Vector<Module const*> mods;
void registerModule(Module const*mod) noexcept {
mods.emplace_back(mod);
if (mod) {
mods.emplace_back(mod);
}
}
[[nodiscard]]

View File

@@ -81,8 +81,8 @@ static ox::Error pack(
return {};
}
static ox::Error run(int argc, char const**argv, ox::StringView projectDataDir) noexcept {
ox::ClArgs const args(argc, argv);
static ox::Error run(ox::SpanView<char const*> argv, ox::StringView projectDataDir) 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", "");
@@ -103,9 +103,8 @@ ox::Error run(
[[maybe_unused]] ox::StringView project,
[[maybe_unused]] ox::StringView appName,
ox::StringView projectDataDir,
int argc,
char const**argv) noexcept {
return ::run(argc, argv, projectDataDir);
ox::SpanView<char const*> argv) noexcept {
return ::run(argv, projectDataDir);
}
}

View File

@@ -15,16 +15,22 @@ static ox::Error pathToInode(
ox::FileSystem &dest,
ox::ModelObject &obj) noexcept {
auto &o = obj;
auto type = static_cast<ox::FileAddressType>(o.at("type").unwrap()->get<int8_t>());
auto &data = o.at("data").unwrap()->get<ox::ModelUnion>();
oxRequire(typeVal, o.at("type"));
auto const type = static_cast<ox::FileAddressType>(typeVal->get<int8_t>());
oxRequire(dataVal, o.at("data"));
auto &data = dataVal->get<ox::ModelUnion>();
ox::String path;
switch (type) {
case ox::FileAddressType::Path:
path = data.at("path").unwrap()->get<ox::String>();
case ox::FileAddressType::Path: {
oxRequire(pathVal, data.at("path"));
path = pathVal->get<ox::String>();
break;
case ox::FileAddressType::ConstPath:
path = data.at("constPath").unwrap()->get<ox::String>();
}
case ox::FileAddressType::ConstPath: {
oxRequire(pathVal, data.at("constPath"));
path = pathVal->get<ox::String>();
break;
}
case ox::FileAddressType::Inode:
case ox::FileAddressType::None:
return {};
@@ -34,7 +40,7 @@ static ox::Error pathToInode(
oxReturnError(keel::uuidToPath(ctx, uuid).to<ox::String>().moveTo(path));
}
oxRequire(s, dest.stat(path));
oxReturnError(o.at("type").unwrap()->set(static_cast<int8_t>(ox::FileAddressType::Inode)));
oxReturnError(typeVal->set(static_cast<int8_t>(ox::FileAddressType::Inode)));
oxOutf("\tpath to inode: {} => {}\n", path, s.inode);
return data.set(2, s.inode);
}
@@ -162,12 +168,12 @@ static ox::Error copy(
// copy
oxRequire(fileList, src.ls(path));
for (auto const&name : fileList) {
auto currentFile = ox::sfmt("{}{}", path, name);
auto const currentFile = ox::sfmt("{}{}", path, name);
if (beginsWith(name, ".")) {
continue;
}
oxRequire(stat, src.stat(currentFile));
if (stat.fileType == ox::FileType::Directory) {
oxRequire(srcStat, src.stat(currentFile));
if (srcStat.fileType == ox::FileType::Directory) {
oxReturnError(dest.mkdir(currentFile, true));
oxReturnError(copy(manifest, src, dest, currentFile + '/', childLogPrefix));
} else {
@@ -181,9 +187,9 @@ static ox::Error copy(
// write file to dest
oxReturnError(dest.write(currentFile, buff));
status = "OK";
oxRequire(stat, dest.stat(currentFile));
oxRequire(dstStat, dest.stat(currentFile));
manifest.files[currentFile] = {
.inode = stat.inode,
.inode = dstStat.inode,
.type = ox::String{keel::readAssetTypeId(buff).or_value({})},
};
}

View File

@@ -2,8 +2,6 @@
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#include <ox/claw/read.hpp>
#include <keel/media.hpp>
#include <keel/typeconv.hpp>

View File

@@ -25,9 +25,10 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
},
};
int main(int argc, const char **args) {
int main(int argc, const char **argv) {
int retval = -1;
if (argc > 0) {
auto const args = ox::Span{argv, static_cast<size_t>(argc)};
auto testName = args[1];
if (tests.find(testName) != tests.end()) {
retval = static_cast<int>(tests[testName]());