Added entity creation event and entity destroyed events
This commit is contained in:
parent
5ff765c6b9
commit
b3d9a54d8f
|
@ -0,0 +1,12 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ECS_Base/Entity/SHEntity.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
struct SHEntityCreationEvent
|
||||||
|
{
|
||||||
|
EntityID eid;
|
||||||
|
std::vector<ComponentTypeID> componentTypeIDs;
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ECS_Base/Entity/SHEntity.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
struct SHEntityDestroyedEvent
|
||||||
|
{
|
||||||
|
EntityID eid;
|
||||||
|
};
|
||||||
|
}
|
|
@ -103,6 +103,10 @@ namespace SHADE
|
||||||
SHComponentManager::AddComponent(eID, id);
|
SHComponentManager::AddComponent(eID, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//set up event stuff
|
||||||
|
SHEntityCreationEvent event{ eID,componentTypeIDs };
|
||||||
|
SHEventManager::BroadcastEvent<SHEntityCreationEvent>(event, SH_ENTITY_CREATION_EVENT);
|
||||||
|
|
||||||
//(SHComponentManager::AddComponent<ComponentTypes>(eID), ...);
|
//(SHComponentManager::AddComponent<ComponentTypes>(eID), ...);
|
||||||
|
|
||||||
//if (entityHandle.IsValid(parentEID) == false)
|
//if (entityHandle.IsValid(parentEID) == false)
|
||||||
|
@ -153,6 +157,12 @@ namespace SHADE
|
||||||
entityHandle.RemoveHandle(eID);
|
entityHandle.RemoveHandle(eID);
|
||||||
|
|
||||||
entityVec[eIndex].reset(nullptr);
|
entityVec[eIndex].reset(nullptr);
|
||||||
|
|
||||||
|
|
||||||
|
SHEntityDestroyedEvent event{eID};
|
||||||
|
SHEventManager::BroadcastEvent<SHEntityDestroyedEvent>(event, SH_ENTITY_DESTROYED_EVENT);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
#include "../Components/SHComponent.h"
|
#include "../Components/SHComponent.h"
|
||||||
#include "../General/SHHandleGenerator.h"
|
#include "../General/SHHandleGenerator.h"
|
||||||
#include "../SHECSMacros.h"
|
#include "../SHECSMacros.h"
|
||||||
|
#include "ECS_Base/Events/SHEntityCreationEvent.h"
|
||||||
|
#include "ECS_Base/Events/SHEntityDestroyedEvent.h"
|
||||||
|
#include "Events/SHEventManager.h"
|
||||||
#include "SH_API.h"
|
#include "SH_API.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
|
@ -125,6 +128,14 @@ namespace SHADE
|
||||||
entityVec[eIndex]->name = name;
|
entityVec[eIndex]->name = name;
|
||||||
(SHComponentManager::AddComponent<ComponentTypes>(eID), ...);
|
(SHComponentManager::AddComponent<ComponentTypes>(eID), ...);
|
||||||
|
|
||||||
|
//set up event stuff
|
||||||
|
std::vector<ComponentTypeID> typeIDVec;
|
||||||
|
(typeIDVec.push_back(ComponentFamily::GetID<ComponentTypes>()), ...);
|
||||||
|
|
||||||
|
SHEntityCreationEvent event{ eID,typeIDVec };
|
||||||
|
SHEventManager::BroadcastEvent<SHEntityCreationEvent>(event, SH_ENTITY_CREATION_EVENT);
|
||||||
|
|
||||||
|
|
||||||
/*if (entityHandle.IsValid(parentEID) == false)
|
/*if (entityHandle.IsValid(parentEID) == false)
|
||||||
{
|
{
|
||||||
entityVec[eIndex]->sceneNode.ConnectToRoot();
|
entityVec[eIndex]->sceneNode.ConnectToRoot();
|
||||||
|
|
|
@ -7,3 +7,5 @@ typedef void* SHEventDataPtr;
|
||||||
|
|
||||||
//Add your event identifiers here:
|
//Add your event identifiers here:
|
||||||
constexpr SHEventIdentifier SH_EXAMPLE_EVENT{0};
|
constexpr SHEventIdentifier SH_EXAMPLE_EVENT{0};
|
||||||
|
constexpr SHEventIdentifier SH_ENTITY_DESTROYED_EVENT{ 1 };
|
||||||
|
constexpr SHEventIdentifier SH_ENTITY_CREATION_EVENT{ 2 };
|
||||||
|
|
Loading…
Reference in New Issue