Merge pull request #30 from SHADE-DP/SP3-5-ECS

Sp3-5-ECS
Added Entity Creation/Destroyed events
This commit is contained in:
XiaoQiDigipen 2022-09-18 16:51:54 +08:00 committed by GitHub
commit 37fde32e7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 1 deletions

View File

@ -0,0 +1,12 @@
#pragma once
#include "ECS_Base/Entity/SHEntity.h"
namespace SHADE
{
struct SHEntityCreationEvent
{
EntityID eid;
std::vector<ComponentTypeID> componentTypeIDs;
};
}

View File

@ -0,0 +1,11 @@
#pragma once
#include "ECS_Base/Entity/SHEntity.h"
namespace SHADE
{
struct SHEntityDestroyedEvent
{
EntityID eid;
};
}

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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 };