Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
Olympe::NodeGraph Class Reference

#include <BTNodeGraphManager.h>

+ Collaboration diagram for Olympe::NodeGraph:

Public Types

enum class  BlackboardType : uint8_t {
  Int = 0 , Float , Bool , String ,
  Vector3
}
 Supported variable types in the blackboard. More...
 
enum class  EditorMode { Editor , Visualizer , Debug }
 Mode d'édition du graphe. More...
 
enum class  LayoutDirection : uint8_t { TopToBottom = 0 , BottomToTop = 1 , LeftToRight = 2 , RightToLeft = 3 }
 
using Vector2 = Vector
 

Public Member Functions

 NodeGraph ()
 
 ~NodeGraph ()=default
 
 NodeGraph (const NodeGraph &other)
 
NodeGraphoperator= (const NodeGraph &other)
 
 NodeGraph (NodeGraph &&other) noexcept
 
NodeGraphoperator= (NodeGraph &&other) noexcept
 
int CreateNode (NodeType type, float x, float y, const std::string &name="")
 
bool DeleteNode (int nodeId)
 
GraphNodeGetNode (int nodeId)
 
const GraphNodeGetNode (int nodeId) const
 
std::vector< GraphNode * > GetAllNodes ()
 
std::vector< const GraphNode * > GetAllNodes () const
 
bool LinkNodes (int parentId, int childId)
 
bool UnlinkNodes (int parentId, int childId)
 
std::vector< GraphLinkGetAllLinks () const
 
bool SetNodeParameter (int nodeId, const std::string &paramName, const std::string &value)
 
std::string GetNodeParameter (int nodeId, const std::string &paramName) const
 
nlohmann::json ToJson () const
 
bool ValidateGraph (std::string &errorMsg) const
 
void Clear ()
 
int GetNextNodeId () const
 
int GetRootNodeId () const
 
void CalculateNodePositionsHierarchical ()
 
bool IsDirty () const
 
void MarkDirty ()
 
void ClearDirty ()
 
const std::string & GetFilepath () const
 
void SetFilepath (const std::string &filepath)
 
bool HasFilepath () const
 
CommandHistoryGetCommandHistory ()
 
const CommandHistoryGetCommandHistory () const
 
bool CanUndo () const
 
bool CanRedo () const
 
std::string GetUndoDescription () const
 
std::string GetRedoDescription () const
 
bool Undo ()
 
bool Redo ()
 
void CopyNodesToClipboard (const std::vector< int > &nodeIds)
 
std::vector< intPasteNodesFromClipboard (float offsetX=30.0f, float offsetY=30.0f)
 
std::vector< intDuplicateNodes (const std::vector< int > &nodeIds, float offsetX=30.0f, float offsetY=30.0f)
 

Static Public Member Functions

static NodeGraph FromJson (const nlohmann::json &j)
 

Public Attributes

std::string name
 
std::string type
 
int rootNodeId = -1
 
EditorMetadata editorMetadata
 
std::vector< ClipboardNodem_clipboardData
 

Private Member Functions

bool IsValidRoot (uint32_t nodeId) const
 Check if a node ID is a valid root (main Root or OnEvent root) Root nodes cannot be deleted or moved under other nodes.
 
void AddEventRoot (uint32_t nodeId)
 Add node ID to event roots array Called when creating an OnEvent node.
 
void RemoveEventRoot (uint32_t nodeId)
 Remove node ID from event roots array Called when deleting an OnEvent node.
 
const std::vector< uint32_t > & GetEventRootIds () const
 Get all OnEvent root node IDs.
 
int FindNodeIndex (int nodeId) const
 

Private Attributes

std::vector< GraphNodem_Nodes
 
int m_NextNodeId = 1
 
bool m_IsDirty = false
 
std::string m_Filepath
 
std::unique_ptr< CommandHistorym_commandHistory
 
std::vector< uint32_tm_eventRootIds
 Separate array of node IDs that are OnEvent root nodes These nodes represent independent execution trees triggered by EventQueue messages Not connected to the main Root node tree.
 

Detailed Description

Definition at line 279 of file BTNodeGraphManager.h.

