Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
GraphAutoLayout.h
Go to the documentation of this file.
1/**
2 * @file GraphAutoLayout.h
3 * @brief Hierarchical (Sugiyama-inspired) auto-layout for VS task graphs (Phase 6).
4 * @author Olympe Engine
5 * @date 2026-03-09
6 *
7 * @details
8 * Assigns positions to TaskNodeDefinition nodes in a TaskGraphTemplate so that
9 * the graph can be read top-to-bottom. The EntryPoint node is placed at the
10 * root (top), and nodes are arranged into layers based on their distance from
11 * the entry point in the exec-connection graph.
12 *
13 * Algorithm summary (Sugiyama-inspired):
14 * 1. BFS from the EntryPoint node → assign each node a layer index.
15 * 2. Within each layer, order nodes by ascending NodeID (stable).
16 * 3. Assign (x, y) screen-space positions using fixed spacing constants.
17 * 4. Positions are stored in the Parameters map under "__posX" / "__posY".
18 *
19 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
20 */
21
22#pragma once
23
24#include <vector>
25#include <cstdint>
26
27#include "../TaskSystem/TaskGraphTemplate.h"
28
29namespace Olympe {
30
31// ============================================================================
32// GraphAutoLayout
33// ============================================================================
34
35/**
36 * @class GraphAutoLayout
37 * @brief Applies a hierarchical layout to a TaskGraphTemplate in place.
38 *
39 * Typical usage:
40 * @code
41 * GraphAutoLayout::ApplyHierarchicalLayout(myGraph);
42 * @endcode
43 */
45public:
46
47 /// Horizontal gap between columns (pixels).
48 static constexpr float SPACING_X = 220.0f;
49
50 /// Vertical gap between rows (pixels).
51 static constexpr float SPACING_Y = 130.0f;
52
53 /// X coordinate of the root (EntryPoint) column.
54 static constexpr float ORIGIN_X = 100.0f;
55
56 /// Y coordinate of the first row.
57 static constexpr float ORIGIN_Y = 100.0f;
58
59 /**
60 * @brief Assigns screen-space positions to every node in @p graph.
61 *
62 * @details
63 * Positions are written into each node's Parameters map under the keys
64 * "__posX" (float) and "__posY" (float) so they can be consumed by the
65 * editor canvas without touching the node's semantic fields.
66 *
67 * If @p graph has no EntryPoint node, the first node in Nodes is used as
68 * the root. Disconnected (orphan) nodes are placed in an overflow column
69 * to the right of the main layout.
70 *
71 * @param graph The graph whose nodes will be positioned.
72 */
74
75 // -----------------------------------------------------------------------
76 // Internal helpers exposed for unit-testing
77 // -----------------------------------------------------------------------
78
79 /**
80 * @brief A single layer in the hierarchical layout.
81 */
82 struct Layer {
83 std::vector<int32_t> NodeIDs; ///< IDs of nodes assigned to this layer, in order
84 };
85
86 /**
87 * @brief Builds layers via BFS from the entry point.
88 *
89 * @param graph Source graph.
90 * @return Vector of layers; layer[0] contains the root node.
91 */
92 static std::vector<Layer> BuildLayers(const TaskGraphTemplate& graph);
93
94 /**
95 * @brief Assigns x/y positions from the layer structure.
96 *
97 * @param graph Graph whose nodes will be modified.
98 * @param layers Layer structure produced by BuildLayers().
99 */
101 const std::vector<Layer>& layers);
102
103private:
104
105 /**
106 * @brief Writes a float position into a node's Parameters map.
107 */
108 static void SetPos(TaskNodeDefinition& node, float x, float y);
109};
110
111} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Applies a hierarchical layout to a TaskGraphTemplate in place.
static constexpr float ORIGIN_X
X coordinate of the root (EntryPoint) column.
static constexpr float SPACING_Y
Vertical gap between rows (pixels).
static void AssignPositions(TaskGraphTemplate &graph, const std::vector< Layer > &layers)
Assigns x/y positions from the layer structure.
static void SetPos(TaskNodeDefinition &node, float x, float y)
Writes a float position into a node's Parameters map.
static constexpr float SPACING_X
Horizontal gap between columns (pixels).
static std::vector< Layer > BuildLayers(const TaskGraphTemplate &graph)
Builds layers via BFS from the entry point.
static constexpr float ORIGIN_Y
Y coordinate of the first row.
static void ApplyHierarchicalLayout(TaskGraphTemplate &graph)
Assigns screen-space positions to every node in graph.
Immutable, shareable task graph asset.
< Provides AssetID and INVALID_ASSET_ID
A single layer in the hierarchical layout.
std::vector< int32_t > NodeIDs
IDs of nodes assigned to this layer, in order.
Full description of a single node in the task graph.