Added faulty registration to entityDestroyed event

This commit is contained in:
Kah Wei 2022-09-22 16:40:49 +08:00
parent 5bc24b09d4
commit 3b533ac03d
3 changed files with 56 additions and 14 deletions

View File

@ -16,9 +16,14 @@ of DigiPen Institute of Technology is prohibited.
// Standard Library
#include <fstream> // std::fstream
#include <filesystem> // std::filesystem::canonical, std::filesystem::remove
#include <memory> // std::shared_ptr
// Project Headers
#include "Tools/SHLogger.h"
#include "Tools/SHStringUtils.h"
#include "ECS_Base/Events/SHEntityDestroyedEvent.h"
#include "Events/SHEvent.h"
#include "Events/SHEventReceiver.h"
#include "Events/SHEventManager.hpp"
namespace SHADE
{
@ -55,14 +60,8 @@ namespace SHADE
// Initialise the CSharp Engine
csEngineInit();
// Link events
// - Entity Destruction
/*onEntityDestroy = [this](const SHEntity& e)
{
csScriptsRemoveAll(e.GetEID());
csGOLibNotifyDestroyEntity(e.GetEID());
};
ECS::OnEntityDestroy += onEntityDestroy;*/
// Register entity creation events
registerEvents();
}
void SHScriptEngine::UnloadScriptAssembly()
{
@ -265,6 +264,16 @@ namespace SHADE
file.close();
}
/*-----------------------------------------------------------------------------------*/
/* Event Handler Functions */
/*-----------------------------------------------------------------------------------*/
SHEventHandle SHScriptEngine::onEntityDestroyed(SHEventPtr eventPtr)
{
auto eventData = reinterpret_cast<const SHEventSpec<SHEntityDestroyedEvent>*>(eventPtr.get());
csScriptsRemoveAll(eventData->data->eid);
return eventData->handle;
}
/*-----------------------------------------------------------------------------------*/
/* Helper Functions */
/*-----------------------------------------------------------------------------------*/
@ -385,6 +394,17 @@ namespace SHADE
);*/
}
void SHScriptEngine::registerEvents()
{
// Register for entity destroyed event
std::shared_ptr<SHEventReceiverSpec<SHScriptEngine>> destroyedEventReceiver
{
std::make_shared<SHEventReceiverSpec<SHScriptEngine>>(this, &SHScriptEngine::onEntityDestroyed)
};
ReceiverPtr receiver = std::dynamic_pointer_cast<SHEventReceiver>(destroyedEventReceiver);
SHEventManager::SubscribeTo(SH_ENTITY_DESTROYED_EVENT, receiver);
}
void SHScriptEngine::dumpBuildLog(const std::string_view& buildLogPath)
{
std::ifstream buildLog(buildLogPath);
@ -495,5 +515,4 @@ namespace SHADE
oss << " -o \"./tmp/\" -fl -flp:LogFile=build.log;Verbosity=quiet";
return oss.str();
}
}

View File

@ -15,12 +15,14 @@ of DigiPen Institute of Technology is prohibited.
#include <filesystem>
// Project Headers
#include "SH_API.h"
#include "SHDotNetRuntime.h"
#include "ECS_Base/SHECSMacros.h"
#include "ECS_Base/Entity/SHEntity.h"
#include "ECS_Base/System/SHSystem.h"
#include "ECS_Base/System/SHSystemRoutine.h"
#include "SH_API.h"
#include "Events/SHEventDefines.h"
#include "Events/SHEvent.h"
namespace SHADE
{
@ -242,6 +244,11 @@ namespace SHADE
/*ECS::EntityEvent::Delegate onEntityCreate;
ECS::EntityEvent::Delegate onEntityDestroy;*/
/*-----------------------------------------------------------------------------*/
/* Event Handler Functions */
/*-----------------------------------------------------------------------------*/
SHEventHandle onEntityDestroyed(SHEventPtr eventPtr);
/*-----------------------------------------------------------------------------*/
/* Helper Functions */
/*-----------------------------------------------------------------------------*/
@ -250,6 +257,10 @@ namespace SHADE
/// </summary>
void loadFunctions();
/// <summary>
/// Registers events for the scripting system
/// </summary>
void registerEvents();
/// <summary>
/// Reads the file via the specified path that represents a build log of error
/// and warning messages.
/// </summary>

View File

@ -4,8 +4,20 @@ public class TestScript : Script
{
public TestScript(GameObject gameObj) : base(gameObj) {}
protected override void awake()
{
Debug.Log("TestScript.Awake()");
}
protected override void start()
{
Debug.Log("TestScript.Start()");
}
protected override void update()
{
Debug.Log("TestScript.Update()");
}
protected override void onDestroy()
{
Debug.Log("TestScript.OnDestroy()");
}
}