diff --git a/SHADE_Engine/src/ECS_Base/Events/SHEntityCreationEvent.h b/SHADE_Engine/src/ECS_Base/Events/SHEntityCreationEvent.h new file mode 100644 index 00000000..728d80f6 --- /dev/null +++ b/SHADE_Engine/src/ECS_Base/Events/SHEntityCreationEvent.h @@ -0,0 +1,12 @@ +#pragma once + +#include "ECS_Base/Entity/SHEntity.h" + +namespace SHADE +{ + struct SHEntityCreationEvent + { + EntityID eid; + std::vector componentTypeIDs; + }; +} diff --git a/SHADE_Engine/src/ECS_Base/Events/SHEntityDestroyedEvent.h b/SHADE_Engine/src/ECS_Base/Events/SHEntityDestroyedEvent.h new file mode 100644 index 00000000..770f0c4e --- /dev/null +++ b/SHADE_Engine/src/ECS_Base/Events/SHEntityDestroyedEvent.h @@ -0,0 +1,11 @@ +#pragma once + +#include "ECS_Base/Entity/SHEntity.h" + +namespace SHADE +{ + struct SHEntityDestroyedEvent + { + EntityID eid; + }; +} diff --git a/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.cpp b/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.cpp index 240c0b32..fddd52cc 100644 --- a/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.cpp +++ b/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.cpp @@ -103,6 +103,10 @@ namespace SHADE SHComponentManager::AddComponent(eID, id); } + //set up event stuff + SHEntityCreationEvent event{ eID,componentTypeIDs }; + SHEventManager::BroadcastEvent(event, SH_ENTITY_CREATION_EVENT); + //(SHComponentManager::AddComponent(eID), ...); //if (entityHandle.IsValid(parentEID) == false) @@ -153,6 +157,12 @@ namespace SHADE entityHandle.RemoveHandle(eID); entityVec[eIndex].reset(nullptr); + + + SHEntityDestroyedEvent event{eID}; + SHEventManager::BroadcastEvent(event, SH_ENTITY_DESTROYED_EVENT); + + } } diff --git a/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.h b/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.h index 2d8a3ce5..a9560fa3 100644 --- a/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.h +++ b/SHADE_Engine/src/ECS_Base/Managers/SHEntityManager.h @@ -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(eID), ...); + //set up event stuff + std::vector typeIDVec; + (typeIDVec.push_back(ComponentFamily::GetID()), ...); + + SHEntityCreationEvent event{ eID,typeIDVec }; + SHEventManager::BroadcastEvent(event, SH_ENTITY_CREATION_EVENT); + + /*if (entityHandle.IsValid(parentEID) == false) { entityVec[eIndex]->sceneNode.ConnectToRoot(); diff --git a/SHADE_Engine/src/Events/SHEventDefines.h b/SHADE_Engine/src/Events/SHEventDefines.h index db8d7752..f1e92b42 100644 --- a/SHADE_Engine/src/Events/SHEventDefines.h +++ b/SHADE_Engine/src/Events/SHEventDefines.h @@ -5,4 +5,6 @@ typedef uint32_t SHEventIdentifier; typedef uint32_t SHEventHandle; //Add your event identifiers here: -constexpr SHEventIdentifier SH_EXAMPLE_EVENT{0}; \ No newline at end of file +constexpr SHEventIdentifier SH_EXAMPLE_EVENT{0}; +constexpr SHEventIdentifier SH_ENTITY_DESTROYED_EVENT{ 1 }; +constexpr SHEventIdentifier SH_ENTITY_CREATION_EVENT{ 2 };