From c861fb2af79bb3585038158f3e9ce360138530c1 Mon Sep 17 00:00:00 2001 From: Gauthier Quesnel Date: Thu, 20 Jun 2024 18:44:35 +0200 Subject: [PATCH] app: fix data window sim/mod srcs access --- app/gui/application.cpp | 37 +- app/gui/application.hpp | 24 +- app/gui/data-window.cpp | 826 +++++++++++++++++---------------- app/gui/editor.cpp | 5 +- app/src/main.cpp | 3 +- lib/include/irritator/core.hpp | 356 ++++++++------ lib/src/external_source.cpp | 27 +- lib/src/modeling.cpp | 8 +- lib/src/parameter.cpp | 8 +- lib/src/project.cpp | 2 - 10 files changed, 712 insertions(+), 584 deletions(-) diff --git a/app/gui/application.cpp b/app/gui/application.cpp index 76645aa9..02054e65 100644 --- a/app/gui/application.cpp +++ b/app/gui/application.cpp @@ -794,22 +794,29 @@ void application::start_init_source(const u64 id, attempt_all( [&]() noexcept -> status { - irt_check( - sim.srcs.dispatch(src, source::operation_type::initialize)); - - data_ed.plot.clear(); - for (sz i = 0, e = src.buffer.size(); i != e; ++i) - data_ed.plot.push_back(ImVec2{ - static_cast(i), static_cast(src.buffer[i]) }); - data_ed.plot_available = true; - - return mod.srcs.prepare(); + if (mod.srcs.dispatch(src, source::operation_type::initialize)) { + data_ed.plot.clear(); + for (sz i = 0, e = src.buffer.size(); i != e; ++i) + data_ed.plot.push_back( + ImVec2{ static_cast(i), + static_cast(src.buffer[i]) }); + data_ed.plot_available = true; + + if (!mod.srcs.prepare()) + notifications.try_insert( + log_level::error, [](auto& title, auto& msg) noexcept { + title = "Data error"; + msg = "Fail to prepare data from source."; + }); + } + return success(); }, - - [&]() -> void { - auto& n = notifications.alloc(log_level::error); - n.title = "Fail to initialize data"; - notifications.enable(n); + [&]() { + notifications.try_insert( + log_level::error, [](auto& title, auto& msg) noexcept { + title = "Data error"; + msg = "Fail to prepare data from source."; + }); }); }); } diff --git a/app/gui/application.hpp b/app/gui/application.hpp index acc240c9..bbe334de 100644 --- a/app/gui/application.hpp +++ b/app/gui/application.hpp @@ -24,7 +24,7 @@ namespace irt { template -constexpr std::ptrdiff_t offset_of(const M T::* member) +constexpr std::ptrdiff_t offset_of(const M T::*member) { return reinterpret_cast( &(reinterpret_cast(0)->*member)); @@ -44,7 +44,7 @@ constexpr std::ptrdiff_t offset_of(const M T::* member) //! } //! @endcode template -constexpr T& container_of(M* ptr, const M T::* member) +constexpr T& container_of(M* ptr, const M T::*member) { return *reinterpret_cast(reinterpret_cast(ptr) - offset_of(member)); @@ -632,10 +632,22 @@ struct data_window { ImPlotContext* context = nullptr; - irt::constant_source* constant_ptr = nullptr; - irt::binary_file_source* binary_file_ptr = nullptr; - irt::text_file_source* text_file_ptr = nullptr; - irt::random_source* random_source_ptr = nullptr; + struct selection { + void clear() noexcept; + + void select(constant_source_id id) noexcept; + void select(text_file_source_id id) noexcept; + void select(binary_file_source_id id) noexcept; + void select(random_source_id id) noexcept; + + bool is(constant_source_id id) const noexcept; + bool is(text_file_source_id id) const noexcept; + bool is(binary_file_source_id id) const noexcept; + bool is(random_source_id id) const noexcept; + + std::optional type_sel; + u64 id_sel = 0; + } sel; bool show_file_dialog = false; bool plot_available = false; diff --git a/app/gui/data-window.cpp b/app/gui/data-window.cpp index b3d5dcae..513b4df9 100644 --- a/app/gui/data-window.cpp +++ b/app/gui/data-window.cpp @@ -191,7 +191,7 @@ static void task_try_finalize_source(application& app, src.id = id; src.type = type; - if (auto ret = app.sim.srcs.dispatch(src, source::operation_type::finalize); + if (auto ret = app.mod.srcs.dispatch(src, source::operation_type::finalize); !ret) { auto& n = app.notifications.alloc(log_level::error); n.title = "Fail to finalize data"; @@ -211,158 +211,214 @@ data_window::~data_window() noexcept void data_window::show() noexcept { + auto& app = container_of(this, &application::data_ed); + if (!ImGui::Begin(data_window::name, &is_open)) { ImGui::End(); return; } - auto& app = container_of(this, &application::data_ed); - - auto* old_constant_ptr = constant_ptr; - auto* old_text_file_ptr = text_file_ptr; - auto* old_binary_file_ptr = binary_file_ptr; - auto* old_random_source_ptr = random_source_ptr; - if (ImGui::BeginTable("All sources", - 4, + 5, ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg)) { ImGui::TableSetupColumn("id", ImGuiTableColumnFlags_WidthFixed, 60.f); ImGui::TableSetupColumn("name", ImGuiTableColumnFlags_WidthStretch); ImGui::TableSetupColumn("type", ImGuiTableColumnFlags_WidthStretch); ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthStretch); + ImGui::TableSetupColumn("action", ImGuiTableColumnFlags_WidthStretch); ImGui::TableHeadersRow(); small_string<32> label; - constant_source* cst_src = nullptr; - while (app.mod.srcs.constant_sources.next(cst_src)) { - const auto id = app.mod.srcs.constant_sources.get_id(cst_src); - const auto index = get_index(id); - const bool item_is_selected = cst_src == constant_ptr; - - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - format( - label, "{}-{}", ordinal(source::source_type::constant), index); - if (ImGui::Selectable(label.c_str(), - item_is_selected, - ImGuiSelectableFlags_SpanAllColumns)) { - constant_ptr = cst_src; - binary_file_ptr = nullptr; - text_file_ptr = nullptr; - random_source_ptr = nullptr; - } + { + constant_source* cst_src = nullptr; + constant_source* cst_src_del = nullptr; + while (app.mod.srcs.constant_sources.next(cst_src)) { + ImGui::PushID(cst_src); + const auto id = app.mod.srcs.constant_sources.get_id(cst_src); + const auto index = get_index(id); + const bool item_is_selected = sel.is(id); + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + format(label, + "{}-{}", + ordinal(source::source_type::constant), + index); + if (ImGui::Selectable(label.c_str(), + item_is_selected, + ImGuiSelectableFlags_SpanAllColumns)) { + sel.select(id); + } - ImGui::TableNextColumn(); - ImGui::TextUnformatted(cst_src->name.c_str()); - ImGui::TableNextColumn(); - ImGui::TextUnformatted( - external_source_str(source::source_type::constant)); - ImGui::TableNextColumn(); - if (cst_src->buffer.empty()) { - ImGui::TextUnformatted("-"); - } else { - size_t min = std::min(cst_src->buffer.size(), size_t(3)); - if (min == 1u) - ImGui::Text("%f", cst_src->buffer[0]); - else if (min == 2u) - ImGui::Text( - "%f %f", cst_src->buffer[0], cst_src->buffer[1]); - else - ImGui::Text("%f %f %f ...", - cst_src->buffer[0], - cst_src->buffer[1], - cst_src->buffer[2]); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(cst_src->name.c_str()); + ImGui::TableNextColumn(); + ImGui::TextUnformatted( + external_source_str(source::source_type::constant)); + ImGui::TableNextColumn(); + if (cst_src->buffer.empty()) { + ImGui::TextUnformatted("-"); + } else { + size_t min = std::min(cst_src->buffer.size(), size_t(3)); + if (min == 1u) + ImGui::Text("%f", cst_src->buffer[0]); + else if (min == 2u) + ImGui::Text( + "%f %f", cst_src->buffer[0], cst_src->buffer[1]); + else + ImGui::Text("%f %f %f ...", + cst_src->buffer[0], + cst_src->buffer[1], + cst_src->buffer[2]); + } + ImGui::TableNextColumn(); + if (ImGui::Button("del")) { + cst_src_del = cst_src; + if (sel.is(id)) + sel.clear(); + } + + ImGui::PopID(); } - } - text_file_source* txt_src = nullptr; - while (app.mod.srcs.text_file_sources.next(txt_src)) { - const auto id = app.mod.srcs.text_file_sources.get_id(txt_src); - const auto index = get_index(id); - const bool item_is_selected = txt_src == text_file_ptr; - - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - format( - label, "{}-{}", ordinal(source::source_type::text_file), index); - if (ImGui::Selectable(label.c_str(), - item_is_selected, - ImGuiSelectableFlags_SpanAllColumns)) { - constant_ptr = nullptr; - binary_file_ptr = nullptr; - text_file_ptr = txt_src; - random_source_ptr = nullptr; + if (cst_src_del) + app.mod.srcs.constant_sources.free(*cst_src_del); + } + + { + text_file_source* txt_src = nullptr; + text_file_source* txt_src_del = nullptr; + while (app.mod.srcs.text_file_sources.next(txt_src)) { + ImGui::PushID(txt_src); + + const auto id = app.mod.srcs.text_file_sources.get_id(txt_src); + const auto index = get_index(id); + const bool item_is_selected = sel.is(id); + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + format(label, + "{}-{}", + ordinal(source::source_type::text_file), + index); + if (ImGui::Selectable(label.c_str(), + item_is_selected, + ImGuiSelectableFlags_SpanAllColumns)) { + sel.select(id); + } + + ImGui::TableNextColumn(); + ImGui::TextUnformatted(txt_src->name.c_str()); + ImGui::TableNextColumn(); + ImGui::TextUnformatted( + external_source_str(source::source_type::text_file)); + ImGui::TableNextColumn(); + // ImGui::Text("%s", txt_src->file_path.string().c_str()); + + ImGui::TableNextColumn(); + if (ImGui::Button("del")) { + txt_src_del = txt_src; + if (sel.is(id)) + sel.clear(); + } + + ImGui::PopID(); } - ImGui::TableNextColumn(); - ImGui::TextUnformatted(txt_src->name.c_str()); - ImGui::TableNextColumn(); - ImGui::TextUnformatted( - external_source_str(source::source_type::text_file)); - ImGui::TableNextColumn(); - // ImGui::Text("%s", txt_src->file_path.string().c_str()); - } - - binary_file_source* bin_src = nullptr; - while (app.mod.srcs.binary_file_sources.next(bin_src)) { - const auto id = app.mod.srcs.binary_file_sources.get_id(bin_src); - const auto index = get_index(id); - const bool item_is_selected = bin_src == binary_file_ptr; - - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - format( - label, "{}-{}", ordinal(source::source_type::binary_file), index); - if (ImGui::Selectable(label.c_str(), - item_is_selected, - ImGuiSelectableFlags_SpanAllColumns)) { - constant_ptr = nullptr; - binary_file_ptr = bin_src; - text_file_ptr = nullptr; - random_source_ptr = nullptr; + if (txt_src_del) + app.mod.srcs.text_file_sources.free(*txt_src_del); + } + + { + binary_file_source* bin_src = nullptr; + binary_file_source* bin_src_del = nullptr; + while (app.mod.srcs.binary_file_sources.next(bin_src)) { + ImGui::PushID(bin_src); + const auto id = + app.mod.srcs.binary_file_sources.get_id(bin_src); + const auto index = get_index(id); + const bool item_is_selected = sel.is(id); + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + format(label, + "{}-{}", + ordinal(source::source_type::binary_file), + index); + if (ImGui::Selectable(label.c_str(), + item_is_selected, + ImGuiSelectableFlags_SpanAllColumns)) { + sel.select(id); + } + + ImGui::TableNextColumn(); + ImGui::TextUnformatted(bin_src->name.c_str()); + ImGui::TableNextColumn(); + ImGui::TextUnformatted( + external_source_str(source::source_type::binary_file)); + ImGui::TableNextColumn(); + // ImGui::Text("%s", bin_src->file_path.string().c_str()); + ImGui::TableNextColumn(); + if (ImGui::Button("del")) { + bin_src_del = bin_src; + if (sel.is(id)) + sel.clear(); + } + + ImGui::PopID(); } - ImGui::TableNextColumn(); - ImGui::TextUnformatted(bin_src->name.c_str()); - ImGui::TableNextColumn(); - ImGui::TextUnformatted( - external_source_str(source::source_type::binary_file)); - ImGui::TableNextColumn(); - // ImGui::Text("%s", bin_src->file_path.string().c_str()); - } - - random_source* rnd_src = nullptr; - while (app.mod.srcs.random_sources.next(rnd_src)) { - const auto id = app.mod.srcs.random_sources.get_id(rnd_src); - const auto index = get_index(id); - const bool item_is_selected = rnd_src == random_source_ptr; - - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - format(label, "{}-{}", ordinal(source::source_type::random), index); - if (ImGui::Selectable(label.c_str(), - item_is_selected, - ImGuiSelectableFlags_SpanAllColumns)) { - constant_ptr = nullptr; - binary_file_ptr = nullptr; - text_file_ptr = nullptr; - random_source_ptr = rnd_src; + if (bin_src_del) + app.mod.srcs.binary_file_sources.free(*bin_src_del); + } + + { + random_source* rnd_src = nullptr; + random_source* rnd_src_del = nullptr; + while (app.mod.srcs.random_sources.next(rnd_src)) { + ImGui::PushID(rnd_src); + const auto id = app.mod.srcs.random_sources.get_id(rnd_src); + const auto index = get_index(id); + const bool item_is_selected = sel.is(id); + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + format( + label, "{}-{}", ordinal(source::source_type::random), index); + if (ImGui::Selectable(label.c_str(), + item_is_selected, + ImGuiSelectableFlags_SpanAllColumns)) { + sel.select(id); + } + + ImGui::TableNextColumn(); + ImGui::TextUnformatted(rnd_src->name.c_str()); + ImGui::TableNextColumn(); + ImGui::TextUnformatted( + external_source_str(source::source_type::random)); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(distribution_str(rnd_src->distribution)); + + ImGui::TableNextColumn(); + if (ImGui::Button("del")) { + rnd_src_del = rnd_src; + if (sel.is(id)) + sel.clear(); + } + + ImGui::PopID(); } - ImGui::TableNextColumn(); - ImGui::TextUnformatted(rnd_src->name.c_str()); - ImGui::TableNextColumn(); - ImGui::TextUnformatted( - external_source_str(source::source_type::random)); - ImGui::TableNextColumn(); - ImGui::TextUnformatted(distribution_str(rnd_src->distribution)); + if (rnd_src_del) + app.mod.srcs.random_sources.free(*rnd_src_del); } + ImGui::EndTable(); ImGuiStyle& style = ImGui::GetStyle(); const float width = - (ImGui::GetContentRegionAvail().x - 4.f * style.ItemSpacing.x) / 5.f; + (ImGui::GetContentRegionAvail().x - 4.f * style.ItemSpacing.x) / 4.f; ImVec2 button_sz(width, 20); ImGui::Spacing(); @@ -408,25 +464,25 @@ void data_window::show() noexcept if (ImGui::Button("+text file", button_sz)) { if (app.mod.srcs.text_file_sources.can_alloc(1u)) { auto& new_src = app.mod.srcs.text_file_sources.alloc(); - attempt_all( - [&]() noexcept -> status { - irt_check(new_src.init()); - return success(); - }, - - [&](const external_source::part s) noexcept -> void { - auto& n = app.notifications.alloc(); - n.title = "Fail to initialize source"; - format(n.message, "Error: {}", ordinal(s)); - app.notifications.enable(n); - }, - - [&]() noexcept -> void { - auto& n = app.notifications.alloc(); - n.title = "Fail to initialize source"; - n.message = "Error: unknown"; - app.notifications.enable(n); - }); + // attempt_all( + // [&]() noexcept -> status { + // irt_check(new_src.init()); + // return success(); + // }, + + // [&](const external_source::part s) noexcept -> void { + // auto& n = app.notifications.alloc(); + // n.title = "Fail to initialize source"; + // format(n.message, "Error: {}", ordinal(s)); + // app.notifications.enable(n); + // }, + + // [&]() noexcept -> void { + // auto& n = app.notifications.alloc(); + // n.title = "Fail to initialize source"; + // n.message = "Error: unknown"; + // app.notifications.enable(n); + // }); } } @@ -434,25 +490,25 @@ void data_window::show() noexcept if (ImGui::Button("+binary file", button_sz)) { if (app.mod.srcs.binary_file_sources.can_alloc(1u)) { auto& new_src = app.mod.srcs.binary_file_sources.alloc(); - attempt_all( - [&]() noexcept -> status { - irt_check(new_src.init()); - return success(); - }, - - [&](const external_source::part s) noexcept -> void { - auto& n = app.notifications.alloc(); - n.title = "Fail to initialize source"; - format(n.message, "Error: {}", ordinal(s)); - app.notifications.enable(n); - }, - - [&]() noexcept -> void { - auto& n = app.notifications.alloc(); - n.title = "Fail to initialize source"; - n.message = "Error: unknown"; - app.notifications.enable(n); - }); + // attempt_all( + // [&]() noexcept -> status { + // irt_check(new_src.init()); + // return success(); + // }, + + // [&](const external_source::part s) noexcept -> void { + // auto& n = app.notifications.alloc(); + // n.title = "Fail to initialize source"; + // format(n.message, "Error: {}", ordinal(s)); + // app.notifications.enable(n); + // }, + + // [&]() noexcept -> void { + // auto& n = app.notifications.alloc(); + // n.title = "Fail to initialize source"; + // n.message = "Error: unknown"; + // app.notifications.enable(n); + // }); } } @@ -484,266 +540,188 @@ void data_window::show() noexcept }); } } - - ImGui::SameLine(); - if (ImGui::Button("delete", button_sz)) { - if (constant_ptr) { - app.mod.srcs.constant_sources.free(*constant_ptr); - constant_ptr = nullptr; - old_constant_ptr = nullptr; - } - if (text_file_ptr) { - app.mod.srcs.text_file_sources.free(*text_file_ptr); - text_file_ptr = nullptr; - old_text_file_ptr = nullptr; - } - if (binary_file_ptr) { - app.mod.srcs.binary_file_sources.free(*binary_file_ptr); - binary_file_ptr = nullptr; - old_binary_file_ptr = nullptr; - } - if (random_source_ptr) { - app.mod.srcs.random_sources.free(*random_source_ptr); - random_source_ptr = nullptr; - old_random_source_ptr = nullptr; - } - } } ImGui::Spacing(); ImGui::Separator(); ImGui::Spacing(); - if (ImGui::CollapsingHeader("Source editor", + if (sel.type_sel.has_value() and + ImGui::CollapsingHeader("Source editor", ImGuiTreeNodeFlags_DefaultOpen)) { - if (constant_ptr) { - const auto id = app.mod.srcs.constant_sources.get_id(constant_ptr); - auto index = get_index(id); - - unsigned new_size = constant_ptr->length; - - ImGui::InputScalar("id", - ImGuiDataType_U32, - reinterpret_cast(&index), - nullptr, - nullptr, - nullptr, - ImGuiInputTextFlags_ReadOnly); - - ImGui::InputText("name", - constant_ptr->name.begin(), - to_unsigned(constant_ptr->name.capacity())); - - if (ImGui::InputScalar("length", ImGuiDataType_U32, &new_size) && - new_size != constant_ptr->length && - new_size < external_source_chunk_size) { - constant_ptr->length = new_size; - } - - for (u32 i = 0; i < constant_ptr->length; ++i) { - ImGui::PushID(static_cast(i)); - ImGui::InputDouble("##name", &constant_ptr->buffer[i]); - ImGui::PopID(); - } - } - - if (text_file_ptr) { - const auto id = - app.mod.srcs.text_file_sources.get_id(text_file_ptr); - auto index = get_index(id); - - ImGui::InputScalar("id", - ImGuiDataType_U32, - reinterpret_cast(&index), - nullptr, - nullptr, - nullptr, - ImGuiInputTextFlags_ReadOnly); - - ImGui::InputText("name", - text_file_ptr->name.begin(), - to_unsigned(text_file_ptr->name.capacity())); - - // ImGui::Text("%s", text_file_ptr->file_path.string().c_str()); - if (ImGui::Button("...")) { - show_file_dialog = true; - } - } + switch (*sel.type_sel) { + case source::source_type::constant: { + const auto id = enum_cast(sel.id_sel); + const auto idx = get_index(id); + if (auto* ptr = app.mod.srcs.constant_sources.try_to_get(id); ptr) { + auto new_size = ptr->length; + + ImGui::InputScalar("id", + ImGuiDataType_U32, + const_cast(&idx), + nullptr, + nullptr, + nullptr, + ImGuiInputTextFlags_ReadOnly); + + ImGui::InputSmallString("name", ptr->name); + + if (ImGui::InputScalar( + "length", ImGuiDataType_U32, &new_size) && + new_size != ptr->length && + new_size < external_source_chunk_size) { + ptr->length = new_size; + } - if (binary_file_ptr) { - const auto id = - app.mod.srcs.binary_file_sources.get_id(binary_file_ptr); - auto index = get_index(id); - - ImGui::InputScalar("id", - ImGuiDataType_U32, - reinterpret_cast(&index), - nullptr, - nullptr, - nullptr, - ImGuiInputTextFlags_ReadOnly); - - ImGui::InputText("name", - binary_file_ptr->name.begin(), - to_unsigned(binary_file_ptr->name.capacity())); - - if (ImGui::InputScalar( - "max source", - ImGuiDataType_U32, - reinterpret_cast(&binary_file_ptr->max_clients))) { - if (auto ret = binary_file_ptr->init(); !ret) { - auto& n = app.notifications.alloc(); - n.title = "Fail to initialize binary file source"; - app.notifications.enable(n); + for (u32 i = 0; i < ptr->length; ++i) { + ImGui::PushID(static_cast(i)); + ImGui::InputDouble("##name", &ptr->buffer[i]); + ImGui::PopID(); } } - - // ImGui::Text("%s", binary_file_ptr->file_path.string().c_str()); - if (ImGui::Button("...")) { - show_file_dialog = true; + } break; + + case source::source_type::text_file: { + const auto id = enum_cast(sel.id_sel); + const auto idx = get_index(id); + if (auto* ptr = app.mod.srcs.text_file_sources.try_to_get(id); + ptr) { + + ImGui::InputScalar("id", + ImGuiDataType_U32, + const_cast(&idx), + nullptr, + nullptr, + nullptr, + ImGuiInputTextFlags_ReadOnly); + + ImGui::InputSmallString("name", ptr->name); + + // ImGui::Text("%s", text_file_ptr->file_path.string().c_str()); + if (ImGui::Button("...")) { + show_file_dialog = true; + } } - } + } break; + + case source::source_type::binary_file: { + const auto id = enum_cast(sel.id_sel); + const auto idx = get_index(id); + if (auto* ptr = app.mod.srcs.binary_file_sources.try_to_get(id); + ptr) { + ImGui::InputScalar("id", + ImGuiDataType_U32, + const_cast(&idx), + nullptr, + nullptr, + nullptr, + ImGuiInputTextFlags_ReadOnly); + + ImGui::InputSmallString("name", ptr->name); + + if (ImGui::InputScalar( + "max source", + ImGuiDataType_U32, + reinterpret_cast(&ptr->max_clients))) { + if (auto ret = ptr->init(); !ret) { + auto& n = app.notifications.alloc(); + n.title = "Fail to initialize binary file source"; + app.notifications.enable(n); + } + } - if (random_source_ptr) { - const auto id = - app.mod.srcs.random_sources.get_id(random_source_ptr); - auto index = get_index(id); - - ImGui::InputScalar("id", - ImGuiDataType_U32, - reinterpret_cast(&index), - nullptr, - nullptr, - nullptr, - ImGuiInputTextFlags_ReadOnly); - - ImGui::InputText("name", - random_source_ptr->name.begin(), - to_unsigned(random_source_ptr->name.capacity())); - - if (ImGui::InputScalar( - "max source", - ImGuiDataType_U32, - reinterpret_cast(&random_source_ptr->max_clients))) { - if (auto ret = random_source_ptr->init(); !ret) { - auto& n = app.notifications.alloc(); - n.title = "Fail to initialize random source"; - app.notifications.enable(n); + // ImGui::Text("%s", + // binary_file_ptr->file_path.string().c_str()); + if (ImGui::Button("...")) { + show_file_dialog = true; } } + } break; + + case source::source_type::random: { + const auto id = enum_cast(sel.id_sel); + const auto idx = get_index(id); + if (auto* ptr = app.mod.srcs.random_sources.try_to_get(id); ptr) { + ImGui::InputScalar("id", + ImGuiDataType_U32, + const_cast(&idx), + nullptr, + nullptr, + nullptr, + ImGuiInputTextFlags_ReadOnly); + + ImGui::InputSmallString("name", ptr->name); + + if (ImGui::InputScalar( + "max source", + ImGuiDataType_U32, + reinterpret_cast(&ptr->max_clients))) { + if (auto ret = ptr->init(); !ret) { + auto& n = app.notifications.alloc(); + n.title = "Fail to initialize random source"; + app.notifications.enable(n); + } + } - show_random_distribution_input(*random_source_ptr); + show_random_distribution_input(*ptr); + } + } break; } } - if (show_file_dialog) { - if (binary_file_ptr) { - const char* title = "Select file path to load"; - const char8_t* filters[] = { u8".dat", nullptr }; - - ImGui::OpenPopup(title); - if (app.f_dialog.show_load_file(title, filters)) { - if (app.f_dialog.state == file_dialog::status::ok) { - binary_file_ptr->file_path = app.f_dialog.result; - - app.start_init_source( - ordinal(app.mod.srcs.binary_file_sources.get_id( - binary_file_ptr)), - source::source_type::binary_file); + if (sel.type_sel.has_value() and show_file_dialog) { + if (*sel.type_sel == source::source_type::binary_file) { + const auto id = enum_cast(sel.id_sel); + if (auto* ptr = app.mod.srcs.binary_file_sources.try_to_get(id); + ptr) { + const char* title = "Select binary file path to load"; + const char8_t* filters[] = { u8".dat", nullptr }; + + ImGui::OpenPopup(title); + if (app.f_dialog.show_load_file(title, filters)) { + if (app.f_dialog.state == file_dialog::status::ok) { + ptr->file_path = app.f_dialog.result; + + app.start_init_source(sel.id_sel, + source::source_type::binary_file); + } + app.f_dialog.clear(); + show_file_dialog = false; } - app.f_dialog.clear(); - binary_file_ptr = nullptr; - show_file_dialog = false; } - } - - if (text_file_ptr) { - const char* title = "Select file path to load"; - const char8_t* filters[] = { u8".txt", nullptr }; - - ImGui::OpenPopup(title); - if (app.f_dialog.show_load_file(title, filters)) { - if (app.f_dialog.state == file_dialog::status::ok) { - text_file_ptr->file_path = app.f_dialog.result; + } else if (*sel.type_sel == source::source_type::text_file) { + const auto id = enum_cast(sel.id_sel); + if (auto* ptr = app.mod.srcs.text_file_sources.try_to_get(id); + ptr) { + const char* title = "Select text file path to load"; + const char8_t* filters[] = { u8".txt", nullptr }; + + ImGui::OpenPopup(title); + if (app.f_dialog.show_load_file(title, filters)) { + if (app.f_dialog.state == file_dialog::status::ok) { + ptr->file_path = app.f_dialog.result; + + app.start_init_source(sel.id_sel, + source::source_type::text_file); + } + app.f_dialog.clear(); + show_file_dialog = false; } - app.f_dialog.clear(); - text_file_ptr = nullptr; - show_file_dialog = false; } } } - const bool user_select_other_source = - old_constant_ptr != constant_ptr || old_text_file_ptr != text_file_ptr || - old_binary_file_ptr != binary_file_ptr || - old_random_source_ptr != random_source_ptr; - - if (user_select_other_source) { - plot_available = false; - u64 id = 0; - source::source_type type = source::source_type::none; - - if (old_text_file_ptr) { - id = ordinal( - app.mod.srcs.text_file_sources.get_id(*old_text_file_ptr)); - type = source::source_type::text_file; - } else if (old_random_source_ptr) { - id = ordinal( - app.mod.srcs.random_sources.get_id(*old_random_source_ptr)); - type = source::source_type::random; - } else if (old_binary_file_ptr) { - id = ordinal( - app.mod.srcs.binary_file_sources.get_id(*old_binary_file_ptr)); - type = source::source_type::binary_file; - } else if (old_constant_ptr) { - id = - ordinal(app.mod.srcs.constant_sources.get_id(*old_constant_ptr)); - type = source::source_type::constant; - } - - if (id != 0 && type != source::source_type::none) - task_try_finalize_source(app, id, type); - - if (text_file_ptr) { - id = ordinal(app.mod.srcs.text_file_sources.get_id(*text_file_ptr)); - type = source::source_type::text_file; - } else if (random_source_ptr) { - id = - ordinal(app.mod.srcs.random_sources.get_id(*random_source_ptr)); - type = source::source_type::random; - } else if (binary_file_ptr) { - id = ordinal( - app.mod.srcs.binary_file_sources.get_id(*binary_file_ptr)); - type = source::source_type::binary_file; - } else if (constant_ptr) { - id = ordinal(app.mod.srcs.constant_sources.get_id(*constant_ptr)); - type = source::source_type::constant; - } - - if (id && type != source::source_type::none) - app.start_init_source(id, type); - } + if (plot_available) { + debug::ensure(plot.size() > 0); + if (ImPlot::BeginPlot("Plot", ImVec2(-1, -1))) { + ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 1.f); + ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 1.f); - const bool show_source = - constant_ptr || random_source_ptr || binary_file_ptr || text_file_ptr; - - if (show_source) { - if (plot_available) { - debug::ensure(plot.size() > 0); - if (ImPlot::BeginPlot("Plot", ImVec2(-1, -1))) { - ImPlot::PushStyleVar(ImPlotStyleVar_LineWeight, 1.f); - ImPlot::PushStyleVar(ImPlotStyleVar_MarkerSize, 1.f); - - ImPlot::PlotScatter("value", - &plot[0].x, - &plot[0].y, - plot.Size, - 0, - sizeof(ImVec2)); - - ImPlot::PopStyleVar(2); - ImPlot::EndPlot(); - } + ImPlot::PlotScatter( + "value", &plot[0].x, &plot[0].y, plot.Size, 0, sizeof(ImVec2)); + + ImPlot::PopStyleVar(2); + ImPlot::EndPlot(); } } @@ -878,4 +856,60 @@ void show_menu_external_sources(application& app, } } +void data_window::selection::clear() noexcept +{ + type_sel.reset(); + id_sel = 0; +} + +void data_window::selection::select(constant_source_id id) noexcept +{ + type_sel = source::source_type::constant; + id_sel = ordinal(id); +} + +void data_window::selection::select(text_file_source_id id) noexcept +{ + type_sel = source::source_type::text_file; + id_sel = ordinal(id); +} + +void data_window::selection::select(binary_file_source_id id) noexcept +{ + type_sel = source::source_type::binary_file; + id_sel = ordinal(id); +} + +void data_window::selection::select(random_source_id id) noexcept +{ + type_sel = source::source_type::random; + id_sel = ordinal(id); +} + +bool data_window::selection::is(constant_source_id id) const noexcept +{ + return type_sel.has_value() and + *type_sel == source::source_type::constant and id_sel == ordinal(id); +} + +bool data_window::selection::is(text_file_source_id id) const noexcept +{ + return type_sel.has_value() and + *type_sel == source::source_type::text_file and + id_sel == ordinal(id); +} + +bool data_window::selection::is(binary_file_source_id id) const noexcept +{ + return type_sel.has_value() and + *type_sel == source::source_type::binary_file and + id_sel == ordinal(id); +} + +bool data_window::selection::is(random_source_id id) const noexcept +{ + return type_sel.has_value() and *type_sel == source::source_type::random and + id_sel == ordinal(id); +} + } // namespace irt diff --git a/app/gui/editor.cpp b/app/gui/editor.cpp index f5cac6e0..aec4bbd0 100644 --- a/app/gui/editor.cpp +++ b/app/gui/editor.cpp @@ -260,9 +260,6 @@ bool show_external_sources_combo(external_source& srcs, small_string<63> label("None"); switch (src_type) { - case source::source_type::none: - break; - case source::source_type::binary_file: { const auto id = enum_cast(src_id); const auto index = get_index(id); @@ -316,7 +313,7 @@ bool show_external_sources_combo(external_source& srcs, if (ImGui::BeginCombo(title, label.c_str())) { { - bool is_selected = src_type == source::source_type::none; + bool is_selected = src_type == source::source_type::constant; ImGui::Selectable("None", is_selected); } diff --git a/app/src/main.cpp b/app/src/main.cpp index 1fa9a83a..abe0140d 100644 --- a/app/src/main.cpp +++ b/app/src/main.cpp @@ -264,7 +264,6 @@ void run_simulation(irt::real begin, irt::modeling mod; irt::simulation_memory_requirement smr{ 1024 * 1024 * 8 }; irt::simulation sim{ smr }; - irt::external_source srcs; irt::cache_rw cache; irt_check(pj.init(init)); @@ -274,7 +273,7 @@ void run_simulation(irt::real begin, irt::time t = begin; const irt::time end = begin + duration; - irt_check(srcs.prepare()); + irt_check(sim.srcs.prepare()); irt_check(sim.initialize(t)); do { diff --git a/lib/include/irritator/core.hpp b/lib/include/irritator/core.hpp index 5e8be43f..5b601940 100644 --- a/lib/include/irritator/core.hpp +++ b/lib/include/irritator/core.hpp @@ -310,6 +310,44 @@ enum class log_level { debug }; +//! Assign a value constrained by the template parameters. +//! +//! @code +//! static int v = 0; +//! if (ImGui::InputInt("test", &v)) { +//! f(v); +//! } +//! +//! void f(constrained_value v) +//! { +//! assert(0 <= *v && *v <= 100); +//! } +//! @endcode +template +class constrained_value +{ +public: + using value_type = T; + +private: + static_assert(std::is_trivial_v, + "T must be a trivial type in ratio_parameter"); + static_assert(Lower < Upper); + + T m_value; + +public: + constexpr constrained_value(const T value_) noexcept + : m_value(value_ < Lower ? Lower + : value_ < Upper ? value_ + : Upper) + {} + + constexpr explicit operator T() const noexcept { return m_value; } + constexpr value_type operator*() const noexcept { return m_value; } + constexpr value_type value() const noexcept { return m_value; } +}; + /***************************************************************************** * * Return status of many function @@ -398,6 +436,116 @@ enum class binary_file_source_id : u64; enum class text_file_source_id : u64; enum class random_source_id : u64; +//! Helps to calculate the sizes of the `vectors` and `data_array` from a +//! number of bytes. Compute for each `source` the same number and adjust +//! the `max_client` variables for both random and binary source. +struct external_source_memory_requirement { + int constant_nb = 4; + int text_file_nb = 4; + int binary_file_nb = 4; + int random_nb = 4; + int binary_file_max_client = 8; + int random_max_client = 8; + + constexpr external_source_memory_requirement() noexcept = default; + + //! Compute the size of each source. + //! + //! @param bytes The numbers of bytes availables. + //! @param source_client_ratio A integer in the range `[0..100]` defines + //! the ratio between `source` and `max_client` variables. `50` mean 50% + //! sources and 50% max_clients, `0` means no source, `100` means no + //! max-client. + constexpr external_source_memory_requirement( + const std::size_t bytes, + const constrained_value source_client_ratio) noexcept; + + constexpr external_source_memory_requirement( + const std::size_t constant, + const std::size_t text_f, + const std::size_t bin_f, + const std::size_t random, + const std::size_t bin_f_max_client, + const std::size_t random_max_client) noexcept; + + constexpr bool valid() const; + + constexpr size_t in_bytes() const noexcept; +}; + +//! Helps to calculate the sizes of the `vectors` and `data_array` from a +//! number of bytes. +class simulation_memory_requirement +{ +public: + constexpr static inline auto default_simulation_model_number = 256u; + constexpr static inline auto default_simulation_connection_number = 1024u; + + std::size_t connections_b = 0; + std::size_t dated_messages_b = 0; + std::size_t external_source_b = 0; + std::size_t simulation_b = 0; + std::size_t global_b = 0; + + int model_nb = 0; + int hsm_nb = 0; + + external_source_memory_requirement srcs; + + /** Computes the required memory to build the simulation that can run at + * least @c model_nb models and @c connection_nb connections. + * + * @param bytes The numbers of bytes availables. + * @param external_source Percentage of memory to use in external source. + * @param source_client_ratio + * @param connections Percentage of simulation memory dedicated to + * connections. + * @param dated_messages Percentage of siulation memory dedicated to fifo, + * lifo history. + */ + constexpr simulation_memory_requirement( + const std::size_t model_nb, + const std::size_t connection_nb, + const constrained_value connections = 5, + const constrained_value hsms = 1, + const constrained_value dated_messages = 5, + const constrained_value external_source = 10, + const constrained_value source_client = 50) noexcept; + + /** Computes the required memory to build the simulation and splits + * available memory in memory resource, free list and container. + * + * @param bytes The numbers of bytes availables. + * @param external_source Percentage of memory to use in external source. + * @param source_client_ratio + * @param connections Percentage of simulation memory dedicated to + * connections. + * @param dated_messages Percentage of siulation memory dedicated to fifo, + * lifo history. + */ + constexpr simulation_memory_requirement( + const std::size_t bytes, + const constrained_value connections = 5, + const constrained_value hsms = 10, + const constrained_value dated_messages = 5, + const constrained_value external_source = 10, + const constrained_value source_client = 50) noexcept; + + constexpr bool valid() const noexcept; + + //! Compute an estimate to store a model in simulation memory. + constexpr static size_t estimate_model() noexcept; + +private: + constexpr void compute_buffer_size( + const std::size_t bytes, + const constrained_value connections, + const constrained_value hsms, + const constrained_value dated_messages, + const constrained_value external_source, + const constrained_value source_client) noexcept; +}; + /***************************************************************************** * * @c source and @c source_id are data from files or random generators. @@ -578,7 +726,6 @@ class source { public: enum class source_type : i16 { - none, binary_file, /* Best solution to reproductible simulation. Each client take a part of the stream (substream). */ constant, /* Just an easy source to use mode. */ @@ -597,7 +744,7 @@ class source std::span buffer; u64 id = 0; - source_type type = source_type::none; + source_type type = source_type::constant; i16 index = 0; // The index of the next double to read in current chunk. std::array chunk_id; // Current chunk. Use when restore is apply. @@ -609,7 +756,7 @@ class source { buffer = std::span(); id = 0u; - type = source_type::none; + type = source_type::constant; index = 0; std::fill_n(chunk_id.data(), chunk_id.size(), 0); } @@ -644,6 +791,9 @@ class external_source random_source, }; + mr_allocator alloc; + freelist_memory_resource shared; + data_array constant_sources; data_array @@ -653,6 +803,27 @@ class external_source data_array random_sources; + external_source(const external_source_memory_requirement& init) noexcept + : external_source(get_malloc_memory_resource(), init) + {} + + external_source(memory_resource* mem, + const external_source_memory_requirement& init) noexcept + : alloc(mem) + , constant_sources(&shared) + , binary_file_sources(&shared) + , text_file_sources(&shared) + , random_sources(&shared) + { + realloc(init); + } + + /** Destroy then allocate memory according to the @c init parameter .*/ + void realloc(const external_source_memory_requirement& init) noexcept; + + //! Call `clear()` and release memory. + void destroy() noexcept; + u64 seed[2] = { 0xdeadbeef12345678U, 0xdeadbeef12345678U }; //! Call the @c init function for all sources (@c constant_source, @c @@ -670,53 +841,12 @@ class external_source //! Call the @c data_array::clear() function for all sources. void clear() noexcept; - //! Call `clear()` and release memory. - void destroy() noexcept; - //! An example of error handlers to catch all error from the external //! source class and friend (@c binary_file_source, @c text_file_source, //! @c random_source and @c constant_source). // constexpr auto make_error_handlers() const noexcept; }; -//! Assign a value constrained by the template parameters. -//! -//! @code -//! static int v = 0; -//! if (ImGui::InputInt("test", &v)) { -//! f(v); -//! } -//! -//! void f(constrained_value v) -//! { -//! assert(0 <= *v && *v <= 100); -//! } -//! @endcode -template -class constrained_value -{ -public: - using value_type = T; - -private: - static_assert(std::is_trivial_v, - "T must be a trivial type in ratio_parameter"); - static_assert(Lower < Upper); - - T m_value; - -public: - constexpr constrained_value(const T value_) noexcept - : m_value(value_ < Lower ? Lower - : value_ < Upper ? value_ - : Upper) - {} - - constexpr explicit operator T() const noexcept { return m_value; } - constexpr value_type operator*() const noexcept { return m_value; } - constexpr value_type value() const noexcept { return m_value; } -}; - //! To be used in model declaration to initialize a source instance //! according to the type of the external source. inline status initialize_source(simulation& sim, source& src) noexcept; @@ -1027,109 +1157,6 @@ class scheduller int ssize() const noexcept; }; -//! Helps to calculate the sizes of the `vectors` and `data_array` from a -//! number of bytes. Compute for each `source` the same number and adjust -//! the `max_client` variables for both random and binary source. -struct external_source_memory_requirement { - int constant_nb = 4; - int text_file_nb = 4; - int binary_file_nb = 4; - int random_nb = 4; - int binary_file_max_client = 8; - int random_max_client = 8; - - //! Assign a default size for each external source subobject. - constexpr external_source_memory_requirement() noexcept = default; - - //! Compute the size of each source. - //! - //! @param bytes The numbers of bytes availables. - //! @param source_client_ratio A integer in the range `[0..100]` defines - //! the ratio between `source` and `max_client` variables. `50` mean 50% - //! sources and 50% max_clients, `0` means no source, `100` means no - //! max-client. - constexpr external_source_memory_requirement( - const std::size_t bytes, - const constrained_value source_client_ratio) noexcept; - - constexpr bool valid() const; - - constexpr size_t in_bytes() const noexcept; -}; - -//! Helps to calculate the sizes of the `vectors` and `data_array` from a -//! number of bytes. -class simulation_memory_requirement -{ -public: - constexpr static inline auto default_simulation_model_number = 256u; - constexpr static inline auto default_simulation_connection_number = 1024u; - - std::size_t connections_b = 0; - std::size_t dated_messages_b = 0; - std::size_t external_source_b = 0; - std::size_t simulation_b = 0; - std::size_t global_b = 0; - - int model_nb = 0; - int hsm_nb = 0; - - external_source_memory_requirement srcs; - - /** Computes the required memory to build the simulation that can run at - * least @c model_nb models and @c connection_nb connections. - * - * @param bytes The numbers of bytes availables. - * @param external_source Percentage of memory to use in external source. - * @param source_client_ratio - * @param connections Percentage of simulation memory dedicated to - * connections. - * @param dated_messages Percentage of siulation memory dedicated to fifo, - * lifo history. - */ - constexpr simulation_memory_requirement( - const std::size_t model_nb, - const std::size_t connection_nb, - const constrained_value connections = 5, - const constrained_value hsms = 1, - const constrained_value dated_messages = 5, - const constrained_value external_source = 10, - const constrained_value source_client = 50) noexcept; - - /** Computes the required memory to build the simulation and splits - * available memory in memory resource, free list and container. - * - * @param bytes The numbers of bytes availables. - * @param external_source Percentage of memory to use in external source. - * @param source_client_ratio - * @param connections Percentage of simulation memory dedicated to - * connections. - * @param dated_messages Percentage of siulation memory dedicated to fifo, - * lifo history. - */ - constexpr simulation_memory_requirement( - const std::size_t bytes, - const constrained_value connections = 5, - const constrained_value hsms = 10, - const constrained_value dated_messages = 5, - const constrained_value external_source = 10, - const constrained_value source_client = 50) noexcept; - - constexpr bool valid() const noexcept; - - //! Compute an estimate to store a model in simulation memory. - constexpr static size_t estimate_model() noexcept; - -private: - constexpr void compute_buffer_size( - const std::size_t bytes, - const constrained_value connections, - const constrained_value hsms, - const constrained_value dated_messages, - const constrained_value external_source, - const constrained_value source_client) noexcept; -}; - class simulation { public: @@ -5484,10 +5511,7 @@ inline simulation::simulation( , messages(&shared) , dated_messages(&shared) , sched(&shared) - , srcs{ .constant_sources{ &external_source_alloc }, - .binary_file_sources{ &external_source_alloc }, - .text_file_sources{ &external_source_alloc }, - .random_sources{ &external_source_alloc } } + , srcs{ mem, init.srcs } { realloc(init); } @@ -6547,6 +6571,36 @@ inline constexpr external_source_memory_requirement:: random_max_client = client; } +inline constexpr external_source_memory_requirement:: + external_source_memory_requirement( + const std::size_t constant, + const std::size_t text_f, + const std::size_t bin_f, + const std::size_t random, + const std::size_t bin_f_max_client, + const std::size_t random_max_client) noexcept + : external_source_memory_requirement( + sizeof(data_array::internal_value_type) * + constant + + sizeof(data_array::internal_value_type) * + text_f + + (sizeof(data_array::internal_value_type) + + (sizeof(chunk_type) + sizeof(u64)) * bin_f_max_client) * + bin_f + + (sizeof(data_array::internal_value_type) + + (sizeof(chunk_type) + sizeof(u64) * 4) * random_max_client) * + random, + 10) +{} + inline constexpr bool external_source_memory_requirement::valid() const { return constant_nb >= 0 and text_file_nb >= 0 and binary_file_nb >= 0 and diff --git a/lib/src/external_source.cpp b/lib/src/external_source.cpp index acfc000b..4f1c7709 100644 --- a/lib/src/external_source.cpp +++ b/lib/src/external_source.cpp @@ -754,9 +754,6 @@ status external_source::dispatch(source& src, const source::operation_type op) noexcept { switch (src.type) { - case source::source_type::none: - return success(); - case source::source_type::binary_file: { const auto src_id = enum_cast(src.id); if (auto* bin_src = binary_file_sources.try_to_get(src_id); bin_src) @@ -811,6 +808,30 @@ void external_source::destroy() noexcept binary_file_sources.destroy(); text_file_sources.destroy(); random_sources.destroy(); + + shared.destroy(); +} + +void external_source::realloc( + const external_source_memory_requirement& init) noexcept +{ + debug::ensure(init.valid()); + destroy(); + + const auto size = init.in_bytes(); + shared.reset(alloc.allocate_bytes(size), size); + + if (init.constant_nb > 0) + constant_sources.reserve(init.constant_nb); + + if (init.binary_file_nb > 0) + binary_file_sources.reserve(init.binary_file_nb); + + if (init.text_file_nb > 0) + text_file_sources.reserve(init.text_file_nb); + + if (init.random_nb > 0) + random_sources.reserve(init.random_nb); } } // namespace irt diff --git a/lib/src/modeling.cpp b/lib/src/modeling.cpp index d6582fb3..ef81ad2d 100644 --- a/lib/src/modeling.cpp +++ b/lib/src/modeling.cpp @@ -18,7 +18,8 @@ namespace irt { modeling::modeling() noexcept - : log_entries{ 16 } + : srcs(external_source_memory_requirement(16, 16, 16, 16, 256, 256)) + , log_entries{ 16 } {} status modeling::init(modeling_initializer& p) noexcept @@ -68,6 +69,11 @@ status modeling::init(modeling_initializer& p) noexcept component_colors.resize(components.capacity()); + srcs.constant_sources.reserve(8); + srcs.binary_file_sources.reserve(8); + srcs.text_file_sources.reserve(6); + srcs.random_sources.reserve(16); + return success(); } diff --git a/lib/src/parameter.cpp b/lib/src/parameter.cpp index d17fde71..9d771f9f 100644 --- a/lib/src/parameter.cpp +++ b/lib/src/parameter.cpp @@ -70,7 +70,7 @@ static void model_init(const parameter& param, dynamic_queue& dyn) noexcept dyn.default_source_ta.type = (0 <= param.integers[2] && param.integers[2] < 4) ? enum_cast(param.integers[2]) - : source::source_type::none; + : source::source_type::constant; } static void parameter_init(parameter& param, const dynamic_queue& dyn) noexcept @@ -88,7 +88,7 @@ static void model_init(const parameter& param, priority_queue& dyn) noexcept dyn.default_source_ta.type = (0 <= param.integers[2] && param.integers[2] < 4) ? enum_cast(param.integers[2]) - : source::source_type::none; + : source::source_type::constant; } static void parameter_init(parameter& param, const priority_queue& dyn) noexcept @@ -108,7 +108,7 @@ static void model_init(const parameter& param, generator& dyn) noexcept dyn.default_source_ta.type = (0 <= param.integers[2] && param.integers[2] < 4) ? enum_cast(param.integers[2]) - : source::source_type::none; + : source::source_type::constant; } if (dyn.flags[generator::option::value_use_source]) { @@ -117,7 +117,7 @@ static void model_init(const parameter& param, generator& dyn) noexcept dyn.default_source_value.type = (0 <= param.integers[4] && param.integers[4] < 4) ? enum_cast(param.integers[4]) - : source::source_type::none; + : source::source_type::constant; } } diff --git a/lib/src/project.cpp b/lib/src/project.cpp index 9e3bacd2..07247c62 100644 --- a/lib/src/project.cpp +++ b/lib/src/project.cpp @@ -484,8 +484,6 @@ static status simulation_copy_source(simulation_copy& sc, source& dst) noexcept { switch (enum_cast(type)) { - case source::source_type::none: - break; case source::source_type::constant: if (auto* ret = sc.cache.constants.get(id); ret) { dst.id = ordinal(*ret);