Compare commits

...

6 Commits

Author SHA1 Message Date
7da2f68d30 [nostalgia/sample_project] Add assets
All checks were successful
Build / build (push) Successful in 1m22s
2025-05-06 22:30:28 -05:00
d20889aef1 [nostalgia/gfx/studio] Update for Ox changes 2025-05-06 22:29:51 -05:00
50c8302f4a [ox] Rename itoa to intToStr 2025-05-06 22:29:31 -05:00
d8195d300d [olympic,nostalgia] Address unsafe buffer warnings 2025-05-06 22:25:36 -05:00
a8c1387d5a [ox] Address unsafe buffer warnings 2025-05-06 22:25:13 -05:00
ff1e8f260b [studio] Add popup to warn about UUID duplication 2025-05-06 22:22:26 -05:00
46 changed files with 4472 additions and 129 deletions

View File

@ -29,7 +29,7 @@ ClArgs::ClArgs(ox::SpanView<const char*> args) noexcept {
m_bools[arg] = false; m_bools[arg] = false;
} }
m_strings[arg] = val; m_strings[arg] = val;
if (auto r = ox::atoi(val.c_str()); r.error == 0) { if (auto r = ox::strToInt(val); r.error == 0) {
m_ints[arg] = r.value; m_ints[arg] = r.value;
} }
++i; ++i;

View File

@ -81,7 +81,7 @@ Result<ClawHeader> readClawHeader(ox::BufferView buff) noexcept {
return ox::Error(4, "Claw format does not match any supported format/version combo"); return ox::Error(4, "Claw format does not match any supported format/version combo");
} }
hdr.typeName = typeName; hdr.typeName = typeName;
std::ignore = ox::atoi(versionStr).copyTo(hdr.typeVersion); std::ignore = ox::strToInt(versionStr).copyTo(hdr.typeVersion);
hdr.data = buffRaw; hdr.data = buffRaw;
hdr.dataSize = buffLen; hdr.dataSize = buffLen;
return hdr; return hdr;

View File