Member Typedef Documentation

◆ Vector2

using Olympe::NodeGraph::Vector2 = Vector

Definition at line 64 of file NodeGraphCore.h.

Member Enumeration Documentation

◆ BlackboardType

enum class Olympe::NodeGraph::BlackboardType : uint8_t
strong

Supported variable types in the blackboard.

Enumerator
Int 
Float 
Bool 
String 
Vector3 

Definition at line 29 of file BlackboardSystem.h.

◆ EditorMode

enum class Olympe::NodeGraph::EditorMode
strong

Mode d'édition du graphe.

Enumerator
Editor 
Visualizer 
Debug 

Definition at line 23 of file EditorContext.h.

◆ LayoutDirection

enum class Olympe::NodeGraph::LayoutDirection : uint8_t
strong
Enumerator
TopToBottom 
BottomToTop 
LeftToRight 
RightToLeft 

Definition at line 123 of file NodeGraphCore.h.

Constructor & Destructor Documentation

◆ NodeGraph() [1/3]

Olympe::NodeGraph::NodeGraph ( )

Definition at line 27 of file BTNodeGraphManager.cpp.

◆ ~NodeGraph()

Olympe::NodeGraph::~NodeGraph ( )
default

References operator=().

+ Here is the call graph for this function:

◆ NodeGraph() [2/3]

Olympe::NodeGraph::NodeGraph ( const NodeGraph other)

Definition at line 36 of file BTNodeGraphManager.cpp.

◆ NodeGraph() [3/3]

Olympe::NodeGraph::NodeGraph ( NodeGraph &&  other)
noexcept

Definition at line 69 of file BTNodeGraphManager.cpp.

Member Function Documentation

◆ AddEventRoot()

void Olympe::NodeGraph::AddEventRoot ( uint32_t  nodeId)
private

Add node ID to event roots array Called when creating an OnEvent node.

Definition at line 637 of file BTNodeGraphManager.cpp.

References m_eventRootIds, and MarkDirty().

+ Here is the call graph for this function:

◆ CalculateNodePositionsHierarchical()

void Olympe::NodeGraph::CalculateNodePositionsHierarchical ( )

Definition at line 674 of file BTNodeGraphManager.cpp.

References FindNodeIndex(), GetComponentTypeID_Static(), m_Nodes, and rootNodeId.

+ Here is the call graph for this function:

◆ CanRedo()

bool Olympe::NodeGraph::CanRedo ( ) const

Definition at line 600 of file BTNodeGraphManager.cpp.

References m_commandHistory.

◆ CanUndo()

bool Olympe::NodeGraph::CanUndo ( ) const

Definition at line 595 of file BTNodeGraphManager.cpp.

References m_commandHistory.

◆ Clear()

void Olympe::NodeGraph::Clear ( )

Definition at line 576 of file BTNodeGraphManager.cpp.

References m_commandHistory, m_NextNodeId, m_Nodes, and rootNodeId.

◆ ClearDirty()

void Olympe::NodeGraph::ClearDirty ( )
inline

Definition at line 334 of file BTNodeGraphManager.h.

References m_IsDirty.

Referenced by Olympe::NodeGraphShared::BTGraphDocumentConverter::FromBehaviorTree().

+ Here is the caller graph for this function:

◆ CopyNodesToClipboard()

void Olympe::NodeGraph::CopyNodesToClipboard ( const std::vector< int > &  nodeIds)

Definition at line 1174 of file BTNodeGraphManager.cpp.

References GetComponentTypeID_Static(), m_clipboardData, m_IsDirty, m_Nodes, and Olympe::ClipboardNode::nodeId.

Referenced by Olympe::CopyNodesCommand::Execute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CreateNode()

int Olympe::NodeGraph::CreateNode ( NodeType  type,
float  x,
float  y,
const std::string &  name = "" 
)

Definition at line 100 of file BTNodeGraphManager.cpp.

References GetComponentTypeID_Static(), Olympe::GraphNode::id, m_NextNodeId, m_Nodes, MarkDirty(), and Olympe::NodeTypeToString().

+ Here is the call graph for this function:

◆ DeleteNode()

