// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Content/BinaryAsset.h" #include "Engine/Visject/VisjectGraph.h" class BehaviorKnowledge; class BehaviorTree; class BehaviorTreeNode; class BehaviorTreeRootNode; /// /// Behavior Tree graph node. /// class BehaviorTreeGraphNode : public VisjectGraphNode<> { public: // Instance of the graph node. BehaviorTreeNode* Instance = nullptr; ~BehaviorTreeGraphNode(); }; /// /// Behavior Tree graph. /// class BehaviorTreeGraph : public VisjectGraph { friend BehaviorTree; public: // Instance of the graph root node. BehaviorTreeRootNode* Root = nullptr; // Total count of used nodes. int32 NodesCount = 0; // Total size of the nodes states memory. int32 NodesStatesSize = 0; // [VisjectGraph] void Clear() override; bool onNodeLoaded(Node* n) override; private: void Setup(BehaviorTree* tree); void SetupRecursive(Node& node); }; /// /// Behavior Tree graph executor runtime. /// class BehaviorTreeExecutor : public VisjectExecutor { }; /// /// Behavior Tree asset with AI logic graph. /// /// API_CLASS(NoSpawn, Sealed) class FLAXENGINE_API BehaviorTree : public BinaryAsset { DECLARE_BINARY_ASSET_HEADER(BehaviorTree, 1); public: /// /// The Behavior Tree graph. /// BehaviorTreeGraph Graph; /// /// Gets a specific node instance object from Behavior Tree. /// /// The unique node identifier (Visject surface). /// The node instance or null if cannot get it. API_FUNCTION() BehaviorTreeNode* GetNodeInstance(uint32 id); /// /// Tries to load surface graph from the asset. /// /// The surface data or empty if failed to load it. API_FUNCTION() BytesContainer LoadSurface(); #if USE_EDITOR /// /// Updates the graph surface (save new one, discard cached data, reload asset). /// /// Stream with graph data. /// True if cannot save it, otherwise false. API_FUNCTION() bool SaveSurface(const BytesContainer& data); #endif private: #if USE_EDITOR void OnScriptsReloadStart(); void OnScriptsReloadEnd(); #endif public: // [BinaryAsset] void OnScriptingDispose() override; #if USE_EDITOR void GetReferences(Array& output) const override; #endif protected: // [BinaryAsset] LoadResult load() override; void unload(bool isReloading) override; AssetChunksFlag getChunksToPreload() const override; };