Compare commits

..

1 Commits

Author SHA1 Message Date
870fb9c6e3 [nostalgia/studio] Set version to d2025.07.0
All checks were successful
Build / build (push) Successful in 1m17s
2025-07-31 22:07:22 -05:00
23 changed files with 128 additions and 135 deletions

View File

@@ -30,49 +30,11 @@ constexpr void *operator new(std::size_t, void *addr) noexcept {
constexpr void *operator new[](std::size_t, void *addr) noexcept { constexpr void *operator new[](std::size_t, void *addr) noexcept {
return addr; return addr;
} }
namespace std {
template<typename T>
[[nodiscard]]
constexpr T* launder(T* __p) noexcept {
return __builtin_launder(__p);
}
template<typename T, typename... Args, bool noex>
void launder(T(*)(Args...) noexcept(noex)) = delete;
template<typename T, typename... Args, bool noex>
void launder(T(*)(Args......) noexcept(noex)) = delete;
void launder(void*) = delete;
void launder(void const*) = delete;
void launder(volatile void*) = delete;
void launder(volatile void const*) = delete;
}
#endif #endif
namespace ox { namespace ox {
/**
* Aliases type T in size and alignment to allow allocating space for a T
* without running the constructor.
*/
template<typename T, std::size_t sz = sizeof(T)>
struct alignas(alignof(T)) AllocAlias {
char buff[sz];
constexpr AllocAlias() noexcept = default;
[[nodiscard]]
auto data() noexcept {
return reinterpret_cast<T*>(this);
}
[[nodiscard]]
auto data() const noexcept {
return reinterpret_cast<T const*>(this);
}
};
template<typename T, typename U = T, typename ...Args> template<typename T, typename U = T, typename ...Args>
[[nodiscard]] [[nodiscard]]
constexpr U *make(Args &&...args) noexcept { constexpr U *make(Args &&...args) noexcept {

View File

@@ -63,6 +63,25 @@ namespace ox {
using CString = char const*; using CString = char const*;
/**
* Aliases type T in size and alignment to allow allocating space for a T
* without running the constructor.
*/
template<typename T, std::size_t sz = sizeof(T)>
struct alignas(alignof(T)) AllocAlias {
char buff[sz];
constexpr AllocAlias() noexcept = default;
[[nodiscard]]
auto data() noexcept {
return reinterpret_cast<T*>(this);
}
[[nodiscard]]
auto data() const noexcept {
return reinterpret_cast<const T*>(this);
}
};
template<std::size_t sz> template<std::size_t sz>
struct SignedType { struct SignedType {
}; };

View File

@@ -34,10 +34,10 @@ struct VectorAllocator {
ox::Array<AllocAlias<T>, Size> m_data = {}; ox::Array<AllocAlias<T>, Size> m_data = {};
protected: protected:
constexpr VectorAllocator() noexcept = default; constexpr VectorAllocator() noexcept = default;
constexpr VectorAllocator(VectorAllocator const&) noexcept = default; constexpr VectorAllocator(const VectorAllocator&) noexcept = default;
constexpr VectorAllocator(VectorAllocator&&) noexcept = default; constexpr VectorAllocator(VectorAllocator&&) noexcept = default;
constexpr void allocate(T **items, std::size_t const cap) noexcept { constexpr void allocate(T **items, std::size_t cap) noexcept {
// small vector optimization cannot be done it constexpr, but it doesn't really matter in constexpr // small vector optimization cannot be done it constexpr, but it doesn't really matter in constexpr
if (std::is_constant_evaluated() || cap > Size) { if (std::is_constant_evaluated() || cap > Size) {
*items = Allocator{}.allocate(cap); *items = Allocator{}.allocate(cap);
@@ -49,26 +49,42 @@ struct VectorAllocator {
constexpr void moveConstructItemsFrom( constexpr void moveConstructItemsFrom(
T **items, T **items,
VectorAllocator *src, VectorAllocator *src,
std::size_t const count, const std::size_t count,
std::size_t const cap) noexcept { const std::size_t cap) noexcept {
// this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM, // this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM,
// try removing it later // try removing it later
if (!std::is_constant_evaluated()) { if (!std::is_constant_evaluated()) {
if (cap <= m_data.size() && count <= m_data.size()) { if (cap <= m_data.size() && count <= m_data.size()) {
for (auto i = 0u; i < count; ++i) { for (auto i = 0u; i < count; ++i) {
auto const srcItem = std::launder(reinterpret_cast<T*>(&src->m_data[i])); const auto dstItem = reinterpret_cast<T *>(&m_data[i]);
new (&m_data[i]) T(std::move(*srcItem)); const auto srcItem = reinterpret_cast<T *>(&src->m_data[i]);
std::construct_at<T>(dstItem, std::move(*srcItem));
} }
if (count) {
*items = std::launder(reinterpret_cast<T*>(m_data.data()));
} else {
*items = reinterpret_cast<T*>(m_data.data()); *items = reinterpret_cast<T*>(m_data.data());
} }
} }
} }
constexpr void moveItemsFrom(
T **items,
VectorAllocator *src,
const std::size_t count,
const std::size_t cap) noexcept {
// this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM,
// try removing it later
if (!std::is_constant_evaluated()) {
if (cap <= m_data.size() && count <= m_data.size()) {
for (std::size_t i = 0; i < count; ++i) {
const auto dstItem = reinterpret_cast<T *>(&m_data[i]);
const auto srcItem = reinterpret_cast<T *>(&src->m_data[i]);
*dstItem = std::move(*srcItem);
}
*items = reinterpret_cast<T*>(m_data.data());
}
}
} }
constexpr void deallocate(T *const items, std::size_t const cap) noexcept { constexpr void deallocate(T *items, std::size_t cap) noexcept {
// small vector optimization cannot be done it constexpr, but it doesn't really matter in constexpr // small vector optimization cannot be done it constexpr, but it doesn't really matter in constexpr
if (std::is_constant_evaluated()) { if (std::is_constant_evaluated()) {
if (items) { if (items) {
@@ -87,10 +103,10 @@ template<typename T, typename Allocator>
struct VectorAllocator<T, Allocator, 0> { struct VectorAllocator<T, Allocator, 0> {
protected: protected:
constexpr VectorAllocator() noexcept = default; constexpr VectorAllocator() noexcept = default;
constexpr VectorAllocator(VectorAllocator const&) noexcept = default; constexpr VectorAllocator(const VectorAllocator&) noexcept = default;
constexpr VectorAllocator(VectorAllocator&&) noexcept = default; constexpr VectorAllocator(VectorAllocator&&) noexcept = default;
constexpr void allocate(T **items, std::size_t const cap) noexcept { constexpr void allocate(T **items, std::size_t cap) noexcept {
*items = Allocator{}.allocate(cap); *items = Allocator{}.allocate(cap);
} }
@@ -98,15 +114,15 @@ struct VectorAllocator<T, Allocator, 0> {
constexpr void moveConstructItemsFrom( constexpr void moveConstructItemsFrom(
T**, T**,
VectorAllocator*, VectorAllocator*,
std::size_t const, const std::size_t,
std::size_t const) noexcept { const std::size_t) noexcept {
} }
[[maybe_unused]] [[maybe_unused]]
constexpr void moveItemsFrom(T**, VectorAllocator*, std::size_t const, std::size_t const) noexcept { constexpr void moveItemsFrom(T**, VectorAllocator*, const std::size_t, const std::size_t) noexcept {
} }
constexpr void deallocate(T *const items, std::size_t const cap) noexcept { constexpr void deallocate(T *items, std::size_t cap) noexcept {
if (items) { if (items) {
Allocator{}.deallocate(items, cap); Allocator{}.deallocate(items, cap);
} }
@@ -405,7 +421,7 @@ constexpr Vector<T, SmallVectorSize, Allocator> &Vector<T, SmallVectorSize, Allo
m_size = other.m_size; m_size = other.m_size;
m_cap = other.m_cap; m_cap = other.m_cap;
m_items = other.m_items; m_items = other.m_items;
this->moveConstructItemsFrom(&m_items, &other, m_size, m_cap); this->moveItemsFrom(&m_items, &other, m_size, m_cap);
other.m_size = 0; other.m_size = 0;
other.m_cap = 0; other.m_cap = 0;
other.m_items = nullptr; other.m_items = nullptr;

View File

@@ -15,7 +15,7 @@ target_link_libraries(
target_compile_definitions( target_compile_definitions(
NostalgiaStudio PUBLIC NostalgiaStudio PUBLIC
OLYMPIC_APP_VERSION="dev build" OLYMPIC_APP_VERSION="d2025.07.0"
) )
install( install(

View File

@@ -18,7 +18,7 @@
<string>APPL</string> <string>APPL</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>dev build</string> <string>d2025.07.0</string>
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>
<string>12.0.0</string> <string>12.0.0</string>

View File

@@ -13,7 +13,7 @@ namespace keel {
constexpr auto K1HdrSz = 40; constexpr auto K1HdrSz = 40;
ox::Result<ox::UUID> readUuidHeader(ox::BufferView const &buff) noexcept; ox::Result<ox::UUID> readUuidHeader(ox::BufferView buff) noexcept;
ox::Result<ox::UUID> regenerateUuidHeader(ox::Buffer &buff) noexcept; ox::Result<ox::UUID> regenerateUuidHeader(ox::Buffer &buff) noexcept;
@@ -35,15 +35,15 @@ ox::Result<T> readAsset(ox::BufferView buff) noexcept {
return out; return out;
} }
ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView const &buff) noexcept; ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView buff) noexcept;
struct AssetHdr { struct AssetHdr {
ox::UUID uuid; ox::UUID uuid;
ox::ClawHeader clawHdr; ox::ClawHeader clawHdr;
}; };
ox::Result<ox::StringView> readAssetTypeId(ox::BufferView const &buff) noexcept; ox::Result<ox::StringView> readAssetTypeId(ox::BufferView buff) noexcept;
ox::Result<AssetHdr> readAssetHeader(ox::BufferView const &buff) noexcept; ox::Result<AssetHdr> readAssetHeader(ox::BufferView buff) noexcept;
} }

View File

@@ -147,7 +147,7 @@ template<typename T>
ox::Result<AssetRef<T>> readObj( ox::Result<AssetRef<T>> readObj(
Context &ctx, Context &ctx,
ox::StringViewCR assetId, ox::StringViewCR assetId,
[[maybe_unused]] bool const forceLoad = false) noexcept { [[maybe_unused]] bool forceLoad = false) noexcept {
#ifndef OX_BARE_METAL #ifndef OX_BARE_METAL
return readObjFile<T>(ctx, assetId, forceLoad); return readObjFile<T>(ctx, assetId, forceLoad);
#else #else
@@ -159,7 +159,7 @@ template<typename T>
ox::Result<AssetRef<T>> readObj( ox::Result<AssetRef<T>> readObj(
Context &ctx, Context &ctx,
ox::FileAddress const&file, ox::FileAddress const&file,
[[maybe_unused]] bool const forceLoad = false) noexcept { [[maybe_unused]] bool forceLoad = false) noexcept {
#ifndef OX_BARE_METAL #ifndef OX_BARE_METAL
OX_REQUIRE(assetId, file.getPath()); OX_REQUIRE(assetId, file.getPath());
return readObj<T>(ctx, ox::StringView(assetId), forceLoad); return readObj<T>(ctx, ox::StringView(assetId), forceLoad);
@@ -178,7 +178,7 @@ ox::Error writeObj(
Context &ctx, Context &ctx,
ox::FileAddress const&file, ox::FileAddress const&file,
T const&obj, T const&obj,
ox::ClawFormat const fmt = ox::ClawFormat::Metal) noexcept { ox::ClawFormat fmt = ox::ClawFormat::Metal) noexcept {
OX_REQUIRE(objBuff, ox::writeClaw(obj, fmt)); OX_REQUIRE(objBuff, ox::writeClaw(obj, fmt));
return ctx.rom->write(file, objBuff.data(), objBuff.size()); return ctx.rom->write(file, objBuff.data(), objBuff.size());
} }

View File

@@ -214,7 +214,7 @@ class Converter {
} }
[[nodiscard]] [[nodiscard]]
BaseConverter const &converter() const noexcept { BaseConverter const &converter() const noexcept {
return *std::launder(m_buff.data()); return *m_buff.data();
} }
}; };

View File

@@ -16,7 +16,7 @@ class TypeStore: public ox::TypeStore {
ox::String m_descPath; ox::String m_descPath;
public: public:
explicit TypeStore(ox::FileSystem &fs, ox::StringViewCR descPath) noexcept; explicit TypeStore(ox::FileSystem &fs, ox::StringView descPath) noexcept;
protected: protected:
ox::Result<ox::UPtr<ox::DescriptorType>> loadDescriptor(ox::StringView typeId) noexcept override; ox::Result<ox::UPtr<ox::DescriptorType>> loadDescriptor(ox::StringView typeId) noexcept override;

View File

@@ -6,7 +6,7 @@
namespace keel { namespace keel {
ox::Result<ox::UUID> readUuidHeader(ox::BufferView const &buff) noexcept { ox::Result<ox::UUID> readUuidHeader(ox::BufferView buff) noexcept {
if (buff.size() < K1HdrSz) [[unlikely]] { if (buff.size() < K1HdrSz) [[unlikely]] {
return ox::Error{1, "Insufficient data to contain complete Keel header"}; return ox::Error{1, "Insufficient data to contain complete Keel header"};
} }
@@ -27,15 +27,16 @@ ox::Result<ox::UUID> regenerateUuidHeader(ox::Buffer &buff) noexcept {
return id; return id;
} }
ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView const &buff) noexcept { ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView buff) noexcept {
std::size_t offset = 0; std::size_t offset = 0;
if (!readUuidHeader(buff).error) { if (!readUuidHeader(buff).error) {
offset = K1HdrSz; offset = K1HdrSz;
} }
return ox::readClaw(ts, buff + offset); buff += offset;
return ox::readClaw(ts, buff);
} }
ox::Result<ox::StringView> readAssetTypeId(ox::BufferView const &buff) noexcept { ox::Result<ox::StringView> readAssetTypeId(ox::BufferView const buff) noexcept {
auto const err = readUuidHeader(buff).error; auto const err = readUuidHeader(buff).error;
auto const offset = err ? 0u : K1HdrSz; auto const offset = err ? 0u : K1HdrSz;
if (offset >= buff.size()) [[unlikely]] { if (offset >= buff.size()) [[unlikely]] {
@@ -44,14 +45,15 @@ ox::Result<ox::StringView> readAssetTypeId(ox::BufferView const &buff) noexcept
return ox::readClawTypeId(buff + offset); return ox::readClawTypeId(buff + offset);
} }
ox::Result<AssetHdr> readAssetHeader(ox::BufferView const &buff) noexcept { ox::Result<AssetHdr> readAssetHeader(ox::BufferView buff) noexcept {
ox::Result<AssetHdr> out; ox::Result<AssetHdr> out;
auto const err = readUuidHeader(buff).moveTo(out.value.uuid); auto const err = readUuidHeader(buff).moveTo(out.value.uuid);
auto const offset = err ? 0u : K1HdrSz; auto const offset = err ? 0u : K1HdrSz;
if (offset >= buff.size()) [[unlikely]] { if (offset >= buff.size()) [[unlikely]] {
return ox::Error(1, "Buffer too small for expected data"); return ox::Error(1, "Buffer too small for expected data");
} }
OX_RETURN_ERROR(ox::readClawHeader(buff + offset).moveTo(out.value.clawHdr)); buff += offset;
OX_RETURN_ERROR(ox::readClawHeader(buff).moveTo(out.value.clawHdr));
return out; return out;
} }

View File

@@ -6,7 +6,7 @@
namespace keel { namespace keel {
TypeStore::TypeStore(ox::FileSystem &fs, ox::StringViewCR descPath) noexcept: TypeStore::TypeStore(ox::FileSystem &fs, ox::StringView descPath) noexcept:
m_fs(fs), m_fs(fs),
m_descPath(descPath) { m_descPath(descPath) {
} }

View File

@@ -25,7 +25,7 @@ static std::map<ox::StringView, ox::Error(*)()> tests = {
}, },
}; };
int main(int const argc, char const **argv) { int main(int argc, char const **argv) {
int retval = -1; int retval = -1;
if (argc > 0) { if (argc > 0) {
auto const args = ox::Span{argv, static_cast<size_t>(argc)}; auto const args = ox::Span{argv, static_cast<size_t>(argc)};

View File

@@ -8,18 +8,13 @@ namespace studio {
void navigateTo(Context &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept { void navigateTo(Context &ctx, ox::StringParam filePath, ox::StringParam navArgs) noexcept {
ox::String path = std::move(filePath); ox::String path = std::move(filePath);
if (keel::isUuidUrl(path)) { if (beginsWith(path, "uuid://")) {
auto const [p, err] = keel::uuidUrlToPath(keelCtx(ctx), path); auto const [p, err] = keel::uuidUrlToPath(keelCtx(ctx), path);
if (err) { if (err) {
return; return;
} }
path = p; path = p;
} }
//if (
// auto const [np, err] = ctx.navStack.back();
// !err && np->filePath == path && np->navArgs == navArgs.view()) {
// return;
//}
ctx.navStack.resize(ctx.navIdx + 1); ctx.navStack.resize(ctx.navIdx + 1);
ctx.navStack.emplace_back(ox::String{path}, ox::String{navArgs.view()}); ctx.navStack.emplace_back(ox::String{path}, ox::String{navArgs.view()});
try { try {
@@ -54,9 +49,8 @@ void navigateBack(Context &ctx) noexcept {
} }
void navigateForward(Context &ctx) noexcept { void navigateForward(Context &ctx) noexcept {
auto const nextIdx = ctx.navIdx + 1; while (ctx.navIdx < ctx.navStack.size()) {
while (nextIdx < ctx.navStack.size()) { auto const &n = ctx.navStack[ctx.navIdx];
auto const &n = ctx.navStack[nextIdx];
try { try {
ctx.navCallback(n.filePath, n.navArgs); ctx.navCallback(n.filePath, n.navArgs);
} catch (std::exception const &e) { } catch (std::exception const &e) {
@@ -64,7 +58,7 @@ void navigateForward(Context &ctx) noexcept {
oxErrf("navigateForward failed: {}", e.what()); oxErrf("navigateForward failed: {}", e.what());
} }
if (!ctx.project->exists(n.filePath)) { if (!ctx.project->exists(n.filePath)) {
std::ignore = ctx.navStack.erase(nextIdx); std::ignore = ctx.navStack.erase(ctx.navIdx);
continue; continue;
} }
++ctx.navIdx; ++ctx.navIdx;