mirror of
https://github.com/arabine/open-story-teller.git
synced 2025-12-06 17:09:06 +01:00
(WIP) Code debug: add breakpoint button
This commit is contained in:
parent
52f0312c5c
commit
5ed9233778
8 changed files with 114 additions and 50 deletions
|
|
@ -3,10 +3,12 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
CodeEditor::CodeEditor()
|
CodeEditor::CodeEditor(IStoryManager &project)
|
||||||
: WindowBase("Code editor")
|
: WindowBase("Code editor")
|
||||||
|
, m_storyManager(project)
|
||||||
{
|
{
|
||||||
mEditor.SetReadOnly(true);
|
mEditor.SetReadOnly(false);
|
||||||
|
SetFlags(ImGuiWindowFlags_MenuBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeEditor::Initialize()
|
void CodeEditor::Initialize()
|
||||||
|
|
@ -18,8 +20,8 @@ void CodeEditor::Initialize()
|
||||||
|
|
||||||
|
|
||||||
// "breakpoint" markers
|
// "breakpoint" markers
|
||||||
// m_breakPoints.insert(42);
|
// m_breakPoints.insert(42);
|
||||||
// mEditor.SetBreakpoints(m_breakPoints);
|
// mEditor.SetBreakpoints(m_breakPoints);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,6 +42,12 @@ void CodeEditor::SetScript(const std::string &txt)
|
||||||
mEditor.SetText(txt);
|
mEditor.SetText(txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CodeEditor::GetScript() const
|
||||||
|
{
|
||||||
|
return mEditor.GetText();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CodeEditor::Draw()
|
void CodeEditor::Draw()
|
||||||
{
|
{
|
||||||
WindowBase::BeginDraw();
|
WindowBase::BeginDraw();
|
||||||
|
|
@ -109,6 +117,21 @@ void CodeEditor::Draw()
|
||||||
mEditor.IsOverwrite() ? "Ovr" : "Ins",
|
mEditor.IsOverwrite() ? "Ovr" : "Ins",
|
||||||
mEditor.CanUndo() ? "*" : " ");
|
mEditor.CanUndo() ? "*" : " ");
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::SmallButton("Toggle breakpoint")) {
|
||||||
|
if (m_breakPoints.contains(cpos.mLine))
|
||||||
|
{
|
||||||
|
m_breakPoints.erase(cpos.mLine);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_breakPoints.insert(cpos.mLine);
|
||||||
|
}
|
||||||
|
mEditor.SetBreakpoints(m_breakPoints);
|
||||||
|
|
||||||
|
m_storyManager.ToggleBreakpoint(cpos.mLine);
|
||||||
|
}
|
||||||
|
|
||||||
mEditor.Render("TextEditor");
|
mEditor.Render("TextEditor");
|
||||||
WindowBase::EndDraw();
|
WindowBase::EndDraw();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,19 @@
|
||||||
|
|
||||||
#include "TextEditor.h"
|
#include "TextEditor.h"
|
||||||
#include "window_base.h"
|
#include "window_base.h"
|
||||||
|
#include "i_story_manager.h"
|
||||||
|
|
||||||
class CodeEditor : public WindowBase
|
class CodeEditor : public WindowBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CodeEditor();
|
CodeEditor(IStoryManager &project);
|
||||||
|
|
||||||
virtual void Draw() override;
|
virtual void Draw() override;
|
||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
|
|
||||||
void SetScript(const std::string &txt);
|
void SetScript(const std::string &txt);
|
||||||
|
std::string GetScript() const;
|
||||||
void ClearErrors();
|
void ClearErrors();
|
||||||
void AddError(int line, const std::string &text);
|
void AddError(int line, const std::string &text);
|
||||||
|
|
||||||
|
|
@ -21,6 +23,8 @@ public:
|
||||||
mEditor.SetExecutionMarker(line);
|
mEditor.SetExecutionMarker(line);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
IStoryManager &m_storyManager;
|
||||||
|
|
||||||
TextEditor mEditor;
|
TextEditor mEditor;
|
||||||
TextEditor::Breakpoints m_breakPoints;
|
TextEditor::Breakpoints m_breakPoints;
|
||||||
TextEditor::ErrorMarkers m_markers;
|
TextEditor::ErrorMarkers m_markers;
|
||||||
|
|
|
||||||
|
|
@ -76,13 +76,14 @@ void EmulatorWindow::Draw()
|
||||||
|
|
||||||
ImGui::SeparatorText("Script control and debug");
|
ImGui::SeparatorText("Script control and debug");
|
||||||
|
|
||||||
if (ImGui::Button("Generate pack"))
|
if (ImGui::Button("Build nodes"))
|
||||||
{
|
{
|
||||||
m_story.Build(false);
|
m_story.BuildNodes(true);
|
||||||
}
|
}
|
||||||
if (ImGui::Button("Build script"))
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("Build code"))
|
||||||
{
|
{
|
||||||
m_story.Build(true);
|
m_story.BuildCode(true);
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::Button("Play"))
|
if (ImGui::Button("Play"))
|
||||||
|
|
|
||||||
|
|
@ -46,12 +46,14 @@ public:
|
||||||
virtual void DeleteResource(FilterIterator &it) = 0;
|
virtual void DeleteResource(FilterIterator &it) = 0;
|
||||||
|
|
||||||
// Node interaction
|
// Node interaction
|
||||||
virtual void Build(bool compileonly) = 0;
|
virtual void BuildNodes(bool compileonly) = 0;
|
||||||
|
virtual void BuildCode(bool compileonly) = 0;
|
||||||
virtual std::shared_ptr<BaseNode> CreateNode(const std::string &type) = 0;
|
virtual std::shared_ptr<BaseNode> CreateNode(const std::string &type) = 0;
|
||||||
virtual void DeleteNode(const std::string &id) = 0;
|
virtual void DeleteNode(const std::string &id) = 0;
|
||||||
virtual void DeleteLink(std::shared_ptr<Connection> c) = 0;
|
virtual void DeleteLink(std::shared_ptr<Connection> c) = 0;
|
||||||
virtual std::list<std::shared_ptr<Connection>> GetNodeConnections(const std::string &nodeId) = 0;
|
virtual std::list<std::shared_ptr<Connection>> GetNodeConnections(const std::string &nodeId) = 0;
|
||||||
virtual void LoadBinaryStory(const std::string &filename) = 0;
|
virtual void LoadBinaryStory(const std::string &filename) = 0;
|
||||||
|
virtual void ToggleBreakpoint(int line) = 0;
|
||||||
|
|
||||||
virtual void Play() = 0;
|
virtual void Play() = 0;
|
||||||
virtual void Ok() = 0;
|
virtual void Ok() = 0;
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
MainWindow::MainWindow()
|
MainWindow::MainWindow()
|
||||||
: m_libraryManager(*this)
|
: m_libraryManager(*this)
|
||||||
, m_emulatorWindow(*this)
|
, m_emulatorWindow(*this)
|
||||||
|
, m_codeEditorWindow(*this)
|
||||||
, m_resourcesWindow(*this)
|
, m_resourcesWindow(*this)
|
||||||
, m_nodeEditorWindow(*this)
|
, m_nodeEditorWindow(*this)
|
||||||
, m_libraryWindow(*this, m_libraryManager)
|
, m_libraryWindow(*this, m_libraryManager)
|
||||||
|
|
@ -192,7 +193,7 @@ void MainWindow::ProcessStory()
|
||||||
{
|
{
|
||||||
if (m_dbg.m_breakpoints.contains(m_dbg.line + 1))
|
if (m_dbg.m_breakpoints.contains(m_dbg.line + 1))
|
||||||
{
|
{
|
||||||
Log("Breakpoint on line: " + std::to_string(m_dbg.line + 1));
|
// Log("Breakpoint on line: " + std::to_string(m_dbg.line + 1));
|
||||||
m_dbg.free_run = false;
|
m_dbg.free_run = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -427,7 +428,7 @@ bool MainWindow::Initialize()
|
||||||
m_player.Initialize(); // Initialize audio after GUI (uses SDL)
|
m_player.Initialize(); // Initialize audio after GUI (uses SDL)
|
||||||
// gui.ApplyTheme();
|
// gui.ApplyTheme();
|
||||||
|
|
||||||
m_editorWindow.Initialize();
|
m_codeEditorWindow.Initialize();
|
||||||
m_emulatorWindow.Initialize();
|
m_emulatorWindow.Initialize();
|
||||||
m_nodeEditorWindow.Initialize();
|
m_nodeEditorWindow.Initialize();
|
||||||
m_PropertiesWindow.Initialize();
|
m_PropertiesWindow.Initialize();
|
||||||
|
|
@ -725,7 +726,7 @@ void MainWindow::OpenProject(const std::string &uuid)
|
||||||
m_nodeEditorWindow.Enable();
|
m_nodeEditorWindow.Enable();
|
||||||
m_emulatorWindow.Enable();
|
m_emulatorWindow.Enable();
|
||||||
m_consoleWindow.Enable();
|
m_consoleWindow.Enable();
|
||||||
m_editorWindow.Enable();
|
m_codeEditorWindow.Enable();
|
||||||
m_resourcesWindow.Enable();
|
m_resourcesWindow.Enable();
|
||||||
m_PropertiesWindow.Enable();
|
m_PropertiesWindow.Enable();
|
||||||
}
|
}
|
||||||
|
|
@ -771,12 +772,12 @@ void MainWindow::CloseProject()
|
||||||
m_nodeEditorWindow.Clear();
|
m_nodeEditorWindow.Clear();
|
||||||
m_emulatorWindow.ClearImage();
|
m_emulatorWindow.ClearImage();
|
||||||
m_consoleWindow.ClearLog();
|
m_consoleWindow.ClearLog();
|
||||||
m_editorWindow.ClearErrors();
|
m_codeEditorWindow.ClearErrors();
|
||||||
m_editorWindow.SetScript("");
|
m_codeEditorWindow.SetScript("");
|
||||||
|
|
||||||
m_nodeEditorWindow.Disable();
|
m_nodeEditorWindow.Disable();
|
||||||
m_emulatorWindow.Disable();
|
m_emulatorWindow.Disable();
|
||||||
m_editorWindow.Disable();
|
m_codeEditorWindow.Disable();
|
||||||
m_resourcesWindow.Disable();
|
m_resourcesWindow.Disable();
|
||||||
m_PropertiesWindow.Disable();
|
m_PropertiesWindow.Disable();
|
||||||
|
|
||||||
|
|
@ -855,7 +856,7 @@ void MainWindow::Loop()
|
||||||
{
|
{
|
||||||
m_consoleWindow.Draw();
|
m_consoleWindow.Draw();
|
||||||
m_emulatorWindow.Draw();
|
m_emulatorWindow.Draw();
|
||||||
m_editorWindow.Draw();
|
m_codeEditorWindow.Draw();
|
||||||
m_resourcesWindow.Draw();
|
m_resourcesWindow.Draw();
|
||||||
m_nodeEditorWindow.Draw();
|
m_nodeEditorWindow.Draw();
|
||||||
|
|
||||||
|
|
@ -969,47 +970,71 @@ void MainWindow::LoadBinaryStory(const std::string &filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::ToggleBreakpoint(int line)
|
||||||
|
{
|
||||||
|
if (m_dbg.m_breakpoints.contains(line))
|
||||||
|
{
|
||||||
|
m_dbg.m_breakpoints.erase(line);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_dbg.m_breakpoints.insert(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::Build(bool compileonly)
|
void MainWindow::BuildNodes(bool compileonly)
|
||||||
{
|
{
|
||||||
if (m_story->GenerateScript(m_currentCode))
|
if (m_story->GenerateScript(m_currentCode))
|
||||||
{
|
{
|
||||||
m_editorWindow.SetScript(m_currentCode);
|
m_codeEditorWindow.SetScript(m_currentCode);
|
||||||
m_dbg.run_result = VM_FINISHED;
|
Build(compileonly);
|
||||||
m_dbg.free_run = false;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!compileonly)
|
|
||||||
|
void MainWindow::Build(bool compileonly)
|
||||||
|
{
|
||||||
|
m_dbg.run_result = VM_FINISHED;
|
||||||
|
m_dbg.free_run = false;
|
||||||
|
|
||||||
|
if (!compileonly)
|
||||||
|
{
|
||||||
|
// 3. Convert all media to desired type format
|
||||||
|
m_resources.ConvertResources(m_story->AssetsPath(), "", m_story->GetImageFormat(), m_story->GetSoundFormat()); // pas de répertoire de destination
|
||||||
|
}
|
||||||
|
|
||||||
|
Chip32::Assembler::Error err;
|
||||||
|
m_codeEditorWindow.ClearErrors();
|
||||||
|
if (m_story->GenerateBinary(m_currentCode, err))
|
||||||
|
{
|
||||||
|
m_result.Print();
|
||||||
|
|
||||||
|
if (m_story->CopyProgramTo(m_rom_data, sizeof (m_rom_data)))
|
||||||
{
|
{
|
||||||
// 3. Convert all media to desired type format
|
// m_ramView->SetMemory(m_ram_data, sizeof(m_ram_data));
|
||||||
m_resources.ConvertResources(m_story->AssetsPath(), "", m_story->GetImageFormat(), m_story->GetSoundFormat()); // pas de répertoire de destination
|
|
||||||
}
|
|
||||||
|
|
||||||
Chip32::Assembler::Error err;
|
|
||||||
if (m_story->GenerateBinary(m_currentCode, err))
|
|
||||||
{
|
|
||||||
m_result.Print();
|
|
||||||
|
|
||||||
if (m_story->CopyProgramTo(m_rom_data, sizeof (m_rom_data)))
|
|
||||||
{
|
|
||||||
// m_ramView->SetMemory(m_ram_data, sizeof(m_ram_data));
|
|
||||||
// m_romView->SetMemory(m_rom_data, m_program.size());
|
// m_romView->SetMemory(m_rom_data, m_program.size());
|
||||||
m_story->SaveBinary();
|
m_story->SaveBinary();
|
||||||
chip32_initialize(&m_chip32_ctx);
|
chip32_initialize(&m_chip32_ctx);
|
||||||
m_dbg.run_result = VM_READY;
|
m_dbg.run_result = VM_READY;
|
||||||
UpdateVmView();
|
UpdateVmView();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Log("Program too big. Expand ROM memory.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log(err.ToString(), true);
|
Log("Program too big. Expand ROM memory.");
|
||||||
m_editorWindow.AddError(err.line, err.message); // show also the error in the code editor
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log(err.ToString(), true);
|
||||||
|
m_codeEditorWindow.AddError(err.line, err.message); // show also the error in the code editor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::BuildCode(bool compileonly)
|
||||||
|
{
|
||||||
|
m_currentCode = m_codeEditorWindow.GetScript();
|
||||||
|
Build(compileonly);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::DeleteNode(const std::string &id)
|
void MainWindow::DeleteNode(const std::string &id)
|
||||||
|
|
@ -1039,7 +1064,7 @@ void MainWindow::UpdateVmView()
|
||||||
if (m_story->GetAssemblyLine(pcVal, line))
|
if (m_story->GetAssemblyLine(pcVal, line))
|
||||||
{
|
{
|
||||||
m_dbg.line = (line - 1);
|
m_dbg.line = (line - 1);
|
||||||
m_editorWindow.HighlightLine(m_dbg.line);
|
m_codeEditorWindow.HighlightLine(m_dbg.line);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ private:
|
||||||
Gui m_gui;
|
Gui m_gui;
|
||||||
EmulatorWindow m_emulatorWindow;
|
EmulatorWindow m_emulatorWindow;
|
||||||
ConsoleWindow m_consoleWindow;
|
ConsoleWindow m_consoleWindow;
|
||||||
CodeEditor m_editorWindow;
|
CodeEditor m_codeEditorWindow;
|
||||||
|
|
||||||
char m_project_name[256] = "";
|
char m_project_name[256] = "";
|
||||||
|
|
||||||
|
|
@ -133,11 +133,13 @@ private:
|
||||||
virtual void DeleteResource(FilterIterator &it) override;
|
virtual void DeleteResource(FilterIterator &it) override;
|
||||||
|
|
||||||
virtual std::shared_ptr<BaseNode> CreateNode(const std::string &type) override;
|
virtual std::shared_ptr<BaseNode> CreateNode(const std::string &type) override;
|
||||||
virtual void Build(bool compileonly) override;
|
virtual void BuildNodes(bool compileonly) override;
|
||||||
|
virtual void BuildCode(bool compileonly) override;
|
||||||
virtual void DeleteNode(const std::string &id) override;
|
virtual void DeleteNode(const std::string &id) override;
|
||||||
virtual void DeleteLink(std::shared_ptr<Connection> c) override;
|
virtual void DeleteLink(std::shared_ptr<Connection> c) override;
|
||||||
virtual std::list<std::shared_ptr<Connection>> GetNodeConnections(const std::string &nodeId) override;
|
virtual std::list<std::shared_ptr<Connection>> GetNodeConnections(const std::string &nodeId) override;
|
||||||
virtual void LoadBinaryStory(const std::string &filename) override;
|
virtual void LoadBinaryStory(const std::string &filename) override;
|
||||||
|
virtual void ToggleBreakpoint(int line) override;
|
||||||
|
|
||||||
virtual void Play() override;
|
virtual void Play() override;
|
||||||
virtual void Ok() override;
|
virtual void Ok() override;
|
||||||
|
|
@ -172,6 +174,7 @@ private:
|
||||||
void StepInstruction();
|
void StepInstruction();
|
||||||
void RefreshProjectInformation();
|
void RefreshProjectInformation();
|
||||||
void ProjectPropertiesPopup();
|
void ProjectPropertiesPopup();
|
||||||
|
void Build(bool compileonly);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ WindowBase::WindowBase(const std::string &title)
|
||||||
|
|
||||||
bool WindowBase::BeginDraw()
|
bool WindowBase::BeginDraw()
|
||||||
{
|
{
|
||||||
bool ok = ImGui::Begin(m_title.c_str(), nullptr);
|
bool ok = ImGui::Begin(m_title.c_str(), nullptr, m_windowFlags);
|
||||||
|
|
||||||
if (m_disabled)
|
if (m_disabled)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define WINDOWBASE_H
|
#define WINDOWBASE_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "imgui.h"
|
||||||
|
|
||||||
class WindowBase
|
class WindowBase
|
||||||
{
|
{
|
||||||
|
|
@ -26,10 +27,15 @@ public:
|
||||||
m_disabled = false;
|
m_disabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetFlags(ImGuiWindowFlags flags) {
|
||||||
|
m_windowFlags = flags;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool m_disabled{false};
|
bool m_disabled{false};
|
||||||
std::string m_title;
|
std::string m_title;
|
||||||
|
ImGuiWindowFlags m_windowFlags = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WINDOWBASE_H
|
#endif // WINDOWBASE_H
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue