Compare commits
8 Commits
cee4f65d4a
...
3308b4dd72
Author | SHA1 | Date | |
---|---|---|---|
3308b4dd72 | |||
27f4703a9a | |||
6af00d9a2e | |||
86b9f9316e | |||
a0ed1b3f62 | |||
8dad624b21 | |||
dc6605fd48 | |||
c78d3cf638 |
4
deps/ox/src/ox/logconn/circularbuff.hpp
vendored
4
deps/ox/src/ox/logconn/circularbuff.hpp
vendored
@ -45,6 +45,7 @@ class CirculerBuffer {
|
|||||||
if (sz > avail()) {
|
if (sz > avail()) {
|
||||||
return OxError(1, "Insufficient space in buffer");
|
return OxError(1, "Insufficient space in buffer");
|
||||||
}
|
}
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
// write seg 1
|
// write seg 1
|
||||||
const auto seg1Sz = ox::min(sz, m_buff.size() - m_writePt);
|
const auto seg1Sz = ox::min(sz, m_buff.size() - m_writePt);
|
||||||
ox::listcpy(&m_buff[m_writePt], &buff[0], seg1Sz);
|
ox::listcpy(&m_buff[m_writePt], &buff[0], seg1Sz);
|
||||||
@ -56,6 +57,7 @@ class CirculerBuffer {
|
|||||||
ox::listcpy(&m_buff[0], &buff[seg1Sz], seg2Sz);
|
ox::listcpy(&m_buff[0], &buff[seg1Sz], seg2Sz);
|
||||||
oxAssert(m_buff[0] == buff[seg1Sz], "break");
|
oxAssert(m_buff[0] == buff[seg1Sz], "break");
|
||||||
}
|
}
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +92,9 @@ class CirculerBuffer {
|
|||||||
m_readPt -= m_buff.size();
|
m_readPt -= m_buff.size();
|
||||||
// read seg 2
|
// read seg 2
|
||||||
const auto seg2Sz = bytesRead - seg1Sz;
|
const auto seg2Sz = bytesRead - seg1Sz;
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
ox::listcpy(&out[seg1Sz], &m_buff[0], seg2Sz);
|
ox::listcpy(&out[seg1Sz], &m_buff[0], seg2Sz);
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
}
|
}
|
||||||
return bytesRead;
|
return bytesRead;
|
||||||
}
|
}
|
||||||
|
10
deps/ox/src/ox/mc/intops.hpp
vendored
10
deps/ox/src/ox/mc/intops.hpp
vendored
@ -57,7 +57,7 @@ static_assert(highestBit(uint64_t(1) << 31) == 31);
|
|||||||
static_assert(highestBit(uint64_t(1) << 63) == 63);
|
static_assert(highestBit(uint64_t(1) << 63) == 63);
|
||||||
|
|
||||||
struct McInt {
|
struct McInt {
|
||||||
uint8_t data[9] = {};
|
ox::Array<uint8_t, 9> data{};
|
||||||
// length of integer in bytes
|
// length of integer in bytes
|
||||||
std::size_t length = 0;
|
std::size_t length = 0;
|
||||||
};
|
};
|
||||||
@ -104,7 +104,7 @@ 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::memcpy(out.data, &intermediate, sizeof(intermediate));
|
ox::memcpy(&out.data[0], &intermediate, sizeof(intermediate));
|
||||||
}
|
}
|
||||||
out.length = bytes;
|
out.length = bytes;
|
||||||
}
|
}
|
||||||
@ -160,7 +160,7 @@ constexpr Result<I> decodeInteger(Reader_c auto&rdr, std::size_t *bytesRead) noe
|
|||||||
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.data(), &decoded, sizeof(decoded));
|
ox::memcpy(&d[0], &decoded, sizeof(decoded));
|
||||||
auto bit = negBit;
|
auto bit = negBit;
|
||||||
for (; bit < ox::min<std::size_t>(Bits<I>, 32); ++bit) {
|
for (; bit < ox::min<std::size_t>(Bits<I>, 32); ++bit) {
|
||||||
d[0] |= 1 << bit;
|
d[0] |= 1 << bit;
|
||||||
@ -175,7 +175,7 @@ constexpr Result<I> decodeInteger(Reader_c auto&rdr, std::size_t *bytesRead) noe
|
|||||||
d[0] = d[1];
|
d[0] = d[1];
|
||||||
d[1] = d0Tmp;
|
d[1] = d0Tmp;
|
||||||
}
|
}
|
||||||
ox::memcpy(&out, d.data(), sizeof(out));
|
ox::memcpy(&out, &d[0], sizeof(out));
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,7 +185,7 @@ constexpr Result<I> decodeInteger(Reader_c auto&rdr, std::size_t *bytesRead) noe
|
|||||||
template<typename I>
|
template<typename I>
|
||||||
Result<I> decodeInteger(McInt m) noexcept {
|
Result<I> decodeInteger(McInt m) noexcept {
|
||||||
std::size_t bytesRead{};
|
std::size_t bytesRead{};
|
||||||
BufferReader br({reinterpret_cast<const char*>(m.data), 9});
|
BufferReader br({reinterpret_cast<const char*>(m.data.data()), 9});
|
||||||
return decodeInteger<I>(br, &bytesRead);
|
return decodeInteger<I>(br, &bytesRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
deps/ox/src/ox/mc/presenceindicator.hpp
vendored
2
deps/ox/src/ox/mc/presenceindicator.hpp
vendored
@ -147,11 +147,13 @@ constexpr FieldBitmap::FieldBitmap(uint8_t *map, std::size_t maxLen) noexcept:
|
|||||||
|
|
||||||
constexpr Error FieldBitmap::set(std::size_t i, bool on) noexcept {
|
constexpr Error FieldBitmap::set(std::size_t i, bool on) noexcept {
|
||||||
if (i / 8 < m_mapLen) {
|
if (i / 8 < m_mapLen) {
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
if (on) {
|
if (on) {
|
||||||
m_map[i / 8] |= 1 << (i % 8);
|
m_map[i / 8] |= 1 << (i % 8);
|
||||||
} else {
|
} else {
|
||||||
m_map[i / 8] &= ~static_cast<uint8_t>(1 << (i % 8));
|
m_map[i / 8] &= ~static_cast<uint8_t>(1 << (i % 8));
|
||||||
}
|
}
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
return {};
|
return {};
|
||||||
} else {
|
} else {
|
||||||
return OxError(McPresenceMapOverflow);
|
return OxError(McPresenceMapOverflow);
|
||||||
|
10
deps/ox/src/ox/mc/read.hpp
vendored
10
deps/ox/src/ox/mc/read.hpp
vendored
@ -214,7 +214,9 @@ constexpr Error MetalClawReaderTemplate<Reader>::field(const char *name, auto *v
|
|||||||
auto &handler = *reader.interface();
|
auto &handler = *reader.interface();
|
||||||
oxReturnError(handler.setTypeInfo("List", 0, {}, static_cast<std::size_t>(len)));
|
oxReturnError(handler.setTypeInfo("List", 0, {}, static_cast<std::size_t>(len)));
|
||||||
for (std::size_t i = 0; i < len; ++i) {
|
for (std::size_t i = 0; i < len; ++i) {
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
oxReturnError(handler.field({}, &val[i]));
|
oxReturnError(handler.field({}, &val[i]));
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
oxTracef("ox.mc.read.field(T)", "{}, length: {}", name, valLen);
|
oxTracef("ox.mc.read.field(T)", "{}, length: {}", name, valLen);
|
||||||
@ -380,9 +382,9 @@ constexpr Error MetalClawReaderTemplate<Reader>::fieldCString(const char*, char
|
|||||||
// re-allocate in case too small
|
// re-allocate in case too small
|
||||||
safeDelete(*val);
|
safeDelete(*val);
|
||||||
*val = new char[size + 1];
|
*val = new char[size + 1];
|
||||||
auto data = *val;
|
auto data = ox::Span{*val, size + 1};
|
||||||
// read the string
|
// read the string
|
||||||
oxReturnError(m_reader.read(data, size));
|
oxReturnError(m_reader.read(data.data(), size));
|
||||||
data[size] = 0;
|
data[size] = 0;
|
||||||
}
|
}
|
||||||
++m_field;
|
++m_field;
|
||||||
@ -402,9 +404,9 @@ constexpr Error MetalClawReaderTemplate<Reader>::fieldCString(const char*, char
|
|||||||
*val = new char[size + 1];
|
*val = new char[size + 1];
|
||||||
buffLen = size + 1;
|
buffLen = size + 1;
|
||||||
}
|
}
|
||||||
auto data = *val;
|
auto data = ox::Span{*val, size + 1};
|
||||||
// read the string
|
// read the string
|
||||||
oxReturnError(m_reader.read(data, size));
|
oxReturnError(m_reader.read(data.data(), size));
|
||||||
data[size] = 0;
|
data[size] = 0;
|
||||||
} else {
|
} else {
|
||||||
auto data = *val;
|
auto data = *val;
|
||||||
|
14
deps/ox/src/ox/mc/write.hpp
vendored
14
deps/ox/src/ox/mc/write.hpp
vendored
@ -117,7 +117,7 @@ class MetalClawWriter {
|
|||||||
bool fieldSet = false;
|
bool fieldSet = false;
|
||||||
if (val && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
if (val && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||||
auto mi = mc::encodeInteger(val);
|
auto mi = mc::encodeInteger(val);
|
||||||
oxReturnError(m_writer.write(reinterpret_cast<const char*>(mi.data), mi.length));
|
oxReturnError(m_writer.write(reinterpret_cast<const char*>(mi.data.data()), mi.length));
|
||||||
fieldSet = true;
|
fieldSet = true;
|
||||||
}
|
}
|
||||||
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
oxReturnError(m_fieldPresence.set(static_cast<std::size_t>(m_field), fieldSet));
|
||||||
@ -194,7 +194,7 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, const BasicString<Sm
|
|||||||
if (val->len() && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
if (val->len() && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||||
// write the length
|
// write the length
|
||||||
const auto strLen = mc::encodeInteger(val->len());
|
const auto strLen = mc::encodeInteger(val->len());
|
||||||
oxReturnError(m_writer.write(reinterpret_cast<const char*>(strLen.data), strLen.length));
|
oxReturnError(m_writer.write(reinterpret_cast<const char*>(strLen.data.data()), strLen.length));
|
||||||
// write the string
|
// write the string
|
||||||
oxReturnError(m_writer.write(val->c_str(), static_cast<std::size_t>(val->len())));
|
oxReturnError(m_writer.write(val->c_str(), static_cast<std::size_t>(val->len())));
|
||||||
fieldSet = true;
|
fieldSet = true;
|
||||||
@ -217,7 +217,7 @@ constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *c
|
|||||||
const auto strLen = *val ? ox::strlen(*val) : 0;
|
const auto strLen = *val ? ox::strlen(*val) : 0;
|
||||||
// write the length
|
// write the length
|
||||||
const auto strLenBuff = mc::encodeInteger(strLen);
|
const auto strLenBuff = mc::encodeInteger(strLen);
|
||||||
oxReturnError(m_writer.write(reinterpret_cast<const char*>(strLenBuff.data), strLenBuff.length));
|
oxReturnError(m_writer.write(reinterpret_cast<const char*>(strLenBuff.data.data()), strLenBuff.length));
|
||||||
// write the string
|
// write the string
|
||||||
oxReturnError(m_writer.write(*val, static_cast<std::size_t>(strLen)));
|
oxReturnError(m_writer.write(*val, static_cast<std::size_t>(strLen)));
|
||||||
fieldSet = true;
|
fieldSet = true;
|
||||||
@ -243,7 +243,7 @@ constexpr Error MetalClawWriter<Writer>::fieldCString(const char*, const char *v
|
|||||||
if (strLen && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
if (strLen && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||||
// write the length
|
// write the length
|
||||||
const auto strLenBuff = mc::encodeInteger(strLen);
|
const auto strLenBuff = mc::encodeInteger(strLen);
|
||||||
oxReturnError(m_writer.write(reinterpret_cast<const char*>(strLenBuff.data), strLenBuff.length));
|
oxReturnError(m_writer.write(reinterpret_cast<const char*>(strLenBuff.data.data()), strLenBuff.length));
|
||||||
// write the string
|
// write the string
|
||||||
oxReturnError(m_writer.write(val, static_cast<std::size_t>(strLen)));
|
oxReturnError(m_writer.write(val, static_cast<std::size_t>(strLen)));
|
||||||
fieldSet = true;
|
fieldSet = true;
|
||||||
@ -298,14 +298,16 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, const T *val, std::s
|
|||||||
if (len && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
if (len && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||||
// write the length
|
// write the length
|
||||||
const auto arrLen = mc::encodeInteger(len);
|
const auto arrLen = mc::encodeInteger(len);
|
||||||
oxReturnError(m_writer.write(reinterpret_cast<const char*>(arrLen.data), arrLen.length));
|
oxReturnError(m_writer.write(reinterpret_cast<const char*>(arrLen.data.data()), arrLen.length));
|
||||||
auto const writeIdx = m_writer.tellp();
|
auto const writeIdx = m_writer.tellp();
|
||||||
MetalClawWriter<Writer> writer(m_writer);
|
MetalClawWriter<Writer> writer(m_writer);
|
||||||
ModelHandlerInterface handler{&writer};
|
ModelHandlerInterface handler{&writer};
|
||||||
oxReturnError(handler.template setTypeInfo<T>("List", 0, {}, static_cast<std::size_t>(len)));
|
oxReturnError(handler.template setTypeInfo<T>("List", 0, {}, static_cast<std::size_t>(len)));
|
||||||
// write the array
|
// write the array
|
||||||
for (std::size_t i = 0; i < len; ++i) {
|
for (std::size_t i = 0; i < len; ++i) {
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
oxReturnError(handler.field("", &val[i]));
|
oxReturnError(handler.field("", &val[i]));
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
}
|
}
|
||||||
oxReturnError(writer.finalize());
|
oxReturnError(writer.finalize());
|
||||||
fieldSet = writeIdx != m_writer.tellp();
|
fieldSet = writeIdx != m_writer.tellp();
|
||||||
@ -324,7 +326,7 @@ constexpr Error MetalClawWriter<Writer>::field(const char*, const HashMap<String
|
|||||||
if (len && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
if (len && (!m_unionIdx.has_value() || *m_unionIdx == m_field)) {
|
||||||
// write the length
|
// write the length
|
||||||
const auto arrLen = mc::encodeInteger(len);
|
const auto arrLen = mc::encodeInteger(len);
|
||||||
oxReturnError(m_writer.write(reinterpret_cast<const char*>(arrLen.data), arrLen.length));
|
oxReturnError(m_writer.write(reinterpret_cast<const char*>(arrLen.data.data()), arrLen.length));
|
||||||
// write map
|
// write map
|
||||||
MetalClawWriter<Writer> writer(m_writer);
|
MetalClawWriter<Writer> writer(m_writer);
|
||||||
ModelHandlerInterface handler{&writer};
|
ModelHandlerInterface handler{&writer};
|
||||||
|
4
deps/ox/src/ox/oc/read.hpp
vendored
4
deps/ox/src/ox/oc/read.hpp
vendored
@ -244,7 +244,9 @@ Error OrganicClawReader::field(const char *key, T *val, std::size_t valLen) noex
|
|||||||
OrganicClawReader r(srcVal);
|
OrganicClawReader r(srcVal);
|
||||||
ModelHandlerInterface handler{&r};
|
ModelHandlerInterface handler{&r};
|
||||||
for (decltype(srcSize) i = 0; i < srcSize; ++i) {
|
for (decltype(srcSize) i = 0; i < srcSize; ++i) {
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
oxReturnError(handler.field("", &val[i]));
|
oxReturnError(handler.field("", &val[i]));
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
}
|
}
|
||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
@ -272,7 +274,9 @@ Error readOC(BufferView buff, auto &val) noexcept {
|
|||||||
Json::Value doc;
|
Json::Value doc;
|
||||||
Json::CharReaderBuilder parserBuilder;
|
Json::CharReaderBuilder parserBuilder;
|
||||||
auto parser = UniquePtr<Json::CharReader>(parserBuilder.newCharReader());
|
auto parser = UniquePtr<Json::CharReader>(parserBuilder.newCharReader());
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
if (!parser->parse(buff.data(), buff.data() + buff.size(), &doc, nullptr)) {
|
if (!parser->parse(buff.data(), buff.data() + buff.size(), &doc, nullptr)) {
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
return OxError(1, "Could not parse JSON");
|
return OxError(1, "Could not parse JSON");
|
||||||
}
|
}
|
||||||
OrganicClawReader reader(buff.data(), buff.size());
|
OrganicClawReader reader(buff.data(), buff.size());
|
||||||
|
2
deps/ox/src/ox/oc/write.hpp
vendored
2
deps/ox/src/ox/oc/write.hpp
vendored
@ -200,7 +200,9 @@ Error OrganicClawWriter::field(const char *key, const T *val, std::size_t len) n
|
|||||||
OrganicClawWriter w((Json::Value(Json::arrayValue)));
|
OrganicClawWriter w((Json::Value(Json::arrayValue)));
|
||||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler{&w};
|
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler{&w};
|
||||||
for (std::size_t i = 0; i < len; ++i) {
|
for (std::size_t i = 0; i < len; ++i) {
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
oxReturnError(handler.field({}, &val[i]));
|
oxReturnError(handler.field({}, &val[i]));
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
}
|
}
|
||||||
value(key) = w.m_json;
|
value(key) = w.m_json;
|
||||||
}
|
}
|
||||||
|
4
deps/ox/src/ox/std/def.hpp
vendored
4
deps/ox/src/ox/std/def.hpp
vendored
@ -77,9 +77,13 @@ constexpr void oxAssert(const ox::Error&, const char*) noexcept {}
|
|||||||
OX_PRAGMA(clang diagnostic push) \
|
OX_PRAGMA(clang diagnostic push) \
|
||||||
OX_PRAGMA(clang diagnostic ignored #warnoption)
|
OX_PRAGMA(clang diagnostic ignored #warnoption)
|
||||||
#define OX_CLANG_NOWARN_END OX_PRAGMA(clang diagnostic pop)
|
#define OX_CLANG_NOWARN_END OX_PRAGMA(clang diagnostic pop)
|
||||||
|
#define OX_ALLOW_UNSAFE_BUFFERS_BEGIN OX_CLANG_NOWARN_BEGIN(-Wunsafe-buffer-usage)
|
||||||
|
#define OX_ALLOW_UNSAFE_BUFFERS_END OX_CLANG_NOWARN_END
|
||||||
#else
|
#else
|
||||||
#define OX_CLANG_NOWARN_BEGIN(warnoption)
|
#define OX_CLANG_NOWARN_BEGIN(warnoption)
|
||||||
#define OX_CLANG_NOWARN_END
|
#define OX_CLANG_NOWARN_END
|
||||||
|
#define OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
|
#define OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
19
deps/ox/src/ox/std/span.hpp
vendored
19
deps/ox/src/ox/std/span.hpp
vendored
@ -47,7 +47,7 @@ class SpanView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t sz>
|
template<std::size_t sz>
|
||||||
constexpr SpanView(const T a[sz]) noexcept:
|
constexpr SpanView(const T (&a)[sz]) noexcept:
|
||||||
m_items(a),
|
m_items(a),
|
||||||
m_size(sz) {
|
m_size(sz) {
|
||||||
}
|
}
|
||||||
@ -116,6 +116,7 @@ class SpanView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr SpanView operator+=(size_t i) noexcept {
|
constexpr SpanView operator+=(size_t i) noexcept {
|
||||||
|
ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Span access overflow");
|
||||||
m_items += i;
|
m_items += i;
|
||||||
m_size -= i;
|
m_size -= i;
|
||||||
return *this;
|
return *this;
|
||||||
@ -143,7 +144,7 @@ class Span {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
T *m_items{};
|
T *m_items{};
|
||||||
const std::size_t m_size{};
|
std::size_t m_size{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using value_type = T;
|
using value_type = T;
|
||||||
@ -165,7 +166,7 @@ class Span {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t sz>
|
template<std::size_t sz>
|
||||||
constexpr Span(T a[sz]) noexcept:
|
constexpr Span(T (&a)[sz]) noexcept:
|
||||||
m_items(a),
|
m_items(a),
|
||||||
m_size(sz) {
|
m_size(sz) {
|
||||||
}
|
}
|
||||||
@ -243,6 +244,18 @@ class Span {
|
|||||||
return m_items[i];
|
return m_items[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr Span operator+(size_t i) const noexcept {
|
||||||
|
ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Span access overflow");
|
||||||
|
return {m_items + i, m_size - i};
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Span operator+=(size_t i) noexcept {
|
||||||
|
ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Span access overflow");
|
||||||
|
m_items += i;
|
||||||
|
m_size -= i;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr auto data() const noexcept {
|
constexpr auto data() const noexcept {
|
||||||
return m_items;
|
return m_items;
|
||||||
|
4
deps/teagba/include/teagba/registers.hpp
vendored
4
deps/teagba/include/teagba/registers.hpp
vendored
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include "addresses.hpp"
|
#include "addresses.hpp"
|
||||||
|
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
|
|
||||||
namespace teagba {
|
namespace teagba {
|
||||||
|
|
||||||
inline auto bgSetSbb(volatile BgCtl &bgCtl, unsigned sbb) noexcept {
|
inline auto bgSetSbb(volatile BgCtl &bgCtl, unsigned sbb) noexcept {
|
||||||
@ -53,3 +55,5 @@ constexpr void iterateBgCtl(auto cb) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
|
||||||
|
# enable warnings
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunsafe-buffer-usage")
|
||||||
|
endif()
|
||||||
|
|
||||||
project(nostalgia CXX)
|
project(nostalgia CXX)
|
||||||
|
|
||||||
#project packages
|
#project packages
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
#include "context.hpp"
|
#include "context.hpp"
|
||||||
|
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
static constexpr auto SpriteCount = 128;
|
static constexpr auto SpriteCount = 128;
|
||||||
@ -283,3 +285,5 @@ uint_t spriteCount(Context&) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
|
@ -25,7 +25,9 @@ using namespace nostalgia::core;
|
|||||||
|
|
||||||
void panic(const char *file, int line, const char *panicMsg, ox::Error const&err) noexcept {
|
void panic(const char *file, int line, const char *panicMsg, ox::Error const&err) noexcept {
|
||||||
// reset heap to make sure we have enough memory to allocate context data
|
// reset heap to make sure we have enough memory to allocate context data
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
ox::heapmgr::initHeap(HEAP_BEGIN, HEAP_END);
|
ox::heapmgr::initHeap(HEAP_BEGIN, HEAP_END);
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
auto tctx = turbine::init(keel::loadRomFs("").unwrap(), "Nostalgia").unwrap();
|
auto tctx = turbine::init(keel::loadRomFs("").unwrap(), "Nostalgia").unwrap();
|
||||||
auto ctx = init(*tctx).unwrap();
|
auto ctx = init(*tctx).unwrap();
|
||||||
std::ignore = initGfx(*ctx, {});
|
std::ignore = initGfx(*ctx, {});
|
||||||
|
@ -554,20 +554,21 @@ static ox::Result<TileSheetData> buildSetTsd(
|
|||||||
|
|
||||||
static void copyPixels(
|
static void copyPixels(
|
||||||
CompactTileSheet const&ts,
|
CompactTileSheet const&ts,
|
||||||
uint32_t *dst,
|
ox::Span<uint32_t> dst,
|
||||||
size_t const srcPxIdx,
|
size_t const srcPxIdx,
|
||||||
size_t pxlCnt) noexcept {
|
size_t pxlCnt) noexcept {
|
||||||
|
size_t idx{};
|
||||||
if (ts.bpp == 4) {
|
if (ts.bpp == 4) {
|
||||||
for (size_t i = 0; i < pxlCnt; i += 2) {
|
for (size_t i = 0; i < pxlCnt; i += 2) {
|
||||||
auto const [a, b] = get2Pixels4Bpp(ts, i + srcPxIdx);
|
auto const [a, b] = get2Pixels4Bpp(ts, i + srcPxIdx);
|
||||||
*(dst++) = a;
|
dst[idx++] = a;
|
||||||
*(dst++) = b;
|
dst[idx++] = b;
|
||||||
}
|
}
|
||||||
} else if (ts.bpp == 8) {
|
} else if (ts.bpp == 8) {
|
||||||
for (size_t i = 0; i < pxlCnt; i += 2) {
|
for (size_t i = 0; i < pxlCnt; i += 2) {
|
||||||
auto const [a, b] = get2Pixels8Bpp(ts, i + srcPxIdx);
|
auto const [a, b] = get2Pixels8Bpp(ts, i + srcPxIdx);
|
||||||
*(dst++) = a;
|
dst[idx++] = a;
|
||||||
*(dst++) = b;
|
dst[idx++] = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -587,7 +588,7 @@ ox::Error loadBgTileSheet(
|
|||||||
if (dstPxIdx + pxlCnt >= cbbPxls.size()) {
|
if (dstPxIdx + pxlCnt >= cbbPxls.size()) {
|
||||||
return OxError(1, "video mem dst overflow");
|
return OxError(1, "video mem dst overflow");
|
||||||
}
|
}
|
||||||
auto const dst = &cbbPxls[dstPxIdx];
|
auto const dst = ox::Span{cbbPxls} + dstPxIdx;
|
||||||
copyPixels(ts, dst, srcPxIdx, pxlCnt);
|
copyPixels(ts, dst, srcPxIdx, pxlCnt);
|
||||||
auto const cbbTiles = cbbPxls.size() / bytesPerTile;
|
auto const cbbTiles = cbbPxls.size() / bytesPerTile;
|
||||||
int constexpr cbbWidth = 8;
|
int constexpr cbbWidth = 8;
|
||||||
|
@ -22,7 +22,7 @@ core::DeleteTilesCommand::DeleteTilesCommand(
|
|||||||
auto &s = getSubSheet(m_img, m_idx);
|
auto &s = getSubSheet(m_img, m_idx);
|
||||||
auto &p = s.pixels;
|
auto &p = s.pixels;
|
||||||
auto dst = m_deletedPixels.data();
|
auto dst = m_deletedPixels.data();
|
||||||
auto src = p.data() + m_deletePos;
|
auto src = &p[m_deletePos];
|
||||||
const auto sz = m_deleteSz * sizeof(decltype(p[0]));
|
const auto sz = m_deleteSz * sizeof(decltype(p[0]));
|
||||||
ox::memcpy(dst, src, sz);
|
ox::memcpy(dst, src, sz);
|
||||||
}
|
}
|
||||||
@ -32,9 +32,9 @@ ox::Error core::DeleteTilesCommand::redo() noexcept {
|
|||||||
auto &s = getSubSheet(m_img, m_idx);
|
auto &s = getSubSheet(m_img, m_idx);
|
||||||
auto &p = s.pixels;
|
auto &p = s.pixels;
|
||||||
auto srcPos = m_deletePos + m_deleteSz;
|
auto srcPos = m_deletePos + m_deleteSz;
|
||||||
const auto src = p.data() + srcPos;
|
const auto src = &p[srcPos];
|
||||||
const auto dst1 = p.data() + m_deletePos;
|
const auto dst1 = &p[m_deletePos];
|
||||||
const auto dst2 = p.data() + (p.size() - m_deleteSz);
|
const auto dst2 = &p[(p.size() - m_deleteSz)];
|
||||||
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])));
|
||||||
return {};
|
return {};
|
||||||
@ -43,8 +43,8 @@ ox::Error core::DeleteTilesCommand::redo() noexcept {
|
|||||||
ox::Error DeleteTilesCommand::undo() noexcept {
|
ox::Error DeleteTilesCommand::undo() noexcept {
|
||||||
auto &s = getSubSheet(m_img, m_idx);
|
auto &s = getSubSheet(m_img, m_idx);
|
||||||
auto &p = s.pixels;
|
auto &p = s.pixels;
|
||||||
const auto src = p.data() + m_deletePos;
|
const auto src = &p[m_deletePos];
|
||||||
const auto dst1 = p.data() + m_deletePos + m_deleteSz;
|
const auto dst1 = &p[m_deletePos + m_deleteSz];
|
||||||
const auto dst2 = src;
|
const auto dst2 = src;
|
||||||
const auto sz = p.size() - m_deletePos - m_deleteSz;
|
const auto sz = p.size() - m_deletePos - m_deleteSz;
|
||||||
ox::memmove(dst1, src, sz);
|
ox::memmove(dst1, src, sz);
|
||||||
|
@ -22,7 +22,7 @@ core::InsertTilesCommand::InsertTilesCommand(
|
|||||||
auto &s = getSubSheet(m_img, m_idx);
|
auto &s = getSubSheet(m_img, m_idx);
|
||||||
auto &p = s.pixels;
|
auto &p = s.pixels;
|
||||||
auto dst = m_deletedPixels.data();
|
auto dst = m_deletedPixels.data();
|
||||||
auto src = p.data() + p.size() - m_insertCnt;
|
auto src = &p[p.size() - m_insertCnt];
|
||||||
const auto sz = m_insertCnt * sizeof(decltype(p[0]));
|
const auto sz = m_insertCnt * sizeof(decltype(p[0]));
|
||||||
ox::memcpy(dst, src, sz);
|
ox::memcpy(dst, src, sz);
|
||||||
}
|
}
|
||||||
@ -32,8 +32,8 @@ 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;
|
||||||
auto dstPos = m_insertPos + m_insertCnt;
|
auto dstPos = m_insertPos + m_insertCnt;
|
||||||
const auto dst = p.data() + dstPos;
|
auto const dst = &p[dstPos];
|
||||||
const auto src = p.data() + m_insertPos;
|
auto const src = &p[m_insertPos];
|
||||||
ox::memmove(dst, src, p.size() - dstPos);
|
ox::memmove(dst, src, p.size() - dstPos);
|
||||||
ox::memset(src, 0, m_insertCnt * sizeof(decltype(p[0])));
|
ox::memset(src, 0, m_insertCnt * sizeof(decltype(p[0])));
|
||||||
return {};
|
return {};
|
||||||
@ -42,11 +42,11 @@ ox::Error InsertTilesCommand::redo() noexcept {
|
|||||||
ox::Error InsertTilesCommand::undo() noexcept {
|
ox::Error InsertTilesCommand::undo() noexcept {
|
||||||
auto &s = getSubSheet(m_img, m_idx);
|
auto &s = getSubSheet(m_img, m_idx);
|
||||||
auto &p = s.pixels;
|
auto &p = s.pixels;
|
||||||
const auto srcIdx = m_insertPos + m_insertCnt;
|
auto const srcIdx = m_insertPos + m_insertCnt;
|
||||||
const auto src = p.data() + srcIdx;
|
auto const src = &p[srcIdx];
|
||||||
const auto dst1 = p.data() + m_insertPos;
|
auto const dst1 = &p[m_insertPos];
|
||||||
const auto dst2 = p.data() + p.size() - m_insertCnt;
|
auto const dst2 = &p[p.size() - m_insertCnt];
|
||||||
const auto sz = p.size() - srcIdx;
|
auto const sz = p.size() - srcIdx;
|
||||||
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());
|
||||||
return {};
|
return {};
|
||||||
|
@ -120,7 +120,7 @@ ox::StringView TileSheetEditorModel::palPath() const noexcept {
|
|||||||
}
|
}
|
||||||
constexpr ox::StringView uuidPrefix = "uuid://";
|
constexpr ox::StringView uuidPrefix = "uuid://";
|
||||||
if (ox::beginsWith(path, uuidPrefix)) {
|
if (ox::beginsWith(path, uuidPrefix)) {
|
||||||
auto uuid = ox::StringView(path.data() + uuidPrefix.bytes(), path.bytes() - uuidPrefix.bytes());
|
auto uuid = ox::StringView(&path[uuidPrefix.bytes()], path.bytes() - uuidPrefix.bytes());
|
||||||
auto out = keelCtx(m_tctx).uuidToPath.at(uuid);
|
auto out = keelCtx(m_tctx).uuidToPath.at(uuid);
|
||||||
if (out.error) {
|
if (out.error) {
|
||||||
return {};
|
return {};
|
||||||
@ -197,7 +197,7 @@ void TileSheetEditorModel::fill(ox::Point const&pt, int palIdx) noexcept {
|
|||||||
if (pt.x >= s.columns * TileWidth || pt.y >= s.rows * TileHeight) {
|
if (pt.x >= s.columns * TileWidth || pt.y >= s.rows * TileHeight) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
getFillPixels(updateMap.data(), pt, oldColor);
|
getFillPixels(updateMap, pt, oldColor);
|
||||||
ox::Vector<std::size_t> idxList;
|
ox::Vector<std::size_t> idxList;
|
||||||
auto i = core::idx(s, pt) / PixelsPerTile * PixelsPerTile;
|
auto i = core::idx(s, pt) / PixelsPerTile * PixelsPerTile;
|
||||||
for (auto u : updateMap) {
|
for (auto u : updateMap) {
|
||||||
@ -281,7 +281,7 @@ bool TileSheetEditorModel::pixelSelected(std::size_t idx) const noexcept {
|
|||||||
return m_selection && m_selection->contains(pt);
|
return m_selection && m_selection->contains(pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileSheetEditorModel::getFillPixels(bool *pixels, ox::Point const&pt, int oldColor) const noexcept {
|
void TileSheetEditorModel::getFillPixels(ox::Span<bool> pixels, ox::Point const&pt, int oldColor) const noexcept {
|
||||||
const auto &activeSubSheet = this->activeSubSheet();
|
const auto &activeSubSheet = this->activeSubSheet();
|
||||||
const auto tileIdx = [activeSubSheet](const ox::Point &pt) noexcept {
|
const auto tileIdx = [activeSubSheet](const ox::Point &pt) noexcept {
|
||||||
return ptToIdx(pt, activeSubSheet.columns) / PixelsPerTile;
|
return ptToIdx(pt, activeSubSheet.columns) / PixelsPerTile;
|
||||||
|
@ -128,7 +128,7 @@ class TileSheetEditorModel: public ox::SignalHandler {
|
|||||||
bool pixelSelected(std::size_t idx) const noexcept;
|
bool pixelSelected(std::size_t idx) const noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void getFillPixels(bool *pixels, ox::Point const&pt, int oldColor) const noexcept;
|
void getFillPixels(ox::Span<bool> pixels, ox::Point const&pt, int oldColor) const noexcept;
|
||||||
|
|
||||||
void pushCommand(studio::UndoCommand *cmd) noexcept;
|
void pushCommand(studio::UndoCommand *cmd) noexcept;
|
||||||
|
|
||||||
|
@ -24,9 +24,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;
|
int retval = -1;
|
||||||
if (argc > 0) {
|
if (argc > 0) {
|
||||||
|
auto const args = ox::SpanView{argv, static_cast<size_t>(argc)};
|
||||||
auto const testName = ox::StringView(args[1]);
|
auto const testName = ox::StringView(args[1]);
|
||||||
if (tests.find(testName) != tests.end()) {
|
if (tests.find(testName) != tests.end()) {
|
||||||
retval = static_cast<int>(tests[testName]());
|
retval = static_cast<int>(tests[testName]());
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
|
||||||
|
# enable warnings
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunsafe-buffer-usage")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(BUILDCORE_TARGET STREQUAL "gba")
|
if(BUILDCORE_TARGET STREQUAL "gba")
|
||||||
project(Olympic ASM CXX)
|
project(Olympic ASM CXX)
|
||||||
else()
|
else()
|
||||||
|
@ -14,7 +14,7 @@ ox::Result<ox::UUID> readUuidHeader(ox::BufferView buff) noexcept {
|
|||||||
if (k1Hdr != ox::StringView(buff.data(), k1Hdr.bytes())) [[unlikely]] {
|
if (k1Hdr != ox::StringView(buff.data(), k1Hdr.bytes())) [[unlikely]] {
|
||||||
return OxError(2, "No Keel asset header data");
|
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 {
|
ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView buff) noexcept {
|
||||||
|
@ -15,16 +15,22 @@ static ox::Error pathToInode(
|
|||||||
ox::FileSystem &dest,
|
ox::FileSystem &dest,
|
||||||
ox::ModelObject &obj) noexcept {
|
ox::ModelObject &obj) noexcept {
|
||||||
auto &o = obj;
|
auto &o = obj;
|
||||||
auto type = static_cast<ox::FileAddressType>(o.at("type").unwrap()->get<int8_t>());
|
oxRequire(typeVal, o.at("type"));
|
||||||
auto &data = o.at("data").unwrap()->get<ox::ModelUnion>();
|
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;
|
ox::String path;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ox::FileAddressType::Path:
|
case ox::FileAddressType::Path: {
|
||||||
path = data.at("path").unwrap()->get<ox::String>();
|
oxRequire(pathVal, data.at("path"));
|
||||||
|
path = pathVal->get<ox::String>();
|
||||||
break;
|
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;
|
break;
|
||||||
|
}
|
||||||
case ox::FileAddressType::Inode:
|
case ox::FileAddressType::Inode:
|
||||||
case ox::FileAddressType::None:
|
case ox::FileAddressType::None:
|
||||||
return {};
|
return {};
|
||||||
@ -34,7 +40,7 @@ static ox::Error pathToInode(
|
|||||||
oxReturnError(keel::uuidToPath(ctx, uuid).to<ox::String>().moveTo(path));
|
oxReturnError(keel::uuidToPath(ctx, uuid).to<ox::String>().moveTo(path));
|
||||||
}
|
}
|
||||||
oxRequire(s, dest.stat(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);
|
oxOutf("\tpath to inode: {} => {}\n", path, s.inode);
|
||||||
return data.set(2, s.inode);
|
return data.set(2, s.inode);
|
||||||
}
|
}
|
||||||
@ -162,12 +168,12 @@ static ox::Error copy(
|
|||||||
// copy
|
// copy
|
||||||
oxRequire(fileList, src.ls(path));
|
oxRequire(fileList, src.ls(path));
|
||||||
for (auto const&name : fileList) {
|
for (auto const&name : fileList) {
|
||||||
auto currentFile = ox::sfmt("{}{}", path, name);
|
auto const currentFile = ox::sfmt("{}{}", path, name);
|
||||||
if (beginsWith(name, ".")) {
|
if (beginsWith(name, ".")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
oxRequire(stat, src.stat(currentFile));
|
oxRequire(srcStat, src.stat(currentFile));
|
||||||
if (stat.fileType == ox::FileType::Directory) {
|
if (srcStat.fileType == ox::FileType::Directory) {
|
||||||
oxReturnError(dest.mkdir(currentFile, true));
|
oxReturnError(dest.mkdir(currentFile, true));
|
||||||
oxReturnError(copy(manifest, src, dest, currentFile + '/', childLogPrefix));
|
oxReturnError(copy(manifest, src, dest, currentFile + '/', childLogPrefix));
|
||||||
} else {
|
} else {
|
||||||
@ -181,9 +187,9 @@ static ox::Error copy(
|
|||||||
// write file to dest
|
// write file to dest
|
||||||
oxReturnError(dest.write(currentFile, buff));
|
oxReturnError(dest.write(currentFile, buff));
|
||||||
status = "OK";
|
status = "OK";
|
||||||
oxRequire(stat, dest.stat(currentFile));
|
oxRequire(dstStat, dest.stat(currentFile));
|
||||||
manifest.files[currentFile] = {
|
manifest.files[currentFile] = {
|
||||||
.inode = stat.inode,
|
.inode = dstStat.inode,
|
||||||
.type = ox::String{keel::readAssetTypeId(buff).or_value({})},
|
.type = ox::String{keel::readAssetTypeId(buff).or_value({})},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -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;
|
int retval = -1;
|
||||||
if (argc > 0) {
|
if (argc > 0) {
|
||||||
|
auto const args = ox::SpanView{argv, static_cast<size_t>(argc)};
|
||||||
auto testName = args[1];
|
auto testName = args[1];
|
||||||
if (tests.find(testName) != tests.end()) {
|
if (tests.find(testName) != tests.end()) {
|
||||||
retval = static_cast<int>(tests[testName]());
|
retval = static_cast<int>(tests[testName]());
|
||||||
|
@ -63,12 +63,14 @@ void NewMenu::addItemMaker(ox::UniquePtr<studio::ItemMaker> &&im) noexcept {
|
|||||||
|
|
||||||
void NewMenu::drawNewItemType(studio::StudioContext &sctx) noexcept {
|
void NewMenu::drawNewItemType(studio::StudioContext &sctx) noexcept {
|
||||||
drawWindow(sctx.tctx, &m_open, [this] {
|
drawWindow(sctx.tctx, &m_open, [this] {
|
||||||
auto items = ox_malloca(m_types.size() * sizeof(char const*), char const*, nullptr);
|
auto const allocSz = m_types.size() * sizeof(char const*);
|
||||||
|
auto mem = ox_malloca(allocSz, char const*, nullptr);
|
||||||
|
auto items = ox::Span{mem.get(), allocSz};
|
||||||
for (auto i = 0u; auto const&im : m_types) {
|
for (auto i = 0u; auto const&im : m_types) {
|
||||||
items.get()[i] = im->typeName.c_str();
|
items[i] = im->typeName.c_str();
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
ImGui::ListBox("Item Type", &m_selectedType, items.get(), static_cast<int>(m_types.size()));
|
ImGui::ListBox("Item Type", &m_selectedType, items.data(), static_cast<int>(m_types.size()));
|
||||||
drawFirstPageButtons();
|
drawFirstPageButtons();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -116,11 +118,12 @@ void NewMenu::drawLastPageButtons(studio::StudioContext &sctx) noexcept {
|
|||||||
|
|
||||||
void NewMenu::finish(studio::StudioContext &sctx) noexcept {
|
void NewMenu::finish(studio::StudioContext &sctx) noexcept {
|
||||||
if (m_itemName.len() == 0) {
|
if (m_itemName.len() == 0) {
|
||||||
|
oxLogError(OxError(1, "New file error: no file name"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto const&typeMaker = *m_types[static_cast<std::size_t>(m_selectedType)];
|
auto const&typeMaker = *m_types[static_cast<std::size_t>(m_selectedType)];
|
||||||
if (sctx.project->exists(typeMaker.itemPath(m_itemName))) {
|
if (sctx.project->exists(typeMaker.itemPath(m_itemName))) {
|
||||||
oxLogError(OxError(1, "New file error: File already exists"));
|
oxLogError(OxError(1, "New file error: file already exists"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto const [path, err] = typeMaker.write(sctx, m_itemName);
|
auto const [path, err] = typeMaker.write(sctx, m_itemName);
|
||||||
|
@ -22,10 +22,12 @@ static ox::Result<ox::String> toResult(nfdresult_t r, NFD::UniquePathN const&pat
|
|||||||
switch (r) {
|
switch (r) {
|
||||||
case NFD_OKAY: {
|
case NFD_OKAY: {
|
||||||
ox::String out;
|
ox::String out;
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||||
for (auto i = 0u; path.get()[i]; ++i) {
|
for (auto i = 0u; path.get()[i]; ++i) {
|
||||||
auto const c = static_cast<char>(path.get()[i]);
|
auto const c = static_cast<char>(path.get()[i]);
|
||||||
std::ignore = out.append(&c, 1);
|
std::ignore = out.append(&c, 1);
|
||||||
}
|
}
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
case NFD_CANCEL:
|
case NFD_CANCEL:
|
||||||
@ -35,11 +37,11 @@ static ox::Result<ox::String> toResult(nfdresult_t r, NFD::UniquePathN const&pat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<ox::String> saveFile(ox::Vector<FDFilterItem> const&filters) noexcept {
|
ox::Result<ox::String> saveFile(ox::Vector<FDFilterItem> const&exts) noexcept {
|
||||||
NFD::Guard const guard;
|
NFD::Guard const guard;
|
||||||
NFD::UniquePathN path;
|
NFD::UniquePathN path;
|
||||||
ox::Vector<nfdnfilteritem_t, 5> filterItems(filters.size());
|
ox::Vector<nfdnfilteritem_t, 5> filterItems(exts.size());
|
||||||
for (auto i = 0u; auto const&f : filters) {
|
for (auto i = 0u; auto const&f : exts) {
|
||||||
filterItems[i].name = f.name.data();
|
filterItems[i].name = f.name.data();
|
||||||
filterItems[i].spec = f.spec.data();
|
filterItems[i].spec = f.spec.data();
|
||||||
++i;
|
++i;
|
||||||
|
@ -47,12 +47,14 @@ static ox::Result<std::size_t> findPreloadSection() noexcept {
|
|||||||
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) {
|
||||||
return reinterpret_cast<std::size_t>(current + headerLen);
|
return reinterpret_cast<std::size_t>(current + headerLen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||||
return OxError(1);
|
return OxError(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
#include <imgui_impl_opengl3.h>
|
#include <imgui_impl_opengl3.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <ox/std/span.hpp>
|
||||||
|
|
||||||
#include "context.hpp"
|
#include "context.hpp"
|
||||||
|
|
||||||
namespace turbine {
|
namespace turbine {
|
||||||
@ -128,60 +130,61 @@ static void themeImgui() noexcept {
|
|||||||
static_cast<float>(b),
|
static_cast<float>(b),
|
||||||
static_cast<float>(a));
|
static_cast<float>(a));
|
||||||
};
|
};
|
||||||
style.Colors[ImGuiCol_Text] = imVec4(0.9490196108818054, 0.95686274766922, 0.9764705896377563, 1.0);
|
auto colors = ox::Span(style.Colors);
|
||||||
style.Colors[ImGuiCol_TextDisabled] = imVec4(0.3568627536296844, 0.4196078479290009, 0.4666666686534882, 1.0);
|
colors[ImGuiCol_Text] = imVec4(0.9490196108818054, 0.95686274766922, 0.9764705896377563, 1.0);
|
||||||
style.Colors[ImGuiCol_WindowBg] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
|
colors[ImGuiCol_TextDisabled] = imVec4(0.3568627536296844, 0.4196078479290009, 0.4666666686534882, 1.0);
|
||||||
style.Colors[ImGuiCol_ChildBg] = imVec4(0.1490196138620377, 0.1764705926179886, 0.2196078449487686, 1.0);
|
colors[ImGuiCol_WindowBg] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
|
||||||
style.Colors[ImGuiCol_PopupBg] = imVec4(0.0784313753247261, 0.0784313753247261, 0.0784313753247261, 0.9399999976158142);
|
colors[ImGuiCol_ChildBg] = imVec4(0.1490196138620377, 0.1764705926179886, 0.2196078449487686, 1.0);
|
||||||
style.Colors[ImGuiCol_Border] = imVec4(0.0784313753247261, 0.09803921729326248, 0.1176470592617989, 1.0);
|
colors[ImGuiCol_PopupBg] = imVec4(0.0784313753247261, 0.0784313753247261, 0.0784313753247261, 0.9399999976158142);
|
||||||
style.Colors[ImGuiCol_BorderShadow] = imVec4(0.0, 0.0, 0.0, 0.0);
|
colors[ImGuiCol_Border] = imVec4(0.0784313753247261, 0.09803921729326248, 0.1176470592617989, 1.0);
|
||||||
style.Colors[ImGuiCol_FrameBg] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
|
colors[ImGuiCol_BorderShadow] = imVec4(0.0, 0.0, 0.0, 0.0);
|
||||||
style.Colors[ImGuiCol_FrameBgHovered] = imVec4(0.1176470592617989, 0.2000000029802322, 0.2784313857555389, 1.0);
|
colors[ImGuiCol_FrameBg] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
|
||||||
style.Colors[ImGuiCol_FrameBgActive] = imVec4(0.08627451211214066, 0.1176470592617989, 0.1372549086809158, 1.0);
|
colors[ImGuiCol_FrameBgHovered] = imVec4(0.1176470592617989, 0.2000000029802322, 0.2784313857555389, 1.0);
|
||||||
style.Colors[ImGuiCol_TitleBg] = imVec4(0.08627451211214066, 0.1176470592617989, 0.1372549086809158, 0.6499999761581421);
|
colors[ImGuiCol_FrameBgActive] = imVec4(0.08627451211214066, 0.1176470592617989, 0.1372549086809158, 1.0);
|
||||||
style.Colors[ImGuiCol_TitleBgActive] = imVec4(0.0784313753247261, 0.09803921729326248, 0.1176470592617989, 1.0);
|
colors[ImGuiCol_TitleBg] = imVec4(0.08627451211214066, 0.1176470592617989, 0.1372549086809158, 0.6499999761581421);
|
||||||
style.Colors[ImGuiCol_TitleBgCollapsed] = imVec4(0.0, 0.0, 0.0, 0.5099999904632568);
|
colors[ImGuiCol_TitleBgActive] = imVec4(0.0784313753247261, 0.09803921729326248, 0.1176470592617989, 1.0);
|
||||||
style.Colors[ImGuiCol_MenuBarBg] = imVec4(0.1490196138620377, 0.1764705926179886, 0.2196078449487686, 1.0);
|
colors[ImGuiCol_TitleBgCollapsed] = imVec4(0.0, 0.0, 0.0, 0.5099999904632568);
|
||||||
style.Colors[ImGuiCol_ScrollbarBg] = imVec4(0.01960784383118153, 0.01960784383118153, 0.01960784383118153, 0.3899999856948853);
|
colors[ImGuiCol_MenuBarBg] = imVec4(0.1490196138620377, 0.1764705926179886, 0.2196078449487686, 1.0);
|
||||||
style.Colors[ImGuiCol_ScrollbarGrab] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
|
colors[ImGuiCol_ScrollbarBg] = imVec4(0.01960784383118153, 0.01960784383118153, 0.01960784383118153, 0.3899999856948853);
|
||||||
style.Colors[ImGuiCol_ScrollbarGrabHovered] = imVec4(0.1764705926179886, 0.2196078449487686, 0.2470588237047195, 1.0);
|
colors[ImGuiCol_ScrollbarGrab] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
|
||||||
style.Colors[ImGuiCol_ScrollbarGrabActive] = imVec4(0.08627451211214066, 0.2078431397676468, 0.3098039329051971, 1.0);
|
colors[ImGuiCol_ScrollbarGrabHovered] = imVec4(0.1764705926179886, 0.2196078449487686, 0.2470588237047195, 1.0);
|
||||||
style.Colors[ImGuiCol_CheckMark] = imVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0);
|
colors[ImGuiCol_ScrollbarGrabActive] = imVec4(0.08627451211214066, 0.2078431397676468, 0.3098039329051971, 1.0);
|
||||||
style.Colors[ImGuiCol_SliderGrab] = imVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0);
|
colors[ImGuiCol_CheckMark] = imVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0);
|
||||||
style.Colors[ImGuiCol_SliderGrabActive] = imVec4(0.3686274588108063, 0.6078431606292725, 1.0, 1.0);
|
colors[ImGuiCol_SliderGrab] = imVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0);
|
||||||
style.Colors[ImGuiCol_Button] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
|
colors[ImGuiCol_SliderGrabActive] = imVec4(0.3686274588108063, 0.6078431606292725, 1.0, 1.0);
|
||||||
style.Colors[ImGuiCol_ButtonHovered] = imVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0);
|
colors[ImGuiCol_Button] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
|
||||||
style.Colors[ImGuiCol_ButtonActive] = imVec4(0.05882352963089943, 0.529411792755127, 0.9764705896377563, 1.0);
|
colors[ImGuiCol_ButtonHovered] = imVec4(0.2784313857555389, 0.5568627715110779, 1.0, 1.0);
|
||||||
|
colors[ImGuiCol_ButtonActive] = imVec4(0.05882352963089943, 0.529411792755127, 0.9764705896377563, 1.0);
|
||||||
// custom value
|
// custom value
|
||||||
style.Colors[ImGuiCol_Header] = imVec4(0.4000000029802322, 0.4470588237047195, 0.4862745225429535, 0.550000011920929);
|
colors[ImGuiCol_Header] = imVec4(0.4000000029802322, 0.4470588237047195, 0.4862745225429535, 0.550000011920929);
|
||||||
style.Colors[ImGuiCol_HeaderHovered] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.800000011920929);
|
colors[ImGuiCol_HeaderHovered] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.800000011920929);
|
||||||
style.Colors[ImGuiCol_HeaderActive] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 1.0);
|
colors[ImGuiCol_HeaderActive] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 1.0);
|
||||||
style.Colors[ImGuiCol_Separator] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
|
colors[ImGuiCol_Separator] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
|
||||||
style.Colors[ImGuiCol_SeparatorHovered] = imVec4(0.09803921729326248, 0.4000000059604645, 0.7490196228027344, 0.7799999713897705);
|
colors[ImGuiCol_SeparatorHovered] = imVec4(0.09803921729326248, 0.4000000059604645, 0.7490196228027344, 0.7799999713897705);
|
||||||
style.Colors[ImGuiCol_SeparatorActive] = imVec4(0.09803921729326248, 0.4000000059604645, 0.7490196228027344, 1.0);
|
colors[ImGuiCol_SeparatorActive] = imVec4(0.09803921729326248, 0.4000000059604645, 0.7490196228027344, 1.0);
|
||||||
style.Colors[ImGuiCol_ResizeGrip] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.25);
|
colors[ImGuiCol_ResizeGrip] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.25);
|
||||||
style.Colors[ImGuiCol_ResizeGripHovered] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.6700000166893005);
|
colors[ImGuiCol_ResizeGripHovered] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.6700000166893005);
|
||||||
style.Colors[ImGuiCol_ResizeGripActive] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.949999988079071);
|
colors[ImGuiCol_ResizeGripActive] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.949999988079071);
|
||||||
style.Colors[ImGuiCol_Tab] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
|
colors[ImGuiCol_Tab] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
|
||||||
style.Colors[ImGuiCol_TabHovered] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.800000011920929);
|
colors[ImGuiCol_TabHovered] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.800000011920929);
|
||||||
style.Colors[ImGuiCol_TabActive] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
|
colors[ImGuiCol_TabActive] = imVec4(0.2000000029802322, 0.2470588237047195, 0.2862745225429535, 1.0);
|
||||||
style.Colors[ImGuiCol_TabUnfocused] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
|
colors[ImGuiCol_TabUnfocused] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
|
||||||
style.Colors[ImGuiCol_TabUnfocusedActive] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
|
colors[ImGuiCol_TabUnfocusedActive] = imVec4(0.1098039224743843, 0.1490196138620377, 0.168627455830574, 1.0);
|
||||||
style.Colors[ImGuiCol_PlotLines] = imVec4(0.6078431606292725, 0.6078431606292725, 0.6078431606292725, 1.0);
|
colors[ImGuiCol_PlotLines] = imVec4(0.6078431606292725, 0.6078431606292725, 0.6078431606292725, 1.0);
|
||||||
style.Colors[ImGuiCol_PlotLinesHovered] = imVec4(1.0, 0.4274509847164154, 0.3490196168422699, 1.0);
|
colors[ImGuiCol_PlotLinesHovered] = imVec4(1.0, 0.4274509847164154, 0.3490196168422699, 1.0);
|
||||||
style.Colors[ImGuiCol_PlotHistogram] = imVec4(0.8980392217636108, 0.6980392336845398, 0.0, 1.0);
|
colors[ImGuiCol_PlotHistogram] = imVec4(0.8980392217636108, 0.6980392336845398, 0.0, 1.0);
|
||||||
style.Colors[ImGuiCol_PlotHistogramHovered] = imVec4(1.0, 0.6000000238418579, 0.0, 1.0);
|
colors[ImGuiCol_PlotHistogramHovered] = imVec4(1.0, 0.6000000238418579, 0.0, 1.0);
|
||||||
style.Colors[ImGuiCol_TableHeaderBg] = imVec4(0.1882352977991104, 0.1882352977991104, 0.2000000029802322, 1.0);
|
colors[ImGuiCol_TableHeaderBg] = imVec4(0.1882352977991104, 0.1882352977991104, 0.2000000029802322, 1.0);
|
||||||
style.Colors[ImGuiCol_TableBorderStrong] = imVec4(0.3098039329051971, 0.3098039329051971, 0.3490196168422699, 1.0);
|
colors[ImGuiCol_TableBorderStrong] = imVec4(0.3098039329051971, 0.3098039329051971, 0.3490196168422699, 1.0);
|
||||||
style.Colors[ImGuiCol_TableBorderLight] = imVec4(0.2274509817361832, 0.2274509817361832, 0.2470588237047195, 1.0);
|
colors[ImGuiCol_TableBorderLight] = imVec4(0.2274509817361832, 0.2274509817361832, 0.2470588237047195, 1.0);
|
||||||
style.Colors[ImGuiCol_TableRowBg] = imVec4(0.0, 0.0, 0.0, 0.0);
|
colors[ImGuiCol_TableRowBg] = imVec4(0.0, 0.0, 0.0, 0.0);
|
||||||
style.Colors[ImGuiCol_TableRowBgAlt] = imVec4(1.0, 1.0, 1.0, 0.05999999865889549);
|
colors[ImGuiCol_TableRowBgAlt] = imVec4(1.0, 1.0, 1.0, 0.05999999865889549);
|
||||||
style.Colors[ImGuiCol_TextSelectedBg] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.3499999940395355);
|
colors[ImGuiCol_TextSelectedBg] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 0.3499999940395355);
|
||||||
style.Colors[ImGuiCol_DragDropTarget] = imVec4(1.0, 1.0, 0.0, 0.8999999761581421);
|
colors[ImGuiCol_DragDropTarget] = imVec4(1.0, 1.0, 0.0, 0.8999999761581421);
|
||||||
style.Colors[ImGuiCol_NavHighlight] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 1.0);
|
colors[ImGuiCol_NavHighlight] = imVec4(0.2588235437870026, 0.5882353186607361, 0.9764705896377563, 1.0);
|
||||||
style.Colors[ImGuiCol_NavWindowingHighlight] = imVec4(1.0, 1.0, 1.0, 0.699999988079071);
|
colors[ImGuiCol_NavWindowingHighlight] = imVec4(1.0, 1.0, 1.0, 0.699999988079071);
|
||||||
style.Colors[ImGuiCol_NavWindowingDimBg] = imVec4(0.800000011920929, 0.800000011920929, 0.800000011920929, 0.2000000029802322);
|
colors[ImGuiCol_NavWindowingDimBg] = imVec4(0.800000011920929, 0.800000011920929, 0.800000011920929, 0.2000000029802322);
|
||||||
style.Colors[ImGuiCol_ModalWindowDimBg] = imVec4(0.800000011920929, 0.800000011920929, 0.800000011920929, 0.3499999940395355);
|
colors[ImGuiCol_ModalWindowDimBg] = imVec4(0.800000011920929, 0.800000011920929, 0.800000011920929, 0.3499999940395355);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user