@ -31,10 +31,10 @@ FileAddress::FileAddress(uint64_t inode) noexcept {
FileAddress::FileAddress(ox::StringViewCR path) noexcept { FileAddress::FileAddress(ox::StringViewCR path) noexcept {
auto pathSize = path.bytes(); auto pathSize = path.bytes();
m_data.path = new char[pathSize + 1]; m_data.path = new char[pathSize + 1];
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
memcpy(m_data.path, path.data(), pathSize); memcpy(m_data.path, path.data(), pathSize);
OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
m_data.path[pathSize] = 0; m_data.path[pathSize] = 0;
OX_CLANG_NOWARN_END OX_ALLOW_UNSAFE_BUFFERS_END
m_type = FileAddressType::Path; m_type = FileAddressType::Path;
} }
@ -48,9 +48,11 @@ FileAddress &FileAddress::operator=(const FileAddress &other) noexcept {
case FileAddressType::Path: case FileAddressType::Path:
{ {
if (other.m_data.path) { if (other.m_data.path) {
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
auto strSize = ox::strlen(other.m_data.path) + 1; auto strSize = ox::strlen(other.m_data.path) + 1;
m_data.path = new char[strSize]; m_data.path = new char[strSize];
ox::memcpy(m_data.path, other.m_data.path, strSize); ox::memcpy(m_data.path, other.m_data.path, strSize);
OX_ALLOW_UNSAFE_BUFFERS_END
} else { } else {
m_data.constPath = ""; m_data.constPath = "";
m_type = FileAddressType::ConstPath; m_type = FileAddressType::ConstPath;

View File

@ -468,7 +468,7 @@ Error FileSystemTemplate<FileStore, Directory>::writeFilePath(
template<typename FileStore, typename Directory> template<typename FileStore, typename Directory>
Error FileSystemTemplate<FileStore, Directory>::writeFileInode(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept { Error FileSystemTemplate<FileStore, Directory>::writeFileInode(uint64_t inode, const void *buffer, uint64_t size, FileType fileType) noexcept {
oxTrace("ox.fs.FileSystemTemplate.writeFileInode", ox::itoa(inode)); oxTrace("ox.fs.FileSystemTemplate.writeFileInode", ox::intToStr(inode));
return m_fs.write(inode, buffer, static_cast<size_t>(size), static_cast<uint8_t>(fileType)); return m_fs.write(inode, buffer, static_cast<size_t>(size), static_cast<uint8_t>(fileType));
} }

View File

@ -119,7 +119,9 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
auto constexpr path = ox::StringLiteral("/usr/share/charset.gbag"); auto constexpr path = ox::StringLiteral("/usr/share/charset.gbag");
ox::PathIterator it(path.c_str(), path.len()); ox::PathIterator it(path.c_str(), path.len());
auto buff = static_cast<char*>(ox_alloca(path.len() + 1)); auto buff = static_cast<char*>(ox_alloca(path.len() + 1));
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
oxAssert(it.dirPath(buff, path.len()) == 0 && ox::strcmp(buff, "/usr/share/") == 0, "PathIterator shows incorrect dir path"); oxAssert(it.dirPath(buff, path.len()) == 0 && ox::strcmp(buff, "/usr/share/") == 0, "PathIterator shows incorrect dir path");
OX_ALLOW_UNSAFE_BUFFERS_END
return ox::Error(0); return ox::Error(0);
} }
}, },
@ -127,7 +129,9 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
"PathIterator::hasNext", "PathIterator::hasNext",
[](ox::StringView) { [](ox::StringView) {
const auto path = "/file1"; const auto path = "/file1";
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
ox::PathIterator it(path, ox::strlen(path)); ox::PathIterator it(path, ox::strlen(path));
OX_ALLOW_UNSAFE_BUFFERS_END
oxAssert(it.hasNext(), "PathIterator shows incorrect hasNext"); oxAssert(it.hasNext(), "PathIterator shows incorrect hasNext");
oxAssert(!it.next().hasNext(), "PathIterator shows incorrect hasNext"); oxAssert(!it.next().hasNext(), "PathIterator shows incorrect hasNext");
return ox::Error(0); return ox::Error(0);
@ -163,9 +167,11 @@ const std::map<ox::StringView, std::function<ox::Error(ox::StringView)>> tests =
[](ox::StringView) { [](ox::StringView) {
constexpr auto buffLen = 5000; constexpr auto buffLen = 5000;
constexpr auto str1 = "Hello, World!"; constexpr auto str1 = "Hello, World!";
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
constexpr auto str1Len = ox::strlen(str1) + 1; constexpr auto str1Len = ox::strlen(str1) + 1;
constexpr auto str2 = "Hello, Moon!"; constexpr auto str2 = "Hello, Moon!";
constexpr auto str2Len = ox::strlen(str2) + 1; constexpr auto str2Len = ox::strlen(str2) + 1;
OX_ALLOW_UNSAFE_BUFFERS_END
auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer<uint32_t, ox::FileStoreItem<uint32_t>>(buffLen); auto list = new (ox_alloca(buffLen)) ox::ptrarith::NodeBuffer<uint32_t, ox::FileStoreItem<uint32_t>>(buffLen);
oxAssert(ox::FileStore32::format(list, buffLen), "FileStore::format failed."); oxAssert(ox::FileStore32::format(list, buffLen), "FileStore::format failed.");
ox::FileStore32 fileStore(list, buffLen); ox::FileStore32 fileStore(list, buffLen);

View File

@ -57,7 +57,9 @@ static ox::Error runRead(ox::FileSystem *fs, ox::Span<const char*> args) noexcep
return ox::Error(1); return ox::Error(1);
} }
OX_REQUIRE(buff, fs->read(ox::StringView(args[1]))); OX_REQUIRE(buff, fs->read(ox::StringView(args[1])));
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
std::ignore = fwrite(buff.data(), sizeof(decltype(buff)::value_type), buff.size(), stdout); std::ignore = fwrite(buff.data(), sizeof(decltype(buff)::value_type), buff.size(), stdout);
OX_ALLOW_UNSAFE_BUFFERS_END
return ox::Error(0); return ox::Error(0);
} }

View File

@ -71,7 +71,9 @@ constexpr McInt encodeInteger(I pInput) noexcept {
// move input to uint64_t to allow consistent bit manipulation, and to avoid // move input to uint64_t to allow consistent bit manipulation, and to avoid
// overflow concerns // overflow concerns
uint64_t val = 0; uint64_t val = 0;
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
ox::memcpy(&val, &input, sizeof(input)); ox::memcpy(&val, &input, sizeof(input));
OX_ALLOW_UNSAFE_BUFFERS_END
if (val) { if (val) {
// bits needed to represent number factoring in space possibly // bits needed to represent number factoring in space possibly
// needed for signed bit // needed for signed bit
@ -94,7 +96,9 @@ constexpr McInt encodeInteger(I pInput) noexcept {
} }
if (bytes == 9) { if (bytes == 9) {
out.data[0] = bytesIndicator; out.data[0] = bytesIndicator;
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
ox::memcpy(&out.data[1], &leVal, 8); ox::memcpy(&out.data[1], &leVal, 8);
OX_ALLOW_UNSAFE_BUFFERS_END
if (inputNegative) { if (inputNegative) {
out.data[1] |= 0b1000'0000; out.data[1] |= 0b1000'0000;
} }
@ -104,7 +108,9 @@ constexpr McInt encodeInteger(I pInput) noexcept {
auto intermediate = auto intermediate =
static_cast<uint64_t>(leVal.raw() | (negBit << (valBits - 1))) << bytes | static_cast<uint64_t>(leVal.raw() | (negBit << (valBits - 1))) << bytes |
static_cast<uint64_t>(bytesIndicator); static_cast<uint64_t>(bytesIndicator);
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
ox::memcpy(&out.data[0], &intermediate, sizeof(intermediate)); ox::memcpy(&out.data[0], &intermediate, sizeof(intermediate));
OX_ALLOW_UNSAFE_BUFFERS_END
} }
out.length = bytes; out.length = bytes;
} }
@ -151,33 +157,37 @@ constexpr Result<I> decodeInteger(Reader_c auto&rdr, std::size_t *bytesRead) noe
decoded >>= bytes; decoded >>= bytes;
// move sign bit // move sign bit
if constexpr(is_signed_v<I>) { if constexpr(is_signed_v<I>) {
const auto negBit = bytes * 8 - bytes - 1; const auto negBit = bytes * 8 - bytes - 1;
// move sign // move sign
const auto negative = (decoded >> negBit) == 1; const auto negative = (decoded >> negBit) == 1;
if (negative) { if (negative) {
// fill in all bits between encoded sign and real sign with 1s // fill in all bits between encoded sign and real sign with 1s
// split it up because the 32-bit ARM can't shift more than 32 bits // split it up because the 32-bit ARM can't shift more than 32 bits
ox::Array<uint32_t, 2> d = {}; ox::Array<uint32_t, 2> d = {};
//d[0] = decoded & 0xffff'ffff; //d[0] = decoded & 0xffff'ffff;
//d[1] = decoded >> 32; //d[1] = decoded >> 32;
ox::memcpy(&d[0], &decoded, sizeof(decoded)); OX_ALLOW_UNSAFE_BUFFERS_BEGIN
auto bit = negBit; ox::memcpy(&d[0], &decoded, sizeof(decoded));
for (; bit < ox::min<std::size_t>(Bits<I>, 32); ++bit) { OX_ALLOW_UNSAFE_BUFFERS_END
d[0] |= 1 << bit; auto bit = negBit;
} for (; bit < ox::min<std::size_t>(Bits<I>, 32); ++bit) {
bit -= 32; d[0] |= 1 << bit;
for (; bit < Bits<I>; ++bit) { }
d[1] |= 1 << bit; bit -= 32;
} for (; bit < Bits<I>; ++bit) {
I out = 0; d[1] |= 1 << bit;
if constexpr(ox::defines::BigEndian) { }
const auto d0Tmp = d[0]; I out = 0;
d[0] = d[1]; if constexpr(ox::defines::BigEndian) {
d[1] = d0Tmp; const auto d0Tmp = d[0];
} d[0] = d[1];
ox::memcpy(&out, &d[0], sizeof(out)); d[1] = d0Tmp;
return out; }
} OX_ALLOW_UNSAFE_BUFFERS_BEGIN
ox::memcpy(&out, &d[0], sizeof(out));
OX_ALLOW_UNSAFE_BUFFERS_END
return out;
}
} }
return static_cast<I>(decoded); return static_cast<I>(decoded);
} }

View File

@ -211,10 +211,12 @@ constexpr Error MetalClawWriter<Writer>::field(const char *name, const IString<L
} }
template<Writer_c Writer> template<Writer_c Writer>
constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *const*val, std::size_t) noexcept { constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *const*val, std::size_t buffLen) noexcept {
bool fieldSet = false; bool fieldSet = false;
if (!m_unionIdx.has_value() || *m_unionIdx == m_field) { if (!m_unionIdx.has_value() || *m_unionIdx == m_field) {
const auto strLen = *val ? ox::strlen(*val) : 0; OX_ALLOW_UNSAFE_BUFFERS_BEGIN
const auto strLen = *val ? ox::strnlen_s(*val, buffLen) : 0;
OX_ALLOW_UNSAFE_BUFFERS_END
// write the length // write the length
const auto strLenBuff = mc::encodeInteger(strLen); const auto strLenBuff = mc::encodeInteger(strLen);
OX_RETURN_ERROR(m_writer.write(reinterpret_cast<const char*>(strLenBuff.data.data()), strLenBuff.length)); OX_RETURN_ERROR(m_writer.write(reinterpret_cast<const char*>(strLenBuff.data.data()), strLenBuff.length));

View File

@ -997,7 +997,7 @@ constexpr ModelValue::ModelValue(const ModelValue &other) noexcept {
case Type::SignedInteger16: case Type::SignedInteger16:
case Type::SignedInteger32: case Type::SignedInteger32:
case Type::SignedInteger64: case Type::SignedInteger64:
ox::memcpy(&m_data, &other.m_data, sizeof(m_data)); m_data = other.m_data;
break; break;
case Type::String: case Type::String:
m_data.str = new String(other.get<String>()); m_data.str = new String(other.get<String>());
@ -1030,8 +1030,8 @@ constexpr ModelValue::ModelValue(ModelValue &&other) noexcept {
case Type::SignedInteger16: case Type::SignedInteger16:
case Type::SignedInteger32: case Type::SignedInteger32:
case Type::SignedInteger64: case Type::SignedInteger64:
ox::memcpy(&m_data, &other.m_data, sizeof(m_data)); m_data = other.m_data;
ox::memset(&other.m_data, 0, sizeof(m_data)); other.m_data.ui64 = 0;
break; break;
case Type::String: case Type::String:
m_data.str = other.m_data.str; m_data.str = other.m_data.str;
@ -1223,7 +1223,7 @@ constexpr ModelValue &ModelValue::operator=(const ModelValue &other) noexcept {
case Type::SignedInteger16: case Type::SignedInteger16:
case Type::SignedInteger32: case Type::SignedInteger32:
case Type::SignedInteger64: case Type::SignedInteger64:
ox::memcpy(&m_data, &other.m_data, sizeof(m_data)); m_data = other.m_data;
break; break;
case Type::String: case Type::String:
m_data.str = new String(other.get<String>()); m_data.str = new String(other.get<String>());
@ -1261,8 +1261,8 @@ constexpr ModelValue &ModelValue::operator=(ModelValue &&other) noexcept {
case Type::SignedInteger16: case Type::SignedInteger16:
case Type::SignedInteger32: case Type::SignedInteger32:
case Type::SignedInteger64: case Type::SignedInteger64:
ox::memcpy(&m_data, &other.m_data, sizeof(m_data)); m_data = other.m_data;
ox::memset(&other.m_data, 0, sizeof(m_data)); other.m_data = {};
break; break;
case Type::String: case Type::String:
m_data.str = other.m_data.str; m_data.str = other.m_data.str;

View File

@ -15,7 +15,7 @@ namespace ox {
OrganicClawReader::OrganicClawReader(const uint8_t *buff, std::size_t buffSize) { OrganicClawReader::OrganicClawReader(const uint8_t *buff, std::size_t buffSize) {
auto json = reinterpret_cast<const char*>(buff); auto json = reinterpret_cast<const char*>(buff);
auto jsonLen = ox::strnlen(json, buffSize); auto jsonLen = ox::strnlen_s(json, buffSize);
Json::CharReaderBuilder parserBuilder; Json::CharReaderBuilder parserBuilder;
auto parser = std::unique_ptr<Json::CharReader>(parserBuilder.newCharReader()); auto parser = std::unique_ptr<Json::CharReader>(parserBuilder.newCharReader());
if (!parser->parse(json, json + jsonLen, &m_json, nullptr)) { if (!parser->parse(json, json + jsonLen, &m_json, nullptr)) {

View File

@ -8,7 +8,11 @@
#pragma once #pragma once
#include <ox/std/def.hpp>
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
#include <json/json.h> #include <json/json.h>
OX_ALLOW_UNSAFE_BUFFERS_END
#include <ox/model/fieldcounter.hpp> #include <ox/model/fieldcounter.hpp>
#include <ox/model/modelhandleradaptor.hpp> #include <ox/model/modelhandleradaptor.hpp>

View File

@ -8,7 +8,11 @@
#pragma once #pragma once
#include <ox/std/def.hpp>
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
#include <json/json.h> #include <json/json.h>
OX_ALLOW_UNSAFE_BUFFERS_END
#include <ox/model/fieldcounter.hpp> #include <ox/model/fieldcounter.hpp>
#include <ox/model/modelhandleradaptor.hpp> #include <ox/model/modelhandleradaptor.hpp>
@ -258,7 +262,9 @@ Result<ox::Buffer> writeOC(const auto &val) noexcept {
const auto str = Json::writeString(jsonBuilder, writer.m_json); const auto str = Json::writeString(jsonBuilder, writer.m_json);
Result<Buffer> buff; Result<Buffer> buff;
buff.value.resize(str.size() + 1); buff.value.resize(str.size() + 1);
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
memcpy(buff.value.data(), str.data(), str.size() + 1); memcpy(buff.value.data(), str.data(), str.size() + 1);
OX_ALLOW_UNSAFE_BUFFERS_END
return buff; return buff;
} }
@ -270,7 +276,9 @@ Result<ox::String> writeOCString(const auto &val) noexcept {
const auto str = Json::writeString(jsonBuilder, writer.m_json); const auto str = Json::writeString(jsonBuilder, writer.m_json);
Result<ox::String> buff; Result<ox::String> buff;
buff.value.resize(str.size()); buff.value.resize(str.size());
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
memcpy(buff.value.data(), str.data(), str.size() + 1); memcpy(buff.value.data(), str.data(), str.size() + 1);
OX_ALLOW_UNSAFE_BUFFERS_END
return buff; return buff;
} }

View File

@ -30,9 +30,12 @@ constexpr T1 strncpy(T1 dest, T2 src, std::size_t maxLen) noexcept {
} }
[[nodiscard]] [[nodiscard]]
constexpr auto strnlen(const char *str1, std::size_t maxLen) noexcept { constexpr size_t strnlen_s(const char *str, size_t const maxLen) noexcept {
std::size_t len = 0; if (!str) [[unlikely]] {
for (; len < maxLen && str1[len]; len++); return 0;
}
size_t len = 0;
for (; len < maxLen && str[len]; len++);
return len; return len;
} }

View File

@ -245,7 +245,7 @@ struct MaybeView<ox::IString<sz>> {
template<Integer_c Integer> template<Integer_c Integer>
[[nodiscard]] [[nodiscard]]
constexpr auto itoa(Integer v) noexcept { constexpr auto intToStr(Integer v) noexcept {
constexpr auto Cap = [] { constexpr auto Cap = [] {
auto out = 0; auto out = 0;
switch (sizeof(Integer)) { switch (sizeof(Integer)) {

View File

@ -8,6 +8,10 @@
#pragma once #pragma once
#if __has_include(<array>)
#include <array>
#endif
#include "array.hpp" #include "array.hpp"
#include "bit.hpp" #include "bit.hpp"
#include "def.hpp" #include "def.hpp"
@ -35,6 +39,20 @@ class Span {
constexpr Span() noexcept = default; constexpr Span() noexcept = default;
#if __has_include(<array>)
template<std::size_t sz>
constexpr Span(std::array<T, sz> &a) noexcept:
m_items(a.data()),
m_size(a.size()) {
}
template<std::size_t sz>
constexpr Span(std::array<ox::remove_const_t<T>, sz> const&a) noexcept:
m_items(a.data()),
m_size(a.size()) {
}
#endif
template<std::size_t sz> template<std::size_t sz>
constexpr Span(ox::Array<T, sz> &a) noexcept: constexpr Span(ox::Array<T, sz> &a) noexcept:
m_items(a.data()), m_items(a.data()),

View File

@ -28,7 +28,7 @@ OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
namespace ox { namespace ox {
template<typename Integer> template<typename Integer>
constexpr ox::IString<21> itoa(Integer v) noexcept; constexpr ox::IString<21> intToStr(Integer v) noexcept;
template<std::size_t SmallStringSize_v> template<std::size_t SmallStringSize_v>
class BasicString { class BasicString {
@ -317,13 +317,13 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
template<std::size_t SmallStringSize_v> template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(int64_t i) noexcept { constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(int64_t i) noexcept {
set(ox::itoa(i)); set(ox::intToStr(i));
return *this; return *this;
} }
template<std::size_t SmallStringSize_v> template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(uint64_t i) noexcept { constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator=(uint64_t i) noexcept {
set(ox::itoa(i)); set(ox::intToStr(i));
return *this; return *this;
} }
@ -371,7 +371,7 @@ constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operat
template<std::size_t SmallStringSize_v> template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator+=(Integer_c auto i) noexcept { constexpr BasicString<SmallStringSize_v> &BasicString<SmallStringSize_v>::operator+=(Integer_c auto i) noexcept {
auto const str = ox::itoa(i); auto const str = ox::intToStr(i);
return this->operator+=(str.c_str()); return this->operator+=(str.c_str());
} }
@ -414,7 +414,7 @@ constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operato
template<std::size_t SmallStringSize_v> template<std::size_t SmallStringSize_v>
constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operator+(Integer_c auto i) const noexcept { constexpr BasicString<SmallStringSize_v> BasicString<SmallStringSize_v>::operator+(Integer_c auto i) const noexcept {
auto const str = ox::itoa(i); auto const str = ox::intToStr(i);
return *this + str; return *this + str;
} }

View File

@ -32,7 +32,9 @@ class StringLiteral: public detail::BaseStringView {
constexpr explicit StringLiteral(const char *str, std::size_t len) noexcept: BaseStringView(str, len) {} constexpr explicit StringLiteral(const char *str, std::size_t len) noexcept: BaseStringView(str, len) {}
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
constexpr explicit StringLiteral(char const *str) noexcept: StringLiteral(str, ox::strlen(str)) {} constexpr explicit StringLiteral(char const *str) noexcept: StringLiteral(str, ox::strlen(str)) {}
OX_ALLOW_UNSAFE_BUFFERS_END
constexpr StringLiteral &operator=(StringLiteral const&other) noexcept { constexpr StringLiteral &operator=(StringLiteral const&other) noexcept {
if (&other != this) { if (&other != this) {

View File

@ -100,7 +100,8 @@ constexpr auto toStdStringView(StringViewCR sv) noexcept {
#endif #endif
constexpr ox::Result<int> atoi(ox::StringViewCR str) noexcept { constexpr ox::Result<int> strToInt(ox::StringViewCR str) noexcept {
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
int total = 0; int total = 0;
int multiplier = 1; int multiplier = 1;
for (auto i = static_cast<int64_t>(str.len()) - 1; i != -1; --i) { for (auto i = static_cast<int64_t>(str.len()) - 1; i != -1; --i) {
@ -113,6 +114,7 @@ constexpr ox::Result<int> atoi(ox::StringViewCR str) noexcept {
} }
} }
return total; return total;
OX_ALLOW_UNSAFE_BUFFERS_END
} }

View File

@ -9,6 +9,8 @@
#include "def.hpp" #include "def.hpp"
#include "strops.hpp" #include "strops.hpp"
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
static_assert(ox::strcmp("asdf", "hijk") < 0, "asdf < hijk"); static_assert(ox::strcmp("asdf", "hijk") < 0, "asdf < hijk");
static_assert(ox::strcmp("hijk", "asdf") > 0, "hijk > asdf"); static_assert(ox::strcmp("hijk", "asdf") > 0, "hijk > asdf");
static_assert(ox::strcmp("resize", "read") > 0, "resize > read"); static_assert(ox::strcmp("resize", "read") > 0, "resize > read");
@ -42,3 +44,5 @@ std::size_t strlen(const char *str) {
} }
#endif #endif
OX_ALLOW_UNSAFE_BUFFERS_END

View File

@ -145,6 +145,7 @@ OX_CLANG_NOWARN_END
return ox::Error{}; return ox::Error{};
} }
}, },
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
{ {
"ABCDEFG != HIJKLMN", "ABCDEFG != HIJKLMN",
[]() { []() {
@ -169,6 +170,7 @@ OX_CLANG_NOWARN_END
return ox::Error(ox::memcmp("ABCDEFGHI", "ABCDEFG", 7) != 0); return ox::Error(ox::memcmp("ABCDEFGHI", "ABCDEFG", 7) != 0);
} }
}, },
OX_ALLOW_UNSAFE_BUFFERS_END
{ {
"IString", "IString",
[]() { []() {

View File

@ -39,6 +39,8 @@ enum LogChan {
Debug = 4, Debug = 4,
}; };
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
template<LogChan chan> template<LogChan chan>
static void log(ox::StringViewCR str) { static void log(ox::StringViewCR str) {
const auto sz = ox::min<std::size_t>(0x100, str.bytes()); const auto sz = ox::min<std::size_t>(0x100, str.bytes());
@ -103,5 +105,7 @@ void oxTraceHook([[maybe_unused]] const char *file, [[maybe_unused]] int line,
#endif #endif
} }
OX_ALLOW_UNSAFE_BUFFERS_END
} }

View File

@ -105,6 +105,10 @@ class UUID {
ox::Array<uint8_t, 16> m_value{}; ox::Array<uint8_t, 16> m_value{};
public: public:
static constexpr auto TypeName = "net.drinkingtea.ox.UUID";
static constexpr auto TypeVersion = 1;
static void seedGenerator(const RandomSeed &seed) noexcept; static void seedGenerator(const RandomSeed &seed) noexcept;
static ox::Result<UUID> generate() noexcept; static ox::Result<UUID> generate() noexcept;

View File

@ -0,0 +1,28 @@
K1;3d1a77ec-265f-4905-2061-4f1003ee2189;O1;net.drinkingtea.nostalgia.gfx.Palette;5;{
"colorNames" :
[
"Color 1",
"Color 2",
"Color 3"
],
"pages" :
[
{
"colors" :
[
{
"b" : 10,
"g" : 5,
"r" : 5
},
{},
{
"b" : 31,
"g" : 31,
"r" : 31
}
],
"name" : "Page 1"
}
]
}

File diff suppressed because it is too large Load Diff

View File

@ -238,7 +238,7 @@ uint_t spriteCount(Context &ctx) noexcept;
ox::Error initConsole(Context &ctx) noexcept; ox::Error initConsole(Context &ctx) noexcept;
void puts(Context &ctx, int column, int row, ox::StringViewCR str) noexcept; void consoleWrite(Context &ctx, int column, int row, ox::StringViewCR str) noexcept;
} }

View File

@ -36,13 +36,13 @@ OX_ALLOW_UNSAFE_BUFFERS_END
setBgStatus(*ctx, 0, true); setBgStatus(*ctx, 0, true);
clearBg(*ctx, 0); clearBg(*ctx, 0);
auto const serr = ox::sfmt<ox::IString<23>>("Error code: {}", static_cast<int64_t>(err)); auto const serr = ox::sfmt<ox::IString<23>>("Error code: {}", static_cast<int64_t>(err));
puts(*ctx, 32 + 1, 1, "SADNESS..."); consoleWrite(*ctx, 32 + 1, 1, "SADNESS...");
puts(*ctx, 32 + 1, 4, "UNEXPECTED STATE:"); consoleWrite(*ctx, 32 + 1, 4, "UNEXPECTED STATE:");
puts(*ctx, 32 + 2, 6, panicMsg); consoleWrite(*ctx, 32 + 2, 6, panicMsg);
if (err) { if (err) {
puts(*ctx, 32 + 2, 8, serr); consoleWrite(*ctx, 32 + 2, 8, serr);
} }
puts(*ctx, 32 + 1, 15, "PLEASE RESTART THE SYSTEM"); consoleWrite(*ctx, 32 + 1, 15, "PLEASE RESTART THE SYSTEM");
// print to terminal if in mGBA // print to terminal if in mGBA
oxErrf("\033[31;1;1mPANIC:\033[0m [{}:{}]: {}\n", file, line, panicMsg); oxErrf("\033[31;1;1mPANIC:\033[0m [{}:{}]: {}\n", file, line, panicMsg);
if (err.msg) { if (err.msg) {

View File

@ -251,7 +251,7 @@ ox::Error initConsole(Context &ctx) noexcept {
return loadBgPalette(ctx, 0, PaletteAddr); return loadBgPalette(ctx, 0, PaletteAddr);
} }
void puts( void consoleWrite(
Context &ctx, Context &ctx,
int const column, int const column,
int const row, int const row,

View File

@ -105,13 +105,13 @@ void PaletteEditorImGui::navigateTo(ox::StringViewCR arg) noexcept {
auto const &color = args[0]; auto const &color = args[0];
auto const &page = args[1]; auto const &page = args[1];
{ {
auto const [c, err] = atoi(color); auto const [c, err] = strToInt(color);
if (!err && static_cast<size_t>(c) < colorCnt(m_pal)) { if (!err && static_cast<size_t>(c) < colorCnt(m_pal)) {
m_selectedColorRow = static_cast<size_t>(c); m_selectedColorRow = static_cast<size_t>(c);
} }
} }
{ {
auto const [pg, err] = atoi(page); auto const [pg, err] = strToInt(page);
if (!err && static_cast<size_t>(pg) < m_pal.pages.size()) { if (!err && static_cast<size_t>(pg) < m_pal.pages.size()) {
m_page = static_cast<size_t>(pg); m_page = static_cast<size_t>(pg);
} }

View File

@ -53,7 +53,7 @@ class PaletteEditorImGui: public studio::Editor {
static void drawColumn(ox::CStringView txt) noexcept; static void drawColumn(ox::CStringView txt) noexcept;
static void drawColumn(ox::Integer_c auto i) noexcept { static void drawColumn(ox::Integer_c auto i) noexcept {
drawColumn(ox::itoa(i)); drawColumn(ox::intToStr(i));
} }
static void numShortcuts(size_t &val, size_t sizeRange) noexcept; static void numShortcuts(size_t &val, size_t sizeRange) noexcept;

View File

@ -35,8 +35,10 @@ ox::Error gfx::DeleteTilesCommand::redo() noexcept {
auto const src = &p[srcPos]; auto const src = &p[srcPos];
auto const dst1 = &p[m_deletePos]; auto const dst1 = &p[m_deletePos];
auto const dst2 = &p[(p.size() - m_deleteSz)]; auto const dst2 = &p[(p.size() - m_deleteSz)];
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
ox::memmove(dst1, src, p.size() - srcPos); ox::memmove(dst1, src, p.size() - srcPos);
ox::memset(dst2, 0, m_deleteSz * sizeof(decltype(p[0]))); ox::memset(dst2, 0, m_deleteSz * sizeof(decltype(p[0])));
OX_ALLOW_UNSAFE_BUFFERS_END
return {}; return {};
} }
@ -47,8 +49,10 @@ ox::Error DeleteTilesCommand::undo() noexcept {
auto const dst1 = &p[m_deletePos + m_deleteSz]; auto const dst1 = &p[m_deletePos + m_deleteSz];
auto const dst2 = src; auto const dst2 = src;
auto const sz = p.size() - m_deletePos - m_deleteSz; auto const sz = p.size() - m_deletePos - m_deleteSz;
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
ox::memmove(dst1, src, sz); ox::memmove(dst1, src, sz);
ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size()); ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size());
OX_ALLOW_UNSAFE_BUFFERS_END
return {}; return {};
} }

View File

@ -27,6 +27,8 @@ InsertTilesCommand::InsertTilesCommand(
} }
} }
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
ox::Error InsertTilesCommand::redo() noexcept { ox::Error InsertTilesCommand::redo() noexcept {
auto &s = getSubSheet(m_img, m_idx); auto &s = getSubSheet(m_img, m_idx);
auto &p = s.pixels; auto &p = s.pixels;
@ -55,6 +57,8 @@ ox::Error InsertTilesCommand::undo() noexcept {
return {}; return {};
} }
OX_ALLOW_UNSAFE_BUFFERS_END
int InsertTilesCommand::commandId() const noexcept { int InsertTilesCommand::commandId() const noexcept {
return static_cast<int>(CommandId::InsertTile); return static_cast<int>(CommandId::InsertTile);
} }

View File

@ -549,7 +549,7 @@ void TileSheetEditorImGui::drawPaletteMenu() noexcept {
ImGui::PushID(static_cast<int>(i)); ImGui::PushID(static_cast<int>(i));
// Column: color idx // Column: color idx
ImGui::TableNextColumn(); ImGui::TableNextColumn();
auto const label = ox::itoa(i + 1); auto const label = ox::intToStr(i + 1);
auto const rowSelected = i == m_view.palIdx(); auto const rowSelected = i == m_view.palIdx();
if (ImGui::Selectable( if (ImGui::Selectable(
label.c_str(), rowSelected, ImGuiSelectableFlags_SpanAllColumns)) { label.c_str(), rowSelected, ImGuiSelectableFlags_SpanAllColumns)) {

View File

@ -5,12 +5,13 @@
#include <ox/claw/write.hpp> #include <ox/claw/write.hpp>
#include <nostalgia/gfx/consts.hpp> #include <nostalgia/gfx/consts.hpp>
#include <nostalgia/gfx/gfx.hpp>
#include "tilesheetpixelgrid.hpp" #include "tilesheetpixelgrid.hpp"
namespace nostalgia::gfx { namespace nostalgia::gfx {
void TileSheetGrid::setPixelSizeMod(float sm) noexcept { void TileSheetGrid::setPixelSizeMod(float const sm) noexcept {
m_pixelSizeMod = sm; m_pixelSizeMod = sm;
} }
@ -18,10 +19,11 @@ ox::Error TileSheetGrid::buildShader() noexcept {
auto const pixelLineVshad = ox::sfmt(VShad, gl::GlslVersion); auto const pixelLineVshad = ox::sfmt(VShad, gl::GlslVersion);
auto const pixelLineFshad = ox::sfmt(FShad, gl::GlslVersion); auto const pixelLineFshad = ox::sfmt(FShad, gl::GlslVersion);
auto const pixelLineGshad = ox::sfmt(GShad, gl::GlslVersion); auto const pixelLineGshad = ox::sfmt(GShad, gl::GlslVersion);
return glutils::buildShaderProgram(pixelLineVshad, pixelLineFshad, pixelLineGshad).moveTo(m_shader); return glutils::buildShaderProgram(
pixelLineVshad, pixelLineFshad, pixelLineGshad).moveTo(m_shader);
} }
void TileSheetGrid::draw(bool update, ox::Vec2 const&scroll) noexcept { void TileSheetGrid::draw(bool const update, ox::Vec2 const&scroll) noexcept {
// the lines just show up bigger on Windows for some reason // the lines just show up bigger on Windows for some reason
if constexpr(ox::defines::OS == ox::OS::Windows) { if constexpr(ox::defines::OS == ox::OS::Windows) {
glLineWidth(3 * m_pixelSizeMod * 0.25f); glLineWidth(3 * m_pixelSizeMod * 0.25f);
@ -51,7 +53,8 @@ void TileSheetGrid::initBufferSet(ox::Vec2 const&paneSize, TileSheet::SubSheet c
// vbo layout // vbo layout
auto const pt1Attr = static_cast<GLuint>(glGetAttribLocation(m_shader, "vPt1")); auto const pt1Attr = static_cast<GLuint>(glGetAttribLocation(m_shader, "vPt1"));
glEnableVertexAttribArray(pt1Attr); glEnableVertexAttribArray(pt1Attr);
glVertexAttribPointer(pt1Attr, 2, GL_FLOAT, GL_FALSE, VertexVboRowLength * sizeof(float), nullptr); glVertexAttribPointer(
pt1Attr, 2, GL_FLOAT, GL_FALSE, VertexVboRowLength * sizeof(float), nullptr);
auto const pt2Attr = static_cast<GLuint>(glGetAttribLocation(m_shader, "vPt2")); auto const pt2Attr = static_cast<GLuint>(glGetAttribLocation(m_shader, "vPt2"));
glEnableVertexAttribArray(pt2Attr); glEnableVertexAttribArray(pt2Attr);
glVertexAttribPointer(pt2Attr, 2, GL_FLOAT, GL_FALSE, VertexVboRowLength * sizeof(float), glVertexAttribPointer(pt2Attr, 2, GL_FLOAT, GL_FALSE, VertexVboRowLength * sizeof(float),
@ -70,18 +73,18 @@ void TileSheetGrid::update(ox::Vec2 const&paneSize, TileSheet::SubSheet const&su
} }
void TileSheetGrid::setBufferObject( void TileSheetGrid::setBufferObject(
ox::Point pt1, ox::Point const pt1,
ox::Point pt2, ox::Point const pt2,
Color32 c, Color32 const c,
float *vbo, ox::Span<float> const vbo,
ox::Vec2 const&pixSize) noexcept { ox::Vec2 const&pixSize) noexcept {
auto const x1 = static_cast<float>(pt1.x) * pixSize.x - 1.f; auto const x1 = static_cast<float>(pt1.x) * pixSize.x - 1.f;
auto const y1 = 1.f - static_cast<float>(pt1.y) * pixSize.y; auto const y1 = 1.f - static_cast<float>(pt1.y) * pixSize.y;
auto const x2 = static_cast<float>(pt2.x) * pixSize.x - 1.f; auto const x2 = static_cast<float>(pt2.x) * pixSize.x - 1.f;
auto const y2 = 1.f - static_cast<float>(pt2.y) * pixSize.y; auto const y2 = 1.f - static_cast<float>(pt2.y) * pixSize.y;
// don't worry, this memcpy gets optimized to something much more ideal // don't worry, this gets optimized to something much more ideal
ox::Array<float, VertexVboLength> const vertices = {x1, y1, x2, y2, redf(c), greenf(c), bluef(c)}; ox::Array<float, VertexVboLength> const vertices = {x1, y1, x2, y2, redf(c), greenf(c), bluef(c)};
memcpy(vbo, vertices.data(), sizeof(vertices)); ox::spancpy(vbo, ox::SpanView<float>{vertices});
} }
void TileSheetGrid::setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept { void TileSheetGrid::setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept {
@ -92,7 +95,8 @@ void TileSheetGrid::setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubShee
} }
auto const pixSize = pixelSize(paneSize); auto const pixSize = pixelSize(paneSize);
auto const set = [&](std::size_t i, ox::Point pt1, ox::Point pt2, Color32 c) { auto const set = [&](std::size_t i, ox::Point pt1, ox::Point pt2, Color32 c) {
auto const vbo = &m_bufferSet.vertices[i * VertexVboLength]; auto const idx = i * VertexVboLength;
auto const vbo = ox::Span{m_bufferSet.vertices} + idx;
setBufferObject(pt1, pt2, c, vbo, pixSize); setBufferObject(pt1, pt2, c, vbo, pixSize);
}; };
// set buffer length // set buffer length

View File

@ -7,7 +7,6 @@
#include <glutils/glutils.hpp> #include <glutils/glutils.hpp>
#include <studio/studio.hpp> #include <studio/studio.hpp>
#include <nostalgia/gfx/gfx.hpp>
#include <nostalgia/gfx/tilesheet.hpp> #include <nostalgia/gfx/tilesheet.hpp>
namespace nostalgia::gfx { namespace nostalgia::gfx {
@ -74,7 +73,7 @@ class TileSheetGrid {
void update(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept; void update(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept;
private: private:
static void setBufferObject(ox::Point pt1, ox::Point pt2, Color32 c, float *vbo, ox::Vec2 const&pixSize) noexcept; static void setBufferObject(ox::Point pt1, ox::Point pt2, Color32 c, ox::Span<float> vbo, ox::Vec2 const&pixSize) noexcept;
void setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept; void setBufferObjects(ox::Vec2 const&paneSize, TileSheet::SubSheet const&subsheet) noexcept;

View File

@ -2,8 +2,6 @@
* Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved. * Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/ */
#include <nostalgia/gfx/consts.hpp>
#include <nostalgia/gfx/ptidxconv.hpp>
#include "tilesheeteditormodel.hpp" #include "tilesheeteditormodel.hpp"
#include "tilesheetpixels.hpp" #include "tilesheetpixels.hpp"
@ -88,11 +86,11 @@ ox::Vec2 TileSheetPixels::pixelSize(ox::Vec2 const&paneSize) const noexcept {
void TileSheetPixels::setPixelBufferObject( void TileSheetPixels::setPixelBufferObject(
ox::Vec2 const&paneSize, ox::Vec2 const&paneSize,
unsigned vertexRow, unsigned const vertexRow,
float x, float y, float x, float y,
Color16 color, Color16 const color,
float *vbo, ox::Span<float> const vbo,
GLuint *ebo) const noexcept { ox::Span<GLuint> const ebo) const noexcept {
auto const [xmod, ymod] = pixelSize(paneSize); auto const [xmod, ymod] = pixelSize(paneSize);
x *= xmod; x *= xmod;
y *= -ymod; y *= -ymod;
@ -106,12 +104,12 @@ void TileSheetPixels::setPixelBufferObject(
x + xmod, y + ymod, r, g, b, // top right x + xmod, y + ymod, r, g, b, // top right
x, y + ymod, r, g, b, // top left x, y + ymod, r, g, b, // top left
}; };
memcpy(vbo, vertices.data(), sizeof(vertices)); ox::spancpy(vbo, ox::SpanView<float>{vertices});
std::array const elms = { std::array const elms = {
vertexRow + 0, vertexRow + 1, vertexRow + 2, vertexRow + 0, vertexRow + 1, vertexRow + 2,
vertexRow + 2, vertexRow + 3, vertexRow + 0, vertexRow + 2, vertexRow + 3, vertexRow + 0,
}; };
memcpy(ebo, elms.data(), sizeof(elms)); ox::spancpy(ebo, ox::SpanView<GLuint>{elms});
} }
void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept { void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept {
@ -137,8 +135,8 @@ void TileSheetPixels::setBufferObjects(ox::Vec2 const&paneSize) noexcept {
auto const pt = idxToPt(static_cast<int>(i), subSheet.columns); auto const pt = idxToPt(static_cast<int>(i), subSheet.columns);
auto const fx = static_cast<float>(pt.x); auto const fx = static_cast<float>(pt.x);
auto const fy = static_cast<float>(pt.y); auto const fy = static_cast<float>(pt.y);
auto const vbo = &m_bufferSet.vertices[i * vboLen]; auto const vbo = ox::Span{m_bufferSet.vertices} + i * vboLen;
auto const ebo = &m_bufferSet.elements[i * VertexEboLength]; auto const ebo = ox::Span{m_bufferSet.elements} + i * VertexEboLength;
if (i * vboLen + vboLen > m_bufferSet.vertices.size()) { if (i * vboLen + vboLen > m_bufferSet.vertices.size()) {
return; return;
} }

View File

@ -6,11 +6,9 @@
#include <ox/std/vec.hpp> #include <ox/std/vec.hpp>
#include <glutils/glutils.hpp>
#include <studio/studio.hpp>
#include <nostalgia/gfx/color.hpp> #include <nostalgia/gfx/color.hpp>
#include <nostalgia/gfx/gfx.hpp>
#include <glutils/glutils.hpp>
namespace nostalgia::gfx { namespace nostalgia::gfx {
@ -44,15 +42,15 @@ class TileSheetPixels {
private: private:
void setPixelBufferObject( void setPixelBufferObject(
ox::Vec2 const&paneS, ox::Vec2 const&paneSize,
unsigned vertexRow, unsigned vertexRow,
float x, float x,
float y, float y,
Color16 color, Color16 color,
float *vbo, ox::Span<float> vbo,
GLuint *ebo) const noexcept; ox::Span<GLuint> ebo) const noexcept;
void setBufferObjects(ox::Vec2 const&paneS) noexcept; void setBufferObjects(ox::Vec2 const&paneSize) noexcept;
}; };

View File

@ -69,7 +69,7 @@ static ox::Error runTest(turbine::Context &tctx) {
OX_RETURN_ERROR(gfx::loadSpriteTileSheet(*cctx, "/TileSheets/Charset.nts")); OX_RETURN_ERROR(gfx::loadSpriteTileSheet(*cctx, "/TileSheets/Charset.nts"));
OX_RETURN_ERROR(gfx::loadSpritePalette(*cctx, "/Palettes/Chester.npal")); OX_RETURN_ERROR(gfx::loadSpritePalette(*cctx, "/Palettes/Chester.npal"));
OX_RETURN_ERROR(gfx::initConsole(*cctx)); OX_RETURN_ERROR(gfx::initConsole(*cctx));
gfx::puts(*cctx, 10, 9, "DOPENESS!!!"); gfx::consoleWrite(*cctx, 10, 9, "DOPENESS!!!");
turbine::setUpdateHandler(tctx, testUpdateHandler); turbine::setUpdateHandler(tctx, testUpdateHandler);
turbine::setKeyEventHandler(tctx, testKeyEventHandler); turbine::setKeyEventHandler(tctx, testKeyEventHandler);
return turbine::run(tctx); return turbine::run(tctx);

View File

@ -17,6 +17,12 @@
#include "font.hpp" #include "font.hpp"
#include "studioui.hpp" #include "studioui.hpp"
#ifdef OX_OS_Darwin
#define STUDIO_CTRL "Cmd"
#else
#define STUDIO_CTRL "Ctrl"
#endif
namespace studio { namespace studio {
static bool shutdownHandler(turbine::Context &ctx) { static bool shutdownHandler(turbine::Context &ctx) {
@ -174,45 +180,64 @@ bool StudioUI::handleShutdown() noexcept {
void StudioUI::drawMenu() noexcept { void StudioUI::drawMenu() noexcept {
if (ImGui::BeginMainMenuBar()) { if (ImGui::BeginMainMenuBar()) {
if (ImGui::BeginMenu("File")) { if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("New...", "Ctrl+N", false, m_project)) { if (ImGui::MenuItem("New...", STUDIO_CTRL "+N", false, m_project)) {
m_newMenu.open(); m_newMenu.open();
} }
if (ImGui::MenuItem("New Project...", "Ctrl+Shift+N")) { if (ImGui::MenuItem("New Project...", STUDIO_CTRL "+Shift+N")) {
m_newProject.open(); m_newProject.open();
} }
if (ImGui::MenuItem("Open Project...", "Ctrl+O")) { if (ImGui::MenuItem("Open Project...", STUDIO_CTRL "+O")) {
m_taskRunner.add(*ox::make<FileDialogManager>(this, &StudioUI::openProjectPath)); m_taskRunner.add(*ox::make<FileDialogManager>(this, &StudioUI::openProjectPath));
} }
if (ImGui::MenuItem("Save", "Ctrl+S", false, m_activeEditor && m_activeEditor->unsavedChanges())) { if (ImGui::MenuItem(
"Save",
STUDIO_CTRL "+S",
false,
m_activeEditor && m_activeEditor->unsavedChanges())) {
m_activeEditor->save(); m_activeEditor->save();
} }
if (ImGui::MenuItem("Quit", "Ctrl+Q")) { if (ImGui::MenuItem("Quit", STUDIO_CTRL "+Q")) {
turbine::requestShutdown(m_tctx); turbine::requestShutdown(m_tctx);
} }
ImGui::EndMenu(); ImGui::EndMenu();
} }
if (ImGui::BeginMenu("Edit")) { if (ImGui::BeginMenu("Edit")) {
auto undoStack = m_activeEditor ? m_activeEditor->undoStack() : nullptr; auto undoStack = m_activeEditor ? m_activeEditor->undoStack() : nullptr;
if (ImGui::MenuItem("Undo", "Ctrl+Z", false, undoStack && undoStack->canUndo())) { if (ImGui::MenuItem(
"Undo", STUDIO_CTRL "+Z", false, undoStack && undoStack->canUndo())) {
oxLogError(undoStack->undo()); oxLogError(undoStack->undo());
} }
if (ImGui::MenuItem("Redo", "Ctrl+Y", false, undoStack && undoStack->canRedo())) { if (ImGui::MenuItem(
"Redo", STUDIO_CTRL "+Y", false, undoStack && undoStack->canRedo())) {
oxLogError(undoStack->redo()); oxLogError(undoStack->redo());
} }
ImGui::Separator(); ImGui::Separator();
if (ImGui::MenuItem("Copy", "Ctrl+C", false, m_activeEditor && m_activeEditor->copyEnabled())) { if (ImGui::MenuItem(
"Copy",
STUDIO_CTRL "+C",
false,
m_activeEditor && m_activeEditor->copyEnabled())) {
m_activeEditor->copy(); m_activeEditor->copy();
} }
if (ImGui::MenuItem("Cut", "Ctrl+X", false, m_activeEditor && m_activeEditor->cutEnabled())) { if (ImGui::MenuItem(
"Cut",
STUDIO_CTRL "+X",
false,
m_activeEditor && m_activeEditor->cutEnabled())) {
m_activeEditor->cut(); m_activeEditor->cut();
} }
if (ImGui::MenuItem("Paste", "Ctrl+V", false, m_activeEditor && m_activeEditor->pasteEnabled())) { if (ImGui::MenuItem(
"Paste",
STUDIO_CTRL "+V",
false,
m_activeEditor && m_activeEditor->pasteEnabled())) {
m_activeEditor->paste(); m_activeEditor->paste();
} }
ImGui::EndMenu(); ImGui::EndMenu();
} }
if (ImGui::BeginMenu("View")) { if (ImGui::BeginMenu("View")) {
if (ImGui::MenuItem("Project Explorer", "Ctrl+Shift+1", m_showProjectExplorer)) { if (ImGui::MenuItem(
"Project Explorer", STUDIO_CTRL "+Shift+1", m_showProjectExplorer)) {
toggleProjectExplorer(); toggleProjectExplorer();
} }
ImGui::EndMenu(); ImGui::EndMenu();
@ -278,12 +303,8 @@ void StudioUI::drawTabs() noexcept {
if (m_activeEditor == (*it).get()) { if (m_activeEditor == (*it).get()) {
m_activeEditor = nullptr; m_activeEditor = nullptr;
} }
try { if (auto const err = m_editors.erase(it).moveTo(it)) {
OX_THROW_ERROR(m_editors.erase(it).moveTo(it)); oxErrf("Editor tab deletion failed: {} ({}:{})\n", toStr(err), err.src.file_name(), err.src.line());
} catch (ox::Exception const&ex) {
oxErrf("Editor tab deletion failed: {} ({}:{})\n", ex.what(), ex.src.file_name(), ex.src.line());
} catch (std::exception const&ex) {
oxErrf("Editor tab deletion failed: {}\n", ex.what());
} }
} }
} else { } else {
@ -478,12 +499,25 @@ ox::Error StudioUI::createOpenProject(ox::StringViewCR path) noexcept {
ox::Error StudioUI::openProjectPath(ox::StringParam path) noexcept { ox::Error StudioUI::openProjectPath(ox::StringParam path) noexcept {
OX_REQUIRE_M(fs, keel::loadRomFs(path.view())); OX_REQUIRE_M(fs, keel::loadRomFs(path.view()));
OX_RETURN_ERROR(keel::setRomFs(keelCtx(m_tctx), std::move(fs))); keel::DuplicateSet ds;
OX_RETURN_ERROR(keel::setRomFs(keelCtx(m_tctx), std::move(fs), ds));
if (ds.size()) {
ox::String msg;
msg += "Multiple files have the same UUID:\n";
for (auto const &k : ds.keys()) {
msg += ox::sfmt("\n\t{}:\n", k.toString());
for (auto const &v : ds[k]) {
msg += ox::sfmt("\t\t - {}\n", v);
}
}
m_messagePopup.show(msg);
}
OX_RETURN_ERROR( OX_RETURN_ERROR(
ox::make_unique_catch<Project>(keelCtx(m_tctx), std::move(path), m_projectDataDir) ox::make_unique_catch<Project>(keelCtx(m_tctx), std::move(path), m_projectDataDir)
.moveTo(m_project)); .moveTo(m_project));
m_sctx.project = m_project.get(); m_sctx.project = m_project.get();
turbine::setWindowTitle(m_tctx, ox::sfmt("{} - {}", keelCtx(m_tctx).appName, m_project->projectPath())); turbine::setWindowTitle(
m_tctx, ox::sfmt("{} - {}", keelCtx(m_tctx).appName, m_project->projectPath()));
m_deleteConfirmation.deleteFile.connect(m_sctx.project, &Project::deleteItem); m_deleteConfirmation.deleteFile.connect(m_sctx.project, &Project::deleteItem);
m_copyFilePopup.makeCopy.connect(m_sctx.project, &Project::copyItem); m_copyFilePopup.makeCopy.connect(m_sctx.project, &Project::copyItem);
m_newDirDialog.newDir.connect(m_sctx.project, &Project::mkdir); m_newDirDialog.newDir.connect(m_sctx.project, &Project::mkdir);

View File

@ -52,11 +52,12 @@ class StudioUI: public ox::SignalHandler {
"Close Application?", "Close Application?",
"There are files with unsaved changes. Close?" "There are files with unsaved changes. Close?"
}; };
ig::MessagePopup m_messagePopup{"Message", ""};
MakeCopyPopup m_copyFilePopup; MakeCopyPopup m_copyFilePopup;
RenameFile m_renameFile; RenameFile m_renameFile;
NewProject m_newProject; NewProject m_newProject;
AboutPopup m_aboutPopup; AboutPopup m_aboutPopup;
ox::Array<Widget*, 9> const m_widgets { ox::Array<Widget*, 10> const m_widgets {
&m_closeFileConfirm, &m_closeFileConfirm,
&m_closeAppConfirm, &m_closeAppConfirm,
&m_copyFilePopup, &m_copyFilePopup,
@ -66,6 +67,7 @@ class StudioUI: public ox::SignalHandler {
&m_deleteConfirmation, &m_deleteConfirmation,
&m_newDirDialog, &m_newDirDialog,
&m_renameFile, &m_renameFile,
&m_messagePopup,
}; };
bool m_showProjectExplorer = true; bool m_showProjectExplorer = true;
struct NavAction { struct NavAction {

View File

@ -169,7 +169,9 @@ TextInput<ox::IString<MaxChars>> InputText(
out.changed = ImGui::InputText( out.changed = ImGui::InputText(
label.c_str(), out.text.data(), MaxChars + 1, flags, callback, user_data); label.c_str(), out.text.data(), MaxChars + 1, flags, callback, user_data);
if (out.changed) { if (out.changed) {
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
std::ignore = out.text.unsafeResize(ox::strlen(out.text.c_str())); std::ignore = out.text.unsafeResize(ox::strlen(out.text.c_str()));
OX_ALLOW_UNSAFE_BUFFERS_END
} }
return out; return out;
} }
@ -186,7 +188,9 @@ TextInput<ox::IString<MaxChars>> InputTextWithHint(
out.changed = ImGui::InputTextWithHint( out.changed = ImGui::InputTextWithHint(
label.c_str(), hint.c_str(), out.text.data(), MaxChars + 1, flags, callback, user_data); label.c_str(), hint.c_str(), out.text.data(), MaxChars + 1, flags, callback, user_data);
if (out.changed) { if (out.changed) {
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
std::ignore = out.text.unsafeResize(ox::strlen(out.text.c_str())); std::ignore = out.text.unsafeResize(ox::strlen(out.text.c_str()));
OX_ALLOW_UNSAFE_BUFFERS_END
} }
return out; return out;
} }
@ -201,7 +205,9 @@ bool InputText(
auto const out = ImGui::InputText( auto const out = ImGui::InputText(
label.c_str(), text.data(), StrCap + 1, flags, callback, user_data); label.c_str(), text.data(), StrCap + 1, flags, callback, user_data);
if (out) { if (out) {
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
std::ignore = text.unsafeResize(ox::strlen(text.c_str())); std::ignore = text.unsafeResize(ox::strlen(text.c_str()));
OX_ALLOW_UNSAFE_BUFFERS_END
} }
return out; return out;
} }
@ -223,6 +229,10 @@ PopupResponse PopupControlsOkCancel(
ox::CStringViewCR ok = "OK", ox::CStringViewCR ok = "OK",
ox::CStringViewCR cancel = "Cancel"); ox::CStringViewCR cancel = "Cancel");
PopupResponse PopupControlsOk(
bool &popupOpen,
ox::CStringViewCR ok);
[[nodiscard]] [[nodiscard]]
bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show, ImVec2 const&sz = {285, 0}); bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show, ImVec2 const&sz = {285, 0});
@ -250,7 +260,7 @@ bool ComboBox(ox::CStringView lbl, ox::Span<const ox::String> list, size_t &sele
/** /**
* *
* @param lbl * @param lbl
* @param callback * @param f callback function
* @param selectedIdx * @param selectedIdx
* @return true if new value selected, false otherwise * @return true if new value selected, false otherwise
*/ */
@ -285,7 +295,7 @@ bool ListBox(ox::CStringViewCR name, ox::SpanView<ox::String> const&list, size_t
class FilePicker { class FilePicker {
private: private:
bool m_show{}; bool m_show{};
studio::StudioContext &m_sctx; StudioContext &m_sctx;
ox::String const m_title; ox::String const m_title;
ox::String const m_fileExt; ox::String const m_fileExt;
ImVec2 const m_size; ImVec2 const m_size;
@ -304,8 +314,8 @@ class FilePicker {
}; };
class QuestionPopup: public Widget { class Popup: public Widget {
private: protected:
enum class Stage { enum class Stage {
Closed, Closed,
Opening, Opening,
@ -314,12 +324,11 @@ class QuestionPopup: public Widget {
Stage m_stage = Stage::Closed; Stage m_stage = Stage::Closed;
bool m_open{}; bool m_open{};
ox::String m_title; ox::String m_title;
ox::String m_question;
public: public:
ox::Signal<ox::Error(PopupResponse)> response; ox::Signal<ox::Error(PopupResponse)> response;
QuestionPopup(ox::StringParam title, ox::StringParam question) noexcept; explicit Popup(ox::StringParam title) noexcept;
void open() noexcept; void open() noexcept;
@ -328,7 +337,33 @@ class QuestionPopup: public Widget {
[[nodiscard]] [[nodiscard]]
bool isOpen() const noexcept; bool isOpen() const noexcept;
void draw(StudioContext &ctx) noexcept; };
class QuestionPopup: public Popup {
private:
ox::String m_question;
public:
ox::Signal<ox::Error(PopupResponse)> response;
QuestionPopup(ox::StringParam title, ox::StringParam question) noexcept;
void draw(StudioContext &ctx) noexcept override;
};
class MessagePopup: public Popup {
private:
ox::String m_msg;
public:
ox::Signal<ox::Error(PopupResponse)> response;
MessagePopup(ox::StringParam title, ox::StringParam msg) noexcept;
void show(ox::StringParam msg) noexcept;
void draw(StudioContext &ctx) noexcept override;
}; };

View File

@ -12,10 +12,12 @@
namespace studio { namespace studio {
FDFilterItem::FDFilterItem(ox::StringViewCR pName, ox::StringViewCR pSpec) noexcept { FDFilterItem::FDFilterItem(ox::StringViewCR pName, ox::StringViewCR pSpec) noexcept {
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
name.resize(pName.len() + 1); name.resize(pName.len() + 1);
ox::strncpy(name.data(), pName.data(), pName.len()); ox::strncpy(name.data(), pName.data(), pName.len());
spec.resize(pSpec.len() + 1); spec.resize(pSpec.len() + 1);
ox::strncpy(spec.data(), pSpec.data(), pSpec.len()); ox::strncpy(spec.data(), pSpec.data(), pSpec.len());
OX_ALLOW_UNSAFE_BUFFERS_END
} }
static ox::Result<ox::String> toResult(nfdresult_t r, NFD::UniquePathN const&path) noexcept { static ox::Result<ox::String> toResult(nfdresult_t r, NFD::UniquePathN const&path) noexcept {

View File

@ -88,7 +88,7 @@ PopupResponse PopupControlsOk(
auto out = PopupResponse::None; auto out = PopupResponse::None;
constexpr auto btnSz = ImVec2{50, BtnSz.y}; constexpr auto btnSz = ImVec2{50, BtnSz.y};
ImGui::Separator(); ImGui::Separator();
ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x - 101); ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x - 42);
if (ImGui::Button(ok.c_str(), btnSz)) { if (ImGui::Button(ok.c_str(), btnSz)) {
popupOpen = false; popupOpen = false;
out = PopupResponse::OK; out = PopupResponse::OK;
@ -245,24 +245,28 @@ void FilePicker::show() noexcept {
} }
QuestionPopup::QuestionPopup(ox::StringParam title, ox::StringParam question) noexcept: Popup::Popup(ox::StringParam title) noexcept: m_title{std::move(title)} {
m_title{std::move(title)},
m_question{std::move(question)} {
} }
void QuestionPopup::open() noexcept { void Popup::open() noexcept {
m_stage = Stage::Opening; m_stage = Stage::Opening;
} }
void QuestionPopup::close() noexcept { void Popup::close() noexcept {
m_stage = Stage::Closed; m_stage = Stage::Closed;
m_open = false; m_open = false;
} }
bool QuestionPopup::isOpen() const noexcept { bool Popup::isOpen() const noexcept {
return m_open; return m_open;
} }
QuestionPopup::QuestionPopup(ox::StringParam title, ox::StringParam question) noexcept:
Popup{std::move(title)},
m_question{std::move(question)} {
}
void QuestionPopup::draw(StudioContext &ctx) noexcept { void QuestionPopup::draw(StudioContext &ctx) noexcept {
switch (m_stage) { switch (m_stage) {
case Stage::Closed: case Stage::Closed:
@ -298,6 +302,49 @@ void QuestionPopup::draw(StudioContext &ctx) noexcept {
} }
MessagePopup::MessagePopup(ox::StringParam title, ox::StringParam msg) noexcept:
Popup{std::move(title)},
m_msg{std::move(msg)} {
}
void MessagePopup::show(ox::StringParam msg) noexcept {
m_msg = std::move(msg);
open();
}
void MessagePopup::draw(StudioContext &ctx) noexcept {
switch (m_stage) {
case Stage::Closed:
break;
case Stage::Opening:
ImGui::OpenPopup(m_title.c_str());
m_stage = Stage::Open;
m_open = true;
[[fallthrough]];
case Stage::Open:
centerNextWindow(ctx.tctx);
ImGui::SetNextWindowSize({});
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
if (ImGui::BeginPopupModal(m_title.c_str(), &m_open, modalFlags)) {
ImGui::Text("%s", m_msg.c_str());
auto const r = PopupControlsOk(m_open, "OK");
switch (r) {
case PopupResponse::None:
break;
case PopupResponse::OK:
response.emit(r);
close();
break;
case PopupResponse::Cancel:
break;
}
ImGui::EndPopup();
}
break;
}
}
bool s_mainWinHasFocus{}; bool s_mainWinHasFocus{};
bool mainWinHasFocus() noexcept { bool mainWinHasFocus() noexcept {
return s_mainWinHasFocus; return s_mainWinHasFocus;

View File

@ -44,10 +44,10 @@ static ox::Result<std::size_t> findPreloadSection() noexcept {
// media section // media section
constexpr auto headerP2 = "DER_____________"; constexpr auto headerP2 = "DER_____________";
constexpr auto headerP1 = "KEEL_PRELOAD_HEA"; constexpr auto headerP1 = "KEEL_PRELOAD_HEA";
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
constexpr auto headerP1Len = ox::strlen(headerP2); constexpr auto headerP1Len = ox::strlen(headerP2);
constexpr auto headerP2Len = ox::strlen(headerP1); constexpr auto headerP2Len = ox::strlen(headerP1);
constexpr auto headerLen = headerP1Len + headerP2Len; constexpr auto headerLen = headerP1Len + headerP2Len;
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
for (auto current = MEM_ROM; current < reinterpret_cast<char*>(0x0a000000); current += headerLen) { for (auto current = MEM_ROM; current < reinterpret_cast<char*>(0x0a000000); current += headerLen) {
if (memcmp(current, headerP1, headerP1Len) == 0 && if (memcmp(current, headerP1, headerP1Len) == 0 &&
memcmp(current + headerP1Len, headerP2, headerP2Len) == 0) { memcmp(current + headerP1Len, headerP2, headerP2Len) == 0) {

View File

@ -18,7 +18,9 @@ ox::String getClipboardText(Context &ctx) noexcept {
void setClipboardText(Context &ctx, ox::StringViewCR text) noexcept { void setClipboardText(Context &ctx, ox::StringViewCR text) noexcept {
auto cstr = ox_malloca(text.bytes() + 1, char); auto cstr = ox_malloca(text.bytes() + 1, char);
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
ox::strncpy(cstr.get(), text.data(), text.bytes()); ox::strncpy(cstr.get(), text.data(), text.bytes());
OX_ALLOW_UNSAFE_BUFFERS_END
glfwSetClipboardString(ctx.window, cstr.get()); glfwSetClipboardString(ctx.window, cstr.get());
} }

View File

@ -267,7 +267,9 @@ ox::Error setWindowIcon(Context &ctx, ox::SpanView<ox::SpanView<uint8_t>> const
void setWindowTitle(Context &ctx, ox::StringViewCR title) noexcept { void setWindowTitle(Context &ctx, ox::StringViewCR title) noexcept {
auto cstr = ox_malloca(title.bytes() + 1, char); auto cstr = ox_malloca(title.bytes() + 1, char);
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
ox::strncpy(cstr.get(), title.data(), title.bytes()); ox::strncpy(cstr.get(), title.data(), title.bytes());
OX_ALLOW_UNSAFE_BUFFERS_END
glfwSetWindowTitle(ctx.window, cstr.get()); glfwSetWindowTitle(ctx.window, cstr.get());
} }