vecs
This commit is contained in:
parent
a811f3287c
commit
7c5768034f
5 changed files with 49 additions and 33 deletions
|
@ -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) {
|
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);
|
u32 frame = GetNodeInputArg<PlugboardGraph::T_Int>(s, n, 0, show_nodes);
|
||||||
|
|
||||||
auto *v = std::any_cast<Vector<ChainSegment>>(&n.extra);
|
auto& [v, _] = *std::any_cast<ChainExtra>(&n.extra);
|
||||||
if (v->empty())
|
if (v.empty())
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
if (v->back().frame <= frame)
|
if (v.back().frame <= frame)
|
||||||
return v->back().value;
|
return v.back().value;
|
||||||
if (v->front().frame >= frame)
|
if (v.front().frame >= frame)
|
||||||
return v->front().value;
|
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) {
|
[](u32 a, const PlugboardNodes::ChainSegment& b) {
|
||||||
return a < b.frame;
|
return a < b.frame;
|
||||||
}), it = std::prev(nit);
|
}), it = std::prev(nit);
|
||||||
|
@ -480,7 +480,7 @@ namespace K::PlugboardNodes {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetUpChain(PlugboardGraph::NodeInstance& n) {
|
void SetUpChain(PlugboardGraph::NodeInstance& n) {
|
||||||
n.extra = Vector<ChainSegment>{};
|
n.extra = ChainExtra{};
|
||||||
}
|
}
|
||||||
|
|
||||||
PlugboardGraph::Node Chain = {
|
PlugboardGraph::Node Chain = {
|
||||||
|
|
|
@ -13,9 +13,11 @@
|
||||||
#include <implot.h>
|
#include <implot.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <format>
|
||||||
|
|
||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
#include <stb_image_write.h>
|
#include <stb_image_write.h>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
// Panels
|
// Panels
|
||||||
|
@ -996,12 +998,12 @@ namespace K::UI {
|
||||||
ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_Leaf |
|
ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_Leaf |
|
||||||
ImGuiTreeNodeFlags_FramePadding);
|
ImGuiTreeNodeFlags_FramePadding);
|
||||||
ImGui::TableSetColumnIndex(2);
|
ImGui::TableSetColumnIndex(2);
|
||||||
auto *m = std::any_cast<Vector<PlugboardNodes::ChainSegment>>(&info.p->extra);
|
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;
|
bool m_empty = m.empty(), m_has_before = !m_empty && m.begin()->frame >= s.current_frame;
|
||||||
|
|
||||||
ImGui::BeginDisabled(m_empty || m_has_before);
|
ImGui::BeginDisabled(m_empty || m_has_before);
|
||||||
if (ImGui::Button("<"))
|
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;
|
[](u32 a, const PlugboardNodes::ChainSegment& b) { return a < b.frame; }))->frame;
|
||||||
ImGui::EndDisabled();
|
ImGui::EndDisabled();
|
||||||
|
|
||||||
|
@ -1011,39 +1013,40 @@ namespace K::UI {
|
||||||
PlugboardGraph::Eval(s, info)), copy = v;
|
PlugboardGraph::Eval(s, info)), copy = v;
|
||||||
ImGui::DragFloat("##value", &v);
|
ImGui::DragFloat("##value", &v);
|
||||||
if (v != copy) {
|
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; });
|
[](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;
|
l->value = v;
|
||||||
else
|
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
|
m_has_before ? std::prev(l)->interp.interp : PlugboardNodes::K_I_Linear
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SameLine();
|
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(">"))
|
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;
|
[](u32 a, const PlugboardNodes::ChainSegment& b) { return a < b.frame; })->frame;
|
||||||
ImGui::EndDisabled();
|
ImGui::EndDisabled();
|
||||||
|
|
||||||
ImGui::TableSetColumnIndex(3);
|
ImGui::TableSetColumnIndex(3);
|
||||||
ImGui::Text("%lu", m->size());
|
ImGui::Text("%lu", m.size());
|
||||||
ImGui::TableSetColumnIndex(4);
|
ImGui::TableSetColumnIndex(4);
|
||||||
ImVec2 begin_tl = ImGui::GetCursorScreenPos();
|
ImVec2 begin_tl = ImGui::GetCursorScreenPos();
|
||||||
|
|
||||||
static Vector<PlugboardNodes::ChainSegment> m_copy{};
|
static Vector<PlugboardNodes::ChainSegment> m_copy{};
|
||||||
static u32 dragging{};
|
static u32 dragging{};
|
||||||
static decltype(m) drag_m = nullptr;
|
static decltype(m)* drag_m = nullptr;
|
||||||
static i64 drag_og = -1;
|
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)
|
if (!not_dragging)
|
||||||
m->clear();
|
m.clear();
|
||||||
auto key_loop_target = not_dragging ? m : &m_copy;
|
auto key_loop_target = not_dragging ? &m : &m_copy;
|
||||||
for (auto& [k, val, segment]: *key_loop_target) {
|
for (u32 ii = 0; ii < key_loop_target->size(); ii++) {
|
||||||
|
auto& [k, val, segment] = (*key_loop_target)[ii];
|
||||||
ImGui::PushID(k);
|
ImGui::PushID(k);
|
||||||
|
|
||||||
if (!not_dragging && drag_og == k)
|
if (!not_dragging && drag_og == k)
|
||||||
|
@ -1058,10 +1061,10 @@ namespace K::UI {
|
||||||
s.frame_max) + begin_tl.x - 2.5f,
|
s.frame_max) + begin_tl.x - 2.5f,
|
||||||
begin_tl.y});
|
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 (!not_dragging) {
|
||||||
if (drag_og == k) {
|
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) {
|
[](const PlugboardNodes::ChainSegment& a, u32 b) {
|
||||||
return a.frame < b;
|
return a.frame < b;
|
||||||
}), dragging, val, segment);
|
}), dragging, val, segment);
|
||||||
|
@ -1078,15 +1081,15 @@ namespace K::UI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
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) {
|
[](const PlugboardNodes::ChainSegment& a, u32 b) {
|
||||||
return a.frame < b;
|
return a.frame < b;
|
||||||
}), k, val, segment);
|
}), k, val, segment);
|
||||||
}
|
}
|
||||||
else if (ImGui::IsItemClicked()) {
|
else if (ImGui::IsItemClicked()) {
|
||||||
m_copy = *m;
|
m_copy = m;
|
||||||
drag_og = k;
|
drag_og = k;
|
||||||
drag_m = m;
|
drag_m = &m;
|
||||||
}
|
}
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
|
@ -1350,10 +1353,11 @@ namespace K::UI {
|
||||||
|
|
||||||
void Assets(CompState& s) {
|
void Assets(CompState& s) {
|
||||||
if (ImGui::Begin("Assets", &draw_assets)) {
|
if (ImGui::Begin("Assets", &draw_assets)) {
|
||||||
ImGui::TextUnformatted("Currently loaded assets:");
|
ImGui::TextUnformatted("Loaded assets:");
|
||||||
if (ImGui::BeginTable("Assets", 2, ImGuiTableFlags_Borders)) {
|
if (ImGui::BeginTable("Assets", 3, ImGuiTableFlags_Borders)) {
|
||||||
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch);
|
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch);
|
||||||
ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_WidthFixed);
|
ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_WidthFixed);
|
||||||
|
ImGui::TableSetupColumn("Modified", ImGuiTableColumnFlags_WidthFixed);
|
||||||
ImGui::TableHeadersRow();
|
ImGui::TableHeadersRow();
|
||||||
|
|
||||||
i32 i = 0;
|
i32 i = 0;
|
||||||
|
@ -1362,9 +1366,9 @@ namespace K::UI {
|
||||||
ImGui::PushID(i++);
|
ImGui::PushID(i++);
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::Text("%s", name.c_str());
|
ImGui::Text("%s", name.c_str());
|
||||||
ImGui::TableNextColumn();
|
|
||||||
std::visit([](auto&& arg){
|
std::visit([](auto&& arg){
|
||||||
using T = std::decay_t<decltype(arg)>;
|
using T = std::decay_t<decltype(arg)>;
|
||||||
|
ImGui::TableNextColumn();
|
||||||
if constexpr (std::is_same_v<T, Resource::Resource<Resource::K_R_Still>>) {
|
if constexpr (std::is_same_v<T, Resource::Resource<Resource::K_R_Still>>) {
|
||||||
ImGui::Text("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>>) {
|
else if constexpr (std::is_same_v<T, Resource::Resource<Resource::K_R_AudioOnly>>) {
|
||||||
ImGui::Text("Audio");
|
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);
|
}, res);
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
|
@ -1419,7 +1430,6 @@ namespace K::UI {
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||||
// io.Fonts->AddFontFromFileTTF("SourceHanSans-Regular.ttc", 17);
|
|
||||||
ImGui_Implbgfx_Init(K::Graphics::K_VIEW_UI);
|
ImGui_Implbgfx_Init(K::Graphics::K_VIEW_UI);
|
||||||
|
|
||||||
switch (bgfx::getRendererType()) {
|
switch (bgfx::getRendererType()) {
|
||||||
|
|
|
@ -36,8 +36,8 @@ namespace K {
|
||||||
|
|
||||||
extern struct AppState {
|
extern struct AppState {
|
||||||
SDL_Window *window = nullptr;
|
SDL_Window *window = nullptr;
|
||||||
u16 window_width = 1920;
|
u16 window_width = 2300,
|
||||||
u16 window_height = 1080;
|
window_height = 1300;
|
||||||
|
|
||||||
u64 init_time{}, last_time{}, current_time{}, delta_t{};
|
u64 init_time{}, last_time{}, current_time{}, delta_t{};
|
||||||
u32 bgfx_frame{};
|
u32 bgfx_frame{};
|
||||||
|
|
|
@ -110,6 +110,11 @@ namespace K::PlugboardNodes {
|
||||||
InterpolationExtra interp;
|
InterpolationExtra interp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ChainExtra {
|
||||||
|
Vector<ChainSegment> segments;
|
||||||
|
Vector<u32> selected; // indices
|
||||||
|
};
|
||||||
|
|
||||||
extern PlugboardGraph::Node Chain;
|
extern PlugboardGraph::Node Chain;
|
||||||
|
|
||||||
extern std::array<PlugboardGraph::Node*, 20> Nodes;
|
extern std::array<PlugboardGraph::Node*, 20> Nodes;
|
||||||
|
|
1
TODO.md
1
TODO.md
|
@ -36,6 +36,7 @@
|
||||||
|
|
||||||
## Compositor
|
## Compositor
|
||||||
- Simple 3D engine
|
- Simple 3D engine
|
||||||
|
- Flat sets and flat maps pending compiler support
|
||||||
|
|
||||||
## UI
|
## UI
|
||||||
- Adapt nodes for shader graph -- code editor will be fine for now
|
- Adapt nodes for shader graph -- code editor will be fine for now
|
||||||
|
|
Loading…
Add table
Reference in a new issue