diff --git a/core/story-manager/src/compiler/assembly_generator.h b/core/story-manager/src/compiler/assembly_generator.h index f4a5234..407e230 100644 --- a/core/story-manager/src/compiler/assembly_generator.h +++ b/core/story-manager/src/compiler/assembly_generator.h @@ -29,25 +29,39 @@ public: struct GeneratorContext { std::string timestamp; - std::string username; + std::string compiler; bool debugOutput; bool optimizeCode; int stackSize; + std::vector> variables; - GeneratorContext(const std::string& ts = "2025-04-08 12:09:01", - const std::string& user = "anonymous", + GeneratorContext(std::vector> &v, + const std::string& ts = "2025-04-08 12:09:01", + const std::string& comp = "ost-v1", bool debug = true, bool optimize = true, - int stack = 1024) - : timestamp(ts) - , username(user) + int stack = 1024 + ) + : variables(v) + , compiler(comp) , debugOutput(debug) , optimizeCode(optimize) , stackSize(stack) + , timestamp(ts) {} + + // Find variable by uuid + std::shared_ptr FindVariableByUuid(const std::string& uuid) const { + for (const auto& var : variables) { + if (var->GetUuid() == uuid) { + return var; + } + } + return nullptr; + } }; - AssemblyGenerator(const GeneratorContext& context = GeneratorContext()) + AssemblyGenerator(const GeneratorContext& context) : m_context(context) { Reset(); @@ -56,9 +70,7 @@ public: void Reset() { m_assembly.str(""); m_labelCounter = 0; - m_variableAddresses.clear(); m_currentStackOffset = 0; - m_stringLiterals.clear(); m_depth = 0; m_currentSection = Section::NONE; } @@ -66,7 +78,7 @@ public: void GenerateHeader() { AddComment("Assembly generated by Visual Node Editor"); AddComment("Generation time: " + m_context.timestamp); - AddComment("Generated by: " + m_context.username); + AddComment("Generated by: " + m_context.compiler); AddComment("Optimization: " + m_context.optimizeCode ? "enabled" : "disabled"); } @@ -99,9 +111,9 @@ public: m_assembly << "\n\n"; } - void GenerateGlobalVariables(const std::vector> &variables) + void GenerateGlobalVariables() { - for (const auto& v : variables) { + for (const auto& v : m_context.variables) { GenerateVariable(v); } } @@ -129,31 +141,18 @@ protected: virtual void GenerateVariable(const std::shared_ptr v) = 0; - std::string AddStringLiteral(const std::string& text) - { - std::string label = "str_" + std::to_string(m_stringLiterals.size()); - m_stringLiterals.push_back(text); - return label; - } - std::string GenerateUniqueLabel(const std::string& prefix) { return prefix + "_" + std::to_string(m_labelCounter++); } - - -protected: GeneratorContext m_context; std::stringstream m_assembly; int m_labelCounter; - std::unordered_map m_variableAddresses; int m_currentStackOffset; - std::vector m_stringLiterals; int m_depth{0}; Section m_currentSection; - private: diff --git a/core/story-manager/src/compiler/assembly_generator_chip32.h b/core/story-manager/src/compiler/assembly_generator_chip32.h index 25a5be9..24509bf 100644 --- a/core/story-manager/src/compiler/assembly_generator_chip32.h +++ b/core/story-manager/src/compiler/assembly_generator_chip32.h @@ -6,7 +6,7 @@ class AssemblyGeneratorChip32 : public AssemblyGenerator { public: - AssemblyGeneratorChip32(const GeneratorContext& context = GeneratorContext()) + AssemblyGeneratorChip32(const GeneratorContext& context) : AssemblyGenerator(context) { @@ -117,8 +117,10 @@ private: { auto* varNode = inputNode->GetAs(); if (varNode) { - auto var = varNode->GetVariable(); + std::string varUuid = varNode->GetVariableUuid(); + // Find variable in the context + auto var = m_context.FindVariableByUuid(varUuid); if (var) { // Generate code to load the variable value @@ -230,18 +232,7 @@ private: m_assembly << "$" << v->GetLabel() << " DVB, " << (v->GetValue() ? "1" : "0") << " ; " << v->GetVariableName() << "\n"; } } -/* - void GenerateVariableNode(std::shared_ptr node) { - auto* varNode = node->GetAs(); - if (!varNode) return; - std::string varName = varNode->GetVariableName(); - - AddComment("Load variable: " + varName); - m_assembly << " mov eax, [" << m_variableAddresses[varName] << "]\n" - << " push eax\n"; - } -*/ }; diff --git a/core/story-manager/src/nodes/function_node.cpp b/core/story-manager/src/nodes/function_node.cpp index 570aa37..1c6c971 100644 --- a/core/story-manager/src/nodes/function_node.cpp +++ b/core/story-manager/src/nodes/function_node.cpp @@ -11,15 +11,6 @@ FunctionNode::FunctionNode(const std::string &type) SetInternalData(j); } -void FunctionNode::StoreInternalData() -{ - nlohmann::json j; - // j["image"] = m_image; - // j["sound"] = m_sound; - - SetInternalData(j); -} - void FunctionNode::Initialize() { nlohmann::json j = GetInternalData(); diff --git a/core/story-manager/src/nodes/function_node.h b/core/story-manager/src/nodes/function_node.h index 485cb28..6127a3b 100644 --- a/core/story-manager/src/nodes/function_node.h +++ b/core/story-manager/src/nodes/function_node.h @@ -13,8 +13,6 @@ public: virtual void Initialize() override; - void StoreInternalData(); - private: }; diff --git a/core/story-manager/src/nodes/print_node.cpp b/core/story-manager/src/nodes/print_node.cpp index 5b52978..ba1778b 100644 --- a/core/story-manager/src/nodes/print_node.cpp +++ b/core/story-manager/src/nodes/print_node.cpp @@ -9,14 +9,34 @@ PrintNode::PrintNode(const std::string &type) { // Create empty variable in memory auto v = std::make_shared(m_label); - v->SetTextValue(""); v->SetConstant(true); m_label = v->GetLabel(); m_variables[m_label] = v; -} + SetText(""); +} void PrintNode::Initialize() { - + nlohmann::json j = GetInternalData(); + m_variables.at(m_label)->SetTextValue(j["text"].get()); } + + +void PrintNode::SetText(const std::string &text) +{ + m_variables.at(m_label)->SetValue(text); + + SetInternalData({{"text", text}}); +} + +std::string PrintNode::GetLabel() const +{ + return m_label; +} + +std::string PrintNode::GetText() const +{ + return m_variables.at(m_label)->GetValue(); +} + diff --git a/core/story-manager/src/nodes/print_node.h b/core/story-manager/src/nodes/print_node.h index 66afa07..36df5e8 100644 --- a/core/story-manager/src/nodes/print_node.h +++ b/core/story-manager/src/nodes/print_node.h @@ -13,18 +13,9 @@ public: virtual void Initialize() override; - void SetText(const std::string &text) { - - m_variables.at(m_label)->SetValue(text); - } - - std::string GetLabel() const { - return m_label; - } - - std::string GetText() const { - return m_variables.at(m_label)->GetValue(); - } + void SetText(const std::string &text); + std::string GetLabel() const; + std::string GetText() const; private: std::string m_label; // Label for the string literal diff --git a/core/story-manager/src/nodes/syscall_node.cpp b/core/story-manager/src/nodes/syscall_node.cpp new file mode 100644 index 0000000..c94f1f7 --- /dev/null +++ b/core/story-manager/src/nodes/syscall_node.cpp @@ -0,0 +1,22 @@ +#include "syscall_node.h" +#include "story_project.h" +#include "connection.h" +#include "sys_lib.h" + + +SyscallNode::SyscallNode(const std::string &type) + : BaseNode(type, "Syscall Node") +{ + nlohmann::json j{ {"uuid", ""} }; + SetInternalData(j); +} + +void SyscallNode::Initialize() +{ + nlohmann::json j = GetInternalData(); + + // m_variableUuid = j["uuid"].get(); +} + + + diff --git a/core/story-manager/src/nodes/syscall_node.h b/core/story-manager/src/nodes/syscall_node.h new file mode 100644 index 0000000..7d6e1ae --- /dev/null +++ b/core/story-manager/src/nodes/syscall_node.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +#include "variable.h" +#include "i_story_manager.h" +#include "base_node.h" +#include "i_script_node.h" +#include "i_story_project.h" + +class SyscallNode : public BaseNode +{ +public: + + SyscallNode(const std::string &type = "syscall-node"); + + virtual void Initialize() override; + +private: + + +}; + diff --git a/core/story-manager/src/nodes/variable_node.cpp b/core/story-manager/src/nodes/variable_node.cpp index 62a97f2..e047cd8 100644 --- a/core/story-manager/src/nodes/variable_node.cpp +++ b/core/story-manager/src/nodes/variable_node.cpp @@ -7,24 +7,29 @@ VariableNode::VariableNode(const std::string &type) : BaseNode(type, "Variable Node") { - nlohmann::json j{ {"name", "i"}, {"value", 3} }; - SetInternalData(j); -} - -void VariableNode::StoreInternalData() -{ - nlohmann::json j; - // j["image"] = m_image; - // j["sound"] = m_sound; - + nlohmann::json j{ {"uuid", ""} }; SetInternalData(j); } void VariableNode::Initialize() { nlohmann::json j = GetInternalData(); - // m_image = j["image"].get(); - // m_sound = j["sound"].get(); + + m_variableUuid = j["uuid"].get(); +} + +void VariableNode::SetVariableUuid(const std::string &uuid) +{ + m_variableUuid = uuid; + + nlohmann::json j; + j["uuid"] = m_variableUuid; + SetInternalData(j); +} + +std::string VariableNode::GetVariableUuid() const +{ + return m_variableUuid; } diff --git a/core/story-manager/src/nodes/variable_node.h b/core/story-manager/src/nodes/variable_node.h index 5945a52..60b6434 100644 --- a/core/story-manager/src/nodes/variable_node.h +++ b/core/story-manager/src/nodes/variable_node.h @@ -16,18 +16,12 @@ public: virtual void Initialize() override; - void StoreInternalData(); + void SetVariableUuid(const std::string &uuid); - void SetVariable(const std::shared_ptr v) { - m_variable = v; - } - - std::shared_ptr GetVariable() const { - return m_variable; - } + std::string GetVariableUuid() const; private: - std::shared_ptr m_variable; + std::string m_variableUuid; }; diff --git a/core/story-manager/src/story_project.cpp b/core/story-manager/src/story_project.cpp index fc4e9a7..ec01705 100644 --- a/core/story-manager/src/story_project.cpp +++ b/core/story-manager/src/story_project.cpp @@ -394,6 +394,7 @@ bool StoryProject::GenerateScript(std::string &codeStr) // Create generator context with current time and user AssemblyGenerator::GeneratorContext context( + m_variables, "2025-04-08 12:09:01", // Current UTC time "story-editor", // Current user true, // Enable debug output @@ -424,7 +425,7 @@ bool StoryProject::GenerateScript(std::string &codeStr) { p->BuildNodesVariables(generator); } - generator.GenerateGlobalVariables(m_variables); + generator.GenerateGlobalVariables(); generator.GenerateExit(); diff --git a/story-editor/imgui.ini b/story-editor/imgui.ini index 7e834c7..3b6e00f 100644 --- a/story-editor/imgui.ini +++ b/story-editor/imgui.ini @@ -9,67 +9,67 @@ Size=400,400 Collapsed=0 [Window][Library Manager] -Pos=900,26 -Size=380,322 +Pos=731,26 +Size=549,268 Collapsed=0 DockId=0x00000003,0 [Window][Console] -Pos=60,545 -Size=1220,175 +Pos=60,467 +Size=610,253 Collapsed=0 -DockId=0x00000008,0 +DockId=0x00000004,0 [Window][Emulator] -Pos=398,26 -Size=500,517 +Pos=731,26 +Size=549,268 Collapsed=0 -DockId=0x00000005,1 +DockId=0x00000003,5 [Window][Code viewer] -Pos=398,26 -Size=500,517 +Pos=731,26 +Size=549,268 Collapsed=0 -DockId=0x00000005,0 +DockId=0x00000003,4 [Window][Resources] -Pos=900,26 -Size=380,322 +Pos=731,26 +Size=549,268 Collapsed=0 DockId=0x00000003,1 [Window][Node editor] Pos=60,26 -Size=336,517 +Size=669,439 Collapsed=0 -DockId=0x00000004,0 +DockId=0x00000001,0 [Window][TOOLBAR] -Pos=92,208 +Pos=76,71 Size=79,42 Collapsed=0 [Window][Variables] -Pos=398,26 -Size=500,517 +Pos=672,467 +Size=608,253 Collapsed=0 -DockId=0x00000005,2 +DockId=0x00000005,0 [Window][CPU] -Pos=900,26 -Size=380,322 +Pos=731,26 +Size=549,268 Collapsed=0 DockId=0x00000003,2 [Window][RAM view] -Pos=900,26 -Size=380,322 +Pos=731,26 +Size=549,268 Collapsed=0 DockId=0x00000003,3 [Window][Properties] -Pos=900,350 -Size=380,193 +Pos=731,296 +Size=549,169 Collapsed=0 DockId=0x00000006,0 @@ -83,6 +83,11 @@ Pos=479,312 Size=321,96 Collapsed=0 +[Window][ProjectPropertiesPopup] +Pos=381,236 +Size=518,248 +Collapsed=0 + [Table][0x7728942D,5] RefScale=20 Column 0 Width=44 Sort=0v @@ -104,12 +109,12 @@ Column 2 Width=124 [Docking][Data] DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=60,26 Size=1220,694 Split=Y - DockNode ID=0x00000007 Parent=0x08BD597D SizeRef=1220,517 Split=X - DockNode ID=0x00000001 Parent=0x00000007 SizeRef=838,694 Split=X - DockNode ID=0x00000004 Parent=0x00000001 SizeRef=336,600 CentralNode=1 Selected=0xBB79A587 - DockNode ID=0x00000005 Parent=0x00000001 SizeRef=500,600 Selected=0x52EB28B5 - DockNode ID=0x00000002 Parent=0x00000007 SizeRef=380,694 Split=Y Selected=0xE5897A33 - DockNode ID=0x00000003 Parent=0x00000002 SizeRef=608,322 Selected=0x63869CAF - DockNode ID=0x00000006 Parent=0x00000002 SizeRef=608,193 Selected=0x8C72BEA8 - DockNode ID=0x00000008 Parent=0x08BD597D SizeRef=1220,175 Selected=0xEA83D666 + DockNode ID=0x00000007 Parent=0x08BD597D SizeRef=1220,439 Split=X + DockNode ID=0x00000001 Parent=0x00000007 SizeRef=669,694 CentralNode=1 Selected=0xBB79A587 + DockNode ID=0x00000002 Parent=0x00000007 SizeRef=549,694 Split=Y Selected=0x52EB28B5 + DockNode ID=0x00000003 Parent=0x00000002 SizeRef=718,268 Selected=0x63869CAF + DockNode ID=0x00000006 Parent=0x00000002 SizeRef=718,169 Selected=0x8C72BEA8 + DockNode ID=0x00000008 Parent=0x08BD597D SizeRef=1220,253 Split=X Selected=0xEA83D666 + DockNode ID=0x00000004 Parent=0x00000008 SizeRef=610,192 Selected=0xEA83D666 + DockNode ID=0x00000005 Parent=0x00000008 SizeRef=608,192 Selected=0x6DE9B20C diff --git a/story-editor/src/node_editor/variable_node_widget.cpp b/story-editor/src/node_editor/variable_node_widget.cpp index 9fb66db..adcc4f7 100644 --- a/story-editor/src/node_editor/variable_node_widget.cpp +++ b/story-editor/src/node_editor/variable_node_widget.cpp @@ -21,8 +21,16 @@ VariableNodeWidget::VariableNodeWidget(IStoryManager &manager, std::shared_ptrGetVariableUuid(); + + m_manager.ScanVariable([this] (std::shared_ptr var) { + if (var->GetUuid() == m_selectedVariableUuid) + { + m_selectedVariableName = var->GetVariableName(); + } + }); +} void VariableNodeWidget::DrawProperties() @@ -30,7 +38,7 @@ void VariableNodeWidget::DrawProperties() ImGui::AlignTextToFramePadding(); static ImGuiComboFlags flags = 0; - if (ImGui::BeginCombo("Variables list", m_selectedVariable.c_str(), flags)) + if (ImGui::BeginCombo("Variables list", m_selectedVariableName.c_str(), flags)) { int i = 0; m_manager.ScanVariable([&i, this] (std::shared_ptr var) { @@ -42,13 +50,15 @@ void VariableNodeWidget::DrawProperties() if (ImGui::Selectable(l.c_str(), is_selected)) { m_selectedIndex = i; - m_selectedVariable = l; - m_variableNode->SetVariable(var); + m_selectedVariableName = l; + m_variableNode->SetVariableUuid(var->GetUuid()); } // Set the initial focus when opening the combo (scrolling + keyboard navigation focus) if (is_selected) ImGui::SetItemDefaultFocus(); + + i++; }); ImGui::EndCombo(); } @@ -59,7 +69,7 @@ void VariableNodeWidget::Draw() { BaseNodeWidget::FrameStart(); - ImGui::TextUnformatted(m_selectedVariable.c_str()); + ImGui::TextUnformatted(m_selectedVariableName.c_str()); DrawPins(); diff --git a/story-editor/src/node_editor/variable_node_widget.h b/story-editor/src/node_editor/variable_node_widget.h index 79b2c06..1a185d7 100644 --- a/story-editor/src/node_editor/variable_node_widget.h +++ b/story-editor/src/node_editor/variable_node_widget.h @@ -27,5 +27,6 @@ private: IStoryManager &m_manager; std::shared_ptr m_variableNode; int m_selectedIndex{-1}; - std::string m_selectedVariable; + std::string m_selectedVariableUuid; + std::string m_selectedVariableName; }; diff --git a/story-editor/src/windows/main_window.cpp b/story-editor/src/windows/main_window.cpp index 2384d60..e3976ad 100644 --- a/story-editor/src/windows/main_window.cpp +++ b/story-editor/src/windows/main_window.cpp @@ -924,11 +924,13 @@ void MainWindow::RefreshProjectInformation() void MainWindow::CloseProject() { - if (m_story) - { - m_story->Clear(); - m_story.reset(); - } + // FIXME: not sure but if present, we lost some information in the library manager + + // if (m_story) + // { + // m_story->Clear(); + // m_story.reset(); + // } m_resources.Clear();