From 51eac85360c1930afaa8f32e19dccf94e5428670 Mon Sep 17 00:00:00 2001 From: "anthony@rabine.fr" Date: Wed, 23 Apr 2025 00:01:09 +0200 Subject: [PATCH] make story editor build --- .../interfaces/i_story_manager.h | 2 +- core/story-manager/lib/variable.h | 39 +++++++ core/story-manager/src/media_node.h | 3 +- core/story-manager/src/nodes/base_node.h | 1 - core/story-manager/src/nodes/branch_node.cpp | 27 ----- core/story-manager/src/nodes/branch_node.h | 1 - core/story-manager/src/nodes/compare_node.cpp | 53 --------- core/story-manager/src/nodes/compare_node.h | 1 - .../story-manager/src/nodes/function_node.cpp | 5 - core/story-manager/src/nodes/function_node.h | 1 - .../story-manager/src/nodes/variable_node.cpp | 5 +- core/story-manager/src/nodes/variable_node.h | 1 - core/story-manager/src/story_page.h | 8 +- core/story-manager/src/story_project.cpp | 14 ++- core/story-manager/src/story_project.h | 4 +- story-editor/CMakeLists.txt | 21 ++-- story-editor/imgui.ini | 105 ++++++++++++++++++ .../src/node_editor/function_node_widget.h | 2 +- .../src/node_editor/node_editor_window.cpp | 2 +- .../src/node_editor/variable_node_widget.cpp | 7 +- story-editor/src/windows/main_window.cpp | 2 +- story-editor/src/windows/main_window.h | 2 +- story-editor/src/windows/variables_window.cpp | 31 +++--- 23 files changed, 201 insertions(+), 136 deletions(-) create mode 100644 story-editor/imgui.ini diff --git a/core/story-manager/interfaces/i_story_manager.h b/core/story-manager/interfaces/i_story_manager.h index eef9c37..7caae03 100644 --- a/core/story-manager/interfaces/i_story_manager.h +++ b/core/story-manager/interfaces/i_story_manager.h @@ -56,7 +56,7 @@ public: virtual uint32_t GetRegister(int reg) = 0; // Variables management - virtual void ScanVariable(const std::function& operation) = 0; + virtual void ScanVariable(const std::function element)>& operation) = 0; virtual void AddVariable() = 0; virtual void DeleteVariable(int i) = 0; diff --git a/core/story-manager/lib/variable.h b/core/story-manager/lib/variable.h index 6013b70..fe46367 100644 --- a/core/story-manager/lib/variable.h +++ b/core/story-manager/lib/variable.h @@ -26,6 +26,8 @@ public: ALL_CHARSETS = CHARSET_ALPHABET_LOWER | CHARSET_ALPHABET_UPPER |CHARSET_NUMBERS | CHARSET_SIGNS }; + static const int NameMaxSize = 32; // Max size for the variable name + Variable() { m_uuid = Uuid().String(); m_label = Variable::GenerateRandomString(10, Variable::CHARSET_ALPHABET_LOWER | Variable::CHARSET_ALPHABET_UPPER ); @@ -99,6 +101,10 @@ public: m_valueType = ValueType::BOOL; } + void SetScalePower(int scalePower) { + m_scalePower = scalePower; + } + // Getters std::string GetVariableName() const { return m_variableName; @@ -125,12 +131,45 @@ public: } } + std::string GetStringValue() const { + return GetValue(); + } + + int GetIntegerValue() const { + return GetValue(); + } + + float GetFloatValue() const { + return GetValue(); + } + + bool GetBoolValue() const { + return GetValue(); + } + using VariableValue = std::variant; std::string GetUuid() const { return m_uuid; } + bool IsString() const { + return m_valueType == ValueType::STRING; + } + bool IsInteger() const { + return m_valueType == ValueType::INTEGER; + } + bool IsFloat() const { + return m_valueType == ValueType::FLOAT; + } + bool IsBool() const { + return m_valueType == ValueType::BOOL; + } + + int GetScalePower() const { + return m_scalePower; + } + static std::string GenerateRandomString(size_t length, uint32_t flags) { std::string charset = ""; diff --git a/core/story-manager/src/media_node.h b/core/story-manager/src/media_node.h index 39c05bf..f016896 100644 --- a/core/story-manager/src/media_node.h +++ b/core/story-manager/src/media_node.h @@ -12,8 +12,7 @@ public: MediaNode(const std::string &type); virtual void Initialize() override; - virtual std::string Build(IStoryPage &page, const StoryOptions &options, int nb_out_conns) override; - virtual std::string GenerateConstants(IStoryPage &page, IStoryProject &project, int nb_out_conns) override; + void SetImage(const std::string &image); std::string_view GetImage() const; diff --git a/core/story-manager/src/nodes/base_node.h b/core/story-manager/src/nodes/base_node.h index 46fc718..1bde624 100644 --- a/core/story-manager/src/nodes/base_node.h +++ b/core/story-manager/src/nodes/base_node.h @@ -69,7 +69,6 @@ public: static std::string GetEntryLabel(const std::string &id); virtual void Initialize() = 0; - virtual std::string Build(IStoryPage &page, const StoryOptions &options, int nb_out_conns) = 0; void SetPosition(float x, float y); diff --git a/core/story-manager/src/nodes/branch_node.cpp b/core/story-manager/src/nodes/branch_node.cpp index c2c84a5..4a3e42a 100644 --- a/core/story-manager/src/nodes/branch_node.cpp +++ b/core/story-manager/src/nodes/branch_node.cpp @@ -16,30 +16,3 @@ void BranchNode::Initialize() } - - -std::string BranchNode::Build(IStoryPage &page, const StoryOptions &options, int nb_out_conns) -{ - std::stringstream ss; - - std::list> conns; - page.GetNodeConnections(conns, GetId()); - int i = 0; - std::list>::iterator c = conns.begin(); - - if (conns.size() == 2) - { - ss << R"(; ---------------------------- )" - << GetTitle() - << " Type: Branch" - << "\n"; - - ss << "eq r0, r0, r1\n" - << "skipz r0\n" - << "jump " << BaseNode::GetEntryLabel((*c)->inNodeId); - ++c; - ss << "jump " << BaseNode::GetEntryLabel((*c)->inNodeId); - } - return ss.str(); -} - diff --git a/core/story-manager/src/nodes/branch_node.h b/core/story-manager/src/nodes/branch_node.h index a79cef3..f43b46c 100644 --- a/core/story-manager/src/nodes/branch_node.h +++ b/core/story-manager/src/nodes/branch_node.h @@ -12,7 +12,6 @@ public: BranchNode(const std::string &type); virtual void Initialize() override; - virtual std::string Build(IStoryPage &page, const StoryOptions &options, int nb_out_conns) override; private: }; diff --git a/core/story-manager/src/nodes/compare_node.cpp b/core/story-manager/src/nodes/compare_node.cpp index edf0cc8..9d9bdd6 100644 --- a/core/story-manager/src/nodes/compare_node.cpp +++ b/core/story-manager/src/nodes/compare_node.cpp @@ -16,56 +16,3 @@ void CompareNode::Initialize() } - - -std::string CompareNode::Build(IStoryPage &page, const StoryOptions &options, int nb_out_conns) -{ - std::stringstream ss; - - std::list> conns; - page.GetNodeConnections(conns, GetId()); - int i = 0; - std::list>::iterator c = conns.begin(); - -/* - -; Déclaration des variables en RAM -$var1 DV32 1 ; Première variable à comparer -$var2 DV32 1 ; Deuxième variable à comparer - -; Code principal -.compare_ge: - ; Charger les valeurs des variables dans les registres - lcons r1, $var1 - load r1, @r1, 4 ; Charger 4 bytes (32 bits) de var1 dans r1 - lcons r2, $var2 - load r2, @r2, 4 ; Charger 4 bytes (32 bits) de var2 dans r2 - - ; Comparer r1 >= r2 - gt r3, r1, r2 ; r3 = 1 si r1 > r2, sinon 0 - eq r4, r1, r2 ; r4 = 1 si r1 == r2, sinon 0 - or r0, r3, r4 ; r0 = 1 si r1 > r2 OU r1 == r2, sinon 0 - - ret - - - - */ - - - if (conns.size() == 2) - { - ss << R"(; ---------------------------- )" - << GetTitle() - << " Type: Branch" - << "\n"; - - ss << "eq r0, r0, r1\n" - << "skipz r0\n" - << "jump " << BaseNode::GetEntryLabel((*c)->inNodeId); - ++c; - ss << "jump " << BaseNode::GetEntryLabel((*c)->inNodeId); - } - return ss.str(); -} - diff --git a/core/story-manager/src/nodes/compare_node.h b/core/story-manager/src/nodes/compare_node.h index 0fcee4b..1624176 100644 --- a/core/story-manager/src/nodes/compare_node.h +++ b/core/story-manager/src/nodes/compare_node.h @@ -12,7 +12,6 @@ public: CompareNode(const std::string &type); virtual void Initialize() override; - virtual std::string Build(IStoryPage &page, const StoryOptions &options, int nb_out_conns) override; private: diff --git a/core/story-manager/src/nodes/function_node.cpp b/core/story-manager/src/nodes/function_node.cpp index a3b0d78..570aa37 100644 --- a/core/story-manager/src/nodes/function_node.cpp +++ b/core/story-manager/src/nodes/function_node.cpp @@ -27,8 +27,3 @@ void FunctionNode::Initialize() // m_sound = j["sound"].get(); } -std::string FunctionNode::Build(IStoryPage &page, const StoryOptions &options, int nb_out_conns) -{ - return std::string(); -} - diff --git a/core/story-manager/src/nodes/function_node.h b/core/story-manager/src/nodes/function_node.h index 25991d6..485cb28 100644 --- a/core/story-manager/src/nodes/function_node.h +++ b/core/story-manager/src/nodes/function_node.h @@ -12,7 +12,6 @@ public: FunctionNode(const std::string &type); virtual void Initialize() override; - virtual std::string Build(IStoryPage &page, const StoryOptions &options, int nb_out_conns) override; void StoreInternalData(); diff --git a/core/story-manager/src/nodes/variable_node.cpp b/core/story-manager/src/nodes/variable_node.cpp index 9e5dd5e..62a97f2 100644 --- a/core/story-manager/src/nodes/variable_node.cpp +++ b/core/story-manager/src/nodes/variable_node.cpp @@ -27,8 +27,5 @@ void VariableNode::Initialize() // m_sound = j["sound"].get(); } -std::string VariableNode::Build(IStoryPage &page, const StoryOptions &options, int nb_out_conns) -{ - return std::string(); -} + diff --git a/core/story-manager/src/nodes/variable_node.h b/core/story-manager/src/nodes/variable_node.h index 92706cd..6a91668 100644 --- a/core/story-manager/src/nodes/variable_node.h +++ b/core/story-manager/src/nodes/variable_node.h @@ -15,7 +15,6 @@ public: VariableNode(const std::string &type = "variable-node"); virtual void Initialize() override; - virtual std::string Build(IStoryPage &page, const StoryOptions &options, int nb_out_conns) override; void StoreInternalData(); diff --git a/core/story-manager/src/story_page.h b/core/story-manager/src/story_page.h index 9307d43..4a1a884 100644 --- a/core/story-manager/src/story_page.h +++ b/core/story-manager/src/story_page.h @@ -58,10 +58,10 @@ public: // code << n->GenerateConstants(*this, project, OutputsCount(n->GetId())) << "\n"; // } - for (const auto & n : m_nodes) - { - code << n->Build(*this, project.GetOptions(), OutputsCount(n->GetId())) << "\n"; - } + // for (const auto & n : m_nodes) + // { + // code << n->Build(*this, project.GetOptions(), OutputsCount(n->GetId())) << "\n"; + // } } virtual void GetNodeConnections(std::list> &c, const std::string &nodeId) override diff --git a/core/story-manager/src/story_project.cpp b/core/story-manager/src/story_project.cpp index d829e47..f016f69 100644 --- a/core/story-manager/src/story_project.cpp +++ b/core/story-manager/src/story_project.cpp @@ -7,7 +7,7 @@ #include "story_project.h" #include "json.hpp" -#include "media_node.h" +// #include "media_node.h" #include "function_node.h" #include "variable_node.h" #include "sys_lib.h" @@ -15,7 +15,7 @@ StoryProject::StoryProject(ILogger &log) : m_log(log) { - registerNode("media-node"); + // registerNode("media-node"); registerNode("function-node"); registerNode("variable-node"); } @@ -223,7 +223,7 @@ std::pair>::iterator, std::list>::iterator, std::list>::iterator>(); } -void StoryProject::ScanVariable(const std::function& operation) +void StoryProject::ScanVariable(const std::function element)>& operation) { for (auto &v : m_variables) { @@ -233,7 +233,13 @@ void StoryProject::ScanVariable(const std::function& op void StoryProject::AddVariable() { - m_variables.push_back(Variable("var_" + std::to_string(m_variables.size()), "int32_t", 0, 8)); + auto v = std::make_shared("var_" + std::to_string(m_variables.size())); + + v->SetValue(0); + v->SetValueType(Variable::ValueType::INTEGER); + v->SetConstant(false); + + m_variables.push_back(v); } void StoryProject::DeleteVariable(int i) diff --git a/core/story-manager/src/story_project.h b/core/story-manager/src/story_project.h index d8790b7..d8c5b52 100644 --- a/core/story-manager/src/story_project.h +++ b/core/story-manager/src/story_project.h @@ -103,7 +103,7 @@ public: std::pair>::iterator, std::list>::iterator> Links(const std::string_view &page_uuid); - void ScanVariable(const std::function& operation); + void ScanVariable(const std::function element)>& operation); void AddVariable(); void DeleteVariable(int i); @@ -134,7 +134,7 @@ private: std::list> m_pages; - std::vector m_variables; + std::vector> m_variables; StoryOptions m_storyOptions; diff --git a/story-editor/CMakeLists.txt b/story-editor/CMakeLists.txt index d996b8e..918a2e7 100644 --- a/story-editor/CMakeLists.txt +++ b/story-editor/CMakeLists.txt @@ -130,7 +130,7 @@ set(SRCS src/windows/cpu_window.cpp src/windows/variables_window.cpp - src/node_editor/media_node_widget.cpp + # src/node_editor/media_node_widget.cpp src/node_editor/base_node_widget.cpp src/node_editor/node_editor_window.cpp src/node_editor/function_node_widget.cpp @@ -168,16 +168,17 @@ set(SRCS # Core engine files - ../core/story-manager/src/compiler.cpp ../core/story-manager/src/story_project.cpp ../core/story-manager/src/story_page.cpp - ../core/story-manager/src/base_node.cpp - ../core/story-manager/src/media_node.cpp - ../core/story-manager/src/compare_node.cpp - ../core/story-manager/src/branch_node.cpp - ../core/story-manager/src/variable_node.cpp - ../core/story-manager/src/function_node.cpp - ../core/story-manager/src/connection.cpp + + + ../core/story-manager/src/nodes/base_node.cpp + ../core/story-manager/src/nodes/compare_node.cpp + ../core/story-manager/src/nodes/branch_node.cpp + ../core/story-manager/src/nodes/variable_node.cpp + ../core/story-manager/src/nodes/function_node.cpp + ../core/story-manager/src/nodes/connection.cpp + ../core/story-manager/lib/sys_lib.cpp ../core/story-manager/lib/resource.cpp @@ -222,6 +223,8 @@ target_include_directories(${STORY_EDITOR_PROJECT} PUBLIC ../core/chip32 ../shared ../core/story-manager/src + ../core/story-manager/src/nodes + ../core/story-manager/src/compiler ../core/story-manager/lib ../core/story-manager/interfaces ) diff --git a/story-editor/imgui.ini b/story-editor/imgui.ini new file mode 100644 index 0000000..1bac5e9 --- /dev/null +++ b/story-editor/imgui.ini @@ -0,0 +1,105 @@ +[Window][WindowOverViewport_11111111] +Pos=60,26 +Size=1220,694 +Collapsed=0 + +[Window][Debug##Default] +Pos=60,60 +Size=400,400 +Collapsed=0 + +[Window][Library Manager] +Pos=672,26 +Size=608,694 +Collapsed=0 +DockId=0x00000002,0 + +[Window][Console] +Pos=386,659 +Size=1152,344 +Collapsed=0 + +[Window][Emulator] +Pos=269,26 +Size=401,694 +Collapsed=0 +DockId=0x00000005,1 + +[Window][Code viewer] +Pos=269,26 +Size=401,694 +Collapsed=0 +DockId=0x00000005,0 + +[Window][Resources] +Pos=672,26 +Size=608,694 +Collapsed=0 +DockId=0x00000002,1 + +[Window][Node editor] +Pos=96,129 +Size=394,407 +Collapsed=0 + +[Window][TOOLBAR] +Pos=96,105 +Size=79,42 +Collapsed=0 + +[Window][Variables] +Pos=199,187 +Size=121,72 +Collapsed=0 + +[Window][CPU] +Pos=515,59 +Size=626,744 +Collapsed=0 + +[Window][RAM view] +Pos=378,79 +Size=738,442 +Collapsed=0 + +[Window][Properties] +Pos=754,344 +Size=626,744 +Collapsed=0 + +[Window][ToolBar] +Pos=0,26 +Size=60,694 +Collapsed=0 + +[Window][QuitConfirm] +Pos=479,312 +Size=321,96 +Collapsed=0 + +[Table][0x7728942D,5] +RefScale=20 +Column 0 Width=44 Sort=0v +Column 1 Width=72 +Column 2 Width=104 +Column 3 Width=54 +Column 4 Width=75 + +[Table][0x69D69F59,2] +RefScale=20 +Column 0 Width=22 Sort=0v +Column 1 Width=68 + +[Table][0x30BF8F98,3] +RefScale=20 +Column 0 Width=259 Sort=0v +Column 1 Width=88 +Column 2 Width=124 + +[Docking][Data] +DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=60,26 Size=1220,694 Split=X + DockNode ID=0x00000001 Parent=0x08BD597D SizeRef=610,694 Split=X + DockNode ID=0x00000004 Parent=0x00000001 SizeRef=397,600 CentralNode=1 Selected=0x63869CAF + DockNode ID=0x00000005 Parent=0x00000001 SizeRef=401,600 Selected=0x4B07C626 + DockNode ID=0x00000002 Parent=0x08BD597D SizeRef=608,694 Selected=0x30401527 + diff --git a/story-editor/src/node_editor/function_node_widget.h b/story-editor/src/node_editor/function_node_widget.h index cfc37aa..fd15456 100644 --- a/story-editor/src/node_editor/function_node_widget.h +++ b/story-editor/src/node_editor/function_node_widget.h @@ -10,7 +10,7 @@ #include "i_story_project.h" #include "gui.h" #include -#include "media_node.h" + class FunctionNodeWidget : public BaseNodeWidget { diff --git a/story-editor/src/node_editor/node_editor_window.cpp b/story-editor/src/node_editor/node_editor_window.cpp index 92b6244..3a3cc6e 100644 --- a/story-editor/src/node_editor/node_editor_window.cpp +++ b/story-editor/src/node_editor/node_editor_window.cpp @@ -28,7 +28,7 @@ NodeEditorWindow::NodeEditorWindow(IStoryManager &manager) , m_manager(manager) { - registerNode("media-node"); + // registerNode("media-node"); registerNode("function-node"); registerNode("variable-node"); } diff --git a/story-editor/src/node_editor/variable_node_widget.cpp b/story-editor/src/node_editor/variable_node_widget.cpp index b41acae..2fdf13f 100644 --- a/story-editor/src/node_editor/variable_node_widget.cpp +++ b/story-editor/src/node_editor/variable_node_widget.cpp @@ -32,15 +32,16 @@ void VariableNodeWidget::DrawProperties() if (ImGui::BeginCombo("Variables list", m_selectedVariable.c_str(), flags)) { int i = 0; - m_manager.ScanVariable([&i, this] (Variable &var) { + m_manager.ScanVariable([&i, this] (std::shared_ptr var) { // ImGui::PushID(static_cast(i)); // Assure l'unicité des widgets const bool is_selected = (m_selectedIndex == i); - if (ImGui::Selectable(var.name.c_str(), is_selected)) + std::string l = var->GetVariableName(); + if (ImGui::Selectable(l.c_str(), is_selected)) { m_selectedIndex = i; - m_selectedVariable = var.name; + m_selectedVariable = l; } // Set the initial focus when opening the combo (scrolling + keyboard navigation focus) diff --git a/story-editor/src/windows/main_window.cpp b/story-editor/src/windows/main_window.cpp index ec3e340..07ff46a 100644 --- a/story-editor/src/windows/main_window.cpp +++ b/story-editor/src/windows/main_window.cpp @@ -1096,7 +1096,7 @@ uint32_t MainWindow::GetRegister(int reg) return regVal; } -void MainWindow::ScanVariable(const std::function& operation) +void MainWindow::ScanVariable(const std::function element)>& operation) { if (m_story) { diff --git a/story-editor/src/windows/main_window.h b/story-editor/src/windows/main_window.h index adee0d9..5511683 100644 --- a/story-editor/src/windows/main_window.h +++ b/story-editor/src/windows/main_window.h @@ -153,7 +153,7 @@ private: virtual uint32_t GetRegister(int reg) override; // Variable - virtual void ScanVariable(const std::function& operation) override; + virtual void ScanVariable(const std::function element)>& operation) override; virtual void AddVariable() override; virtual void DeleteVariable(int i); diff --git a/story-editor/src/windows/variables_window.cpp b/story-editor/src/windows/variables_window.cpp index 47512e3..b67cd2c 100644 --- a/story-editor/src/windows/variables_window.cpp +++ b/story-editor/src/windows/variables_window.cpp @@ -42,47 +42,52 @@ void VariablesWindow::ShowRAMEditor() ImGui::Separator(); int i = 0; - m_story.ScanVariable([&i, this] (Variable &var) { + m_story.ScanVariable([&i, this] (std::shared_ptr var) { ImGui::PushID(static_cast(i)); // Assure l'unicité des widgets - if (ImGui::TreeNode((var.name + "###variable").c_str())) + std::string l = var->GetVariableName(); + if (ImGui::TreeNode((l + "###variable").c_str())) { // Modifier le nom de la variable static char buffer[Variable::NameMaxSize]; - std::strncpy(buffer, var.name.c_str(), sizeof(buffer)); + std::strncpy(buffer, l.c_str(), sizeof(buffer)); buffer[sizeof(buffer) - 1] = '\0'; // Assure la terminaison if (ImGui::InputText("Name", buffer, sizeof(buffer))) { - var.name = buffer; + var->SetVariableName(buffer); } // Choisir le type de la variable const char* types[] = {"Integer", "String"}; - static int selectedType = (var.type == "Integer") ? 0 : 1; + static int selectedType = var->IsInteger() ? 0 : 1; // 0 for Integer, 1 for String if (ImGui::Combo("Type", &selectedType, types, IM_ARRAYSIZE(types))) { - var.type = types[selectedType]; + var->SetValueType(selectedType == 0 ? Variable::ValueType::INTEGER : Variable::ValueType::STRING); } - if (var.type == "Integer") + if (var->IsInteger()) { // Modifier l'échelle - ImGui::InputInt("Scale Power (10^x)", &var.scalePower); + int scalePower = var->GetScalePower(); + if (ImGui::InputInt("Scale Power (10^x)", &scalePower)) + { + var->SetScalePower(scalePower); + } // Modifier la valeur entière - int intValue = static_cast(var.value); + int intValue = static_cast(var->GetIntegerValue()); if (ImGui::InputInt("Integer Value", &intValue)) { - var.value = static_cast(intValue); + var->SetIntegerValue(static_cast(intValue)); } // Afficher la valeur flottante calculée - float floatValue = ScaledToFloat(var.value, var.scalePower); + float floatValue = ScaledToFloat(var->GetIntegerValue(), var->GetScalePower()); ImGui::Text("Float Value: %.6f", floatValue); } else { - std::strncpy(buffer, var.valueText.c_str(), sizeof(buffer)); + std::strncpy(buffer, var->GetStringValue().c_str(), sizeof(buffer)); if (ImGui::InputText("Text value", buffer, sizeof(buffer))) { - var.valueText = buffer; + var->SetTextValue(buffer); } }