Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
SharedGraphRenderer.cpp
Go to the documentation of this file.
1/**
2 * @file SharedGraphRenderer.cpp
3 * @brief Shared renderer for BlueprintEditor and RuntimeDebugger.
4 * @author Olympe Engine
5 * @date 2026-03-08
6 *
7 * @details
8 * This file provides the SharedGraphRenderer implementation.
9 * When compiled as part of a build that includes ImGui and ImNodes
10 * (e.g. OlympeCore linked into BlueprintEditor or RuntimeEngine), the render
11 * methods issue real draw calls.
12 *
13 * In headless builds (unit tests, server processes) ImGui is not present; the
14 * methods compile to empty stubs via the OLYMPE_BLUEPRINT_EDITOR_ENABLED guard.
15 *
16 * C++14 compliant - no C++17/20 features.
17 */
18
19#include "SharedGraphRenderer.h"
20
21#ifdef OLYMPE_BLUEPRINT_EDITOR_ENABLED
22// Full ImGui / ImNodes rendering available.
23// GraphDocument, EditorContext, LocalBlackboard headers are only available in
24// editor builds that link OlympeCore.
25#include "GraphDocument.h"
26#include "EditorContext.h"
27#include "../TaskSystem/LocalBlackboard.h"
28
29#include "imgui.h"
30#include "imnodes.h"
31#endif
32
33namespace Olympe {
34namespace NodeGraph {
35
36// ============================================================================
37// Config factories
38// ============================================================================
39
41{
42 Config cfg;
43 cfg.readOnly = false;
44 cfg.showRuntimeHighlight = false;
45 cfg.showBlackboardPanel = true;
46 cfg.showToolbar = true;
47 return cfg;
48}
49
51{
52 Config cfg;
53 cfg.readOnly = true;
54 cfg.showRuntimeHighlight = true;
55 cfg.showBlackboardPanel = true;
56 cfg.showToolbar = false;
57 return cfg;
58}
59
60// ============================================================================
61// Render (main entry point)
62// ============================================================================
63
65 const EditorContext& ctx,
66 const Config& cfg,
67 int activeNodeID)
68{
69 if (!doc) return;
70
71#ifdef OLYMPE_BLUEPRINT_EDITOR_ENABLED
72
73 if (cfg.showToolbar)
74 {
76 }
77
78 ImNodes::BeginNodeEditor();
79
80 // Render all nodes.
81 const auto& nodes = doc->GetNodes();
82 for (size_t i = 0; i < nodes.size(); ++i)
83 {
84 RenderNode(nodes[i], cfg, activeNodeID);
85 }
86
87 // Render all links.
88 const auto& links = doc->GetLinks();
89 for (size_t i = 0; i < links.size(); ++i)
90 {
92 }
93
94 ImNodes::EndNodeEditor();
95
96 if (cfg.showBlackboardPanel)
97 {
98 // Blackboard panel is rendered separately; caller passes bb explicitly
99 // via RenderBlackboardPanel().
100 }
101
102#else
103 // Headless / no-ImGui build: no-op.
104 (void)ctx;
105 (void)cfg;
107#endif
108}
109
110// ============================================================================
111// RenderBlackboardPanel
112// ============================================================================
113
115{
116#ifdef OLYMPE_BLUEPRINT_EDITOR_ENABLED
117 if (!ImGui::Begin("Blackboard"))
118 {
119 ImGui::End();
120 return;
121 }
122
123 if (!bb)
124 {
125 ImGui::TextDisabled("(no blackboard)");
126 ImGui::End();
127 return;
128 }
129
130 const auto& names = bb->GetVariableNames();
131 for (size_t i = 0; i < names.size(); ++i)
132 {
133 try
134 {
135 const Olympe::TaskValue val = bb->GetValue(names[i]);
136 ImGui::Text("%s", names[i].c_str());
137 }
138 catch (...)
139 {
140 ImGui::TextDisabled("%s (error)", names[i].c_str());
141 }
142 }
143
144 ImGui::End();
145#else
146 (void)bb;
147#endif
148}
149
150// ============================================================================
151// Private: RenderNode
152// ============================================================================
153
155 const Config& cfg,
156 int activeNodeID)
157{
158#ifdef OLYMPE_BLUEPRINT_EDITOR_ENABLED
159 const bool isActive = (node.id.value == activeNodeID);
160
161 if (cfg.showRuntimeHighlight && isActive)
162 {
163 ImNodes::PushColorStyle(ImNodesCol_NodeBackground,
164 IM_COL32(255, 200, 0, 200));
165 }
166
167 ImNodes::BeginNode(node.id.value);
168 ImGui::TextUnformatted(node.name.c_str());
169 ImNodes::EndNode();
170
171 if (cfg.showRuntimeHighlight && isActive)
172 {
173 ImNodes::PopColorStyle();
174 }
175#else
176 (void)node;
177 (void)cfg;
179#endif
180}
181
182// ============================================================================
183// Private: RenderLink
184// ============================================================================
185
187{
188#ifdef OLYMPE_BLUEPRINT_EDITOR_ENABLED
189 ImNodes::Link(link.id.value, link.fromPin.value, link.toPin.value);
190#else
191 (void)link;
192#endif
193}
194
195// ============================================================================
196// Private: RenderToolbar
197// ============================================================================
198
200 const EditorContext& ctx)
201{
202#ifdef OLYMPE_BLUEPRINT_EDITOR_ENABLED
203 if (ImGui::Button("Auto Layout"))
204 {
205 // Trigger auto-layout via the document's built-in method.
206 // Requires NodeGraphCore AutoLayout support.
207 (void)doc;
208 }
209 ImGui::SameLine();
210 ImGui::TextDisabled(ctx.GetMode() == Olympe::NodeGraph::EditorMode::Debug ? "[Debug]" : "[Editor]");
211#else
212 (void)doc;
213 (void)ctx;
214#endif
215}
216
217} // namespace NodeGraph
218} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Document class for managing node graphs.
Shared renderer for BlueprintEditor and RuntimeDebugger.
Simple map-based blackboard for task graph runtime state.
Contexte d'édition pour un graphe.
Main document class for a node graph.
static Config MakeDebuggerConfig()
Returns the default configuration for the Runtime Debugger (read-only mode).
static void Render(GraphDocument *doc, const EditorContext &ctx, const Config &cfg, int activeNodeID=-1)
Renders the graph inside the current ImGui window.
static Config MakeEditorConfig()
Returns the default configuration for the BlueprintEditor (full-edit mode).
static void RenderBlackboardPanel(const LocalBlackboard *bb)
Renders the blackboard variables panel.
static void RenderLink(const LinkData &link)
Renders a single link between two nodes.
static void RenderToolbar(GraphDocument *doc, const EditorContext &ctx)
Renders the graph toolbar (save/load/auto-layout buttons).
static void RenderNode(const NodeData &node, const Config &cfg, int activeNodeID)
Renders a single node.
C++14-compliant type-safe value container for task parameters.
< Provides AssetID and INVALID_ASSET_ID
bool readOnly
Disable node dragging / connection editing.