[nostalgia/core] Make readObj move output object instead of copy

This commit is contained in:
Gary Talent 2022-02-26 10:12:25 -06:00
parent 13ba8430c7
commit 9762a38a44

View File

@ -25,22 +25,22 @@ ox::Result<AssetRef<T>> readObj(Context *ctx, const ox::FileAddress &file, bool
}
oxReturnError(convert<T>(buff, &obj));
}
return obj;
return std::move(obj);
};
oxRequire(path, file.getPath());
if (forceLoad) {
oxRequire(buff, ctx->rom->read(file));
oxRequire(obj, readConvert(buff));
oxRequire(cached, ctx->assetManager.template setAsset(path, obj));
return cached;
oxRequire(cached, ctx->assetManager.setAsset(path, obj));
return std::move(cached);
} else {
auto [cached, err] = ctx->assetManager.template getAsset<T>(path);
auto [cached, err] = ctx->assetManager.getAsset<T>(path);
if (err) {
oxRequire(buff, ctx->rom->read(file));
oxRequire(obj, readConvert(buff));
oxReturnError(ctx->assetManager.template setAsset(path, obj).moveTo(&cached));
oxReturnError(ctx->assetManager.setAsset(path, obj).moveTo(&cached));
}
return cached;
return std::move(cached);
}
#else
return OxError(1);