![]() |
Divide Framework 0.1
A free and open-source 3D Framework under heavy development
|
#include <SceneGraphNode.h>
Classes | |
struct | ChildContainer |
struct | events |
struct | hacks |
Public Types | |
enum class | Flags : U16 { LOADING = toBit( 1 ) , HOVERED = toBit( 2 ) , SELECTED = toBit( 3 ) , ACTIVE = toBit( 4 ) , VISIBILITY_LOCKED = toBit( 5 ) , PARENT_POST_RENDERED = toBit( 6 ) , SELECTION_LOCKED = toBit( 7 ) , IS_CONTAINER = toBit( 8 ) , COUNT = 9 } |
Public Member Functions | |
SceneGraphNode (PlatformContext &context, SceneGraph *sceneGraph, const SceneGraphNodeDescriptor &descriptor) | |
Avoid creating SGNs directly. Use the "addChildNode" on an existing node (even root) or "addNode" on the existing SceneGraph. | |
~SceneGraphNode () override | |
If we are destroying the current graph node. | |
SceneGraph * | sceneGraph () noexcept |
Return a reference to the parent graph. Operator= should be disabled. | |
SceneGraphNode * | addChildNode (const SceneGraphNodeDescriptor &descriptor) |
Add child node increments the node's ref counter if the node was already added to the scene graph. | |
bool | removeChildNode (const SceneGraphNode *node, bool recursive=true, bool deleteNode=true) |
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) | |
SceneGraphNode * | findChild (I64 GUID, bool sceneNodeGuid=false, bool recursive=false) const |
Find a child using the given SGN or SceneNode GUID. | |
bool | removeNodesByType (SceneNodeType nodeType) |
If this function returns true, at least one node of the specified type was removed. | |
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 it to the new parent's list (happens after a full frame) | |
bool | isChildOfType (U16 typeMask) const |
Checks if we have a parent matching the typeMask. We check recursively until we hit the top node (if ignoreRoot is false, top node is Root) | |
bool | isRelated (const SceneGraphNode *target) const |
Returns true if the current node is related somehow to the specified target node (see RelationshipType enum for more details) | |
bool | isRelated (const SceneGraphNode *target, SGNRelationshipCache::RelationshipType relationship) const |
Returns true if the current node is related to the specified target node in the specified way (see RelationshipType enum for more details) | |
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 current node. | |
ChildContainer & | getChildren () noexcept |
const ChildContainer & | getChildren () const noexcept |
void | sceneUpdate (U64 deltaTimeUS, SceneState &sceneState) |
Called from parent SceneGraph. | |
void | postLoad () |
Invoked by the contained SceneNode when it finishes all of its internal loading and is ready for processing. | |
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 | changeUsageContext (const NodeUsageContext &newContext) |
void | setFlag (Flags flag, bool recursive=true) |
General purpose flag management. Certain flags propagate to children (e.g. selection)! | |
void | clearFlag (Flags flag, bool recursive=true) |
Clearing a flag might propagate to child nodes (e.g. selection). | |
bool | hasFlag (const Flags flag) const noexcept |
Returns true only if the current node has the specified flag. Does not check children! | |
template<typename T = SceneNode> requires std::is_base_of_v<SceneNode, T> | |
T & | getNode () noexcept |
FORCE_INLINE SceneNodeHandle | handle () const noexcept |
template<typename T = SceneNode> requires std::is_base_of_v<SceneNode, T> | |
const T & | getNode () const noexcept |
template<typename T > | |
FORCE_INLINE T * | get () const |
Returns a pointer to a specific component. Returns null if the SGN does not have the component requested. | |
FORCE_INLINE U32 | dataFlag () const noexcept |
void | SendEvent (ECS::CustomEvent &&event) |
template<class E , class... ARGS> | |
void | SendEvent (ARGS &&... eventArgs) const |
Sends a global event but dispatched is handled between update steps. | |
template<class E , class... ARGS> | |
void | SendAndDispatchEvent (ARGS &&... eventArgs) const |
Sends a global event with dispatched happening immediately. Avoid using often. Bad for performance. | |
template<class T , class ... P> requires std::is_base_of_v<SGNComponent, T> | |
T * | AddSGNComponent (P &&... param) |
template<class T > requires std::is_base_of_v<SGNComponent, T> | |
void | RemoveSGNComponent () |
Remove a component by type (if any). Because we have a limit of one component type per node, this works as expected. | |
void | AddComponents (U32 componentMask, bool allowDuplicates) |
void | RemoveComponents (U32 componentMask) |
bool | HasComponents (ComponentType componentType) const |
bool | HasComponents (U32 componentMask) const |
void | saveToXML (const ResourcePath &sceneLocation, DELEGATE< void, std::string_view > msgCallback={}) const |
Serialization: save to XML file. | |
void | loadFromXML (const ResourcePath &sceneLocation) |
void | loadFromXML (const boost::property_tree::ptree &pt) |
Serialization: load from XML file (expressed as a boost property_tree) | |
template<> | |
TransformComponent * | get () const |
template<> | |
BoundsComponent * | get () const |
template<> | |
RenderingComponent * | get () const |
![]() | |
EntityTypeId | GetStaticEntityTypeID () const override |
Entity () | |
virtual | ~Entity () |
![]() | |
IEntity () | |
virtual | ~IEntity () |
template<class T > | |
T * | GetComponent () const |
template<class T , class ... P> | |
T * | AddComponent (P &&... param) |
template<class T > | |
void | RemoveComponent () |
void | RemoveAllComponents () |
void | PassDataToAllComponents (const ECS::CustomEvent &evt) |
bool | operator== (const IEntity &rhs) const |
bool | operator!= (const IEntity &rhs) const |
bool | operator== (const IEntity *rhs) const |
bool | operator!= (const IEntity *rhs) const |
virtual EntityTypeId | GetStaticEntityTypeID () const =0 |
EntityId | GetEntityID () const |
void | SetActive (bool active) |
bool | IsActive () const |
virtual void | OnEnable () |
virtual void | OnDisable () |
![]() | |
GUIDWrapper () noexcept | |
GUIDWrapper (const GUIDWrapper &old) noexcept | |
GUIDWrapper (GUIDWrapper &&old) noexcept | |
virtual | ~GUIDWrapper ()=default |
FORCE_INLINE I64 | getGUID () const noexcept |
GUIDWrapper & | operator= (const GUIDWrapper &old)=delete |
GUIDWrapper & | operator= (GUIDWrapper &&other)=delete |
![]() | |
PlatformContextComponent (PlatformContext &context) noexcept | |
virtual | ~PlatformContextComponent ()=default |
PlatformContext & | context () noexcept |
const PlatformContext & | context () const noexcept |
![]() | |
NonCopyable (const NonCopyable &)=delete | |
NonCopyable & | operator= (const NonCopyable &)=delete |
NonCopyable (NonCopyable &&)=default | |
NonCopyable & | operator= (NonCopyable &&)=default |
Protected Member Functions | |
void | updateCollisions (const SceneGraphNode &parentNode, IntersectionContainer &intersections, Mutex &intersectionsLock) const |
![]() | |
NonCopyable ()=default | |
~NonCopyable ()=default | |
Private Member Functions | |
void | processEvents () |
Process any events that might of queued up during the ECS Update stages. | |
SceneGraphNode * | addChildNode (SceneGraphNode *sgn) |
Add a new SceneGraphNode to the current node's child list based on a SceneNode. | |
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 current stage). | |
FrustumCollision | clippingCullNode (const NodeCullParams ¶ms) const |
FrustumCollision | frustumCullNode (const NodeCullParams ¶ms, U16 cullFlags, F32 &distanceToClosestPointSQ) const |
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 buffer that's going to be used for this RenderStagePass. | |
void | onNetworkSend (U32 frameCount) const |
Called whenever we send a networking packet from our NetworkingComponent (if any). FrameCount is the frame ID sent with the packet. | |
void | getAllNodes (vector< SceneGraphNode * > &nodeList) |
Returns a bottom-up list(leafs -> root) of all of the nodes parented under the current one. | |
void | processDeleteQueue (vector< size_t > &childList) |
Destructs all of the nodes specified in the list and removes them from the _children container. | |
bool | saveCache (ByteBuffer &outputBuffer) const |
Similar to the saveToXML call but is geared towards temporary state (e.g. save game) | |
bool | loadCache (ByteBuffer &inputBuffer) |
Similar to the loadFromXML call but is geared towards temporary state (e.g. save game) | |
void | setTransformDirty (U32 transformMask) |
Called by the TransformComponent whenever the transform changed. | |
ECS::ECSEngine & | GetECSEngine () const noexcept |
This indirect is used to avoid including ECS headers in this file, but we still need the ECS engine for templated methods. | |
void | invalidateRelationshipCache (SceneGraphNode *source=nullptr) |
Only called from withing "setParent()" (which is also called from "addChildNode()"). Used to mark the existing relationship cache as invalid. | |
void | setParentInternal () |
Changes this node's parent. | |
bool | canDraw (const RenderStagePass &stagePass) const |
void | AddSGNComponentInternal (SGNComponent *comp) |
void | RemoveSGNComponentInternal (SGNComponent *comp) |
template<bool checkInternalNode = false> | |
SceneGraphNode * | findChildInternal (U64 nameHash, bool recursive=false) const |
template<bool checkInternalNode = false> | |
SceneGraphNode * | findChildInternal (I64 GUID, bool recursive=false) const |
POINTER_R (SceneGraph, sceneGraph, nullptr) | |
POINTER_R (SceneNode, node, nullptr) | |
POINTER_R (ECS::ComponentManager, compManager, nullptr) | |
POINTER_R (SceneGraphNode, parent, nullptr) | |
PROPERTY_R (Str< 64 >, name, "") | |
PROPERTY_R (U64, nameHash, 0u) | |
PROPERTY_R (I64, queuedNewParent, -1) | |
PROPERTY_R (U32, componentMask, 0u) | |
PROPERTY_R (U32, nodeFlags, 0u) | |
PROPERTY_R (U32, instanceCount, 1u) | |
PROPERTY_R (bool, serialize, true) | |
PROPERTY_R (NodeUsageContext, usageContext, NodeUsageContext::NODE_STATIC) | |
Static Private Member Functions | |
static void | PostLoad (SceneNode *sceneNode, SceneGraphNode *sgn) |
As opposed to "postLoad()" that's called when the SceneNode is ready for processing, this call is used as a callback for when the SceneNode finishes loading as a Resource. postLoad() is called after this always. | |
Private Attributes | |
SGNRelationshipCache | _relationshipCache |
ChildContainer | _children |
struct Divide::SceneGraphNode::hacks | Hacks |
struct Divide::SceneGraphNode::events | Events |
I8 | _frustPlaneCache = -1 |
const SceneGraphNodeDescriptor | _descriptor |
Additional Inherited Members | |
![]() | |
static I64 | generateGUID () noexcept |
![]() | |
static const EntityTypeId | STATIC_ENTITY_TYPE_ID |
![]() | |
DECLARE_STATIC_LOGGER EntityId | m_EntityID |
bool | m_Active |
![]() | |
const I64 | _guid |
![]() | |
PlatformContext & | _context |
![]() | |
static std::shared_mutex | s_ComponentManagerLock |
Definition at line 107 of file SceneGraphNode.h.
|
strong |
Enumerator | |
---|---|
LOADING | |
HOVERED | |
SELECTED | |
ACTIVE | |
VISIBILITY_LOCKED | |
PARENT_POST_RENDERED | |
SELECTION_LOCKED | |
IS_CONTAINER | |
COUNT |
Definition at line 121 of file SceneGraphNode.h.
|
explicit |
Avoid creating SGNs directly. Use the "addChildNode" on an existing node (even root) or "addNode" on the existing SceneGraph.
Definition at line 152 of file SceneGraphNode.cpp.
|
override |
If we are destroying the current graph node.
Definition at line 206 of file SceneGraphNode.cpp.
SceneGraphNode * Divide::SceneGraphNode::addChildNode | ( | const SceneGraphNodeDescriptor & | descriptor | ) |
Add child node increments the node's ref counter if the node was already added to the scene graph.
Add a new SceneGraphNode to the current node's child list based on a SceneNode.
Definition at line 819 of file SceneGraphNode.cpp.
|
private |
Add a new SceneGraphNode to the current node's child list based on a SceneNode.
Definition at line 336 of file SceneGraphNode.cpp.
void Divide::SceneGraphNode::AddComponents | ( | U32 | componentMask, |
bool | allowDuplicates | ||
) |
Definition at line 48 of file SceneGraphNode.cpp.
|
inline |
Emplacement call for an ECS component. Pass in the component's constructor parameters. Can only add one component of a single type. This may be bad for scripts, but there are workarounds
Definition at line 266 of file SceneGraphNode.h.
|
private |
Definition at line 63 of file SceneGraphNode.cpp.
|
private |
Definition at line 719 of file SceneGraphNode.cpp.
void Divide::SceneGraphNode::changeUsageContext | ( | const NodeUsageContext & | newContext | ) |
Definition at line 235 of file SceneGraphNode.cpp.
void Divide::SceneGraphNode::clearFlag | ( | Flags | flag, |
bool | recursive = true |
||
) |
Clearing a flag might propagate to child nodes (e.g. selection).
Definition at line 1174 of file SceneGraphNode.cpp.
|
private |
Definition at line 913 of file SceneGraphNode.cpp.
|
inlinenoexcept |
Definition at line 246 of file SceneGraphNode.h.
SceneGraphNode * Divide::SceneGraphNode::findChild | ( | I64 | GUID, |
bool | sceneNodeGuid = false , |
||
bool | recursive = false |
||
) | const |
Find a child using the given SGN or SceneNode GUID.
Definition at line 504 of file SceneGraphNode.cpp.
SceneGraphNode * Divide::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)
Definition at line 498 of file SceneGraphNode.cpp.
|
inlineprivate |
Definition at line 138 of file SceneGraphNode.inl.
|
inlineprivate |
Definition at line 98 of file SceneGraphNode.inl.
|
private |
Definition at line 941 of file SceneGraphNode.cpp.
|
inline |
Returns a pointer to a specific component. Returns null if the SGN does not have the component requested.
Definition at line 241 of file SceneGraphNode.h.
|
inline |
Definition at line 59 of file SceneGraphNode.inl.
|
inline |
Definition at line 65 of file SceneGraphNode.inl.
|
inline |
Definition at line 71 of file SceneGraphNode.inl.
|
private |
Returns a bottom-up list(leafs -> root) of all of the nodes parented under the current one.
Definition at line 547 of file SceneGraphNode.cpp.
|
inlinenoexcept |
Definition at line 195 of file SceneGraphNode.h.
|
inlinenoexcept |
Definition at line 191 of file SceneGraphNode.h.
|
privatenoexcept |
This indirect is used to avoid including ECS headers in this file, but we still need the ECS engine for templated methods.
Definition at line 43 of file SceneGraphNode.cpp.
|
inlinenoexcept |
Always use the level of redirection needed to reduce virtual function overhead. Use getNode<SceneNode> if you need material properties for ex. or getNode<SkinnedSubMesh> for animation transforms
Definition at line 234 of file SceneGraphNode.h.
|
inlinenoexcept |
Always use the level of redirection needed to reduce virtual function overhead. Use getNode<SceneNode> if you need material properties for ex. or getNode<SkinnedSubMesh> for animation transforms
Definition at line 221 of file SceneGraphNode.h.
|
inlinenoexcept |
Definition at line 226 of file SceneGraphNode.h.
bool Divide::SceneGraphNode::HasComponents | ( | ComponentType | componentType | ) | const |
Definition at line 128 of file SceneGraphNode.cpp.
bool Divide::SceneGraphNode::HasComponents | ( | U32 | componentMask | ) | const |
Definition at line 133 of file SceneGraphNode.cpp.
|
noexcept |
Returns true only if the current node has the specified flag. Does not check children!
Definition at line 53 of file SceneGraphNode.inl.
bool Divide::SceneGraphNode::intersect | ( | const Ray & | intersectionRay, |
vec2< F32 > | range, | ||
vector< SGNRayResult > & | intersections | ||
) | const |
Find the graph nodes whom's bounding boxes intersects the given ray.
Definition at line 510 of file SceneGraphNode.cpp.
|
private |
Only called from withing "setParent()" (which is also called from "addChildNode()"). Used to mark the existing relationship cache as invalid.
Definition at line 1020 of file SceneGraphNode.cpp.
bool Divide::SceneGraphNode::isChild | ( | const SceneGraphNode * | target, |
bool | recursive | ||
) | const |
Returns true if the specified target node is a parent or grandparent(if recursive == true) of the current node.
Definition at line 483 of file SceneGraphNode.cpp.
bool Divide::SceneGraphNode::isChildOfType | ( | U16 | typeMask | ) | const |
Checks if we have a parent matching the typeMask. We check recursively until we hit the top node (if ignoreRoot is false, top node is Root)
Definition at line 446 of file SceneGraphNode.cpp.
bool Divide::SceneGraphNode::isRelated | ( | const SceneGraphNode * | target | ) | const |
Returns true if the current node is related somehow to the specified target node (see RelationshipType enum for more details)
Definition at line 461 of file SceneGraphNode.cpp.
bool Divide::SceneGraphNode::isRelated | ( | const SceneGraphNode * | target, |
SGNRelationshipCache::RelationshipType | relationship | ||
) | const |
Returns true if the current node is related to the specified target node in the specified way (see RelationshipType enum for more details)
Definition at line 472 of file SceneGraphNode.cpp.
|
private |
Similar to the loadFromXML call but is geared towards temporary state (e.g. save game)
Definition at line 1058 of file SceneGraphNode.cpp.
void Divide::SceneGraphNode::loadFromXML | ( | const boost::property_tree::ptree & | pt | ) |
Serialization: load from XML file (expressed as a boost property_tree)
Definition at line 1115 of file SceneGraphNode.cpp.
void Divide::SceneGraphNode::loadFromXML | ( | const ResourcePath & | sceneLocation | ) |
Definition at line 1103 of file SceneGraphNode.cpp.
|
private |
Called whenever we send a networking packet from our NetworkingComponent (if any). FrameCount is the frame ID sent with the packet.
Definition at line 702 of file SceneGraphNode.cpp.
|
private |
|
private |
|
private |
|
private |
void Divide::SceneGraphNode::postLoad | ( | ) |
Invoked by the contained SceneNode when it finishes all of its internal loading and is ready for processing.
Definition at line 438 of file SceneGraphNode.cpp.
|
staticprivate |
As opposed to "postLoad()" that's called when the SceneNode is ready for processing, this call is used as a callback for when the SceneNode finishes loading as a Resource. postLoad() is called after this always.
Definition at line 354 of file SceneGraphNode.cpp.
|
private |
Called after preRender and after we rebuild our command buffers. Useful for modifying the command buffer that's going to be used for this RenderStagePass.
Definition at line 661 of file SceneGraphNode.cpp.
|
private |
Destructs all of the nodes specified in the list and removes them from the _children container.
Definition at line 562 of file SceneGraphNode.cpp.
|
private |
Process any events that might of queued up during the ECS Update stages.
Definition at line 598 of file SceneGraphNode.cpp.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
bool Divide::SceneGraphNode::removeChildNode | ( | const SceneGraphNode * | node, |
bool | recursive = true , |
||
bool | deleteNode = true |
||
) |
If this function returns true, the node will no longer be part of the scene hierarchy. If the node is not a child of the calling node, we will recursively look in all of its children for a match
Definition at line 396 of file SceneGraphNode.cpp.
void Divide::SceneGraphNode::RemoveComponents | ( | U32 | componentMask | ) |
Definition at line 116 of file SceneGraphNode.cpp.
bool Divide::SceneGraphNode::removeNodesByType | ( | SceneNodeType | nodeType | ) |
If this function returns true, at least one node of the specified type was removed.
Definition at line 364 of file SceneGraphNode.cpp.
|
inline |
Remove a component by type (if any). Because we have a limit of one component type per node, this works as expected.
Definition at line 275 of file SceneGraphNode.h.
|
private |
Definition at line 83 of file SceneGraphNode.cpp.
|
private |
Similar to the saveToXML call but is geared towards temporary state (e.g. save game)
Definition at line 1050 of file SceneGraphNode.cpp.
void Divide::SceneGraphNode::saveToXML | ( | const ResourcePath & | sceneLocation, |
DELEGATE< void, std::string_view > | msgCallback = {} |
||
) | const |
Serialization: save to XML file.
Definition at line 1068 of file SceneGraphNode.cpp.
|
inlinenoexcept |
Return a reference to the parent graph. Operator= should be disabled.
Definition at line 156 of file SceneGraphNode.h.
void Divide::SceneGraphNode::sceneUpdate | ( | U64 | deltaTimeUS, |
SceneState & | sceneState | ||
) |
Called from parent SceneGraph.
Definition at line 578 of file SceneGraphNode.cpp.
|
inline |
Sends a global event with dispatched happening immediately. Avoid using often. Bad for performance.
Definition at line 258 of file SceneGraphNode.h.
|
inline |
Sends a global event but dispatched is handled between update steps.
Definition at line 252 of file SceneGraphNode.h.
void Divide::SceneGraphNode::SendEvent | ( | ECS::CustomEvent && | event | ) |
Definition at line 1202 of file SceneGraphNode.cpp.
void Divide::SceneGraphNode::setFlag | ( | Flags | flag, |
bool | recursive = true |
||
) |
General purpose flag management. Certain flags propagate to children (e.g. selection)!
Definition at line 1146 of file SceneGraphNode.cpp.
void Divide::SceneGraphNode::setParent | ( | SceneGraphNode * | parent, |
bool | defer = false |
||
) |
Changing a node's parent means removing this node from the current parent's child list and appending it to the new parent's list (happens after a full frame)
Change current SceneGraphNode's parent.
Definition at line 253 of file SceneGraphNode.cpp.
|
private |
Changes this node's parent.
Definition at line 266 of file SceneGraphNode.cpp.
|
private |
Called by the TransformComponent whenever the transform changed.
Definition at line 138 of file SceneGraphNode.cpp.
|
private |
Returns a collision result that determines if the node SHOULD be culled (is not visible for the current stage).
Definition at line 831 of file SceneGraphNode.cpp.
|
protected |
Definition at line 1230 of file SceneGraphNode.cpp.
|
friend |
Definition at line 112 of file SceneGraphNode.h.
|
friend |
Definition at line 111 of file SceneGraphNode.h.
|
friend |
Definition at line 117 of file SceneGraphNode.h.
|
friend |
Definition at line 115 of file SceneGraphNode.h.
|
friend |
Definition at line 116 of file SceneGraphNode.h.
|
friend |
Definition at line 114 of file SceneGraphNode.h.
|
friend |
Definition at line 113 of file SceneGraphNode.h.
|
private |
Definition at line 343 of file SceneGraphNode.h.
|
private |
Definition at line 378 of file SceneGraphNode.h.
|
mutableprivate |
Definition at line 375 of file SceneGraphNode.h.
|
private |
Definition at line 342 of file SceneGraphNode.h.
|
private |
|
private |