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 <memory>
|
||||
|
||||
CodeEditor::CodeEditor()
|
||||
CodeEditor::CodeEditor(IStoryManager &project)
|
||||
: WindowBase("Code editor")
|
||||
, m_storyManager(project)
|
||||
{
|
||||
mEditor.SetReadOnly(true);
|
||||
mEditor.SetReadOnly(false);
|
||||
SetFlags(ImGuiWindowFlags_MenuBar);
|
||||
}
|
||||
|
||||
void CodeEditor::Initialize()
|
||||
|
|
@ -18,8 +20,8 @@ void CodeEditor::Initialize()
|
|||
|
||||
|
||||
// "breakpoint" markers
|
||||
// m_breakPoints.insert(42);
|
||||
// mEditor.SetBreakpoints(m_breakPoints);
|
||||
// m_breakPoints.insert(42);
|
||||
// mEditor.SetBreakpoints(m_breakPoints);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -40,6 +42,12 @@ void CodeEditor::SetScript(const std::string &txt)
|
|||
mEditor.SetText(txt);
|
||||
}
|
||||
|
||||
std::string CodeEditor::GetScript() const
|
||||
{
|
||||
return mEditor.GetText();
|
||||
}
|
||||
|
||||
|
||||
void CodeEditor::Draw()
|
||||
{
|
||||
WindowBase::BeginDraw();
|
||||
|
|
@ -109,6 +117,21 @@ void CodeEditor::Draw()
|
|||
mEditor.IsOverwrite() ? "Ovr" : "Ins",
|
||||
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");
|
||||
WindowBase::EndDraw();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,17 +2,19 @@
|
|||
|
||||
#include "TextEditor.h"
|
||||
#include "window_base.h"
|
||||
#include "i_story_manager.h"
|
||||
|
||||
class CodeEditor : public WindowBase
|
||||
{
|
||||
public:
|
||||
CodeEditor();
|
||||
CodeEditor(IStoryManager &project);
|
||||
|
||||
virtual void Draw() override;
|
||||
|
||||
void Initialize();
|
||||
|
||||
void SetScript(const std::string &txt);
|
||||
std::string GetScript() const;
|
||||
void ClearErrors();
|
||||
void AddError(int line, const std::string &text);
|
||||
|
||||
|
|
@ -21,6 +23,8 @@ public:
|
|||
mEditor.SetExecutionMarker(line);
|
||||
}
|
||||
private:
|
||||
IStoryManager &m_storyManager;
|
||||
|
||||
TextEditor mEditor;
|
||||
TextEditor::Breakpoints m_breakPoints;
|
||||
TextEditor::ErrorMarkers m_markers;
|
||||
|
|
|
|||
|
|
@ -76,13 +76,14 @@ void EmulatorWindow::Draw()
|
|||
|
||||
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();
|
||||
if (ImGui::Button("Play"))
|
||||
|
|
|
|||
|
|
@ -46,12 +46,14 @@ public:
|
|||
virtual void DeleteResource(FilterIterator &it) = 0;
|
||||
|
||||
// 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 void DeleteNode(const std::string &id) = 0;
|
||||
virtual void DeleteLink(std::shared_ptr<Connection> c) = 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 Ok() = 0;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
MainWindow::MainWindow()
|
||||
: m_libraryManager(*this)
|
||||
, m_emulatorWindow(*this)
|
||||
, m_codeEditorWindow(*this)
|
||||
, m_resourcesWindow(*this)
|
||||
, m_nodeEditorWindow(*this)
|
||||
, m_libraryWindow(*this, m_libraryManager)
|
||||
|
|
@ -192,7 +193,7 @@ void MainWindow::ProcessStory()
|
|||
{
|
||||
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;
|
||||
return;
|
||||
}
|
||||
|
|
@ -427,7 +428,7 @@ bool MainWindow::Initialize()
|
|||
m_player.Initialize(); // Initialize audio after GUI (uses SDL)
|
||||
// gui.ApplyTheme();
|
||||
|
||||
m_editorWindow.Initialize();
|
||||
m_codeEditorWindow.Initialize();
|
||||
m_emulatorWindow.Initialize();
|
||||
m_nodeEditorWindow.Initialize();
|
||||
m_PropertiesWindow.Initialize();
|
||||
|
|
@ -725,7 +726,7 @@ void MainWindow::OpenProject(const std::string &uuid)
|
|||
m_nodeEditorWindow.Enable();
|
||||
m_emulatorWindow.Enable();
|
||||
m_consoleWindow.Enable();
|
||||
m_editorWindow.Enable();
|
||||
m_codeEditorWindow.Enable();
|
||||
m_resourcesWindow.Enable();
|
||||
m_PropertiesWindow.Enable();
|
||||
}
|
||||
|
|
@ -771,12 +772,12 @@ void MainWindow::CloseProject()
|
|||
m_nodeEditorWindow.Clear();
|
||||
m_emulatorWindow.ClearImage();
|
||||
m_consoleWindow.ClearLog();
|
||||
m_editorWindow.ClearErrors();
|
||||
m_editorWindow.SetScript("");
|
||||
m_codeEditorWindow.ClearErrors();
|
||||
m_codeEditorWindow.SetScript("");
|
||||
|
||||
m_nodeEditorWindow.Disable();
|
||||
m_emulatorWindow.Disable();
|
||||
m_editorWindow.Disable();
|
||||
m_codeEditorWindow.Disable();
|
||||
m_resourcesWindow.Disable();
|
||||
m_PropertiesWindow.Disable();
|
||||
|
||||
|
|
@ -855,7 +856,7 @@ void MainWindow::Loop()
|
|||
{
|
||||
m_consoleWindow.Draw();
|
||||
m_emulatorWindow.Draw();
|
||||
m_editorWindow.Draw();
|
||||
m_codeEditorWindow.Draw();
|
||||
m_resourcesWindow.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))
|
||||
{
|
||||
m_editorWindow.SetScript(m_currentCode);
|
||||
m_dbg.run_result = VM_FINISHED;
|
||||
m_dbg.free_run = false;
|
||||
m_codeEditorWindow.SetScript(m_currentCode);
|
||||
Build(compileonly);
|
||||
}
|
||||
}
|
||||
|
||||
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_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_ramView->SetMemory(m_ram_data, sizeof(m_ram_data));
|
||||
// m_romView->SetMemory(m_rom_data, m_program.size());
|
||||
m_story->SaveBinary();
|
||||
chip32_initialize(&m_chip32_ctx);
|
||||
m_dbg.run_result = VM_READY;
|
||||
UpdateVmView();
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Program too big. Expand ROM memory.");
|
||||
}
|
||||
m_story->SaveBinary();
|
||||
chip32_initialize(&m_chip32_ctx);
|
||||
m_dbg.run_result = VM_READY;
|
||||
UpdateVmView();
|
||||
}
|
||||
else
|
||||
{
|
||||
Log(err.ToString(), true);
|
||||
m_editorWindow.AddError(err.line, err.message); // show also the error in the code editor
|
||||
Log("Program too big. Expand ROM memory.");
|
||||
}
|
||||
}
|
||||
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)
|
||||
|
|
@ -1039,7 +1064,7 @@ void MainWindow::UpdateVmView()
|
|||
if (m_story->GetAssemblyLine(pcVal, line))
|
||||
{
|
||||
m_dbg.line = (line - 1);
|
||||
m_editorWindow.HighlightLine(m_dbg.line);
|
||||
m_codeEditorWindow.HighlightLine(m_dbg.line);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ private:
|
|||
Gui m_gui;
|
||||
EmulatorWindow m_emulatorWindow;
|
||||
ConsoleWindow m_consoleWindow;
|
||||
CodeEditor m_editorWindow;
|
||||
CodeEditor m_codeEditorWindow;
|
||||
|
||||
char m_project_name[256] = "";
|
||||
|
||||
|
|
@ -133,11 +133,13 @@ private:
|
|||
virtual void DeleteResource(FilterIterator &it) 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 DeleteLink(std::shared_ptr<Connection> c) override;
|
||||
virtual std::list<std::shared_ptr<Connection>> GetNodeConnections(const std::string &nodeId) override;
|
||||
virtual void LoadBinaryStory(const std::string &filename) override;
|
||||
virtual void ToggleBreakpoint(int line) override;
|
||||
|
||||
virtual void Play() override;
|
||||
virtual void Ok() override;
|
||||
|
|
@ -172,6 +174,7 @@ private:
|
|||
void StepInstruction();
|
||||
void RefreshProjectInformation();
|
||||
void ProjectPropertiesPopup();
|
||||
void Build(bool compileonly);
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ WindowBase::WindowBase(const std::string &title)
|
|||
|
||||
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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define WINDOWBASE_H
|
||||
|
||||
#include <string>
|
||||
#include "imgui.h"
|
||||
|
||||
class WindowBase
|
||||
{
|
||||
|
|
@ -26,10 +27,15 @@ public:
|
|||
m_disabled = false;
|
||||
}
|
||||
|
||||
void SetFlags(ImGuiWindowFlags flags) {
|
||||
m_windowFlags = flags;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
bool m_disabled{false};
|
||||
std::string m_title;
|
||||
ImGuiWindowFlags m_windowFlags = 0;
|
||||
};
|
||||
|
||||
#endif // WINDOWBASE_H
|
||||
|
|
|
|||
Loading…
Reference in a new issue