Compare commits

..

17 Commits

Author SHA1 Message Date
d7f309750e Merge commit 'c0baf7efca0e4c3a86a018ad2564d9df7b07c133'
All checks were successful
Build / build (push) Successful in 2m22s
2024-04-21 13:13:26 -05:00
eeb2a5a151 [olympic/studio] Add new ImGui util functions 2024-04-21 10:24:53 -05:00
453f2750dd [nostalgia/core/studio] Cleanup context types 2024-04-21 10:24:29 -05:00
189ba4c545 [olympic/studio] Make studio::run static 2024-04-21 10:23:55 -05:00
057738088e [olympic] Change TypeId building to use constexpr globals 2024-04-21 10:23:22 -05:00
272eabc732 [nostalgia/core/opengl] Unbind vertex arrays when done with them 2024-04-21 10:22:32 -05:00
a02566697a [glutils] Remove trailing whitespace 2024-04-21 10:21:44 -05:00
6808adc8a1 [ox/std] Replace ox::ignore with std::ignore 2024-04-13 00:35:49 -05:00
abc076d657 [ox/std] Cleanup 2024-04-13 00:10:09 -05:00
1b790a34c4 [ox/std] Fix Signed_c and Unsigned_c 2024-04-13 00:07:40 -05:00
9220271630 [nostalgia/core] Update pack transforms to use ModelTypeId_v 2024-04-10 22:20:26 -05:00
7941a514ba [ox/model] Add constexpr ModelTypeId_v 2024-04-10 00:00:48 -05:00
0c09c5306e [ox/std] Fix sfmt constexpr problems 2024-04-09 23:47:18 -05:00
3ff91af86b [ox/std] Sort of fix custom assert 2024-04-09 23:46:54 -05:00
79b42e1df7 [ox/std] Fix some Vector constexpr problems 2024-04-09 23:46:12 -05:00
5eec9085f8 [ox/std] Add nodiscard to some string functions 2024-04-09 22:40:37 -05:00
af7c89564c [ox/std] Add ox::ignore 2024-04-09 22:40:20 -05:00
18 changed files with 182 additions and 42 deletions

View File

@ -57,6 +57,7 @@ misc-*,
readability-duplicate-include,
-misc-non-private-member-variables-in-classes,
-misc-no-recursion,
-misc-include-cleaner,
bugprone-*,
clang-analyzer-*,
modernize-*,

View File

@ -210,7 +210,7 @@ struct BufferSet {
};
void sendVbo(BufferSet const&bs) noexcept;
void sendEbo(BufferSet const&bs) noexcept;
void clearScreen() noexcept;

View File

@ -147,4 +147,19 @@ constexpr auto ModelTypeName_v = getModelTypeName<T, Str>();
template<typename T, typename Str = const char*>
constexpr auto ModelTypeVersion_v = requireModelTypeVersion<T>();
template<typename T, typename Str = const char*>
constexpr auto ModelTypeVersionStr_v = [] {
constexpr auto version = ModelTypeVersion_v<T>;
constexpr auto versionStr = ox::sfmt("{}", version);
return ox::BString<versionStr.len()>{versionStr};
};
template<typename T>
constexpr auto ModelTypeId_v = [] {
constexpr auto name = ModelTypeName_v<T, ox::StringView>;
constexpr auto version = ModelTypeVersion_v<T>;
constexpr auto versionStr = ox::sfmt<ox::BString<19>>("{}", version);
return ox::sfmt<ox::BString<name.len() + versionStr.len() + 1>>("{};{}", name, versionStr);
}();
}

View File

