Compare commits
15 Commits
f24929f421
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| ef1c108b58 | |||
| 6a054cd970 | |||
| 9070e6e109 | |||
| 6cc6e9e7ed | |||
| de859bef77 | |||
| d1a3538e9a | |||
| d10a71f06d | |||
| 9593e7eef9 | |||
| 2f9b9c0842 | |||
| dce09b564c | |||
| 9f485d9496 | |||
| 2c50ce48ed | |||
| 72e16cb285 | |||
| d1e410ac55 | |||
| be32d575f5 |
+2
-2
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.19)
|
||||
cmake_minimum_required(VERSION 3.25)
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0110 NEW) # requires CMake 3.19
|
||||
|
||||
if(BUILDCORE_TARGET STREQUAL "gba")
|
||||
@@ -52,7 +52,7 @@ if(NOT BUILDCORE_TARGET STREQUAL "gba")
|
||||
set(GLFW_BUILD_TESTS OFF)
|
||||
set(GLFW_BUILD_DOCS OFF)
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||
set(GLFW_BUILD_WAYLAND OFF)
|
||||
set(GLFW_BUILD_WAYLAND ON)
|
||||
endif()
|
||||
add_subdirectory(deps/glfw)
|
||||
add_subdirectory(deps/glutils)
|
||||
|
||||
+20
@@ -120,4 +120,24 @@ Result<Buffer> writeClaw(
|
||||
return out;
|
||||
}
|
||||
|
||||
Error writeClaw(
|
||||
auto const &obj,
|
||||
Writer_c auto &writer,
|
||||
ClawFormat const fmt = ClawFormat::Metal) noexcept {
|
||||
OX_RETURN_ERROR(detail::writeClawHeader(writer, &obj, fmt));
|
||||
#ifdef OX_USE_STDLIB
|
||||
if (fmt == ClawFormat::Metal) {
|
||||
OX_RETURN_ERROR(writeMC(writer, obj));
|
||||
} else if (fmt == ClawFormat::Organic) {
|
||||
OX_RETURN_ERROR(writeOC(writer, obj));
|
||||
}
|
||||
#else
|
||||
if (fmt != ClawFormat::Metal) {
|
||||
return ox::Error(1, "OC is not supported in this build");
|
||||
}
|
||||
OX_RETURN_ERROR(writeMC(writer, obj));
|
||||
#endif
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+13
-2
@@ -28,6 +28,7 @@ namespace ox {
|
||||
|
||||
class OrganicClawWriter {
|
||||
|
||||
friend Error writeOC(Writer_c auto &writer, auto const &val) noexcept;
|
||||
friend Result<Buffer> writeOC(const auto &val) noexcept;
|
||||
friend Result<String> writeOCString(const auto &val) noexcept;
|
||||
|
||||
@@ -254,9 +255,19 @@ Error OrganicClawWriter::field(CString key, UnionView<U, force> val) noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
Error writeOC(Writer_c auto &writer, auto const &val) noexcept {
|
||||
OrganicClawWriter ocWriter;
|
||||
ModelHandlerInterface handler(ocWriter);
|
||||
OX_RETURN_ERROR(model(&handler, &val));
|
||||
Json::StreamWriterBuilder const jsonBuilder;
|
||||
auto const str = Json::writeString(jsonBuilder, ocWriter.m_json);
|
||||
OX_RETURN_ERROR(writer.write(str.data(), str.size()));
|
||||
return writer.put('\0');
|
||||
}
|
||||
|
||||
Result<Buffer> writeOC(auto const &val) noexcept {
|
||||
OrganicClawWriter writer;
|
||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler(writer);
|
||||
ModelHandlerInterface handler(writer);
|
||||
OX_RETURN_ERROR(model(&handler, &val));
|
||||
Json::StreamWriterBuilder const jsonBuilder;
|
||||
auto const str = Json::writeString(jsonBuilder, writer.m_json);
|
||||
@@ -270,7 +281,7 @@ Result<Buffer> writeOC(auto const &val) noexcept {
|
||||
|
||||
Result<String> writeOCString(auto const &val) noexcept {
|
||||
OrganicClawWriter writer;
|
||||
ModelHandlerInterface<OrganicClawWriter, OpType::Write> handler(writer);
|
||||
ModelHandlerInterface handler(writer);
|
||||
OX_RETURN_ERROR(model(&handler, &val));
|
||||
Json::StreamWriterBuilder const jsonBuilder;
|
||||
auto const str = Json::writeString(jsonBuilder, writer.m_json);
|
||||
|
||||
+15
@@ -345,6 +345,21 @@ struct [[nodiscard]] Result {
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Result reoriginate(
|
||||
ErrorCode const pErrCode,
|
||||
CString const pMsg = nullptr,
|
||||
std::source_location const &pSrc = std::source_location::current()) const && noexcept {
|
||||
if (error) {
|
||||
return {std::move(value), Error{pErrCode, pMsg, pSrc}};
|
||||
}
|
||||
return {std::move(value)};
|
||||
}
|
||||
|
||||
constexpr Result reoriginate(
|
||||
std::source_location const &pSrc = std::source_location::current()) const && noexcept {
|
||||
return {std::move(value), Error{error.errCode, error.msg, pSrc}};
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
+21
@@ -36,6 +36,27 @@ constexpr StringView substr(StringViewCR str, std::size_t const start, std::size
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr char toUpper(char const c) noexcept {
|
||||
return c & static_cast<char>(0b1101'1111);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr int caseInsensitiveStrCmp(StringViewCR a, StringViewCR b) noexcept {
|
||||
auto const sz = ox::min(a.size(), b.size());
|
||||
for (size_t i{}; i < sz; ++i) {
|
||||
auto const ac = toUpper(a[i]);
|
||||
auto const bc = toUpper(b[i]);
|
||||
if (ac < bc) {
|
||||
return -1;
|
||||
}
|
||||
if (ac > bc) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool beginsWith(StringViewCR base, char const beginning) noexcept {
|
||||
return base.size() && base[0] == beginning;
|
||||
|
||||
@@ -54,6 +54,10 @@ struct VectorAllocator {
|
||||
// this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM,
|
||||
// try removing it later
|
||||
if (!std::is_constant_evaluated()) {
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstringop-overflow="
|
||||
#endif
|
||||
if (cap <= m_data.size() && count <= m_data.size()) {
|
||||
for (auto i = 0u; i < count; ++i) {
|
||||
auto const srcItem = std::launder(reinterpret_cast<T*>(&src->m_data[i]));
|
||||
@@ -65,6 +69,9 @@ struct VectorAllocator {
|
||||
*items = reinterpret_cast<T*>(m_data.data());
|
||||
}
|
||||
}
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,16 @@ static ox::Error convertFile(
|
||||
ox::TypeStore &ts,
|
||||
ox::StringViewCR path,
|
||||
ox::ClawFormat const fmt) noexcept {
|
||||
ox::Buffer buff;
|
||||
ox::ModelObject obj;
|
||||
OX_RETURN_ERROR(fs.read(path).moveTo(buff).reoriginate(1, "unable to read file"));
|
||||
OX_RETURN_ERROR(keel::readAsset(ts, buff).moveTo(obj).reoriginate(1, "unable to parse file"));
|
||||
OX_RETURN_ERROR(ox::writeClaw(obj, fmt).moveTo(buff));
|
||||
OX_REQUIRE_M(buff, fs.read(path).reoriginate(1, "unable to read file"));
|
||||
OX_REQUIRE(uuid, keel::readUuidHeader(buff));
|
||||
OX_REQUIRE(obj, keel::readAsset(ts, buff).reoriginate(1, "unable to parse file"));
|
||||
buff.clear();
|
||||
ox::BufferWriter writer{&buff};
|
||||
OX_RETURN_ERROR(keel::writeUuidHeader(writer, uuid));
|
||||
OX_RETURN_ERROR(ox::writeClaw(obj, writer, fmt));
|
||||
if (fmt == ox::ClawFormat::Organic) {
|
||||
*buff.back().value = '\n';
|
||||
}
|
||||
OX_RETURN_ERROR(fs.write(path, buff).reoriginate(1, "unable to write file"));
|
||||
return {};
|
||||
}
|
||||
@@ -31,12 +36,12 @@ static void printUsage() noexcept {
|
||||
|
||||
[[nodiscard]]
|
||||
static constexpr ox::Result<ox::ClawFormat> getFmt(ox::StringViewCR fmtStr) noexcept {
|
||||
if (fmtStr == "mc") {
|
||||
if (caseInsensitiveStrCmp(fmtStr, "mc") == 0) {
|
||||
return ox::ClawFormat::Metal;
|
||||
} else if (fmtStr == "oc") {
|
||||
} else if (caseInsensitiveStrCmp(fmtStr, "oc") == 0) {
|
||||
return ox::ClawFormat::Organic;
|
||||
}
|
||||
return ox::Error(1, "invalid format");
|
||||
return ox::Error{1, "invalid format"};
|
||||
}
|
||||
|
||||
ox::Error cmdChangeFormat(Project &project, ox::SpanView<ox::CString> const args) noexcept {
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <studio/project.hpp>
|
||||
|
||||
namespace studio {
|
||||
|
||||
ox::Error cmdChangeFormat(Project &project, ox::SpanView<ox::CString> args) noexcept;
|
||||
|
||||
@@ -165,7 +165,7 @@ template<typename T>
|
||||
ox::Error Project::writeObj(ox::StringViewCR path, T const &obj, ox::ClawFormat fmt) noexcept {
|
||||
OX_REQUIRE_M(buff, ox::writeClaw(obj, fmt));
|
||||
if (fmt == ox::ClawFormat::Organic) {
|
||||
buff.pop_back();
|
||||
*buff.back().value = '\n';
|
||||
}
|
||||
// write to FS
|
||||
OX_RETURN_ERROR(mkdir(parentDir(path)));
|
||||
|
||||
Reference in New Issue
Block a user