Moved commits over to C# Branch
This commit is contained in:
commit
a6a8700b82
|
@ -0,0 +1,53 @@
|
|||
/************************************************************************************//*!
|
||||
\file SHPhysicsSystemInterface.cpp
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 31, 2022
|
||||
\brief Contains the definitions of the functions of the static
|
||||
SHPhysicsSystemInterface class.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
// Precompiled Headers
|
||||
#include "SHpch.h"
|
||||
// Primary Header
|
||||
#include "SHPhysicsSystemInterface.h"
|
||||
// Project Includes
|
||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
#include "Physics/SHPhysicsSystem.h"
|
||||
#include "Physics/SHPhysicsUtils.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Static Usage Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
const std::vector<SHCollisionEvent>& SHPhysicsSystemInterface::GetCollisionInfo() noexcept
|
||||
{
|
||||
static std::vector<SHCollisionEvent> emptyVec;
|
||||
|
||||
auto phySystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||
if (phySystem)
|
||||
{
|
||||
return phySystem->GetCollisionInfo();
|
||||
}
|
||||
|
||||
SHLOG_WARNING("[SHPhysicsSystemInterface] Failed to get collision events. Empty vector returned instead.");
|
||||
return emptyVec;
|
||||
}
|
||||
const std::vector<SHCollisionEvent>& SHPhysicsSystemInterface::GetTriggerInfo() noexcept
|
||||
{
|
||||
static std::vector<SHCollisionEvent> emptyVec;
|
||||
|
||||
auto phySystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||
if (phySystem)
|
||||
{
|
||||
return phySystem->GetTriggerInfo();
|
||||
}
|
||||
|
||||
SHLOG_WARNING("[SHPhysicsSystemInterface] Failed to get trigger events. Empty vector returned instead.");
|
||||
return emptyVec;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/************************************************************************************//*!
|
||||
\file SHPhysicsSystemInterface.h
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 31, 2022
|
||||
\brief Contains the definition of the SHGraphicsSystemInterface static class.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
// STL Includes
|
||||
#include <vector>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Forward Declarations */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
class SHCollisionEvent;
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Static class that wraps up certain functions in the SHPhysicsSystem so that
|
||||
/// accessing it from SHADE_Managed would not cause issues due to C++20 features.
|
||||
/// </summary>
|
||||
class SH_API SHPhysicsSystemInterface final
|
||||
{
|
||||
public:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructor */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
SHPhysicsSystemInterface() = delete;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Static Usage Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
[[nodiscard]] static const std::vector<SHCollisionEvent>& GetCollisionInfo() noexcept;
|
||||
[[nodiscard]] static const std::vector<SHCollisionEvent>& GetTriggerInfo() noexcept;
|
||||
};
|
||||
}
|
|
@ -80,7 +80,10 @@ namespace SHADE
|
|||
{
|
||||
csScriptsExecuteFixedUpdate();
|
||||
}
|
||||
|
||||
void SHScriptEngine::ExecuteCollisionFunctions()
|
||||
{
|
||||
csScriptsExecutePhysicsEvents();
|
||||
}
|
||||
void SHScriptEngine::Exit()
|
||||
{
|
||||
// Do not allow deinitialization if not initialised
|
||||
|
@ -377,6 +380,12 @@ namespace SHADE
|
|||
DEFAULT_CSHARP_NAMESPACE + ".ScriptStore",
|
||||
"ExecuteLateUpdate"
|
||||
);
|
||||
csScriptsExecutePhysicsEvents = dotNet.GetFunctionPtr<CsFuncPtr>
|
||||
(
|
||||
DEFAULT_CSHARP_LIB_NAME,
|
||||
DEFAULT_CSHARP_NAMESPACE + ".ScriptStore",
|
||||
"ExecuteCollisionFunctions"
|
||||
);
|
||||
csScriptsFrameCleanUp = dotNet.GetFunctionPtr<CsFuncPtr>
|
||||
(
|
||||
DEFAULT_CSHARP_LIB_NAME,
|
||||
|
|
|
@ -98,6 +98,11 @@ namespace SHADE
|
|||
/// </summary>
|
||||
void ExecuteFixedUpdates();
|
||||
/// <summary>
|
||||
/// Executes the OnCollision*()s and OnTrigger*()s of the Scripts that are attached
|
||||
/// to Entities.
|
||||
/// </summary>
|
||||
void ExecuteCollisionFunctions();
|
||||
/// <summary>
|
||||
/// Shuts down the DotNetRuntime.
|
||||
/// </summary>
|
||||
void Exit() override;
|
||||
|
@ -245,6 +250,7 @@ namespace SHADE
|
|||
CsFuncPtr csScriptsExecuteFixedUpdate = nullptr;
|
||||
CsFuncPtr csScriptsExecuteUpdate = nullptr;
|
||||
CsFuncPtr csScriptsExecuteLateUpdate = nullptr;
|
||||
CsFuncPtr csScriptsExecutePhysicsEvents = nullptr;
|
||||
CsFuncPtr csScriptsFrameCleanUp = nullptr;
|
||||
CsScriptManipFuncPtr csScriptsAdd = nullptr;
|
||||
CsScriptBasicFuncPtr csScriptsRemoveAll = nullptr;
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/************************************************************************************//*!
|
||||
\file CollisionInfo.cxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 31, 2022
|
||||
\brief Contains the definition of the functions of the managed CollisionInfo
|
||||
struct.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#include "SHpch.h"
|
||||
#include "CollisionInfo.hxx"
|
||||
#include "Components/RigidBody.hxx"
|
||||
#include "Components/Collider.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
Collider^ CollisionInfo::Collider::get()
|
||||
{
|
||||
return GameObject.GetComponent<SHADE::Collider^>();
|
||||
}
|
||||
|
||||
CollisionShape^ CollisionInfo::CollisionShape::get()
|
||||
{
|
||||
throw gcnew System::NotImplementedException();
|
||||
}
|
||||
|
||||
RigidBody^ CollisionInfo::RigidBody::get()
|
||||
{
|
||||
return GameObject.GetComponent<SHADE::RigidBody^>();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/************************************************************************************//*!
|
||||
\file CollisionInfo.hxx
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Oct 31, 2022
|
||||
\brief Contains the definition of the managed CollisionInfo struct with the
|
||||
definition of its properties and declaration of functions.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
// Project Includes
|
||||
#include "Engine/GameObject.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Forward Declarations */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
ref class RigidBody;
|
||||
ref class Collider;
|
||||
ref class CollisionShape;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Struct that describes a collision
|
||||
/// </summary>
|
||||
public value struct CollisionInfo
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// The GameObject whose collider you are colliding with.
|
||||
/// </summary>
|
||||
property GameObject GameObject;
|
||||
/// <summary>
|
||||
/// The Collider that you are colliding with.
|
||||
/// </summary>
|
||||
property Collider^ Collider
|
||||
{
|
||||
SHADE::Collider^ get();
|
||||
}
|
||||
/// <summary>
|
||||
/// The CollisionShape of the Collider that you are colliding with.
|
||||
/// </summary>
|
||||
property CollisionShape^ CollisionShape
|
||||
{
|
||||
SHADE::CollisionShape^ get();
|
||||
}
|
||||
/// <summary>
|
||||
/// The RigidBody that you are colliding with.
|
||||
/// </summary>
|
||||
property RigidBody^ RigidBody
|
||||
{
|
||||
SHADE::RigidBody^ get();
|
||||
}
|
||||
};
|
||||
}
|
|
@ -147,6 +147,48 @@ namespace SHADE
|
|||
SAFE_NATIVE_CALL_END(this)
|
||||
}
|
||||
|
||||
void Script::OnCollisionEnter(CollisionInfo collision)
|
||||
{
|
||||
SAFE_NATIVE_CALL_BEGIN
|
||||
onCollisionEnter(collision);
|
||||
SAFE_NATIVE_CALL_END(this)
|
||||
}
|
||||
|
||||
void Script::OnCollisionStay(CollisionInfo collision)
|
||||
{
|
||||
SAFE_NATIVE_CALL_BEGIN
|
||||
onCollisionStay(collision);
|
||||
SAFE_NATIVE_CALL_END(this)
|
||||
}
|
||||
|
||||
void Script::OnCollisionExit(CollisionInfo collision)
|
||||
{
|
||||
SAFE_NATIVE_CALL_BEGIN
|
||||
onCollisionExit(collision);
|
||||
SAFE_NATIVE_CALL_END(this)
|
||||
}
|
||||
|
||||
void Script::OnTriggerEnter(CollisionInfo collision)
|
||||
{
|
||||
SAFE_NATIVE_CALL_BEGIN
|
||||
onTriggerEnter(collision);
|
||||
SAFE_NATIVE_CALL_END(this)
|
||||
}
|
||||
|
||||
void Script::OnTriggerStay(CollisionInfo collision)
|
||||
{
|
||||
SAFE_NATIVE_CALL_BEGIN
|
||||
onTriggerStay(collision);
|
||||
SAFE_NATIVE_CALL_END(this)
|
||||
}
|
||||
|
||||
void Script::OnTriggerExit(CollisionInfo collision)
|
||||
{
|
||||
SAFE_NATIVE_CALL_BEGIN
|
||||
onTriggerExit(collision);
|
||||
SAFE_NATIVE_CALL_END(this)
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -169,4 +211,14 @@ namespace SHADE
|
|||
void Script::update() {}
|
||||
void Script::lateUpdate() {}
|
||||
void Script::onDestroy() {}
|
||||
}// namespace PlushieAPI
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Virtual Event Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
void Script::onTriggerEnter(CollisionInfo) {}
|
||||
void Script::onTriggerStay(CollisionInfo) {}
|
||||
void Script::onTriggerExit(CollisionInfo) {}
|
||||
void Script::onCollisionEnter(CollisionInfo) {}
|
||||
void Script::onCollisionStay(CollisionInfo) {}
|
||||
void Script::onCollisionExit(CollisionInfo) {}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
|
||||
// Project Includes
|
||||
#include "Engine/GameObject.hxx"
|
||||
#include "Physics/CollisionInfo.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -213,6 +214,46 @@ namespace SHADE
|
|||
/// </summary>
|
||||
void OnDestroy();
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Event Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Used to call onCollisionEnter(). This should be called when a collision is
|
||||
/// detected between the attached GameObject and another GameObject.
|
||||
/// </summary>
|
||||
/// <param name="collision">Information on the collision event.</param>
|
||||
void OnCollisionEnter(CollisionInfo collision);
|
||||
/// <summary>
|
||||
/// Used to call onCollisionStay(). This should be called when a collision is
|
||||
/// persistent between the attached GameObject and another GameObject.
|
||||
/// </summary>
|
||||
/// <param name="collision">Information on the collision event.</param>
|
||||
void OnCollisionStay(CollisionInfo collision);
|
||||
/// <summary>
|
||||
/// Used to call onCollisionExit(). This should be called when a collision ends
|
||||
/// between the attached GameObject and another GameObject.
|
||||
/// </summary>
|
||||
/// <param name="collision">Information on the collision event.</param>
|
||||
void OnCollisionExit(CollisionInfo collision);
|
||||
/// <summary>
|
||||
/// Used to call onTriggerEnter(). This should be called when a trigger-type
|
||||
/// collision is detected between the attached GameObject and another GameObject.
|
||||
/// </summary>
|
||||
/// <param name="collision">Information on the collision event.</param>
|
||||
void OnTriggerEnter(CollisionInfo collision);
|
||||
/// <summary>
|
||||
/// Used to call onTriggerStay(). This should be called when a trigger-type
|
||||
/// collision is detected between the attached GameObject and another GameObject.
|
||||
/// </summary>
|
||||
/// <param name="collision">Information on the collision event.</param>
|
||||
void OnTriggerStay(CollisionInfo collision);
|
||||
/// <summary>
|
||||
/// Used to call onTriggerExit(). This should be called when a trigger-type
|
||||
/// collision is detected between the attached GameObject and another GameObject.
|
||||
/// </summary>
|
||||
/// <param name="collision">Information on the collision event.</param>
|
||||
void OnTriggerExit(CollisionInfo collision);
|
||||
|
||||
protected:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
|
@ -273,6 +314,46 @@ namespace SHADE
|
|||
/// </summary>
|
||||
virtual void onDestroy();
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Virtual Event Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Called when the attached GameObject has a trigger Collider and collides with
|
||||
/// another GameObject with a Collider in the first frame of collision.
|
||||
/// </summary>
|
||||
/// <param name="info">Information on the collision event.</param>
|
||||
virtual void onTriggerEnter(CollisionInfo info);
|
||||
/// <summary>
|
||||
/// Called when the attached GameObject has a trigger Collider and collides with
|
||||
/// another GameObject with a Collider in subsequent frames of collision.
|
||||
/// </summary>
|
||||
/// <param name="info">Information on the collision event.</param>
|
||||
virtual void onTriggerStay(CollisionInfo info);
|
||||
/// <summary>
|
||||
/// Called when the attached GameObject has a trigger Collider and leaves a
|
||||
/// collision with another GameObject with a Collider2D.
|
||||
/// </summary>
|
||||
/// <param name="info">Information on the collision event.</param>
|
||||
virtual void onTriggerExit(CollisionInfo info);
|
||||
/// <summary>
|
||||
/// Called when the attached GameObject has a Collider and collides with
|
||||
/// another GameObject with a Collider in the first frame of collision.
|
||||
/// </summary>
|
||||
/// <param name="info">Information on the collision event.</param>
|
||||
virtual void onCollisionEnter(CollisionInfo info);
|
||||
/// <summary>
|
||||
/// Called when the attached GameObject has a Collider and collides with
|
||||
/// another GameObject with a Collider in subsequent frames of collision.
|
||||
/// </summary>
|
||||
/// <param name="info">Information on the collision event.</param>
|
||||
virtual void onCollisionStay(CollisionInfo info);
|
||||
/// <summary>
|
||||
/// Called when the attached GameObject has a Collider and leaves a
|
||||
/// collision with another GameObject with a Collider2D.
|
||||
/// </summary>
|
||||
/// <param name="info">Information on the collision event.</param>
|
||||
virtual void onCollisionExit(CollisionInfo info);
|
||||
|
||||
private:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
|
@ -280,4 +361,4 @@ namespace SHADE
|
|||
GameObject owner;
|
||||
};
|
||||
|
||||
} // namespace PlushieAPI
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "Engine/Entity.hxx"
|
||||
#include "Serialisation/ReflectionUtilities.hxx"
|
||||
#include "Engine/Application.hxx"
|
||||
#include "Physics/SHPhysicsSystemInterface.h"
|
||||
#include "Physics/SHPhysicsUtils.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -71,7 +73,7 @@ namespace SHADE
|
|||
SAFE_NATIVE_CALL_BEGIN
|
||||
Script^ script;
|
||||
return AddScriptViaNameWithRef(entity, scriptName, script);
|
||||
SAFE_NATIVE_CALL_END_N("SHADE.ScriptStore")
|
||||
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -301,7 +303,7 @@ namespace SHADE
|
|||
removeScript(script);
|
||||
}
|
||||
scriptList->Clear();
|
||||
SAFE_NATIVE_CALL_END_N("SHADE.ScriptStore")
|
||||
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||
}
|
||||
void ScriptStore::RemoveAllScriptsImmediately(Entity entity, bool callOnDestroy)
|
||||
{
|
||||
|
@ -326,7 +328,7 @@ namespace SHADE
|
|||
startList.Remove(script);
|
||||
}
|
||||
scriptList->Clear();
|
||||
SAFE_NATIVE_CALL_END_N("SHADE.ScriptStore")
|
||||
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -365,7 +367,7 @@ namespace SHADE
|
|||
startList.AddRange(%inactiveStartList);
|
||||
inactiveStartList.Clear();
|
||||
|
||||
SAFE_NATIVE_CALL_END_N("SHADE.ScriptStore")
|
||||
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||
}
|
||||
void ScriptStore::FrameCleanUp()
|
||||
{
|
||||
|
@ -386,7 +388,7 @@ namespace SHADE
|
|||
scripts.Remove(entity);
|
||||
}
|
||||
}
|
||||
SAFE_NATIVE_CALL_END_N("SHADE.ScriptStore")
|
||||
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||
}
|
||||
void ScriptStore::Exit()
|
||||
{
|
||||
|
@ -410,7 +412,7 @@ namespace SHADE
|
|||
startList.Clear();
|
||||
disposalQueue.Clear();
|
||||
scriptTypeList = nullptr;
|
||||
SAFE_NATIVE_CALL_END_N("SHADE.ScriptStore")
|
||||
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -439,7 +441,7 @@ namespace SHADE
|
|||
script->FixedUpdate();
|
||||
}
|
||||
}
|
||||
SAFE_NATIVE_CALL_END_N("SHADE.ScriptStore")
|
||||
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||
}
|
||||
void ScriptStore::ExecuteUpdate()
|
||||
{
|
||||
|
@ -456,7 +458,7 @@ namespace SHADE
|
|||
script->Update();
|
||||
}
|
||||
}
|
||||
SAFE_NATIVE_CALL_END_N("SHADE.ScriptStore")
|
||||
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||
}
|
||||
void ScriptStore::ExecuteLateUpdate()
|
||||
{
|
||||
|
@ -473,7 +475,83 @@ namespace SHADE
|
|||
script->LateUpdate();
|
||||
}
|
||||
}
|
||||
SAFE_NATIVE_CALL_END_N("SHADE.ScriptStore")
|
||||
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||
}
|
||||
|
||||
void ScriptStore::ExecuteCollisionFunctions()
|
||||
{
|
||||
SAFE_NATIVE_CALL_BEGIN
|
||||
/* Collisions */
|
||||
const auto& collisions = SHPhysicsSystemInterface::GetCollisionInfo();
|
||||
for (const auto& collisionInfo : collisions)
|
||||
{
|
||||
const EntityID OWNER = collisionInfo.GetEntityA();
|
||||
|
||||
// Don't bother if this object has no scripts or is inactive
|
||||
if (!isEntityActive(OWNER) || !scripts.ContainsKey(OWNER))
|
||||
continue;
|
||||
|
||||
// Construct the collision state object
|
||||
CollisionInfo info;
|
||||
info.GameObject = GameObject(OWNER);
|
||||
|
||||
// Call all of the script's functions
|
||||
auto entityScripts = scripts[OWNER];
|
||||
if (entityScripts->Count > 0)
|
||||
{
|
||||
for each (Script^ script in entityScripts)
|
||||
{
|
||||
switch (collisionInfo.GetCollisionState())
|
||||
{
|
||||
case SHCollisionEvent::State::ENTER:
|
||||
script->OnCollisionEnter(info);
|
||||
break;
|
||||
case SHCollisionEvent::State::STAY:
|
||||
script->OnCollisionStay(info);
|
||||
break;
|
||||
case SHCollisionEvent::State::EXIT:
|
||||
script->OnCollisionExit(info);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Triggers */
|
||||
const auto& triggers = SHPhysicsSystemInterface::GetTriggerInfo();
|
||||
for (const auto& triggerInfo : triggers)
|
||||
{
|
||||
const EntityID OWNER = triggerInfo.GetEntityA();
|
||||
|
||||
// Don't bother if this object has no scripts or is inactive
|
||||
if (!isEntityActive(OWNER) || !scripts.ContainsKey(OWNER))
|
||||
continue;
|
||||
|
||||
// Construct the collision state object
|
||||
CollisionInfo info;
|
||||
info.GameObject = GameObject(OWNER);
|
||||
|
||||
// Call all of the script's functions
|
||||
auto entityScripts = scripts[OWNER];
|
||||
if (entityScripts->Count > 0)
|
||||
{
|
||||
for each (Script ^ script in entityScripts)
|
||||
{
|
||||
switch (triggerInfo.GetCollisionState())
|
||||
{
|
||||
case SHCollisionEvent::State::ENTER:
|
||||
script->OnTriggerEnter(info);
|
||||
break;
|
||||
case SHCollisionEvent::State::STAY:
|
||||
script->OnTriggerStay(info);
|
||||
break;
|
||||
case SHCollisionEvent::State::EXIT:
|
||||
script->OnTriggerExit(info);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||
}
|
||||
|
||||
bool ScriptStore::SerialiseScripts(Entity entity, System::IntPtr yamlNodePtr)
|
||||
|
@ -509,7 +587,7 @@ namespace SHADE
|
|||
}
|
||||
|
||||
return true;
|
||||
SAFE_NATIVE_CALL_END_N("SHADE.ScriptStore")
|
||||
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -559,7 +637,7 @@ namespace SHADE
|
|||
}
|
||||
return true;
|
||||
|
||||
SAFE_NATIVE_CALL_END_N("SHADE.ScriptStore")
|
||||
SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore")
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -233,6 +233,10 @@ namespace SHADE
|
|||
/// Executes LateUpdate() for all scripts.
|
||||
/// </summary>
|
||||
static void ExecuteLateUpdate();
|
||||
/// <summary>
|
||||
/// Executes OnCollision*() and OnTrigger*() for all scripts.
|
||||
/// </summary>
|
||||
static void ExecuteCollisionFunctions();
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Serialisation Functions */
|
||||
|
|
Loading…
Reference in New Issue