@ -103,6 +103,7 @@ install(
hardware.hpp
hashmap.hpp
heapmgr.hpp
ignore.hpp
iterator.hpp
math.hpp
maybeview.hpp

View File

@ -77,7 +77,7 @@ class FmtArg {
char dataStr[10] = {};
template<typename T>
static StringView sv(const T &v, char *dataStr) noexcept {
constexpr StringView sv(const T &v, char *dataStr) noexcept {
if constexpr(is_bool_v<T>) {
return v ? "true" : "false";
} else if constexpr(is_integer_v<T>) {

20
deps/ox/src/ox/std/ignore.hpp vendored Normal file
View File

@ -0,0 +1,20 @@
/*
* Copyright 2016 - 2024 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#if __has_include(<tuple>)
#include <tuple>
#else
namespace std {
inline constexpr struct {
constexpr void operator=(auto&&) const noexcept {}
} ignore;
}
#endif

View File

@ -11,5 +11,5 @@
#if __has_include(<cassert>)
#include <cassert>
#else
#define assert(e) while (1);
#define assert(e) while (!(e));
#endif

View File

@ -26,6 +26,7 @@
#include "hardware.hpp"
#include "hashmap.hpp"
#include "heapmgr.hpp"
#include "ignore.hpp"
#include "iterator.hpp"
#include "math.hpp"
#include "maybeview.hpp"

View File

@ -80,6 +80,7 @@ constexpr bool endsWith(CRStringView base, CRStringView ending) noexcept {
return base.len() >= endingLen && ox::strcmp(base.data() + (base.len() - endingLen), ending) == 0;
}
[[nodiscard]]
constexpr std::size_t find(CRStringView str, char search) noexcept {
std::size_t i = 0;
for (; i < str.len(); ++i) {
@ -90,6 +91,7 @@ constexpr std::size_t find(CRStringView str, char search) noexcept {
return i;
}
[[nodiscard]]
constexpr std::size_t find(CRStringView str, CRStringView search) noexcept {
std::size_t i = 0;
for (; i < str.len(); ++i) {
@ -101,6 +103,7 @@ constexpr std::size_t find(CRStringView str, CRStringView search) noexcept {
}
template<std::size_t smallSz = 0>
[[nodiscard]]
constexpr ox::Vector<ox::StringView, smallSz> split(CRStringView str, char del) noexcept {
ox::Vector<ox::StringView, smallSz> out;
constexpr auto nextSeg = [](CRStringView current, char del) {
@ -117,6 +120,7 @@ constexpr ox::Vector<ox::StringView, smallSz> split(CRStringView str, char del)
}
template<std::size_t smallSz = 0>
[[nodiscard]]
constexpr ox::Vector<ox::StringView, smallSz> split(CRStringView str, CRStringView del) noexcept {
ox::Vector<ox::StringView, smallSz> out;
constexpr auto nextSeg = [](CRStringView current, CRStringView del) {

View File

@ -143,7 +143,7 @@ template<typename T>
constexpr bool memberable(...) { return false; }
template<typename T>
struct is_class: integral_constant<bool, !is_union<T>::value && memberable<T>(0)> {};
struct is_class: integral_constant<bool, !is_union_v<T> && memberable<T>(nullptr)> {};
namespace test {
struct TestClass {int i;};
@ -159,11 +159,11 @@ constexpr bool is_class_v = is_class<T>();
template<typename T>
constexpr bool is_signed_v = integral_constant<bool, T(-1) < T(0)>::value;
template<typename T, std::size_t bits>
concept Signed_c = is_signed_v<T> && sizeof(T) == 8 * bits;
template<typename T, std::size_t bits = sizeof(T) * 8>
concept Signed_c = is_signed_v<T> && sizeof(T) == bits / 8;
template<typename T, std::size_t bits>
concept Unsigned_c = !is_signed_v<T> && sizeof(T) == 8 * bits;
template<typename T, std::size_t bits = sizeof(T) * 8>
concept Unsigned_c = !is_signed_v<T> && sizeof(T) == bits / 8;
template<typename T, typename U>
struct is_same: false_type {};

View File

@ -52,13 +52,15 @@ struct VectorAllocator {
const std::size_t cap) noexcept {
// this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM,
// try removing it later
if (cap <= m_data.size() && count <= m_data.size()) {
for (auto i = 0u; i < count; ++i) {
const auto dstItem = reinterpret_cast<T*>(&m_data[i]);
const auto srcItem = reinterpret_cast<T*>(&src->m_data[i]);
std::construct_at<T>(dstItem, std::move(*srcItem));
if (!std::is_constant_evaluated()) {
if (cap <= m_data.size() && count <= m_data.size()) {
for (auto i = 0u; i < count; ++i) {
const auto dstItem = reinterpret_cast<T *>(&m_data[i]);
const auto srcItem = reinterpret_cast<T *>(&src->m_data[i]);
std::construct_at<T>(dstItem, std::move(*srcItem));
}
*items = reinterpret_cast<T*>(m_data.data());
}
*items = reinterpret_cast<T*>(m_data.data());
}
}
@ -69,20 +71,24 @@ struct VectorAllocator {
const std::size_t cap) noexcept {
// this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM,
// try removing it later
if (cap <= m_data.size() && count <= m_data.size()) {
for (std::size_t i = 0; i < count; ++i) {
const auto dstItem = reinterpret_cast<T*>(&m_data[i]);
const auto srcItem = reinterpret_cast<T*>(&src->m_data[i]);
*dstItem = std::move(*srcItem);
if (!std::is_constant_evaluated()) {
if (cap <= m_data.size() && count <= m_data.size()) {
for (std::size_t i = 0; i < count; ++i) {
const auto dstItem = reinterpret_cast<T *>(&m_data[i]);
const auto srcItem = reinterpret_cast<T *>(&src->m_data[i]);
*dstItem = std::move(*srcItem);
}
*items = reinterpret_cast<T*>(m_data.data());
}
*items = reinterpret_cast<T*>(m_data.data());
}
}
constexpr void deallocate(T *items, std::size_t cap) noexcept {
// small vector optimization cannot be done it constexpr, but it doesn't really matter in constexpr
if (std::is_constant_evaluated() || (items && static_cast<void*>(items) != static_cast<void*>(m_data.data()))) {
m_allocator.deallocate(items, cap);
if (std::is_constant_evaluated()) {
if (items && static_cast<void*>(items) != static_cast<void*>(m_data.data())) {
m_allocator.deallocate(items, cap);
}
}
}

View File

@ -14,7 +14,7 @@
namespace nostalgia::core {
class KeelModule: public keel::Module {
static class: public keel::Module {
private:
NostalgiaPaletteToPaletteV1Converter m_nostalgiaPaletteToPaletteV1Converter;
PaletteV1ToPaletteV2Converter m_paletteV1ToPaletteV2Converter;
@ -62,11 +62,11 @@ class KeelModule: public keel::Module {
oxRequire(hdr, keel::readAssetHeader(buff));
auto const typeId = ox::buildTypeId(
hdr.clawHdr.typeName, hdr.clawHdr.typeVersion, hdr.clawHdr.typeParams);
if (typeId == ox::buildTypeId<TileSheetV1>() ||
typeId == ox::buildTypeId<TileSheetV2>() ||
typeId == ox::buildTypeId<TileSheetV3>() ||
typeId == ox::buildTypeId<TileSheetV4>()) {
oxReturnError(keel::convertBuffToBuff<core::CompactTileSheet>(
if (typeId == ox::ModelTypeId_v<TileSheetV1> ||
typeId == ox::ModelTypeId_v<TileSheetV2> ||
typeId == ox::ModelTypeId_v<TileSheetV3> ||
typeId == ox::ModelTypeId_v<TileSheetV4>) {
oxReturnError(keel::convertBuffToBuff<CompactTileSheet>(
ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
}
return {};
@ -75,19 +75,18 @@ class KeelModule: public keel::Module {
oxRequire(hdr, keel::readAssetHeader(buff));
auto const typeId = ox::buildTypeId(
hdr.clawHdr.typeName, hdr.clawHdr.typeVersion, hdr.clawHdr.typeParams);
if (typeId == ox::buildTypeId<NostalgiaPalette>() ||
typeId == ox::buildTypeId<PaletteV1>()) {
oxReturnError(keel::convertBuffToBuff<core::Palette>(
if (typeId == ox::ModelTypeId_v<NostalgiaPalette> ||
typeId == ox::ModelTypeId_v<PaletteV1>) {
oxReturnError(keel::convertBuffToBuff<Palette>(
ctx, buff, ox::ClawFormat::Metal).moveTo(buff));
}
return {};
},
};
}
};
} mod;
static const KeelModule mod;
const keel::Module *keelModule() noexcept {
keel::Module const*keelModule() noexcept {
return &mod;
}

View File

@ -239,6 +239,7 @@ static void initSpritesBufferset(Context &ctx) noexcept {
glEnableVertexAttribArray(texCoordAttr);
glVertexAttribPointer(texCoordAttr, 2, GL_FLOAT, GL_FALSE, SpriteVertexVboRowLength * sizeof(float),
std::bit_cast<void*>(uintptr_t{4 * sizeof(float)}));
glBindVertexArray(0);
}
static void initBackgroundBufferset(
@ -272,6 +273,7 @@ static void initBackgroundBufferset(
glVertexAttribPointer(
palBankAttr, 1, GL_FLOAT, GL_FALSE, BgVertexVboRowLength * sizeof(float),
std::bit_cast<void*>(uintptr_t{6 * sizeof(float)}));
glBindVertexArray(0);
}
static glutils::GLTexture createTexture(
@ -301,6 +303,7 @@ static void drawBackground(CBB &cbb) noexcept {
}
glBindTexture(GL_TEXTURE_2D, cbb.tex);
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(cbb.elements.size()), GL_UNSIGNED_INT, nullptr);
glBindVertexArray(0);
}
static void drawBackgrounds(
@ -354,6 +357,7 @@ static void drawSprites(Context &ctx, ox::Size const&renderSz) noexcept {
// draw
glBindTexture(GL_TEXTURE_2D, sb.tex);
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(sb.elements.size()), GL_UNSIGNED_INT, nullptr);
glBindVertexArray(0);
}
static void loadPalette(

View File

@ -342,13 +342,14 @@ void TileSheetEditorImGui::drawTileSheet(ox::Vec2 const&fbSize) noexcept {
} else if (m_view.updated()) {
m_view.ackUpdate();
}
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
// clear screen and draw
glViewport(0, 0, fbSizei.width, fbSizei.height);
m_view.draw();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
{
glutils::FrameBufferBind const frameBufferBind(m_framebuffer);
// clear screen and draw
glViewport(0, 0, fbSizei.width, fbSizei.height);
m_view.draw();
}
ImGui::Image(
std::bit_cast<ImTextureID>(uintptr_t{m_framebuffer.color.id}),
ig::toImTextureID(m_framebuffer.color.id),
static_cast<ImVec2>(fbSize),
ImVec2(0, 1),
ImVec2(1, 0));

View File

@ -14,6 +14,7 @@ namespace nostalgia::core {
TileSheetEditorView::TileSheetEditorView(studio::StudioContext &sctx, ox::StringView path, studio::UndoStack &undoStack):
m_model(sctx, path, undoStack),
m_pixelsDrawer(m_model) {
glBindVertexArray(0);
// build shaders
oxThrowError(m_pixelsDrawer.buildShader());
oxThrowError(m_pixelGridDrawer.buildShader());

View File

@ -160,7 +160,7 @@ auto transformRule(keel::Context &ctx, ox::Buffer &buff) noexcept -> ox::Error {
oxRequire(hdr, readAssetHeader(buff));
const auto typeId = ox::buildTypeId(
hdr.clawHdr.typeName, hdr.clawHdr.typeVersion, hdr.clawHdr.typeParams);
if (typeId == ox::buildTypeId<From>()) {
if (typeId == ox::ModelTypeId_v<From>) {
oxReturnError(keel::convertBuffToBuff<To>(ctx, buff, fmt).moveTo(buff));
}
return {};

View File

@ -56,7 +56,7 @@ static ox::Error runApp(
return err;
}
ox::Error run(
static ox::Error run(
ox::CRStringView appName,
ox::CRStringView projectDataDir,
int,

View File

@ -8,6 +8,8 @@
#include <imgui.h>
#include <ox/std/bit.hpp>
#include <turbine/context.hpp>
#include <studio/context.hpp>
@ -15,6 +17,91 @@ namespace studio::ig {
inline constexpr auto BtnSz = ImVec2{52, 22};
constexpr ImTextureID toImTextureID(ox::Unsigned_c auto id) noexcept
requires(sizeof(id) <= sizeof(ox::Uint<sizeof(ImTextureID)*8>)) {
return std::bit_cast<ImTextureID>(ox::Uint<sizeof(ImTextureID)*8>{id});
}
template<typename T>
ox::Result<T> getDragDropPayload(ox::CStringView name) noexcept {
auto const payload = ImGui::AcceptDragDropPayload(name.c_str());
if (!payload) {
return OxError(1, "No drag/drop payload");
}
return ox::readClaw<T>(
reinterpret_cast<char const*>(payload->Data),
static_cast<size_t>(payload->DataSize));
}
ox::Error setDragDropPayload(ox::CStringView name, auto const &obj) noexcept {
oxRequire(buff, ox::writeClaw(obj, ox::ClawFormat::Metal));
ImGui::SetDragDropPayload(name.c_str(), buff.data(), buff.size());
return {};
}
class DragDropSource {
private:
bool const m_active{};
public:
inline DragDropSource() noexcept:
m_active(ImGui::BeginDragDropSource()) {
}
inline ~DragDropSource() noexcept {
if (m_active) {
ImGui::EndDragDropSource();
}
}
constexpr operator bool() const noexcept {
return m_active;
}
};
inline auto dragDropSource(auto const&cb) noexcept {
if constexpr(ox::is_same_v<decltype(cb()), ox::Error>) {
if (ig::DragDropSource const tgt; tgt) [[unlikely]] {
return cb();
}
} else {
if (ig::DragDropSource const tgt; tgt) [[unlikely]] {
cb();
}
}
}
class DragDropTarget {
private:
bool const m_active{};
public:
inline DragDropTarget() noexcept:
m_active(ImGui::BeginDragDropTarget()) {
}
inline ~DragDropTarget() noexcept {
if (m_active) {
ImGui::EndDragDropTarget();
}
}
constexpr operator bool() const noexcept {
return m_active;
}
};
inline auto dragDropTarget(auto const&cb) noexcept {
if constexpr(ox::is_same_v<decltype(cb()), ox::Error>) {
if (ig::DragDropTarget const tgt; tgt) [[unlikely]] {
return cb();
}
return ox::Error{};
} else {
if (ig::DragDropTarget const tgt; tgt) [[unlikely]] {
cb();
}
}
}
class ChildStackItem {
public:
explicit ChildStackItem(ox::CStringView id, ImVec2 const&sz = {}) noexcept;