bool Olympe::NodeGraph::DeleteNode ( int  nodeId)

Definition at line 117 of file BTNodeGraphManager.cpp.

References FindNodeIndex(), GetComponentTypeID_Static(), m_Nodes, and MarkDirty().

Referenced by Olympe::Blueprint::CreateNodeCommand::Undo(), Olympe::Blueprint::DuplicateNodeCommand::Undo(), Olympe::PasteNodesCommand::Undo(), and Olympe::DuplicateNodeCommand::Undo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DuplicateNodes()

std::vector< int > Olympe::NodeGraph::DuplicateNodes ( const std::vector< int > &  nodeIds,
float  offsetX = 30.0f,
float  offsetY = 30.0f 
)

Definition at line 1246 of file BTNodeGraphManager.cpp.

References GetComponentTypeID_Static(), Olympe::GraphNode::id, m_IsDirty, m_NextNodeId, and m_Nodes.

Referenced by Olympe::DuplicateNodeCommand::Execute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FindNodeIndex()

int Olympe::NodeGraph::FindNodeIndex ( int  nodeId) const
private

Definition at line 664 of file BTNodeGraphManager.cpp.

References GetComponentTypeID_Static(), and m_Nodes.

Referenced by CalculateNodePositionsHierarchical(), DeleteNode(), GetNode(), and GetNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FromJson()

NodeGraph Olympe::NodeGraph::FromJson ( const nlohmann::json j)
static

◆ GetAllLinks()

std::vector< GraphLink > Olympe::NodeGraph::GetAllLinks ( ) const

Definition at line 234 of file BTNodeGraphManager.cpp.

References GetComponentTypeID_Static(), and m_Nodes.

+ Here is the call graph for this function:

◆ GetAllNodes() [1/2]

std::vector< GraphNode * > Olympe::NodeGraph::GetAllNodes ( )

Definition at line 161 of file BTNodeGraphManager.cpp.

References GetComponentTypeID_Static(), and m_Nodes.

Referenced by Olympe::NodeGraphPanel::RenderContextMenu(), and Olympe::NodeGraphPanel::SyncNodePositionsFromImNodes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetAllNodes() [2/2]

std::vector< const GraphNode * > Olympe::NodeGraph::GetAllNodes ( ) const

Definition at line 169 of file BTNodeGraphManager.cpp.

References GetComponentTypeID_Static(), and m_Nodes.

+ Here is the call graph for this function:

◆ GetCommandHistory() [1/2]

CommandHistory * Olympe::NodeGraph::GetCommandHistory ( )

Definition at line 585 of file BTNodeGraphManager.cpp.

References m_commandHistory.

◆ GetCommandHistory() [2/2]

const CommandHistory * Olympe::NodeGraph::GetCommandHistory ( ) const

Definition at line 590 of file BTNodeGraphManager.cpp.

References m_commandHistory.

◆ GetEventRootIds()

const std::vector< uint32_t > & Olympe::NodeGraph::GetEventRootIds ( ) const
private

Get all OnEvent root node IDs.

Definition at line 659 of file BTNodeGraphManager.cpp.

References m_eventRootIds.

◆ GetFilepath()

const std::string & Olympe::NodeGraph::GetFilepath ( ) const
inline

Definition at line 337 of file BTNodeGraphManager.h.

References m_Filepath.

◆ GetNextNodeId()

int Olympe::NodeGraph::GetNextNodeId ( ) const
inline

Definition at line 325 of file BTNodeGraphManager.h.

References m_NextNodeId.

◆ GetNode() [1/2]

GraphNode * Olympe::NodeGraph::GetNode ( int  nodeId)

Definition at line 145 of file BTNodeGraphManager.cpp.

References FindNodeIndex(), GetComponentTypeID_Static(), and m_Nodes.

Referenced by GetNodeParameter(), LinkNodes(), SetNodeParameter(), UnlinkNodes(), and ValidateGraph().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetNode() [2/2]

const GraphNode * Olympe::NodeGraph::GetNode ( int  nodeId) const

Definition at line 153 of file BTNodeGraphManager.cpp.

