Added Add and Remove Child Events to SceneGraph
This commit is contained in:
parent
eeab3494ba
commit
ac217ffe97
|
@ -11,9 +11,11 @@ constexpr SHEventIdentifier SH_ENTITY_CREATION_EVENT { 2 };
|
||||||
constexpr SHEventIdentifier SH_COMPONENT_ADDED_EVENT { 3 };
|
constexpr SHEventIdentifier SH_COMPONENT_ADDED_EVENT { 3 };
|
||||||
constexpr SHEventIdentifier SH_COMPONENT_REMOVED_EVENT { 4 };
|
constexpr SHEventIdentifier SH_COMPONENT_REMOVED_EVENT { 4 };
|
||||||
constexpr SHEventIdentifier SH_SCENEGRAPH_CHANGE_PARENT_EVENT { 5 };
|
constexpr SHEventIdentifier SH_SCENEGRAPH_CHANGE_PARENT_EVENT { 5 };
|
||||||
constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_ADDED_EVENT { 6 };
|
constexpr SHEventIdentifier SH_SCENEGRAPH_ADD_CHILD_EVENT { 6 };
|
||||||
constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_REMOVED_EVENT { 7 };
|
constexpr SHEventIdentifier SH_SCENEGRAPH_REMOVE_CHILD_EVENT { 7 };
|
||||||
constexpr SHEventIdentifier SH_EDITOR_ON_PLAY_EVENT { 8 };
|
constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_ADDED_EVENT { 8 };
|
||||||
constexpr SHEventIdentifier SH_EDITOR_ON_PAUSE_EVENT { 9 };
|
constexpr SHEventIdentifier SH_PHYSICS_COLLIDER_REMOVED_EVENT { 9 };
|
||||||
constexpr SHEventIdentifier SH_EDITOR_ON_STOP_EVENT { 10 };
|
constexpr SHEventIdentifier SH_EDITOR_ON_PLAY_EVENT { 10 };
|
||||||
|
constexpr SHEventIdentifier SH_EDITOR_ON_PAUSE_EVENT { 11 };
|
||||||
|
constexpr SHEventIdentifier SH_EDITOR_ON_STOP_EVENT { 12 };
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
* \file SHSceneGraph.cpp
|
* \file SHSceneGraph.cpp
|
||||||
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
||||||
* \brief Implementation for a Scene Graph & Scene Nodes.
|
* \brief Implementation for a Scene Graph.
|
||||||
*
|
*
|
||||||
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||||
* disclosure of this file or its contents without the prior written consent
|
* disclosure of this file or its contents without the prior written consent
|
||||||
|
@ -477,6 +477,14 @@ namespace SHADE
|
||||||
|
|
||||||
newChild->parent = node;
|
newChild->parent = node;
|
||||||
node->children.emplace_back(newChild);
|
node->children.emplace_back(newChild);
|
||||||
|
|
||||||
|
const SHSceneGraphAddChildEvent EVENT_DATA
|
||||||
|
{
|
||||||
|
.parent = node
|
||||||
|
, .childAdded = newChild
|
||||||
|
};
|
||||||
|
|
||||||
|
SHEventManager::BroadcastEvent<SHSceneGraphAddChildEvent>(EVENT_DATA, SH_SCENEGRAPH_ADD_CHILD_EVENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHSceneGraph::RemoveChild(SHSceneNode* node, SHSceneNode* childToRemove)
|
void SHSceneGraph::RemoveChild(SHSceneNode* node, SHSceneNode* childToRemove)
|
||||||
|
@ -490,6 +498,14 @@ namespace SHADE
|
||||||
|
|
||||||
childIter = node->children.erase(childIter);
|
childIter = node->children.erase(childIter);
|
||||||
childToRemove->parent = nullptr;
|
childToRemove->parent = nullptr;
|
||||||
|
|
||||||
|
const SHSceneGraphRemoveChildEvent EVENT_DATA
|
||||||
|
{
|
||||||
|
.parent = node
|
||||||
|
, .childRemoved = childToRemove
|
||||||
|
};
|
||||||
|
|
||||||
|
SHEventManager::BroadcastEvent<SHSceneGraphRemoveChildEvent>(EVENT_DATA, SH_SCENEGRAPH_REMOVE_CHILD_EVENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHSceneGraph::TraverseAndInvokeFunction(const SHSceneNode* node, const UnaryFunction& function)
|
void SHSceneGraph::TraverseAndInvokeFunction(const SHSceneNode* node, const UnaryFunction& function)
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "ECS_Base/Entity/SHEntity.h"
|
#include "ECS_Base/Entity/SHEntity.h"
|
||||||
#include "SH_API.h"
|
#include "SH_API.h"
|
||||||
#include "SHSceneNode.h"
|
#include "SHSceneNode.h"
|
||||||
|
#include "SHSceneGraphEvents.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -102,27 +103,4 @@ namespace SHADE
|
||||||
static void TraverseAndInvokeFunction (const SHSceneNode* node, const UnaryFunction& function);
|
static void TraverseAndInvokeFunction (const SHSceneNode* node, const UnaryFunction& function);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
|
||||||
/* Event Data Definitions */
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
struct SHSceneGraphChangeParentEvent
|
|
||||||
{
|
|
||||||
SHSceneNode* node;
|
|
||||||
SHSceneNode* oldParent;
|
|
||||||
SHSceneNode* newParent;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SHSceneGraphAddChildEvent
|
|
||||||
{
|
|
||||||
SHSceneNode* parent;
|
|
||||||
SHSceneNode* addedChild;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SHSceneGraphRemoveChildEvent
|
|
||||||
{
|
|
||||||
SHSceneNode* parent;
|
|
||||||
SHSceneNode* removedChild;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace SHADE
|
} // namespace SHADE
|
|
@ -0,0 +1,41 @@
|
||||||
|
/****************************************************************************************
|
||||||
|
* \file SHSceneGraphEvents.h
|
||||||
|
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
||||||
|
* \brief Interface for Scene Graph Events.
|
||||||
|
*
|
||||||
|
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||||
|
* disclosure of this file or its contents without the prior written consent
|
||||||
|
* of DigiPen Institute of Technology is prohibited.
|
||||||
|
****************************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Project Headers
|
||||||
|
#include "SHSceneNode.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
/* Event Data Definitions */
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
struct SHSceneGraphChangeParentEvent
|
||||||
|
{
|
||||||
|
SHSceneNode* node;
|
||||||
|
SHSceneNode* oldParent;
|
||||||
|
SHSceneNode* newParent;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SHSceneGraphAddChildEvent
|
||||||
|
{
|
||||||
|
SHSceneNode* parent;
|
||||||
|
SHSceneNode* childAdded;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SHSceneGraphRemoveChildEvent
|
||||||
|
{
|
||||||
|
SHSceneNode* parent;
|
||||||
|
SHSceneNode* childRemoved;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace SHADE
|
Loading…
Reference in New Issue