This commit is contained in:
lachrymaLF 2024-06-17 22:37:15 -04:00
parent a811f3287c
commit 7c5768034f
5 changed files with 49 additions and 33 deletions

View file

@ -459,15 +459,15 @@ namespace K::PlugboardNodes {
PlugboardGraph::T_Map<PlugboardGraph::T_Count>::type FetchChain(const CompState& s, const PlugboardGraph::NodeInstance& n, Vector<PlugboardGraph::ConnectInfo> *show_nodes) {
u32 frame = GetNodeInputArg<PlugboardGraph::T_Int>(s, n, 0, show_nodes);
auto *v = std::any_cast<Vector<ChainSegment>>(&n.extra);
if (v->empty())
auto& [v, _] = *std::any_cast<ChainExtra>(&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<ChainSegment>{};
n.extra = ChainExtra{};
}
PlugboardGraph::Node Chain = {

View file

@ -13,9 +13,11 @@
#include <implot.h>
#include <algorithm>
#include <format>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <stb_image_write.h>
#include <chrono>
namespace {
// Panels
@ -996,12 +998,12 @@ namespace K::UI {
ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_Leaf |
ImGuiTreeNodeFlags_FramePadding);
ImGui::TableSetColumnIndex(2);
auto *m = std::any_cast<Vector<PlugboardNodes::ChainSegment>>(&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<PlugboardNodes::ChainExtra>(&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<PlugboardNodes::ChainSegment> 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<decltype(arg)>;
ImGui::TableNextColumn();
if constexpr (std::is_same_v<T, Resource::Resource<Resource::K_R_Still>>) {
ImGui::Text("Still");
}
@ -1380,6 +1384,13 @@ namespace K::UI {
else if constexpr (std::is_same_v<T, Resource::Resource<Resource::K_R_AudioOnly>>) {
ImGui::Text("Audio");
}
ImGui::TableNextColumn();
if constexpr (std::is_same_v<T, Resource::Resource<Resource::K_R_ShaderProgram>>) {
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()) {

View file

@ -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{};

View file

@ -110,6 +110,11 @@ namespace K::PlugboardNodes {
InterpolationExtra interp;
};
struct ChainExtra {
Vector<ChainSegment> segments;
Vector<u32> selected; // indices
};
extern PlugboardGraph::Node Chain;
extern std::array<PlugboardGraph::Node*, 20> Nodes;

View file

@ -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