References FindNodeIndex(), GetComponentTypeID_Static(), and m_Nodes.

+ Here is the call graph for this function:

◆ GetNodeParameter()

std::string Olympe::NodeGraph::GetNodeParameter ( int  nodeId,
const std::string &  paramName 
) const

Definition at line 267 of file BTNodeGraphManager.cpp.

References GetComponentTypeID_Static(), and GetNode().

+ Here is the call graph for this function:

◆ GetRedoDescription()

std::string Olympe::NodeGraph::GetRedoDescription ( ) const

Definition at line 610 of file BTNodeGraphManager.cpp.

References m_commandHistory.

◆ GetRootNodeId()

int Olympe::NodeGraph::GetRootNodeId ( ) const
inline

Definition at line 326 of file BTNodeGraphManager.h.

◆ GetUndoDescription()

std::string Olympe::NodeGraph::GetUndoDescription ( ) const

Definition at line 605 of file BTNodeGraphManager.cpp.

References m_commandHistory.

◆ HasFilepath()

bool Olympe::NodeGraph::HasFilepath ( ) const
inline

Definition at line 339 of file BTNodeGraphManager.h.

References m_Filepath.

Referenced by Olympe::NodeGraphPanel::RenderContent().

+ Here is the caller graph for this function:

◆ IsDirty()

bool Olympe::NodeGraph::IsDirty ( ) const
inline

Definition at line 332 of file BTNodeGraphManager.h.

References m_IsDirty.

Referenced by Olympe::BehaviorTreeRenderer::IsDirty().

+ Here is the caller graph for this function:

◆ IsValidRoot()

bool Olympe::NodeGraph::IsValidRoot ( uint32_t  nodeId) const
private

Check if a node ID is a valid root (main Root or OnEvent root) Root nodes cannot be deleted or moved under other nodes.

Definition at line 627 of file BTNodeGraphManager.cpp.

References m_eventRootIds, and rootNodeId.

◆ LinkNodes()

bool Olympe::NodeGraph::LinkNodes ( int  parentId,
int  childId 
)

Definition at line 177 of file BTNodeGraphManager.cpp.

References Olympe::BT_Decorator, Olympe::GraphNode::childIds, Olympe::GraphNode::decoratorChildId, GetNode(), MarkDirty(), and Olympe::GraphNode::type.

Referenced by Olympe::Blueprint::LinkNodesCommand::Execute(), and Olympe::Blueprint::UnlinkNodesCommand::Undo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MarkDirty()

void Olympe::NodeGraph::MarkDirty ( )
inline

Definition at line 333 of file BTNodeGraphManager.h.

References m_IsDirty.

Referenced by AddEventRoot(), CreateNode(), DeleteNode(), LinkNodes(), RemoveEventRoot(), Olympe::NodeGraphPanel::RenderNodePinsAndContent(), SetNodeParameter(), and UnlinkNodes().

+ Here is the caller graph for this function:

◆ operator=() [1/2]

NodeGraph & Olympe::NodeGraph::operator= ( const NodeGraph other)

Definition at line 50 of file BTNodeGraphManager.cpp.

References editorMetadata, GetComponentTypeID_Static(), m_commandHistory, m_eventRootIds, m_Filepath, m_IsDirty, m_NextNodeId, m_Nodes, name, rootNodeId, and type.

Referenced by ~NodeGraph().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=() [2/2]

NodeGraph & Olympe::NodeGraph::operator= ( NodeGraph &&  other)
noexcept

Definition at line 83 of file BTNodeGraphManager.cpp.

References GetComponentTypeID_Static().

+ Here is the call graph for this function:

◆ PasteNodesFromClipboard()

std::vector< int > Olympe::NodeGraph::PasteNodesFromClipboard ( float  offsetX = 30.0f,
float  offsetY = 30.0f 
)

Definition at line 1206 of file BTNodeGraphManager.cpp.

References GetComponentTypeID_Static(), Olympe::GraphNode::id, m_clipboardData, m_IsDirty, m_NextNodeId, and m_Nodes.

Referenced by Olympe::PasteNodesCommand::Execute().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Redo()

