33#ifndef DVD_SCENE_GRAPH_NODE_H_
34#define DVD_SCENE_GRAPH_NODE_H_
49 struct MemoryBarrierCommand;
56 class BoundsComponent;
57 class TransformSystem;
58 class RenderPassManager;
59 class RenderPassExecutor;
60 class RenderingComponent;
61 class TransformComponent;
64 struct NodeCullParams;
65 struct CameraSnapshot;
66 struct RenderStagePass;
67 struct RenderPassCuller;
78 template<
typename T>
requires std::is_base_of_v<SceneNode, T>
81 template<
typename T>
requires std::is_base_of_v<SceneNode, T>
98 class SceneGraphNodeEditor;
99 class SceneGraphNodeComponent;
100 class SceneGraphNodeSystem;
101 class SceneGraphNodeSceneGraph;
102 class SceneGraphNodeRenderPassCuller;
103 class SceneGraphNodeRenderPassManager;
104 class SceneGraphNodeRelationshipCache;
137 eastl::fixed_vector<SceneGraphNode*, 32, true>
_data;
143 assert( idx <
_count.load() );
216 [[nodiscard]]
bool hasFlag(
const Flags flag )
const noexcept;
220 template <
typename T = SceneNode>
requires std::is_base_of_v<SceneNode, T>
223 return static_cast<T&
>(*_node);
233 template <
typename T = SceneNode>
requires std::is_base_of_v<SceneNode, T>
236 return static_cast<const T&
>(*_node);
240 template <
typename T>
243 return GetComponent<T>();
251 template<
class E,
class... ARGS>
257 template<
class E,
class... ARGS>
265 template<
class T,
class ...P>
requires std::is_base_of_v<SGNComponent, T>
270 return static_cast<T*
>(comp);
274 template<
class T>
requires std::is_base_of_v<SGNComponent, T>
278 RemoveComponent<T>();
287 void loadFromXML(
const ResourcePath& sceneLocation );
289 void loadFromXML(
const boost::property_tree::ptree& pt );
306 GFX::MemoryBarrierCommand& postDrawMemCmd,
307 const RenderStagePass& renderStagePass,
308 const CameraSnapshot& cameraSnapshot,
313 void getAllNodes( vector<SceneGraphNode*>& nodeList );
317 bool saveCache( ByteBuffer& outputBuffer )
const;
319 bool loadCache( ByteBuffer& inputBuffer );
323 static void PostLoad( SceneNode* sceneNode, SceneGraphNode* sgn );
331 bool canDraw( const RenderStagePass& stagePass ) const;
336 template<
bool checkInternalNode = false>
338 template<
bool checkInternalNode = false>
358 std::array<ECS::CustomEvent, EVENT_QUEUE_SIZE>
_events;
387 return node->Hacks._editorComponents;
392 return node->Hacks._editorComponents;
453 node->
prepareRender( rComp, pkg, postDrawMemCmd, renderStagePass, cameraSnapshot, refreshData );
466 return node->
frustumCullNode( params, cullFlags, distanceToClosestPointSQ );
470 return node->
stateCullNode( params, cullFlags, filterMask, distanceToClosestPointSQ );
480 return frustumCullNode( node, params, cullFlags, distanceToClosestPointSQ );
490 return node->
canDraw( stagePass );
502 return node->_relationshipCache;
static void prepareRender(SceneGraphNode *node, RenderingComponent &rComp, RenderPackage &pkg, GFX::MemoryBarrierCommand &postDrawMemCmd, const CameraSnapshot &cameraSnapshot, const RenderStagePass &renderStagePass, const bool refreshData)
static vector< EditorComponent * > & editorComponents(SceneGraphNode *node) noexcept
static const vector< EditorComponent * > & editorComponents(const SceneGraphNode *node) noexcept
static const SGNRelationshipCache & relationshipCache(const SceneGraphNode *node) noexcept
static FrustumCollision frustumCullNode(const SceneGraphNode *node, const NodeCullParams ¶ms, const U16 cullFlags)
static FrustumCollision clippingCullNode(const SceneGraphNode *node, const NodeCullParams ¶ms)
static FrustumCollision frustumCullNode(const SceneGraphNode *node, const NodeCullParams ¶ms, const U16 cullFlags, F32 &distanceToClosestPointSQ)
static FrustumCollision stateCullNode(const SceneGraphNode *node, const NodeCullParams ¶ms, const U16 cullFlags, const U32 filterMask, F32 distanceToClosestPointSQ)
static bool canDraw(const SceneGraphNode *node, const RenderStagePass &stagePass)
static void onNetworkSend(const SceneGraphNode *node, const U32 frameCount)
static void processEvents(SceneGraphNode *node)
static void getAllNodes(SceneGraphNode *node, vector< SceneGraphNode * > &nodeList)
static void updateCollisions(const SceneGraphNode &node, const SceneGraphNode &parentNode, IntersectionContainer &intersections, Mutex &intersectionsLock)
static void changeParent(SceneGraphNode *node)
static void processDeleteQueue(SceneGraphNode *node, vector< size_t > &childList)
static bool saveCache(const SceneGraphNode *node, ByteBuffer &outputBuffer)
static bool loadCache(SceneGraphNode *node, ByteBuffer &inputBuffer)
static void setTransformDirty(SceneGraphNode *node, const U32 transformMask)
Utility class that adds basic GUID management to objects.
PlatformContext & context() noexcept
SceneGraphNode * findChild(U64 nameHash, bool sceneNodeName=false, bool recursive=false) const
Find a child Node using the given name (either SGN name or SceneNode name)
SceneGraph * sceneGraph() noexcept
Return a reference to the parent graph. Operator= should be disabled.
static void PostLoad(SceneNode *sceneNode, SceneGraphNode *sgn)
As opposed to "postLoad()" that's called when the SceneNode is ready for processing,...
void prepareRender(RenderingComponent &rComp, RenderPackage &pkg, GFX::MemoryBarrierCommand &postDrawMemCmd, const RenderStagePass &renderStagePass, const CameraSnapshot &cameraSnapshot, bool refreshData)
Called after preRender and after we rebuild our command buffers. Useful for modifying the command buf...
bool HasComponents(ComponentType componentType) const
void SendAndDispatchEvent(ARGS &&... eventArgs) const
Sends a global event with dispatched happening immediately. Avoid using often. Bad for performance.
FrustumCollision frustumCullNode(const NodeCullParams ¶ms, U16 cullFlags, F32 &distanceToClosestPointSQ) const
void setParentInternal()
Changes this node's parent.
void clearFlag(Flags flag, bool recursive=true)
Clearing a flag might propagate to child nodes (e.g. selection).
void RemoveSGNComponentInternal(SGNComponent *comp)
~SceneGraphNode() override
If we are destroying the current graph node.
FORCE_INLINE SceneNodeHandle handle() const noexcept
bool intersect(const Ray &intersectionRay, vec2< F32 > range, vector< SGNRayResult > &intersections) const
Find the graph nodes whom's bounding boxes intersects the given ray.
void setFlag(Flags flag, bool recursive=true)
General purpose flag management. Certain flags propagate to children (e.g. selection)!
FrustumCollision stateCullNode(const NodeCullParams ¶ms, U16 cullFlags, U32 filterMask, const F32 distanceToClosestPointSQ) const
Returns a collision result that determines if the node SHOULD be culled (is not visible for the curre...
void updateCollisions(const SceneGraphNode &parentNode, IntersectionContainer &intersections, Mutex &intersectionsLock) const
struct Divide::SceneGraphNode::events Events
void setTransformDirty(U32 transformMask)
Called by the TransformComponent whenever the transform changed.
void SendEvent(ECS::CustomEvent &&event)
void RemoveComponents(U32 componentMask)
bool loadCache(ByteBuffer &inputBuffer)
Similar to the loadFromXML call but is geared towards temporary state (e.g. save game)
ECS::ECSEngine & GetECSEngine() const noexcept
This indirect is used to avoid including ECS headers in this file, but we still need the ECS engine f...
PROPERTY_R(U64, nameHash, 0u)
bool isChildOfType(U16 typeMask) const
Checks if we have a parent matching the typeMask. We check recursively until we hit the top node (if ...
PROPERTY_R(U32, nodeFlags, 0u)
const ChildContainer & getChildren() const noexcept
bool isChild(const SceneGraphNode *target, bool recursive) const
Returns true if the specified target node is a parent or grandparent(if recursive == true) of the cur...
PROPERTY_R(NodeUsageContext, usageContext, NodeUsageContext::NODE_STATIC)
PROPERTY_R(Str< 64 >, name, "")
void processEvents()
Process any events that might of queued up during the ECS Update stages.
void onNetworkSend(U32 frameCount) const
Called whenever we send a networking packet from our NetworkingComponent (if any)....
void setParent(SceneGraphNode *parent, bool defer=false)
Changing a node's parent means removing this node from the current parent's child list and appending ...
void SendEvent(ARGS &&... eventArgs) const
Sends a global event but dispatched is handled between update steps.
PROPERTY_R(bool, serialize, true)
void invalidateRelationshipCache(SceneGraphNode *source=nullptr)
Only called from withing "setParent()" (which is also called from "addChildNode()")....
bool isRelated(const SceneGraphNode *target) const
Returns true if the current node is related somehow to the specified target node (see RelationshipTyp...
void changeUsageContext(const NodeUsageContext &newContext)
SceneGraphNode * addChildNode(const SceneGraphNodeDescriptor &descriptor)
Add child node increments the node's ref counter if the node was already added to the scene graph.
struct Divide::SceneGraphNode::hacks Hacks
void processDeleteQueue(vector< size_t > &childList)
Destructs all of the nodes specified in the list and removes them from the _children container.
PROPERTY_R(U32, componentMask, 0u)
FORCE_INLINE T * get() const
Returns a pointer to a specific component. Returns null if the SGN does not have the component reques...
POINTER_R(SceneNode, node, nullptr)
void AddComponents(U32 componentMask, bool allowDuplicates)
FrustumCollision clippingCullNode(const NodeCullParams ¶ms) const
void postLoad()
Invoked by the contained SceneNode when it finishes all of its internal loading and is ready for proc...
SGNRelationshipCache _relationshipCache
PROPERTY_R(I64, queuedNewParent, -1)
T * AddSGNComponent(P &&... param)
void AddSGNComponentInternal(SGNComponent *comp)
bool hasFlag(const Flags flag) const noexcept
Returns true only if the current node has the specified flag. Does not check children!
FORCE_INLINE U32 dataFlag() const noexcept
POINTER_R(SceneGraph, sceneGraph, nullptr)
bool saveCache(ByteBuffer &outputBuffer) const
Similar to the saveToXML call but is geared towards temporary state (e.g. save game)
POINTER_R(ECS::ComponentManager, compManager, nullptr)
PROPERTY_R(U32, instanceCount, 1u)
void loadFromXML(const ResourcePath &sceneLocation)
const SceneGraphNodeDescriptor _descriptor
const T & getNode() const noexcept
bool removeChildNode(const SceneGraphNode *node, bool recursive=true, bool deleteNode=true)
void getAllNodes(vector< SceneGraphNode * > &nodeList)
Returns a bottom-up list(leafs -> root) of all of the nodes parented under the current one.
void RemoveSGNComponent()
Remove a component by type (if any). Because we have a limit of one component type per node,...
ChildContainer & getChildren() noexcept
bool canDraw(const RenderStagePass &stagePass) const
void saveToXML(const ResourcePath &sceneLocation, DELEGATE< void, std::string_view > msgCallback={}) const
Serialization: save to XML file.
POINTER_R(SceneGraphNode, parent, nullptr)
SceneGraphNode * findChildInternal(U64 nameHash, bool recursive=false) const
bool removeNodesByType(SceneNodeType nodeType)
If this function returns true, at least one node of the specified type was removed.
void sceneUpdate(U64 deltaTimeUS, SceneState &sceneState)
Called from parent SceneGraph.
void SendEventAndDispatch(ARGS &&... eventArgs) const
void SendEvent(ARGS &&... eventArgs) const
Handle console commands that start with a forward slash.
NodeUsageContext
Usage context affects lighting, navigation, physics, etc.
DELEGATE_STD< Ret, Args... > DELEGATE
eastl::fixed_vector< IntersectionRecord, 32u, true > IntersectionContainer
SceneNodeType
ToDo: Move particle emitter to components (it will make them way more dynamic) - Ionut.
std::shared_mutex SharedMutex
eastl::vector< Type > vector
std::shared_lock< mutex > SharedLock
SceneNodeHandle FromHandle(const Handle< T > handle)
constexpr T toBit(const T X)
Converts an arbitrary positive integer value to a bitwise value used for masks.
Handle< T > ToHandle(const SceneNodeHandle handle)
SceneGraphNode * getChild(const U32 idx)
Return a specific child by index. Does not recurse.
eastl::fixed_vector< SceneGraphNode *, 32, true > _data
static constexpr size_t EVENT_QUEUE_SIZE
std::array< std::atomic_bool, EVENT_QUEUE_SIZE > _eventsFreeList
std::array< ECS::CustomEvent, EVENT_QUEUE_SIZE > _events
vector< EditorComponent * > _editorComponents
SceneNodeHandle _nodeHandle
NodeUsageContext _usageContext
Handle< SceneNode > _handle
DELEGATE< void > _deleter