From 7c5768034f288f72a4a7a0ccb258d946a4a9a433 Mon Sep 17 00:00:00 2001 From: lachrymaLF Date: Mon, 17 Jun 2024 22:37:15 -0400 Subject: [PATCH] vecs --- Keishiki/PlugboardNodes.cpp | 16 ++++----- Keishiki/UI.cpp | 56 ++++++++++++++++++------------- Keishiki/include/Keishiki.h | 4 +-- Keishiki/include/PlugboardNodes.h | 5 +++ TODO.md | 1 + 5 files changed, 49 insertions(+), 33 deletions(-) diff --git a/Keishiki/PlugboardNodes.cpp b/Keishiki/PlugboardNodes.cpp index 30f40c8..be6d9f1 100644 --- a/Keishiki/PlugboardNodes.cpp +++ b/Keishiki/PlugboardNodes.cpp @@ -459,15 +459,15 @@ namespace K::PlugboardNodes { PlugboardGraph::T_Map::type FetchChain(const CompState& s, const PlugboardGraph::NodeInstance& n, Vector *show_nodes) { u32 frame = GetNodeInputArg(s, n, 0, show_nodes); - auto *v = std::any_cast>(&n.extra); - if (v->empty()) + auto& [v, _] = *std::any_cast(&n.extra); + if (v.empty()) return 0.0f; - if (v->back().frame <= frame) - return v->back().value; - if (v->front().frame >= frame) - return v->front().value; + if (v.back().frame <= frame) + return v.back().value; + if (v.front().frame >= frame) + return v.front().value; - auto nit = std::upper_bound(v->cbegin(), v->cend(), frame, + auto nit = std::upper_bound(v.cbegin(), v.cend(), frame, [](u32 a, const PlugboardNodes::ChainSegment& b) { return a < b.frame; }), it = std::prev(nit); @@ -480,7 +480,7 @@ namespace K::PlugboardNodes { } void SetUpChain(PlugboardGraph::NodeInstance& n) { - n.extra = Vector{}; + n.extra = ChainExtra{}; } PlugboardGraph::Node Chain = { diff --git a/Keishiki/UI.cpp b/Keishiki/UI.cpp index f23298f..24503c2 100644 --- a/Keishiki/UI.cpp +++ b/Keishiki/UI.cpp @@ -13,9 +13,11 @@ #include #include +#include #define STB_IMAGE_WRITE_IMPLEMENTATION #include +#include namespace { // Panels @@ -996,12 +998,12 @@ namespace K::UI { ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_FramePadding); ImGui::TableSetColumnIndex(2); - auto *m = std::any_cast>(&info.p->extra); - bool m_empty = m->empty(), m_has_before = !m_empty && m->begin()->frame >= s.current_frame; + auto& [m, m_sel] = *std::any_cast(&info.p->extra); + bool m_empty = m.empty(), m_has_before = !m_empty && m.begin()->frame >= s.current_frame; ImGui::BeginDisabled(m_empty || m_has_before); if (ImGui::Button("<")) - s.current_frame = std::prev(std::upper_bound(m->begin(), m->end(), s.current_frame, + s.current_frame = std::prev(std::upper_bound(m.begin(), m.end(), s.current_frame, [](u32 a, const PlugboardNodes::ChainSegment& b) { return a < b.frame; }))->frame; ImGui::EndDisabled(); @@ -1011,39 +1013,40 @@ namespace K::UI { PlugboardGraph::Eval(s, info)), copy = v; ImGui::DragFloat("##value", &v); if (v != copy) { - auto l = std::lower_bound(m->begin(), m->end(), s.current_frame, + auto l = std::lower_bound(m.begin(), m.end(), s.current_frame, [](const PlugboardNodes::ChainSegment& a, u32 b) { return a.frame < b; }); - if (l != m->end() && l->frame == s.current_frame) + if (l != m.end() && l->frame == s.current_frame) l->value = v; else - m->emplace(l, s.current_frame, v, PlugboardNodes::InterpolationExtra{ + m.emplace(l, s.current_frame, v, PlugboardNodes::InterpolationExtra{ m_has_before ? std::prev(l)->interp.interp : PlugboardNodes::K_I_Linear }); } ImGui::SameLine(); - ImGui::BeginDisabled(m_empty || m->back().frame <= s.current_frame); + ImGui::BeginDisabled(m_empty || m.back().frame <= s.current_frame); if (ImGui::Button(">")) - s.current_frame = std::upper_bound(m->begin(), m->end(), s.current_frame, + s.current_frame = std::upper_bound(m.begin(), m.end(), s.current_frame, [](u32 a, const PlugboardNodes::ChainSegment& b) { return a < b.frame; })->frame; ImGui::EndDisabled(); ImGui::TableSetColumnIndex(3); - ImGui::Text("%lu", m->size()); + ImGui::Text("%lu", m.size()); ImGui::TableSetColumnIndex(4); ImVec2 begin_tl = ImGui::GetCursorScreenPos(); static Vector m_copy{}; static u32 dragging{}; - static decltype(m) drag_m = nullptr; + static decltype(m)* drag_m = nullptr; static i64 drag_og = -1; - bool not_dragging = drag_m != m || drag_og == -1; + bool not_dragging = drag_m != &m || drag_og == -1; if (!not_dragging) - m->clear(); - auto key_loop_target = not_dragging ? m : &m_copy; - for (auto& [k, val, segment]: *key_loop_target) { + m.clear(); + auto key_loop_target = not_dragging ? &m : &m_copy; + for (u32 ii = 0; ii < key_loop_target->size(); ii++) { + auto& [k, val, segment] = (*key_loop_target)[ii]; ImGui::PushID(k); if (!not_dragging && drag_og == k) @@ -1058,10 +1061,10 @@ namespace K::UI { s.frame_max) + begin_tl.x - 2.5f, begin_tl.y}); - ImGui::Button("k", {0.0f, row_height * .8f}); + ImGui::Selectable("k", std::find(m_sel.begin(), m_sel.end(), ii) != m_sel.end(), ImGuiSelectableFlags_None, {7.0f, row_height * .8f}); if (!not_dragging) { if (drag_og == k) { - m->emplace(std::lower_bound(m->begin(), m->end(), dragging, + m.emplace(std::lower_bound(m.begin(), m.end(), dragging, [](const PlugboardNodes::ChainSegment& a, u32 b) { return a.frame < b; }), dragging, val, segment); @@ -1078,15 +1081,15 @@ namespace K::UI { } } else - m->emplace(std::lower_bound(m->begin(), m->end(), k, + m.emplace(std::lower_bound(m.begin(), m.end(), k, [](const PlugboardNodes::ChainSegment& a, u32 b) { return a.frame < b; }), k, val, segment); } else if (ImGui::IsItemClicked()) { - m_copy = *m; + m_copy = m; drag_og = k; - drag_m = m; + drag_m = &m; } ImGui::PopID(); } @@ -1350,10 +1353,11 @@ namespace K::UI { void Assets(CompState& s) { if (ImGui::Begin("Assets", &draw_assets)) { - ImGui::TextUnformatted("Currently loaded assets:"); - if (ImGui::BeginTable("Assets", 2, ImGuiTableFlags_Borders)) { + ImGui::TextUnformatted("Loaded assets:"); + if (ImGui::BeginTable("Assets", 3, ImGuiTableFlags_Borders)) { ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch); ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("Modified", ImGuiTableColumnFlags_WidthFixed); ImGui::TableHeadersRow(); i32 i = 0; @@ -1362,9 +1366,9 @@ namespace K::UI { ImGui::PushID(i++); ImGui::TableNextColumn(); ImGui::Text("%s", name.c_str()); - ImGui::TableNextColumn(); std::visit([](auto&& arg){ using T = std::decay_t; + ImGui::TableNextColumn(); if constexpr (std::is_same_v>) { ImGui::Text("Still"); } @@ -1380,6 +1384,13 @@ namespace K::UI { else if constexpr (std::is_same_v>) { ImGui::Text("Audio"); } + ImGui::TableNextColumn(); + if constexpr (std::is_same_v>) { + ImGui::Text("%s", std::format("{:%Y-%m-%d %X}", arg.frag_last_updated).c_str()); + } + else { + ImGui::Text("%s", std::format("{:%Y-%m-%d %X}", arg.last_updated).c_str()); + } }, res); ImGui::PopID(); } @@ -1419,7 +1430,6 @@ namespace K::UI { ImGuiIO& io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; -// io.Fonts->AddFontFromFileTTF("SourceHanSans-Regular.ttc", 17); ImGui_Implbgfx_Init(K::Graphics::K_VIEW_UI); switch (bgfx::getRendererType()) { diff --git a/Keishiki/include/Keishiki.h b/Keishiki/include/Keishiki.h index d98bde0..9c8cc94 100644 --- a/Keishiki/include/Keishiki.h +++ b/Keishiki/include/Keishiki.h @@ -36,8 +36,8 @@ namespace K { extern struct AppState { SDL_Window *window = nullptr; - u16 window_width = 1920; - u16 window_height = 1080; + u16 window_width = 2300, + window_height = 1300; u64 init_time{}, last_time{}, current_time{}, delta_t{}; u32 bgfx_frame{}; diff --git a/Keishiki/include/PlugboardNodes.h b/Keishiki/include/PlugboardNodes.h index e68ca90..91eb69e 100644 --- a/Keishiki/include/PlugboardNodes.h +++ b/Keishiki/include/PlugboardNodes.h @@ -110,6 +110,11 @@ namespace K::PlugboardNodes { InterpolationExtra interp; }; + struct ChainExtra { + Vector segments; + Vector selected; // indices + }; + extern PlugboardGraph::Node Chain; extern std::array Nodes; diff --git a/TODO.md b/TODO.md index 541a193..a507f2f 100644 --- a/TODO.md +++ b/TODO.md @@ -36,6 +36,7 @@ ## Compositor - Simple 3D engine +- Flat sets and flat maps pending compiler support ## UI - Adapt nodes for shader graph -- code editor will be fine for now