bool Olympe::NodeGraph::Redo ( )

Definition at line 620 of file BTNodeGraphManager.cpp.

References m_commandHistory.

◆ RemoveEventRoot()

void Olympe::NodeGraph::RemoveEventRoot ( uint32_t  nodeId)
private

Remove node ID from event roots array Called when deleting an OnEvent node.

Definition at line 648 of file BTNodeGraphManager.cpp.

References GetComponentTypeID_Static(), m_eventRootIds, and MarkDirty().

+ Here is the call graph for this function:

◆ SetFilepath()

void Olympe::NodeGraph::SetFilepath ( const std::string &  filepath)
inline

Definition at line 338 of file BTNodeGraphManager.h.

References m_Filepath.

◆ SetNodeParameter()

bool Olympe::NodeGraph::SetNodeParameter ( int  nodeId,
const std::string &  paramName,
const std::string &  value 
)

Definition at line 256 of file BTNodeGraphManager.cpp.

References GetComponentTypeID_Static(), GetNode(), and MarkDirty().

Referenced by Olympe::Blueprint::SetParameterCommand::Execute(), and Olympe::Blueprint::SetParameterCommand::Undo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ToJson()

nlohmann::json Olympe::NodeGraph::ToJson ( ) const

◆ Undo()

bool Olympe::NodeGraph::Undo ( )

Definition at line 615 of file BTNodeGraphManager.cpp.

References m_commandHistory.

◆ UnlinkNodes()

bool Olympe::NodeGraph::UnlinkNodes ( int  parentId,
int  childId 
)

Definition at line 203 of file BTNodeGraphManager.cpp.

References Olympe::GraphNode::childIds, Olympe::GraphNode::decoratorChildId, GetComponentTypeID_Static(), GetNode(), and MarkDirty().

Referenced by Olympe::Blueprint::UnlinkNodesCommand::Execute(), and Olympe::Blueprint::LinkNodesCommand::Undo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ValidateGraph()

bool Olympe::NodeGraph::ValidateGraph ( std::string &  errorMsg) const

Definition at line 551 of file BTNodeGraphManager.cpp.

References GetComponentTypeID_Static(), GetNode(), and m_Nodes.

+ Here is the call graph for this function:

Member Data Documentation

◆ editorMetadata

EditorMetadata Olympe::NodeGraph::editorMetadata

Definition at line 297 of file BTNodeGraphManager.h.

Referenced by operator=(), and ToJson().

◆ m_clipboardData

std::vector<ClipboardNode> Olympe::NodeGraph::m_clipboardData

Definition at line 352 of file BTNodeGraphManager.h.

Referenced by CopyNodesToClipboard(), and PasteNodesFromClipboard().

◆ m_commandHistory

std::unique_ptr<CommandHistory> Olympe::NodeGraph::m_commandHistory
private

◆ m_eventRootIds

std::vector<uint32_t> Olympe::NodeGraph::m_eventRootIds
private

Separate array of node IDs that are OnEvent root nodes These nodes represent independent execution trees triggered by EventQueue messages Not connected to the main Root node tree.

Definition at line 372 of file BTNodeGraphManager.h.

Referenced by AddEventRoot(), GetEventRootIds(), IsValidRoot(), operator=(), RemoveEventRoot(), and ToJson().

◆ m_Filepath

std::string Olympe::NodeGraph::m_Filepath
private

Definition at line 361 of file BTNodeGraphManager.h.

Referenced by GetFilepath(), HasFilepath(), operator=(), and SetFilepath().

◆ m_IsDirty

bool Olympe::NodeGraph::m_IsDirty = false
private

◆ m_NextNodeId

int Olympe::NodeGraph::m_NextNodeId = 1
private

◆ m_Nodes

std::vector<GraphNode> Olympe::NodeGraph::m_Nodes
private

◆ name

std::string Olympe::NodeGraph::name

◆ rootNodeId

int Olympe::NodeGraph::rootNodeId = -1

◆ type

std::string Olympe::NodeGraph::type

Definition at line 295 of file BTNodeGraphManager.h.

Referenced by operator=(), and ToJson().


The documentation for this class was generated from the following files: