Merge pull request #30 from SHADE-DP/SP3-5-ECS
Sp3-5-ECS Added Entity Creation/Destroyed events
This commit is contained in:
commit
37fde32e7c
|
@ -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);
|
||||
}
|
||||
|
||||
//set up event stuff
|
||||
SHEntityCreationEvent event{ eID,componentTypeIDs };
|
||||
SHEventManager::BroadcastEvent<SHEntityCreationEvent>(event, SH_ENTITY_CREATION_EVENT);
|
||||
|
||||
//(SHComponentManager::AddComponent<ComponentTypes>(eID), ...);
|
||||
|
||||
//if (entityHandle.IsValid(parentEID) == false)
|
||||
|
@ -153,6 +157,12 @@ namespace SHADE
|
|||
entityHandle.RemoveHandle(eID);
|
||||
|
||||
entityVec[eIndex].reset(nullptr);
|
||||
|
||||
|
||||
SHEntityDestroyedEvent event{eID};
|
||||
SHEventManager::BroadcastEvent<SHEntityDestroyedEvent>(event, SH_ENTITY_DESTROYED_EVENT);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
#include "../Components/SHComponent.h"
|
||||
#include "../General/SHHandleGenerator.h"
|
||||
#include "../SHECSMacros.h"
|
||||
#include "ECS_Base/Events/SHEntityCreationEvent.h"
|
||||
#include "ECS_Base/Events/SHEntityDestroyedEvent.h"
|
||||
#include "Events/SHEventManager.h"
|
||||
#include "SH_API.h"
|
||||
|
||||
namespace SHADE
|
||||
|
@ -125,6 +128,14 @@ namespace SHADE
|
|||
entityVec[eIndex]->name = name;
|
||||
(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)
|
||||
{
|
||||
entityVec[eIndex]->sceneNode.ConnectToRoot();
|
||||
|
|
|
@ -5,4 +5,6 @@ typedef uint32_t SHEventIdentifier;
|
|||
typedef uint32_t SHEventHandle;
|
||||
|
||||
//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